2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "ospfd/ospfd.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_ism.h"
43 #include "ospfd/ospf_interface.h"
44 #include "ospfd/ospf_nsm.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_flood.h"
47 #include "ospfd/ospf_abr.h"
48 #include "ospfd/ospf_spf.h"
49 #include "ospfd/ospf_route.h"
50 #include "ospfd/ospf_zebra.h"
51 /*#include "ospfd/ospf_routemap.h" */
52 #include "ospfd/ospf_vty.h"
53 #include "ospfd/ospf_dump.h"
54 #include "ospfd/ospf_bfd.h"
56 static const char *ospf_network_type_str
[] = {
57 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
58 "VIRTUALLINK", "LOOPBACK"};
60 /* Utility functions. */
61 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
65 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
66 if (*ep
&& !inet_aton(str
, area_id
))
70 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
75 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
78 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
79 inet_ntop(AF_INET
, area_id
, buf
, length
);
81 sprintf(buf
, "%lu", (unsigned long)ntohl(area_id
->s_addr
));
84 static int str2metric(const char *str
, int *metric
)
90 *metric
= strtol(str
, NULL
, 10);
91 if (*metric
< 0 && *metric
> 16777214) {
92 /* vty_out (vty, "OSPF metric value is invalid\n"); */
99 static int str2metric_type(const char *str
, int *metric_type
)
105 if (strncmp(str
, "1", 1) == 0)
106 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
107 else if (strncmp(str
, "2", 1) == 0)
108 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
115 int ospf_oi_count(struct interface
*ifp
)
117 struct route_node
*rn
;
120 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
127 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
128 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
129 vrf_name = argv[idx_vrf + 1]->arg; \
130 all_vrf = strmatch(vrf_name, "all"); \
133 static struct ospf
*ospf_cmd_lookup_ospf(struct vty
*vty
,
134 struct cmd_token
*argv
[],
135 const int argc
, uint32_t enable
,
136 unsigned short *instance
)
138 struct ospf
*ospf
= NULL
;
139 int idx_vrf
= 0, idx_inst
= 0;
140 const char *vrf_name
= NULL
;
143 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
))
144 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
146 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
147 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
149 /* Allocate VRF aware instance */
150 ospf
= ospf_get(*instance
, vrf_name
);
152 ospf
= ospf_lookup_by_inst_name(*instance
, vrf_name
);
156 ospf
= ospf_get(*instance
, NULL
);
158 ospf
= ospf_lookup_instance(*instance
);
165 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
166 json_object
*json
, uint8_t use_vrf
)
170 if (ospf
->vrf_id
== VRF_DEFAULT
)
171 json_object_string_add(json
, "vrfName",
174 json_object_string_add(json
, "vrfName",
176 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
178 if (ospf
->vrf_id
== VRF_DEFAULT
)
179 vty_out(vty
, "VRF Name: %s\n", "default");
181 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
186 #ifndef VTYSH_EXTRACT_PL
187 #include "ospfd/ospf_vty_clippy.c"
190 DEFUN_NOSH (router_ospf
,
192 "router ospf [{(1-65535)|vrf NAME}]",
193 "Enable a routing process\n"
194 "Start OSPF configuration\n"
198 struct ospf
*ospf
= NULL
;
199 int ret
= CMD_SUCCESS
;
200 unsigned short instance
= 0;
201 struct vrf
*vrf
= NULL
;
202 struct route_node
*rn
;
203 struct interface
*ifp
;
205 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 1, &instance
);
207 return CMD_WARNING_CONFIG_FAILED
;
209 /* The following logic to set the vty qobj index is in place to be able
210 to ignore the commands which dont belong to this instance. */
211 if (ospf
->instance
!= instance
) {
212 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
213 ret
= CMD_NOT_MY_INSTANCE
;
215 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
216 ospf
->oi_running
= 1;
217 if (IS_DEBUG_OSPF_EVENT
)
219 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
220 instance
, ospf
->name
? ospf
->name
: "NIL",
221 ospf
->vrf_id
, ospf
->oi_running
);
222 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
224 /* Activate 'ip ospf area x' configured interfaces for given
225 * vrf. Activate area on vrf x aware interfaces.
226 * vrf_enable callback calls router_id_update which
227 * internally will call ospf_if_update to trigger
230 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
232 FOR_ALL_INTERFACES (vrf
, ifp
) {
233 struct ospf_if_params
*params
;
235 params
= IF_DEF_PARAMS(ifp
);
236 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
237 for (rn
= route_top(ospf
->networks
); rn
;
238 rn
= route_next(rn
)) {
239 if (rn
->info
!= NULL
) {
241 "Interface %s has area config but please remove all network commands first.\n",
246 ospf_interface_area_set(ospf
, ifp
);
247 ospf
->if_ospf_cli_count
++;
251 ospf_router_id_update(ospf
);
257 DEFUN (no_router_ospf
,
259 "no router ospf [{(1-65535)|vrf NAME}]",
261 "Enable a routing process\n"
262 "Start OSPF configuration\n"
267 unsigned short instance
= 0;
269 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 0, &instance
);
272 return CMD_NOT_MY_INSTANCE
;
282 DEFPY (ospf_router_id
,
284 "ospf router-id A.B.C.D",
285 "OSPF specific commands\n"
286 "router-id for the OSPF process\n"
287 "OSPF router-id in IP address format\n")
289 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
291 struct listnode
*node
;
292 struct ospf_area
*area
;
294 ospf
->router_id_static
= router_id
;
296 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
297 if (area
->full_nbrs
) {
299 "For this router-id change to take effect,"
300 " save config and restart ospfd\n");
304 ospf_router_id_update(ospf
);
309 DEFUN_HIDDEN (ospf_router_id_old
,
310 ospf_router_id_old_cmd
,
312 "router-id for the OSPF process\n"
313 "OSPF router-id in IP address format\n")
315 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
317 struct listnode
*node
;
318 struct ospf_area
*area
;
319 struct in_addr router_id
;
322 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
324 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
325 return CMD_WARNING_CONFIG_FAILED
;
328 ospf
->router_id_static
= router_id
;
330 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
331 if (area
->full_nbrs
) {
333 "For this router-id change to take effect,"
334 " save config and restart ospfd\n");
338 ospf_router_id_update(ospf
);
343 DEFPY (no_ospf_router_id
,
344 no_ospf_router_id_cmd
,
345 "no ospf router-id [A.B.C.D]",
347 "OSPF specific commands\n"
348 "router-id for the OSPF process\n"
349 "OSPF router-id in IP address format\n")
351 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
352 struct listnode
*node
;
353 struct ospf_area
*area
;
356 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
357 vty_out(vty
, "%% OSPF router-id doesn't match\n");
358 return CMD_WARNING_CONFIG_FAILED
;
362 ospf
->router_id_static
.s_addr
= 0;
364 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
365 if (area
->full_nbrs
) {
367 "For this router-id change to take effect,"
368 " save config and restart ospfd\n");
372 ospf_router_id_update(ospf
);
378 static void ospf_passive_interface_default(struct ospf
*ospf
, uint8_t newval
)
380 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
382 struct interface
*ifp
;
383 struct ospf_interface
*oi
;
385 ospf
->passive_interface_default
= newval
;
387 FOR_ALL_INTERFACES (vrf
, ifp
) {
388 if (ifp
&& OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
390 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp
), passive_interface
);
392 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
)) {
393 if (OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
394 UNSET_IF_PARAM(oi
->params
, passive_interface
);
395 /* update multicast memberships */
396 ospf_if_set_multicast(oi
);
400 static void ospf_passive_interface_update_addr(struct ospf
*ospf
,
401 struct interface
*ifp
,
402 struct ospf_if_params
*params
,
408 params
->passive_interface
= value
;
409 if (params
!= IF_DEF_PARAMS(ifp
)) {
410 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
412 dflt
= IF_DEF_PARAMS(ifp
)->passive_interface
;
414 dflt
= ospf
->passive_interface_default
;
417 SET_IF_PARAM(params
, passive_interface
);
419 UNSET_IF_PARAM(params
, passive_interface
);
421 ospf_free_if_params(ifp
, addr
);
422 ospf_if_update_params(ifp
, addr
);
426 static void ospf_passive_interface_update(struct ospf
*ospf
,
427 struct interface
*ifp
,
428 struct ospf_if_params
*params
,
431 params
->passive_interface
= value
;
432 if (params
== IF_DEF_PARAMS(ifp
)) {
433 if (value
!= ospf
->passive_interface_default
)
434 SET_IF_PARAM(params
, passive_interface
);
436 UNSET_IF_PARAM(params
, passive_interface
);
440 DEFUN (ospf_passive_interface
,
441 ospf_passive_interface_addr_cmd
,
442 "passive-interface <IFNAME [A.B.C.D]|default>",
443 "Suppress routing updates on an interface\n"
446 "Suppress routing updates on interfaces by default\n")
448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
450 struct interface
*ifp
= NULL
;
451 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
453 struct ospf_if_params
*params
;
454 struct route_node
*rn
;
456 if (strmatch(argv
[1]->text
, "default")) {
457 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
460 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
461 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, 0);
464 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
465 return CMD_WARNING_CONFIG_FAILED
;
468 params
= IF_DEF_PARAMS(ifp
);
471 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
474 "Please specify interface address by A.B.C.D\n");
475 return CMD_WARNING_CONFIG_FAILED
;
478 params
= ospf_get_if_params(ifp
, addr
);
479 ospf_if_update_params(ifp
, addr
);
480 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
481 OSPF_IF_PASSIVE
, addr
);
484 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
486 /* XXX We should call ospf_if_set_multicast on exactly those
487 * interfaces for which the passive property changed. It is too much
488 * work to determine this set, so we do this for every interface.
489 * This is safe and reasonable because ospf_if_set_multicast uses a
490 * record of joined groups to avoid systems calls if the desired
491 * memberships match the current memership.
494 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
495 struct ospf_interface
*oi
= rn
->info
;
497 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
499 ospf_if_set_multicast(oi
);
502 * XXX It is not clear what state transitions the interface needs to
503 * undergo when going from active to passive. Fixing this will
504 * require precise identification of interfaces having such a
511 DEFUN (no_ospf_passive_interface
,
512 no_ospf_passive_interface_addr_cmd
,
513 "no passive-interface <IFNAME [A.B.C.D]|default>",
515 "Allow routing updates on an interface\n"
518 "Allow routing updates on interfaces by default\n")
520 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
522 struct interface
*ifp
= NULL
;
523 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
524 struct ospf_if_params
*params
;
526 struct route_node
*rn
;
528 if (strmatch(argv
[2]->text
, "default")) {
529 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
533 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
534 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, 0);
537 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
538 return CMD_WARNING_CONFIG_FAILED
;
541 params
= IF_DEF_PARAMS(ifp
);
544 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
547 "Please specify interface address by A.B.C.D\n");
548 return CMD_WARNING_CONFIG_FAILED
;
551 params
= ospf_lookup_if_params(ifp
, addr
);
554 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
555 OSPF_IF_ACTIVE
, addr
);
557 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
559 /* XXX We should call ospf_if_set_multicast on exactly those
560 * interfaces for which the passive property changed. It is too much
561 * work to determine this set, so we do this for every interface.
562 * This is safe and reasonable because ospf_if_set_multicast uses a
563 * record of joined groups to avoid systems calls if the desired
564 * memberships match the current memership.
566 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
567 struct ospf_interface
*oi
= rn
->info
;
570 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
571 ospf_if_set_multicast(oi
);
578 DEFUN (ospf_network_area
,
579 ospf_network_area_cmd
,
580 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
581 "Enable routing on an IP network\n"
582 "OSPF network prefix\n"
583 "Set the OSPF area ID\n"
584 "OSPF area ID in IP address format\n"
585 "OSPF area ID as a decimal value\n")
587 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
588 int idx_ipv4_prefixlen
= 1;
589 int idx_ipv4_number
= 3;
590 struct prefix_ipv4 p
;
591 struct in_addr area_id
;
594 if (ospf
->instance
) {
596 "The network command is not supported in multi-instance ospf\n");
597 return CMD_WARNING_CONFIG_FAILED
;
600 if (ospf
->if_ospf_cli_count
> 0) {
602 "Please remove all ip ospf area x.x.x.x commands first.\n");
603 if (IS_DEBUG_OSPF_EVENT
)
605 "%s ospf vrf %s num of %u ip osp area x config",
607 ospf
->name
? ospf
->name
: "NIL",
608 ospf
->if_ospf_cli_count
);
609 return CMD_WARNING_CONFIG_FAILED
;
612 /* Get network prefix and Area ID. */
613 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
614 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
616 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
618 vty_out(vty
, "There is already same network statement.\n");
619 return CMD_WARNING_CONFIG_FAILED
;
625 DEFUN (no_ospf_network_area
,
626 no_ospf_network_area_cmd
,
627 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
629 "Enable routing on an IP network\n"
630 "OSPF network prefix\n"
631 "Set the OSPF area ID\n"
632 "OSPF area ID in IP address format\n"
633 "OSPF area ID as a decimal value\n")
635 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
636 int idx_ipv4_prefixlen
= 2;
637 int idx_ipv4_number
= 4;
638 struct prefix_ipv4 p
;
639 struct in_addr area_id
;
642 if (ospf
->instance
) {
644 "The network command is not supported in multi-instance ospf\n");
645 return CMD_WARNING_CONFIG_FAILED
;
648 /* Get network prefix and Area ID. */
649 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
650 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
652 ret
= ospf_network_unset(ospf
, &p
, area_id
);
655 "Can't find specified network area configuration.\n");
656 return CMD_WARNING_CONFIG_FAILED
;
662 DEFUN (ospf_area_range
,
664 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
665 "OSPF area parameters\n"
666 "OSPF area ID in IP address format\n"
667 "OSPF area ID as a decimal value\n"
668 "Summarize routes matching address/mask (border routers only)\n"
669 "Area range prefix\n"
670 "Advertise this range (default)\n"
671 "User specified metric for this range\n"
672 "Advertised metric for this range\n")
674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
675 int idx_ipv4_number
= 1;
676 int idx_ipv4_prefixlen
= 3;
678 struct prefix_ipv4 p
;
679 struct in_addr area_id
;
683 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
684 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
686 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
688 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
689 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
695 DEFUN (ospf_area_range_cost
,
696 ospf_area_range_cost_cmd
,
697 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
698 "OSPF area parameters\n"
699 "OSPF area ID in IP address format\n"
700 "OSPF area ID as a decimal value\n"
701 "Summarize routes matching address/mask (border routers only)\n"
702 "Area range prefix\n"
703 "User specified metric for this range\n"
704 "Advertised metric for this range\n")
706 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
707 int idx_ipv4_number
= 1;
708 int idx_ipv4_prefixlen
= 3;
710 struct prefix_ipv4 p
;
711 struct in_addr area_id
;
715 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
716 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
718 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
719 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
722 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
723 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
728 DEFUN (ospf_area_range_not_advertise
,
729 ospf_area_range_not_advertise_cmd
,
730 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
731 "OSPF area parameters\n"
732 "OSPF area ID in IP address format\n"
733 "OSPF area ID as a decimal value\n"
734 "Summarize routes matching address/mask (border routers only)\n"
735 "Area range prefix\n"
736 "DoNotAdvertise this range\n")
738 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
739 int idx_ipv4_number
= 1;
740 int idx_ipv4_prefixlen
= 3;
741 struct prefix_ipv4 p
;
742 struct in_addr area_id
;
745 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
746 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
748 ospf_area_range_set(ospf
, area_id
, &p
, 0);
749 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
755 DEFUN (no_ospf_area_range
,
756 no_ospf_area_range_cmd
,
757 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
759 "OSPF area parameters\n"
760 "OSPF area ID in IP address format\n"
761 "OSPF area ID as a decimal value\n"
762 "Summarize routes matching address/mask (border routers only)\n"
763 "Area range prefix\n"
764 "User specified metric for this range\n"
765 "Advertised metric for this range\n"
766 "Advertise this range (default)\n"
767 "User specified metric for this range\n"
768 "Advertised metric for this range\n"
769 "DoNotAdvertise this range\n")
771 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
772 int idx_ipv4_number
= 2;
773 int idx_ipv4_prefixlen
= 4;
774 struct prefix_ipv4 p
;
775 struct in_addr area_id
;
778 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
779 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
781 ospf_area_range_unset(ospf
, area_id
, &p
);
786 DEFUN (ospf_area_range_substitute
,
787 ospf_area_range_substitute_cmd
,
788 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
789 "OSPF area parameters\n"
790 "OSPF area ID in IP address format\n"
791 "OSPF area ID as a decimal value\n"
792 "Summarize routes matching address/mask (border routers only)\n"
793 "Area range prefix\n"
794 "Announce area range as another prefix\n"
795 "Network prefix to be announced instead of range\n")
797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
798 int idx_ipv4_number
= 1;
799 int idx_ipv4_prefixlen
= 3;
800 int idx_ipv4_prefixlen_2
= 5;
801 struct prefix_ipv4 p
, s
;
802 struct in_addr area_id
;
805 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
806 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
807 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
809 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
810 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
816 DEFUN (no_ospf_area_range_substitute
,
817 no_ospf_area_range_substitute_cmd
,
818 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
820 "OSPF area parameters\n"
821 "OSPF area ID in IP address format\n"
822 "OSPF area ID as a decimal value\n"
823 "Summarize routes matching address/mask (border routers only)\n"
824 "Area range prefix\n"
825 "Announce area range as another prefix\n"
826 "Network prefix to be announced instead of range\n")
828 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
829 int idx_ipv4_number
= 2;
830 int idx_ipv4_prefixlen
= 4;
831 int idx_ipv4_prefixlen_2
= 6;
832 struct prefix_ipv4 p
, s
;
833 struct in_addr area_id
;
836 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
837 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
838 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
840 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
846 /* Command Handler Logic in VLink stuff is delicate!!
848 ALTER AT YOUR OWN RISK!!!!
850 Various dummy values are used to represent 'NoChange' state for
851 VLink configuration NOT being changed by a VLink command, and
852 special syntax is used within the command strings so that the
853 typed in command verbs can be seen in the configuration command
854 bacckend handler. This is to drastically reduce the verbeage
855 required to coe up with a reasonably compatible Cisco VLink command
857 - Matthew Grant <grantma@anathoth.gen.nz>
858 Wed, 21 Feb 2001 15:13:52 +1300
861 /* Configuration data for virtual links
863 struct ospf_vl_config_data
{
864 struct vty
*vty
; /* vty stuff */
865 struct in_addr area_id
; /* area ID from command line */
866 int area_id_fmt
; /* command line area ID format */
867 struct in_addr vl_peer
; /* command line vl_peer */
868 int auth_type
; /* Authehntication type, if given */
869 char *auth_key
; /* simple password if present */
870 int crypto_key_id
; /* Cryptographic key ID */
871 char *md5_key
; /* MD5 authentication key */
872 int hello_interval
; /* Obvious what these are... */
873 int retransmit_interval
;
878 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
881 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
882 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
883 vl_config
->vty
= vty
;
886 static struct ospf_vl_data
*
887 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
889 struct ospf_area
*area
;
890 struct ospf_vl_data
*vl_data
;
892 struct in_addr area_id
;
894 vty
= vl_config
->vty
;
895 area_id
= vl_config
->area_id
;
897 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
899 "Configuring VLs over the backbone is not allowed\n");
902 area
= ospf_area_get(ospf
, area_id
);
903 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
905 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
906 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
907 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
908 area
->external_routing
== OSPF_AREA_NSSA
912 vty_out(vty
, "Area %ld is %s\n",
913 (unsigned long)ntohl(area_id
.s_addr
),
914 area
->external_routing
== OSPF_AREA_NSSA
920 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
922 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
923 if (vl_data
->vl_oi
== NULL
) {
924 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
925 ospf_vl_add(ospf
, vl_data
);
926 ospf_spf_calculate_schedule(ospf
,
927 SPF_FLAG_CONFIG_CHANGE
);
934 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
935 struct ospf_vl_config_data
*vl_config
)
937 struct crypt_key
*ck
;
939 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
941 vty
= vl_config
->vty
;
943 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
944 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
945 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
948 if (vl_config
->auth_key
) {
949 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
950 OSPF_AUTH_SIMPLE_SIZE
+ 1);
951 strncpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
952 vl_config
->auth_key
, OSPF_AUTH_SIMPLE_SIZE
);
953 } else if (vl_config
->md5_key
) {
954 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
955 vl_config
->crypto_key_id
)
957 vty_out(vty
, "OSPF: Key %d already exists\n",
958 vl_config
->crypto_key_id
);
961 ck
= ospf_crypt_key_new();
962 ck
->key_id
= vl_config
->crypto_key_id
;
963 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
964 strncpy((char *)ck
->auth_key
, vl_config
->md5_key
,
967 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
968 } else if (vl_config
->crypto_key_id
!= 0) {
971 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
972 vl_config
->crypto_key_id
)
974 vty_out(vty
, "OSPF: Key %d does not exist\n",
975 vl_config
->crypto_key_id
);
976 return CMD_WARNING_CONFIG_FAILED
;
979 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
980 vl_config
->crypto_key_id
);
986 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
987 struct ospf_vl_config_data
*vl_config
)
989 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
990 /* Virtual Link data initialised to defaults, so only set
992 if (vl_config
->hello_interval
) {
993 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
994 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
997 if (vl_config
->dead_interval
) {
998 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
999 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1002 if (vl_config
->retransmit_interval
) {
1003 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1004 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1005 vl_config
->retransmit_interval
;
1008 if (vl_config
->transmit_delay
) {
1009 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1010 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1017 /* The business end of all of the above */
1018 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1020 struct ospf_vl_data
*vl_data
;
1023 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1025 return CMD_WARNING_CONFIG_FAILED
;
1027 /* Process this one first as it can have a fatal result, which can
1028 only logically occur if the virtual link exists already
1029 Thus a command error does not result in a change to the
1030 running configuration such as unexpectedly altered timer
1032 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1033 if (ret
!= CMD_SUCCESS
)
1036 /* Set any time based parameters, these area already range checked */
1038 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1039 if (ret
!= CMD_SUCCESS
)
1045 /* This stuff exists to make specifying all the alias commands A LOT simpler
1047 #define VLINK_HELPSTR_IPADDR \
1048 "OSPF area parameters\n" \
1049 "OSPF area ID in IP address format\n" \
1050 "OSPF area ID as a decimal value\n" \
1051 "Configure a virtual link\n" \
1052 "Router ID of the remote ABR\n"
1054 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1055 "Enable authentication on this virtual link\n" \
1058 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1059 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1060 "Use null authentication\n" \
1061 "Use message-digest authentication\n"
1063 #define VLINK_HELPSTR_TIME_PARAM \
1064 "Time between HELLO packets\n" \
1066 "Time between retransmitting lost link state advertisements\n" \
1068 "Link state transmit delay\n" \
1070 "Interval time after which a neighbor is declared down\n" \
1073 #define VLINK_HELPSTR_AUTH_SIMPLE \
1074 "Authentication password (key)\n" \
1075 "The OSPF password (key)\n"
1077 #define VLINK_HELPSTR_AUTH_MD5 \
1078 "Message digest authentication password (key)\n" \
1080 "Use MD5 algorithm\n" \
1081 "The OSPF password (key)\n"
1083 DEFUN (ospf_area_vlink
,
1084 ospf_area_vlink_cmd
,
1085 "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>]",
1086 VLINK_HELPSTR_IPADDR
1087 "Enable authentication on this virtual link\n"
1088 "Use message-digest authentication\n"
1089 "Use null authentication\n"
1090 VLINK_HELPSTR_AUTH_MD5
1091 VLINK_HELPSTR_AUTH_SIMPLE
)
1093 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1094 int idx_ipv4_number
= 1;
1096 struct ospf_vl_config_data vl_config
;
1097 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1098 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1102 ospf_vl_config_data_init(&vl_config
, vty
);
1104 /* Read off first 2 parameters and check them */
1105 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1106 &vl_config
.area_id_fmt
);
1108 vty_out(vty
, "OSPF area ID is invalid\n");
1109 return CMD_WARNING_CONFIG_FAILED
;
1112 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1114 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1115 return CMD_WARNING_CONFIG_FAILED
;
1119 /* Thats all folks! - BUGS B. strikes again!!!*/
1121 return ospf_vl_set(ospf
, &vl_config
);
1124 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1125 /* authentication - this option can only occur
1126 at start of command line */
1127 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1130 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1131 /* authentication message-digest */
1132 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1133 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1134 /* "authentication null" */
1135 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1138 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1139 vl_config
.md5_key
= NULL
;
1140 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1141 if (vl_config
.crypto_key_id
< 0)
1142 return CMD_WARNING_CONFIG_FAILED
;
1144 memset(md5_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
1145 strncpy(md5_key
, argv
[idx
+ 3]->arg
, OSPF_AUTH_MD5_SIZE
);
1146 vl_config
.md5_key
= md5_key
;
1149 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1150 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1151 strncpy(auth_key
, argv
[idx
+ 1]->arg
, OSPF_AUTH_SIMPLE_SIZE
);
1152 vl_config
.auth_key
= auth_key
;
1155 /* Action configuration */
1157 return ospf_vl_set(ospf
, &vl_config
);
1160 DEFUN (no_ospf_area_vlink
,
1161 no_ospf_area_vlink_cmd
,
1162 "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>]",
1164 VLINK_HELPSTR_IPADDR
1165 "Enable authentication on this virtual link\n" \
1166 "Use message-digest authentication\n" \
1167 "Use null authentication\n" \
1168 VLINK_HELPSTR_AUTH_MD5
1169 VLINK_HELPSTR_AUTH_SIMPLE
)
1171 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1172 int idx_ipv4_number
= 2;
1174 struct ospf_area
*area
;
1175 struct ospf_vl_config_data vl_config
;
1176 struct ospf_vl_data
*vl_data
= NULL
;
1177 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1181 ospf_vl_config_data_init(&vl_config
, vty
);
1183 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1186 vty_out(vty
, "OSPF area ID is invalid\n");
1187 return CMD_WARNING_CONFIG_FAILED
;
1190 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1192 vty_out(vty
, "Area does not exist\n");
1193 return CMD_WARNING_CONFIG_FAILED
;
1196 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1198 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1199 return CMD_WARNING_CONFIG_FAILED
;
1203 /* Basic VLink no command */
1204 /* Thats all folks! - BUGS B. strikes again!!!*/
1205 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
)))
1206 ospf_vl_delete(ospf
, vl_data
);
1208 ospf_area_check_free(ospf
, vl_config
.area_id
);
1213 /* If we are down here, we are reseting parameters */
1214 /* Deal with other parameters */
1216 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1217 /* authentication - this option can only occur
1218 at start of command line */
1219 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1222 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1223 vl_config
.md5_key
= NULL
;
1224 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1225 if (vl_config
.crypto_key_id
< 0)
1226 return CMD_WARNING_CONFIG_FAILED
;
1229 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1230 /* Reset authentication-key to 0 */
1231 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1232 vl_config
.auth_key
= auth_key
;
1235 /* Action configuration */
1237 return ospf_vl_set(ospf
, &vl_config
);
1240 DEFUN (ospf_area_vlink_intervals
,
1241 ospf_area_vlink_intervals_cmd
,
1242 "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)}",
1243 VLINK_HELPSTR_IPADDR
1244 VLINK_HELPSTR_TIME_PARAM
)
1246 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1247 struct ospf_vl_config_data vl_config
;
1250 ospf_vl_config_data_init(&vl_config
, vty
);
1252 char *area_id
= argv
[1]->arg
;
1253 char *router_id
= argv
[3]->arg
;
1255 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1257 vty_out(vty
, "OSPF area ID is invalid\n");
1258 return CMD_WARNING_CONFIG_FAILED
;
1261 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1263 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1264 return CMD_WARNING_CONFIG_FAILED
;
1267 for (int idx
= 4; idx
< argc
; idx
++) {
1268 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1269 vl_config
.hello_interval
=
1270 strtol(argv
[++idx
]->arg
, NULL
, 10);
1271 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1272 vl_config
.retransmit_interval
=
1273 strtol(argv
[++idx
]->arg
, NULL
, 10);
1274 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1275 vl_config
.transmit_delay
=
1276 strtol(argv
[++idx
]->arg
, NULL
, 10);
1277 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1278 vl_config
.dead_interval
=
1279 strtol(argv
[++idx
]->arg
, NULL
, 10);
1282 /* Action configuration */
1283 return ospf_vl_set(ospf
, &vl_config
);
1286 DEFUN (no_ospf_area_vlink_intervals
,
1287 no_ospf_area_vlink_intervals_cmd
,
1288 "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)}",
1290 VLINK_HELPSTR_IPADDR
1291 VLINK_HELPSTR_TIME_PARAM
)
1293 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1294 struct ospf_vl_config_data vl_config
;
1297 ospf_vl_config_data_init(&vl_config
, vty
);
1299 char *area_id
= argv
[2]->arg
;
1300 char *router_id
= argv
[4]->arg
;
1302 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1304 vty_out(vty
, "OSPF area ID is invalid\n");
1305 return CMD_WARNING_CONFIG_FAILED
;
1308 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1310 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1311 return CMD_WARNING_CONFIG_FAILED
;
1314 for (int idx
= 5; idx
< argc
; idx
++) {
1315 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1316 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1317 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1318 vl_config
.retransmit_interval
=
1319 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1320 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1321 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1322 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1323 vl_config
.dead_interval
=
1324 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1327 /* Action configuration */
1328 return ospf_vl_set(ospf
, &vl_config
);
1331 DEFUN (ospf_area_shortcut
,
1332 ospf_area_shortcut_cmd
,
1333 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1334 "OSPF area parameters\n"
1335 "OSPF area ID in IP address format\n"
1336 "OSPF area ID as a decimal value\n"
1337 "Configure the area's shortcutting mode\n"
1338 "Set default shortcutting behavior\n"
1339 "Enable shortcutting through the area\n"
1340 "Disable shortcutting through the area\n")
1342 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1343 int idx_ipv4_number
= 1;
1344 int idx_enable_disable
= 3;
1345 struct ospf_area
*area
;
1346 struct in_addr area_id
;
1350 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1351 argv
[idx_ipv4_number
]->arg
);
1353 area
= ospf_area_get(ospf
, area_id
);
1354 ospf_area_display_format_set(ospf
, area
, format
);
1356 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1357 mode
= OSPF_SHORTCUT_DEFAULT
;
1358 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1359 mode
= OSPF_SHORTCUT_DISABLE
;
1360 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1361 mode
= OSPF_SHORTCUT_ENABLE
;
1363 return CMD_WARNING_CONFIG_FAILED
;
1365 ospf_area_shortcut_set(ospf
, area
, mode
);
1367 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1369 "Shortcut area setting will take effect "
1370 "only when the router is configured as Shortcut ABR\n");
1375 DEFUN (no_ospf_area_shortcut
,
1376 no_ospf_area_shortcut_cmd
,
1377 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1379 "OSPF area parameters\n"
1380 "OSPF area ID in IP address format\n"
1381 "OSPF area ID as a decimal value\n"
1382 "Deconfigure the area's shortcutting mode\n"
1383 "Deconfigure enabled shortcutting through the area\n"
1384 "Deconfigure disabled shortcutting through the area\n")
1386 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1387 int idx_ipv4_number
= 2;
1388 struct ospf_area
*area
;
1389 struct in_addr area_id
;
1392 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1393 argv
[idx_ipv4_number
]->arg
);
1395 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1399 ospf_area_shortcut_unset(ospf
, area
);
1405 DEFUN (ospf_area_stub
,
1407 "area <A.B.C.D|(0-4294967295)> stub",
1408 "OSPF area parameters\n"
1409 "OSPF area ID in IP address format\n"
1410 "OSPF area ID as a decimal value\n"
1411 "Configure OSPF area as stub\n")
1413 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1414 int idx_ipv4_number
= 1;
1415 struct in_addr area_id
;
1418 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1419 argv
[idx_ipv4_number
]->arg
);
1421 ret
= ospf_area_stub_set(ospf
, area_id
);
1422 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1426 "First deconfigure all virtual link through this area\n");
1427 return CMD_WARNING_CONFIG_FAILED
;
1430 ospf_area_no_summary_unset(ospf
, area_id
);
1435 DEFUN (ospf_area_stub_no_summary
,
1436 ospf_area_stub_no_summary_cmd
,
1437 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1438 "OSPF stub parameters\n"
1439 "OSPF area ID in IP address format\n"
1440 "OSPF area ID as a decimal value\n"
1441 "Configure OSPF area as stub\n"
1442 "Do not inject inter-area routes into stub\n")
1444 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1445 int idx_ipv4_number
= 1;
1446 struct in_addr area_id
;
1449 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1450 argv
[idx_ipv4_number
]->arg
);
1452 ret
= ospf_area_stub_set(ospf
, area_id
);
1453 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1457 "%% Area cannot be stub as it contains a virtual link\n");
1458 return CMD_WARNING_CONFIG_FAILED
;
1461 ospf_area_no_summary_set(ospf
, area_id
);
1466 DEFUN (no_ospf_area_stub
,
1467 no_ospf_area_stub_cmd
,
1468 "no area <A.B.C.D|(0-4294967295)> stub",
1470 "OSPF area parameters\n"
1471 "OSPF area ID in IP address format\n"
1472 "OSPF area ID as a decimal value\n"
1473 "Configure OSPF area as stub\n")
1475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1476 int idx_ipv4_number
= 2;
1477 struct in_addr area_id
;
1480 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1481 argv
[idx_ipv4_number
]->arg
);
1483 ospf_area_stub_unset(ospf
, area_id
);
1484 ospf_area_no_summary_unset(ospf
, area_id
);
1489 DEFUN (no_ospf_area_stub_no_summary
,
1490 no_ospf_area_stub_no_summary_cmd
,
1491 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1493 "OSPF area parameters\n"
1494 "OSPF area ID in IP address format\n"
1495 "OSPF area ID as a decimal value\n"
1496 "Configure OSPF area as stub\n"
1497 "Do not inject inter-area routes into area\n")
1499 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1500 int idx_ipv4_number
= 2;
1501 struct in_addr area_id
;
1504 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1505 argv
[idx_ipv4_number
]->arg
);
1506 ospf_area_no_summary_unset(ospf
, area_id
);
1511 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1512 struct cmd_token
**argv
, int cfg_nosum
,
1515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1516 struct in_addr area_id
;
1519 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1521 ret
= ospf_area_nssa_set(ospf
, area_id
);
1522 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1526 "%% Area cannot be nssa as it contains a virtual link\n");
1527 return CMD_WARNING_CONFIG_FAILED
;
1531 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1532 ospf_area_nssa_translator_role_set(
1533 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1534 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1535 ospf_area_nssa_translator_role_set(
1536 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1537 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1538 ospf_area_nssa_translator_role_set(
1539 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1541 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1542 OSPF_NSSA_ROLE_CANDIDATE
);
1547 ospf_area_no_summary_set(ospf
, area_id
);
1549 ospf_area_no_summary_unset(ospf
, area_id
);
1552 ospf_schedule_abr_task(ospf
);
1558 DEFUN (ospf_area_nssa_translate
,
1559 ospf_area_nssa_translate_cmd
,
1560 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1561 "OSPF area parameters\n"
1562 "OSPF area ID in IP address format\n"
1563 "OSPF area ID as a decimal value\n"
1564 "Configure OSPF area as nssa\n"
1565 "Configure NSSA-ABR for translate election (default)\n"
1566 "Configure NSSA-ABR to never translate\n"
1567 "Configure NSSA-ABR to always translate\n")
1569 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1572 DEFUN (ospf_area_nssa
,
1574 "area <A.B.C.D|(0-4294967295)> nssa",
1575 "OSPF area parameters\n"
1576 "OSPF area ID in IP address format\n"
1577 "OSPF area ID as a decimal value\n"
1578 "Configure OSPF area as nssa\n")
1580 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1583 DEFUN (ospf_area_nssa_no_summary
,
1584 ospf_area_nssa_no_summary_cmd
,
1585 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1586 "OSPF area parameters\n"
1587 "OSPF area ID in IP address format\n"
1588 "OSPF area ID as a decimal value\n"
1589 "Configure OSPF area as nssa\n"
1590 "Do not inject inter-area routes into nssa\n")
1592 int idx_ipv4_number
= 1;
1593 struct in_addr area_id
;
1596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1597 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1598 argv
[idx_ipv4_number
]->arg
);
1600 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1602 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1604 ospf_schedule_abr_task(ospf
);
1609 DEFUN (no_ospf_area_nssa_no_summary
,
1610 no_ospf_area_nssa_no_summary_cmd
,
1611 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1613 "OSPF area parameters\n"
1614 "OSPF area ID in IP address format\n"
1615 "OSPF area ID as a decimal value\n"
1616 "Configure OSPF area as nssa\n"
1617 "Do not inject inter-area routes into nssa\n")
1619 int idx_ipv4_number
= 2;
1620 struct in_addr area_id
;
1623 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1625 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1626 argv
[idx_ipv4_number
]->arg
);
1628 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1630 ospf_area_no_summary_unset(ospf
, area_id
);
1632 ospf_schedule_abr_task(ospf
);
1637 DEFUN (no_ospf_area_nssa
,
1638 no_ospf_area_nssa_cmd
,
1639 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1641 "OSPF area parameters\n"
1642 "OSPF area ID in IP address format\n"
1643 "OSPF area ID as a decimal value\n"
1644 "Configure OSPF area as nssa\n"
1645 "Configure NSSA-ABR for translate election (default)\n"
1646 "Configure NSSA-ABR to never translate\n"
1647 "Configure NSSA-ABR to always translate\n")
1649 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1650 int idx_ipv4_number
= 2;
1651 struct in_addr area_id
;
1654 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1655 argv
[idx_ipv4_number
]->arg
);
1657 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1659 ospf_schedule_abr_task(ospf
);
1665 DEFUN (ospf_area_default_cost
,
1666 ospf_area_default_cost_cmd
,
1667 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1668 "OSPF area parameters\n"
1669 "OSPF area ID in IP address format\n"
1670 "OSPF area ID as a decimal value\n"
1671 "Set the summary-default cost of a NSSA or stub area\n"
1672 "Stub's advertised default summary cost\n")
1674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1675 int idx_ipv4_number
= 1;
1677 struct ospf_area
*area
;
1678 struct in_addr area_id
;
1681 struct prefix_ipv4 p
;
1683 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1684 argv
[idx_ipv4_number
]->arg
);
1685 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1687 area
= ospf_area_get(ospf
, area_id
);
1688 ospf_area_display_format_set(ospf
, area
, format
);
1690 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1691 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1692 return CMD_WARNING_CONFIG_FAILED
;
1695 area
->default_cost
= cost
;
1698 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1700 if (IS_DEBUG_OSPF_EVENT
)
1702 "ospf_abr_announce_stub_defaults(): "
1703 "announcing 0.0.0.0/0 to area %s",
1704 inet_ntoa(area
->area_id
));
1705 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1710 DEFUN (no_ospf_area_default_cost
,
1711 no_ospf_area_default_cost_cmd
,
1712 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1714 "OSPF area parameters\n"
1715 "OSPF area ID in IP address format\n"
1716 "OSPF area ID as a decimal value\n"
1717 "Set the summary-default cost of a NSSA or stub area\n"
1718 "Stub's advertised default summary cost\n")
1720 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1721 int idx_ipv4_number
= 2;
1722 struct ospf_area
*area
;
1723 struct in_addr area_id
;
1725 struct prefix_ipv4 p
;
1727 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1728 argv
[idx_ipv4_number
]->arg
);
1730 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1734 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1735 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1736 return CMD_WARNING_CONFIG_FAILED
;
1739 area
->default_cost
= 1;
1742 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1744 if (IS_DEBUG_OSPF_EVENT
)
1746 "ospf_abr_announce_stub_defaults(): "
1747 "announcing 0.0.0.0/0 to area %s",
1748 inet_ntoa(area
->area_id
));
1749 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1752 ospf_area_check_free(ospf
, area_id
);
1757 DEFUN (ospf_area_export_list
,
1758 ospf_area_export_list_cmd
,
1759 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1760 "OSPF area parameters\n"
1761 "OSPF area ID in IP address format\n"
1762 "OSPF area ID as a decimal value\n"
1763 "Set the filter for networks announced to other areas\n"
1764 "Name of the access-list\n")
1766 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1767 int idx_ipv4_number
= 1;
1768 struct ospf_area
*area
;
1769 struct in_addr area_id
;
1772 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1774 area
= ospf_area_get(ospf
, area_id
);
1775 ospf_area_display_format_set(ospf
, area
, format
);
1776 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1781 DEFUN (no_ospf_area_export_list
,
1782 no_ospf_area_export_list_cmd
,
1783 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1785 "OSPF area parameters\n"
1786 "OSPF area ID in IP address format\n"
1787 "OSPF area ID as a decimal value\n"
1788 "Unset the filter for networks announced to other areas\n"
1789 "Name of the access-list\n")
1791 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1792 int idx_ipv4_number
= 2;
1793 struct ospf_area
*area
;
1794 struct in_addr area_id
;
1797 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1799 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1803 ospf_area_export_list_unset(ospf
, area
);
1809 DEFUN (ospf_area_import_list
,
1810 ospf_area_import_list_cmd
,
1811 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1812 "OSPF area parameters\n"
1813 "OSPF area ID in IP address format\n"
1814 "OSPF area ID as a decimal value\n"
1815 "Set the filter for networks from other areas announced to the specified one\n"
1816 "Name of the access-list\n")
1818 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1819 int idx_ipv4_number
= 1;
1820 struct ospf_area
*area
;
1821 struct in_addr area_id
;
1824 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1826 area
= ospf_area_get(ospf
, area_id
);
1827 ospf_area_display_format_set(ospf
, area
, format
);
1828 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1833 DEFUN (no_ospf_area_import_list
,
1834 no_ospf_area_import_list_cmd
,
1835 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1837 "OSPF area parameters\n"
1838 "OSPF area ID in IP address format\n"
1839 "OSPF area ID as a decimal value\n"
1840 "Unset the filter for networks announced to other areas\n"
1841 "Name of the access-list\n")
1843 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1844 int idx_ipv4_number
= 2;
1845 struct ospf_area
*area
;
1846 struct in_addr area_id
;
1849 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1851 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1855 ospf_area_import_list_unset(ospf
, area
);
1860 DEFUN (ospf_area_filter_list
,
1861 ospf_area_filter_list_cmd
,
1862 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1863 "OSPF area parameters\n"
1864 "OSPF area ID in IP address format\n"
1865 "OSPF area ID as a decimal value\n"
1866 "Filter networks between OSPF areas\n"
1867 "Filter prefixes between OSPF areas\n"
1868 "Name of an IP prefix-list\n"
1869 "Filter networks sent to this area\n"
1870 "Filter networks sent from this area\n")
1872 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1873 int idx_ipv4_number
= 1;
1876 struct ospf_area
*area
;
1877 struct in_addr area_id
;
1878 struct prefix_list
*plist
;
1881 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1883 area
= ospf_area_get(ospf
, area_id
);
1884 ospf_area_display_format_set(ospf
, area
, format
);
1885 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1886 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1887 PREFIX_LIST_IN(area
) = plist
;
1888 if (PREFIX_NAME_IN(area
))
1889 free(PREFIX_NAME_IN(area
));
1891 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1892 ospf_schedule_abr_task(ospf
);
1894 PREFIX_LIST_OUT(area
) = plist
;
1895 if (PREFIX_NAME_OUT(area
))
1896 free(PREFIX_NAME_OUT(area
));
1898 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1899 ospf_schedule_abr_task(ospf
);
1905 DEFUN (no_ospf_area_filter_list
,
1906 no_ospf_area_filter_list_cmd
,
1907 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1909 "OSPF area parameters\n"
1910 "OSPF area ID in IP address format\n"
1911 "OSPF area ID as a decimal value\n"
1912 "Filter networks between OSPF areas\n"
1913 "Filter prefixes between OSPF areas\n"
1914 "Name of an IP prefix-list\n"
1915 "Filter networks sent to this area\n"
1916 "Filter networks sent from this area\n")
1918 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1919 int idx_ipv4_number
= 2;
1922 struct ospf_area
*area
;
1923 struct in_addr area_id
;
1926 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1928 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1931 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1932 if (PREFIX_NAME_IN(area
))
1933 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1937 PREFIX_LIST_IN(area
) = NULL
;
1938 if (PREFIX_NAME_IN(area
))
1939 free(PREFIX_NAME_IN(area
));
1941 PREFIX_NAME_IN(area
) = NULL
;
1943 ospf_schedule_abr_task(ospf
);
1945 if (PREFIX_NAME_OUT(area
))
1946 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1950 PREFIX_LIST_OUT(area
) = NULL
;
1951 if (PREFIX_NAME_OUT(area
))
1952 free(PREFIX_NAME_OUT(area
));
1954 PREFIX_NAME_OUT(area
) = NULL
;
1956 ospf_schedule_abr_task(ospf
);
1963 DEFUN (ospf_area_authentication_message_digest
,
1964 ospf_area_authentication_message_digest_cmd
,
1965 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1967 "OSPF area parameters\n"
1968 "OSPF area ID in IP address format\n"
1969 "OSPF area ID as a decimal value\n"
1970 "Enable authentication\n"
1971 "Use message-digest authentication\n")
1973 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1975 struct ospf_area
*area
;
1976 struct in_addr area_id
;
1979 argv_find(argv
, argc
, "area", &idx
);
1980 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1982 area
= ospf_area_get(ospf
, area_id
);
1983 ospf_area_display_format_set(ospf
, area
, format
);
1984 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1986 : OSPF_AUTH_CRYPTOGRAPHIC
;
1991 DEFUN (ospf_area_authentication
,
1992 ospf_area_authentication_cmd
,
1993 "area <A.B.C.D|(0-4294967295)> authentication",
1994 "OSPF area parameters\n"
1995 "OSPF area ID in IP address format\n"
1996 "OSPF area ID as a decimal value\n"
1997 "Enable authentication\n")
1999 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2000 int idx_ipv4_number
= 1;
2001 struct ospf_area
*area
;
2002 struct in_addr area_id
;
2005 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2007 area
= ospf_area_get(ospf
, area_id
);
2008 ospf_area_display_format_set(ospf
, area
, format
);
2009 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2014 DEFUN (no_ospf_area_authentication
,
2015 no_ospf_area_authentication_cmd
,
2016 "no area <A.B.C.D|(0-4294967295)> authentication",
2018 "OSPF area parameters\n"
2019 "OSPF area ID in IP address format\n"
2020 "OSPF area ID as a decimal value\n"
2021 "Enable authentication\n")
2023 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2024 int idx_ipv4_number
= 2;
2025 struct ospf_area
*area
;
2026 struct in_addr area_id
;
2029 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2031 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2035 area
->auth_type
= OSPF_AUTH_NULL
;
2037 ospf_area_check_free(ospf
, area_id
);
2043 DEFUN (ospf_abr_type
,
2045 "ospf abr-type <cisco|ibm|shortcut|standard>",
2046 "OSPF specific commands\n"
2047 "Set OSPF ABR type\n"
2048 "Alternative ABR, cisco implementation\n"
2049 "Alternative ABR, IBM implementation\n"
2051 "Standard behavior (RFC2328)\n")
2053 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2055 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2057 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2058 abr_type
= OSPF_ABR_CISCO
;
2059 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2060 abr_type
= OSPF_ABR_IBM
;
2061 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2062 abr_type
= OSPF_ABR_SHORTCUT
;
2063 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2064 abr_type
= OSPF_ABR_STAND
;
2066 return CMD_WARNING_CONFIG_FAILED
;
2068 /* If ABR type value is changed, schedule ABR task. */
2069 if (ospf
->abr_type
!= abr_type
) {
2070 ospf
->abr_type
= abr_type
;
2071 ospf_schedule_abr_task(ospf
);
2077 DEFUN (no_ospf_abr_type
,
2078 no_ospf_abr_type_cmd
,
2079 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2081 "OSPF specific commands\n"
2082 "Set OSPF ABR type\n"
2083 "Alternative ABR, cisco implementation\n"
2084 "Alternative ABR, IBM implementation\n"
2088 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2090 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2092 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2093 abr_type
= OSPF_ABR_CISCO
;
2094 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2095 abr_type
= OSPF_ABR_IBM
;
2096 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2097 abr_type
= OSPF_ABR_SHORTCUT
;
2098 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2099 abr_type
= OSPF_ABR_STAND
;
2101 return CMD_WARNING_CONFIG_FAILED
;
2103 /* If ABR type value is changed, schedule ABR task. */
2104 if (ospf
->abr_type
== abr_type
) {
2105 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2106 ospf_schedule_abr_task(ospf
);
2112 DEFUN (ospf_log_adjacency_changes
,
2113 ospf_log_adjacency_changes_cmd
,
2114 "log-adjacency-changes",
2115 "Log changes in adjacency state\n")
2117 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2119 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2120 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2124 DEFUN (ospf_log_adjacency_changes_detail
,
2125 ospf_log_adjacency_changes_detail_cmd
,
2126 "log-adjacency-changes detail",
2127 "Log changes in adjacency state\n"
2128 "Log all state changes\n")
2130 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2132 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2133 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2137 DEFUN (no_ospf_log_adjacency_changes
,
2138 no_ospf_log_adjacency_changes_cmd
,
2139 "no log-adjacency-changes",
2141 "Log changes in adjacency state\n")
2143 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2145 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2146 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2150 DEFUN (no_ospf_log_adjacency_changes_detail
,
2151 no_ospf_log_adjacency_changes_detail_cmd
,
2152 "no log-adjacency-changes detail",
2154 "Log changes in adjacency state\n"
2155 "Log all state changes\n")
2157 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2159 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2163 DEFUN (ospf_compatible_rfc1583
,
2164 ospf_compatible_rfc1583_cmd
,
2165 "compatible rfc1583",
2166 "OSPF compatibility list\n"
2167 "compatible with RFC 1583\n")
2169 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2171 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2172 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2173 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2178 DEFUN (no_ospf_compatible_rfc1583
,
2179 no_ospf_compatible_rfc1583_cmd
,
2180 "no compatible rfc1583",
2182 "OSPF compatibility list\n"
2183 "compatible with RFC 1583\n")
2185 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2187 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2188 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2189 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2194 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2195 "ospf rfc1583compatibility",
2196 "OSPF specific commands\n"
2197 "Enable the RFC1583Compatibility flag\n")
2199 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2200 "no ospf rfc1583compatibility", NO_STR
2201 "OSPF specific commands\n"
2202 "Disable the RFC1583Compatibility flag\n")
2204 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2205 unsigned int hold
, unsigned int max
)
2207 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2209 ospf
->spf_delay
= delay
;
2210 ospf
->spf_holdtime
= hold
;
2211 ospf
->spf_max_holdtime
= max
;
2216 DEFUN (ospf_timers_min_ls_interval
,
2217 ospf_timers_min_ls_interval_cmd
,
2218 "timers throttle lsa all (0-5000)",
2219 "Adjust routing timers\n"
2220 "Throttling adaptive timer\n"
2221 "LSA delay between transmissions\n"
2223 "Delay (msec) between sending LSAs\n")
2225 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2227 unsigned int interval
;
2230 vty_out(vty
, "Insufficient arguments\n");
2231 return CMD_WARNING_CONFIG_FAILED
;
2234 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2236 ospf
->min_ls_interval
= interval
;
2241 DEFUN (no_ospf_timers_min_ls_interval
,
2242 no_ospf_timers_min_ls_interval_cmd
,
2243 "no timers throttle lsa all [(0-5000)]",
2245 "Adjust routing timers\n"
2246 "Throttling adaptive timer\n"
2247 "LSA delay between transmissions\n"
2249 "Delay (msec) between sending LSAs\n")
2251 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2252 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2257 DEFUN (ospf_timers_throttle_spf
,
2258 ospf_timers_throttle_spf_cmd
,
2259 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2260 "Adjust routing timers\n"
2261 "Throttling adaptive timer\n"
2263 "Delay (msec) from first change received till SPF calculation\n"
2264 "Initial hold time (msec) between consecutive SPF calculations\n"
2265 "Maximum hold time (msec)\n")
2268 int idx_number_2
= 4;
2269 int idx_number_3
= 5;
2270 unsigned int delay
, hold
, max
;
2273 vty_out(vty
, "Insufficient arguments\n");
2274 return CMD_WARNING_CONFIG_FAILED
;
2277 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2278 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2279 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2281 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2284 DEFUN (no_ospf_timers_throttle_spf
,
2285 no_ospf_timers_throttle_spf_cmd
,
2286 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2288 "Adjust routing timers\n"
2289 "Throttling adaptive timer\n"
2291 "Delay (msec) from first change received till SPF calculation\n"
2292 "Initial hold time (msec) between consecutive SPF calculations\n"
2293 "Maximum hold time (msec)\n")
2295 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2296 OSPF_SPF_HOLDTIME_DEFAULT
,
2297 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2301 DEFUN (ospf_timers_lsa_min_arrival
,
2302 ospf_timers_lsa_min_arrival_cmd
,
2303 "timers lsa min-arrival (0-600000)",
2304 "Adjust routing timers\n"
2306 "Minimum delay in receiving new version of a LSA\n"
2307 "Delay in milliseconds\n")
2309 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2310 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2314 DEFUN (no_ospf_timers_lsa_min_arrival
,
2315 no_ospf_timers_lsa_min_arrival_cmd
,
2316 "no timers lsa min-arrival [(0-600000)]",
2318 "Adjust routing timers\n"
2320 "Minimum delay in receiving new version of a LSA\n"
2321 "Delay in milliseconds\n")
2323 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2324 unsigned int minarrival
;
2327 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2329 if (ospf
->min_ls_arrival
!= minarrival
2330 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2334 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2339 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
2340 CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08")
2342 ALIAS_HIDDEN(ospf_timers_lsa_min_arrival
, ospf_timers_lsa_arrival_cmd
,
2343 "timers lsa arrival (0-1000)",
2344 "adjust routing timers\n"
2345 "throttling link state advertisement delays\n"
2346 "ospf minimum arrival interval delay\n"
2347 "delay (msec) between accepted lsas\n");
2349 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
2350 CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08")
2352 ALIAS_HIDDEN(no_ospf_timers_lsa_min_arrival
, no_ospf_timers_lsa_arrival_cmd
,
2353 "no timers lsa arrival (0-1000)", NO_STR
2354 "adjust routing timers\n"
2355 "throttling link state advertisement delays\n"
2356 "ospf minimum arrival interval delay\n"
2357 "delay (msec) between accepted lsas\n");
2360 DEFUN (ospf_neighbor
,
2362 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2364 "Neighbor IP address\n"
2365 "Neighbor Priority\n"
2367 "Dead Neighbor Polling interval\n"
2370 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2374 struct in_addr nbr_addr
;
2375 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2376 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2378 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2379 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2380 return CMD_WARNING_CONFIG_FAILED
;
2384 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2387 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2389 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2392 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2395 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2400 DEFUN (ospf_neighbor_poll_interval
,
2401 ospf_neighbor_poll_interval_cmd
,
2402 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2404 "Neighbor IP address\n"
2405 "Dead Neighbor Polling interval\n"
2407 "OSPF priority of non-broadcast neighbor\n"
2410 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2414 struct in_addr nbr_addr
;
2415 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2416 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2418 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2419 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2420 return CMD_WARNING_CONFIG_FAILED
;
2423 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2426 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2428 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2429 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2432 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2437 DEFUN (no_ospf_neighbor
,
2438 no_ospf_neighbor_cmd
,
2439 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2442 "Neighbor IP address\n"
2443 "Neighbor Priority\n"
2445 "Dead Neighbor Polling interval\n"
2448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2450 struct in_addr nbr_addr
;
2452 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2453 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2454 return CMD_WARNING_CONFIG_FAILED
;
2457 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2462 DEFUN (no_ospf_neighbor_poll
,
2463 no_ospf_neighbor_poll_cmd
,
2464 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2467 "Neighbor IP address\n"
2468 "Dead Neighbor Polling interval\n"
2470 "Neighbor Priority\n"
2473 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2475 struct in_addr nbr_addr
;
2477 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2478 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2479 return CMD_WARNING_CONFIG_FAILED
;
2482 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2487 DEFUN (ospf_refresh_timer
,
2488 ospf_refresh_timer_cmd
,
2489 "refresh timer (10-1800)",
2490 "Adjust refresh parameters\n"
2491 "Set refresh timer\n"
2492 "Timer value in seconds\n")
2494 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2496 unsigned int interval
;
2498 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2499 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2500 * OSPF_LSA_REFRESHER_GRANULARITY
;
2502 ospf_timers_refresh_set(ospf
, interval
);
2507 DEFUN (no_ospf_refresh_timer
,
2508 no_ospf_refresh_timer_val_cmd
,
2509 "no refresh timer [(10-1800)]",
2511 "Adjust refresh parameters\n"
2512 "Unset refresh timer\n"
2513 "Timer value in seconds\n")
2515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2517 unsigned int interval
;
2520 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2522 if (ospf
->lsa_refresh_interval
!= interval
2523 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2527 ospf_timers_refresh_unset(ospf
);
2533 DEFUN (ospf_auto_cost_reference_bandwidth
,
2534 ospf_auto_cost_reference_bandwidth_cmd
,
2535 "auto-cost reference-bandwidth (1-4294967)",
2536 "Calculate OSPF interface cost according to bandwidth\n"
2537 "Use reference bandwidth method to assign OSPF cost\n"
2538 "The reference bandwidth in terms of Mbits per second\n")
2540 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2541 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2544 struct interface
*ifp
;
2546 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2547 if (refbw
< 1 || refbw
> 4294967) {
2548 vty_out(vty
, "reference-bandwidth value is invalid\n");
2549 return CMD_WARNING_CONFIG_FAILED
;
2552 /* If reference bandwidth is changed. */
2553 if ((refbw
) == ospf
->ref_bandwidth
)
2556 ospf
->ref_bandwidth
= refbw
;
2557 FOR_ALL_INTERFACES (vrf
, ifp
)
2558 ospf_if_recalculate_output_cost(ifp
);
2563 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2564 no_ospf_auto_cost_reference_bandwidth_cmd
,
2565 "no auto-cost reference-bandwidth [(1-4294967)]",
2567 "Calculate OSPF interface cost according to bandwidth\n"
2568 "Use reference bandwidth method to assign OSPF cost\n"
2569 "The reference bandwidth in terms of Mbits per second\n")
2571 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2572 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2573 struct interface
*ifp
;
2575 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2578 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2579 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2581 " Please ensure reference bandwidth is consistent across all routers\n");
2583 FOR_ALL_INTERFACES (vrf
, ifp
)
2584 ospf_if_recalculate_output_cost(ifp
);
2589 DEFUN (ospf_write_multiplier
,
2590 ospf_write_multiplier_cmd
,
2591 "ospf write-multiplier (1-100)",
2592 "OSPF specific commands\n"
2593 "Write multiplier\n"
2594 "Maximum number of interface serviced per write\n")
2596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2598 uint32_t write_oi_count
;
2605 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2606 if (write_oi_count
< 1 || write_oi_count
> 100) {
2607 vty_out(vty
, "write-multiplier value is invalid\n");
2608 return CMD_WARNING_CONFIG_FAILED
;
2611 ospf
->write_oi_count
= write_oi_count
;
2615 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2616 "Write multiplier\n"
2617 "Maximum number of interface serviced per write\n")
2619 DEFUN (no_ospf_write_multiplier
,
2620 no_ospf_write_multiplier_cmd
,
2621 "no ospf write-multiplier (1-100)",
2623 "OSPF specific commands\n"
2624 "Write multiplier\n"
2625 "Maximum number of interface serviced per write\n")
2627 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2629 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2633 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2634 "no write-multiplier (1-100)", NO_STR
2635 "Write multiplier\n"
2636 "Maximum number of interface serviced per write\n")
2638 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2639 "Alternative IBM", "Alternative Cisco",
2640 "Alternative Shortcut"};
2642 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2644 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2645 json_object
*json_areas
, uint8_t use_json
)
2647 json_object
*json_area
= NULL
;
2650 json_area
= json_object_new_object();
2654 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2656 /* Show Area type/mode. */
2657 if (OSPF_IS_AREA_BACKBONE(area
)) {
2659 json_object_boolean_true_add(json_area
, "backbone");
2661 vty_out(vty
, " (Backbone)\n");
2664 if (area
->external_routing
== OSPF_AREA_STUB
) {
2665 if (area
->no_summary
)
2666 json_object_boolean_true_add(
2667 json_area
, "stubNoSummary");
2668 if (area
->shortcut_configured
)
2669 json_object_boolean_true_add(
2670 json_area
, "stubShortcut");
2671 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2672 if (area
->no_summary
)
2673 json_object_boolean_true_add(
2674 json_area
, "nssaNoSummary");
2675 if (area
->shortcut_configured
)
2676 json_object_boolean_true_add(
2677 json_area
, "nssaShortcut");
2680 json_object_string_add(
2681 json_area
, "shortcuttingMode",
2682 ospf_shortcut_mode_descr_str
2683 [area
->shortcut_configured
]);
2684 if (area
->shortcut_capability
)
2685 json_object_boolean_true_add(json_area
,
2688 if (area
->external_routing
== OSPF_AREA_STUB
)
2689 vty_out(vty
, " (Stub%s%s)",
2690 area
->no_summary
? ", no summary" : "",
2691 area
->shortcut_configured
? "; " : "");
2692 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2693 vty_out(vty
, " (NSSA%s%s)",
2694 area
->no_summary
? ", no summary" : "",
2695 area
->shortcut_configured
? "; " : "");
2698 vty_out(vty
, " Shortcutting mode: %s",
2699 ospf_shortcut_mode_descr_str
2700 [area
->shortcut_configured
]);
2701 vty_out(vty
, ", S-bit consensus: %s\n",
2702 area
->shortcut_capability
? "ok" : "no");
2706 /* Show number of interfaces */
2708 json_object_int_add(json_area
, "areaIfTotalCounter",
2709 listcount(area
->oiflist
));
2710 json_object_int_add(json_area
, "areaIfActiveCounter",
2714 " Number of interfaces in this area: Total: %d, "
2716 listcount(area
->oiflist
), area
->act_ints
);
2718 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2720 json_object_boolean_true_add(json_area
, "nssa");
2721 if (!IS_OSPF_ABR(area
->ospf
))
2722 json_object_boolean_false_add(json_area
, "abr");
2723 else if (area
->NSSATranslatorState
) {
2724 json_object_boolean_true_add(json_area
, "abr");
2725 if (area
->NSSATranslatorRole
2726 == OSPF_NSSA_ROLE_CANDIDATE
)
2727 json_object_boolean_true_add(
2729 "nssaTranslatorElected");
2730 else if (area
->NSSATranslatorRole
2731 == OSPF_NSSA_ROLE_ALWAYS
)
2732 json_object_boolean_true_add(
2734 "nssaTranslatorAlways");
2736 json_object_boolean_true_add(json_area
, "abr");
2737 if (area
->NSSATranslatorRole
2738 == OSPF_NSSA_ROLE_CANDIDATE
)
2739 json_object_boolean_false_add(
2741 "nssaTranslatorElected");
2743 json_object_boolean_true_add(
2745 "nssaTranslatorNever");
2749 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2750 if (!IS_OSPF_ABR(area
->ospf
))
2752 " It is not ABR, therefore not Translator. \n");
2753 else if (area
->NSSATranslatorState
) {
2754 vty_out(vty
, " We are an ABR and ");
2755 if (area
->NSSATranslatorRole
2756 == OSPF_NSSA_ROLE_CANDIDATE
)
2758 "the NSSA Elected Translator. \n");
2759 else if (area
->NSSATranslatorRole
2760 == OSPF_NSSA_ROLE_ALWAYS
)
2762 "always an NSSA Translator. \n");
2764 vty_out(vty
, " We are an ABR, but ");
2765 if (area
->NSSATranslatorRole
2766 == OSPF_NSSA_ROLE_CANDIDATE
)
2768 "not the NSSA Elected Translator. \n");
2771 "never an NSSA Translator. \n");
2776 /* Stub-router state for this area */
2777 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2778 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2781 json_object_boolean_true_add(
2782 json_area
, "originStubMaxDistRouterLsa");
2783 if (CHECK_FLAG(area
->stub_router_state
,
2784 OSPF_AREA_ADMIN_STUB_ROUTED
))
2785 json_object_boolean_true_add(
2786 json_area
, "indefiniteActiveAdmin");
2787 if (area
->t_stub_router
) {
2791 &area
->t_stub_router
->u
.sands
,
2794 json_object_int_add(
2796 "activeStartupRemainderMsecs",
2801 " Originating stub / maximum-distance Router-LSA\n");
2802 if (CHECK_FLAG(area
->stub_router_state
,
2803 OSPF_AREA_ADMIN_STUB_ROUTED
))
2805 " Administratively activated (indefinitely)\n");
2806 if (area
->t_stub_router
)
2808 " Active from startup, %s remaining\n",
2809 ospf_timer_dump(area
->t_stub_router
,
2816 /* Show number of fully adjacent neighbors. */
2817 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2820 /* Show authentication type. */
2821 if (area
->auth_type
== OSPF_AUTH_NULL
)
2822 json_object_string_add(json_area
, "authentication",
2823 "authenticationNone");
2824 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2825 json_object_string_add(json_area
, "authentication",
2826 "authenticationSimplePassword");
2827 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2828 json_object_string_add(json_area
, "authentication",
2829 "authenticationMessageDigest");
2831 if (!OSPF_IS_AREA_BACKBONE(area
))
2832 json_object_int_add(json_area
,
2833 "virtualAdjacenciesPassingCounter",
2836 /* Show SPF calculation times. */
2837 json_object_int_add(json_area
, "spfExecutedCounter",
2838 area
->spf_calculation
);
2839 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2840 json_object_int_add(
2841 json_area
, "lsaRouterNumber",
2842 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaRouterChecksum",
2845 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaNetworkNumber",
2848 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2849 json_object_int_add(
2850 json_area
, "lsaNetworkChecksum",
2851 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2852 json_object_int_add(
2853 json_area
, "lsaSummaryNumber",
2854 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2855 json_object_int_add(
2856 json_area
, "lsaSummaryChecksum",
2857 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2858 json_object_int_add(
2859 json_area
, "lsaAsbrNumber",
2860 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2861 json_object_int_add(
2862 json_area
, "lsaAsbrChecksum",
2863 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2864 json_object_int_add(
2865 json_area
, "lsaNssaNumber",
2866 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2867 json_object_int_add(
2868 json_area
, "lsaNssaChecksum",
2869 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2871 /* Show number of fully adjacent neighbors. */
2873 " Number of fully adjacent neighbors in this area:"
2877 /* Show authentication type. */
2878 vty_out(vty
, " Area has ");
2879 if (area
->auth_type
== OSPF_AUTH_NULL
)
2880 vty_out(vty
, "no authentication\n");
2881 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2882 vty_out(vty
, "simple password authentication\n");
2883 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2884 vty_out(vty
, "message digest authentication\n");
2886 if (!OSPF_IS_AREA_BACKBONE(area
))
2888 " Number of full virtual adjacencies going through"
2892 /* Show SPF calculation times. */
2893 vty_out(vty
, " SPF algorithm executed %d times\n",
2894 area
->spf_calculation
);
2896 /* Show number of LSA. */
2897 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2899 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2900 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2901 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2903 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2904 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2905 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2907 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2908 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2909 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2911 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2912 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2913 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2914 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2915 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2916 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2920 json_object_int_add(
2921 json_area
, "lsaOpaqueLinkNumber",
2922 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2923 json_object_int_add(
2924 json_area
, "lsaOpaqueLinkChecksum",
2925 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2926 json_object_int_add(
2927 json_area
, "lsaOpaqueAreaNumber",
2928 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2929 json_object_int_add(
2930 json_area
, "lsaOpaqueAreaChecksum",
2931 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2934 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2935 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2936 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2938 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2939 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2940 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2944 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2950 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2951 json_object
*json
, uint8_t use_vrf
)
2953 struct listnode
*node
, *nnode
;
2954 struct ospf_area
*area
;
2955 struct timeval result
;
2956 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2957 json_object
*json_vrf
= NULL
;
2958 json_object
*json_areas
= NULL
;
2962 json_vrf
= json_object_new_object();
2965 json_areas
= json_object_new_object();
2968 if (ospf
->instance
) {
2970 json_object_int_add(json
, "ospfInstance",
2973 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2977 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2979 /* Show Router ID. */
2981 json_object_string_add(json_vrf
, "routerId",
2982 inet_ntoa(ospf
->router_id
));
2984 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2985 inet_ntoa(ospf
->router_id
));
2988 /* Graceful shutdown */
2989 if (ospf
->t_deferred_shutdown
) {
2994 &ospf
->t_deferred_shutdown
->u
.sands
,
2997 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3001 " Deferred shutdown in progress, %s remaining\n",
3002 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3003 timebuf
, sizeof(timebuf
)));
3007 /* Show capability. */
3009 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3010 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3011 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3012 json_object_boolean_true_add(json_vrf
,
3013 "rfc1583Compatibility");
3016 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3017 vty_out(vty
, " This implementation conforms to RFC2328\n");
3018 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3019 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3025 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3026 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3029 vty_out(vty
, " OpaqueCapability flag is %s\n",
3030 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3035 /* Show stub-router configuration */
3036 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3037 || ospf
->stub_router_shutdown_time
3038 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3040 json_object_boolean_true_add(json_vrf
,
3041 "stubAdvertisement");
3042 if (ospf
->stub_router_startup_time
3043 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3044 json_object_int_add(
3045 json_vrf
, "postStartEnabledMsecs",
3046 ospf
->stub_router_startup_time
/ 1000);
3047 if (ospf
->stub_router_shutdown_time
3048 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3049 json_object_int_add(
3050 json_vrf
, "preShutdownEnabledMsecs",
3051 ospf
->stub_router_shutdown_time
/ 1000);
3054 " Stub router advertisement is configured\n");
3055 if (ospf
->stub_router_startup_time
3056 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3058 " Enabled for %us after start-up\n",
3059 ospf
->stub_router_startup_time
);
3060 if (ospf
->stub_router_shutdown_time
3061 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3063 " Enabled for %us prior to full shutdown\n",
3064 ospf
->stub_router_shutdown_time
);
3068 /* Show SPF timers. */
3070 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3072 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3073 ospf
->spf_holdtime
);
3074 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3075 ospf
->spf_max_holdtime
);
3076 json_object_int_add(json_vrf
, "holdtimeMultplier",
3077 ospf
->spf_hold_multiplier
);
3080 " Initial SPF scheduling delay %d millisec(s)\n"
3081 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3082 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3083 " Hold time multiplier is currently %d\n",
3084 ospf
->spf_delay
, ospf
->spf_holdtime
,
3085 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3089 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3090 long time_store
= 0;
3093 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3094 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3097 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3098 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3099 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3102 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3104 vty_out(vty
, " SPF algorithm ");
3105 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3106 monotime_since(&ospf
->ts_spf
, &result
);
3107 vty_out(vty
, "last executed %s ago\n",
3108 ospf_timeval_dump(&result
, timebuf
,
3110 vty_out(vty
, " Last SPF duration %s\n",
3111 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3112 timebuf
, sizeof(timebuf
)));
3114 vty_out(vty
, "has not been run\n");
3118 if (ospf
->t_spf_calc
) {
3121 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3123 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3127 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3128 ospf
->min_ls_interval
);
3129 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3130 ospf
->min_ls_arrival
);
3131 /* Show write multiplier values */
3132 json_object_int_add(json_vrf
, "writeMultiplier",
3133 ospf
->write_oi_count
);
3134 /* Show refresh parameters. */
3135 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3136 ospf
->lsa_refresh_interval
* 1000);
3138 vty_out(vty
, " SPF timer %s%s\n",
3139 (ospf
->t_spf_calc
? "due in " : "is "),
3140 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3143 vty_out(vty
, " LSA minimum interval %d msecs\n",
3144 ospf
->min_ls_interval
);
3145 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3146 ospf
->min_ls_arrival
);
3148 /* Show write multiplier values */
3149 vty_out(vty
, " Write Multiplier set to %d \n",
3150 ospf
->write_oi_count
);
3152 /* Show refresh parameters. */
3153 vty_out(vty
, " Refresh timer %d secs\n",
3154 ospf
->lsa_refresh_interval
);
3157 /* Show ABR/ASBR flags. */
3158 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3160 json_object_string_add(
3161 json_vrf
, "abrType",
3162 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3165 " This router is an ABR, ABR type is: %s\n",
3166 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3168 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3170 json_object_string_add(
3171 json_vrf
, "asbrRouter",
3172 "injectingExternalRoutingInformation");
3175 " This router is an ASBR "
3176 "(injecting external routing information)\n");
3179 /* Show Number of AS-external-LSAs. */
3181 json_object_int_add(
3182 json_vrf
, "lsaExternalCounter",
3183 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3184 json_object_int_add(
3185 json_vrf
, "lsaExternalChecksum",
3186 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3189 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3190 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3191 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3195 json_object_int_add(
3196 json_vrf
, "lsaAsopaqueCounter",
3197 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3198 json_object_int_add(
3199 json_vrf
, "lsaAsOpaqueChecksum",
3200 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3203 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3204 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3205 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3208 /* Show number of areas attached. */
3210 json_object_int_add(json_vrf
, "attachedAreaCounter",
3211 listcount(ospf
->areas
));
3213 vty_out(vty
, " Number of areas attached to this router: %d\n",
3214 listcount(ospf
->areas
));
3216 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3217 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3219 json_object_boolean_true_add(
3220 json_vrf
, "adjacencyChangesLoggedAll");
3223 " All adjacency changes are logged\n");
3226 json_object_boolean_true_add(
3227 json_vrf
, "adjacencyChangesLogged");
3229 vty_out(vty
, " Adjacency changes are logged\n");
3232 /* Show each area status. */
3233 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3234 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3238 json_object_object_add(json_vrf
, "areas", json_areas
);
3239 if (ospf
->vrf_id
== VRF_DEFAULT
)
3240 json_object_object_add(json
, "default",
3243 json_object_object_add(json
, ospf
->name
,
3246 json_object_object_add(json
, "areas", json_areas
);
3254 DEFUN (show_ip_ospf
,
3256 "show ip ospf [vrf <NAME|all>] [json]",
3259 "OSPF information\n"
3265 uint8_t uj
= use_json(argc
, argv
);
3266 struct listnode
*node
= NULL
;
3267 char *vrf_name
= NULL
;
3268 bool all_vrf
= FALSE
;
3269 int ret
= CMD_SUCCESS
;
3272 json_object
*json
= NULL
;
3273 uint8_t use_vrf
= 0;
3275 if (listcount(om
->ospf
) == 0)
3278 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3281 json
= json_object_new_object();
3283 /* vrf input is provided could be all or specific vrf*/
3287 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3288 if (!ospf
->oi_running
)
3290 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3294 vty_out(vty
, "%s\n",
3295 json_object_to_json_string_ext(
3296 json
, JSON_C_TO_STRING_PRETTY
));
3297 json_object_free(json
);
3301 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3302 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3304 json_object_free(json
);
3308 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3309 /* Display default ospf (instance 0) info */
3310 if (ospf
== NULL
|| !ospf
->oi_running
) {
3312 json_object_free(json
);
3318 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3320 vty_out(vty
, "%s\n",
3321 json_object_to_json_string_ext(
3322 json
, JSON_C_TO_STRING_PRETTY
));
3326 json_object_free(json
);
3331 DEFUN (show_ip_ospf_instance
,
3332 show_ip_ospf_instance_cmd
,
3333 "show ip ospf (1-65535) [json]",
3336 "OSPF information\n"
3342 unsigned short instance
= 0;
3343 uint8_t uj
= use_json(argc
, argv
);
3344 int ret
= CMD_SUCCESS
;
3345 json_object
*json
= NULL
;
3347 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3348 ospf
= ospf_lookup_instance(instance
);
3350 return CMD_NOT_MY_INSTANCE
;
3352 if (!ospf
->oi_running
)
3356 json
= json_object_new_object();
3358 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3361 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3362 json
, JSON_C_TO_STRING_PRETTY
));
3363 json_object_free(json
);
3369 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3370 struct interface
*ifp
,
3371 json_object
*json_interface_sub
,
3375 struct ospf_neighbor
*nbr
;
3376 struct route_node
*rn
;
3377 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3379 /* Is interface up? */
3381 is_up
= if_is_operative(ifp
);
3383 json_object_boolean_true_add(json_interface_sub
,
3386 json_object_boolean_false_add(json_interface_sub
,
3389 json_object_int_add(json_interface_sub
, "ifIndex",
3391 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3392 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3394 json_object_string_add(json_interface_sub
, "ifFlags",
3395 if_flag_dump(ifp
->flags
));
3397 vty_out(vty
, "%s is %s\n", ifp
->name
,
3398 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3399 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3400 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3401 if_flag_dump(ifp
->flags
));
3404 /* Is interface OSPF enabled? */
3406 if (ospf_oi_count(ifp
) == 0) {
3407 json_object_boolean_false_add(json_interface_sub
,
3410 } else if (!is_up
) {
3411 json_object_boolean_false_add(json_interface_sub
,
3415 json_object_boolean_true_add(json_interface_sub
,
3418 if (ospf_oi_count(ifp
) == 0) {
3419 vty_out(vty
, " OSPF not enabled on this interface\n");
3421 } else if (!is_up
) {
3423 " OSPF is enabled, but not running on this interface\n");
3428 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3429 struct ospf_interface
*oi
= rn
->info
;
3434 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3436 json_object_boolean_true_add(json_interface_sub
,
3439 vty_out(vty
, " This interface is UNNUMBERED,");
3441 /* Show OSPF interface information. */
3443 json_object_string_add(
3444 json_interface_sub
, "ipAddress",
3445 inet_ntoa(oi
->address
->u
.prefix4
));
3446 json_object_int_add(json_interface_sub
,
3447 "ipAddressPrefixlen",
3448 oi
->address
->prefixlen
);
3450 vty_out(vty
, " Internet Address %s/%d,",
3451 inet_ntoa(oi
->address
->u
.prefix4
),
3452 oi
->address
->prefixlen
);
3454 if (oi
->connected
->destination
3455 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3456 struct in_addr
*dest
;
3459 if (CONNECTED_PEER(oi
->connected
)
3460 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3465 /* For Vlinks, showing the peer address is
3467 * * * * * informative than the local
3468 * interface that is being used
3470 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3471 dest
= &oi
->vl_data
->peer_addr
;
3473 dest
= &oi
->connected
->destination
->u
3477 json_object_string_add(
3479 "ospfIfType", dstr
);
3480 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3481 json_object_string_add(
3486 json_object_string_add(
3491 vty_out(vty
, " %s %s,", dstr
,
3496 json_object_string_add(json_interface_sub
, "area",
3497 ospf_area_desc_string(oi
->area
));
3498 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3499 json_object_boolean_true_add(
3501 "mtuMismatchDetect");
3502 json_object_string_add(json_interface_sub
, "routerId",
3503 inet_ntoa(ospf
->router_id
));
3504 json_object_string_add(json_interface_sub
,
3506 ospf_network_type_str
[oi
->type
]);
3507 json_object_int_add(json_interface_sub
, "cost",
3509 json_object_int_add(
3510 json_interface_sub
, "transmitDelayMsecs",
3511 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3512 json_object_string_add(json_interface_sub
, "state",
3513 lookup_msg(ospf_ism_state_msg
,
3515 json_object_int_add(json_interface_sub
, "priority",
3518 vty_out(vty
, " Area %s\n",
3519 ospf_area_desc_string(oi
->area
));
3521 vty_out(vty
, " MTU mismatch detection: %s\n",
3522 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3526 " Router ID %s, Network Type %s, Cost: %d\n",
3527 inet_ntoa(ospf
->router_id
),
3528 ospf_network_type_str
[oi
->type
],
3532 " Transmit Delay is %d sec, State %s, Priority %d\n",
3533 OSPF_IF_PARAM(oi
, transmit_delay
),
3534 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3538 /* Show DR information. */
3539 if (DR(oi
).s_addr
== 0) {
3542 " No backup designated router on this network\n");
3544 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3548 " No backup designated router on this network\n");
3551 json_object_string_add(
3552 json_interface_sub
, "bdrId",
3553 inet_ntoa(nbr
->router_id
));
3554 json_object_string_add(
3557 inet_ntoa(nbr
->address
.u
3561 " Backup Designated Router (ID) %s,",
3562 inet_ntoa(nbr
->router_id
));
3563 vty_out(vty
, " Interface Address %s\n",
3564 inet_ntoa(nbr
->address
.u
3570 /* Next network-LSA sequence number we'll use, if we're elected
3573 && ntohl(oi
->params
->network_lsa_seqnum
)
3574 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3576 json_object_int_add(
3578 "networkLsaSequence",
3579 ntohl(oi
->params
->network_lsa_seqnum
));
3582 " Saved Network-LSA sequence number 0x%x\n",
3583 ntohl(oi
->params
->network_lsa_seqnum
));
3587 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3588 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3589 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3590 json_object_boolean_true_add(
3592 "mcastMemberOspfAllRouters");
3593 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3594 json_object_boolean_true_add(
3596 "mcastMemberOspfDesignatedRouters");
3599 vty_out(vty
, " Multicast group memberships:");
3600 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3601 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3602 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3603 vty_out(vty
, " OSPFAllRouters");
3604 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3605 vty_out(vty
, " OSPFDesignatedRouters");
3607 vty_out(vty
, " <None>");
3612 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3613 json_object_int_add(
3614 json_interface_sub
, "timerMsecs",
3615 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3617 json_object_int_add(
3618 json_interface_sub
, "timerMsecs",
3619 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3620 json_object_int_add(json_interface_sub
,
3622 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3623 json_object_int_add(json_interface_sub
,
3625 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3626 json_object_int_add(
3627 json_interface_sub
, "timerRetransmit",
3628 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3630 vty_out(vty
, " Timer intervals configured,");
3631 vty_out(vty
, " Hello ");
3632 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3633 vty_out(vty
, "%ds,",
3634 OSPF_IF_PARAM(oi
, v_hello
));
3636 vty_out(vty
, "%dms,",
3637 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3638 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3639 OSPF_IF_PARAM(oi
, v_wait
),
3640 OSPF_IF_PARAM(oi
, v_wait
),
3641 OSPF_IF_PARAM(oi
, retransmit_interval
));
3644 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3645 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3647 long time_store
= 0;
3651 &oi
->t_hello
->u
.sands
,
3654 json_object_int_add(json_interface_sub
,
3655 "timerHelloInMsecs",
3658 vty_out(vty
, " Hello due in %s\n",
3659 ospf_timer_dump(oi
->t_hello
, timebuf
,
3661 } else /* passive-interface is set */
3664 json_object_boolean_true_add(
3666 "timerPassiveIface");
3669 " No Hellos (Passive interface)\n");
3673 json_object_int_add(json_interface_sub
, "nbrCount",
3674 ospf_nbr_count(oi
, 0));
3675 json_object_int_add(json_interface_sub
,
3677 ospf_nbr_count(oi
, NSM_Full
));
3680 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3681 ospf_nbr_count(oi
, 0),
3682 ospf_nbr_count(oi
, NSM_Full
));
3683 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3687 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3688 char *intf_name
, uint8_t use_vrf
,
3689 json_object
*json
, uint8_t use_json
)
3691 struct interface
*ifp
;
3692 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3693 json_object
*json_vrf
= NULL
;
3694 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3698 json_vrf
= json_object_new_object();
3701 json_interface
= json_object_new_object();
3704 if (ospf
->instance
) {
3706 json_object_int_add(json
, "ospfInstance",
3709 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3712 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3714 if (intf_name
== NULL
) {
3715 /* Show All Interfaces.*/
3716 FOR_ALL_INTERFACES (vrf
, ifp
) {
3717 if (ospf_oi_count(ifp
)) {
3719 json_interface_sub
=
3720 json_object_new_object();
3722 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3727 json_object_object_add(
3728 json_interface
, ifp
->name
,
3729 json_interface_sub
);
3734 json_object_object_add(json_vrf
, "interfaces",
3737 /* Interface name is specified. */
3738 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3741 json_object_boolean_true_add(json_vrf
,
3744 vty_out(vty
, "No such interface name\n");
3747 json_interface_sub
= json_object_new_object();
3748 json_interface
= json_object_new_object();
3751 show_ip_ospf_interface_sub(
3752 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3755 json_object_object_add(json_interface
,
3757 json_interface_sub
);
3758 json_object_object_add(json_vrf
, "interfaces",
3766 if (ospf
->vrf_id
== VRF_DEFAULT
)
3767 json_object_object_add(json
, "default",
3770 json_object_object_add(json
, ospf
->name
,
3779 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3780 struct ospf_interface
*oi
,
3781 json_object
*json_interface_sub
,
3785 json_object_int_add(json_interface_sub
, "ifIndex",
3787 json_object_int_add(json_interface_sub
, "helloIn",
3789 json_object_int_add(json_interface_sub
, "helloOut",
3791 json_object_int_add(json_interface_sub
, "dbDescIn",
3793 json_object_int_add(json_interface_sub
, "dbDescOut",
3795 json_object_int_add(json_interface_sub
, "lsReqIn",
3797 json_object_int_add(json_interface_sub
, "lsReqOut",
3799 json_object_int_add(json_interface_sub
, "lsUpdIn",
3801 json_object_int_add(json_interface_sub
, "lsUpdOut",
3803 json_object_int_add(json_interface_sub
, "lsAckIn",
3805 json_object_int_add(json_interface_sub
, "lsAckOut",
3809 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3810 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3811 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3812 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3813 oi
->ls_ack_in
, oi
->ls_ack_out
);
3817 /* OSPFv2 Packet Counters */
3818 static int show_ip_ospf_interface_traffic_common(
3819 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3820 int display_once
, uint8_t use_vrf
, uint8_t use_json
)
3822 struct vrf
*vrf
= NULL
;
3823 struct interface
*ifp
= NULL
;
3824 json_object
*json_vrf
= NULL
;
3825 json_object
*json_interface_sub
= NULL
;
3827 if (!use_json
&& !display_once
) {
3829 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3830 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3832 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3833 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3836 "--------------------------------------------------------------------------------------------\n");
3837 } else if (use_json
) {
3839 json_vrf
= json_object_new_object();
3844 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3846 if (intf_name
== NULL
) {
3847 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3848 FOR_ALL_INTERFACES (vrf
, ifp
) {
3849 struct route_node
*rn
;
3850 struct ospf_interface
*oi
;
3852 if (ospf_oi_count(ifp
) == 0)
3855 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3856 rn
= route_next(rn
)) {
3863 json_interface_sub
=
3864 json_object_new_object();
3867 show_ip_ospf_interface_traffic_sub(
3868 vty
, oi
, json_interface_sub
, use_json
);
3870 json_object_object_add(
3871 json_vrf
, ifp
->name
,
3872 json_interface_sub
);
3877 /* Interface name is specified. */
3878 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3880 struct route_node
*rn
;
3881 struct ospf_interface
*oi
;
3883 if (ospf_oi_count(ifp
) == 0) {
3885 " OSPF not enabled on this interface %s\n",
3890 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3891 rn
= route_next(rn
)) {
3895 json_interface_sub
=
3896 json_object_new_object();
3899 show_ip_ospf_interface_traffic_sub(
3900 vty
, oi
, json_interface_sub
, use_json
);
3902 json_object_object_add(
3903 json_vrf
, ifp
->name
,
3904 json_interface_sub
);
3912 if (ospf
->vrf_id
== VRF_DEFAULT
)
3913 json_object_object_add(json
, "default",
3916 json_object_object_add(json
, ospf
->name
,
3925 DEFUN (show_ip_ospf_interface
,
3926 show_ip_ospf_interface_cmd
,
3927 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3930 "OSPF information\n"
3933 "Interface information\n"
3938 uint8_t uj
= use_json(argc
, argv
);
3939 struct listnode
*node
= NULL
;
3940 char *vrf_name
= NULL
, *intf_name
= NULL
;
3941 bool all_vrf
= FALSE
;
3942 int ret
= CMD_SUCCESS
;
3944 int idx_vrf
= 0, idx_intf
= 0;
3945 uint8_t use_vrf
= 0;
3946 json_object
*json
= NULL
;
3948 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3950 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3951 intf_name
= argv
[idx_intf
]->arg
;
3954 json
= json_object_new_object();
3956 /* vrf input is provided could be all or specific vrf*/
3960 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3961 if (!ospf
->oi_running
)
3963 ret
= show_ip_ospf_interface_common(
3964 vty
, ospf
, intf_name
, use_vrf
, json
,
3969 vty_out(vty
, "%s\n",
3970 json_object_to_json_string_ext(
3971 json
, JSON_C_TO_STRING_PRETTY
));
3972 json_object_free(json
);
3977 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3978 if (ospf
== NULL
|| !ospf
->oi_running
) {
3980 json_object_free(json
);
3983 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3987 /* Display default ospf (instance 0) info */
3988 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3989 if (ospf
== NULL
|| !ospf
->oi_running
) {
3991 json_object_free(json
);
3994 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3999 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4000 json
, JSON_C_TO_STRING_PRETTY
));
4001 json_object_free(json
);
4007 DEFUN (show_ip_ospf_instance_interface
,
4008 show_ip_ospf_instance_interface_cmd
,
4009 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4012 "OSPF information\n"
4014 "Interface information\n"
4021 unsigned short instance
= 0;
4022 uint8_t uj
= use_json(argc
, argv
);
4023 char *intf_name
= NULL
;
4024 int ret
= CMD_SUCCESS
;
4025 json_object
*json
= NULL
;
4027 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4028 ospf
= ospf_lookup_instance(instance
);
4030 return CMD_NOT_MY_INSTANCE
;
4032 if (!ospf
->oi_running
)
4036 json
= json_object_new_object();
4038 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4039 intf_name
= argv
[idx_intf
]->arg
;
4041 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4044 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4045 json
, JSON_C_TO_STRING_PRETTY
));
4046 json_object_free(json
);
4052 DEFUN (show_ip_ospf_interface_traffic
,
4053 show_ip_ospf_interface_traffic_cmd
,
4054 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4057 "OSPF information\n"
4060 "Interface information\n"
4061 "Protocol Packet counters\n"
4065 struct ospf
*ospf
= NULL
;
4066 struct listnode
*node
= NULL
;
4067 char *vrf_name
= NULL
, *intf_name
= NULL
;
4068 bool all_vrf
= FALSE
;
4070 int idx_vrf
= 0, idx_intf
= 0;
4071 uint8_t uj
= use_json(argc
, argv
);
4072 json_object
*json
= NULL
;
4073 int ret
= CMD_SUCCESS
;
4074 int display_once
= 0;
4075 uint8_t use_vrf
= 0;
4077 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4079 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4080 intf_name
= argv
[idx_intf
]->arg
;
4083 json
= json_object_new_object();
4088 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4089 if (!ospf
->oi_running
)
4092 ret
= show_ip_ospf_interface_traffic_common(
4093 vty
, ospf
, intf_name
, json
,
4094 display_once
, use_vrf
, uj
);
4099 vty_out(vty
, "%s\n",
4100 json_object_to_json_string_ext(
4101 json
, JSON_C_TO_STRING_PRETTY
));
4102 json_object_free(json
);
4107 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4108 if (ospf
== NULL
|| !ospf
->oi_running
) {
4110 json_object_free(json
);
4114 ret
= show_ip_ospf_interface_traffic_common(
4115 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4117 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4118 if (ospf
== NULL
|| !ospf
->oi_running
) {
4120 json_object_free(json
);
4124 ret
= show_ip_ospf_interface_traffic_common(
4125 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4129 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4130 json
, JSON_C_TO_STRING_PRETTY
));
4131 json_object_free(json
);
4138 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4140 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4141 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4142 "Interface", "RXmtL", "RqstL", "DBsmL");
4145 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4146 struct ospf_interface
*oi
,
4147 json_object
*json
, uint8_t use_json
)
4149 struct route_node
*rn
;
4150 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4152 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4153 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4155 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4156 if ((nbr
= rn
->info
)) {
4157 /* Do not show myself. */
4158 if (nbr
== oi
->nbr_self
)
4160 /* Down state is not shown. */
4161 if (nbr
->state
== NSM_Down
)
4164 char neigh_str
[INET_ADDRSTRLEN
];
4167 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4169 /* Start new neigh list */
4170 json_neigh_array
= NULL
;
4173 if (nbr
->state
== NSM_Attempt
4174 && nbr
->router_id
.s_addr
== 0)
4175 strlcpy(neigh_str
, "neighbor",
4179 inet_ntoa(nbr
->router_id
),
4182 json_object_object_get_ex(json
, neigh_str
,
4185 if (!json_neigh_array
) {
4187 json_object_new_array();
4188 json_object_object_add(
4193 json_neighbor
= json_object_new_object();
4195 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4201 &nbr
->t_inactivity
->u
.sands
,
4205 json_object_int_add(json_neighbor
, "priority",
4207 json_object_string_add(json_neighbor
, "state",
4209 json_object_int_add(json_neighbor
,
4212 json_object_string_add(json_neighbor
, "address",
4213 inet_ntoa(nbr
->src
));
4214 json_object_string_add(json_neighbor
,
4217 json_object_int_add(
4218 json_neighbor
, "retransmitCounter",
4219 ospf_ls_retransmit_count(nbr
));
4220 json_object_int_add(json_neighbor
,
4222 ospf_ls_request_count(nbr
));
4223 json_object_int_add(json_neighbor
,
4225 ospf_db_summary_count(nbr
));
4227 json_object_array_add(json_neigh_array
,
4230 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4232 if (nbr
->state
== NSM_Attempt
4233 && nbr
->router_id
.s_addr
== 0)
4234 vty_out(vty
, "%-15s %3d %-15s ", "-",
4235 nbr
->priority
, msgbuf
);
4237 vty_out(vty
, "%-15s %3d %-15s ",
4238 inet_ntoa(nbr
->router_id
),
4239 nbr
->priority
, msgbuf
);
4241 vty_out(vty
, "%9s ",
4242 ospf_timer_dump(nbr
->t_inactivity
,
4245 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4246 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4248 ospf_ls_retransmit_count(nbr
),
4249 ospf_ls_request_count(nbr
),
4250 ospf_db_summary_count(nbr
));
4257 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4258 json_object
*json
, uint8_t use_json
,
4261 struct ospf_interface
*oi
;
4262 struct listnode
*node
;
4263 json_object
*json_vrf
= NULL
;
4264 json_object
*json_nbr_sub
= NULL
;
4268 json_vrf
= json_object_new_object();
4271 json_nbr_sub
= json_object_new_object();
4274 if (ospf
->instance
) {
4276 json_object_int_add(json
, "ospfInstance",
4279 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4282 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4284 show_ip_ospf_neighbour_header(vty
);
4286 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4287 if (ospf_interface_neighbor_count(oi
) == 0)
4289 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4293 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4295 if (ospf
->vrf_id
== VRF_DEFAULT
)
4296 json_object_object_add(json
, "default",
4299 json_object_object_add(json
, ospf
->name
,
4308 DEFUN (show_ip_ospf_neighbor
,
4309 show_ip_ospf_neighbor_cmd
,
4310 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4313 "OSPF information\n"
4320 uint8_t uj
= use_json(argc
, argv
);
4321 struct listnode
*node
= NULL
;
4322 char *vrf_name
= NULL
;
4323 bool all_vrf
= FALSE
;
4324 int ret
= CMD_SUCCESS
;
4327 uint8_t use_vrf
= 0;
4328 json_object
*json
= NULL
;
4330 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4333 json
= json_object_new_object();
4335 /* vrf input is provided could be all or specific vrf*/
4339 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4340 if (!ospf
->oi_running
)
4342 ret
= show_ip_ospf_neighbor_common(
4343 vty
, ospf
, json
, uj
, use_vrf
);
4347 vty_out(vty
, "%s\n",
4348 json_object_to_json_string_ext(
4349 json
, JSON_C_TO_STRING_PRETTY
));
4350 json_object_free(json
);
4356 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4357 if (ospf
== NULL
|| !ospf
->oi_running
) {
4359 json_object_free(json
);
4363 /* Display default ospf (instance 0) info */
4364 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4365 if (ospf
== NULL
|| !ospf
->oi_running
) {
4367 json_object_free(json
);
4373 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4377 vty_out(vty
, "%s\n",
4378 json_object_to_json_string_ext(
4379 json
, JSON_C_TO_STRING_PRETTY
));
4384 json_object_free(json
);
4390 DEFUN (show_ip_ospf_instance_neighbor
,
4391 show_ip_ospf_instance_neighbor_cmd
,
4392 "show ip ospf (1-65535) neighbor [json]",
4395 "OSPF information\n"
4402 unsigned short instance
= 0;
4403 uint8_t uj
= use_json(argc
, argv
);
4404 json_object
*json
= NULL
;
4405 int ret
= CMD_SUCCESS
;
4407 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4408 ospf
= ospf_lookup_instance(instance
);
4410 return CMD_NOT_MY_INSTANCE
;
4412 if (!ospf
->oi_running
)
4416 json
= json_object_new_object();
4418 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4421 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4422 json
, JSON_C_TO_STRING_PRETTY
));
4423 json_object_free(json
);
4429 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4430 json_object
*json
, uint8_t use_json
,
4433 struct listnode
*node
;
4434 struct ospf_interface
*oi
;
4435 json_object
*json_vrf
= NULL
;
4436 json_object
*json_neighbor_sub
= NULL
;
4440 json_vrf
= json_object_new_object();
4443 json_neighbor_sub
= json_object_new_object();
4446 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4448 show_ip_ospf_neighbour_header(vty
);
4450 if (ospf
->instance
) {
4452 json_object_int_add(json_vrf
, "ospfInstance",
4455 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4458 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4459 struct listnode
*nbr_node
;
4460 struct ospf_nbr_nbma
*nbr_nbma
;
4462 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4464 /* print Down neighbor status */
4465 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4466 if (nbr_nbma
->nbr
== NULL
4467 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4469 json_object_int_add(json_neighbor_sub
,
4471 nbr_nbma
->priority
);
4472 json_object_boolean_true_add(
4475 json_object_string_add(
4479 json_object_int_add(
4481 "nbrNbmaRetransmitCounter", 0);
4482 json_object_int_add(
4484 "nbrNbmaRequestCounter", 0);
4485 json_object_int_add(
4487 "nbrNbmaDbSummaryCounter", 0);
4488 json_object_object_add(
4490 inet_ntoa(nbr_nbma
->addr
),
4493 vty_out(vty
, "%-15s %3d %-15s %9s ",
4494 "-", nbr_nbma
->priority
, "Down",
4497 "%-15s %-20s %5d %5d %5d\n",
4498 inet_ntoa(nbr_nbma
->addr
),
4499 IF_NAME(oi
), 0, 0, 0);
4507 if (ospf
->vrf_id
== VRF_DEFAULT
)
4508 json_object_object_add(json
, "default",
4511 json_object_object_add(json
, ospf
->name
,
4520 DEFUN (show_ip_ospf_neighbor_all
,
4521 show_ip_ospf_neighbor_all_cmd
,
4522 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4525 "OSPF information\n"
4529 "include down status neighbor\n"
4533 uint8_t uj
= use_json(argc
, argv
);
4534 struct listnode
*node
= NULL
;
4535 char *vrf_name
= NULL
;
4536 bool all_vrf
= FALSE
;
4537 int ret
= CMD_SUCCESS
;
4540 uint8_t use_vrf
= 0;
4541 json_object
*json
= NULL
;
4543 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4546 json
= json_object_new_object();
4548 /* vrf input is provided could be all or specific vrf*/
4552 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4553 if (!ospf
->oi_running
)
4555 ret
= show_ip_ospf_neighbor_all_common(
4556 vty
, ospf
, json
, uj
, use_vrf
);
4560 vty_out(vty
, "%s\n",
4561 json_object_to_json_string_ext(
4562 json
, JSON_C_TO_STRING_PRETTY
));
4563 json_object_free(json
);
4569 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4570 if (ospf
== NULL
|| !ospf
->oi_running
) {
4572 json_object_free(json
);
4576 /* Display default ospf (instance 0) info */
4577 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4578 if (ospf
== NULL
|| !ospf
->oi_running
) {
4580 json_object_free(json
);
4586 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4589 vty_out(vty
, "%s\n",
4590 json_object_to_json_string_ext(
4591 json
, JSON_C_TO_STRING_PRETTY
));
4596 json_object_free(json
);
4601 DEFUN (show_ip_ospf_instance_neighbor_all
,
4602 show_ip_ospf_instance_neighbor_all_cmd
,
4603 "show ip ospf (1-65535) neighbor all [json]",
4606 "OSPF information\n"
4609 "include down status neighbor\n"
4614 unsigned short instance
= 0;
4615 uint8_t uj
= use_json(argc
, argv
);
4616 json_object
*json
= NULL
;
4617 int ret
= CMD_SUCCESS
;
4619 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4620 ospf
= ospf_lookup_instance(instance
);
4622 return CMD_NOT_MY_INSTANCE
;
4624 if (!ospf
->oi_running
)
4627 json
= json_object_new_object();
4629 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4632 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4633 json
, JSON_C_TO_STRING_PRETTY
));
4634 json_object_free(json
);
4640 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4642 struct cmd_token
**argv
,
4643 uint8_t use_json
, uint8_t use_vrf
)
4645 struct interface
*ifp
;
4646 struct route_node
*rn
;
4647 json_object
*json
= NULL
;
4650 json
= json_object_new_object();
4652 if (ospf
->instance
) {
4654 json_object_int_add(json
, "ospfInstance",
4657 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4660 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4662 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4665 json_object_boolean_true_add(json
, "noSuchIface");
4667 vty_out(vty
, "No such interface.\n");
4671 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4672 struct ospf_interface
*oi
= rn
->info
;
4677 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4681 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4682 json
, JSON_C_TO_STRING_PRETTY
));
4683 json_object_free(json
);
4690 DEFUN (show_ip_ospf_neighbor_int
,
4691 show_ip_ospf_neighbor_int_cmd
,
4692 "show ip ospf neighbor IFNAME [json]",
4695 "OSPF information\n"
4702 uint8_t uj
= use_json(argc
, argv
);
4703 struct listnode
*node
= NULL
;
4704 int ret
= CMD_SUCCESS
;
4705 struct interface
*ifp
= NULL
;
4708 show_ip_ospf_neighbour_header(vty
);
4710 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4711 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4712 if (!ospf
->oi_running
)
4714 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4716 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4723 DEFUN (show_ip_ospf_instance_neighbor_int
,
4724 show_ip_ospf_instance_neighbor_int_cmd
,
4725 "show ip ospf (1-65535) neighbor IFNAME [json]",
4728 "OSPF information\n"
4737 unsigned short instance
= 0;
4738 uint8_t uj
= use_json(argc
, argv
);
4741 show_ip_ospf_neighbour_header(vty
);
4743 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4744 ospf
= ospf_lookup_instance(instance
);
4746 return CMD_NOT_MY_INSTANCE
;
4748 if (!ospf
->oi_running
)
4752 show_ip_ospf_neighbour_header(vty
);
4754 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4758 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4759 struct ospf_interface
*oi
,
4760 struct ospf_nbr_nbma
*nbr_nbma
,
4764 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4765 json_object
*json_sub
= NULL
;
4768 json_sub
= json_object_new_object();
4769 else /* Show neighbor ID. */
4770 vty_out(vty
, " Neighbor %s,", "-");
4772 /* Show interface address. */
4774 json_object_string_add(json_sub
, "ifaceAddress",
4775 inet_ntoa(nbr_nbma
->addr
));
4777 vty_out(vty
, " interface address %s\n",
4778 inet_ntoa(nbr_nbma
->addr
));
4782 json_object_string_add(json_sub
, "areaId",
4783 ospf_area_desc_string(oi
->area
));
4784 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4786 vty_out(vty
, " In the area %s via interface %s\n",
4787 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4789 /* Show neighbor priority and state. */
4791 json_object_int_add(json_sub
, "nbrPriority",
4792 nbr_nbma
->priority
);
4793 json_object_string_add(json_sub
, "nbrState", "down");
4795 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4796 nbr_nbma
->priority
, "Down");
4798 /* Show state changes. */
4800 json_object_int_add(json_sub
, "stateChangeCounter",
4801 nbr_nbma
->state_change
);
4803 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4805 /* Show PollInterval */
4807 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4809 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4811 /* Show poll-interval timer. */
4814 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
, NULL
)
4816 json_object_int_add(json_sub
, "pollIntervalTimerDueMsec",
4819 vty_out(vty
, " Poll timer due in %s\n",
4820 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4823 /* Show poll-interval timer thread. */
4825 if (nbr_nbma
->t_poll
!= NULL
)
4826 json_object_string_add(json_sub
,
4827 "pollIntervalTimerThread", "on");
4829 vty_out(vty
, " Thread Poll Timer %s\n",
4830 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4833 json_object_object_add(json
, "noNbrId", json_sub
);
4836 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4837 struct ospf_interface
*oi
,
4838 struct ospf_neighbor
*nbr
,
4842 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4843 json_object
*json_sub
= NULL
;
4846 json_sub
= json_object_new_object();
4848 /* Show neighbor ID. */
4849 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4850 vty_out(vty
, " Neighbor %s,", "-");
4852 vty_out(vty
, " Neighbor %s,",
4853 inet_ntoa(nbr
->router_id
));
4856 /* Show interface address. */
4858 json_object_string_add(json_sub
, "ifaceAddress",
4859 inet_ntoa(nbr
->address
.u
.prefix4
));
4861 vty_out(vty
, " interface address %s\n",
4862 inet_ntoa(nbr
->address
.u
.prefix4
));
4866 json_object_string_add(json_sub
, "areaId",
4867 ospf_area_desc_string(oi
->area
));
4868 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4870 vty_out(vty
, " In the area %s via interface %s\n",
4871 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4873 /* Show neighbor priority and state. */
4875 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4876 json_object_string_add(
4877 json_sub
, "nbrState",
4878 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4880 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4882 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4884 /* Show state changes. */
4886 json_object_int_add(json_sub
, "stateChangeCounter",
4889 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4891 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4896 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4898 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4902 " Most recent state change statistics:\n");
4903 vty_out(vty
, " Progressive change %s ago\n",
4904 ospf_timeval_dump(&res
, timebuf
,
4909 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4914 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4916 json_object_int_add(json_sub
,
4917 "lastRegressiveChangeMsec",
4919 if (nbr
->last_regress_str
)
4920 json_object_string_add(
4921 json_sub
, "lastRegressiveChangeReason",
4922 nbr
->last_regress_str
);
4925 " Regressive change %s ago, due to %s\n",
4926 ospf_timeval_dump(&res
, timebuf
,
4928 (nbr
->last_regress_str
? nbr
->last_regress_str
4933 /* Show Designated Rotuer ID. */
4935 json_object_string_add(json_sub
, "routerDesignatedId",
4936 inet_ntoa(nbr
->d_router
));
4938 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4940 /* Show Backup Designated Rotuer ID. */
4942 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4943 inet_ntoa(nbr
->bd_router
));
4945 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4949 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4950 json_object_string_add(json_sub
, "optionsList",
4951 ospf_options_dump(nbr
->options
));
4953 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4954 ospf_options_dump(nbr
->options
));
4956 /* Show Router Dead interval timer. */
4958 if (nbr
->t_inactivity
) {
4960 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4963 json_object_int_add(json_sub
,
4964 "routerDeadIntervalTimerDueMsec",
4967 json_object_int_add(
4968 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
4970 vty_out(vty
, " Dead timer due in %s\n",
4971 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4974 /* Show Database Summary list. */
4976 json_object_int_add(json_sub
, "databaseSummaryListCounter",
4977 ospf_db_summary_count(nbr
));
4979 vty_out(vty
, " Database Summary List %d\n",
4980 ospf_db_summary_count(nbr
));
4982 /* Show Link State Request list. */
4984 json_object_int_add(json_sub
, "linkStateRequestListCounter",
4985 ospf_ls_request_count(nbr
));
4987 vty_out(vty
, " Link State Request List %ld\n",
4988 ospf_ls_request_count(nbr
));
4990 /* Show Link State Retransmission list. */
4992 json_object_int_add(json_sub
,
4993 "linkStateRetransmissionListCounter",
4994 ospf_ls_retransmit_count(nbr
));
4996 vty_out(vty
, " Link State Retransmission List %ld\n",
4997 ospf_ls_retransmit_count(nbr
));
4999 /* Show inactivity timer thread. */
5001 if (nbr
->t_inactivity
!= NULL
)
5002 json_object_string_add(json_sub
,
5003 "threadInactivityTimer", "on");
5005 vty_out(vty
, " Thread Inactivity Timer %s\n",
5006 nbr
->t_inactivity
!= NULL
? "on" : "off");
5008 /* Show Database Description retransmission thread. */
5010 if (nbr
->t_db_desc
!= NULL
)
5011 json_object_string_add(
5013 "threadDatabaseDescriptionRetransmission",
5017 " Thread Database Description Retransmision %s\n",
5018 nbr
->t_db_desc
!= NULL
? "on" : "off");
5020 /* Show Link State Request Retransmission thread. */
5022 if (nbr
->t_ls_req
!= NULL
)
5023 json_object_string_add(
5025 "threadLinkStateRequestRetransmission", "on");
5028 " Thread Link State Request Retransmission %s\n",
5029 nbr
->t_ls_req
!= NULL
? "on" : "off");
5031 /* Show Link State Update Retransmission thread. */
5033 if (nbr
->t_ls_upd
!= NULL
)
5034 json_object_string_add(
5035 json_sub
, "threadLinkStateUpdateRetransmission",
5039 " Thread Link State Update Retransmission %s\n\n",
5040 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5043 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5044 json_object_object_add(json
, "noNbrId", json_sub
);
5046 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5050 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5053 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5055 struct cmd_token
**argv
,
5056 uint8_t use_json
, uint8_t use_vrf
)
5058 struct listnode
*node
;
5059 struct ospf_neighbor
*nbr
;
5060 struct ospf_interface
*oi
;
5061 struct in_addr router_id
;
5063 json_object
*json
= NULL
;
5066 json
= json_object_new_object();
5068 if (ospf
->instance
) {
5070 json_object_int_add(json
, "ospfInstance",
5073 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5076 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5078 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5081 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5083 vty_out(vty
, "{}\n");
5084 json_object_free(json
);
5089 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5090 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5091 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5097 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5098 json
, JSON_C_TO_STRING_PRETTY
));
5099 json_object_free(json
);
5106 DEFUN (show_ip_ospf_neighbor_id
,
5107 show_ip_ospf_neighbor_id_cmd
,
5108 "show ip ospf neighbor A.B.C.D [json]",
5111 "OSPF information\n"
5117 uint8_t uj
= use_json(argc
, argv
);
5118 struct listnode
*node
= NULL
;
5119 int ret
= CMD_SUCCESS
;
5121 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5122 if (!ospf
->oi_running
)
5124 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0, argv
, uj
,
5131 DEFUN (show_ip_ospf_instance_neighbor_id
,
5132 show_ip_ospf_instance_neighbor_id_cmd
,
5133 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5136 "OSPF information\n"
5143 int idx_router_id
= 5;
5145 unsigned short instance
= 0;
5146 uint8_t uj
= use_json(argc
, argv
);
5148 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5149 ospf
= ospf_lookup_instance(instance
);
5151 return CMD_NOT_MY_INSTANCE
;
5153 if (!ospf
->oi_running
)
5156 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5160 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5166 struct ospf_interface
*oi
;
5167 struct listnode
*node
;
5168 json_object
*json_vrf
= NULL
;
5172 json_vrf
= json_object_new_object();
5176 if (ospf
->instance
) {
5178 json_object_int_add(json_vrf
, "ospfInstance",
5181 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5184 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5186 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5187 struct route_node
*rn
;
5188 struct ospf_neighbor
*nbr
;
5190 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5191 if ((nbr
= rn
->info
)) {
5192 if (nbr
!= oi
->nbr_self
) {
5193 if (nbr
->state
!= NSM_Down
) {
5194 show_ip_ospf_neighbor_detail_sub(
5195 vty
, oi
, nbr
, json_vrf
,
5205 if (ospf
->vrf_id
== VRF_DEFAULT
)
5206 json_object_object_add(json
, "default",
5209 json_object_object_add(json
, ospf
->name
,
5218 DEFUN (show_ip_ospf_neighbor_detail
,
5219 show_ip_ospf_neighbor_detail_cmd
,
5220 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5223 "OSPF information\n"
5227 "detail of all neighbors\n"
5231 uint8_t uj
= use_json(argc
, argv
);
5232 struct listnode
*node
= NULL
;
5233 char *vrf_name
= NULL
;
5234 bool all_vrf
= FALSE
;
5235 int ret
= CMD_SUCCESS
;
5238 uint8_t use_vrf
= 0;
5239 json_object
*json
= NULL
;
5241 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5244 json
= json_object_new_object();
5246 /* vrf input is provided could be all or specific vrf*/
5250 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5251 if (!ospf
->oi_running
)
5253 ret
= show_ip_ospf_neighbor_detail_common(
5254 vty
, ospf
, json
, uj
, use_vrf
);
5257 vty_out(vty
, "%s\n",
5258 json_object_to_json_string_ext(
5259 json
, JSON_C_TO_STRING_PRETTY
));
5260 json_object_free(json
);
5265 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5266 if (ospf
== NULL
|| !ospf
->oi_running
) {
5268 json_object_free(json
);
5272 /* Display default ospf (instance 0) info */
5273 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5274 if (ospf
== NULL
|| !ospf
->oi_running
) {
5276 json_object_free(json
);
5282 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5285 vty_out(vty
, "%s\n",
5286 json_object_to_json_string_ext(
5287 json
, JSON_C_TO_STRING_PRETTY
));
5292 json_object_free(json
);
5297 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5298 show_ip_ospf_instance_neighbor_detail_cmd
,
5299 "show ip ospf (1-65535) neighbor detail [json]",
5302 "OSPF information\n"
5305 "detail of all neighbors\n"
5310 unsigned short instance
= 0;
5311 uint8_t uj
= use_json(argc
, argv
);
5312 json_object
*json
= NULL
;
5313 int ret
= CMD_SUCCESS
;
5315 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5316 ospf
= ospf_lookup_instance(instance
);
5318 return CMD_NOT_MY_INSTANCE
;
5320 if (!ospf
->oi_running
)
5324 json
= json_object_new_object();
5326 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5329 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5330 json
, JSON_C_TO_STRING_PRETTY
));
5331 json_object_free(json
);
5337 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5343 struct listnode
*node
;
5344 struct ospf_interface
*oi
;
5345 json_object
*json_vrf
= NULL
;
5349 json_vrf
= json_object_new_object();
5354 if (ospf
->instance
) {
5356 json_object_int_add(json
, "ospfInstance",
5359 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5362 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5364 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5365 struct route_node
*rn
;
5366 struct ospf_neighbor
*nbr
;
5367 struct ospf_nbr_nbma
*nbr_nbma
;
5369 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5370 if ((nbr
= rn
->info
))
5371 if (nbr
!= oi
->nbr_self
)
5372 if (nbr
->state
!= NSM_Down
)
5373 show_ip_ospf_neighbor_detail_sub(
5375 json_vrf
, use_json
);
5377 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5378 struct listnode
*nd
;
5380 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5381 if (nbr_nbma
->nbr
== NULL
5382 || nbr_nbma
->nbr
->state
== NSM_Down
)
5383 show_ip_ospf_nbr_nbma_detail_sub(
5384 vty
, oi
, nbr_nbma
, use_json
,
5392 if (ospf
->vrf_id
== VRF_DEFAULT
)
5393 json_object_object_add(json
, "default",
5396 json_object_object_add(json
, ospf
->name
,
5406 DEFUN (show_ip_ospf_neighbor_detail_all
,
5407 show_ip_ospf_neighbor_detail_all_cmd
,
5408 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5411 "OSPF information\n"
5415 "detail of all neighbors\n"
5416 "include down status neighbor\n"
5420 uint8_t uj
= use_json(argc
, argv
);
5421 struct listnode
*node
= NULL
;
5422 char *vrf_name
= NULL
;
5423 bool all_vrf
= FALSE
;
5424 int ret
= CMD_SUCCESS
;
5427 uint8_t use_vrf
= 0;
5428 json_object
*json
= NULL
;
5430 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5433 json
= json_object_new_object();
5435 /* vrf input is provided could be all or specific vrf*/
5439 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5440 if (!ospf
->oi_running
)
5442 ret
= show_ip_ospf_neighbor_detail_all_common(
5443 vty
, ospf
, json
, uj
, use_vrf
);
5447 vty_out(vty
, "%s\n",
5448 json_object_to_json_string_ext(
5449 json
, JSON_C_TO_STRING_PRETTY
));
5450 json_object_free(json
);
5455 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5456 if (ospf
== NULL
|| !ospf
->oi_running
) {
5458 json_object_free(json
);
5462 /* Display default ospf (instance 0) info */
5463 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5464 if (ospf
== NULL
|| !ospf
->oi_running
) {
5466 json_object_free(json
);
5472 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5475 vty_out(vty
, "%s\n",
5476 json_object_to_json_string_ext(
5477 json
, JSON_C_TO_STRING_PRETTY
));
5482 json_object_free(json
);
5487 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5488 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5489 "show ip ospf (1-65535) neighbor detail all [json]",
5492 "OSPF information\n"
5495 "detail of all neighbors\n"
5496 "include down status neighbor\n"
5501 unsigned short instance
= 0;
5502 uint8_t uj
= use_json(argc
, argv
);
5503 json_object
*json
= NULL
;
5504 int ret
= CMD_SUCCESS
;
5506 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5507 ospf
= ospf_lookup_instance(instance
);
5509 return CMD_NOT_MY_INSTANCE
;
5511 if (!ospf
->oi_running
)
5515 json
= json_object_new_object();
5517 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5520 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5521 json
, JSON_C_TO_STRING_PRETTY
));
5522 json_object_free(json
);
5528 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5531 struct cmd_token
**argv
,
5534 struct ospf_interface
*oi
;
5535 struct interface
*ifp
;
5536 struct route_node
*rn
, *nrn
;
5537 struct ospf_neighbor
*nbr
;
5538 json_object
*json
= NULL
;
5541 json
= json_object_new_object();
5543 if (ospf
->instance
) {
5545 json_object_int_add(json
, "ospfInstance",
5548 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5551 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5554 vty_out(vty
, "No such interface.\n");
5556 vty_out(vty
, "{}\n");
5557 json_object_free(json
);
5562 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5563 if ((oi
= rn
->info
)) {
5564 for (nrn
= route_top(oi
->nbrs
); nrn
;
5565 nrn
= route_next(nrn
)) {
5566 if ((nbr
= nrn
->info
)) {
5567 if (nbr
!= oi
->nbr_self
) {
5568 if (nbr
->state
!= NSM_Down
)
5569 show_ip_ospf_neighbor_detail_sub(
5579 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5580 json
, JSON_C_TO_STRING_PRETTY
));
5581 json_object_free(json
);
5588 DEFUN (show_ip_ospf_neighbor_int_detail
,
5589 show_ip_ospf_neighbor_int_detail_cmd
,
5590 "show ip ospf neighbor IFNAME detail [json]",
5593 "OSPF information\n"
5596 "detail of all neighbors\n"
5600 uint8_t uj
= use_json(argc
, argv
);
5601 struct listnode
*node
= NULL
;
5602 int ret
= CMD_SUCCESS
;
5604 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5605 if (!ospf
->oi_running
)
5607 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5614 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5615 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5616 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5619 "OSPF information\n"
5623 "detail of all neighbors\n"
5629 unsigned short instance
= 0;
5630 uint8_t uj
= use_json(argc
, argv
);
5632 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5633 ospf
= ospf_lookup_instance(instance
);
5635 return CMD_NOT_MY_INSTANCE
;
5637 if (!ospf
->oi_running
)
5640 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5644 /* Show functions */
5645 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5647 struct router_lsa
*rl
;
5648 struct summary_lsa
*sl
;
5649 struct as_external_lsa
*asel
;
5650 struct prefix_ipv4 p
;
5653 /* If self option is set, check LSA self flag. */
5654 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5655 /* LSA common part show. */
5656 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5657 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5658 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5659 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5660 ntohs(lsa
->data
->checksum
));
5661 /* LSA specific part show. */
5662 switch (lsa
->data
->type
) {
5663 case OSPF_ROUTER_LSA
:
5664 rl
= (struct router_lsa
*)lsa
->data
;
5665 vty_out(vty
, " %-d", ntohs(rl
->links
));
5667 case OSPF_SUMMARY_LSA
:
5668 sl
= (struct summary_lsa
*)lsa
->data
;
5671 p
.prefix
= sl
->header
.id
;
5672 p
.prefixlen
= ip_masklen(sl
->mask
);
5673 apply_mask_ipv4(&p
);
5675 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5678 case OSPF_AS_EXTERNAL_LSA
:
5679 case OSPF_AS_NSSA_LSA
:
5680 asel
= (struct as_external_lsa
*)lsa
->data
;
5683 p
.prefix
= asel
->header
.id
;
5684 p
.prefixlen
= ip_masklen(asel
->mask
);
5685 apply_mask_ipv4(&p
);
5687 vty_out(vty
, " %s %s/%d [0x%lx]",
5688 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5691 inet_ntoa(p
.prefix
), p
.prefixlen
,
5692 (unsigned long)ntohl(
5693 asel
->e
[0].route_tag
));
5695 case OSPF_NETWORK_LSA
:
5696 case OSPF_ASBR_SUMMARY_LSA
:
5697 case OSPF_OPAQUE_LINK_LSA
:
5698 case OSPF_OPAQUE_AREA_LSA
:
5699 case OSPF_OPAQUE_AS_LSA
:
5709 static const char *show_database_desc
[] = {
5711 "Router Link States",
5713 "Summary Link States",
5714 "ASBR-Summary Link States",
5715 "AS External Link States",
5716 "Group Membership LSA",
5717 "NSSA-external Link States",
5719 "Link-Local Opaque-LSA",
5720 "Area-Local Opaque-LSA",
5721 "AS-external Opaque-LSA",
5724 static const char *show_database_header
[] = {
5726 "Link ID ADV Router Age Seq# CkSum Link count",
5727 "Link ID ADV Router Age Seq# CkSum",
5728 "Link ID ADV Router Age Seq# CkSum Route",
5729 "Link ID ADV Router Age Seq# CkSum",
5730 "Link ID ADV Router Age Seq# CkSum Route",
5731 " --- header for Group Member ----",
5732 "Link ID ADV Router Age Seq# CkSum Route",
5734 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5735 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5736 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5739 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5741 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5743 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5744 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5745 ospf_options_dump(lsa
->data
->options
));
5746 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5747 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5750 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5751 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5754 vty_out(vty
, " :%s%s%s%s",
5755 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5756 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5757 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5759 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5764 vty_out(vty
, " LS Type: %s\n",
5765 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5766 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5767 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5768 vty_out(vty
, " Advertising Router: %s\n",
5769 inet_ntoa(lsa
->data
->adv_router
));
5770 vty_out(vty
, " LS Seq Number: %08lx\n",
5771 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5772 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5773 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5776 const char *link_type_desc
[] = {
5778 "another Router (point-to-point)",
5779 "a Transit Network",
5784 const char *link_id_desc
[] = {
5785 "(null)", "Neighboring Router ID", "Designated Router address",
5786 "Net", "Neighboring Router ID",
5789 const char *link_data_desc
[] = {
5790 "(null)", "Router Interface address", "Router Interface address",
5791 "Network Mask", "Router Interface address",
5794 /* Show router-LSA each Link information. */
5795 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5796 struct router_lsa
*rl
)
5801 len
= ntohs(rl
->header
.length
) - 4;
5802 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5803 type
= rl
->link
[i
].type
;
5805 vty_out(vty
, " Link connected to: %s\n",
5806 link_type_desc
[type
]);
5807 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5808 inet_ntoa(rl
->link
[i
].link_id
));
5809 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5810 inet_ntoa(rl
->link
[i
].link_data
));
5811 vty_out(vty
, " Number of TOS metrics: 0\n");
5812 vty_out(vty
, " TOS 0 Metric: %d\n",
5813 ntohs(rl
->link
[i
].metric
));
5818 /* Show router-LSA detail information. */
5819 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5822 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5824 show_ip_ospf_database_header(vty
, lsa
);
5826 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5828 show_ip_ospf_database_router_links(vty
, rl
);
5835 /* Show network-LSA detail information. */
5836 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5841 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5843 show_ip_ospf_database_header(vty
, lsa
);
5845 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5847 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5849 for (i
= 0; length
> 0; i
++, length
-= 4)
5850 vty_out(vty
, " Attached Router: %s\n",
5851 inet_ntoa(nl
->routers
[i
]));
5859 /* Show summary-LSA detail information. */
5860 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5863 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5865 show_ip_ospf_database_header(vty
, lsa
);
5867 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5868 vty_out(vty
, " TOS: 0 Metric: %d\n",
5869 GET_METRIC(sl
->metric
));
5876 /* Show summary-ASBR-LSA detail information. */
5877 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5880 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5882 show_ip_ospf_database_header(vty
, lsa
);
5884 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5885 vty_out(vty
, " TOS: 0 Metric: %d\n",
5886 GET_METRIC(sl
->metric
));
5893 /* Show AS-external-LSA detail information. */
5894 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5897 struct as_external_lsa
*al
=
5898 (struct as_external_lsa
*)lsa
->data
;
5900 show_ip_ospf_database_header(vty
, lsa
);
5902 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5903 vty_out(vty
, " Metric Type: %s\n",
5904 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5905 ? "2 (Larger than any link state path)"
5907 vty_out(vty
, " TOS: 0\n");
5908 vty_out(vty
, " Metric: %d\n",
5909 GET_METRIC(al
->e
[0].metric
));
5910 vty_out(vty
, " Forward Address: %s\n",
5911 inet_ntoa(al
->e
[0].fwd_addr
));
5914 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5915 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5922 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5924 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5926 /* show_ip_ospf_database_header (vty, lsa); */
5928 zlog_debug( " Network Mask: /%d%s",
5929 ip_masklen (al
->mask
), "\n");
5930 zlog_debug( " Metric Type: %s%s",
5931 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5932 "2 (Larger than any link state path)" : "1", "\n");
5933 zlog_debug( " TOS: 0%s", "\n");
5934 zlog_debug( " Metric: %d%s",
5935 GET_METRIC (al
->e
[0].metric
), "\n");
5936 zlog_debug( " Forward Address: %s%s",
5937 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5939 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5940 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5945 /* Show AS-NSSA-LSA detail information. */
5946 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5949 struct as_external_lsa
*al
=
5950 (struct as_external_lsa
*)lsa
->data
;
5952 show_ip_ospf_database_header(vty
, lsa
);
5954 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5955 vty_out(vty
, " Metric Type: %s\n",
5956 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5957 ? "2 (Larger than any link state path)"
5959 vty_out(vty
, " TOS: 0\n");
5960 vty_out(vty
, " Metric: %d\n",
5961 GET_METRIC(al
->e
[0].metric
));
5962 vty_out(vty
, " NSSA: Forward Address: %s\n",
5963 inet_ntoa(al
->e
[0].fwd_addr
));
5966 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5967 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5973 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
5978 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5981 show_ip_ospf_database_header(vty
, lsa
);
5982 show_opaque_info_detail(vty
, lsa
);
5989 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
5991 show_router_lsa_detail
,
5992 show_network_lsa_detail
,
5993 show_summary_lsa_detail
,
5994 show_summary_asbr_lsa_detail
,
5995 show_as_external_lsa_detail
,
5997 show_as_nssa_lsa_detail
, /* almost same as external */
5999 show_opaque_lsa_detail
,
6000 show_opaque_lsa_detail
,
6001 show_opaque_lsa_detail
,
6004 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6005 struct in_addr
*id
, struct in_addr
*adv_router
)
6007 memset(lp
, 0, sizeof(struct prefix_ls
));
6011 else if (adv_router
== NULL
) {
6017 lp
->adv_router
= *adv_router
;
6021 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6022 struct in_addr
*id
, struct in_addr
*adv_router
)
6024 struct prefix_ls lp
;
6025 struct route_node
*rn
, *start
;
6026 struct ospf_lsa
*lsa
;
6028 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6029 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6031 route_lock_node(start
);
6032 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6033 if ((lsa
= rn
->info
)) {
6034 if (show_function
[lsa
->data
->type
] != NULL
)
6035 show_function
[lsa
->data
->type
](vty
,
6038 route_unlock_node(start
);
6042 /* Show detail LSA information
6043 -- if id is NULL then show all LSAs. */
6044 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6045 struct in_addr
*id
, struct in_addr
*adv_router
)
6047 struct listnode
*node
;
6048 struct ospf_area
*area
;
6051 case OSPF_AS_EXTERNAL_LSA
:
6052 case OSPF_OPAQUE_AS_LSA
:
6053 vty_out(vty
, " %s \n\n",
6054 show_database_desc
[type
]);
6055 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6058 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6059 vty_out(vty
, "\n %s (Area %s)\n\n",
6060 show_database_desc
[type
],
6061 ospf_area_desc_string(area
));
6062 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6069 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6070 struct route_table
*rt
,
6071 struct in_addr
*adv_router
)
6073 struct route_node
*rn
;
6074 struct ospf_lsa
*lsa
;
6076 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6077 if ((lsa
= rn
->info
))
6078 if (IPV4_ADDR_SAME(adv_router
,
6079 &lsa
->data
->adv_router
)) {
6080 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6082 if (show_function
[lsa
->data
->type
] != NULL
)
6083 show_function
[lsa
->data
->type
](vty
,
6088 /* Show detail LSA information. */
6089 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6090 int type
, struct in_addr
*adv_router
)
6092 struct listnode
*node
;
6093 struct ospf_area
*area
;
6096 case OSPF_AS_EXTERNAL_LSA
:
6097 case OSPF_OPAQUE_AS_LSA
:
6098 vty_out(vty
, " %s \n\n",
6099 show_database_desc
[type
]);
6100 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6104 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6105 vty_out(vty
, "\n %s (Area %s)\n\n",
6106 show_database_desc
[type
],
6107 ospf_area_desc_string(area
));
6108 show_lsa_detail_adv_router_proc(
6109 vty
, AREA_LSDB(area
, type
), adv_router
);
6115 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6118 struct ospf_lsa
*lsa
;
6119 struct route_node
*rn
;
6120 struct ospf_area
*area
;
6121 struct listnode
*node
;
6124 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6125 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6127 case OSPF_AS_EXTERNAL_LSA
:
6128 case OSPF_OPAQUE_AS_LSA
:
6133 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6135 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6136 vty_out(vty
, " %s (Area %s)\n\n",
6137 show_database_desc
[type
],
6138 ospf_area_desc_string(area
));
6139 vty_out(vty
, "%s\n",
6140 show_database_header
[type
]);
6142 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6143 show_lsa_summary(vty
, lsa
, self
);
6150 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6152 case OSPF_AS_EXTERNAL_LSA
:
6153 case OSPF_OPAQUE_AS_LSA
:
6158 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6159 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6160 vty_out(vty
, " %s\n\n",
6161 show_database_desc
[type
]);
6162 vty_out(vty
, "%s\n", show_database_header
[type
]);
6164 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6165 show_lsa_summary(vty
, lsa
, self
);
6174 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6176 struct route_node
*rn
;
6178 vty_out(vty
, "\n MaxAge Link States:\n\n");
6180 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6181 struct ospf_lsa
*lsa
;
6183 if ((lsa
= rn
->info
) != NULL
) {
6184 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6185 vty_out(vty
, "Link State ID: %s\n",
6186 inet_ntoa(lsa
->data
->id
));
6187 vty_out(vty
, "Advertising Router: %s\n",
6188 inet_ntoa(lsa
->data
->adv_router
));
6189 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6195 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6196 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6198 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6199 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6200 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6201 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6203 #define OSPF_LSA_TYPES_DESC \
6204 "ASBR summary link states\n" \
6205 "External link states\n" \
6206 "Network link states\n" \
6207 "Router link states\n" \
6208 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6209 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6210 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6212 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6213 int arg_base
, int argc
,
6214 struct cmd_token
**argv
,
6219 struct in_addr id
, adv_router
;
6222 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6224 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6226 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6227 inet_ntoa(ospf
->router_id
));
6230 if (argc
== arg_base
+ 4) {
6231 show_ip_ospf_database_summary(vty
, ospf
, 0);
6235 /* Set database type to show. */
6236 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6237 type
= OSPF_ROUTER_LSA
;
6238 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6239 type
= OSPF_NETWORK_LSA
;
6240 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6241 type
= OSPF_AS_NSSA_LSA
;
6242 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6243 type
= OSPF_SUMMARY_LSA
;
6244 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6245 type
= OSPF_ASBR_SUMMARY_LSA
;
6246 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6247 type
= OSPF_AS_EXTERNAL_LSA
;
6248 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6249 show_ip_ospf_database_summary(vty
, ospf
, 1);
6251 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6252 show_ip_ospf_database_maxage(vty
, ospf
);
6254 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6255 type
= OSPF_OPAQUE_LINK_LSA
;
6256 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6257 type
= OSPF_OPAQUE_AREA_LSA
;
6258 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6259 type
= OSPF_OPAQUE_AS_LSA
;
6263 /* `show ip ospf database LSA'. */
6264 if (argc
== arg_base
+ 5)
6265 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6266 else if (argc
>= arg_base
+ 6) {
6267 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6271 /* `show ip ospf database LSA ID'. */
6272 if (argc
== arg_base
+ 6)
6273 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6274 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6275 else if (argc
== arg_base
+ 7) {
6276 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6277 adv_router
= ospf
->router_id
;
6279 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6284 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6291 DEFUN (show_ip_ospf_database_max
,
6292 show_ip_ospf_database_max_cmd
,
6293 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6296 "OSPF information\n"
6299 "Database summary\n"
6300 "LSAs in MaxAge list\n"
6301 "Self-originated link states\n")
6303 struct ospf
*ospf
= NULL
;
6304 struct listnode
*node
= NULL
;
6305 char *vrf_name
= NULL
;
6306 bool all_vrf
= FALSE
;
6307 int ret
= CMD_SUCCESS
;
6310 uint8_t use_vrf
= 0;
6312 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6317 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6318 if (!ospf
->oi_running
)
6320 ret
= show_ip_ospf_database_common(
6321 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6325 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6326 if (ospf
== NULL
|| !ospf
->oi_running
)
6328 ret
= (show_ip_ospf_database_common(
6329 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6333 /* Display default ospf (instance 0) info */
6334 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6335 if (ospf
== NULL
|| !ospf
->oi_running
)
6337 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6344 DEFUN (show_ip_ospf_instance_database
,
6345 show_ip_ospf_instance_database_cmd
,
6346 "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>]]]",
6349 "OSPF information\n"
6352 "Database summary\n"
6354 "Link State ID (as an IP address)\n"
6355 "Self-originated link states\n"
6356 "Advertising Router link states\n"
6357 "Advertising Router (as an IP address)\n")
6360 unsigned short instance
= 0;
6361 struct listnode
*node
= NULL
;
6362 char *vrf_name
= NULL
;
6363 bool all_vrf
= FALSE
;
6364 int ret
= CMD_SUCCESS
;
6367 uint8_t use_vrf
= 0;
6369 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6370 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6371 ospf
= ospf_lookup_instance(instance
);
6373 return CMD_NOT_MY_INSTANCE
;
6374 if (!ospf
->oi_running
)
6377 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6378 argc
, argv
, use_vrf
));
6379 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6380 vrf_name
= argv
[++idx
]->arg
;
6381 all_vrf
= strmatch(vrf_name
, "all");
6387 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6388 if (!ospf
->oi_running
)
6390 ret
= (show_ip_ospf_database_common(
6391 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6395 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6396 if ((ospf
== NULL
) || !ospf
->oi_running
)
6398 ret
= (show_ip_ospf_database_common(
6399 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6402 /* Display default ospf (instance 0) info */
6403 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6404 if (ospf
== NULL
|| !ospf
->oi_running
)
6406 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6413 DEFUN (show_ip_ospf_instance_database_max
,
6414 show_ip_ospf_instance_database_max_cmd
,
6415 "show ip ospf (1-65535) database <max-age|self-originate>",
6418 "OSPF information\n"
6420 "Database summary\n"
6421 "LSAs in MaxAge list\n"
6422 "Self-originated link states\n")
6426 unsigned short instance
= 0;
6428 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6430 ospf
= ospf_lookup_instance(instance
);
6432 return CMD_NOT_MY_INSTANCE
;
6434 if (!ospf
->oi_running
)
6437 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6441 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6443 int arg_base
, int argc
,
6444 struct cmd_token
**argv
,
6449 struct in_addr adv_router
;
6452 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6454 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6456 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6457 inet_ntoa(ospf
->router_id
));
6459 /* Set database type to show. */
6460 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6461 type
= OSPF_ROUTER_LSA
;
6462 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6463 type
= OSPF_NETWORK_LSA
;
6464 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6465 type
= OSPF_AS_NSSA_LSA
;
6466 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6467 type
= OSPF_SUMMARY_LSA
;
6468 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6469 type
= OSPF_ASBR_SUMMARY_LSA
;
6470 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6471 type
= OSPF_AS_EXTERNAL_LSA
;
6472 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6473 type
= OSPF_OPAQUE_LINK_LSA
;
6474 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6475 type
= OSPF_OPAQUE_AREA_LSA
;
6476 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6477 type
= OSPF_OPAQUE_AS_LSA
;
6481 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6482 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6483 adv_router
= ospf
->router_id
;
6485 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6490 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6495 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6496 show_ip_ospf_instance_database_type_adv_router_cmd
,
6497 "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>",
6500 "OSPF information\n"
6503 "Database summary\n"
6505 "Advertising Router link states\n"
6506 "Advertising Router (as an IP address)\n"
6507 "Self-originated link states\n")
6509 struct ospf
*ospf
= NULL
;
6510 unsigned short instance
= 0;
6511 struct listnode
*node
= NULL
;
6512 char *vrf_name
= NULL
;
6513 bool all_vrf
= FALSE
;
6514 int ret
= CMD_SUCCESS
;
6516 int idx
= 0, idx_vrf
= 0;
6517 uint8_t use_vrf
= 0;
6519 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6520 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6521 ospf
= ospf_lookup_instance(instance
);
6523 return CMD_NOT_MY_INSTANCE
;
6524 if (!ospf
->oi_running
)
6526 return (show_ip_ospf_database_type_adv_router_common(
6527 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6530 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6535 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6536 if (!ospf
->oi_running
)
6538 ret
= show_ip_ospf_database_type_adv_router_common(
6539 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6543 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6544 if ((ospf
== NULL
) || !ospf
->oi_running
)
6546 ret
= show_ip_ospf_database_type_adv_router_common(
6547 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6550 /* Display default ospf (instance 0) info */
6551 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6552 if (ospf
== NULL
|| !ospf
->oi_running
)
6554 ret
= show_ip_ospf_database_type_adv_router_common(
6555 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6558 /*return (show_ip_ospf_database_type_adv_router_common(
6559 vty, ospf, idx ? 1 : 0, argc, argv));*/
6562 DEFUN (ip_ospf_authentication_args
,
6563 ip_ospf_authentication_args_addr_cmd
,
6564 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6566 "OSPF interface commands\n"
6567 "Enable authentication on this interface\n"
6568 "Use null authentication\n"
6569 "Use message-digest authentication\n"
6570 "Address of interface\n")
6572 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6573 int idx_encryption
= 3;
6575 struct in_addr addr
;
6577 struct ospf_if_params
*params
;
6579 params
= IF_DEF_PARAMS(ifp
);
6582 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6585 "Please specify interface address by A.B.C.D\n");
6586 return CMD_WARNING_CONFIG_FAILED
;
6589 params
= ospf_get_if_params(ifp
, addr
);
6590 ospf_if_update_params(ifp
, addr
);
6593 /* Handle null authentication */
6594 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6595 SET_IF_PARAM(params
, auth_type
);
6596 params
->auth_type
= OSPF_AUTH_NULL
;
6600 /* Handle message-digest authentication */
6601 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6602 SET_IF_PARAM(params
, auth_type
);
6603 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6607 vty_out(vty
, "You shouldn't get here!\n");
6608 return CMD_WARNING_CONFIG_FAILED
;
6611 DEFUN (ip_ospf_authentication
,
6612 ip_ospf_authentication_addr_cmd
,
6613 "ip ospf authentication [A.B.C.D]",
6615 "OSPF interface commands\n"
6616 "Enable authentication on this interface\n"
6617 "Address of interface\n")
6619 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6621 struct in_addr addr
;
6623 struct ospf_if_params
*params
;
6625 params
= IF_DEF_PARAMS(ifp
);
6628 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6631 "Please specify interface address by A.B.C.D\n");
6632 return CMD_WARNING_CONFIG_FAILED
;
6635 params
= ospf_get_if_params(ifp
, addr
);
6636 ospf_if_update_params(ifp
, addr
);
6639 SET_IF_PARAM(params
, auth_type
);
6640 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6645 DEFUN (no_ip_ospf_authentication_args
,
6646 no_ip_ospf_authentication_args_addr_cmd
,
6647 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6650 "OSPF interface commands\n"
6651 "Enable authentication on this interface\n"
6652 "Use null authentication\n"
6653 "Use message-digest authentication\n"
6654 "Address of interface\n")
6656 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6657 int idx_encryption
= 4;
6659 struct in_addr addr
;
6661 struct ospf_if_params
*params
;
6662 struct route_node
*rn
;
6665 params
= IF_DEF_PARAMS(ifp
);
6668 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6671 "Please specify interface address by A.B.C.D\n");
6672 return CMD_WARNING_CONFIG_FAILED
;
6675 params
= ospf_lookup_if_params(ifp
, addr
);
6676 if (params
== NULL
) {
6677 vty_out(vty
, "Ip Address specified is unknown\n");
6678 return CMD_WARNING_CONFIG_FAILED
;
6680 params
->auth_type
= OSPF_AUTH_NOTSET
;
6681 UNSET_IF_PARAM(params
, auth_type
);
6682 if (params
!= IF_DEF_PARAMS(ifp
)) {
6683 ospf_free_if_params(ifp
, addr
);
6684 ospf_if_update_params(ifp
, addr
);
6687 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6688 auth_type
= OSPF_AUTH_NULL
;
6689 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6690 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6692 vty_out(vty
, "Unexpected input encountered\n");
6693 return CMD_WARNING_CONFIG_FAILED
;
6696 * Here we have a case where the user has entered
6697 * 'no ip ospf authentication (null | message_digest )'
6698 * we need to find if we have any ip addresses underneath it
6700 * correspond to the associated type.
6702 if (params
->auth_type
== auth_type
) {
6703 params
->auth_type
= OSPF_AUTH_NOTSET
;
6704 UNSET_IF_PARAM(params
, auth_type
);
6707 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6708 rn
= route_next(rn
)) {
6709 if ((params
= rn
->info
)) {
6710 if (params
->auth_type
== auth_type
) {
6711 params
->auth_type
= OSPF_AUTH_NOTSET
;
6712 UNSET_IF_PARAM(params
, auth_type
);
6713 if (params
!= IF_DEF_PARAMS(ifp
)) {
6714 ospf_free_if_params(
6715 ifp
, rn
->p
.u
.prefix4
);
6716 ospf_if_update_params(
6717 ifp
, rn
->p
.u
.prefix4
);
6727 DEFUN (no_ip_ospf_authentication
,
6728 no_ip_ospf_authentication_addr_cmd
,
6729 "no ip ospf authentication [A.B.C.D]",
6732 "OSPF interface commands\n"
6733 "Enable authentication on this interface\n"
6734 "Address of interface\n")
6736 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6738 struct in_addr addr
;
6740 struct ospf_if_params
*params
;
6741 struct route_node
*rn
;
6743 params
= IF_DEF_PARAMS(ifp
);
6746 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6749 "Please specify interface address by A.B.C.D\n");
6750 return CMD_WARNING_CONFIG_FAILED
;
6753 params
= ospf_lookup_if_params(ifp
, addr
);
6754 if (params
== NULL
) {
6755 vty_out(vty
, "Ip Address specified is unknown\n");
6756 return CMD_WARNING_CONFIG_FAILED
;
6759 params
->auth_type
= OSPF_AUTH_NOTSET
;
6760 UNSET_IF_PARAM(params
, auth_type
);
6761 if (params
!= IF_DEF_PARAMS(ifp
)) {
6762 ospf_free_if_params(ifp
, addr
);
6763 ospf_if_update_params(ifp
, addr
);
6767 * When a user enters 'no ip ospf authentication'
6768 * We should remove all authentication types from
6771 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6772 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6773 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6774 params
->auth_type
= OSPF_AUTH_NOTSET
;
6775 UNSET_IF_PARAM(params
, auth_type
);
6778 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6779 rn
= route_next(rn
)) {
6780 if ((params
= rn
->info
)) {
6782 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6783 || (params
->auth_type
6784 == OSPF_AUTH_CRYPTOGRAPHIC
)
6785 || (params
->auth_type
6786 == OSPF_AUTH_SIMPLE
)) {
6787 params
->auth_type
= OSPF_AUTH_NOTSET
;
6788 UNSET_IF_PARAM(params
, auth_type
);
6789 if (params
!= IF_DEF_PARAMS(ifp
)) {
6790 ospf_free_if_params(
6791 ifp
, rn
->p
.u
.prefix4
);
6792 ospf_if_update_params(
6793 ifp
, rn
->p
.u
.prefix4
);
6804 DEFUN (ip_ospf_authentication_key
,
6805 ip_ospf_authentication_key_addr_cmd
,
6806 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6808 "OSPF interface commands\n"
6809 "Authentication password (key)\n"
6810 "The OSPF password (key)\n"
6811 "Address of interface\n")
6813 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6815 struct in_addr addr
;
6816 struct ospf_if_params
*params
;
6818 params
= IF_DEF_PARAMS(ifp
);
6820 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6821 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6823 "Please specify interface address by A.B.C.D\n");
6824 return CMD_WARNING_CONFIG_FAILED
;
6827 params
= ospf_get_if_params(ifp
, addr
);
6828 ospf_if_update_params(ifp
, addr
);
6831 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6832 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6833 OSPF_AUTH_SIMPLE_SIZE
);
6834 SET_IF_PARAM(params
, auth_simple
);
6839 DEFUN_HIDDEN (ospf_authentication_key
,
6840 ospf_authentication_key_cmd
,
6841 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6842 "OSPF interface commands\n"
6843 VLINK_HELPSTR_AUTH_SIMPLE
6844 "Address of interface\n")
6846 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6849 DEFUN (no_ip_ospf_authentication_key
,
6850 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6851 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6854 "OSPF interface commands\n"
6855 VLINK_HELPSTR_AUTH_SIMPLE
6856 "Address of interface\n")
6858 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6860 struct in_addr addr
;
6861 struct ospf_if_params
*params
;
6862 params
= IF_DEF_PARAMS(ifp
);
6864 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6865 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6867 "Please specify interface address by A.B.C.D\n");
6868 return CMD_WARNING_CONFIG_FAILED
;
6871 params
= ospf_lookup_if_params(ifp
, addr
);
6876 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6877 UNSET_IF_PARAM(params
, auth_simple
);
6879 if (params
!= IF_DEF_PARAMS(ifp
)) {
6880 ospf_free_if_params(ifp
, addr
);
6881 ospf_if_update_params(ifp
, addr
);
6887 DEFUN_HIDDEN (no_ospf_authentication_key
,
6888 no_ospf_authentication_key_authkey_addr_cmd
,
6889 "no 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 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6898 DEFUN (ip_ospf_message_digest_key
,
6899 ip_ospf_message_digest_key_cmd
,
6900 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6902 "OSPF interface commands\n"
6903 "Message digest authentication password (key)\n"
6905 "Use MD5 algorithm\n"
6906 "The OSPF password (key)\n"
6907 "Address of interface\n")
6909 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6910 struct crypt_key
*ck
;
6912 struct in_addr addr
;
6913 struct ospf_if_params
*params
;
6915 params
= IF_DEF_PARAMS(ifp
);
6918 argv_find(argv
, argc
, "(1-255)", &idx
);
6919 char *keyid
= argv
[idx
]->arg
;
6920 argv_find(argv
, argc
, "KEY", &idx
);
6921 char *cryptkey
= argv
[idx
]->arg
;
6923 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6924 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6926 "Please specify interface address by A.B.C.D\n");
6927 return CMD_WARNING_CONFIG_FAILED
;
6930 params
= ospf_get_if_params(ifp
, addr
);
6931 ospf_if_update_params(ifp
, addr
);
6934 key_id
= strtol(keyid
, NULL
, 10);
6935 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
6936 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
6940 ck
= ospf_crypt_key_new();
6941 ck
->key_id
= (uint8_t)key_id
;
6942 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
6943 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
6945 ospf_crypt_key_add(params
->auth_crypt
, ck
);
6946 SET_IF_PARAM(params
, auth_crypt
);
6951 DEFUN_HIDDEN (ospf_message_digest_key
,
6952 ospf_message_digest_key_cmd
,
6953 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6954 "OSPF interface commands\n"
6955 "Message digest authentication password (key)\n"
6957 "Use MD5 algorithm\n"
6958 "The OSPF password (key)\n"
6959 "Address of interface\n")
6961 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
6964 DEFUN (no_ip_ospf_message_digest_key
,
6965 no_ip_ospf_message_digest_key_cmd
,
6966 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6969 "OSPF interface commands\n"
6970 "Message digest authentication password (key)\n"
6972 "Use MD5 algorithm\n"
6973 "The OSPF password (key)\n"
6974 "Address of interface\n")
6976 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6978 struct crypt_key
*ck
;
6980 struct in_addr addr
;
6981 struct ospf_if_params
*params
;
6982 params
= IF_DEF_PARAMS(ifp
);
6984 argv_find(argv
, argc
, "(1-255)", &idx
);
6985 char *keyid
= argv
[idx
]->arg
;
6987 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6988 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6990 "Please specify interface address by A.B.C.D\n");
6991 return CMD_WARNING_CONFIG_FAILED
;
6994 params
= ospf_lookup_if_params(ifp
, addr
);
6999 key_id
= strtol(keyid
, NULL
, 10);
7000 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7002 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7003 return CMD_WARNING_CONFIG_FAILED
;
7006 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7008 if (params
!= IF_DEF_PARAMS(ifp
)) {
7009 ospf_free_if_params(ifp
, addr
);
7010 ospf_if_update_params(ifp
, addr
);
7016 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7017 no_ospf_message_digest_key_cmd
,
7018 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7020 "OSPF interface commands\n"
7021 "Message digest authentication password (key)\n"
7023 "Use MD5 algorithm\n"
7024 "The OSPF password (key)\n"
7025 "Address of interface\n")
7027 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7030 DEFUN (ip_ospf_cost
,
7032 "ip ospf cost (1-65535) [A.B.C.D]",
7034 "OSPF interface commands\n"
7037 "Address of interface\n")
7039 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7041 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7042 struct in_addr addr
;
7043 struct ospf_if_params
*params
;
7044 params
= IF_DEF_PARAMS(ifp
);
7047 char *coststr
= NULL
, *ifaddr
= NULL
;
7049 argv_find(argv
, argc
, "(1-65535)", &idx
);
7050 coststr
= argv
[idx
]->arg
;
7051 cost
= strtol(coststr
, NULL
, 10);
7053 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7055 if (!inet_aton(ifaddr
, &addr
)) {
7057 "Please specify interface address by A.B.C.D\n");
7058 return CMD_WARNING_CONFIG_FAILED
;
7061 params
= ospf_get_if_params(ifp
, addr
);
7062 ospf_if_update_params(ifp
, addr
);
7065 SET_IF_PARAM(params
, output_cost_cmd
);
7066 params
->output_cost_cmd
= cost
;
7068 ospf_if_recalculate_output_cost(ifp
);
7073 DEFUN_HIDDEN (ospf_cost
,
7075 "ospf cost (1-65535) [A.B.C.D]",
7076 "OSPF interface commands\n"
7079 "Address of interface\n")
7081 return ip_ospf_cost(self
, vty
, argc
, argv
);
7084 DEFUN (no_ip_ospf_cost
,
7085 no_ip_ospf_cost_cmd
,
7086 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7089 "OSPF interface commands\n"
7092 "Address of interface\n")
7094 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7096 struct in_addr addr
;
7097 struct ospf_if_params
*params
;
7099 params
= IF_DEF_PARAMS(ifp
);
7102 char *ifaddr
= NULL
;
7103 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7105 /* According to the semantics we are mimicking "no ip ospf cost N" is
7106 * always treated as "no ip ospf cost" regardless of the actual value
7107 * of N already configured for the interface. Thus ignore cost. */
7110 if (!inet_aton(ifaddr
, &addr
)) {
7112 "Please specify interface address by A.B.C.D\n");
7113 return CMD_WARNING_CONFIG_FAILED
;
7116 params
= ospf_lookup_if_params(ifp
, addr
);
7121 UNSET_IF_PARAM(params
, output_cost_cmd
);
7123 if (params
!= IF_DEF_PARAMS(ifp
)) {
7124 ospf_free_if_params(ifp
, addr
);
7125 ospf_if_update_params(ifp
, addr
);
7128 ospf_if_recalculate_output_cost(ifp
);
7133 DEFUN_HIDDEN (no_ospf_cost
,
7135 "no ospf cost [(1-65535)] [A.B.C.D]",
7137 "OSPF interface commands\n"
7140 "Address of interface\n")
7142 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7145 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7147 struct route_node
*rn
;
7148 struct ospf_neighbor
*nbr
;
7150 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7151 if ((nbr
= rn
->info
)) {
7152 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7153 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7154 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7155 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7159 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7160 const char *nbr_str
,
7161 const char *fast_hello_str
)
7163 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7166 struct in_addr addr
;
7168 struct ospf_if_params
*params
;
7169 struct ospf_interface
*oi
;
7170 struct route_node
*rn
;
7172 params
= IF_DEF_PARAMS(ifp
);
7175 ret
= inet_aton(nbr_str
, &addr
);
7178 "Please specify interface address by A.B.C.D\n");
7179 return CMD_WARNING_CONFIG_FAILED
;
7182 params
= ospf_get_if_params(ifp
, addr
);
7183 ospf_if_update_params(ifp
, addr
);
7187 seconds
= strtoul(interval_str
, NULL
, 10);
7189 /* reset fast_hello too, just to be sure */
7190 UNSET_IF_PARAM(params
, fast_hello
);
7191 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7192 } else if (fast_hello_str
) {
7193 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7194 /* 1s dead-interval with sub-second hellos desired */
7195 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7196 SET_IF_PARAM(params
, fast_hello
);
7197 params
->fast_hello
= hellomult
;
7200 "Please specify dead-interval or hello-multiplier\n");
7201 return CMD_WARNING_CONFIG_FAILED
;
7204 SET_IF_PARAM(params
, v_wait
);
7205 params
->v_wait
= seconds
;
7207 /* Update timer values in neighbor structure. */
7209 struct ospf
*ospf
= NULL
;
7211 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7213 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7215 ospf_nbr_timer_update(oi
);
7218 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7219 if ((oi
= rn
->info
))
7220 ospf_nbr_timer_update(oi
);
7226 DEFUN (ip_ospf_dead_interval
,
7227 ip_ospf_dead_interval_cmd
,
7228 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7230 "OSPF interface commands\n"
7231 "Interval time after which a neighbor is declared down\n"
7233 "Address of interface\n")
7236 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7240 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7241 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7245 DEFUN_HIDDEN (ospf_dead_interval
,
7246 ospf_dead_interval_cmd
,
7247 "ospf dead-interval (1-65535) [A.B.C.D]",
7248 "OSPF interface commands\n"
7249 "Interval time after which a neighbor is declared down\n"
7251 "Address of interface\n")
7253 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7256 DEFUN (ip_ospf_dead_interval_minimal
,
7257 ip_ospf_dead_interval_minimal_addr_cmd
,
7258 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7260 "OSPF interface commands\n"
7261 "Interval time after which a neighbor is declared down\n"
7262 "Minimal 1s dead-interval with fast sub-second hellos\n"
7263 "Hello multiplier factor\n"
7264 "Number of Hellos to send each second\n"
7265 "Address of interface\n")
7270 return ospf_vty_dead_interval_set(
7271 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7273 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7274 argv
[idx_number
]->arg
);
7277 DEFUN (no_ip_ospf_dead_interval
,
7278 no_ip_ospf_dead_interval_cmd
,
7279 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7282 "OSPF interface commands\n"
7283 "Interval time after which a neighbor is declared down\n"
7285 "Minimal 1s dead-interval with fast sub-second hellos\n"
7286 "Hello multiplier factor\n"
7287 "Number of Hellos to send each second\n"
7288 "Address of interface\n")
7290 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7291 int idx_ipv4
= argc
- 1;
7292 struct in_addr addr
= {.s_addr
= 0L};
7294 struct ospf_if_params
*params
;
7295 struct ospf_interface
*oi
;
7296 struct route_node
*rn
;
7298 params
= IF_DEF_PARAMS(ifp
);
7300 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7301 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7304 "Please specify interface address by A.B.C.D\n");
7305 return CMD_WARNING_CONFIG_FAILED
;
7308 params
= ospf_lookup_if_params(ifp
, addr
);
7313 UNSET_IF_PARAM(params
, v_wait
);
7314 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7316 UNSET_IF_PARAM(params
, fast_hello
);
7317 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7319 if (params
!= IF_DEF_PARAMS(ifp
)) {
7320 ospf_free_if_params(ifp
, addr
);
7321 ospf_if_update_params(ifp
, addr
);
7324 /* Update timer values in neighbor structure. */
7326 struct ospf
*ospf
= NULL
;
7328 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7330 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7332 ospf_nbr_timer_update(oi
);
7335 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7336 if ((oi
= rn
->info
))
7337 ospf_nbr_timer_update(oi
);
7343 DEFUN_HIDDEN (no_ospf_dead_interval
,
7344 no_ospf_dead_interval_cmd
,
7345 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7347 "OSPF interface commands\n"
7348 "Interval time after which a neighbor is declared down\n"
7350 "Minimal 1s dead-interval with fast sub-second hellos\n"
7351 "Hello multiplier factor\n"
7352 "Number of Hellos to send each second\n"
7353 "Address of interface\n")
7355 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7358 DEFUN (ip_ospf_hello_interval
,
7359 ip_ospf_hello_interval_cmd
,
7360 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7362 "OSPF interface commands\n"
7363 "Time between HELLO packets\n"
7365 "Address of interface\n")
7367 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7369 struct in_addr addr
;
7370 struct ospf_if_params
*params
;
7371 params
= IF_DEF_PARAMS(ifp
);
7372 uint32_t seconds
= 0;
7374 argv_find(argv
, argc
, "(1-65535)", &idx
);
7375 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7377 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7378 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7380 "Please specify interface address by A.B.C.D\n");
7381 return CMD_WARNING_CONFIG_FAILED
;
7384 params
= ospf_get_if_params(ifp
, addr
);
7385 ospf_if_update_params(ifp
, addr
);
7388 SET_IF_PARAM(params
, v_hello
);
7389 params
->v_hello
= seconds
;
7394 DEFUN_HIDDEN (ospf_hello_interval
,
7395 ospf_hello_interval_cmd
,
7396 "ospf hello-interval (1-65535) [A.B.C.D]",
7397 "OSPF interface commands\n"
7398 "Time between HELLO packets\n"
7400 "Address of interface\n")
7402 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7405 DEFUN (no_ip_ospf_hello_interval
,
7406 no_ip_ospf_hello_interval_cmd
,
7407 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7410 "OSPF interface commands\n"
7411 "Time between HELLO packets\n" // ignored
7413 "Address of interface\n")
7415 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7417 struct in_addr addr
;
7418 struct ospf_if_params
*params
;
7420 params
= IF_DEF_PARAMS(ifp
);
7422 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7423 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7425 "Please specify interface address by A.B.C.D\n");
7426 return CMD_WARNING_CONFIG_FAILED
;
7429 params
= ospf_lookup_if_params(ifp
, addr
);
7434 UNSET_IF_PARAM(params
, v_hello
);
7435 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7437 if (params
!= IF_DEF_PARAMS(ifp
)) {
7438 ospf_free_if_params(ifp
, addr
);
7439 ospf_if_update_params(ifp
, addr
);
7445 DEFUN_HIDDEN (no_ospf_hello_interval
,
7446 no_ospf_hello_interval_cmd
,
7447 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7449 "OSPF interface commands\n"
7450 "Time between HELLO packets\n" // ignored
7452 "Address of interface\n")
7454 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7457 DEFUN (ip_ospf_network
,
7458 ip_ospf_network_cmd
,
7459 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7461 "OSPF interface commands\n"
7463 "Specify OSPF broadcast multi-access network\n"
7464 "Specify OSPF NBMA network\n"
7465 "Specify OSPF point-to-multipoint network\n"
7466 "Specify OSPF point-to-point network\n")
7468 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7470 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7471 struct route_node
*rn
;
7473 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7475 "This is a loopback interface. Can't set network type.\n");
7476 return CMD_WARNING_CONFIG_FAILED
;
7479 if (argv_find(argv
, argc
, "broadcast", &idx
))
7480 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7481 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7482 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7483 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7484 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7485 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7486 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7488 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7491 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7493 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7494 struct ospf_interface
*oi
= rn
->info
;
7499 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7501 if (oi
->state
> ISM_Down
) {
7502 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7503 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7510 DEFUN_HIDDEN (ospf_network
,
7512 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7513 "OSPF interface commands\n"
7515 "Specify OSPF broadcast multi-access network\n"
7516 "Specify OSPF NBMA network\n"
7517 "Specify OSPF point-to-multipoint network\n"
7518 "Specify OSPF point-to-point network\n")
7520 return ip_ospf_network(self
, vty
, argc
, argv
);
7523 DEFUN (no_ip_ospf_network
,
7524 no_ip_ospf_network_cmd
,
7525 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7528 "OSPF interface commands\n"
7530 "Specify OSPF broadcast multi-access network\n"
7531 "Specify OSPF NBMA network\n"
7532 "Specify OSPF point-to-multipoint network\n"
7533 "Specify OSPF point-to-point network\n")
7535 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7536 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7537 struct route_node
*rn
;
7539 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7541 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7544 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7545 struct ospf_interface
*oi
= rn
->info
;
7550 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7552 if (oi
->state
> ISM_Down
) {
7553 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7554 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7561 DEFUN_HIDDEN (no_ospf_network
,
7562 no_ospf_network_cmd
,
7563 "no 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 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7575 DEFUN (ip_ospf_priority
,
7576 ip_ospf_priority_cmd
,
7577 "ip ospf priority (0-255) [A.B.C.D]",
7579 "OSPF interface commands\n"
7582 "Address of interface\n")
7584 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7587 struct route_node
*rn
;
7588 struct in_addr addr
;
7589 struct ospf_if_params
*params
;
7590 params
= IF_DEF_PARAMS(ifp
);
7592 argv_find(argv
, argc
, "(0-255)", &idx
);
7593 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7595 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7596 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7598 "Please specify interface address by A.B.C.D\n");
7599 return CMD_WARNING_CONFIG_FAILED
;
7602 params
= ospf_get_if_params(ifp
, addr
);
7603 ospf_if_update_params(ifp
, addr
);
7606 SET_IF_PARAM(params
, priority
);
7607 params
->priority
= priority
;
7609 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7610 struct ospf_interface
*oi
= rn
->info
;
7615 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7616 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7617 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7624 DEFUN_HIDDEN (ospf_priority
,
7626 "ospf priority (0-255) [A.B.C.D]",
7627 "OSPF interface commands\n"
7630 "Address of interface\n")
7632 return ip_ospf_priority(self
, vty
, argc
, argv
);
7635 DEFUN (no_ip_ospf_priority
,
7636 no_ip_ospf_priority_cmd
,
7637 "no ip ospf priority [(0-255) [A.B.C.D]]",
7640 "OSPF interface commands\n"
7641 "Router priority\n" // ignored
7643 "Address of interface\n")
7645 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7647 struct route_node
*rn
;
7648 struct in_addr addr
;
7649 struct ospf_if_params
*params
;
7651 params
= IF_DEF_PARAMS(ifp
);
7653 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7654 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7656 "Please specify interface address by A.B.C.D\n");
7657 return CMD_WARNING_CONFIG_FAILED
;
7660 params
= ospf_lookup_if_params(ifp
, addr
);
7665 UNSET_IF_PARAM(params
, priority
);
7666 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7668 if (params
!= IF_DEF_PARAMS(ifp
)) {
7669 ospf_free_if_params(ifp
, addr
);
7670 ospf_if_update_params(ifp
, addr
);
7673 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7674 struct ospf_interface
*oi
= rn
->info
;
7679 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7680 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7681 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7688 DEFUN_HIDDEN (no_ospf_priority
,
7689 no_ospf_priority_cmd
,
7690 "no ospf priority [(0-255) [A.B.C.D]]",
7692 "OSPF interface commands\n"
7695 "Address of interface\n")
7697 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7700 DEFUN (ip_ospf_retransmit_interval
,
7701 ip_ospf_retransmit_interval_addr_cmd
,
7702 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7704 "OSPF interface commands\n"
7705 "Time between retransmitting lost link state advertisements\n"
7707 "Address of interface\n")
7709 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7712 struct in_addr addr
;
7713 struct ospf_if_params
*params
;
7714 params
= IF_DEF_PARAMS(ifp
);
7716 argv_find(argv
, argc
, "(3-65535)", &idx
);
7717 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7719 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7720 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7722 "Please specify interface address by A.B.C.D\n");
7723 return CMD_WARNING_CONFIG_FAILED
;
7726 params
= ospf_get_if_params(ifp
, addr
);
7727 ospf_if_update_params(ifp
, addr
);
7730 SET_IF_PARAM(params
, retransmit_interval
);
7731 params
->retransmit_interval
= seconds
;
7736 DEFUN_HIDDEN (ospf_retransmit_interval
,
7737 ospf_retransmit_interval_cmd
,
7738 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7739 "OSPF interface commands\n"
7740 "Time between retransmitting lost link state advertisements\n"
7742 "Address of interface\n")
7744 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7747 DEFUN (no_ip_ospf_retransmit_interval
,
7748 no_ip_ospf_retransmit_interval_addr_cmd
,
7749 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7752 "OSPF interface commands\n"
7753 "Time between retransmitting lost link state advertisements\n"
7755 "Address of interface\n")
7757 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7759 struct in_addr addr
;
7760 struct ospf_if_params
*params
;
7762 params
= IF_DEF_PARAMS(ifp
);
7764 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7765 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7767 "Please specify interface address by A.B.C.D\n");
7768 return CMD_WARNING_CONFIG_FAILED
;
7771 params
= ospf_lookup_if_params(ifp
, addr
);
7776 UNSET_IF_PARAM(params
, retransmit_interval
);
7777 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7779 if (params
!= IF_DEF_PARAMS(ifp
)) {
7780 ospf_free_if_params(ifp
, addr
);
7781 ospf_if_update_params(ifp
, addr
);
7787 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7788 no_ospf_retransmit_interval_cmd
,
7789 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7791 "OSPF interface commands\n"
7792 "Time between retransmitting lost link state advertisements\n"
7794 "Address of interface\n")
7796 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7799 DEFUN (ip_ospf_transmit_delay
,
7800 ip_ospf_transmit_delay_addr_cmd
,
7801 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7803 "OSPF interface commands\n"
7804 "Link state transmit delay\n"
7806 "Address of interface\n")
7808 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7811 struct in_addr addr
;
7812 struct ospf_if_params
*params
;
7814 params
= IF_DEF_PARAMS(ifp
);
7815 argv_find(argv
, argc
, "(1-65535)", &idx
);
7816 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7818 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7819 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7821 "Please specify interface address by A.B.C.D\n");
7822 return CMD_WARNING_CONFIG_FAILED
;
7825 params
= ospf_get_if_params(ifp
, addr
);
7826 ospf_if_update_params(ifp
, addr
);
7829 SET_IF_PARAM(params
, transmit_delay
);
7830 params
->transmit_delay
= seconds
;
7835 DEFUN_HIDDEN (ospf_transmit_delay
,
7836 ospf_transmit_delay_cmd
,
7837 "ospf transmit-delay (1-65535) [A.B.C.D]",
7838 "OSPF interface commands\n"
7839 "Link state transmit delay\n"
7841 "Address of interface\n")
7843 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7846 DEFUN (no_ip_ospf_transmit_delay
,
7847 no_ip_ospf_transmit_delay_addr_cmd
,
7848 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7851 "OSPF interface commands\n"
7852 "Link state transmit delay\n"
7854 "Address of interface\n")
7856 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7858 struct in_addr addr
;
7859 struct ospf_if_params
*params
;
7861 params
= IF_DEF_PARAMS(ifp
);
7863 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7864 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7866 "Please specify interface address by A.B.C.D\n");
7867 return CMD_WARNING_CONFIG_FAILED
;
7870 params
= ospf_lookup_if_params(ifp
, addr
);
7875 UNSET_IF_PARAM(params
, transmit_delay
);
7876 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7878 if (params
!= IF_DEF_PARAMS(ifp
)) {
7879 ospf_free_if_params(ifp
, addr
);
7880 ospf_if_update_params(ifp
, addr
);
7887 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7888 no_ospf_transmit_delay_cmd
,
7889 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7891 "OSPF interface commands\n"
7892 "Link state transmit delay\n"
7894 "Address of interface\n")
7896 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7899 DEFUN (ip_ospf_area
,
7901 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7903 "OSPF interface commands\n"
7905 "Enable OSPF on this interface\n"
7906 "OSPF area ID in IP address format\n"
7907 "OSPF area ID as a decimal value\n"
7908 "Address of interface\n")
7910 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7913 struct in_addr area_id
;
7914 struct in_addr addr
;
7915 struct ospf_if_params
*params
= NULL
;
7916 struct route_node
*rn
;
7917 struct ospf
*ospf
= NULL
;
7918 unsigned short instance
= 0;
7921 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7922 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7924 argv_find(argv
, argc
, "area", &idx
);
7925 areaid
= argv
[idx
+ 1]->arg
;
7927 if (ifp
->vrf_id
&& !instance
)
7928 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7930 ospf
= ospf_lookup_instance(instance
);
7932 if (instance
&& ospf
== NULL
) {
7933 params
= IF_DEF_PARAMS(ifp
);
7934 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7935 UNSET_IF_PARAM(params
, if_area
);
7936 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7937 ospf_interface_area_unset(ospf
, ifp
);
7938 ospf
->if_ospf_cli_count
--;
7940 return CMD_NOT_MY_INSTANCE
;
7943 ret
= str2area_id(areaid
, &area_id
, &format
);
7945 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
7946 return CMD_WARNING_CONFIG_FAILED
;
7948 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
7949 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
7950 return CMD_WARNING_CONFIG_FAILED
;
7953 params
= IF_DEF_PARAMS(ifp
);
7954 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
7955 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
7957 "Must remove previous area config before changing ospf area \n");
7958 return CMD_WARNING_CONFIG_FAILED
;
7961 // Check if we have an address arg and proccess it
7962 if (argc
== idx
+ 3) {
7963 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
7965 "Please specify Intf Address by A.B.C.D\n");
7966 return CMD_WARNING_CONFIG_FAILED
;
7968 // update/create address-level params
7969 params
= ospf_get_if_params((ifp
), (addr
));
7970 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7972 "Must remove previous area/address config before changing ospf area");
7973 return CMD_WARNING_CONFIG_FAILED
;
7975 ospf_if_update_params((ifp
), (addr
));
7979 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
7980 if (rn
->info
!= NULL
) {
7982 "Please remove all network commands first.\n");
7983 return CMD_WARNING_CONFIG_FAILED
;
7988 /* enable ospf on this interface with area_id */
7990 SET_IF_PARAM(params
, if_area
);
7991 params
->if_area
= area_id
;
7992 params
->if_area_id_fmt
= format
;
7996 ospf_interface_area_set(ospf
, ifp
);
7997 ospf
->if_ospf_cli_count
++;
8003 DEFUN (no_ip_ospf_area
,
8004 no_ip_ospf_area_cmd
,
8005 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8008 "OSPF interface commands\n"
8010 "Disable OSPF on this interface\n"
8011 "OSPF area ID in IP address format\n"
8012 "OSPF area ID as a decimal value\n"
8013 "Address of interface\n")
8015 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8018 struct ospf_if_params
*params
;
8019 unsigned short instance
= 0;
8020 struct in_addr addr
;
8022 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8023 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8025 if (ifp
->vrf_id
&& !instance
)
8026 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8028 ospf
= ospf_lookup_instance(instance
);
8031 return CMD_NOT_MY_INSTANCE
;
8033 argv_find(argv
, argc
, "area", &idx
);
8035 // Check if we have an address arg and proccess it
8036 if (argc
== idx
+ 3) {
8037 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8039 "Please specify Intf Address by A.B.C.D\n");
8040 return CMD_WARNING_CONFIG_FAILED
;
8042 params
= ospf_lookup_if_params(ifp
, addr
);
8043 if ((params
) == NULL
)
8046 params
= IF_DEF_PARAMS(ifp
);
8048 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8050 "Can't find specified interface area configuration.\n");
8051 return CMD_WARNING_CONFIG_FAILED
;
8054 UNSET_IF_PARAM(params
, if_area
);
8055 if (params
!= IF_DEF_PARAMS((ifp
))) {
8056 ospf_free_if_params((ifp
), (addr
));
8057 ospf_if_update_params((ifp
), (addr
));
8060 ospf_interface_area_unset(ospf
, ifp
);
8061 ospf
->if_ospf_cli_count
--;
8065 DEFUN (ospf_redistribute_source
,
8066 ospf_redistribute_source_cmd
,
8067 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8069 FRR_REDIST_HELP_STR_OSPFD
8070 "Metric for redistributed routes\n"
8071 "OSPF default metric\n"
8072 "OSPF exterior metric type for redistributed routes\n"
8073 "Set OSPF External Type 1/2 metrics\n"
8074 "Route map reference\n"
8075 "Pointer to route-map entries\n")
8077 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8078 int idx_protocol
= 1;
8082 struct ospf_redist
*red
;
8085 /* Get distribute source. */
8086 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8088 return CMD_WARNING_CONFIG_FAILED
;
8090 red
= ospf_redist_add(ospf
, source
, 0);
8092 /* Get metric value. */
8093 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8094 if (!str2metric(argv
[idx
]->arg
, &metric
))
8095 return CMD_WARNING_CONFIG_FAILED
;
8098 /* Get metric type. */
8099 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8100 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8101 return CMD_WARNING_CONFIG_FAILED
;
8105 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8106 ospf_routemap_set(red
, argv
[idx
]->arg
);
8108 ospf_routemap_unset(red
);
8110 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8113 DEFUN (no_ospf_redistribute_source
,
8114 no_ospf_redistribute_source_cmd
,
8115 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8118 FRR_REDIST_HELP_STR_OSPFD
8119 "Metric for redistributed routes\n"
8120 "OSPF default metric\n"
8121 "OSPF exterior metric type for redistributed routes\n"
8122 "Set OSPF External Type 1/2 metrics\n"
8123 "Route map reference\n"
8124 "Pointer to route-map entries\n")
8126 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8127 int idx_protocol
= 2;
8129 struct ospf_redist
*red
;
8131 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8133 return CMD_WARNING_CONFIG_FAILED
;
8135 red
= ospf_redist_lookup(ospf
, source
, 0);
8139 ospf_routemap_unset(red
);
8140 return ospf_redistribute_unset(ospf
, source
, 0);
8143 DEFUN (ospf_redistribute_instance_source
,
8144 ospf_redistribute_instance_source_cmd
,
8145 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8147 "Open Shortest Path First\n"
8148 "Non-main Kernel Routing Table\n"
8149 "Instance ID/Table ID\n"
8150 "Metric for redistributed routes\n"
8151 "OSPF default metric\n"
8152 "OSPF exterior metric type for redistributed routes\n"
8153 "Set OSPF External Type 1/2 metrics\n"
8154 "Route map reference\n"
8155 "Pointer to route-map entries\n")
8157 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8158 int idx_ospf_table
= 1;
8164 unsigned short instance
;
8165 struct ospf_redist
*red
;
8167 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8169 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8171 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8173 "Instance redistribution in non-instanced OSPF not allowed\n");
8174 return CMD_WARNING_CONFIG_FAILED
;
8177 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8178 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8179 return CMD_WARNING_CONFIG_FAILED
;
8182 /* Get metric value. */
8183 if (argv_find(argv
, argc
, "metric", &idx
))
8184 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8185 return CMD_WARNING_CONFIG_FAILED
;
8188 /* Get metric type. */
8189 if (argv_find(argv
, argc
, "metric-type", &idx
))
8190 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8191 return CMD_WARNING_CONFIG_FAILED
;
8193 red
= ospf_redist_add(ospf
, source
, instance
);
8196 if (argv_find(argv
, argc
, "route-map", &idx
))
8197 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8199 ospf_routemap_unset(red
);
8201 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8204 DEFUN (no_ospf_redistribute_instance_source
,
8205 no_ospf_redistribute_instance_source_cmd
,
8206 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8209 "Open Shortest Path First\n"
8210 "Non-main Kernel Routing Table\n"
8211 "Instance ID/Table Id\n"
8212 "Metric for redistributed routes\n"
8213 "OSPF default metric\n"
8214 "OSPF exterior metric type for redistributed routes\n"
8215 "Set OSPF External Type 1/2 metrics\n"
8216 "Route map reference\n"
8217 "Pointer to route-map entries\n")
8219 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8220 int idx_ospf_table
= 2;
8222 unsigned int instance
;
8223 struct ospf_redist
*red
;
8226 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8227 source
= ZEBRA_ROUTE_OSPF
;
8229 source
= ZEBRA_ROUTE_TABLE
;
8231 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8233 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8235 "Instance redistribution in non-instanced OSPF not allowed\n");
8236 return CMD_WARNING_CONFIG_FAILED
;
8239 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8240 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8241 return CMD_WARNING_CONFIG_FAILED
;
8244 red
= ospf_redist_lookup(ospf
, source
, instance
);
8248 ospf_routemap_unset(red
);
8249 return ospf_redistribute_unset(ospf
, source
, instance
);
8252 DEFUN (ospf_distribute_list_out
,
8253 ospf_distribute_list_out_cmd
,
8254 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8255 "Filter networks in routing updates\n"
8256 "Access-list name\n"
8258 FRR_REDIST_HELP_STR_OSPFD
)
8260 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8264 char *proto
= argv
[argc
- 1]->text
;
8266 /* Get distribute source. */
8267 source
= proto_redistnum(AFI_IP
, proto
);
8269 return CMD_WARNING_CONFIG_FAILED
;
8271 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8274 DEFUN (no_ospf_distribute_list_out
,
8275 no_ospf_distribute_list_out_cmd
,
8276 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8278 "Filter networks in routing updates\n"
8279 "Access-list name\n"
8281 FRR_REDIST_HELP_STR_OSPFD
)
8283 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8287 char *proto
= argv
[argc
- 1]->text
;
8288 source
= proto_redistnum(AFI_IP
, proto
);
8290 return CMD_WARNING_CONFIG_FAILED
;
8292 return ospf_distribute_list_out_unset(ospf
, source
,
8293 argv
[idx_word
]->arg
);
8296 /* Default information originate. */
8297 DEFUN (ospf_default_information_originate
,
8298 ospf_default_information_originate_cmd
,
8299 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8300 "Control distribution of default information\n"
8301 "Distribute a default route\n"
8302 "Always advertise default route\n"
8303 "OSPF default metric\n"
8305 "OSPF metric type for default routes\n"
8306 "Set OSPF External Type 1/2 metrics\n"
8307 "Route map reference\n"
8308 "Pointer to route-map entries\n")
8310 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8311 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8314 struct ospf_redist
*red
;
8317 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8319 /* Check whether "always" was specified */
8320 if (argv_find(argv
, argc
, "always", &idx
))
8321 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8323 /* Get metric value */
8324 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8325 if (!str2metric(argv
[idx
]->arg
, &metric
))
8326 return CMD_WARNING_CONFIG_FAILED
;
8329 /* Get metric type. */
8330 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8331 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8332 return CMD_WARNING_CONFIG_FAILED
;
8336 if (argv_find(argv
, argc
, "WORD", &idx
))
8337 ospf_routemap_set(red
, argv
[idx
]->arg
);
8339 ospf_routemap_unset(red
);
8341 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8345 DEFUN (no_ospf_default_information_originate
,
8346 no_ospf_default_information_originate_cmd
,
8347 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8349 "Control distribution of default information\n"
8350 "Distribute a default route\n"
8351 "Always advertise default route\n"
8352 "OSPF default metric\n"
8354 "OSPF metric type for default routes\n"
8355 "Set OSPF External Type 1/2 metrics\n"
8356 "Route map reference\n"
8357 "Pointer to route-map entries\n")
8359 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8360 struct prefix_ipv4 p
;
8361 struct ospf_external
*ext
;
8362 struct ospf_redist
*red
;
8365 p
.prefix
.s_addr
= 0;
8368 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8370 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8371 if (ext
&& EXTERNAL_INFO(ext
)) {
8372 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8373 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8376 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8380 ospf_routemap_unset(red
);
8381 return ospf_redistribute_default_unset(ospf
);
8384 DEFUN (ospf_default_metric
,
8385 ospf_default_metric_cmd
,
8386 "default-metric (0-16777214)",
8387 "Set metric of redistributed routes\n"
8390 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8394 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8395 return CMD_WARNING_CONFIG_FAILED
;
8397 ospf
->default_metric
= metric
;
8402 DEFUN (no_ospf_default_metric
,
8403 no_ospf_default_metric_cmd
,
8404 "no default-metric [(0-16777214)]",
8406 "Set metric of redistributed routes\n"
8409 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8411 ospf
->default_metric
= -1;
8417 DEFUN (ospf_distance
,
8420 "Administrative distance\n"
8421 "OSPF Administrative distance\n")
8423 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8426 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8431 DEFUN (no_ospf_distance
,
8432 no_ospf_distance_cmd
,
8433 "no distance (1-255)",
8435 "Administrative distance\n"
8436 "OSPF Administrative distance\n")
8438 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8440 ospf
->distance_all
= 0;
8445 DEFUN (no_ospf_distance_ospf
,
8446 no_ospf_distance_ospf_cmd
,
8447 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8449 "Administrative distance\n"
8450 "OSPF administrative distance\n"
8451 "Intra-area routes\n"
8452 "Distance for intra-area routes\n"
8453 "Inter-area routes\n"
8454 "Distance for inter-area routes\n"
8456 "Distance for external routes\n")
8458 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8461 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8462 idx
= ospf
->distance_intra
= 0;
8463 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8464 idx
= ospf
->distance_inter
= 0;
8465 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8466 ospf
->distance_external
= 0;
8471 DEFUN (ospf_distance_ospf
,
8472 ospf_distance_ospf_cmd
,
8473 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8474 "Administrative distance\n"
8475 "OSPF administrative distance\n"
8476 "Intra-area routes\n"
8477 "Distance for intra-area routes\n"
8478 "Inter-area routes\n"
8479 "Distance for inter-area routes\n"
8481 "Distance for external routes\n")
8483 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8486 ospf
->distance_intra
= 0;
8487 ospf
->distance_inter
= 0;
8488 ospf
->distance_external
= 0;
8490 if (argv_find(argv
, argc
, "intra-area", &idx
))
8491 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8493 if (argv_find(argv
, argc
, "inter-area", &idx
))
8494 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8496 if (argv_find(argv
, argc
, "external", &idx
))
8497 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8503 DEFUN (ospf_distance_source
,
8504 ospf_distance_source_cmd
,
8505 "distance (1-255) A.B.C.D/M",
8506 "Administrative distance\n"
8508 "IP source prefix\n")
8510 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8512 int idx_ipv4_prefixlen
= 2;
8514 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8519 DEFUN (no_ospf_distance_source
,
8520 no_ospf_distance_source_cmd
,
8521 "no distance (1-255) A.B.C.D/M",
8523 "Administrative distance\n"
8525 "IP source prefix\n")
8527 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8529 int idx_ipv4_prefixlen
= 3;
8531 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8536 DEFUN (ospf_distance_source_access_list
,
8537 ospf_distance_source_access_list_cmd
,
8538 "distance (1-255) A.B.C.D/M WORD",
8539 "Administrative distance\n"
8541 "IP source prefix\n"
8542 "Access list name\n")
8544 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8546 int idx_ipv4_prefixlen
= 2;
8549 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8554 DEFUN (no_ospf_distance_source_access_list
,
8555 no_ospf_distance_source_access_list_cmd
,
8556 "no distance (1-255) A.B.C.D/M WORD",
8558 "Administrative distance\n"
8560 "IP source prefix\n"
8561 "Access list name\n")
8563 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8565 int idx_ipv4_prefixlen
= 3;
8568 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8574 DEFUN (ip_ospf_mtu_ignore
,
8575 ip_ospf_mtu_ignore_addr_cmd
,
8576 "ip ospf mtu-ignore [A.B.C.D]",
8578 "OSPF interface commands\n"
8579 "Disable MTU mismatch detection on this interface\n"
8580 "Address of interface\n")
8582 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8584 struct in_addr addr
;
8587 struct ospf_if_params
*params
;
8588 params
= IF_DEF_PARAMS(ifp
);
8591 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8594 "Please specify interface address by A.B.C.D\n");
8595 return CMD_WARNING_CONFIG_FAILED
;
8597 params
= ospf_get_if_params(ifp
, addr
);
8598 ospf_if_update_params(ifp
, addr
);
8600 params
->mtu_ignore
= 1;
8601 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8602 SET_IF_PARAM(params
, mtu_ignore
);
8604 UNSET_IF_PARAM(params
, mtu_ignore
);
8605 if (params
!= IF_DEF_PARAMS(ifp
)) {
8606 ospf_free_if_params(ifp
, addr
);
8607 ospf_if_update_params(ifp
, addr
);
8613 DEFUN (no_ip_ospf_mtu_ignore
,
8614 no_ip_ospf_mtu_ignore_addr_cmd
,
8615 "no ip ospf mtu-ignore [A.B.C.D]",
8618 "OSPF interface commands\n"
8619 "Disable MTU mismatch detection on this interface\n"
8620 "Address of interface\n")
8622 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8624 struct in_addr addr
;
8627 struct ospf_if_params
*params
;
8628 params
= IF_DEF_PARAMS(ifp
);
8631 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8634 "Please specify interface address by A.B.C.D\n");
8635 return CMD_WARNING_CONFIG_FAILED
;
8637 params
= ospf_get_if_params(ifp
, addr
);
8638 ospf_if_update_params(ifp
, addr
);
8640 params
->mtu_ignore
= 0;
8641 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8642 SET_IF_PARAM(params
, mtu_ignore
);
8644 UNSET_IF_PARAM(params
, mtu_ignore
);
8645 if (params
!= IF_DEF_PARAMS(ifp
)) {
8646 ospf_free_if_params(ifp
, addr
);
8647 ospf_if_update_params(ifp
, addr
);
8654 DEFUN (ospf_max_metric_router_lsa_admin
,
8655 ospf_max_metric_router_lsa_admin_cmd
,
8656 "max-metric router-lsa administrative",
8657 "OSPF maximum / infinite-distance metric\n"
8658 "Advertise own Router-LSA with infinite distance (stub router)\n"
8659 "Administratively applied, for an indefinite period\n")
8661 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8662 struct listnode
*ln
;
8663 struct ospf_area
*area
;
8665 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8666 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8668 if (!CHECK_FLAG(area
->stub_router_state
,
8669 OSPF_AREA_IS_STUB_ROUTED
))
8670 ospf_router_lsa_update_area(area
);
8673 /* Allows for areas configured later to get the property */
8674 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8679 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8680 no_ospf_max_metric_router_lsa_admin_cmd
,
8681 "no max-metric router-lsa administrative",
8683 "OSPF maximum / infinite-distance metric\n"
8684 "Advertise own Router-LSA with infinite distance (stub router)\n"
8685 "Administratively applied, for an indefinite period\n")
8687 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8688 struct listnode
*ln
;
8689 struct ospf_area
*area
;
8691 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8692 UNSET_FLAG(area
->stub_router_state
,
8693 OSPF_AREA_ADMIN_STUB_ROUTED
);
8695 /* Don't trample on the start-up stub timer */
8696 if (CHECK_FLAG(area
->stub_router_state
,
8697 OSPF_AREA_IS_STUB_ROUTED
)
8698 && !area
->t_stub_router
) {
8699 UNSET_FLAG(area
->stub_router_state
,
8700 OSPF_AREA_IS_STUB_ROUTED
);
8701 ospf_router_lsa_update_area(area
);
8704 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8708 DEFUN (ospf_max_metric_router_lsa_startup
,
8709 ospf_max_metric_router_lsa_startup_cmd
,
8710 "max-metric router-lsa on-startup (5-86400)",
8711 "OSPF maximum / infinite-distance metric\n"
8712 "Advertise own Router-LSA with infinite distance (stub router)\n"
8713 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8714 "Time (seconds) to advertise self as stub-router\n")
8716 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8718 unsigned int seconds
;
8721 vty_out(vty
, "%% Must supply stub-router period");
8722 return CMD_WARNING_CONFIG_FAILED
;
8725 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8727 ospf
->stub_router_startup_time
= seconds
;
8732 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8733 no_ospf_max_metric_router_lsa_startup_cmd
,
8734 "no max-metric router-lsa on-startup [(5-86400)]",
8736 "OSPF maximum / infinite-distance metric\n"
8737 "Advertise own Router-LSA with infinite distance (stub router)\n"
8738 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8739 "Time (seconds) to advertise self as stub-router\n")
8741 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8742 struct listnode
*ln
;
8743 struct ospf_area
*area
;
8745 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8747 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8748 SET_FLAG(area
->stub_router_state
,
8749 OSPF_AREA_WAS_START_STUB_ROUTED
);
8750 OSPF_TIMER_OFF(area
->t_stub_router
);
8752 /* Don't trample on admin stub routed */
8753 if (!CHECK_FLAG(area
->stub_router_state
,
8754 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8755 UNSET_FLAG(area
->stub_router_state
,
8756 OSPF_AREA_IS_STUB_ROUTED
);
8757 ospf_router_lsa_update_area(area
);
8764 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8765 ospf_max_metric_router_lsa_shutdown_cmd
,
8766 "max-metric router-lsa on-shutdown (5-100)",
8767 "OSPF maximum / infinite-distance metric\n"
8768 "Advertise own Router-LSA with infinite distance (stub router)\n"
8769 "Advertise stub-router prior to full shutdown of OSPF\n"
8770 "Time (seconds) to wait till full shutdown\n")
8772 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8774 unsigned int seconds
;
8777 vty_out(vty
, "%% Must supply stub-router shutdown period");
8778 return CMD_WARNING_CONFIG_FAILED
;
8781 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8783 ospf
->stub_router_shutdown_time
= seconds
;
8788 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8789 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8790 "no max-metric router-lsa on-shutdown [(5-100)]",
8792 "OSPF maximum / infinite-distance metric\n"
8793 "Advertise own Router-LSA with infinite distance (stub router)\n"
8794 "Advertise stub-router prior to full shutdown of OSPF\n"
8795 "Time (seconds) to wait till full shutdown\n")
8797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8799 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8804 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8806 struct listnode
*ln
;
8807 struct ospf_area
*area
;
8809 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8810 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8811 ospf
->stub_router_startup_time
);
8812 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8813 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8814 ospf
->stub_router_shutdown_time
);
8815 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8816 if (CHECK_FLAG(area
->stub_router_state
,
8817 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8818 vty_out(vty
, " max-metric router-lsa administrative\n");
8825 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8826 struct route_table
*rt
,
8829 struct route_node
*rn
;
8830 struct ospf_route
* or ;
8831 struct listnode
*pnode
, *pnnode
;
8832 struct ospf_path
*path
;
8833 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8834 *json_nexthop
= NULL
;
8838 "============ OSPF network routing table ============\n");
8840 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8841 if ((or = rn
->info
) == NULL
)
8843 char buf1
[PREFIX2STR_BUFFER
];
8845 memset(buf1
, 0, sizeof(buf1
));
8846 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8848 json_route
= json_object_new_object();
8850 json_object_object_add(json
, buf1
, json_route
);
8851 json_object_to_json_string_ext(
8852 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8855 switch (or->path_type
) {
8856 case OSPF_PATH_INTER_AREA
:
8857 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8859 json_object_string_add(json_route
,
8862 json_object_int_add(json_route
, "cost",
8864 json_object_string_add(
8866 inet_ntoa(or->u
.std
.area_id
));
8869 "N IA %-18s [%d] area: %s\n",
8871 inet_ntoa(or->u
.std
.area_id
));
8873 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8875 json_object_string_add(json_route
,
8880 "D IA %-18s Discard entry\n",
8885 case OSPF_PATH_INTRA_AREA
:
8887 json_object_string_add(json_route
, "routeType",
8889 json_object_int_add(json_route
, "cost",
8891 json_object_string_add(
8893 inet_ntoa(or->u
.std
.area_id
));
8895 vty_out(vty
, "N %-18s [%d] area: %s\n",
8897 inet_ntoa(or->u
.std
.area_id
));
8904 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8906 json_nexthop_array
= json_object_new_array();
8907 json_object_object_add(json_route
, "nexthops",
8908 json_nexthop_array
);
8911 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8914 json_nexthop
= json_object_new_object();
8915 json_object_array_add(
8919 if (if_lookup_by_index(path
->ifindex
,
8922 if (path
->nexthop
.s_addr
== 0) {
8924 json_object_string_add(
8927 json_object_string_add(
8929 "directly attached to",
8935 "%24s directly attached to %s\n",
8943 json_object_string_add(
8948 json_object_string_add(
8956 "%24s via %s, %s\n",
8969 json_object_free(json_route
);
8975 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
8976 struct route_table
*rtrs
,
8979 struct route_node
*rn
;
8980 struct ospf_route
* or ;
8981 struct listnode
*pnode
;
8982 struct listnode
*node
;
8983 struct ospf_path
*path
;
8984 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8985 *json_nexthop
= NULL
;
8989 "============ OSPF router routing table =============\n");
8991 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
8992 if (rn
->info
== NULL
)
8996 json_route
= json_object_new_object();
8998 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9000 json_object_string_add(json_route
, "routeType", "R ");
9002 vty_out(vty
, "R %-15s ",
9003 inet_ntoa(rn
->p
.u
.prefix4
));
9006 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9009 vty_out(vty
, "%24s", "");
9014 json_object_int_add(json_route
, "cost",
9016 json_object_string_add(
9018 inet_ntoa(or->u
.std
.area_id
));
9019 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9020 json_object_boolean_true_add(json_route
,
9022 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9023 json_object_string_add(json_route
,
9026 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9027 json_object_string_add(json_route
,
9031 vty_out(vty
, "%s [%d] area: %s",
9032 (or->path_type
== OSPF_PATH_INTER_AREA
9035 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9037 vty_out(vty
, "%s%s\n",
9038 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9041 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9047 json_nexthop_array
= json_object_new_array();
9048 json_object_object_add(json_route
, "nexthops",
9049 json_nexthop_array
);
9052 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9054 json_nexthop
= json_object_new_object();
9055 json_object_array_add(
9059 if (if_lookup_by_index(path
->ifindex
,
9061 if (path
->nexthop
.s_addr
== 0) {
9063 json_object_string_add(
9066 json_object_string_add(
9068 "directly attached to",
9074 "%24s directly attached to %s\n",
9082 json_object_string_add(
9087 json_object_string_add(
9095 "%24s via %s, %s\n",
9108 json_object_free(json_route
);
9114 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9115 struct route_table
*rt
,
9118 struct route_node
*rn
;
9119 struct ospf_route
*er
;
9120 struct listnode
*pnode
, *pnnode
;
9121 struct ospf_path
*path
;
9122 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9123 *json_nexthop
= NULL
;
9127 "============ OSPF external routing table ===========\n");
9129 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9130 if ((er
= rn
->info
) == NULL
)
9135 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9137 json_route
= json_object_new_object();
9139 json_object_object_add(json
, buf1
, json_route
);
9140 json_object_to_json_string_ext(
9141 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9144 switch (er
->path_type
) {
9145 case OSPF_PATH_TYPE1_EXTERNAL
:
9147 json_object_string_add(json_route
, "routeType",
9149 json_object_int_add(json_route
, "cost",
9153 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9155 buf1
, er
->cost
, er
->u
.ext
.tag
);
9158 case OSPF_PATH_TYPE2_EXTERNAL
:
9160 json_object_string_add(json_route
, "routeType",
9162 json_object_int_add(json_route
, "cost",
9166 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9168 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9175 json_nexthop_array
= json_object_new_array();
9176 json_object_object_add(json_route
, "nexthops",
9177 json_nexthop_array
);
9180 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9182 json_nexthop
= json_object_new_object();
9183 json_object_array_add(json_nexthop_array
,
9187 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9188 if (path
->nexthop
.s_addr
== 0) {
9190 json_object_string_add(
9193 json_object_string_add(
9195 "directly attached to",
9201 "%24s directly attached to %s\n",
9209 json_object_string_add(
9213 json_object_string_add(
9214 json_nexthop
, "via",
9220 "%24s via %s, %s\n",
9232 json_object_free(json_route
);
9238 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9243 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9245 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9247 if (ospf
->new_table
== NULL
) {
9248 vty_out(vty
, "No OSPF routing information exist\n");
9252 /* Show Network routes.
9253 show_ip_ospf_route_network (vty, ospf->new_table); */
9255 /* Show Router routes. */
9256 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9263 DEFUN (show_ip_ospf_border_routers
,
9264 show_ip_ospf_border_routers_cmd
,
9265 "show ip ospf [vrf <NAME|all>] border-routers",
9268 "OSPF information\n"
9271 "Show all the ABR's and ASBR's\n")
9273 struct ospf
*ospf
= NULL
;
9274 struct listnode
*node
= NULL
;
9275 char *vrf_name
= NULL
;
9276 bool all_vrf
= FALSE
;
9277 int ret
= CMD_SUCCESS
;
9280 uint8_t use_vrf
= 0;
9282 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9287 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9288 if (!ospf
->oi_running
)
9291 ret
= show_ip_ospf_border_routers_common(
9292 vty
, ospf
, use_vrf
);
9295 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9296 if (ospf
== NULL
|| !ospf
->oi_running
)
9299 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9303 /* Display default ospf (instance 0) info */
9304 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9305 if (ospf
== NULL
|| !ospf
->oi_running
)
9307 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9313 DEFUN (show_ip_ospf_instance_border_routers
,
9314 show_ip_ospf_instance_border_routers_cmd
,
9315 "show ip ospf (1-65535) border-routers",
9318 "OSPF information\n"
9320 "Show all the ABR's and ASBR's\n")
9324 unsigned short instance
= 0;
9326 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9327 ospf
= ospf_lookup_instance(instance
);
9329 return CMD_NOT_MY_INSTANCE
;
9331 if (!ospf
->oi_running
)
9334 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9337 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9338 json_object
*json
, uint8_t use_vrf
)
9340 json_object
*json_vrf
= NULL
;
9343 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9348 json_vrf
= json_object_new_object();
9353 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9355 if (ospf
->new_table
== NULL
) {
9356 vty_out(vty
, "No OSPF routing information exist\n");
9360 /* Show Network routes. */
9361 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9363 /* Show Router routes. */
9364 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9366 /* Show AS External routes. */
9367 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9372 // json_object_object_add(json_vrf, "areas",
9374 if (ospf
->vrf_id
== VRF_DEFAULT
)
9375 json_object_object_add(json
, "default",
9378 json_object_object_add(json
, ospf
->name
,
9388 DEFUN (show_ip_ospf_route
,
9389 show_ip_ospf_route_cmd
,
9390 "show ip ospf [vrf <NAME|all>] route [json]",
9393 "OSPF information\n"
9396 "OSPF routing table\n"
9399 struct ospf
*ospf
= NULL
;
9400 struct listnode
*node
= NULL
;
9401 char *vrf_name
= NULL
;
9402 bool all_vrf
= FALSE
;
9403 int ret
= CMD_SUCCESS
;
9406 uint8_t use_vrf
= 0;
9407 uint8_t uj
= use_json(argc
, argv
);
9408 json_object
*json
= NULL
;
9411 json
= json_object_new_object();
9413 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9415 /* vrf input is provided could be all or specific vrf*/
9419 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9420 if (!ospf
->oi_running
)
9422 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9427 /* Keep Non-pretty format */
9428 vty_out(vty
, "%s\n",
9429 json_object_to_json_string(json
));
9430 json_object_free(json
);
9435 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9436 if (ospf
== NULL
|| !ospf
->oi_running
) {
9438 json_object_free(json
);
9442 /* Display default ospf (instance 0) info */
9443 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9444 if (ospf
== NULL
|| !ospf
->oi_running
) {
9446 json_object_free(json
);
9452 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9453 /* Keep Non-pretty format */
9455 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9459 json_object_free(json
);
9464 DEFUN (show_ip_ospf_instance_route
,
9465 show_ip_ospf_instance_route_cmd
,
9466 "show ip ospf (1-65535) route",
9469 "OSPF information\n"
9471 "OSPF routing table\n")
9475 unsigned short instance
= 0;
9477 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9478 ospf
= ospf_lookup_instance(instance
);
9480 return CMD_NOT_MY_INSTANCE
;
9482 if (!ospf
->oi_running
)
9485 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9489 DEFUN (show_ip_ospf_vrfs
,
9490 show_ip_ospf_vrfs_cmd
,
9491 "show ip ospf vrfs [json]",
9494 "OSPF information\n"
9498 uint8_t uj
= use_json(argc
, argv
);
9499 json_object
*json
= NULL
;
9500 json_object
*json_vrfs
= NULL
;
9501 struct ospf
*ospf
= NULL
;
9502 struct listnode
*node
= NULL
;
9504 static char header
[] = "Name Id RouterId ";
9507 json
= json_object_new_object();
9508 json_vrfs
= json_object_new_object();
9511 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9512 json_object
*json_vrf
= NULL
;
9513 const char *name
= NULL
;
9514 int64_t vrf_id_ui
= 0;
9518 if (!uj
&& count
== 1)
9519 vty_out(vty
, "%s\n", header
);
9521 json_vrf
= json_object_new_object();
9523 if (ospf
->vrf_id
== 0)
9524 name
= VRF_DEFAULT_NAME
;
9528 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9530 : (int64_t)ospf
->vrf_id
;
9533 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9534 json_object_string_add(json_vrf
, "routerId",
9535 inet_ntoa(ospf
->router_id
));
9537 json_object_object_add(json_vrfs
, name
, json_vrf
);
9540 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9541 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9546 json_object_object_add(json
, "vrfs", json_vrfs
);
9547 json_object_int_add(json
, "totalVrfs", count
);
9549 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9550 json
, JSON_C_TO_STRING_PRETTY
));
9551 json_object_free(json
);
9554 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9561 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9564 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9566 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9567 "point-to-point", "broadcast",
9568 "non-broadcast", "point-to-multipoint",
9569 "virtual-link", /* should never be used. */
9572 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9574 struct listnode
*node
;
9575 struct interface
*ifp
;
9576 struct crypt_key
*ck
;
9577 struct route_node
*rn
= NULL
;
9578 struct ospf_if_params
*params
;
9580 struct ospf
*ospf
= vrf
->info
;
9582 FOR_ALL_INTERFACES (vrf
, ifp
) {
9584 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9587 vty_frame(vty
, "!\n");
9588 if (ifp
->vrf_id
== VRF_DEFAULT
)
9589 vty_frame(vty
, "interface %s\n", ifp
->name
);
9591 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9594 vty_out(vty
, " description %s\n", ifp
->desc
);
9598 params
= IF_DEF_PARAMS(ifp
);
9601 /* Interface Network print. */
9602 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9603 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9604 if (params
->type
!= ospf_default_iftype(ifp
)) {
9605 vty_out(vty
, " ip ospf network %s",
9608 if (params
!= IF_DEF_PARAMS(ifp
))
9616 /* OSPF interface authentication print */
9617 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9618 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9619 const char *auth_str
;
9621 /* Translation tables are not that much help
9622 * here due to syntax
9623 * of the simple option */
9624 switch (params
->auth_type
) {
9626 case OSPF_AUTH_NULL
:
9630 case OSPF_AUTH_SIMPLE
:
9634 case OSPF_AUTH_CRYPTOGRAPHIC
:
9635 auth_str
= " message-digest";
9643 vty_out(vty
, " ip ospf authentication%s",
9645 if (params
!= IF_DEF_PARAMS(ifp
))
9647 inet_ntoa(rn
->p
.u
.prefix4
));
9651 /* Simple Authentication Password print. */
9652 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9653 && params
->auth_simple
[0] != '\0') {
9654 vty_out(vty
, " ip ospf authentication-key %s",
9655 params
->auth_simple
);
9656 if (params
!= IF_DEF_PARAMS(ifp
))
9658 inet_ntoa(rn
->p
.u
.prefix4
));
9662 /* Cryptographic Authentication Key print. */
9663 if (params
&& params
->auth_crypt
) {
9664 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9667 " ip ospf message-digest-key %d md5 %s",
9668 ck
->key_id
, ck
->auth_key
);
9669 if (params
!= IF_DEF_PARAMS(ifp
))
9677 /* Interface Output Cost print. */
9678 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9679 vty_out(vty
, " ip ospf cost %u",
9680 params
->output_cost_cmd
);
9681 if (params
!= IF_DEF_PARAMS(ifp
))
9683 inet_ntoa(rn
->p
.u
.prefix4
));
9687 /* Hello Interval print. */
9688 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9689 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9690 vty_out(vty
, " ip ospf hello-interval %u",
9692 if (params
!= IF_DEF_PARAMS(ifp
))
9694 inet_ntoa(rn
->p
.u
.prefix4
));
9699 /* Router Dead Interval print. */
9700 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9702 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9703 vty_out(vty
, " ip ospf dead-interval ");
9706 if (OSPF_IF_PARAM_CONFIGURED(params
,
9709 "minimal hello-multiplier %d",
9710 params
->fast_hello
);
9712 vty_out(vty
, "%u", params
->v_wait
);
9714 if (params
!= IF_DEF_PARAMS(ifp
))
9716 inet_ntoa(rn
->p
.u
.prefix4
));
9720 /* Router Priority print. */
9721 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9723 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9724 vty_out(vty
, " ip ospf priority %u",
9726 if (params
!= IF_DEF_PARAMS(ifp
))
9728 inet_ntoa(rn
->p
.u
.prefix4
));
9732 /* Retransmit Interval print. */
9733 if (OSPF_IF_PARAM_CONFIGURED(params
,
9734 retransmit_interval
)
9735 && params
->retransmit_interval
9736 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9737 vty_out(vty
, " ip ospf retransmit-interval %u",
9738 params
->retransmit_interval
);
9739 if (params
!= IF_DEF_PARAMS(ifp
))
9741 inet_ntoa(rn
->p
.u
.prefix4
));
9745 /* Transmit Delay print. */
9746 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9747 && params
->transmit_delay
9748 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9749 vty_out(vty
, " ip ospf transmit-delay %u",
9750 params
->transmit_delay
);
9751 if (params
!= IF_DEF_PARAMS(ifp
))
9753 inet_ntoa(rn
->p
.u
.prefix4
));
9758 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9759 if (ospf
&& ospf
->instance
)
9760 vty_out(vty
, " ip ospf %d",
9763 vty_out(vty
, " ip ospf");
9765 char buf
[INET_ADDRSTRLEN
];
9767 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9768 params
->if_area_id_fmt
);
9769 vty_out(vty
, " area %s", buf
);
9770 if (params
!= IF_DEF_PARAMS(ifp
))
9772 inet_ntoa(rn
->p
.u
.prefix4
));
9777 if (params
&& params
->bfd_info
)
9778 ospf_bfd_write_config(vty
, params
);
9780 /* MTU ignore print. */
9781 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9782 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9783 if (params
->mtu_ignore
== 0)
9784 vty_out(vty
, " no ip ospf mtu-ignore");
9786 vty_out(vty
, " ip ospf mtu-ignore");
9787 if (params
!= IF_DEF_PARAMS(ifp
))
9789 inet_ntoa(rn
->p
.u
.prefix4
));
9796 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9798 rn
= route_next(rn
);
9808 ospf_opaque_config_write_if(vty
, ifp
);
9810 vty_endframe(vty
, NULL
);
9816 /* Configuration write function for ospfd. */
9817 static int config_write_interface(struct vty
*vty
)
9820 struct vrf
*vrf
= NULL
;
9822 /* Display all VRF aware OSPF interface configuration */
9823 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9824 write
+= config_write_interface_one(vty
, vrf
);
9830 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9832 struct route_node
*rn
;
9833 uint8_t buf
[INET_ADDRSTRLEN
];
9835 /* `network area' print. */
9836 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9838 struct ospf_network
*n
= rn
->info
;
9840 /* Create Area ID string by specified Area ID format. */
9841 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9842 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9845 sprintf((char *)buf
, "%lu",
9846 (unsigned long int)ntohl(
9847 n
->area_id
.s_addr
));
9849 /* Network print. */
9850 vty_out(vty
, " network %s/%d area %s\n",
9851 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9858 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9860 struct listnode
*node
;
9861 struct ospf_area
*area
;
9862 uint8_t buf
[INET_ADDRSTRLEN
];
9864 /* Area configuration print. */
9865 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9866 struct route_node
*rn1
;
9868 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
9871 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9872 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9873 vty_out(vty
, " area %s authentication\n", buf
);
9876 " area %s authentication message-digest\n",
9880 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9881 vty_out(vty
, " area %s shortcut %s\n", buf
,
9882 ospf_shortcut_mode_str
9883 [area
->shortcut_configured
]);
9885 if ((area
->external_routing
== OSPF_AREA_STUB
)
9886 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9887 if (area
->external_routing
== OSPF_AREA_STUB
) {
9888 vty_out(vty
, " area %s stub", buf
);
9889 if (area
->no_summary
)
9890 vty_out(vty
, " no-summary\n");
9892 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9893 switch (area
->NSSATranslatorRole
) {
9894 case OSPF_NSSA_ROLE_NEVER
:
9896 " area %s nssa translate-never\n",
9899 case OSPF_NSSA_ROLE_ALWAYS
:
9901 " area %s nssa translate-always\n",
9904 case OSPF_NSSA_ROLE_CANDIDATE
:
9905 vty_out(vty
, " area %s nssa \n", buf
);
9908 if (area
->no_summary
)
9910 " area %s nssa no-summary\n",
9914 if (area
->default_cost
!= 1)
9915 vty_out(vty
, " area %s default-cost %d\n", buf
,
9916 area
->default_cost
);
9919 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
9921 struct ospf_area_range
*range
= rn1
->info
;
9923 vty_out(vty
, " area %s range %s/%d", buf
,
9924 inet_ntoa(rn1
->p
.u
.prefix4
),
9927 if (range
->cost_config
9928 != OSPF_AREA_RANGE_COST_UNSPEC
)
9929 vty_out(vty
, " cost %d",
9930 range
->cost_config
);
9932 if (!CHECK_FLAG(range
->flags
,
9933 OSPF_AREA_RANGE_ADVERTISE
))
9934 vty_out(vty
, " not-advertise");
9936 if (CHECK_FLAG(range
->flags
,
9937 OSPF_AREA_RANGE_SUBSTITUTE
))
9938 vty_out(vty
, " substitute %s/%d",
9939 inet_ntoa(range
->subst_addr
),
9940 range
->subst_masklen
);
9945 if (EXPORT_NAME(area
))
9946 vty_out(vty
, " area %s export-list %s\n", buf
,
9949 if (IMPORT_NAME(area
))
9950 vty_out(vty
, " area %s import-list %s\n", buf
,
9953 if (PREFIX_NAME_IN(area
))
9954 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
9955 PREFIX_NAME_IN(area
));
9957 if (PREFIX_NAME_OUT(area
))
9958 vty_out(vty
, " area %s filter-list prefix %s out\n",
9959 buf
, PREFIX_NAME_OUT(area
));
9965 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
9967 struct ospf_nbr_nbma
*nbr_nbma
;
9968 struct route_node
*rn
;
9970 /* Static Neighbor configuration print. */
9971 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
9972 if ((nbr_nbma
= rn
->info
)) {
9973 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
9975 if (nbr_nbma
->priority
9976 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
9977 vty_out(vty
, " priority %d",
9978 nbr_nbma
->priority
);
9980 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
9981 vty_out(vty
, " poll-interval %d",
9990 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
9992 struct listnode
*node
;
9993 struct ospf_vl_data
*vl_data
;
9994 char buf
[INET_ADDRSTRLEN
];
9996 /* Virtual-Link print */
9997 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
9998 struct listnode
*n2
;
9999 struct crypt_key
*ck
;
10000 struct ospf_interface
*oi
;
10002 if (vl_data
!= NULL
) {
10003 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10004 vl_data
->vl_area_id_fmt
);
10005 oi
= vl_data
->vl_oi
;
10008 if (OSPF_IF_PARAM(oi
, v_hello
)
10009 != OSPF_HELLO_INTERVAL_DEFAULT
10010 || OSPF_IF_PARAM(oi
, v_wait
)
10011 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10012 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10013 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10014 || OSPF_IF_PARAM(oi
, transmit_delay
)
10015 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10017 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10018 buf
, inet_ntoa(vl_data
->vl_peer
),
10019 OSPF_IF_PARAM(oi
, v_hello
),
10020 OSPF_IF_PARAM(oi
, retransmit_interval
),
10021 OSPF_IF_PARAM(oi
, transmit_delay
),
10022 OSPF_IF_PARAM(oi
, v_wait
));
10024 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10025 inet_ntoa(vl_data
->vl_peer
));
10027 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10030 " area %s virtual-link %s authentication-key %s\n",
10031 buf
, inet_ntoa(vl_data
->vl_peer
),
10032 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10035 for (ALL_LIST_ELEMENTS_RO(
10036 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10040 " area %s virtual-link %s"
10041 " message-digest-key %d md5 %s\n",
10042 buf
, inet_ntoa(vl_data
->vl_peer
),
10043 ck
->key_id
, ck
->auth_key
);
10051 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10055 /* redistribute print. */
10056 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10057 struct list
*red_list
;
10058 struct listnode
*node
;
10059 struct ospf_redist
*red
;
10061 red_list
= ospf
->redist
[type
];
10065 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10066 vty_out(vty
, " redistribute %s",
10067 zebra_route_string(type
));
10069 vty_out(vty
, " %d", red
->instance
);
10071 if (red
->dmetric
.value
>= 0)
10072 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10074 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10075 vty_out(vty
, " metric-type 1");
10077 if (ROUTEMAP_NAME(red
))
10078 vty_out(vty
, " route-map %s",
10079 ROUTEMAP_NAME(red
));
10081 vty_out(vty
, "\n");
10088 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10090 if (ospf
->default_metric
!= -1)
10091 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10095 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10098 struct ospf_redist
*red
;
10101 /* distribute-list print. */
10102 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10103 if (DISTRIBUTE_NAME(ospf
, type
))
10104 vty_out(vty
, " distribute-list %s out %s\n",
10105 DISTRIBUTE_NAME(ospf
, type
),
10106 zebra_route_string(type
));
10108 /* default-information print. */
10109 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10110 vty_out(vty
, " default-information originate");
10111 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10112 vty_out(vty
, " always");
10114 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10116 if (red
->dmetric
.value
>= 0)
10117 vty_out(vty
, " metric %d",
10118 red
->dmetric
.value
);
10120 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10121 vty_out(vty
, " metric-type 1");
10123 if (ROUTEMAP_NAME(red
))
10124 vty_out(vty
, " route-map %s",
10125 ROUTEMAP_NAME(red
));
10128 vty_out(vty
, "\n");
10135 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10137 struct route_node
*rn
;
10138 struct ospf_distance
*odistance
;
10140 if (ospf
->distance_all
)
10141 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10143 if (ospf
->distance_intra
|| ospf
->distance_inter
10144 || ospf
->distance_external
) {
10145 vty_out(vty
, " distance ospf");
10147 if (ospf
->distance_intra
)
10148 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10149 if (ospf
->distance_inter
)
10150 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10151 if (ospf
->distance_external
)
10152 vty_out(vty
, " external %d", ospf
->distance_external
);
10154 vty_out(vty
, "\n");
10157 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10158 if ((odistance
= rn
->info
) != NULL
) {
10159 vty_out(vty
, " distance %d %s/%d %s\n",
10160 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10162 odistance
->access_list
? odistance
->access_list
10168 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10170 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10171 struct interface
*ifp
;
10172 struct ospf_interface
*oi
;
10173 struct listnode
*node
= NULL
;
10176 /* `router ospf' print. */
10177 if (ospf
->instance
&& ospf
->name
) {
10178 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10180 } else if (ospf
->instance
) {
10181 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10182 } else if (ospf
->name
) {
10183 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10185 vty_out(vty
, "router ospf\n");
10187 if (!ospf
->networks
) {
10192 /* Router ID print. */
10193 if (ospf
->router_id_static
.s_addr
!= 0)
10194 vty_out(vty
, " ospf router-id %s\n",
10195 inet_ntoa(ospf
->router_id_static
));
10197 /* ABR type print. */
10198 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10199 vty_out(vty
, " ospf abr-type %s\n",
10200 ospf_abr_type_str
[ospf
->abr_type
]);
10202 /* log-adjacency-changes flag print. */
10203 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10204 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10205 vty_out(vty
, " log-adjacency-changes detail\n");
10206 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10207 vty_out(vty
, " log-adjacency-changes\n");
10208 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10209 vty_out(vty
, " no log-adjacency-changes\n");
10212 /* RFC1583 compatibility flag print -- Compatible with CISCO
10214 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10215 vty_out(vty
, " compatible rfc1583\n");
10217 /* auto-cost reference-bandwidth configuration. */
10218 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10220 "! Important: ensure reference bandwidth "
10221 "is consistent across all routers\n");
10222 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10223 ospf
->ref_bandwidth
);
10226 /* SPF timers print. */
10227 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10228 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10229 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10230 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10231 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10233 /* LSA timers print. */
10234 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10235 vty_out(vty
, " timers throttle lsa all %d\n",
10236 ospf
->min_ls_interval
);
10237 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10238 vty_out(vty
, " timers lsa min-arrival %d\n",
10239 ospf
->min_ls_arrival
);
10241 /* Write multiplier print. */
10242 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10243 vty_out(vty
, " ospf write-multiplier %d\n",
10244 ospf
->write_oi_count
);
10246 /* Max-metric router-lsa print */
10247 config_write_stub_router(vty
, ospf
);
10249 /* SPF refresh parameters print. */
10250 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10251 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10253 /* Redistribute information print. */
10254 config_write_ospf_redistribute(vty
, ospf
);
10256 /* passive-interface print. */
10257 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10258 vty_out(vty
, " passive-interface default\n");
10260 FOR_ALL_INTERFACES (vrf
, ifp
)
10261 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10263 && IF_DEF_PARAMS(ifp
)->passive_interface
10264 != ospf
->passive_interface_default
) {
10265 vty_out(vty
, " %spassive-interface %s\n",
10266 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10270 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10271 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10273 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10274 passive_interface
)) {
10275 if (oi
->params
->passive_interface
10276 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10278 } else if (oi
->params
->passive_interface
10279 == ospf
->passive_interface_default
)
10282 vty_out(vty
, " %spassive-interface %s %s\n",
10283 oi
->params
->passive_interface
? "" : "no ",
10284 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10287 /* Network area print. */
10288 config_write_network_area(vty
, ospf
);
10290 /* Area config print. */
10291 config_write_ospf_area(vty
, ospf
);
10293 /* static neighbor print. */
10294 config_write_ospf_nbr_nbma(vty
, ospf
);
10296 /* Virtual-Link print. */
10297 config_write_virtual_link(vty
, ospf
);
10299 /* Default metric configuration. */
10300 config_write_ospf_default_metric(vty
, ospf
);
10302 /* Distribute-list and default-information print. */
10303 config_write_ospf_distribute(vty
, ospf
);
10305 /* Distance configuration. */
10306 config_write_ospf_distance(vty
, ospf
);
10308 ospf_opaque_config_write_router(vty
, ospf
);
10314 /* OSPF configuration write function. */
10315 static int ospf_config_write(struct vty
*vty
)
10318 struct listnode
*ospf_node
= NULL
;
10321 if (listcount(om
->ospf
) == 0)
10324 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10325 /* VRF Default check if it is running.
10326 * Upon daemon start, there could be default instance
10327 * in absence of 'router ospf'/oi_running is disabled. */
10328 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10329 write
+= ospf_config_write_one(vty
, ospf
);
10330 /* For Non-Default VRF simply display the configuration,
10331 * even if it is not oi_running. */
10332 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10333 write
+= ospf_config_write_one(vty
, ospf
);
10338 void ospf_vty_show_init(void)
10340 /* "show ip ospf" commands. */
10341 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10343 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10345 /* "show ip ospf database" commands. */
10346 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10348 install_element(VIEW_NODE
,
10349 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10350 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10351 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10353 /* "show ip ospf interface" commands. */
10354 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10356 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10357 /* "show ip ospf interface traffic */
10358 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10360 /* "show ip ospf neighbor" commands. */
10361 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10362 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10363 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10364 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10365 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10366 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10367 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10369 install_element(VIEW_NODE
,
10370 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10371 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10372 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10373 install_element(VIEW_NODE
,
10374 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10375 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10376 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10377 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10379 /* "show ip ospf route" commands. */
10380 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10381 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10383 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10384 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10386 /* "show ip ospf vrfs" commands. */
10387 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10391 /* ospfd's interface node. */
10392 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10394 /* Initialization of OSPF interface. */
10395 static void ospf_vty_if_init(void)
10397 /* Install interface node. */
10398 install_node(&interface_node
, config_write_interface
);
10401 /* "ip ospf authentication" commands. */
10402 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10403 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10404 install_element(INTERFACE_NODE
,
10405 &no_ip_ospf_authentication_args_addr_cmd
);
10406 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10407 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10408 install_element(INTERFACE_NODE
,
10409 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10410 install_element(INTERFACE_NODE
,
10411 &no_ospf_authentication_key_authkey_addr_cmd
);
10413 /* "ip ospf message-digest-key" commands. */
10414 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10415 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10417 /* "ip ospf cost" commands. */
10418 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10419 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10421 /* "ip ospf mtu-ignore" commands. */
10422 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10423 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10425 /* "ip ospf dead-interval" commands. */
10426 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10427 install_element(INTERFACE_NODE
,
10428 &ip_ospf_dead_interval_minimal_addr_cmd
);
10429 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10431 /* "ip ospf hello-interval" commands. */
10432 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10433 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10435 /* "ip ospf network" commands. */
10436 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10437 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10439 /* "ip ospf priority" commands. */
10440 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10441 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10443 /* "ip ospf retransmit-interval" commands. */
10444 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10445 install_element(INTERFACE_NODE
,
10446 &no_ip_ospf_retransmit_interval_addr_cmd
);
10448 /* "ip ospf transmit-delay" commands. */
10449 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10450 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10452 /* "ip ospf area" commands. */
10453 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10454 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10456 /* These commands are compatibitliy for previous version. */
10457 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10458 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10459 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10460 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10461 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10462 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10463 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10464 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10465 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10466 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10467 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10468 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10469 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10470 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10471 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10472 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10473 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10476 static void ospf_vty_zebra_init(void)
10478 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10479 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10480 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10481 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10483 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10484 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10486 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10487 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10489 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10490 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10492 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10493 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10494 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10495 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10497 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10498 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10499 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10500 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10504 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10506 static void ospf_interface_clear(struct interface
*ifp
)
10508 if (!if_is_operative(ifp
))
10511 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10512 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10514 ospf_if_reset(ifp
);
10517 DEFUN (clear_ip_ospf_interface
,
10518 clear_ip_ospf_interface_cmd
,
10519 "clear ip ospf interface [IFNAME]",
10522 "OSPF information\n"
10523 "Interface information\n"
10524 "Interface name\n")
10526 int idx_ifname
= 4;
10527 struct interface
*ifp
;
10528 struct listnode
*node
;
10529 struct ospf
*ospf
= NULL
;
10531 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10533 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10534 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10535 FOR_ALL_INTERFACES (vrf
, ifp
)
10536 ospf_interface_clear(ifp
);
10539 /* Interface name is specified. */
10540 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10542 vty_out(vty
, "No such interface name\n");
10544 ospf_interface_clear(ifp
);
10547 return CMD_SUCCESS
;
10550 void ospf_vty_clear_init(void)
10552 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10556 /* Install OSPF related vty commands. */
10557 void ospf_vty_init(void)
10559 /* Install ospf top node. */
10560 install_node(&ospf_node
, ospf_config_write
);
10562 /* "router ospf" commands. */
10563 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10564 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10567 install_default(OSPF_NODE
);
10569 /* "ospf router-id" commands. */
10570 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10571 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10572 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10574 /* "passive-interface" commands. */
10575 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10576 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10578 /* "ospf abr-type" commands. */
10579 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10580 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10582 /* "ospf log-adjacency-changes" commands. */
10583 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10584 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10585 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10586 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10588 /* "ospf rfc1583-compatible" commands. */
10589 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10590 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10591 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10592 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10594 /* "network area" commands. */
10595 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10596 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10598 /* "area authentication" commands. */
10599 install_element(OSPF_NODE
,
10600 &ospf_area_authentication_message_digest_cmd
);
10601 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10602 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10604 /* "area range" commands. */
10605 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10606 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10607 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10608 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10609 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10610 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10612 /* "area virtual-link" commands. */
10613 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10614 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10615 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10616 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10619 /* "area stub" commands. */
10620 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10621 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10622 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10623 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10625 /* "area nssa" commands. */
10626 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10627 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10628 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10629 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10630 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10632 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10633 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10635 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10636 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10638 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10639 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10641 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10642 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10644 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10645 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10647 /* SPF timer commands */
10648 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10649 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10651 /* LSA timers commands */
10652 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10653 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10654 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10655 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10656 install_element(OSPF_NODE
, &ospf_timers_lsa_arrival_cmd
);
10657 install_element(OSPF_NODE
, &no_ospf_timers_lsa_arrival_cmd
);
10659 /* refresh timer commands */
10660 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10661 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10663 /* max-metric commands */
10664 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10665 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10666 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10667 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10668 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10669 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10671 /* reference bandwidth commands */
10672 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10673 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10675 /* "neighbor" commands. */
10676 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10677 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10678 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10679 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10681 /* write multiplier commands */
10682 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10683 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10684 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10685 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10687 /* Init interface related vty commands. */
10688 ospf_vty_if_init();
10690 /* Init zebra related vty commands. */
10691 ospf_vty_zebra_init();