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 DEFUN (ospf_neighbor
,
2341 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2343 "Neighbor IP address\n"
2344 "Neighbor Priority\n"
2346 "Dead Neighbor Polling interval\n"
2349 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2353 struct in_addr nbr_addr
;
2354 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2355 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2357 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2358 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2359 return CMD_WARNING_CONFIG_FAILED
;
2363 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2366 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2368 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2371 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2374 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2379 DEFUN (ospf_neighbor_poll_interval
,
2380 ospf_neighbor_poll_interval_cmd
,
2381 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2383 "Neighbor IP address\n"
2384 "Dead Neighbor Polling interval\n"
2386 "OSPF priority of non-broadcast neighbor\n"
2389 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2393 struct in_addr nbr_addr
;
2394 unsigned int priority
;
2395 unsigned int interval
;
2397 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2398 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2399 return CMD_WARNING_CONFIG_FAILED
;
2402 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2404 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2405 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2407 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2408 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2411 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2416 DEFUN (no_ospf_neighbor
,
2417 no_ospf_neighbor_cmd
,
2418 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2421 "Neighbor IP address\n"
2422 "Neighbor Priority\n"
2424 "Dead Neighbor Polling interval\n"
2427 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2429 struct in_addr nbr_addr
;
2431 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2432 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2433 return CMD_WARNING_CONFIG_FAILED
;
2436 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2441 DEFUN (no_ospf_neighbor_poll
,
2442 no_ospf_neighbor_poll_cmd
,
2443 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2446 "Neighbor IP address\n"
2447 "Dead Neighbor Polling interval\n"
2449 "Neighbor Priority\n"
2452 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2454 struct in_addr nbr_addr
;
2456 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2457 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2458 return CMD_WARNING_CONFIG_FAILED
;
2461 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2466 DEFUN (ospf_refresh_timer
,
2467 ospf_refresh_timer_cmd
,
2468 "refresh timer (10-1800)",
2469 "Adjust refresh parameters\n"
2470 "Set refresh timer\n"
2471 "Timer value in seconds\n")
2473 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2475 unsigned int interval
;
2477 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2478 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2479 * OSPF_LSA_REFRESHER_GRANULARITY
;
2481 ospf_timers_refresh_set(ospf
, interval
);
2486 DEFUN (no_ospf_refresh_timer
,
2487 no_ospf_refresh_timer_val_cmd
,
2488 "no refresh timer [(10-1800)]",
2490 "Adjust refresh parameters\n"
2491 "Unset refresh timer\n"
2492 "Timer value in seconds\n")
2494 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2496 unsigned int interval
;
2499 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2501 if (ospf
->lsa_refresh_interval
!= interval
2502 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2506 ospf_timers_refresh_unset(ospf
);
2512 DEFUN (ospf_auto_cost_reference_bandwidth
,
2513 ospf_auto_cost_reference_bandwidth_cmd
,
2514 "auto-cost reference-bandwidth (1-4294967)",
2515 "Calculate OSPF interface cost according to bandwidth\n"
2516 "Use reference bandwidth method to assign OSPF cost\n"
2517 "The reference bandwidth in terms of Mbits per second\n")
2519 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2520 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2523 struct interface
*ifp
;
2525 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2526 if (refbw
< 1 || refbw
> 4294967) {
2527 vty_out(vty
, "reference-bandwidth value is invalid\n");
2528 return CMD_WARNING_CONFIG_FAILED
;
2531 /* If reference bandwidth is changed. */
2532 if ((refbw
) == ospf
->ref_bandwidth
)
2535 ospf
->ref_bandwidth
= refbw
;
2536 FOR_ALL_INTERFACES (vrf
, ifp
)
2537 ospf_if_recalculate_output_cost(ifp
);
2542 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2543 no_ospf_auto_cost_reference_bandwidth_cmd
,
2544 "no auto-cost reference-bandwidth [(1-4294967)]",
2546 "Calculate OSPF interface cost according to bandwidth\n"
2547 "Use reference bandwidth method to assign OSPF cost\n"
2548 "The reference bandwidth in terms of Mbits per second\n")
2550 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2551 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2552 struct interface
*ifp
;
2554 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2557 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2558 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2560 " Please ensure reference bandwidth is consistent across all routers\n");
2562 FOR_ALL_INTERFACES (vrf
, ifp
)
2563 ospf_if_recalculate_output_cost(ifp
);
2568 DEFUN (ospf_write_multiplier
,
2569 ospf_write_multiplier_cmd
,
2570 "ospf write-multiplier (1-100)",
2571 "OSPF specific commands\n"
2572 "Write multiplier\n"
2573 "Maximum number of interface serviced per write\n")
2575 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2577 uint32_t write_oi_count
;
2584 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2585 if (write_oi_count
< 1 || write_oi_count
> 100) {
2586 vty_out(vty
, "write-multiplier value is invalid\n");
2587 return CMD_WARNING_CONFIG_FAILED
;
2590 ospf
->write_oi_count
= write_oi_count
;
2594 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2595 "Write multiplier\n"
2596 "Maximum number of interface serviced per write\n")
2598 DEFUN (no_ospf_write_multiplier
,
2599 no_ospf_write_multiplier_cmd
,
2600 "no ospf write-multiplier (1-100)",
2602 "OSPF specific commands\n"
2603 "Write multiplier\n"
2604 "Maximum number of interface serviced per write\n")
2606 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2608 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2612 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2613 "no write-multiplier (1-100)", NO_STR
2614 "Write multiplier\n"
2615 "Maximum number of interface serviced per write\n")
2617 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2618 "Alternative IBM", "Alternative Cisco",
2619 "Alternative Shortcut"};
2621 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2623 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2624 json_object
*json_areas
, uint8_t use_json
)
2626 json_object
*json_area
= NULL
;
2629 json_area
= json_object_new_object();
2633 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2635 /* Show Area type/mode. */
2636 if (OSPF_IS_AREA_BACKBONE(area
)) {
2638 json_object_boolean_true_add(json_area
, "backbone");
2640 vty_out(vty
, " (Backbone)\n");
2643 if (area
->external_routing
== OSPF_AREA_STUB
) {
2644 if (area
->no_summary
)
2645 json_object_boolean_true_add(
2646 json_area
, "stubNoSummary");
2647 if (area
->shortcut_configured
)
2648 json_object_boolean_true_add(
2649 json_area
, "stubShortcut");
2650 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2651 if (area
->no_summary
)
2652 json_object_boolean_true_add(
2653 json_area
, "nssaNoSummary");
2654 if (area
->shortcut_configured
)
2655 json_object_boolean_true_add(
2656 json_area
, "nssaShortcut");
2659 json_object_string_add(
2660 json_area
, "shortcuttingMode",
2661 ospf_shortcut_mode_descr_str
2662 [area
->shortcut_configured
]);
2663 if (area
->shortcut_capability
)
2664 json_object_boolean_true_add(json_area
,
2667 if (area
->external_routing
== OSPF_AREA_STUB
)
2668 vty_out(vty
, " (Stub%s%s)",
2669 area
->no_summary
? ", no summary" : "",
2670 area
->shortcut_configured
? "; " : "");
2671 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2672 vty_out(vty
, " (NSSA%s%s)",
2673 area
->no_summary
? ", no summary" : "",
2674 area
->shortcut_configured
? "; " : "");
2677 vty_out(vty
, " Shortcutting mode: %s",
2678 ospf_shortcut_mode_descr_str
2679 [area
->shortcut_configured
]);
2680 vty_out(vty
, ", S-bit consensus: %s\n",
2681 area
->shortcut_capability
? "ok" : "no");
2685 /* Show number of interfaces */
2687 json_object_int_add(json_area
, "areaIfTotalCounter",
2688 listcount(area
->oiflist
));
2689 json_object_int_add(json_area
, "areaIfActiveCounter",
2693 " Number of interfaces in this area: Total: %d, "
2695 listcount(area
->oiflist
), area
->act_ints
);
2697 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2699 json_object_boolean_true_add(json_area
, "nssa");
2700 if (!IS_OSPF_ABR(area
->ospf
))
2701 json_object_boolean_false_add(json_area
, "abr");
2702 else if (area
->NSSATranslatorState
) {
2703 json_object_boolean_true_add(json_area
, "abr");
2704 if (area
->NSSATranslatorRole
2705 == OSPF_NSSA_ROLE_CANDIDATE
)
2706 json_object_boolean_true_add(
2708 "nssaTranslatorElected");
2709 else if (area
->NSSATranslatorRole
2710 == OSPF_NSSA_ROLE_ALWAYS
)
2711 json_object_boolean_true_add(
2713 "nssaTranslatorAlways");
2715 json_object_boolean_true_add(json_area
, "abr");
2716 if (area
->NSSATranslatorRole
2717 == OSPF_NSSA_ROLE_CANDIDATE
)
2718 json_object_boolean_false_add(
2720 "nssaTranslatorElected");
2722 json_object_boolean_true_add(
2724 "nssaTranslatorNever");
2728 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2729 if (!IS_OSPF_ABR(area
->ospf
))
2731 " It is not ABR, therefore not Translator. \n");
2732 else if (area
->NSSATranslatorState
) {
2733 vty_out(vty
, " We are an ABR and ");
2734 if (area
->NSSATranslatorRole
2735 == OSPF_NSSA_ROLE_CANDIDATE
)
2737 "the NSSA Elected Translator. \n");
2738 else if (area
->NSSATranslatorRole
2739 == OSPF_NSSA_ROLE_ALWAYS
)
2741 "always an NSSA Translator. \n");
2743 vty_out(vty
, " We are an ABR, but ");
2744 if (area
->NSSATranslatorRole
2745 == OSPF_NSSA_ROLE_CANDIDATE
)
2747 "not the NSSA Elected Translator. \n");
2750 "never an NSSA Translator. \n");
2755 /* Stub-router state for this area */
2756 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2757 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2760 json_object_boolean_true_add(
2761 json_area
, "originStubMaxDistRouterLsa");
2762 if (CHECK_FLAG(area
->stub_router_state
,
2763 OSPF_AREA_ADMIN_STUB_ROUTED
))
2764 json_object_boolean_true_add(
2765 json_area
, "indefiniteActiveAdmin");
2766 if (area
->t_stub_router
) {
2770 &area
->t_stub_router
->u
.sands
,
2773 json_object_int_add(
2775 "activeStartupRemainderMsecs",
2780 " Originating stub / maximum-distance Router-LSA\n");
2781 if (CHECK_FLAG(area
->stub_router_state
,
2782 OSPF_AREA_ADMIN_STUB_ROUTED
))
2784 " Administratively activated (indefinitely)\n");
2785 if (area
->t_stub_router
)
2787 " Active from startup, %s remaining\n",
2788 ospf_timer_dump(area
->t_stub_router
,
2795 /* Show number of fully adjacent neighbors. */
2796 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2799 /* Show authentication type. */
2800 if (area
->auth_type
== OSPF_AUTH_NULL
)
2801 json_object_string_add(json_area
, "authentication",
2802 "authenticationNone");
2803 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2804 json_object_string_add(json_area
, "authentication",
2805 "authenticationSimplePassword");
2806 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2807 json_object_string_add(json_area
, "authentication",
2808 "authenticationMessageDigest");
2810 if (!OSPF_IS_AREA_BACKBONE(area
))
2811 json_object_int_add(json_area
,
2812 "virtualAdjacenciesPassingCounter",
2815 /* Show SPF calculation times. */
2816 json_object_int_add(json_area
, "spfExecutedCounter",
2817 area
->spf_calculation
);
2818 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2819 json_object_int_add(
2820 json_area
, "lsaRouterNumber",
2821 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2822 json_object_int_add(
2823 json_area
, "lsaRouterChecksum",
2824 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2825 json_object_int_add(
2826 json_area
, "lsaNetworkNumber",
2827 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2828 json_object_int_add(
2829 json_area
, "lsaNetworkChecksum",
2830 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2831 json_object_int_add(
2832 json_area
, "lsaSummaryNumber",
2833 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2834 json_object_int_add(
2835 json_area
, "lsaSummaryChecksum",
2836 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2837 json_object_int_add(
2838 json_area
, "lsaAsbrNumber",
2839 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2840 json_object_int_add(
2841 json_area
, "lsaAsbrChecksum",
2842 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaNssaNumber",
2845 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaNssaChecksum",
2848 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2850 /* Show number of fully adjacent neighbors. */
2852 " Number of fully adjacent neighbors in this area:"
2856 /* Show authentication type. */
2857 vty_out(vty
, " Area has ");
2858 if (area
->auth_type
== OSPF_AUTH_NULL
)
2859 vty_out(vty
, "no authentication\n");
2860 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2861 vty_out(vty
, "simple password authentication\n");
2862 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2863 vty_out(vty
, "message digest authentication\n");
2865 if (!OSPF_IS_AREA_BACKBONE(area
))
2867 " Number of full virtual adjacencies going through"
2871 /* Show SPF calculation times. */
2872 vty_out(vty
, " SPF algorithm executed %d times\n",
2873 area
->spf_calculation
);
2875 /* Show number of LSA. */
2876 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2878 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2879 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2880 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2882 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2883 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2884 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2886 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2887 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2888 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2890 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2891 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2892 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2893 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2894 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2895 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2899 json_object_int_add(
2900 json_area
, "lsaOpaqueLinkNumber",
2901 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2902 json_object_int_add(
2903 json_area
, "lsaOpaqueLinkChecksum",
2904 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2905 json_object_int_add(
2906 json_area
, "lsaOpaqueAreaNumber",
2907 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2908 json_object_int_add(
2909 json_area
, "lsaOpaqueAreaChecksum",
2910 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2913 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2914 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2915 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2917 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2918 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2919 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2923 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2929 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2930 json_object
*json
, uint8_t use_vrf
)
2932 struct listnode
*node
, *nnode
;
2933 struct ospf_area
*area
;
2934 struct timeval result
;
2935 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2936 json_object
*json_vrf
= NULL
;
2937 json_object
*json_areas
= NULL
;
2941 json_vrf
= json_object_new_object();
2944 json_areas
= json_object_new_object();
2947 if (ospf
->instance
) {
2949 json_object_int_add(json
, "ospfInstance",
2952 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2956 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2958 /* Show Router ID. */
2960 json_object_string_add(json_vrf
, "routerId",
2961 inet_ntoa(ospf
->router_id
));
2963 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2964 inet_ntoa(ospf
->router_id
));
2967 /* Graceful shutdown */
2968 if (ospf
->t_deferred_shutdown
) {
2973 &ospf
->t_deferred_shutdown
->u
.sands
,
2976 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
2980 " Deferred shutdown in progress, %s remaining\n",
2981 ospf_timer_dump(ospf
->t_deferred_shutdown
,
2982 timebuf
, sizeof(timebuf
)));
2986 /* Show capability. */
2988 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
2989 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
2990 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2991 json_object_boolean_true_add(json_vrf
,
2992 "rfc1583Compatibility");
2995 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
2996 vty_out(vty
, " This implementation conforms to RFC2328\n");
2997 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
2998 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3004 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3005 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3008 vty_out(vty
, " OpaqueCapability flag is %s\n",
3009 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3014 /* Show stub-router configuration */
3015 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3016 || ospf
->stub_router_shutdown_time
3017 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3019 json_object_boolean_true_add(json_vrf
,
3020 "stubAdvertisement");
3021 if (ospf
->stub_router_startup_time
3022 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3023 json_object_int_add(
3024 json_vrf
, "postStartEnabledMsecs",
3025 ospf
->stub_router_startup_time
/ 1000);
3026 if (ospf
->stub_router_shutdown_time
3027 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3028 json_object_int_add(
3029 json_vrf
, "preShutdownEnabledMsecs",
3030 ospf
->stub_router_shutdown_time
/ 1000);
3033 " Stub router advertisement is configured\n");
3034 if (ospf
->stub_router_startup_time
3035 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3037 " Enabled for %us after start-up\n",
3038 ospf
->stub_router_startup_time
);
3039 if (ospf
->stub_router_shutdown_time
3040 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3042 " Enabled for %us prior to full shutdown\n",
3043 ospf
->stub_router_shutdown_time
);
3047 /* Show SPF timers. */
3049 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3051 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3052 ospf
->spf_holdtime
);
3053 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3054 ospf
->spf_max_holdtime
);
3055 json_object_int_add(json_vrf
, "holdtimeMultplier",
3056 ospf
->spf_hold_multiplier
);
3059 " Initial SPF scheduling delay %d millisec(s)\n"
3060 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3061 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3062 " Hold time multiplier is currently %d\n",
3063 ospf
->spf_delay
, ospf
->spf_holdtime
,
3064 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3068 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3069 long time_store
= 0;
3072 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3073 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3076 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3077 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3078 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3081 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3083 vty_out(vty
, " SPF algorithm ");
3084 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3085 monotime_since(&ospf
->ts_spf
, &result
);
3086 vty_out(vty
, "last executed %s ago\n",
3087 ospf_timeval_dump(&result
, timebuf
,
3089 vty_out(vty
, " Last SPF duration %s\n",
3090 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3091 timebuf
, sizeof(timebuf
)));
3093 vty_out(vty
, "has not been run\n");
3097 if (ospf
->t_spf_calc
) {
3100 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3102 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3106 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3107 ospf
->min_ls_interval
);
3108 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3109 ospf
->min_ls_arrival
);
3110 /* Show write multiplier values */
3111 json_object_int_add(json_vrf
, "writeMultiplier",
3112 ospf
->write_oi_count
);
3113 /* Show refresh parameters. */
3114 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3115 ospf
->lsa_refresh_interval
* 1000);
3117 vty_out(vty
, " SPF timer %s%s\n",
3118 (ospf
->t_spf_calc
? "due in " : "is "),
3119 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3122 vty_out(vty
, " LSA minimum interval %d msecs\n",
3123 ospf
->min_ls_interval
);
3124 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3125 ospf
->min_ls_arrival
);
3127 /* Show write multiplier values */
3128 vty_out(vty
, " Write Multiplier set to %d \n",
3129 ospf
->write_oi_count
);
3131 /* Show refresh parameters. */
3132 vty_out(vty
, " Refresh timer %d secs\n",
3133 ospf
->lsa_refresh_interval
);
3136 /* Show ABR/ASBR flags. */
3137 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3139 json_object_string_add(
3140 json_vrf
, "abrType",
3141 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3144 " This router is an ABR, ABR type is: %s\n",
3145 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3147 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3149 json_object_string_add(
3150 json_vrf
, "asbrRouter",
3151 "injectingExternalRoutingInformation");
3154 " This router is an ASBR "
3155 "(injecting external routing information)\n");
3158 /* Show Number of AS-external-LSAs. */
3160 json_object_int_add(
3161 json_vrf
, "lsaExternalCounter",
3162 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3163 json_object_int_add(
3164 json_vrf
, "lsaExternalChecksum",
3165 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3168 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3169 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3170 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3174 json_object_int_add(
3175 json_vrf
, "lsaAsopaqueCounter",
3176 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3177 json_object_int_add(
3178 json_vrf
, "lsaAsOpaqueChecksum",
3179 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3182 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3183 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3184 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3187 /* Show number of areas attached. */
3189 json_object_int_add(json_vrf
, "attachedAreaCounter",
3190 listcount(ospf
->areas
));
3192 vty_out(vty
, " Number of areas attached to this router: %d\n",
3193 listcount(ospf
->areas
));
3195 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3196 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3198 json_object_boolean_true_add(
3199 json_vrf
, "adjacencyChangesLoggedAll");
3202 " All adjacency changes are logged\n");
3205 json_object_boolean_true_add(
3206 json_vrf
, "adjacencyChangesLogged");
3208 vty_out(vty
, " Adjacency changes are logged\n");
3211 /* Show each area status. */
3212 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3213 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3217 json_object_object_add(json_vrf
, "areas", json_areas
);
3218 if (ospf
->vrf_id
== VRF_DEFAULT
)
3219 json_object_object_add(json
, "default",
3222 json_object_object_add(json
, ospf
->name
,
3225 json_object_object_add(json
, "areas", json_areas
);
3233 DEFUN (show_ip_ospf
,
3235 "show ip ospf [vrf <NAME|all>] [json]",
3238 "OSPF information\n"
3244 uint8_t uj
= use_json(argc
, argv
);
3245 struct listnode
*node
= NULL
;
3246 char *vrf_name
= NULL
;
3247 bool all_vrf
= FALSE
;
3248 int ret
= CMD_SUCCESS
;
3251 json_object
*json
= NULL
;
3252 uint8_t use_vrf
= 0;
3254 if (listcount(om
->ospf
) == 0)
3257 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3260 json
= json_object_new_object();
3262 /* vrf input is provided could be all or specific vrf*/
3266 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3267 if (!ospf
->oi_running
)
3269 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3273 vty_out(vty
, "%s\n",
3274 json_object_to_json_string_ext(
3275 json
, JSON_C_TO_STRING_PRETTY
));
3276 json_object_free(json
);
3280 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3281 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3283 json_object_free(json
);
3287 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3288 /* Display default ospf (instance 0) info */
3289 if (ospf
== NULL
|| !ospf
->oi_running
) {
3291 json_object_free(json
);
3297 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3299 vty_out(vty
, "%s\n",
3300 json_object_to_json_string_ext(
3301 json
, JSON_C_TO_STRING_PRETTY
));
3305 json_object_free(json
);
3310 DEFUN (show_ip_ospf_instance
,
3311 show_ip_ospf_instance_cmd
,
3312 "show ip ospf (1-65535) [json]",
3315 "OSPF information\n"
3321 unsigned short instance
= 0;
3322 uint8_t uj
= use_json(argc
, argv
);
3323 int ret
= CMD_SUCCESS
;
3324 json_object
*json
= NULL
;
3326 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3327 ospf
= ospf_lookup_instance(instance
);
3329 return CMD_NOT_MY_INSTANCE
;
3331 if (!ospf
->oi_running
)
3335 json
= json_object_new_object();
3337 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3340 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3341 json
, JSON_C_TO_STRING_PRETTY
));
3342 json_object_free(json
);
3348 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3349 struct interface
*ifp
,
3350 json_object
*json_interface_sub
,
3354 struct ospf_neighbor
*nbr
;
3355 struct route_node
*rn
;
3356 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3358 /* Is interface up? */
3360 is_up
= if_is_operative(ifp
);
3362 json_object_boolean_true_add(json_interface_sub
,
3365 json_object_boolean_false_add(json_interface_sub
,
3368 json_object_int_add(json_interface_sub
, "ifIndex",
3370 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3371 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3373 json_object_string_add(json_interface_sub
, "ifFlags",
3374 if_flag_dump(ifp
->flags
));
3376 vty_out(vty
, "%s is %s\n", ifp
->name
,
3377 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3378 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3379 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3380 if_flag_dump(ifp
->flags
));
3383 /* Is interface OSPF enabled? */
3385 if (ospf_oi_count(ifp
) == 0) {
3386 json_object_boolean_false_add(json_interface_sub
,
3389 } else if (!is_up
) {
3390 json_object_boolean_false_add(json_interface_sub
,
3394 json_object_boolean_true_add(json_interface_sub
,
3397 if (ospf_oi_count(ifp
) == 0) {
3398 vty_out(vty
, " OSPF not enabled on this interface\n");
3400 } else if (!is_up
) {
3402 " OSPF is enabled, but not running on this interface\n");
3407 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3408 struct ospf_interface
*oi
= rn
->info
;
3413 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3415 json_object_boolean_true_add(json_interface_sub
,
3418 vty_out(vty
, " This interface is UNNUMBERED,");
3420 /* Show OSPF interface information. */
3422 json_object_string_add(
3423 json_interface_sub
, "ipAddress",
3424 inet_ntoa(oi
->address
->u
.prefix4
));
3425 json_object_int_add(json_interface_sub
,
3426 "ipAddressPrefixlen",
3427 oi
->address
->prefixlen
);
3429 vty_out(vty
, " Internet Address %s/%d,",
3430 inet_ntoa(oi
->address
->u
.prefix4
),
3431 oi
->address
->prefixlen
);
3433 if (oi
->connected
->destination
3434 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3435 struct in_addr
*dest
;
3438 if (CONNECTED_PEER(oi
->connected
)
3439 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3444 /* For Vlinks, showing the peer address is
3446 * * * * * informative than the local
3447 * interface that is being used
3449 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3450 dest
= &oi
->vl_data
->peer_addr
;
3452 dest
= &oi
->connected
->destination
->u
3456 json_object_string_add(
3458 "ospfIfType", dstr
);
3459 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3460 json_object_string_add(
3465 json_object_string_add(
3470 vty_out(vty
, " %s %s,", dstr
,
3475 json_object_string_add(json_interface_sub
, "area",
3476 ospf_area_desc_string(oi
->area
));
3477 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3478 json_object_boolean_true_add(
3480 "mtuMismatchDetect");
3481 json_object_string_add(json_interface_sub
, "routerId",
3482 inet_ntoa(ospf
->router_id
));
3483 json_object_string_add(json_interface_sub
,
3485 ospf_network_type_str
[oi
->type
]);
3486 json_object_int_add(json_interface_sub
, "cost",
3488 json_object_int_add(
3489 json_interface_sub
, "transmitDelayMsecs",
3490 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3491 json_object_string_add(json_interface_sub
, "state",
3492 lookup_msg(ospf_ism_state_msg
,
3494 json_object_int_add(json_interface_sub
, "priority",
3497 vty_out(vty
, " Area %s\n",
3498 ospf_area_desc_string(oi
->area
));
3500 vty_out(vty
, " MTU mismatch detection: %s\n",
3501 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3505 " Router ID %s, Network Type %s, Cost: %d\n",
3506 inet_ntoa(ospf
->router_id
),
3507 ospf_network_type_str
[oi
->type
],
3511 " Transmit Delay is %d sec, State %s, Priority %d\n",
3512 OSPF_IF_PARAM(oi
, transmit_delay
),
3513 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3517 /* Show DR information. */
3518 if (DR(oi
).s_addr
== 0) {
3521 " No backup designated router on this network\n");
3523 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3527 " No backup designated router on this network\n");
3530 json_object_string_add(
3531 json_interface_sub
, "bdrId",
3532 inet_ntoa(nbr
->router_id
));
3533 json_object_string_add(
3536 inet_ntoa(nbr
->address
.u
3540 " Backup Designated Router (ID) %s,",
3541 inet_ntoa(nbr
->router_id
));
3542 vty_out(vty
, " Interface Address %s\n",
3543 inet_ntoa(nbr
->address
.u
3549 /* Next network-LSA sequence number we'll use, if we're elected
3552 && ntohl(oi
->params
->network_lsa_seqnum
)
3553 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3555 json_object_int_add(
3557 "networkLsaSequence",
3558 ntohl(oi
->params
->network_lsa_seqnum
));
3561 " Saved Network-LSA sequence number 0x%x\n",
3562 ntohl(oi
->params
->network_lsa_seqnum
));
3566 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3567 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3568 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3569 json_object_boolean_true_add(
3571 "mcastMemberOspfAllRouters");
3572 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3573 json_object_boolean_true_add(
3575 "mcastMemberOspfDesignatedRouters");
3578 vty_out(vty
, " Multicast group memberships:");
3579 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3580 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3581 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3582 vty_out(vty
, " OSPFAllRouters");
3583 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3584 vty_out(vty
, " OSPFDesignatedRouters");
3586 vty_out(vty
, " <None>");
3591 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3592 json_object_int_add(
3593 json_interface_sub
, "timerMsecs",
3594 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3596 json_object_int_add(
3597 json_interface_sub
, "timerMsecs",
3598 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3599 json_object_int_add(json_interface_sub
,
3601 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3602 json_object_int_add(json_interface_sub
,
3604 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3605 json_object_int_add(
3606 json_interface_sub
, "timerRetransmit",
3607 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3609 vty_out(vty
, " Timer intervals configured,");
3610 vty_out(vty
, " Hello ");
3611 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3612 vty_out(vty
, "%ds,",
3613 OSPF_IF_PARAM(oi
, v_hello
));
3615 vty_out(vty
, "%dms,",
3616 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3617 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3618 OSPF_IF_PARAM(oi
, v_wait
),
3619 OSPF_IF_PARAM(oi
, v_wait
),
3620 OSPF_IF_PARAM(oi
, retransmit_interval
));
3623 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3624 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3626 long time_store
= 0;
3630 &oi
->t_hello
->u
.sands
,
3633 json_object_int_add(json_interface_sub
,
3634 "timerHelloInMsecs",
3637 vty_out(vty
, " Hello due in %s\n",
3638 ospf_timer_dump(oi
->t_hello
, timebuf
,
3640 } else /* passive-interface is set */
3643 json_object_boolean_true_add(
3645 "timerPassiveIface");
3648 " No Hellos (Passive interface)\n");
3652 json_object_int_add(json_interface_sub
, "nbrCount",
3653 ospf_nbr_count(oi
, 0));
3654 json_object_int_add(json_interface_sub
,
3656 ospf_nbr_count(oi
, NSM_Full
));
3659 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3660 ospf_nbr_count(oi
, 0),
3661 ospf_nbr_count(oi
, NSM_Full
));
3662 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3666 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3667 char *intf_name
, uint8_t use_vrf
,
3668 json_object
*json
, uint8_t use_json
)
3670 struct interface
*ifp
;
3671 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3672 json_object
*json_vrf
= NULL
;
3673 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3677 json_vrf
= json_object_new_object();
3680 json_interface
= json_object_new_object();
3683 if (ospf
->instance
) {
3685 json_object_int_add(json
, "ospfInstance",
3688 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3691 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3693 if (intf_name
== NULL
) {
3694 /* Show All Interfaces.*/
3695 FOR_ALL_INTERFACES (vrf
, ifp
) {
3696 if (ospf_oi_count(ifp
)) {
3698 json_interface_sub
=
3699 json_object_new_object();
3701 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3706 json_object_object_add(
3707 json_interface
, ifp
->name
,
3708 json_interface_sub
);
3713 json_object_object_add(json_vrf
, "interfaces",
3716 /* Interface name is specified. */
3717 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3720 json_object_boolean_true_add(json_vrf
,
3723 vty_out(vty
, "No such interface name\n");
3726 json_interface_sub
= json_object_new_object();
3727 json_interface
= json_object_new_object();
3730 show_ip_ospf_interface_sub(
3731 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3734 json_object_object_add(json_interface
,
3736 json_interface_sub
);
3737 json_object_object_add(json_vrf
, "interfaces",
3745 if (ospf
->vrf_id
== VRF_DEFAULT
)
3746 json_object_object_add(json
, "default",
3749 json_object_object_add(json
, ospf
->name
,
3758 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3759 struct ospf_interface
*oi
,
3760 json_object
*json_interface_sub
,
3764 json_object_int_add(json_interface_sub
, "ifIndex",
3766 json_object_int_add(json_interface_sub
, "helloIn",
3768 json_object_int_add(json_interface_sub
, "helloOut",
3770 json_object_int_add(json_interface_sub
, "dbDescIn",
3772 json_object_int_add(json_interface_sub
, "dbDescOut",
3774 json_object_int_add(json_interface_sub
, "lsReqIn",
3776 json_object_int_add(json_interface_sub
, "lsReqOut",
3778 json_object_int_add(json_interface_sub
, "lsUpdIn",
3780 json_object_int_add(json_interface_sub
, "lsUpdOut",
3782 json_object_int_add(json_interface_sub
, "lsAckIn",
3784 json_object_int_add(json_interface_sub
, "lsAckOut",
3788 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3789 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3790 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3791 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3792 oi
->ls_ack_in
, oi
->ls_ack_out
);
3796 /* OSPFv2 Packet Counters */
3797 static int show_ip_ospf_interface_traffic_common(
3798 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3799 int display_once
, uint8_t use_vrf
, uint8_t use_json
)
3801 struct vrf
*vrf
= NULL
;
3802 struct interface
*ifp
= NULL
;
3803 json_object
*json_vrf
= NULL
;
3804 json_object
*json_interface_sub
= NULL
;
3806 if (!use_json
&& !display_once
) {
3808 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3809 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3811 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3812 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3815 "--------------------------------------------------------------------------------------------\n");
3816 } else if (use_json
) {
3818 json_vrf
= json_object_new_object();
3823 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3825 if (intf_name
== NULL
) {
3826 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3827 FOR_ALL_INTERFACES (vrf
, ifp
) {
3828 struct route_node
*rn
;
3829 struct ospf_interface
*oi
;
3831 if (ospf_oi_count(ifp
) == 0)
3834 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3835 rn
= route_next(rn
)) {
3842 json_interface_sub
=
3843 json_object_new_object();
3846 show_ip_ospf_interface_traffic_sub(
3847 vty
, oi
, json_interface_sub
, use_json
);
3849 json_object_object_add(
3850 json_vrf
, ifp
->name
,
3851 json_interface_sub
);
3856 /* Interface name is specified. */
3857 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3859 struct route_node
*rn
;
3860 struct ospf_interface
*oi
;
3862 if (ospf_oi_count(ifp
) == 0) {
3864 " OSPF not enabled on this interface %s\n",
3869 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3870 rn
= route_next(rn
)) {
3874 json_interface_sub
=
3875 json_object_new_object();
3878 show_ip_ospf_interface_traffic_sub(
3879 vty
, oi
, json_interface_sub
, use_json
);
3881 json_object_object_add(
3882 json_vrf
, ifp
->name
,
3883 json_interface_sub
);
3891 if (ospf
->vrf_id
== VRF_DEFAULT
)
3892 json_object_object_add(json
, "default",
3895 json_object_object_add(json
, ospf
->name
,
3904 DEFUN (show_ip_ospf_interface
,
3905 show_ip_ospf_interface_cmd
,
3906 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3909 "OSPF information\n"
3912 "Interface information\n"
3917 uint8_t uj
= use_json(argc
, argv
);
3918 struct listnode
*node
= NULL
;
3919 char *vrf_name
= NULL
, *intf_name
= NULL
;
3920 bool all_vrf
= FALSE
;
3921 int ret
= CMD_SUCCESS
;
3923 int idx_vrf
= 0, idx_intf
= 0;
3924 uint8_t use_vrf
= 0;
3925 json_object
*json
= NULL
;
3927 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3929 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3930 intf_name
= argv
[idx_intf
]->arg
;
3933 json
= json_object_new_object();
3935 /* vrf input is provided could be all or specific vrf*/
3939 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3940 if (!ospf
->oi_running
)
3942 ret
= show_ip_ospf_interface_common(
3943 vty
, ospf
, intf_name
, use_vrf
, json
,
3948 vty_out(vty
, "%s\n",
3949 json_object_to_json_string_ext(
3950 json
, JSON_C_TO_STRING_PRETTY
));
3951 json_object_free(json
);
3956 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3957 if (ospf
== NULL
|| !ospf
->oi_running
) {
3959 json_object_free(json
);
3962 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3966 /* Display default ospf (instance 0) info */
3967 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3968 if (ospf
== NULL
|| !ospf
->oi_running
) {
3970 json_object_free(json
);
3973 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3978 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3979 json
, JSON_C_TO_STRING_PRETTY
));
3980 json_object_free(json
);
3986 DEFUN (show_ip_ospf_instance_interface
,
3987 show_ip_ospf_instance_interface_cmd
,
3988 "show ip ospf (1-65535) interface [INTERFACE] [json]",
3991 "OSPF information\n"
3993 "Interface information\n"
4000 unsigned short instance
= 0;
4001 uint8_t uj
= use_json(argc
, argv
);
4002 char *intf_name
= NULL
;
4003 int ret
= CMD_SUCCESS
;
4004 json_object
*json
= NULL
;
4006 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4007 ospf
= ospf_lookup_instance(instance
);
4009 return CMD_NOT_MY_INSTANCE
;
4011 if (!ospf
->oi_running
)
4015 json
= json_object_new_object();
4017 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4018 intf_name
= argv
[idx_intf
]->arg
;
4020 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4023 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4024 json
, JSON_C_TO_STRING_PRETTY
));
4025 json_object_free(json
);
4031 DEFUN (show_ip_ospf_interface_traffic
,
4032 show_ip_ospf_interface_traffic_cmd
,
4033 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4036 "OSPF information\n"
4039 "Interface information\n"
4040 "Protocol Packet counters\n"
4044 struct ospf
*ospf
= NULL
;
4045 struct listnode
*node
= NULL
;
4046 char *vrf_name
= NULL
, *intf_name
= NULL
;
4047 bool all_vrf
= FALSE
;
4049 int idx_vrf
= 0, idx_intf
= 0;
4050 uint8_t uj
= use_json(argc
, argv
);
4051 json_object
*json
= NULL
;
4052 int ret
= CMD_SUCCESS
;
4053 int display_once
= 0;
4054 uint8_t use_vrf
= 0;
4056 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4058 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4059 intf_name
= argv
[idx_intf
]->arg
;
4062 json
= json_object_new_object();
4067 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4068 if (!ospf
->oi_running
)
4071 ret
= show_ip_ospf_interface_traffic_common(
4072 vty
, ospf
, intf_name
, json
,
4073 display_once
, use_vrf
, uj
);
4078 vty_out(vty
, "%s\n",
4079 json_object_to_json_string_ext(
4080 json
, JSON_C_TO_STRING_PRETTY
));
4081 json_object_free(json
);
4086 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4087 if (ospf
== NULL
|| !ospf
->oi_running
) {
4089 json_object_free(json
);
4093 ret
= show_ip_ospf_interface_traffic_common(
4094 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4096 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4097 if (ospf
== NULL
|| !ospf
->oi_running
) {
4099 json_object_free(json
);
4103 ret
= show_ip_ospf_interface_traffic_common(
4104 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4108 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4109 json
, JSON_C_TO_STRING_PRETTY
));
4110 json_object_free(json
);
4117 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4119 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4120 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4121 "Interface", "RXmtL", "RqstL", "DBsmL");
4124 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4125 struct ospf_interface
*oi
,
4126 json_object
*json
, uint8_t use_json
)
4128 struct route_node
*rn
;
4129 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4131 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4132 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4134 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4135 if ((nbr
= rn
->info
)) {
4136 /* Do not show myself. */
4137 if (nbr
== oi
->nbr_self
)
4139 /* Down state is not shown. */
4140 if (nbr
->state
== NSM_Down
)
4143 char neigh_str
[INET_ADDRSTRLEN
];
4146 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4148 /* Start new neigh list */
4149 json_neigh_array
= NULL
;
4152 if (nbr
->state
== NSM_Attempt
4153 && nbr
->router_id
.s_addr
== 0)
4154 strlcpy(neigh_str
, "neighbor",
4158 inet_ntoa(nbr
->router_id
),
4161 json_object_object_get_ex(json
, neigh_str
,
4164 if (!json_neigh_array
) {
4166 json_object_new_array();
4167 json_object_object_add(
4172 json_neighbor
= json_object_new_object();
4174 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4180 &nbr
->t_inactivity
->u
.sands
,
4184 json_object_int_add(json_neighbor
, "priority",
4186 json_object_string_add(json_neighbor
, "state",
4188 json_object_int_add(json_neighbor
,
4191 json_object_string_add(json_neighbor
, "address",
4192 inet_ntoa(nbr
->src
));
4193 json_object_string_add(json_neighbor
,
4196 json_object_int_add(
4197 json_neighbor
, "retransmitCounter",
4198 ospf_ls_retransmit_count(nbr
));
4199 json_object_int_add(json_neighbor
,
4201 ospf_ls_request_count(nbr
));
4202 json_object_int_add(json_neighbor
,
4204 ospf_db_summary_count(nbr
));
4206 json_object_array_add(json_neigh_array
,
4209 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4211 if (nbr
->state
== NSM_Attempt
4212 && nbr
->router_id
.s_addr
== 0)
4213 vty_out(vty
, "%-15s %3d %-15s ", "-",
4214 nbr
->priority
, msgbuf
);
4216 vty_out(vty
, "%-15s %3d %-15s ",
4217 inet_ntoa(nbr
->router_id
),
4218 nbr
->priority
, msgbuf
);
4220 vty_out(vty
, "%9s ",
4221 ospf_timer_dump(nbr
->t_inactivity
,
4224 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4225 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4227 ospf_ls_retransmit_count(nbr
),
4228 ospf_ls_request_count(nbr
),
4229 ospf_db_summary_count(nbr
));
4236 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4237 json_object
*json
, uint8_t use_json
,
4240 struct ospf_interface
*oi
;
4241 struct listnode
*node
;
4242 json_object
*json_vrf
= NULL
;
4243 json_object
*json_nbr_sub
= NULL
;
4247 json_vrf
= json_object_new_object();
4250 json_nbr_sub
= json_object_new_object();
4253 if (ospf
->instance
) {
4255 json_object_int_add(json
, "ospfInstance",
4258 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4261 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4263 show_ip_ospf_neighbour_header(vty
);
4265 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4266 if (ospf_interface_neighbor_count(oi
) == 0)
4268 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4272 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4274 if (ospf
->vrf_id
== VRF_DEFAULT
)
4275 json_object_object_add(json
, "default",
4278 json_object_object_add(json
, ospf
->name
,
4287 DEFUN (show_ip_ospf_neighbor
,
4288 show_ip_ospf_neighbor_cmd
,
4289 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4292 "OSPF information\n"
4299 uint8_t uj
= use_json(argc
, argv
);
4300 struct listnode
*node
= NULL
;
4301 char *vrf_name
= NULL
;
4302 bool all_vrf
= FALSE
;
4303 int ret
= CMD_SUCCESS
;
4306 uint8_t use_vrf
= 0;
4307 json_object
*json
= NULL
;
4309 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4312 json
= json_object_new_object();
4314 /* vrf input is provided could be all or specific vrf*/
4318 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4319 if (!ospf
->oi_running
)
4321 ret
= show_ip_ospf_neighbor_common(
4322 vty
, ospf
, json
, uj
, use_vrf
);
4326 vty_out(vty
, "%s\n",
4327 json_object_to_json_string_ext(
4328 json
, JSON_C_TO_STRING_PRETTY
));
4329 json_object_free(json
);
4335 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4336 if (ospf
== NULL
|| !ospf
->oi_running
) {
4338 json_object_free(json
);
4342 /* Display default ospf (instance 0) info */
4343 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4344 if (ospf
== NULL
|| !ospf
->oi_running
) {
4346 json_object_free(json
);
4352 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4356 vty_out(vty
, "%s\n",
4357 json_object_to_json_string_ext(
4358 json
, JSON_C_TO_STRING_PRETTY
));
4363 json_object_free(json
);
4369 DEFUN (show_ip_ospf_instance_neighbor
,
4370 show_ip_ospf_instance_neighbor_cmd
,
4371 "show ip ospf (1-65535) neighbor [json]",
4374 "OSPF information\n"
4381 unsigned short instance
= 0;
4382 uint8_t uj
= use_json(argc
, argv
);
4383 json_object
*json
= NULL
;
4384 int ret
= CMD_SUCCESS
;
4386 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4387 ospf
= ospf_lookup_instance(instance
);
4389 return CMD_NOT_MY_INSTANCE
;
4391 if (!ospf
->oi_running
)
4395 json
= json_object_new_object();
4397 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4400 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4401 json
, JSON_C_TO_STRING_PRETTY
));
4402 json_object_free(json
);
4408 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4409 json_object
*json
, uint8_t use_json
,
4412 struct listnode
*node
;
4413 struct ospf_interface
*oi
;
4414 json_object
*json_vrf
= NULL
;
4415 json_object
*json_neighbor_sub
= NULL
;
4419 json_vrf
= json_object_new_object();
4422 json_neighbor_sub
= json_object_new_object();
4425 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4427 show_ip_ospf_neighbour_header(vty
);
4429 if (ospf
->instance
) {
4431 json_object_int_add(json_vrf
, "ospfInstance",
4434 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4437 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4438 struct listnode
*nbr_node
;
4439 struct ospf_nbr_nbma
*nbr_nbma
;
4441 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4443 /* print Down neighbor status */
4444 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4445 if (nbr_nbma
->nbr
== NULL
4446 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4448 json_object_int_add(json_neighbor_sub
,
4450 nbr_nbma
->priority
);
4451 json_object_boolean_true_add(
4454 json_object_string_add(
4458 json_object_int_add(
4460 "nbrNbmaRetransmitCounter", 0);
4461 json_object_int_add(
4463 "nbrNbmaRequestCounter", 0);
4464 json_object_int_add(
4466 "nbrNbmaDbSummaryCounter", 0);
4467 json_object_object_add(
4469 inet_ntoa(nbr_nbma
->addr
),
4472 vty_out(vty
, "%-15s %3d %-15s %9s ",
4473 "-", nbr_nbma
->priority
, "Down",
4476 "%-15s %-20s %5d %5d %5d\n",
4477 inet_ntoa(nbr_nbma
->addr
),
4478 IF_NAME(oi
), 0, 0, 0);
4486 if (ospf
->vrf_id
== VRF_DEFAULT
)
4487 json_object_object_add(json
, "default",
4490 json_object_object_add(json
, ospf
->name
,
4499 DEFUN (show_ip_ospf_neighbor_all
,
4500 show_ip_ospf_neighbor_all_cmd
,
4501 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4504 "OSPF information\n"
4508 "include down status neighbor\n"
4512 uint8_t uj
= use_json(argc
, argv
);
4513 struct listnode
*node
= NULL
;
4514 char *vrf_name
= NULL
;
4515 bool all_vrf
= FALSE
;
4516 int ret
= CMD_SUCCESS
;
4519 uint8_t use_vrf
= 0;
4520 json_object
*json
= NULL
;
4522 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4525 json
= json_object_new_object();
4527 /* vrf input is provided could be all or specific vrf*/
4531 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4532 if (!ospf
->oi_running
)
4534 ret
= show_ip_ospf_neighbor_all_common(
4535 vty
, ospf
, json
, uj
, use_vrf
);
4539 vty_out(vty
, "%s\n",
4540 json_object_to_json_string_ext(
4541 json
, JSON_C_TO_STRING_PRETTY
));
4542 json_object_free(json
);
4548 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4549 if (ospf
== NULL
|| !ospf
->oi_running
) {
4551 json_object_free(json
);
4555 /* Display default ospf (instance 0) info */
4556 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4557 if (ospf
== NULL
|| !ospf
->oi_running
) {
4559 json_object_free(json
);
4565 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4568 vty_out(vty
, "%s\n",
4569 json_object_to_json_string_ext(
4570 json
, JSON_C_TO_STRING_PRETTY
));
4575 json_object_free(json
);
4580 DEFUN (show_ip_ospf_instance_neighbor_all
,
4581 show_ip_ospf_instance_neighbor_all_cmd
,
4582 "show ip ospf (1-65535) neighbor all [json]",
4585 "OSPF information\n"
4588 "include down status neighbor\n"
4593 unsigned short instance
= 0;
4594 uint8_t uj
= use_json(argc
, argv
);
4595 json_object
*json
= NULL
;
4596 int ret
= CMD_SUCCESS
;
4598 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4599 ospf
= ospf_lookup_instance(instance
);
4601 return CMD_NOT_MY_INSTANCE
;
4603 if (!ospf
->oi_running
)
4606 json
= json_object_new_object();
4608 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4611 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4612 json
, JSON_C_TO_STRING_PRETTY
));
4613 json_object_free(json
);
4619 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4621 struct cmd_token
**argv
,
4622 uint8_t use_json
, uint8_t use_vrf
)
4624 struct interface
*ifp
;
4625 struct route_node
*rn
;
4626 json_object
*json
= NULL
;
4629 json
= json_object_new_object();
4631 if (ospf
->instance
) {
4633 json_object_int_add(json
, "ospfInstance",
4636 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4639 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4641 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4644 json_object_boolean_true_add(json
, "noSuchIface");
4646 vty_out(vty
, "No such interface.\n");
4650 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4651 struct ospf_interface
*oi
= rn
->info
;
4656 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4660 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4661 json
, JSON_C_TO_STRING_PRETTY
));
4662 json_object_free(json
);
4669 DEFUN (show_ip_ospf_neighbor_int
,
4670 show_ip_ospf_neighbor_int_cmd
,
4671 "show ip ospf neighbor IFNAME [json]",
4674 "OSPF information\n"
4681 uint8_t uj
= use_json(argc
, argv
);
4682 struct listnode
*node
= NULL
;
4683 int ret
= CMD_SUCCESS
;
4684 struct interface
*ifp
= NULL
;
4687 show_ip_ospf_neighbour_header(vty
);
4689 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4690 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4691 if (!ospf
->oi_running
)
4693 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4695 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4702 DEFUN (show_ip_ospf_instance_neighbor_int
,
4703 show_ip_ospf_instance_neighbor_int_cmd
,
4704 "show ip ospf (1-65535) neighbor IFNAME [json]",
4707 "OSPF information\n"
4716 unsigned short instance
= 0;
4717 uint8_t uj
= use_json(argc
, argv
);
4720 show_ip_ospf_neighbour_header(vty
);
4722 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4723 ospf
= ospf_lookup_instance(instance
);
4725 return CMD_NOT_MY_INSTANCE
;
4727 if (!ospf
->oi_running
)
4731 show_ip_ospf_neighbour_header(vty
);
4733 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4737 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4738 struct ospf_interface
*oi
,
4739 struct ospf_nbr_nbma
*nbr_nbma
,
4743 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4744 json_object
*json_sub
= NULL
;
4747 json_sub
= json_object_new_object();
4748 else /* Show neighbor ID. */
4749 vty_out(vty
, " Neighbor %s,", "-");
4751 /* Show interface address. */
4753 json_object_string_add(json_sub
, "ifaceAddress",
4754 inet_ntoa(nbr_nbma
->addr
));
4756 vty_out(vty
, " interface address %s\n",
4757 inet_ntoa(nbr_nbma
->addr
));
4761 json_object_string_add(json_sub
, "areaId",
4762 ospf_area_desc_string(oi
->area
));
4763 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4765 vty_out(vty
, " In the area %s via interface %s\n",
4766 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4768 /* Show neighbor priority and state. */
4770 json_object_int_add(json_sub
, "nbrPriority",
4771 nbr_nbma
->priority
);
4772 json_object_string_add(json_sub
, "nbrState", "down");
4774 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4775 nbr_nbma
->priority
, "Down");
4777 /* Show state changes. */
4779 json_object_int_add(json_sub
, "stateChangeCounter",
4780 nbr_nbma
->state_change
);
4782 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4784 /* Show PollInterval */
4786 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4788 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4790 /* Show poll-interval timer. */
4791 if (nbr_nbma
->t_poll
) {
4794 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4796 json_object_int_add(json_sub
,
4797 "pollIntervalTimerDueMsec",
4800 vty_out(vty
, " Poll timer due in %s\n",
4801 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4805 /* Show poll-interval timer thread. */
4807 if (nbr_nbma
->t_poll
!= NULL
)
4808 json_object_string_add(json_sub
,
4809 "pollIntervalTimerThread", "on");
4811 vty_out(vty
, " Thread Poll Timer %s\n",
4812 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4815 json_object_object_add(json
, "noNbrId", json_sub
);
4818 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4819 struct ospf_interface
*oi
,
4820 struct ospf_neighbor
*nbr
,
4824 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4825 json_object
*json_sub
= NULL
;
4828 json_sub
= json_object_new_object();
4830 /* Show neighbor ID. */
4831 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4832 vty_out(vty
, " Neighbor %s,", "-");
4834 vty_out(vty
, " Neighbor %s,",
4835 inet_ntoa(nbr
->router_id
));
4838 /* Show interface address. */
4840 json_object_string_add(json_sub
, "ifaceAddress",
4841 inet_ntoa(nbr
->address
.u
.prefix4
));
4843 vty_out(vty
, " interface address %s\n",
4844 inet_ntoa(nbr
->address
.u
.prefix4
));
4848 json_object_string_add(json_sub
, "areaId",
4849 ospf_area_desc_string(oi
->area
));
4850 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4852 vty_out(vty
, " In the area %s via interface %s\n",
4853 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4855 /* Show neighbor priority and state. */
4857 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4858 json_object_string_add(
4859 json_sub
, "nbrState",
4860 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4862 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4864 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4866 /* Show state changes. */
4868 json_object_int_add(json_sub
, "stateChangeCounter",
4871 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4873 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4878 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4880 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4884 " Most recent state change statistics:\n");
4885 vty_out(vty
, " Progressive change %s ago\n",
4886 ospf_timeval_dump(&res
, timebuf
,
4891 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4896 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4898 json_object_int_add(json_sub
,
4899 "lastRegressiveChangeMsec",
4901 if (nbr
->last_regress_str
)
4902 json_object_string_add(
4903 json_sub
, "lastRegressiveChangeReason",
4904 nbr
->last_regress_str
);
4907 " Regressive change %s ago, due to %s\n",
4908 ospf_timeval_dump(&res
, timebuf
,
4910 (nbr
->last_regress_str
? nbr
->last_regress_str
4915 /* Show Designated Rotuer ID. */
4917 json_object_string_add(json_sub
, "routerDesignatedId",
4918 inet_ntoa(nbr
->d_router
));
4920 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4922 /* Show Backup Designated Rotuer ID. */
4924 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4925 inet_ntoa(nbr
->bd_router
));
4927 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4931 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4932 json_object_string_add(json_sub
, "optionsList",
4933 ospf_options_dump(nbr
->options
));
4935 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4936 ospf_options_dump(nbr
->options
));
4938 /* Show Router Dead interval timer. */
4940 if (nbr
->t_inactivity
) {
4942 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4945 json_object_int_add(json_sub
,
4946 "routerDeadIntervalTimerDueMsec",
4949 json_object_int_add(
4950 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
4952 vty_out(vty
, " Dead timer due in %s\n",
4953 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4956 /* Show Database Summary list. */
4958 json_object_int_add(json_sub
, "databaseSummaryListCounter",
4959 ospf_db_summary_count(nbr
));
4961 vty_out(vty
, " Database Summary List %d\n",
4962 ospf_db_summary_count(nbr
));
4964 /* Show Link State Request list. */
4966 json_object_int_add(json_sub
, "linkStateRequestListCounter",
4967 ospf_ls_request_count(nbr
));
4969 vty_out(vty
, " Link State Request List %ld\n",
4970 ospf_ls_request_count(nbr
));
4972 /* Show Link State Retransmission list. */
4974 json_object_int_add(json_sub
,
4975 "linkStateRetransmissionListCounter",
4976 ospf_ls_retransmit_count(nbr
));
4978 vty_out(vty
, " Link State Retransmission List %ld\n",
4979 ospf_ls_retransmit_count(nbr
));
4981 /* Show inactivity timer thread. */
4983 if (nbr
->t_inactivity
!= NULL
)
4984 json_object_string_add(json_sub
,
4985 "threadInactivityTimer", "on");
4987 vty_out(vty
, " Thread Inactivity Timer %s\n",
4988 nbr
->t_inactivity
!= NULL
? "on" : "off");
4990 /* Show Database Description retransmission thread. */
4992 if (nbr
->t_db_desc
!= NULL
)
4993 json_object_string_add(
4995 "threadDatabaseDescriptionRetransmission",
4999 " Thread Database Description Retransmision %s\n",
5000 nbr
->t_db_desc
!= NULL
? "on" : "off");
5002 /* Show Link State Request Retransmission thread. */
5004 if (nbr
->t_ls_req
!= NULL
)
5005 json_object_string_add(
5007 "threadLinkStateRequestRetransmission", "on");
5010 " Thread Link State Request Retransmission %s\n",
5011 nbr
->t_ls_req
!= NULL
? "on" : "off");
5013 /* Show Link State Update Retransmission thread. */
5015 if (nbr
->t_ls_upd
!= NULL
)
5016 json_object_string_add(
5017 json_sub
, "threadLinkStateUpdateRetransmission",
5021 " Thread Link State Update Retransmission %s\n\n",
5022 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5025 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5026 json_object_object_add(json
, "noNbrId", json_sub
);
5028 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5032 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5035 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5037 struct cmd_token
**argv
,
5038 uint8_t use_json
, uint8_t use_vrf
)
5040 struct listnode
*node
;
5041 struct ospf_neighbor
*nbr
;
5042 struct ospf_interface
*oi
;
5043 struct in_addr router_id
;
5045 json_object
*json
= NULL
;
5048 json
= json_object_new_object();
5050 if (ospf
->instance
) {
5052 json_object_int_add(json
, "ospfInstance",
5055 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5058 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5060 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5063 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5065 vty_out(vty
, "{}\n");
5066 json_object_free(json
);
5071 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5072 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5073 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5079 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5080 json
, JSON_C_TO_STRING_PRETTY
));
5081 json_object_free(json
);
5088 DEFUN (show_ip_ospf_neighbor_id
,
5089 show_ip_ospf_neighbor_id_cmd
,
5090 "show ip ospf neighbor A.B.C.D [json]",
5093 "OSPF information\n"
5099 uint8_t uj
= use_json(argc
, argv
);
5100 struct listnode
*node
= NULL
;
5101 int ret
= CMD_SUCCESS
;
5103 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5104 if (!ospf
->oi_running
)
5106 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0, argv
, uj
,
5113 DEFUN (show_ip_ospf_instance_neighbor_id
,
5114 show_ip_ospf_instance_neighbor_id_cmd
,
5115 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5118 "OSPF information\n"
5125 int idx_router_id
= 5;
5127 unsigned short instance
= 0;
5128 uint8_t uj
= use_json(argc
, argv
);
5130 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5131 ospf
= ospf_lookup_instance(instance
);
5133 return CMD_NOT_MY_INSTANCE
;
5135 if (!ospf
->oi_running
)
5138 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5142 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5148 struct ospf_interface
*oi
;
5149 struct listnode
*node
;
5150 json_object
*json_vrf
= NULL
;
5154 json_vrf
= json_object_new_object();
5158 if (ospf
->instance
) {
5160 json_object_int_add(json_vrf
, "ospfInstance",
5163 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5166 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5168 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5169 struct route_node
*rn
;
5170 struct ospf_neighbor
*nbr
;
5172 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5173 if ((nbr
= rn
->info
)) {
5174 if (nbr
!= oi
->nbr_self
) {
5175 if (nbr
->state
!= NSM_Down
) {
5176 show_ip_ospf_neighbor_detail_sub(
5177 vty
, oi
, nbr
, json_vrf
,
5187 if (ospf
->vrf_id
== VRF_DEFAULT
)
5188 json_object_object_add(json
, "default",
5191 json_object_object_add(json
, ospf
->name
,
5200 DEFUN (show_ip_ospf_neighbor_detail
,
5201 show_ip_ospf_neighbor_detail_cmd
,
5202 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5205 "OSPF information\n"
5209 "detail of all neighbors\n"
5213 uint8_t uj
= use_json(argc
, argv
);
5214 struct listnode
*node
= NULL
;
5215 char *vrf_name
= NULL
;
5216 bool all_vrf
= FALSE
;
5217 int ret
= CMD_SUCCESS
;
5220 uint8_t use_vrf
= 0;
5221 json_object
*json
= NULL
;
5223 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5226 json
= json_object_new_object();
5228 /* vrf input is provided could be all or specific vrf*/
5232 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5233 if (!ospf
->oi_running
)
5235 ret
= show_ip_ospf_neighbor_detail_common(
5236 vty
, ospf
, json
, uj
, use_vrf
);
5239 vty_out(vty
, "%s\n",
5240 json_object_to_json_string_ext(
5241 json
, JSON_C_TO_STRING_PRETTY
));
5242 json_object_free(json
);
5247 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5248 if (ospf
== NULL
|| !ospf
->oi_running
) {
5250 json_object_free(json
);
5254 /* Display default ospf (instance 0) info */
5255 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5256 if (ospf
== NULL
|| !ospf
->oi_running
) {
5258 json_object_free(json
);
5264 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5267 vty_out(vty
, "%s\n",
5268 json_object_to_json_string_ext(
5269 json
, JSON_C_TO_STRING_PRETTY
));
5274 json_object_free(json
);
5279 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5280 show_ip_ospf_instance_neighbor_detail_cmd
,
5281 "show ip ospf (1-65535) neighbor detail [json]",
5284 "OSPF information\n"
5287 "detail of all neighbors\n"
5292 unsigned short instance
= 0;
5293 uint8_t uj
= use_json(argc
, argv
);
5294 json_object
*json
= NULL
;
5295 int ret
= CMD_SUCCESS
;
5297 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5298 ospf
= ospf_lookup_instance(instance
);
5300 return CMD_NOT_MY_INSTANCE
;
5302 if (!ospf
->oi_running
)
5306 json
= json_object_new_object();
5308 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5311 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5312 json
, JSON_C_TO_STRING_PRETTY
));
5313 json_object_free(json
);
5319 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5325 struct listnode
*node
;
5326 struct ospf_interface
*oi
;
5327 json_object
*json_vrf
= NULL
;
5331 json_vrf
= json_object_new_object();
5336 if (ospf
->instance
) {
5338 json_object_int_add(json
, "ospfInstance",
5341 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5344 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5346 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5347 struct route_node
*rn
;
5348 struct ospf_neighbor
*nbr
;
5349 struct ospf_nbr_nbma
*nbr_nbma
;
5351 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5352 if ((nbr
= rn
->info
))
5353 if (nbr
!= oi
->nbr_self
)
5354 if (nbr
->state
!= NSM_Down
)
5355 show_ip_ospf_neighbor_detail_sub(
5357 json_vrf
, use_json
);
5359 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5360 struct listnode
*nd
;
5362 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5363 if (nbr_nbma
->nbr
== NULL
5364 || nbr_nbma
->nbr
->state
== NSM_Down
)
5365 show_ip_ospf_nbr_nbma_detail_sub(
5366 vty
, oi
, nbr_nbma
, use_json
,
5374 if (ospf
->vrf_id
== VRF_DEFAULT
)
5375 json_object_object_add(json
, "default",
5378 json_object_object_add(json
, ospf
->name
,
5388 DEFUN (show_ip_ospf_neighbor_detail_all
,
5389 show_ip_ospf_neighbor_detail_all_cmd
,
5390 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5393 "OSPF information\n"
5397 "detail of all neighbors\n"
5398 "include down status neighbor\n"
5402 uint8_t uj
= use_json(argc
, argv
);
5403 struct listnode
*node
= NULL
;
5404 char *vrf_name
= NULL
;
5405 bool all_vrf
= FALSE
;
5406 int ret
= CMD_SUCCESS
;
5409 uint8_t use_vrf
= 0;
5410 json_object
*json
= NULL
;
5412 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5415 json
= json_object_new_object();
5417 /* vrf input is provided could be all or specific vrf*/
5421 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5422 if (!ospf
->oi_running
)
5424 ret
= show_ip_ospf_neighbor_detail_all_common(
5425 vty
, ospf
, json
, uj
, use_vrf
);
5429 vty_out(vty
, "%s\n",
5430 json_object_to_json_string_ext(
5431 json
, JSON_C_TO_STRING_PRETTY
));
5432 json_object_free(json
);
5437 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5438 if (ospf
== NULL
|| !ospf
->oi_running
) {
5440 json_object_free(json
);
5444 /* Display default ospf (instance 0) info */
5445 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5446 if (ospf
== NULL
|| !ospf
->oi_running
) {
5448 json_object_free(json
);
5454 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5457 vty_out(vty
, "%s\n",
5458 json_object_to_json_string_ext(
5459 json
, JSON_C_TO_STRING_PRETTY
));
5464 json_object_free(json
);
5469 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5470 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5471 "show ip ospf (1-65535) neighbor detail all [json]",
5474 "OSPF information\n"
5477 "detail of all neighbors\n"
5478 "include down status neighbor\n"
5483 unsigned short instance
= 0;
5484 uint8_t uj
= use_json(argc
, argv
);
5485 json_object
*json
= NULL
;
5486 int ret
= CMD_SUCCESS
;
5488 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5489 ospf
= ospf_lookup_instance(instance
);
5491 return CMD_NOT_MY_INSTANCE
;
5493 if (!ospf
->oi_running
)
5497 json
= json_object_new_object();
5499 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5502 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5503 json
, JSON_C_TO_STRING_PRETTY
));
5504 json_object_free(json
);
5510 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5513 struct cmd_token
**argv
,
5516 struct ospf_interface
*oi
;
5517 struct interface
*ifp
;
5518 struct route_node
*rn
, *nrn
;
5519 struct ospf_neighbor
*nbr
;
5520 json_object
*json
= NULL
;
5523 json
= json_object_new_object();
5525 if (ospf
->instance
) {
5527 json_object_int_add(json
, "ospfInstance",
5530 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5533 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5536 vty_out(vty
, "No such interface.\n");
5538 vty_out(vty
, "{}\n");
5539 json_object_free(json
);
5544 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5545 if ((oi
= rn
->info
)) {
5546 for (nrn
= route_top(oi
->nbrs
); nrn
;
5547 nrn
= route_next(nrn
)) {
5548 if ((nbr
= nrn
->info
)) {
5549 if (nbr
!= oi
->nbr_self
) {
5550 if (nbr
->state
!= NSM_Down
)
5551 show_ip_ospf_neighbor_detail_sub(
5561 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5562 json
, JSON_C_TO_STRING_PRETTY
));
5563 json_object_free(json
);
5570 DEFUN (show_ip_ospf_neighbor_int_detail
,
5571 show_ip_ospf_neighbor_int_detail_cmd
,
5572 "show ip ospf neighbor IFNAME detail [json]",
5575 "OSPF information\n"
5578 "detail of all neighbors\n"
5582 uint8_t uj
= use_json(argc
, argv
);
5583 struct listnode
*node
= NULL
;
5584 int ret
= CMD_SUCCESS
;
5586 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5587 if (!ospf
->oi_running
)
5589 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5596 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5597 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5598 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5601 "OSPF information\n"
5605 "detail of all neighbors\n"
5611 unsigned short instance
= 0;
5612 uint8_t uj
= use_json(argc
, argv
);
5614 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5615 ospf
= ospf_lookup_instance(instance
);
5617 return CMD_NOT_MY_INSTANCE
;
5619 if (!ospf
->oi_running
)
5622 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5626 /* Show functions */
5627 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5629 struct router_lsa
*rl
;
5630 struct summary_lsa
*sl
;
5631 struct as_external_lsa
*asel
;
5632 struct prefix_ipv4 p
;
5635 /* If self option is set, check LSA self flag. */
5636 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5637 /* LSA common part show. */
5638 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5639 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5640 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5641 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5642 ntohs(lsa
->data
->checksum
));
5643 /* LSA specific part show. */
5644 switch (lsa
->data
->type
) {
5645 case OSPF_ROUTER_LSA
:
5646 rl
= (struct router_lsa
*)lsa
->data
;
5647 vty_out(vty
, " %-d", ntohs(rl
->links
));
5649 case OSPF_SUMMARY_LSA
:
5650 sl
= (struct summary_lsa
*)lsa
->data
;
5653 p
.prefix
= sl
->header
.id
;
5654 p
.prefixlen
= ip_masklen(sl
->mask
);
5655 apply_mask_ipv4(&p
);
5657 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5660 case OSPF_AS_EXTERNAL_LSA
:
5661 case OSPF_AS_NSSA_LSA
:
5662 asel
= (struct as_external_lsa
*)lsa
->data
;
5665 p
.prefix
= asel
->header
.id
;
5666 p
.prefixlen
= ip_masklen(asel
->mask
);
5667 apply_mask_ipv4(&p
);
5669 vty_out(vty
, " %s %s/%d [0x%lx]",
5670 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5673 inet_ntoa(p
.prefix
), p
.prefixlen
,
5674 (unsigned long)ntohl(
5675 asel
->e
[0].route_tag
));
5677 case OSPF_NETWORK_LSA
:
5678 case OSPF_ASBR_SUMMARY_LSA
:
5679 case OSPF_OPAQUE_LINK_LSA
:
5680 case OSPF_OPAQUE_AREA_LSA
:
5681 case OSPF_OPAQUE_AS_LSA
:
5691 static const char *show_database_desc
[] = {
5693 "Router Link States",
5695 "Summary Link States",
5696 "ASBR-Summary Link States",
5697 "AS External Link States",
5698 "Group Membership LSA",
5699 "NSSA-external Link States",
5701 "Link-Local Opaque-LSA",
5702 "Area-Local Opaque-LSA",
5703 "AS-external Opaque-LSA",
5706 static const char *show_database_header
[] = {
5708 "Link ID ADV Router Age Seq# CkSum Link count",
5709 "Link ID ADV Router Age Seq# CkSum",
5710 "Link ID ADV Router Age Seq# CkSum Route",
5711 "Link ID ADV Router Age Seq# CkSum",
5712 "Link ID ADV Router Age Seq# CkSum Route",
5713 " --- header for Group Member ----",
5714 "Link ID ADV Router Age Seq# CkSum Route",
5716 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5717 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5718 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5721 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5723 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5725 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5726 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5727 ospf_options_dump(lsa
->data
->options
));
5728 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5729 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5732 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5733 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5736 vty_out(vty
, " :%s%s%s%s",
5737 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5738 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5739 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5741 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5746 vty_out(vty
, " LS Type: %s\n",
5747 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5748 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5749 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5750 vty_out(vty
, " Advertising Router: %s\n",
5751 inet_ntoa(lsa
->data
->adv_router
));
5752 vty_out(vty
, " LS Seq Number: %08lx\n",
5753 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5754 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5755 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5758 const char *link_type_desc
[] = {
5760 "another Router (point-to-point)",
5761 "a Transit Network",
5766 const char *link_id_desc
[] = {
5767 "(null)", "Neighboring Router ID", "Designated Router address",
5768 "Net", "Neighboring Router ID",
5771 const char *link_data_desc
[] = {
5772 "(null)", "Router Interface address", "Router Interface address",
5773 "Network Mask", "Router Interface address",
5776 /* Show router-LSA each Link information. */
5777 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5778 struct router_lsa
*rl
)
5783 len
= ntohs(rl
->header
.length
) - 4;
5784 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5785 type
= rl
->link
[i
].type
;
5787 vty_out(vty
, " Link connected to: %s\n",
5788 link_type_desc
[type
]);
5789 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5790 inet_ntoa(rl
->link
[i
].link_id
));
5791 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5792 inet_ntoa(rl
->link
[i
].link_data
));
5793 vty_out(vty
, " Number of TOS metrics: 0\n");
5794 vty_out(vty
, " TOS 0 Metric: %d\n",
5795 ntohs(rl
->link
[i
].metric
));
5800 /* Show router-LSA detail information. */
5801 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5804 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5806 show_ip_ospf_database_header(vty
, lsa
);
5808 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5810 show_ip_ospf_database_router_links(vty
, rl
);
5817 /* Show network-LSA detail information. */
5818 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5823 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5825 show_ip_ospf_database_header(vty
, lsa
);
5827 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5829 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5831 for (i
= 0; length
> 0; i
++, length
-= 4)
5832 vty_out(vty
, " Attached Router: %s\n",
5833 inet_ntoa(nl
->routers
[i
]));
5841 /* Show summary-LSA detail information. */
5842 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5845 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5847 show_ip_ospf_database_header(vty
, lsa
);
5849 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5850 vty_out(vty
, " TOS: 0 Metric: %d\n",
5851 GET_METRIC(sl
->metric
));
5858 /* Show summary-ASBR-LSA detail information. */
5859 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5862 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5864 show_ip_ospf_database_header(vty
, lsa
);
5866 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5867 vty_out(vty
, " TOS: 0 Metric: %d\n",
5868 GET_METRIC(sl
->metric
));
5875 /* Show AS-external-LSA detail information. */
5876 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5879 struct as_external_lsa
*al
=
5880 (struct as_external_lsa
*)lsa
->data
;
5882 show_ip_ospf_database_header(vty
, lsa
);
5884 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5885 vty_out(vty
, " Metric Type: %s\n",
5886 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5887 ? "2 (Larger than any link state path)"
5889 vty_out(vty
, " TOS: 0\n");
5890 vty_out(vty
, " Metric: %d\n",
5891 GET_METRIC(al
->e
[0].metric
));
5892 vty_out(vty
, " Forward Address: %s\n",
5893 inet_ntoa(al
->e
[0].fwd_addr
));
5896 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5897 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5904 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5906 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5908 /* show_ip_ospf_database_header (vty, lsa); */
5910 zlog_debug( " Network Mask: /%d%s",
5911 ip_masklen (al
->mask
), "\n");
5912 zlog_debug( " Metric Type: %s%s",
5913 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5914 "2 (Larger than any link state path)" : "1", "\n");
5915 zlog_debug( " TOS: 0%s", "\n");
5916 zlog_debug( " Metric: %d%s",
5917 GET_METRIC (al
->e
[0].metric
), "\n");
5918 zlog_debug( " Forward Address: %s%s",
5919 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5921 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5922 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5927 /* Show AS-NSSA-LSA detail information. */
5928 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5931 struct as_external_lsa
*al
=
5932 (struct as_external_lsa
*)lsa
->data
;
5934 show_ip_ospf_database_header(vty
, lsa
);
5936 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5937 vty_out(vty
, " Metric Type: %s\n",
5938 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5939 ? "2 (Larger than any link state path)"
5941 vty_out(vty
, " TOS: 0\n");
5942 vty_out(vty
, " Metric: %d\n",
5943 GET_METRIC(al
->e
[0].metric
));
5944 vty_out(vty
, " NSSA: Forward Address: %s\n",
5945 inet_ntoa(al
->e
[0].fwd_addr
));
5948 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5949 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5955 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
5960 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5963 show_ip_ospf_database_header(vty
, lsa
);
5964 show_opaque_info_detail(vty
, lsa
);
5971 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
5973 show_router_lsa_detail
,
5974 show_network_lsa_detail
,
5975 show_summary_lsa_detail
,
5976 show_summary_asbr_lsa_detail
,
5977 show_as_external_lsa_detail
,
5979 show_as_nssa_lsa_detail
, /* almost same as external */
5981 show_opaque_lsa_detail
,
5982 show_opaque_lsa_detail
,
5983 show_opaque_lsa_detail
,
5986 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
5987 struct in_addr
*id
, struct in_addr
*adv_router
)
5989 memset(lp
, 0, sizeof(struct prefix_ls
));
5993 else if (adv_router
== NULL
) {
5999 lp
->adv_router
= *adv_router
;
6003 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6004 struct in_addr
*id
, struct in_addr
*adv_router
)
6006 struct prefix_ls lp
;
6007 struct route_node
*rn
, *start
;
6008 struct ospf_lsa
*lsa
;
6010 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6011 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6013 route_lock_node(start
);
6014 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6015 if ((lsa
= rn
->info
)) {
6016 if (show_function
[lsa
->data
->type
] != NULL
)
6017 show_function
[lsa
->data
->type
](vty
,
6020 route_unlock_node(start
);
6024 /* Show detail LSA information
6025 -- if id is NULL then show all LSAs. */
6026 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6027 struct in_addr
*id
, struct in_addr
*adv_router
)
6029 struct listnode
*node
;
6030 struct ospf_area
*area
;
6033 case OSPF_AS_EXTERNAL_LSA
:
6034 case OSPF_OPAQUE_AS_LSA
:
6035 vty_out(vty
, " %s \n\n",
6036 show_database_desc
[type
]);
6037 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6040 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6041 vty_out(vty
, "\n %s (Area %s)\n\n",
6042 show_database_desc
[type
],
6043 ospf_area_desc_string(area
));
6044 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6051 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6052 struct route_table
*rt
,
6053 struct in_addr
*adv_router
)
6055 struct route_node
*rn
;
6056 struct ospf_lsa
*lsa
;
6058 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6059 if ((lsa
= rn
->info
))
6060 if (IPV4_ADDR_SAME(adv_router
,
6061 &lsa
->data
->adv_router
)) {
6062 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6064 if (show_function
[lsa
->data
->type
] != NULL
)
6065 show_function
[lsa
->data
->type
](vty
,
6070 /* Show detail LSA information. */
6071 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6072 int type
, struct in_addr
*adv_router
)
6074 struct listnode
*node
;
6075 struct ospf_area
*area
;
6078 case OSPF_AS_EXTERNAL_LSA
:
6079 case OSPF_OPAQUE_AS_LSA
:
6080 vty_out(vty
, " %s \n\n",
6081 show_database_desc
[type
]);
6082 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6086 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6087 vty_out(vty
, "\n %s (Area %s)\n\n",
6088 show_database_desc
[type
],
6089 ospf_area_desc_string(area
));
6090 show_lsa_detail_adv_router_proc(
6091 vty
, AREA_LSDB(area
, type
), adv_router
);
6097 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6100 struct ospf_lsa
*lsa
;
6101 struct route_node
*rn
;
6102 struct ospf_area
*area
;
6103 struct listnode
*node
;
6106 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6107 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6109 case OSPF_AS_EXTERNAL_LSA
:
6110 case OSPF_OPAQUE_AS_LSA
:
6115 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6117 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6118 vty_out(vty
, " %s (Area %s)\n\n",
6119 show_database_desc
[type
],
6120 ospf_area_desc_string(area
));
6121 vty_out(vty
, "%s\n",
6122 show_database_header
[type
]);
6124 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6125 show_lsa_summary(vty
, lsa
, self
);
6132 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6134 case OSPF_AS_EXTERNAL_LSA
:
6135 case OSPF_OPAQUE_AS_LSA
:
6140 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6141 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6142 vty_out(vty
, " %s\n\n",
6143 show_database_desc
[type
]);
6144 vty_out(vty
, "%s\n", show_database_header
[type
]);
6146 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6147 show_lsa_summary(vty
, lsa
, self
);
6156 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6158 struct route_node
*rn
;
6160 vty_out(vty
, "\n MaxAge Link States:\n\n");
6162 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6163 struct ospf_lsa
*lsa
;
6165 if ((lsa
= rn
->info
) != NULL
) {
6166 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6167 vty_out(vty
, "Link State ID: %s\n",
6168 inet_ntoa(lsa
->data
->id
));
6169 vty_out(vty
, "Advertising Router: %s\n",
6170 inet_ntoa(lsa
->data
->adv_router
));
6171 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6177 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6178 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6180 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6181 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6182 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6183 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6185 #define OSPF_LSA_TYPES_DESC \
6186 "ASBR summary link states\n" \
6187 "External link states\n" \
6188 "Network link states\n" \
6189 "Router link states\n" \
6190 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6191 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6192 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6194 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6195 int arg_base
, int argc
,
6196 struct cmd_token
**argv
,
6201 struct in_addr id
, adv_router
;
6204 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6206 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6208 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6209 inet_ntoa(ospf
->router_id
));
6212 if (argc
== arg_base
+ 4) {
6213 show_ip_ospf_database_summary(vty
, ospf
, 0);
6217 /* Set database type to show. */
6218 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6219 type
= OSPF_ROUTER_LSA
;
6220 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6221 type
= OSPF_NETWORK_LSA
;
6222 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6223 type
= OSPF_AS_NSSA_LSA
;
6224 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6225 type
= OSPF_SUMMARY_LSA
;
6226 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6227 type
= OSPF_ASBR_SUMMARY_LSA
;
6228 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6229 type
= OSPF_AS_EXTERNAL_LSA
;
6230 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6231 show_ip_ospf_database_summary(vty
, ospf
, 1);
6233 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6234 show_ip_ospf_database_maxage(vty
, ospf
);
6236 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6237 type
= OSPF_OPAQUE_LINK_LSA
;
6238 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6239 type
= OSPF_OPAQUE_AREA_LSA
;
6240 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6241 type
= OSPF_OPAQUE_AS_LSA
;
6245 /* `show ip ospf database LSA'. */
6246 if (argc
== arg_base
+ 5)
6247 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6248 else if (argc
>= arg_base
+ 6) {
6249 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6253 /* `show ip ospf database LSA ID'. */
6254 if (argc
== arg_base
+ 6)
6255 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6256 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6257 else if (argc
== arg_base
+ 7) {
6258 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6259 adv_router
= ospf
->router_id
;
6261 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6266 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6273 DEFUN (show_ip_ospf_database_max
,
6274 show_ip_ospf_database_max_cmd
,
6275 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6278 "OSPF information\n"
6281 "Database summary\n"
6282 "LSAs in MaxAge list\n"
6283 "Self-originated link states\n")
6285 struct ospf
*ospf
= NULL
;
6286 struct listnode
*node
= NULL
;
6287 char *vrf_name
= NULL
;
6288 bool all_vrf
= FALSE
;
6289 int ret
= CMD_SUCCESS
;
6292 uint8_t use_vrf
= 0;
6294 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6299 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6300 if (!ospf
->oi_running
)
6302 ret
= show_ip_ospf_database_common(
6303 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6307 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6308 if (ospf
== NULL
|| !ospf
->oi_running
)
6310 ret
= (show_ip_ospf_database_common(
6311 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6315 /* Display default ospf (instance 0) info */
6316 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6317 if (ospf
== NULL
|| !ospf
->oi_running
)
6319 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6326 DEFUN (show_ip_ospf_instance_database
,
6327 show_ip_ospf_instance_database_cmd
,
6328 "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>]]]",
6331 "OSPF information\n"
6334 "Database summary\n"
6336 "Link State ID (as an IP address)\n"
6337 "Self-originated link states\n"
6338 "Advertising Router link states\n"
6339 "Advertising Router (as an IP address)\n")
6342 unsigned short instance
= 0;
6343 struct listnode
*node
= NULL
;
6344 char *vrf_name
= NULL
;
6345 bool all_vrf
= FALSE
;
6346 int ret
= CMD_SUCCESS
;
6349 uint8_t use_vrf
= 0;
6351 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6352 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6353 ospf
= ospf_lookup_instance(instance
);
6355 return CMD_NOT_MY_INSTANCE
;
6356 if (!ospf
->oi_running
)
6359 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6360 argc
, argv
, use_vrf
));
6361 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6362 vrf_name
= argv
[++idx
]->arg
;
6363 all_vrf
= strmatch(vrf_name
, "all");
6369 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6370 if (!ospf
->oi_running
)
6372 ret
= (show_ip_ospf_database_common(
6373 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6377 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6378 if ((ospf
== NULL
) || !ospf
->oi_running
)
6380 ret
= (show_ip_ospf_database_common(
6381 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6384 /* Display default ospf (instance 0) info */
6385 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6386 if (ospf
== NULL
|| !ospf
->oi_running
)
6388 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6395 DEFUN (show_ip_ospf_instance_database_max
,
6396 show_ip_ospf_instance_database_max_cmd
,
6397 "show ip ospf (1-65535) database <max-age|self-originate>",
6400 "OSPF information\n"
6402 "Database summary\n"
6403 "LSAs in MaxAge list\n"
6404 "Self-originated link states\n")
6408 unsigned short instance
= 0;
6410 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6412 ospf
= ospf_lookup_instance(instance
);
6414 return CMD_NOT_MY_INSTANCE
;
6416 if (!ospf
->oi_running
)
6419 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6423 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6425 int arg_base
, int argc
,
6426 struct cmd_token
**argv
,
6431 struct in_addr adv_router
;
6434 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6436 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6438 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6439 inet_ntoa(ospf
->router_id
));
6441 /* Set database type to show. */
6442 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6443 type
= OSPF_ROUTER_LSA
;
6444 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6445 type
= OSPF_NETWORK_LSA
;
6446 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6447 type
= OSPF_AS_NSSA_LSA
;
6448 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6449 type
= OSPF_SUMMARY_LSA
;
6450 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6451 type
= OSPF_ASBR_SUMMARY_LSA
;
6452 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6453 type
= OSPF_AS_EXTERNAL_LSA
;
6454 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6455 type
= OSPF_OPAQUE_LINK_LSA
;
6456 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6457 type
= OSPF_OPAQUE_AREA_LSA
;
6458 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6459 type
= OSPF_OPAQUE_AS_LSA
;
6463 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6464 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6465 adv_router
= ospf
->router_id
;
6467 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6472 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6477 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6478 show_ip_ospf_instance_database_type_adv_router_cmd
,
6479 "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>",
6482 "OSPF information\n"
6485 "Database summary\n"
6487 "Advertising Router link states\n"
6488 "Advertising Router (as an IP address)\n"
6489 "Self-originated link states\n")
6491 struct ospf
*ospf
= NULL
;
6492 unsigned short instance
= 0;
6493 struct listnode
*node
= NULL
;
6494 char *vrf_name
= NULL
;
6495 bool all_vrf
= FALSE
;
6496 int ret
= CMD_SUCCESS
;
6498 int idx
= 0, idx_vrf
= 0;
6499 uint8_t use_vrf
= 0;
6501 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6502 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6503 ospf
= ospf_lookup_instance(instance
);
6505 return CMD_NOT_MY_INSTANCE
;
6506 if (!ospf
->oi_running
)
6508 return (show_ip_ospf_database_type_adv_router_common(
6509 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6512 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6517 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6518 if (!ospf
->oi_running
)
6520 ret
= show_ip_ospf_database_type_adv_router_common(
6521 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6525 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6526 if ((ospf
== NULL
) || !ospf
->oi_running
)
6528 ret
= show_ip_ospf_database_type_adv_router_common(
6529 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6532 /* Display default ospf (instance 0) info */
6533 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6534 if (ospf
== NULL
|| !ospf
->oi_running
)
6536 ret
= show_ip_ospf_database_type_adv_router_common(
6537 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6540 /*return (show_ip_ospf_database_type_adv_router_common(
6541 vty, ospf, idx ? 1 : 0, argc, argv));*/
6544 DEFUN (ip_ospf_authentication_args
,
6545 ip_ospf_authentication_args_addr_cmd
,
6546 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6548 "OSPF interface commands\n"
6549 "Enable authentication on this interface\n"
6550 "Use null authentication\n"
6551 "Use message-digest authentication\n"
6552 "Address of interface\n")
6554 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6555 int idx_encryption
= 3;
6557 struct in_addr addr
;
6559 struct ospf_if_params
*params
;
6561 params
= IF_DEF_PARAMS(ifp
);
6564 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6567 "Please specify interface address by A.B.C.D\n");
6568 return CMD_WARNING_CONFIG_FAILED
;
6571 params
= ospf_get_if_params(ifp
, addr
);
6572 ospf_if_update_params(ifp
, addr
);
6575 /* Handle null authentication */
6576 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6577 SET_IF_PARAM(params
, auth_type
);
6578 params
->auth_type
= OSPF_AUTH_NULL
;
6582 /* Handle message-digest authentication */
6583 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6584 SET_IF_PARAM(params
, auth_type
);
6585 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6589 vty_out(vty
, "You shouldn't get here!\n");
6590 return CMD_WARNING_CONFIG_FAILED
;
6593 DEFUN (ip_ospf_authentication
,
6594 ip_ospf_authentication_addr_cmd
,
6595 "ip ospf authentication [A.B.C.D]",
6597 "OSPF interface commands\n"
6598 "Enable authentication on this interface\n"
6599 "Address of interface\n")
6601 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6603 struct in_addr addr
;
6605 struct ospf_if_params
*params
;
6607 params
= IF_DEF_PARAMS(ifp
);
6610 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6613 "Please specify interface address by A.B.C.D\n");
6614 return CMD_WARNING_CONFIG_FAILED
;
6617 params
= ospf_get_if_params(ifp
, addr
);
6618 ospf_if_update_params(ifp
, addr
);
6621 SET_IF_PARAM(params
, auth_type
);
6622 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6627 DEFUN (no_ip_ospf_authentication_args
,
6628 no_ip_ospf_authentication_args_addr_cmd
,
6629 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6632 "OSPF interface commands\n"
6633 "Enable authentication on this interface\n"
6634 "Use null authentication\n"
6635 "Use message-digest authentication\n"
6636 "Address of interface\n")
6638 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6639 int idx_encryption
= 4;
6641 struct in_addr addr
;
6643 struct ospf_if_params
*params
;
6644 struct route_node
*rn
;
6647 params
= IF_DEF_PARAMS(ifp
);
6650 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6653 "Please specify interface address by A.B.C.D\n");
6654 return CMD_WARNING_CONFIG_FAILED
;
6657 params
= ospf_lookup_if_params(ifp
, addr
);
6658 if (params
== NULL
) {
6659 vty_out(vty
, "Ip Address specified is unknown\n");
6660 return CMD_WARNING_CONFIG_FAILED
;
6662 params
->auth_type
= OSPF_AUTH_NOTSET
;
6663 UNSET_IF_PARAM(params
, auth_type
);
6664 if (params
!= IF_DEF_PARAMS(ifp
)) {
6665 ospf_free_if_params(ifp
, addr
);
6666 ospf_if_update_params(ifp
, addr
);
6669 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6670 auth_type
= OSPF_AUTH_NULL
;
6671 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6672 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6674 vty_out(vty
, "Unexpected input encountered\n");
6675 return CMD_WARNING_CONFIG_FAILED
;
6678 * Here we have a case where the user has entered
6679 * 'no ip ospf authentication (null | message_digest )'
6680 * we need to find if we have any ip addresses underneath it
6682 * correspond to the associated type.
6684 if (params
->auth_type
== auth_type
) {
6685 params
->auth_type
= OSPF_AUTH_NOTSET
;
6686 UNSET_IF_PARAM(params
, auth_type
);
6689 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6690 rn
= route_next(rn
)) {
6691 if ((params
= rn
->info
)) {
6692 if (params
->auth_type
== auth_type
) {
6693 params
->auth_type
= OSPF_AUTH_NOTSET
;
6694 UNSET_IF_PARAM(params
, auth_type
);
6695 if (params
!= IF_DEF_PARAMS(ifp
)) {
6696 ospf_free_if_params(
6697 ifp
, rn
->p
.u
.prefix4
);
6698 ospf_if_update_params(
6699 ifp
, rn
->p
.u
.prefix4
);
6709 DEFUN (no_ip_ospf_authentication
,
6710 no_ip_ospf_authentication_addr_cmd
,
6711 "no ip ospf authentication [A.B.C.D]",
6714 "OSPF interface commands\n"
6715 "Enable authentication on this interface\n"
6716 "Address of interface\n")
6718 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6720 struct in_addr addr
;
6722 struct ospf_if_params
*params
;
6723 struct route_node
*rn
;
6725 params
= IF_DEF_PARAMS(ifp
);
6728 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6731 "Please specify interface address by A.B.C.D\n");
6732 return CMD_WARNING_CONFIG_FAILED
;
6735 params
= ospf_lookup_if_params(ifp
, addr
);
6736 if (params
== NULL
) {
6737 vty_out(vty
, "Ip Address specified is unknown\n");
6738 return CMD_WARNING_CONFIG_FAILED
;
6741 params
->auth_type
= OSPF_AUTH_NOTSET
;
6742 UNSET_IF_PARAM(params
, auth_type
);
6743 if (params
!= IF_DEF_PARAMS(ifp
)) {
6744 ospf_free_if_params(ifp
, addr
);
6745 ospf_if_update_params(ifp
, addr
);
6749 * When a user enters 'no ip ospf authentication'
6750 * We should remove all authentication types from
6753 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6754 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6755 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6756 params
->auth_type
= OSPF_AUTH_NOTSET
;
6757 UNSET_IF_PARAM(params
, auth_type
);
6760 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6761 rn
= route_next(rn
)) {
6762 if ((params
= rn
->info
)) {
6764 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6765 || (params
->auth_type
6766 == OSPF_AUTH_CRYPTOGRAPHIC
)
6767 || (params
->auth_type
6768 == OSPF_AUTH_SIMPLE
)) {
6769 params
->auth_type
= OSPF_AUTH_NOTSET
;
6770 UNSET_IF_PARAM(params
, auth_type
);
6771 if (params
!= IF_DEF_PARAMS(ifp
)) {
6772 ospf_free_if_params(
6773 ifp
, rn
->p
.u
.prefix4
);
6774 ospf_if_update_params(
6775 ifp
, rn
->p
.u
.prefix4
);
6786 DEFUN (ip_ospf_authentication_key
,
6787 ip_ospf_authentication_key_addr_cmd
,
6788 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6790 "OSPF interface commands\n"
6791 "Authentication password (key)\n"
6792 "The OSPF password (key)\n"
6793 "Address of interface\n")
6795 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6797 struct in_addr addr
;
6798 struct ospf_if_params
*params
;
6800 params
= IF_DEF_PARAMS(ifp
);
6802 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6803 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6805 "Please specify interface address by A.B.C.D\n");
6806 return CMD_WARNING_CONFIG_FAILED
;
6809 params
= ospf_get_if_params(ifp
, addr
);
6810 ospf_if_update_params(ifp
, addr
);
6813 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6814 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6815 OSPF_AUTH_SIMPLE_SIZE
);
6816 SET_IF_PARAM(params
, auth_simple
);
6821 DEFUN_HIDDEN (ospf_authentication_key
,
6822 ospf_authentication_key_cmd
,
6823 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6824 "OSPF interface commands\n"
6825 VLINK_HELPSTR_AUTH_SIMPLE
6826 "Address of interface\n")
6828 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6831 DEFUN (no_ip_ospf_authentication_key
,
6832 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6833 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6836 "OSPF interface commands\n"
6837 VLINK_HELPSTR_AUTH_SIMPLE
6838 "Address of interface\n")
6840 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6842 struct in_addr addr
;
6843 struct ospf_if_params
*params
;
6844 params
= IF_DEF_PARAMS(ifp
);
6846 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6847 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6849 "Please specify interface address by A.B.C.D\n");
6850 return CMD_WARNING_CONFIG_FAILED
;
6853 params
= ospf_lookup_if_params(ifp
, addr
);
6858 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6859 UNSET_IF_PARAM(params
, auth_simple
);
6861 if (params
!= IF_DEF_PARAMS(ifp
)) {
6862 ospf_free_if_params(ifp
, addr
);
6863 ospf_if_update_params(ifp
, addr
);
6869 DEFUN_HIDDEN (no_ospf_authentication_key
,
6870 no_ospf_authentication_key_authkey_addr_cmd
,
6871 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6873 "OSPF interface commands\n"
6874 VLINK_HELPSTR_AUTH_SIMPLE
6875 "Address of interface\n")
6877 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6880 DEFUN (ip_ospf_message_digest_key
,
6881 ip_ospf_message_digest_key_cmd
,
6882 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6884 "OSPF interface commands\n"
6885 "Message digest authentication password (key)\n"
6887 "Use MD5 algorithm\n"
6888 "The OSPF password (key)\n"
6889 "Address of interface\n")
6891 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6892 struct crypt_key
*ck
;
6894 struct in_addr addr
;
6895 struct ospf_if_params
*params
;
6897 params
= IF_DEF_PARAMS(ifp
);
6900 argv_find(argv
, argc
, "(1-255)", &idx
);
6901 char *keyid
= argv
[idx
]->arg
;
6902 argv_find(argv
, argc
, "KEY", &idx
);
6903 char *cryptkey
= argv
[idx
]->arg
;
6905 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6906 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6908 "Please specify interface address by A.B.C.D\n");
6909 return CMD_WARNING_CONFIG_FAILED
;
6912 params
= ospf_get_if_params(ifp
, addr
);
6913 ospf_if_update_params(ifp
, addr
);
6916 key_id
= strtol(keyid
, NULL
, 10);
6917 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
6918 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
6922 ck
= ospf_crypt_key_new();
6923 ck
->key_id
= (uint8_t)key_id
;
6924 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
6925 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
6927 ospf_crypt_key_add(params
->auth_crypt
, ck
);
6928 SET_IF_PARAM(params
, auth_crypt
);
6933 DEFUN_HIDDEN (ospf_message_digest_key
,
6934 ospf_message_digest_key_cmd
,
6935 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6936 "OSPF interface commands\n"
6937 "Message digest authentication password (key)\n"
6939 "Use MD5 algorithm\n"
6940 "The OSPF password (key)\n"
6941 "Address of interface\n")
6943 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
6946 DEFUN (no_ip_ospf_message_digest_key
,
6947 no_ip_ospf_message_digest_key_cmd
,
6948 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6951 "OSPF interface commands\n"
6952 "Message digest authentication password (key)\n"
6954 "Use MD5 algorithm\n"
6955 "The OSPF password (key)\n"
6956 "Address of interface\n")
6958 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6960 struct crypt_key
*ck
;
6962 struct in_addr addr
;
6963 struct ospf_if_params
*params
;
6964 params
= IF_DEF_PARAMS(ifp
);
6966 argv_find(argv
, argc
, "(1-255)", &idx
);
6967 char *keyid
= argv
[idx
]->arg
;
6969 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6970 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6972 "Please specify interface address by A.B.C.D\n");
6973 return CMD_WARNING_CONFIG_FAILED
;
6976 params
= ospf_lookup_if_params(ifp
, addr
);
6981 key_id
= strtol(keyid
, NULL
, 10);
6982 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
6984 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
6985 return CMD_WARNING_CONFIG_FAILED
;
6988 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
6990 if (params
!= IF_DEF_PARAMS(ifp
)) {
6991 ospf_free_if_params(ifp
, addr
);
6992 ospf_if_update_params(ifp
, addr
);
6998 DEFUN_HIDDEN (no_ospf_message_digest_key
,
6999 no_ospf_message_digest_key_cmd
,
7000 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7002 "OSPF interface commands\n"
7003 "Message digest authentication password (key)\n"
7005 "Use MD5 algorithm\n"
7006 "The OSPF password (key)\n"
7007 "Address of interface\n")
7009 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7012 DEFUN (ip_ospf_cost
,
7014 "ip ospf cost (1-65535) [A.B.C.D]",
7016 "OSPF interface commands\n"
7019 "Address of interface\n")
7021 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7023 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7024 struct in_addr addr
;
7025 struct ospf_if_params
*params
;
7026 params
= IF_DEF_PARAMS(ifp
);
7029 char *coststr
= NULL
, *ifaddr
= NULL
;
7031 argv_find(argv
, argc
, "(1-65535)", &idx
);
7032 coststr
= argv
[idx
]->arg
;
7033 cost
= strtol(coststr
, NULL
, 10);
7035 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7037 if (!inet_aton(ifaddr
, &addr
)) {
7039 "Please specify interface address by A.B.C.D\n");
7040 return CMD_WARNING_CONFIG_FAILED
;
7043 params
= ospf_get_if_params(ifp
, addr
);
7044 ospf_if_update_params(ifp
, addr
);
7047 SET_IF_PARAM(params
, output_cost_cmd
);
7048 params
->output_cost_cmd
= cost
;
7050 ospf_if_recalculate_output_cost(ifp
);
7055 DEFUN_HIDDEN (ospf_cost
,
7057 "ospf cost (1-65535) [A.B.C.D]",
7058 "OSPF interface commands\n"
7061 "Address of interface\n")
7063 return ip_ospf_cost(self
, vty
, argc
, argv
);
7066 DEFUN (no_ip_ospf_cost
,
7067 no_ip_ospf_cost_cmd
,
7068 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7071 "OSPF interface commands\n"
7074 "Address of interface\n")
7076 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7078 struct in_addr addr
;
7079 struct ospf_if_params
*params
;
7081 params
= IF_DEF_PARAMS(ifp
);
7084 char *ifaddr
= NULL
;
7085 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7087 /* According to the semantics we are mimicking "no ip ospf cost N" is
7088 * always treated as "no ip ospf cost" regardless of the actual value
7089 * of N already configured for the interface. Thus ignore cost. */
7092 if (!inet_aton(ifaddr
, &addr
)) {
7094 "Please specify interface address by A.B.C.D\n");
7095 return CMD_WARNING_CONFIG_FAILED
;
7098 params
= ospf_lookup_if_params(ifp
, addr
);
7103 UNSET_IF_PARAM(params
, output_cost_cmd
);
7105 if (params
!= IF_DEF_PARAMS(ifp
)) {
7106 ospf_free_if_params(ifp
, addr
);
7107 ospf_if_update_params(ifp
, addr
);
7110 ospf_if_recalculate_output_cost(ifp
);
7115 DEFUN_HIDDEN (no_ospf_cost
,
7117 "no ospf cost [(1-65535)] [A.B.C.D]",
7119 "OSPF interface commands\n"
7122 "Address of interface\n")
7124 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7127 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7129 struct route_node
*rn
;
7130 struct ospf_neighbor
*nbr
;
7132 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7133 if ((nbr
= rn
->info
)) {
7134 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7135 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7136 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7137 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7141 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7142 const char *nbr_str
,
7143 const char *fast_hello_str
)
7145 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7148 struct in_addr addr
;
7150 struct ospf_if_params
*params
;
7151 struct ospf_interface
*oi
;
7152 struct route_node
*rn
;
7154 params
= IF_DEF_PARAMS(ifp
);
7157 ret
= inet_aton(nbr_str
, &addr
);
7160 "Please specify interface address by A.B.C.D\n");
7161 return CMD_WARNING_CONFIG_FAILED
;
7164 params
= ospf_get_if_params(ifp
, addr
);
7165 ospf_if_update_params(ifp
, addr
);
7169 seconds
= strtoul(interval_str
, NULL
, 10);
7171 /* reset fast_hello too, just to be sure */
7172 UNSET_IF_PARAM(params
, fast_hello
);
7173 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7174 } else if (fast_hello_str
) {
7175 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7176 /* 1s dead-interval with sub-second hellos desired */
7177 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7178 SET_IF_PARAM(params
, fast_hello
);
7179 params
->fast_hello
= hellomult
;
7182 "Please specify dead-interval or hello-multiplier\n");
7183 return CMD_WARNING_CONFIG_FAILED
;
7186 SET_IF_PARAM(params
, v_wait
);
7187 params
->v_wait
= seconds
;
7189 /* Update timer values in neighbor structure. */
7191 struct ospf
*ospf
= NULL
;
7193 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7195 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7197 ospf_nbr_timer_update(oi
);
7200 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7201 if ((oi
= rn
->info
))
7202 ospf_nbr_timer_update(oi
);
7208 DEFUN (ip_ospf_dead_interval
,
7209 ip_ospf_dead_interval_cmd
,
7210 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7212 "OSPF interface commands\n"
7213 "Interval time after which a neighbor is declared down\n"
7215 "Address of interface\n")
7218 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7222 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7223 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7227 DEFUN_HIDDEN (ospf_dead_interval
,
7228 ospf_dead_interval_cmd
,
7229 "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")
7235 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7238 DEFUN (ip_ospf_dead_interval_minimal
,
7239 ip_ospf_dead_interval_minimal_addr_cmd
,
7240 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7242 "OSPF interface commands\n"
7243 "Interval time after which a neighbor is declared down\n"
7244 "Minimal 1s dead-interval with fast sub-second hellos\n"
7245 "Hello multiplier factor\n"
7246 "Number of Hellos to send each second\n"
7247 "Address of interface\n")
7252 return ospf_vty_dead_interval_set(
7253 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7255 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7256 argv
[idx_number
]->arg
);
7259 DEFUN (no_ip_ospf_dead_interval
,
7260 no_ip_ospf_dead_interval_cmd
,
7261 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7264 "OSPF interface commands\n"
7265 "Interval time after which a neighbor is declared down\n"
7267 "Minimal 1s dead-interval with fast sub-second hellos\n"
7268 "Hello multiplier factor\n"
7269 "Number of Hellos to send each second\n"
7270 "Address of interface\n")
7272 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7273 int idx_ipv4
= argc
- 1;
7274 struct in_addr addr
= {.s_addr
= 0L};
7276 struct ospf_if_params
*params
;
7277 struct ospf_interface
*oi
;
7278 struct route_node
*rn
;
7280 params
= IF_DEF_PARAMS(ifp
);
7282 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7283 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7286 "Please specify interface address by A.B.C.D\n");
7287 return CMD_WARNING_CONFIG_FAILED
;
7290 params
= ospf_lookup_if_params(ifp
, addr
);
7295 UNSET_IF_PARAM(params
, v_wait
);
7296 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7298 UNSET_IF_PARAM(params
, fast_hello
);
7299 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7301 if (params
!= IF_DEF_PARAMS(ifp
)) {
7302 ospf_free_if_params(ifp
, addr
);
7303 ospf_if_update_params(ifp
, addr
);
7306 /* Update timer values in neighbor structure. */
7308 struct ospf
*ospf
= NULL
;
7310 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7312 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7314 ospf_nbr_timer_update(oi
);
7317 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7318 if ((oi
= rn
->info
))
7319 ospf_nbr_timer_update(oi
);
7325 DEFUN_HIDDEN (no_ospf_dead_interval
,
7326 no_ospf_dead_interval_cmd
,
7327 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7329 "OSPF interface commands\n"
7330 "Interval time after which a neighbor is declared down\n"
7332 "Minimal 1s dead-interval with fast sub-second hellos\n"
7333 "Hello multiplier factor\n"
7334 "Number of Hellos to send each second\n"
7335 "Address of interface\n")
7337 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7340 DEFUN (ip_ospf_hello_interval
,
7341 ip_ospf_hello_interval_cmd
,
7342 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7344 "OSPF interface commands\n"
7345 "Time between HELLO packets\n"
7347 "Address of interface\n")
7349 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7351 struct in_addr addr
;
7352 struct ospf_if_params
*params
;
7353 params
= IF_DEF_PARAMS(ifp
);
7354 uint32_t seconds
= 0;
7356 argv_find(argv
, argc
, "(1-65535)", &idx
);
7357 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7359 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7360 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7362 "Please specify interface address by A.B.C.D\n");
7363 return CMD_WARNING_CONFIG_FAILED
;
7366 params
= ospf_get_if_params(ifp
, addr
);
7367 ospf_if_update_params(ifp
, addr
);
7370 SET_IF_PARAM(params
, v_hello
);
7371 params
->v_hello
= seconds
;
7376 DEFUN_HIDDEN (ospf_hello_interval
,
7377 ospf_hello_interval_cmd
,
7378 "ospf hello-interval (1-65535) [A.B.C.D]",
7379 "OSPF interface commands\n"
7380 "Time between HELLO packets\n"
7382 "Address of interface\n")
7384 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7387 DEFUN (no_ip_ospf_hello_interval
,
7388 no_ip_ospf_hello_interval_cmd
,
7389 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7392 "OSPF interface commands\n"
7393 "Time between HELLO packets\n" // ignored
7395 "Address of interface\n")
7397 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7399 struct in_addr addr
;
7400 struct ospf_if_params
*params
;
7402 params
= IF_DEF_PARAMS(ifp
);
7404 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7405 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7407 "Please specify interface address by A.B.C.D\n");
7408 return CMD_WARNING_CONFIG_FAILED
;
7411 params
= ospf_lookup_if_params(ifp
, addr
);
7416 UNSET_IF_PARAM(params
, v_hello
);
7417 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7419 if (params
!= IF_DEF_PARAMS(ifp
)) {
7420 ospf_free_if_params(ifp
, addr
);
7421 ospf_if_update_params(ifp
, addr
);
7427 DEFUN_HIDDEN (no_ospf_hello_interval
,
7428 no_ospf_hello_interval_cmd
,
7429 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7431 "OSPF interface commands\n"
7432 "Time between HELLO packets\n" // ignored
7434 "Address of interface\n")
7436 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7439 DEFUN (ip_ospf_network
,
7440 ip_ospf_network_cmd
,
7441 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7443 "OSPF interface commands\n"
7445 "Specify OSPF broadcast multi-access network\n"
7446 "Specify OSPF NBMA network\n"
7447 "Specify OSPF point-to-multipoint network\n"
7448 "Specify OSPF point-to-point network\n")
7450 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7452 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7453 struct route_node
*rn
;
7455 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7457 "This is a loopback interface. Can't set network type.\n");
7458 return CMD_WARNING_CONFIG_FAILED
;
7461 if (argv_find(argv
, argc
, "broadcast", &idx
))
7462 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7463 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7464 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7465 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7466 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7467 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7468 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7470 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7473 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7475 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7476 struct ospf_interface
*oi
= rn
->info
;
7481 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7483 if (oi
->state
> ISM_Down
) {
7484 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7485 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7492 DEFUN_HIDDEN (ospf_network
,
7494 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7495 "OSPF interface commands\n"
7497 "Specify OSPF broadcast multi-access network\n"
7498 "Specify OSPF NBMA network\n"
7499 "Specify OSPF point-to-multipoint network\n"
7500 "Specify OSPF point-to-point network\n")
7502 return ip_ospf_network(self
, vty
, argc
, argv
);
7505 DEFUN (no_ip_ospf_network
,
7506 no_ip_ospf_network_cmd
,
7507 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7510 "OSPF interface commands\n"
7512 "Specify OSPF broadcast multi-access network\n"
7513 "Specify OSPF NBMA network\n"
7514 "Specify OSPF point-to-multipoint network\n"
7515 "Specify OSPF point-to-point network\n")
7517 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7518 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7519 struct route_node
*rn
;
7521 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7523 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7526 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7527 struct ospf_interface
*oi
= rn
->info
;
7532 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7534 if (oi
->state
> ISM_Down
) {
7535 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7536 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7543 DEFUN_HIDDEN (no_ospf_network
,
7544 no_ospf_network_cmd
,
7545 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7547 "OSPF interface commands\n"
7549 "Specify OSPF broadcast multi-access network\n"
7550 "Specify OSPF NBMA network\n"
7551 "Specify OSPF point-to-multipoint network\n"
7552 "Specify OSPF point-to-point network\n")
7554 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7557 DEFUN (ip_ospf_priority
,
7558 ip_ospf_priority_cmd
,
7559 "ip ospf priority (0-255) [A.B.C.D]",
7561 "OSPF interface commands\n"
7564 "Address of interface\n")
7566 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7569 struct route_node
*rn
;
7570 struct in_addr addr
;
7571 struct ospf_if_params
*params
;
7572 params
= IF_DEF_PARAMS(ifp
);
7574 argv_find(argv
, argc
, "(0-255)", &idx
);
7575 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7577 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7578 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7580 "Please specify interface address by A.B.C.D\n");
7581 return CMD_WARNING_CONFIG_FAILED
;
7584 params
= ospf_get_if_params(ifp
, addr
);
7585 ospf_if_update_params(ifp
, addr
);
7588 SET_IF_PARAM(params
, priority
);
7589 params
->priority
= priority
;
7591 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7592 struct ospf_interface
*oi
= rn
->info
;
7597 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7598 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7599 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7606 DEFUN_HIDDEN (ospf_priority
,
7608 "ospf priority (0-255) [A.B.C.D]",
7609 "OSPF interface commands\n"
7612 "Address of interface\n")
7614 return ip_ospf_priority(self
, vty
, argc
, argv
);
7617 DEFUN (no_ip_ospf_priority
,
7618 no_ip_ospf_priority_cmd
,
7619 "no ip ospf priority [(0-255) [A.B.C.D]]",
7622 "OSPF interface commands\n"
7623 "Router priority\n" // ignored
7625 "Address of interface\n")
7627 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7629 struct route_node
*rn
;
7630 struct in_addr addr
;
7631 struct ospf_if_params
*params
;
7633 params
= IF_DEF_PARAMS(ifp
);
7635 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7636 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7638 "Please specify interface address by A.B.C.D\n");
7639 return CMD_WARNING_CONFIG_FAILED
;
7642 params
= ospf_lookup_if_params(ifp
, addr
);
7647 UNSET_IF_PARAM(params
, priority
);
7648 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7650 if (params
!= IF_DEF_PARAMS(ifp
)) {
7651 ospf_free_if_params(ifp
, addr
);
7652 ospf_if_update_params(ifp
, addr
);
7655 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7656 struct ospf_interface
*oi
= rn
->info
;
7661 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7662 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7663 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7670 DEFUN_HIDDEN (no_ospf_priority
,
7671 no_ospf_priority_cmd
,
7672 "no ospf priority [(0-255) [A.B.C.D]]",
7674 "OSPF interface commands\n"
7677 "Address of interface\n")
7679 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7682 DEFUN (ip_ospf_retransmit_interval
,
7683 ip_ospf_retransmit_interval_addr_cmd
,
7684 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7686 "OSPF interface commands\n"
7687 "Time between retransmitting lost link state advertisements\n"
7689 "Address of interface\n")
7691 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7694 struct in_addr addr
;
7695 struct ospf_if_params
*params
;
7696 params
= IF_DEF_PARAMS(ifp
);
7698 argv_find(argv
, argc
, "(3-65535)", &idx
);
7699 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7701 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7702 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7704 "Please specify interface address by A.B.C.D\n");
7705 return CMD_WARNING_CONFIG_FAILED
;
7708 params
= ospf_get_if_params(ifp
, addr
);
7709 ospf_if_update_params(ifp
, addr
);
7712 SET_IF_PARAM(params
, retransmit_interval
);
7713 params
->retransmit_interval
= seconds
;
7718 DEFUN_HIDDEN (ospf_retransmit_interval
,
7719 ospf_retransmit_interval_cmd
,
7720 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7721 "OSPF interface commands\n"
7722 "Time between retransmitting lost link state advertisements\n"
7724 "Address of interface\n")
7726 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7729 DEFUN (no_ip_ospf_retransmit_interval
,
7730 no_ip_ospf_retransmit_interval_addr_cmd
,
7731 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7734 "OSPF interface commands\n"
7735 "Time between retransmitting lost link state advertisements\n"
7737 "Address of interface\n")
7739 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7741 struct in_addr addr
;
7742 struct ospf_if_params
*params
;
7744 params
= IF_DEF_PARAMS(ifp
);
7746 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7747 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7749 "Please specify interface address by A.B.C.D\n");
7750 return CMD_WARNING_CONFIG_FAILED
;
7753 params
= ospf_lookup_if_params(ifp
, addr
);
7758 UNSET_IF_PARAM(params
, retransmit_interval
);
7759 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7761 if (params
!= IF_DEF_PARAMS(ifp
)) {
7762 ospf_free_if_params(ifp
, addr
);
7763 ospf_if_update_params(ifp
, addr
);
7769 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7770 no_ospf_retransmit_interval_cmd
,
7771 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7773 "OSPF interface commands\n"
7774 "Time between retransmitting lost link state advertisements\n"
7776 "Address of interface\n")
7778 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7781 DEFUN (ip_ospf_transmit_delay
,
7782 ip_ospf_transmit_delay_addr_cmd
,
7783 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7785 "OSPF interface commands\n"
7786 "Link state transmit delay\n"
7788 "Address of interface\n")
7790 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7793 struct in_addr addr
;
7794 struct ospf_if_params
*params
;
7796 params
= IF_DEF_PARAMS(ifp
);
7797 argv_find(argv
, argc
, "(1-65535)", &idx
);
7798 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7800 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7801 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7803 "Please specify interface address by A.B.C.D\n");
7804 return CMD_WARNING_CONFIG_FAILED
;
7807 params
= ospf_get_if_params(ifp
, addr
);
7808 ospf_if_update_params(ifp
, addr
);
7811 SET_IF_PARAM(params
, transmit_delay
);
7812 params
->transmit_delay
= seconds
;
7817 DEFUN_HIDDEN (ospf_transmit_delay
,
7818 ospf_transmit_delay_cmd
,
7819 "ospf transmit-delay (1-65535) [A.B.C.D]",
7820 "OSPF interface commands\n"
7821 "Link state transmit delay\n"
7823 "Address of interface\n")
7825 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7828 DEFUN (no_ip_ospf_transmit_delay
,
7829 no_ip_ospf_transmit_delay_addr_cmd
,
7830 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7833 "OSPF interface commands\n"
7834 "Link state transmit delay\n"
7836 "Address of interface\n")
7838 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7840 struct in_addr addr
;
7841 struct ospf_if_params
*params
;
7843 params
= IF_DEF_PARAMS(ifp
);
7845 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7846 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7848 "Please specify interface address by A.B.C.D\n");
7849 return CMD_WARNING_CONFIG_FAILED
;
7852 params
= ospf_lookup_if_params(ifp
, addr
);
7857 UNSET_IF_PARAM(params
, transmit_delay
);
7858 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7860 if (params
!= IF_DEF_PARAMS(ifp
)) {
7861 ospf_free_if_params(ifp
, addr
);
7862 ospf_if_update_params(ifp
, addr
);
7869 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7870 no_ospf_transmit_delay_cmd
,
7871 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7873 "OSPF interface commands\n"
7874 "Link state transmit delay\n"
7876 "Address of interface\n")
7878 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7881 DEFUN (ip_ospf_area
,
7883 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7885 "OSPF interface commands\n"
7887 "Enable OSPF on this interface\n"
7888 "OSPF area ID in IP address format\n"
7889 "OSPF area ID as a decimal value\n"
7890 "Address of interface\n")
7892 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7895 struct in_addr area_id
;
7896 struct in_addr addr
;
7897 struct ospf_if_params
*params
= NULL
;
7898 struct route_node
*rn
;
7899 struct ospf
*ospf
= NULL
;
7900 unsigned short instance
= 0;
7903 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7904 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7906 argv_find(argv
, argc
, "area", &idx
);
7907 areaid
= argv
[idx
+ 1]->arg
;
7909 if (ifp
->vrf_id
&& !instance
)
7910 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7912 ospf
= ospf_lookup_instance(instance
);
7914 if (instance
&& ospf
== NULL
) {
7915 params
= IF_DEF_PARAMS(ifp
);
7916 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7917 UNSET_IF_PARAM(params
, if_area
);
7918 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7919 ospf_interface_area_unset(ospf
, ifp
);
7920 ospf
->if_ospf_cli_count
--;
7922 return CMD_NOT_MY_INSTANCE
;
7925 ret
= str2area_id(areaid
, &area_id
, &format
);
7927 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
7928 return CMD_WARNING_CONFIG_FAILED
;
7930 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
7931 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
7932 return CMD_WARNING_CONFIG_FAILED
;
7935 params
= IF_DEF_PARAMS(ifp
);
7936 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
7937 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
7939 "Must remove previous area config before changing ospf area \n");
7940 return CMD_WARNING_CONFIG_FAILED
;
7943 // Check if we have an address arg and proccess it
7944 if (argc
== idx
+ 3) {
7945 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
7947 "Please specify Intf Address by A.B.C.D\n");
7948 return CMD_WARNING_CONFIG_FAILED
;
7950 // update/create address-level params
7951 params
= ospf_get_if_params((ifp
), (addr
));
7952 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7954 "Must remove previous area/address config before changing ospf area");
7955 return CMD_WARNING_CONFIG_FAILED
;
7957 ospf_if_update_params((ifp
), (addr
));
7961 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
7962 if (rn
->info
!= NULL
) {
7964 "Please remove all network commands first.\n");
7965 return CMD_WARNING_CONFIG_FAILED
;
7970 /* enable ospf on this interface with area_id */
7972 SET_IF_PARAM(params
, if_area
);
7973 params
->if_area
= area_id
;
7974 params
->if_area_id_fmt
= format
;
7978 ospf_interface_area_set(ospf
, ifp
);
7979 ospf
->if_ospf_cli_count
++;
7985 DEFUN (no_ip_ospf_area
,
7986 no_ip_ospf_area_cmd
,
7987 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
7990 "OSPF interface commands\n"
7992 "Disable OSPF on this interface\n"
7993 "OSPF area ID in IP address format\n"
7994 "OSPF area ID as a decimal value\n"
7995 "Address of interface\n")
7997 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8000 struct ospf_if_params
*params
;
8001 unsigned short instance
= 0;
8002 struct in_addr addr
;
8004 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8005 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8007 if (ifp
->vrf_id
&& !instance
)
8008 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8010 ospf
= ospf_lookup_instance(instance
);
8013 return CMD_NOT_MY_INSTANCE
;
8015 argv_find(argv
, argc
, "area", &idx
);
8017 // Check if we have an address arg and proccess it
8018 if (argc
== idx
+ 3) {
8019 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8021 "Please specify Intf Address by A.B.C.D\n");
8022 return CMD_WARNING_CONFIG_FAILED
;
8024 params
= ospf_lookup_if_params(ifp
, addr
);
8025 if ((params
) == NULL
)
8028 params
= IF_DEF_PARAMS(ifp
);
8030 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8032 "Can't find specified interface area configuration.\n");
8033 return CMD_WARNING_CONFIG_FAILED
;
8036 UNSET_IF_PARAM(params
, if_area
);
8037 if (params
!= IF_DEF_PARAMS((ifp
))) {
8038 ospf_free_if_params((ifp
), (addr
));
8039 ospf_if_update_params((ifp
), (addr
));
8042 ospf_interface_area_unset(ospf
, ifp
);
8043 ospf
->if_ospf_cli_count
--;
8047 DEFUN (ospf_redistribute_source
,
8048 ospf_redistribute_source_cmd
,
8049 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8051 FRR_REDIST_HELP_STR_OSPFD
8052 "Metric for redistributed routes\n"
8053 "OSPF default metric\n"
8054 "OSPF exterior metric type for redistributed routes\n"
8055 "Set OSPF External Type 1/2 metrics\n"
8056 "Route map reference\n"
8057 "Pointer to route-map entries\n")
8059 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8060 int idx_protocol
= 1;
8064 struct ospf_redist
*red
;
8067 /* Get distribute source. */
8068 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8070 return CMD_WARNING_CONFIG_FAILED
;
8072 red
= ospf_redist_add(ospf
, source
, 0);
8074 /* Get metric value. */
8075 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8076 if (!str2metric(argv
[idx
]->arg
, &metric
))
8077 return CMD_WARNING_CONFIG_FAILED
;
8080 /* Get metric type. */
8081 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8082 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8083 return CMD_WARNING_CONFIG_FAILED
;
8087 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8088 ospf_routemap_set(red
, argv
[idx
]->arg
);
8090 ospf_routemap_unset(red
);
8092 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8095 DEFUN (no_ospf_redistribute_source
,
8096 no_ospf_redistribute_source_cmd
,
8097 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8100 FRR_REDIST_HELP_STR_OSPFD
8101 "Metric for redistributed routes\n"
8102 "OSPF default metric\n"
8103 "OSPF exterior metric type for redistributed routes\n"
8104 "Set OSPF External Type 1/2 metrics\n"
8105 "Route map reference\n"
8106 "Pointer to route-map entries\n")
8108 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8109 int idx_protocol
= 2;
8111 struct ospf_redist
*red
;
8113 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8115 return CMD_WARNING_CONFIG_FAILED
;
8117 red
= ospf_redist_lookup(ospf
, source
, 0);
8121 ospf_routemap_unset(red
);
8122 return ospf_redistribute_unset(ospf
, source
, 0);
8125 DEFUN (ospf_redistribute_instance_source
,
8126 ospf_redistribute_instance_source_cmd
,
8127 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8129 "Open Shortest Path First\n"
8130 "Non-main Kernel Routing Table\n"
8131 "Instance ID/Table ID\n"
8132 "Metric for redistributed routes\n"
8133 "OSPF default metric\n"
8134 "OSPF exterior metric type for redistributed routes\n"
8135 "Set OSPF External Type 1/2 metrics\n"
8136 "Route map reference\n"
8137 "Pointer to route-map entries\n")
8139 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8140 int idx_ospf_table
= 1;
8146 unsigned short instance
;
8147 struct ospf_redist
*red
;
8149 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8152 vty_out(vty
, "Unknown instance redistribution\n");
8153 return CMD_WARNING_CONFIG_FAILED
;
8156 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8158 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8160 "Instance redistribution in non-instanced OSPF not allowed\n");
8161 return CMD_WARNING_CONFIG_FAILED
;
8164 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8165 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8166 return CMD_WARNING_CONFIG_FAILED
;
8169 /* Get metric value. */
8170 if (argv_find(argv
, argc
, "metric", &idx
))
8171 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8172 return CMD_WARNING_CONFIG_FAILED
;
8175 /* Get metric type. */
8176 if (argv_find(argv
, argc
, "metric-type", &idx
))
8177 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8178 return CMD_WARNING_CONFIG_FAILED
;
8180 red
= ospf_redist_add(ospf
, source
, instance
);
8183 if (argv_find(argv
, argc
, "route-map", &idx
))
8184 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8186 ospf_routemap_unset(red
);
8188 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8191 DEFUN (no_ospf_redistribute_instance_source
,
8192 no_ospf_redistribute_instance_source_cmd
,
8193 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8196 "Open Shortest Path First\n"
8197 "Non-main Kernel Routing Table\n"
8198 "Instance ID/Table Id\n"
8199 "Metric for redistributed routes\n"
8200 "OSPF default metric\n"
8201 "OSPF exterior metric type for redistributed routes\n"
8202 "Set OSPF External Type 1/2 metrics\n"
8203 "Route map reference\n"
8204 "Pointer to route-map entries\n")
8206 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8207 int idx_ospf_table
= 2;
8209 unsigned int instance
;
8210 struct ospf_redist
*red
;
8213 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8214 source
= ZEBRA_ROUTE_OSPF
;
8216 source
= ZEBRA_ROUTE_TABLE
;
8218 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8220 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8222 "Instance redistribution in non-instanced OSPF not allowed\n");
8223 return CMD_WARNING_CONFIG_FAILED
;
8226 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8227 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8228 return CMD_WARNING_CONFIG_FAILED
;
8231 red
= ospf_redist_lookup(ospf
, source
, instance
);
8235 ospf_routemap_unset(red
);
8236 return ospf_redistribute_unset(ospf
, source
, instance
);
8239 DEFUN (ospf_distribute_list_out
,
8240 ospf_distribute_list_out_cmd
,
8241 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8242 "Filter networks in routing updates\n"
8243 "Access-list name\n"
8245 FRR_REDIST_HELP_STR_OSPFD
)
8247 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8251 char *proto
= argv
[argc
- 1]->text
;
8253 /* Get distribute source. */
8254 source
= proto_redistnum(AFI_IP
, proto
);
8256 return CMD_WARNING_CONFIG_FAILED
;
8258 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8261 DEFUN (no_ospf_distribute_list_out
,
8262 no_ospf_distribute_list_out_cmd
,
8263 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8265 "Filter networks in routing updates\n"
8266 "Access-list name\n"
8268 FRR_REDIST_HELP_STR_OSPFD
)
8270 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8274 char *proto
= argv
[argc
- 1]->text
;
8275 source
= proto_redistnum(AFI_IP
, proto
);
8277 return CMD_WARNING_CONFIG_FAILED
;
8279 return ospf_distribute_list_out_unset(ospf
, source
,
8280 argv
[idx_word
]->arg
);
8283 /* Default information originate. */
8284 DEFUN (ospf_default_information_originate
,
8285 ospf_default_information_originate_cmd
,
8286 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8287 "Control distribution of default information\n"
8288 "Distribute a default route\n"
8289 "Always advertise default route\n"
8290 "OSPF default metric\n"
8292 "OSPF metric type for default routes\n"
8293 "Set OSPF External Type 1/2 metrics\n"
8294 "Route map reference\n"
8295 "Pointer to route-map entries\n")
8297 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8298 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8301 struct ospf_redist
*red
;
8304 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8306 /* Check whether "always" was specified */
8307 if (argv_find(argv
, argc
, "always", &idx
))
8308 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8310 /* Get metric value */
8311 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8312 if (!str2metric(argv
[idx
]->arg
, &metric
))
8313 return CMD_WARNING_CONFIG_FAILED
;
8316 /* Get metric type. */
8317 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8318 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8319 return CMD_WARNING_CONFIG_FAILED
;
8323 if (argv_find(argv
, argc
, "WORD", &idx
))
8324 ospf_routemap_set(red
, argv
[idx
]->arg
);
8326 ospf_routemap_unset(red
);
8328 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8332 DEFUN (no_ospf_default_information_originate
,
8333 no_ospf_default_information_originate_cmd
,
8334 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8336 "Control distribution of default information\n"
8337 "Distribute a default route\n"
8338 "Always advertise default route\n"
8339 "OSPF default metric\n"
8341 "OSPF metric type for default routes\n"
8342 "Set OSPF External Type 1/2 metrics\n"
8343 "Route map reference\n"
8344 "Pointer to route-map entries\n")
8346 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8347 struct prefix_ipv4 p
;
8348 struct ospf_external
*ext
;
8349 struct ospf_redist
*red
;
8352 p
.prefix
.s_addr
= 0;
8355 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8357 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8358 if (ext
&& EXTERNAL_INFO(ext
)) {
8359 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8360 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8363 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8367 ospf_routemap_unset(red
);
8368 return ospf_redistribute_default_unset(ospf
);
8371 DEFUN (ospf_default_metric
,
8372 ospf_default_metric_cmd
,
8373 "default-metric (0-16777214)",
8374 "Set metric of redistributed routes\n"
8377 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8381 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8382 return CMD_WARNING_CONFIG_FAILED
;
8384 ospf
->default_metric
= metric
;
8389 DEFUN (no_ospf_default_metric
,
8390 no_ospf_default_metric_cmd
,
8391 "no default-metric [(0-16777214)]",
8393 "Set metric of redistributed routes\n"
8396 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8398 ospf
->default_metric
= -1;
8404 DEFUN (ospf_distance
,
8407 "Administrative distance\n"
8408 "OSPF Administrative distance\n")
8410 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8413 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8418 DEFUN (no_ospf_distance
,
8419 no_ospf_distance_cmd
,
8420 "no distance (1-255)",
8422 "Administrative distance\n"
8423 "OSPF Administrative distance\n")
8425 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8427 ospf
->distance_all
= 0;
8432 DEFUN (no_ospf_distance_ospf
,
8433 no_ospf_distance_ospf_cmd
,
8434 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8436 "Administrative distance\n"
8437 "OSPF administrative distance\n"
8438 "Intra-area routes\n"
8439 "Distance for intra-area routes\n"
8440 "Inter-area routes\n"
8441 "Distance for inter-area routes\n"
8443 "Distance for external routes\n")
8445 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8448 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8449 idx
= ospf
->distance_intra
= 0;
8450 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8451 idx
= ospf
->distance_inter
= 0;
8452 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8453 ospf
->distance_external
= 0;
8458 DEFUN (ospf_distance_ospf
,
8459 ospf_distance_ospf_cmd
,
8460 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8461 "Administrative distance\n"
8462 "OSPF administrative distance\n"
8463 "Intra-area routes\n"
8464 "Distance for intra-area routes\n"
8465 "Inter-area routes\n"
8466 "Distance for inter-area routes\n"
8468 "Distance for external routes\n")
8470 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8473 ospf
->distance_intra
= 0;
8474 ospf
->distance_inter
= 0;
8475 ospf
->distance_external
= 0;
8477 if (argv_find(argv
, argc
, "intra-area", &idx
))
8478 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8480 if (argv_find(argv
, argc
, "inter-area", &idx
))
8481 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8483 if (argv_find(argv
, argc
, "external", &idx
))
8484 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8490 DEFUN (ospf_distance_source
,
8491 ospf_distance_source_cmd
,
8492 "distance (1-255) A.B.C.D/M",
8493 "Administrative distance\n"
8495 "IP source prefix\n")
8497 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8499 int idx_ipv4_prefixlen
= 2;
8501 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8506 DEFUN (no_ospf_distance_source
,
8507 no_ospf_distance_source_cmd
,
8508 "no distance (1-255) A.B.C.D/M",
8510 "Administrative distance\n"
8512 "IP source prefix\n")
8514 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8516 int idx_ipv4_prefixlen
= 3;
8518 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8523 DEFUN (ospf_distance_source_access_list
,
8524 ospf_distance_source_access_list_cmd
,
8525 "distance (1-255) A.B.C.D/M WORD",
8526 "Administrative distance\n"
8528 "IP source prefix\n"
8529 "Access list name\n")
8531 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8533 int idx_ipv4_prefixlen
= 2;
8536 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8541 DEFUN (no_ospf_distance_source_access_list
,
8542 no_ospf_distance_source_access_list_cmd
,
8543 "no distance (1-255) A.B.C.D/M WORD",
8545 "Administrative distance\n"
8547 "IP source prefix\n"
8548 "Access list name\n")
8550 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8552 int idx_ipv4_prefixlen
= 3;
8555 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8561 DEFUN (ip_ospf_mtu_ignore
,
8562 ip_ospf_mtu_ignore_addr_cmd
,
8563 "ip ospf mtu-ignore [A.B.C.D]",
8565 "OSPF interface commands\n"
8566 "Disable MTU mismatch detection on this interface\n"
8567 "Address of interface\n")
8569 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8571 struct in_addr addr
;
8574 struct ospf_if_params
*params
;
8575 params
= IF_DEF_PARAMS(ifp
);
8578 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8581 "Please specify interface address by A.B.C.D\n");
8582 return CMD_WARNING_CONFIG_FAILED
;
8584 params
= ospf_get_if_params(ifp
, addr
);
8585 ospf_if_update_params(ifp
, addr
);
8587 params
->mtu_ignore
= 1;
8588 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8589 SET_IF_PARAM(params
, mtu_ignore
);
8591 UNSET_IF_PARAM(params
, mtu_ignore
);
8592 if (params
!= IF_DEF_PARAMS(ifp
)) {
8593 ospf_free_if_params(ifp
, addr
);
8594 ospf_if_update_params(ifp
, addr
);
8600 DEFUN (no_ip_ospf_mtu_ignore
,
8601 no_ip_ospf_mtu_ignore_addr_cmd
,
8602 "no ip ospf mtu-ignore [A.B.C.D]",
8605 "OSPF interface commands\n"
8606 "Disable MTU mismatch detection on this interface\n"
8607 "Address of interface\n")
8609 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8611 struct in_addr addr
;
8614 struct ospf_if_params
*params
;
8615 params
= IF_DEF_PARAMS(ifp
);
8618 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8621 "Please specify interface address by A.B.C.D\n");
8622 return CMD_WARNING_CONFIG_FAILED
;
8624 params
= ospf_get_if_params(ifp
, addr
);
8625 ospf_if_update_params(ifp
, addr
);
8627 params
->mtu_ignore
= 0;
8628 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8629 SET_IF_PARAM(params
, mtu_ignore
);
8631 UNSET_IF_PARAM(params
, mtu_ignore
);
8632 if (params
!= IF_DEF_PARAMS(ifp
)) {
8633 ospf_free_if_params(ifp
, addr
);
8634 ospf_if_update_params(ifp
, addr
);
8641 DEFUN (ospf_max_metric_router_lsa_admin
,
8642 ospf_max_metric_router_lsa_admin_cmd
,
8643 "max-metric router-lsa administrative",
8644 "OSPF maximum / infinite-distance metric\n"
8645 "Advertise own Router-LSA with infinite distance (stub router)\n"
8646 "Administratively applied, for an indefinite period\n")
8648 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8649 struct listnode
*ln
;
8650 struct ospf_area
*area
;
8652 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8653 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8655 if (!CHECK_FLAG(area
->stub_router_state
,
8656 OSPF_AREA_IS_STUB_ROUTED
))
8657 ospf_router_lsa_update_area(area
);
8660 /* Allows for areas configured later to get the property */
8661 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8666 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8667 no_ospf_max_metric_router_lsa_admin_cmd
,
8668 "no max-metric router-lsa administrative",
8670 "OSPF maximum / infinite-distance metric\n"
8671 "Advertise own Router-LSA with infinite distance (stub router)\n"
8672 "Administratively applied, for an indefinite period\n")
8674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8675 struct listnode
*ln
;
8676 struct ospf_area
*area
;
8678 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8679 UNSET_FLAG(area
->stub_router_state
,
8680 OSPF_AREA_ADMIN_STUB_ROUTED
);
8682 /* Don't trample on the start-up stub timer */
8683 if (CHECK_FLAG(area
->stub_router_state
,
8684 OSPF_AREA_IS_STUB_ROUTED
)
8685 && !area
->t_stub_router
) {
8686 UNSET_FLAG(area
->stub_router_state
,
8687 OSPF_AREA_IS_STUB_ROUTED
);
8688 ospf_router_lsa_update_area(area
);
8691 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8695 DEFUN (ospf_max_metric_router_lsa_startup
,
8696 ospf_max_metric_router_lsa_startup_cmd
,
8697 "max-metric router-lsa on-startup (5-86400)",
8698 "OSPF maximum / infinite-distance metric\n"
8699 "Advertise own Router-LSA with infinite distance (stub router)\n"
8700 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8701 "Time (seconds) to advertise self as stub-router\n")
8703 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8705 unsigned int seconds
;
8708 vty_out(vty
, "%% Must supply stub-router period");
8709 return CMD_WARNING_CONFIG_FAILED
;
8712 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8714 ospf
->stub_router_startup_time
= seconds
;
8719 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8720 no_ospf_max_metric_router_lsa_startup_cmd
,
8721 "no max-metric router-lsa on-startup [(5-86400)]",
8723 "OSPF maximum / infinite-distance metric\n"
8724 "Advertise own Router-LSA with infinite distance (stub router)\n"
8725 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8726 "Time (seconds) to advertise self as stub-router\n")
8728 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8729 struct listnode
*ln
;
8730 struct ospf_area
*area
;
8732 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8734 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8735 SET_FLAG(area
->stub_router_state
,
8736 OSPF_AREA_WAS_START_STUB_ROUTED
);
8737 OSPF_TIMER_OFF(area
->t_stub_router
);
8739 /* Don't trample on admin stub routed */
8740 if (!CHECK_FLAG(area
->stub_router_state
,
8741 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8742 UNSET_FLAG(area
->stub_router_state
,
8743 OSPF_AREA_IS_STUB_ROUTED
);
8744 ospf_router_lsa_update_area(area
);
8751 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8752 ospf_max_metric_router_lsa_shutdown_cmd
,
8753 "max-metric router-lsa on-shutdown (5-100)",
8754 "OSPF maximum / infinite-distance metric\n"
8755 "Advertise own Router-LSA with infinite distance (stub router)\n"
8756 "Advertise stub-router prior to full shutdown of OSPF\n"
8757 "Time (seconds) to wait till full shutdown\n")
8759 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8761 unsigned int seconds
;
8764 vty_out(vty
, "%% Must supply stub-router shutdown period");
8765 return CMD_WARNING_CONFIG_FAILED
;
8768 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8770 ospf
->stub_router_shutdown_time
= seconds
;
8775 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8776 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8777 "no max-metric router-lsa on-shutdown [(5-100)]",
8779 "OSPF maximum / infinite-distance metric\n"
8780 "Advertise own Router-LSA with infinite distance (stub router)\n"
8781 "Advertise stub-router prior to full shutdown of OSPF\n"
8782 "Time (seconds) to wait till full shutdown\n")
8784 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8786 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8791 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8793 struct listnode
*ln
;
8794 struct ospf_area
*area
;
8796 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8797 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8798 ospf
->stub_router_startup_time
);
8799 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8800 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8801 ospf
->stub_router_shutdown_time
);
8802 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8803 if (CHECK_FLAG(area
->stub_router_state
,
8804 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8805 vty_out(vty
, " max-metric router-lsa administrative\n");
8812 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8813 struct route_table
*rt
,
8816 struct route_node
*rn
;
8817 struct ospf_route
* or ;
8818 struct listnode
*pnode
, *pnnode
;
8819 struct ospf_path
*path
;
8820 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8821 *json_nexthop
= NULL
;
8825 "============ OSPF network routing table ============\n");
8827 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8828 if ((or = rn
->info
) == NULL
)
8830 char buf1
[PREFIX2STR_BUFFER
];
8832 memset(buf1
, 0, sizeof(buf1
));
8833 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8835 json_route
= json_object_new_object();
8837 json_object_object_add(json
, buf1
, json_route
);
8838 json_object_to_json_string_ext(
8839 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8842 switch (or->path_type
) {
8843 case OSPF_PATH_INTER_AREA
:
8844 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8846 json_object_string_add(json_route
,
8849 json_object_int_add(json_route
, "cost",
8851 json_object_string_add(
8853 inet_ntoa(or->u
.std
.area_id
));
8856 "N IA %-18s [%d] area: %s\n",
8858 inet_ntoa(or->u
.std
.area_id
));
8860 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8862 json_object_string_add(json_route
,
8867 "D IA %-18s Discard entry\n",
8872 case OSPF_PATH_INTRA_AREA
:
8874 json_object_string_add(json_route
, "routeType",
8876 json_object_int_add(json_route
, "cost",
8878 json_object_string_add(
8880 inet_ntoa(or->u
.std
.area_id
));
8882 vty_out(vty
, "N %-18s [%d] area: %s\n",
8884 inet_ntoa(or->u
.std
.area_id
));
8891 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8893 json_nexthop_array
= json_object_new_array();
8894 json_object_object_add(json_route
, "nexthops",
8895 json_nexthop_array
);
8898 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8901 json_nexthop
= json_object_new_object();
8902 json_object_array_add(
8906 if (if_lookup_by_index(path
->ifindex
,
8909 if (path
->nexthop
.s_addr
== 0) {
8911 json_object_string_add(
8914 json_object_string_add(
8916 "directly attached to",
8922 "%24s directly attached to %s\n",
8930 json_object_string_add(
8935 json_object_string_add(
8943 "%24s via %s, %s\n",
8956 json_object_free(json_route
);
8962 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
8963 struct route_table
*rtrs
,
8966 struct route_node
*rn
;
8967 struct ospf_route
* or ;
8968 struct listnode
*pnode
;
8969 struct listnode
*node
;
8970 struct ospf_path
*path
;
8971 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8972 *json_nexthop
= NULL
;
8976 "============ OSPF router routing table =============\n");
8978 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
8979 if (rn
->info
== NULL
)
8983 json_route
= json_object_new_object();
8985 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
8987 json_object_string_add(json_route
, "routeType", "R ");
8989 vty_out(vty
, "R %-15s ",
8990 inet_ntoa(rn
->p
.u
.prefix4
));
8993 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
8996 vty_out(vty
, "%24s", "");
9001 json_object_int_add(json_route
, "cost",
9003 json_object_string_add(
9005 inet_ntoa(or->u
.std
.area_id
));
9006 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9007 json_object_boolean_true_add(json_route
,
9009 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9010 json_object_string_add(json_route
,
9013 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9014 json_object_string_add(json_route
,
9018 vty_out(vty
, "%s [%d] area: %s",
9019 (or->path_type
== OSPF_PATH_INTER_AREA
9022 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9024 vty_out(vty
, "%s%s\n",
9025 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9028 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9034 json_nexthop_array
= json_object_new_array();
9035 json_object_object_add(json_route
, "nexthops",
9036 json_nexthop_array
);
9039 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9041 json_nexthop
= json_object_new_object();
9042 json_object_array_add(
9046 if (if_lookup_by_index(path
->ifindex
,
9048 if (path
->nexthop
.s_addr
== 0) {
9050 json_object_string_add(
9053 json_object_string_add(
9055 "directly attached to",
9061 "%24s directly attached to %s\n",
9069 json_object_string_add(
9074 json_object_string_add(
9082 "%24s via %s, %s\n",
9095 json_object_free(json_route
);
9101 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9102 struct route_table
*rt
,
9105 struct route_node
*rn
;
9106 struct ospf_route
*er
;
9107 struct listnode
*pnode
, *pnnode
;
9108 struct ospf_path
*path
;
9109 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9110 *json_nexthop
= NULL
;
9114 "============ OSPF external routing table ===========\n");
9116 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9117 if ((er
= rn
->info
) == NULL
)
9122 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9124 json_route
= json_object_new_object();
9126 json_object_object_add(json
, buf1
, json_route
);
9127 json_object_to_json_string_ext(
9128 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9131 switch (er
->path_type
) {
9132 case OSPF_PATH_TYPE1_EXTERNAL
:
9134 json_object_string_add(json_route
, "routeType",
9136 json_object_int_add(json_route
, "cost",
9140 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9142 buf1
, er
->cost
, er
->u
.ext
.tag
);
9145 case OSPF_PATH_TYPE2_EXTERNAL
:
9147 json_object_string_add(json_route
, "routeType",
9149 json_object_int_add(json_route
, "cost",
9153 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9155 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9162 json_nexthop_array
= json_object_new_array();
9163 json_object_object_add(json_route
, "nexthops",
9164 json_nexthop_array
);
9167 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9169 json_nexthop
= json_object_new_object();
9170 json_object_array_add(json_nexthop_array
,
9174 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9175 if (path
->nexthop
.s_addr
== 0) {
9177 json_object_string_add(
9180 json_object_string_add(
9182 "directly attached to",
9188 "%24s directly attached to %s\n",
9196 json_object_string_add(
9200 json_object_string_add(
9201 json_nexthop
, "via",
9207 "%24s via %s, %s\n",
9219 json_object_free(json_route
);
9225 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9230 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9232 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9234 if (ospf
->new_table
== NULL
) {
9235 vty_out(vty
, "No OSPF routing information exist\n");
9239 /* Show Network routes.
9240 show_ip_ospf_route_network (vty, ospf->new_table); */
9242 /* Show Router routes. */
9243 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9250 DEFUN (show_ip_ospf_border_routers
,
9251 show_ip_ospf_border_routers_cmd
,
9252 "show ip ospf [vrf <NAME|all>] border-routers",
9255 "OSPF information\n"
9258 "Show all the ABR's and ASBR's\n")
9260 struct ospf
*ospf
= NULL
;
9261 struct listnode
*node
= NULL
;
9262 char *vrf_name
= NULL
;
9263 bool all_vrf
= FALSE
;
9264 int ret
= CMD_SUCCESS
;
9267 uint8_t use_vrf
= 0;
9269 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9274 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9275 if (!ospf
->oi_running
)
9278 ret
= show_ip_ospf_border_routers_common(
9279 vty
, ospf
, use_vrf
);
9282 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9283 if (ospf
== NULL
|| !ospf
->oi_running
)
9286 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9290 /* Display default ospf (instance 0) info */
9291 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9292 if (ospf
== NULL
|| !ospf
->oi_running
)
9294 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9300 DEFUN (show_ip_ospf_instance_border_routers
,
9301 show_ip_ospf_instance_border_routers_cmd
,
9302 "show ip ospf (1-65535) border-routers",
9305 "OSPF information\n"
9307 "Show all the ABR's and ASBR's\n")
9311 unsigned short instance
= 0;
9313 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9314 ospf
= ospf_lookup_instance(instance
);
9316 return CMD_NOT_MY_INSTANCE
;
9318 if (!ospf
->oi_running
)
9321 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9324 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9325 json_object
*json
, uint8_t use_vrf
)
9327 json_object
*json_vrf
= NULL
;
9330 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9335 json_vrf
= json_object_new_object();
9340 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9342 if (ospf
->new_table
== NULL
) {
9343 vty_out(vty
, "No OSPF routing information exist\n");
9347 /* Show Network routes. */
9348 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9350 /* Show Router routes. */
9351 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9353 /* Show AS External routes. */
9354 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9359 // json_object_object_add(json_vrf, "areas",
9361 if (ospf
->vrf_id
== VRF_DEFAULT
)
9362 json_object_object_add(json
, "default",
9365 json_object_object_add(json
, ospf
->name
,
9375 DEFUN (show_ip_ospf_route
,
9376 show_ip_ospf_route_cmd
,
9377 "show ip ospf [vrf <NAME|all>] route [json]",
9380 "OSPF information\n"
9383 "OSPF routing table\n"
9386 struct ospf
*ospf
= NULL
;
9387 struct listnode
*node
= NULL
;
9388 char *vrf_name
= NULL
;
9389 bool all_vrf
= FALSE
;
9390 int ret
= CMD_SUCCESS
;
9393 uint8_t use_vrf
= 0;
9394 uint8_t uj
= use_json(argc
, argv
);
9395 json_object
*json
= NULL
;
9398 json
= json_object_new_object();
9400 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9402 /* vrf input is provided could be all or specific vrf*/
9406 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9407 if (!ospf
->oi_running
)
9409 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9414 /* Keep Non-pretty format */
9415 vty_out(vty
, "%s\n",
9416 json_object_to_json_string(json
));
9417 json_object_free(json
);
9422 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9423 if (ospf
== NULL
|| !ospf
->oi_running
) {
9425 json_object_free(json
);
9429 /* Display default ospf (instance 0) info */
9430 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9431 if (ospf
== NULL
|| !ospf
->oi_running
) {
9433 json_object_free(json
);
9439 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9440 /* Keep Non-pretty format */
9442 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9446 json_object_free(json
);
9451 DEFUN (show_ip_ospf_instance_route
,
9452 show_ip_ospf_instance_route_cmd
,
9453 "show ip ospf (1-65535) route",
9456 "OSPF information\n"
9458 "OSPF routing table\n")
9462 unsigned short instance
= 0;
9464 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9465 ospf
= ospf_lookup_instance(instance
);
9467 return CMD_NOT_MY_INSTANCE
;
9469 if (!ospf
->oi_running
)
9472 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9476 DEFUN (show_ip_ospf_vrfs
,
9477 show_ip_ospf_vrfs_cmd
,
9478 "show ip ospf vrfs [json]",
9481 "OSPF information\n"
9485 uint8_t uj
= use_json(argc
, argv
);
9486 json_object
*json
= NULL
;
9487 json_object
*json_vrfs
= NULL
;
9488 struct ospf
*ospf
= NULL
;
9489 struct listnode
*node
= NULL
;
9491 static char header
[] = "Name Id RouterId ";
9494 json
= json_object_new_object();
9495 json_vrfs
= json_object_new_object();
9498 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9499 json_object
*json_vrf
= NULL
;
9500 const char *name
= NULL
;
9501 int64_t vrf_id_ui
= 0;
9505 if (!uj
&& count
== 1)
9506 vty_out(vty
, "%s\n", header
);
9508 json_vrf
= json_object_new_object();
9510 if (ospf
->vrf_id
== 0)
9511 name
= VRF_DEFAULT_NAME
;
9515 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9517 : (int64_t)ospf
->vrf_id
;
9520 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9521 json_object_string_add(json_vrf
, "routerId",
9522 inet_ntoa(ospf
->router_id
));
9524 json_object_object_add(json_vrfs
, name
, json_vrf
);
9527 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9528 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9533 json_object_object_add(json
, "vrfs", json_vrfs
);
9534 json_object_int_add(json
, "totalVrfs", count
);
9536 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9537 json
, JSON_C_TO_STRING_PRETTY
));
9538 json_object_free(json
);
9541 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9548 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9551 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9553 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9554 "point-to-point", "broadcast",
9555 "non-broadcast", "point-to-multipoint",
9556 "virtual-link", /* should never be used. */
9559 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9561 struct listnode
*node
;
9562 struct interface
*ifp
;
9563 struct crypt_key
*ck
;
9564 struct route_node
*rn
= NULL
;
9565 struct ospf_if_params
*params
;
9567 struct ospf
*ospf
= vrf
->info
;
9569 FOR_ALL_INTERFACES (vrf
, ifp
) {
9571 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9574 vty_frame(vty
, "!\n");
9575 if (ifp
->vrf_id
== VRF_DEFAULT
)
9576 vty_frame(vty
, "interface %s\n", ifp
->name
);
9578 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9581 vty_out(vty
, " description %s\n", ifp
->desc
);
9585 params
= IF_DEF_PARAMS(ifp
);
9588 /* Interface Network print. */
9589 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9590 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9591 if (params
->type
!= ospf_default_iftype(ifp
)) {
9592 vty_out(vty
, " ip ospf network %s",
9595 if (params
!= IF_DEF_PARAMS(ifp
))
9603 /* OSPF interface authentication print */
9604 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9605 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9606 const char *auth_str
;
9608 /* Translation tables are not that much help
9609 * here due to syntax
9610 * of the simple option */
9611 switch (params
->auth_type
) {
9613 case OSPF_AUTH_NULL
:
9617 case OSPF_AUTH_SIMPLE
:
9621 case OSPF_AUTH_CRYPTOGRAPHIC
:
9622 auth_str
= " message-digest";
9630 vty_out(vty
, " ip ospf authentication%s",
9632 if (params
!= IF_DEF_PARAMS(ifp
))
9634 inet_ntoa(rn
->p
.u
.prefix4
));
9638 /* Simple Authentication Password print. */
9639 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9640 && params
->auth_simple
[0] != '\0') {
9641 vty_out(vty
, " ip ospf authentication-key %s",
9642 params
->auth_simple
);
9643 if (params
!= IF_DEF_PARAMS(ifp
))
9645 inet_ntoa(rn
->p
.u
.prefix4
));
9649 /* Cryptographic Authentication Key print. */
9650 if (params
&& params
->auth_crypt
) {
9651 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9654 " ip ospf message-digest-key %d md5 %s",
9655 ck
->key_id
, ck
->auth_key
);
9656 if (params
!= IF_DEF_PARAMS(ifp
))
9664 /* Interface Output Cost print. */
9665 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9666 vty_out(vty
, " ip ospf cost %u",
9667 params
->output_cost_cmd
);
9668 if (params
!= IF_DEF_PARAMS(ifp
))
9670 inet_ntoa(rn
->p
.u
.prefix4
));
9674 /* Hello Interval print. */
9675 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9676 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9677 vty_out(vty
, " ip ospf hello-interval %u",
9679 if (params
!= IF_DEF_PARAMS(ifp
))
9681 inet_ntoa(rn
->p
.u
.prefix4
));
9686 /* Router Dead Interval print. */
9687 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9689 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9690 vty_out(vty
, " ip ospf dead-interval ");
9693 if (OSPF_IF_PARAM_CONFIGURED(params
,
9696 "minimal hello-multiplier %d",
9697 params
->fast_hello
);
9699 vty_out(vty
, "%u", params
->v_wait
);
9701 if (params
!= IF_DEF_PARAMS(ifp
))
9703 inet_ntoa(rn
->p
.u
.prefix4
));
9707 /* Router Priority print. */
9708 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9710 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9711 vty_out(vty
, " ip ospf priority %u",
9713 if (params
!= IF_DEF_PARAMS(ifp
))
9715 inet_ntoa(rn
->p
.u
.prefix4
));
9719 /* Retransmit Interval print. */
9720 if (OSPF_IF_PARAM_CONFIGURED(params
,
9721 retransmit_interval
)
9722 && params
->retransmit_interval
9723 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9724 vty_out(vty
, " ip ospf retransmit-interval %u",
9725 params
->retransmit_interval
);
9726 if (params
!= IF_DEF_PARAMS(ifp
))
9728 inet_ntoa(rn
->p
.u
.prefix4
));
9732 /* Transmit Delay print. */
9733 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9734 && params
->transmit_delay
9735 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9736 vty_out(vty
, " ip ospf transmit-delay %u",
9737 params
->transmit_delay
);
9738 if (params
!= IF_DEF_PARAMS(ifp
))
9740 inet_ntoa(rn
->p
.u
.prefix4
));
9745 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9746 if (ospf
&& ospf
->instance
)
9747 vty_out(vty
, " ip ospf %d",
9750 vty_out(vty
, " ip ospf");
9752 char buf
[INET_ADDRSTRLEN
];
9754 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9755 params
->if_area_id_fmt
);
9756 vty_out(vty
, " area %s", buf
);
9757 if (params
!= IF_DEF_PARAMS(ifp
))
9759 inet_ntoa(rn
->p
.u
.prefix4
));
9764 if (params
&& params
->bfd_info
)
9765 ospf_bfd_write_config(vty
, params
);
9767 /* MTU ignore print. */
9768 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9769 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9770 if (params
->mtu_ignore
== 0)
9771 vty_out(vty
, " no ip ospf mtu-ignore");
9773 vty_out(vty
, " ip ospf mtu-ignore");
9774 if (params
!= IF_DEF_PARAMS(ifp
))
9776 inet_ntoa(rn
->p
.u
.prefix4
));
9783 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9785 rn
= route_next(rn
);
9795 ospf_opaque_config_write_if(vty
, ifp
);
9797 vty_endframe(vty
, NULL
);
9803 /* Configuration write function for ospfd. */
9804 static int config_write_interface(struct vty
*vty
)
9807 struct vrf
*vrf
= NULL
;
9809 /* Display all VRF aware OSPF interface configuration */
9810 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9811 write
+= config_write_interface_one(vty
, vrf
);
9817 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9819 struct route_node
*rn
;
9820 uint8_t buf
[INET_ADDRSTRLEN
];
9822 /* `network area' print. */
9823 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9825 struct ospf_network
*n
= rn
->info
;
9827 /* Create Area ID string by specified Area ID format. */
9828 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9829 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9832 sprintf((char *)buf
, "%lu",
9833 (unsigned long int)ntohl(
9834 n
->area_id
.s_addr
));
9836 /* Network print. */
9837 vty_out(vty
, " network %s/%d area %s\n",
9838 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9845 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9847 struct listnode
*node
;
9848 struct ospf_area
*area
;
9849 uint8_t buf
[INET_ADDRSTRLEN
];
9851 /* Area configuration print. */
9852 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9853 struct route_node
*rn1
;
9855 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
9858 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9859 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9860 vty_out(vty
, " area %s authentication\n", buf
);
9863 " area %s authentication message-digest\n",
9867 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9868 vty_out(vty
, " area %s shortcut %s\n", buf
,
9869 ospf_shortcut_mode_str
9870 [area
->shortcut_configured
]);
9872 if ((area
->external_routing
== OSPF_AREA_STUB
)
9873 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9874 if (area
->external_routing
== OSPF_AREA_STUB
) {
9875 vty_out(vty
, " area %s stub", buf
);
9876 if (area
->no_summary
)
9877 vty_out(vty
, " no-summary\n");
9879 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9880 switch (area
->NSSATranslatorRole
) {
9881 case OSPF_NSSA_ROLE_NEVER
:
9883 " area %s nssa translate-never\n",
9886 case OSPF_NSSA_ROLE_ALWAYS
:
9888 " area %s nssa translate-always\n",
9891 case OSPF_NSSA_ROLE_CANDIDATE
:
9892 vty_out(vty
, " area %s nssa \n", buf
);
9895 if (area
->no_summary
)
9897 " area %s nssa no-summary\n",
9901 if (area
->default_cost
!= 1)
9902 vty_out(vty
, " area %s default-cost %d\n", buf
,
9903 area
->default_cost
);
9906 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
9908 struct ospf_area_range
*range
= rn1
->info
;
9910 vty_out(vty
, " area %s range %s/%d", buf
,
9911 inet_ntoa(rn1
->p
.u
.prefix4
),
9914 if (range
->cost_config
9915 != OSPF_AREA_RANGE_COST_UNSPEC
)
9916 vty_out(vty
, " cost %d",
9917 range
->cost_config
);
9919 if (!CHECK_FLAG(range
->flags
,
9920 OSPF_AREA_RANGE_ADVERTISE
))
9921 vty_out(vty
, " not-advertise");
9923 if (CHECK_FLAG(range
->flags
,
9924 OSPF_AREA_RANGE_SUBSTITUTE
))
9925 vty_out(vty
, " substitute %s/%d",
9926 inet_ntoa(range
->subst_addr
),
9927 range
->subst_masklen
);
9932 if (EXPORT_NAME(area
))
9933 vty_out(vty
, " area %s export-list %s\n", buf
,
9936 if (IMPORT_NAME(area
))
9937 vty_out(vty
, " area %s import-list %s\n", buf
,
9940 if (PREFIX_NAME_IN(area
))
9941 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
9942 PREFIX_NAME_IN(area
));
9944 if (PREFIX_NAME_OUT(area
))
9945 vty_out(vty
, " area %s filter-list prefix %s out\n",
9946 buf
, PREFIX_NAME_OUT(area
));
9952 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
9954 struct ospf_nbr_nbma
*nbr_nbma
;
9955 struct route_node
*rn
;
9957 /* Static Neighbor configuration print. */
9958 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
9959 if ((nbr_nbma
= rn
->info
)) {
9960 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
9962 if (nbr_nbma
->priority
9963 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
9964 vty_out(vty
, " priority %d",
9965 nbr_nbma
->priority
);
9967 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
9968 vty_out(vty
, " poll-interval %d",
9977 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
9979 struct listnode
*node
;
9980 struct ospf_vl_data
*vl_data
;
9981 char buf
[INET_ADDRSTRLEN
];
9983 /* Virtual-Link print */
9984 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
9985 struct listnode
*n2
;
9986 struct crypt_key
*ck
;
9987 struct ospf_interface
*oi
;
9989 if (vl_data
!= NULL
) {
9990 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
9991 vl_data
->vl_area_id_fmt
);
9992 oi
= vl_data
->vl_oi
;
9995 if (OSPF_IF_PARAM(oi
, v_hello
)
9996 != OSPF_HELLO_INTERVAL_DEFAULT
9997 || OSPF_IF_PARAM(oi
, v_wait
)
9998 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
9999 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10000 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10001 || OSPF_IF_PARAM(oi
, transmit_delay
)
10002 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10004 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10005 buf
, inet_ntoa(vl_data
->vl_peer
),
10006 OSPF_IF_PARAM(oi
, v_hello
),
10007 OSPF_IF_PARAM(oi
, retransmit_interval
),
10008 OSPF_IF_PARAM(oi
, transmit_delay
),
10009 OSPF_IF_PARAM(oi
, v_wait
));
10011 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10012 inet_ntoa(vl_data
->vl_peer
));
10014 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10017 " area %s virtual-link %s authentication-key %s\n",
10018 buf
, inet_ntoa(vl_data
->vl_peer
),
10019 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10022 for (ALL_LIST_ELEMENTS_RO(
10023 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10027 " area %s virtual-link %s"
10028 " message-digest-key %d md5 %s\n",
10029 buf
, inet_ntoa(vl_data
->vl_peer
),
10030 ck
->key_id
, ck
->auth_key
);
10038 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10042 /* redistribute print. */
10043 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10044 struct list
*red_list
;
10045 struct listnode
*node
;
10046 struct ospf_redist
*red
;
10048 red_list
= ospf
->redist
[type
];
10052 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10053 vty_out(vty
, " redistribute %s",
10054 zebra_route_string(type
));
10056 vty_out(vty
, " %d", red
->instance
);
10058 if (red
->dmetric
.value
>= 0)
10059 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10061 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10062 vty_out(vty
, " metric-type 1");
10064 if (ROUTEMAP_NAME(red
))
10065 vty_out(vty
, " route-map %s",
10066 ROUTEMAP_NAME(red
));
10068 vty_out(vty
, "\n");
10075 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10077 if (ospf
->default_metric
!= -1)
10078 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10082 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10085 struct ospf_redist
*red
;
10088 /* distribute-list print. */
10089 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10090 if (DISTRIBUTE_NAME(ospf
, type
))
10091 vty_out(vty
, " distribute-list %s out %s\n",
10092 DISTRIBUTE_NAME(ospf
, type
),
10093 zebra_route_string(type
));
10095 /* default-information print. */
10096 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10097 vty_out(vty
, " default-information originate");
10098 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10099 vty_out(vty
, " always");
10101 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10103 if (red
->dmetric
.value
>= 0)
10104 vty_out(vty
, " metric %d",
10105 red
->dmetric
.value
);
10107 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10108 vty_out(vty
, " metric-type 1");
10110 if (ROUTEMAP_NAME(red
))
10111 vty_out(vty
, " route-map %s",
10112 ROUTEMAP_NAME(red
));
10115 vty_out(vty
, "\n");
10122 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10124 struct route_node
*rn
;
10125 struct ospf_distance
*odistance
;
10127 if (ospf
->distance_all
)
10128 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10130 if (ospf
->distance_intra
|| ospf
->distance_inter
10131 || ospf
->distance_external
) {
10132 vty_out(vty
, " distance ospf");
10134 if (ospf
->distance_intra
)
10135 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10136 if (ospf
->distance_inter
)
10137 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10138 if (ospf
->distance_external
)
10139 vty_out(vty
, " external %d", ospf
->distance_external
);
10141 vty_out(vty
, "\n");
10144 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10145 if ((odistance
= rn
->info
) != NULL
) {
10146 vty_out(vty
, " distance %d %s/%d %s\n",
10147 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10149 odistance
->access_list
? odistance
->access_list
10155 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10157 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10158 struct interface
*ifp
;
10159 struct ospf_interface
*oi
;
10160 struct listnode
*node
= NULL
;
10163 /* `router ospf' print. */
10164 if (ospf
->instance
&& ospf
->name
) {
10165 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10167 } else if (ospf
->instance
) {
10168 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10169 } else if (ospf
->name
) {
10170 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10172 vty_out(vty
, "router ospf\n");
10174 if (!ospf
->networks
) {
10179 /* Router ID print. */
10180 if (ospf
->router_id_static
.s_addr
!= 0)
10181 vty_out(vty
, " ospf router-id %s\n",
10182 inet_ntoa(ospf
->router_id_static
));
10184 /* ABR type print. */
10185 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10186 vty_out(vty
, " ospf abr-type %s\n",
10187 ospf_abr_type_str
[ospf
->abr_type
]);
10189 /* log-adjacency-changes flag print. */
10190 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10191 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10192 vty_out(vty
, " log-adjacency-changes detail\n");
10193 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10194 vty_out(vty
, " log-adjacency-changes\n");
10195 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10196 vty_out(vty
, " no log-adjacency-changes\n");
10199 /* RFC1583 compatibility flag print -- Compatible with CISCO
10201 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10202 vty_out(vty
, " compatible rfc1583\n");
10204 /* auto-cost reference-bandwidth configuration. */
10205 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10207 "! Important: ensure reference bandwidth "
10208 "is consistent across all routers\n");
10209 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10210 ospf
->ref_bandwidth
);
10213 /* SPF timers print. */
10214 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10215 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10216 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10217 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10218 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10220 /* LSA timers print. */
10221 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10222 vty_out(vty
, " timers throttle lsa all %d\n",
10223 ospf
->min_ls_interval
);
10224 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10225 vty_out(vty
, " timers lsa min-arrival %d\n",
10226 ospf
->min_ls_arrival
);
10228 /* Write multiplier print. */
10229 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10230 vty_out(vty
, " ospf write-multiplier %d\n",
10231 ospf
->write_oi_count
);
10233 /* Max-metric router-lsa print */
10234 config_write_stub_router(vty
, ospf
);
10236 /* SPF refresh parameters print. */
10237 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10238 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10240 /* Redistribute information print. */
10241 config_write_ospf_redistribute(vty
, ospf
);
10243 /* passive-interface print. */
10244 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10245 vty_out(vty
, " passive-interface default\n");
10247 FOR_ALL_INTERFACES (vrf
, ifp
)
10248 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10250 && IF_DEF_PARAMS(ifp
)->passive_interface
10251 != ospf
->passive_interface_default
) {
10252 vty_out(vty
, " %spassive-interface %s\n",
10253 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10257 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10258 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10260 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10261 passive_interface
)) {
10262 if (oi
->params
->passive_interface
10263 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10265 } else if (oi
->params
->passive_interface
10266 == ospf
->passive_interface_default
)
10269 vty_out(vty
, " %spassive-interface %s %s\n",
10270 oi
->params
->passive_interface
? "" : "no ",
10271 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10274 /* Network area print. */
10275 config_write_network_area(vty
, ospf
);
10277 /* Area config print. */
10278 config_write_ospf_area(vty
, ospf
);
10280 /* static neighbor print. */
10281 config_write_ospf_nbr_nbma(vty
, ospf
);
10283 /* Virtual-Link print. */
10284 config_write_virtual_link(vty
, ospf
);
10286 /* Default metric configuration. */
10287 config_write_ospf_default_metric(vty
, ospf
);
10289 /* Distribute-list and default-information print. */
10290 config_write_ospf_distribute(vty
, ospf
);
10292 /* Distance configuration. */
10293 config_write_ospf_distance(vty
, ospf
);
10295 ospf_opaque_config_write_router(vty
, ospf
);
10301 /* OSPF configuration write function. */
10302 static int ospf_config_write(struct vty
*vty
)
10305 struct listnode
*ospf_node
= NULL
;
10308 if (listcount(om
->ospf
) == 0)
10311 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10312 /* VRF Default check if it is running.
10313 * Upon daemon start, there could be default instance
10314 * in absence of 'router ospf'/oi_running is disabled. */
10315 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10316 write
+= ospf_config_write_one(vty
, ospf
);
10317 /* For Non-Default VRF simply display the configuration,
10318 * even if it is not oi_running. */
10319 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10320 write
+= ospf_config_write_one(vty
, ospf
);
10325 void ospf_vty_show_init(void)
10327 /* "show ip ospf" commands. */
10328 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10330 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10332 /* "show ip ospf database" commands. */
10333 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10335 install_element(VIEW_NODE
,
10336 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10337 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10338 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10340 /* "show ip ospf interface" commands. */
10341 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10343 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10344 /* "show ip ospf interface traffic */
10345 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10347 /* "show ip ospf neighbor" commands. */
10348 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10349 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10350 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10351 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10352 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10353 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10354 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10356 install_element(VIEW_NODE
,
10357 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10358 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10359 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10360 install_element(VIEW_NODE
,
10361 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10362 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10363 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10364 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10366 /* "show ip ospf route" commands. */
10367 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10368 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10370 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10371 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10373 /* "show ip ospf vrfs" commands. */
10374 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10378 /* ospfd's interface node. */
10379 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10381 /* Initialization of OSPF interface. */
10382 static void ospf_vty_if_init(void)
10384 /* Install interface node. */
10385 install_node(&interface_node
, config_write_interface
);
10388 /* "ip ospf authentication" commands. */
10389 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10390 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10391 install_element(INTERFACE_NODE
,
10392 &no_ip_ospf_authentication_args_addr_cmd
);
10393 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10394 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10395 install_element(INTERFACE_NODE
,
10396 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10397 install_element(INTERFACE_NODE
,
10398 &no_ospf_authentication_key_authkey_addr_cmd
);
10400 /* "ip ospf message-digest-key" commands. */
10401 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10402 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10404 /* "ip ospf cost" commands. */
10405 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10406 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10408 /* "ip ospf mtu-ignore" commands. */
10409 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10410 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10412 /* "ip ospf dead-interval" commands. */
10413 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10414 install_element(INTERFACE_NODE
,
10415 &ip_ospf_dead_interval_minimal_addr_cmd
);
10416 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10418 /* "ip ospf hello-interval" commands. */
10419 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10420 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10422 /* "ip ospf network" commands. */
10423 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10424 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10426 /* "ip ospf priority" commands. */
10427 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10428 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10430 /* "ip ospf retransmit-interval" commands. */
10431 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10432 install_element(INTERFACE_NODE
,
10433 &no_ip_ospf_retransmit_interval_addr_cmd
);
10435 /* "ip ospf transmit-delay" commands. */
10436 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10437 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10439 /* "ip ospf area" commands. */
10440 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10441 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10443 /* These commands are compatibitliy for previous version. */
10444 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10445 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10446 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10447 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10448 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10449 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10450 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10451 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10452 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10453 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10454 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10455 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10456 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10457 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10458 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10459 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10460 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10463 static void ospf_vty_zebra_init(void)
10465 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10466 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10467 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10468 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10470 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10471 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10473 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10474 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10476 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10477 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10479 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10480 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10481 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10482 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10484 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10485 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10486 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10487 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10491 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10493 static void ospf_interface_clear(struct interface
*ifp
)
10495 if (!if_is_operative(ifp
))
10498 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10499 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10501 ospf_if_reset(ifp
);
10504 DEFUN (clear_ip_ospf_interface
,
10505 clear_ip_ospf_interface_cmd
,
10506 "clear ip ospf interface [IFNAME]",
10509 "OSPF information\n"
10510 "Interface information\n"
10511 "Interface name\n")
10513 int idx_ifname
= 4;
10514 struct interface
*ifp
;
10515 struct listnode
*node
;
10516 struct ospf
*ospf
= NULL
;
10518 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10520 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10521 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10522 FOR_ALL_INTERFACES (vrf
, ifp
)
10523 ospf_interface_clear(ifp
);
10526 /* Interface name is specified. */
10527 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10529 vty_out(vty
, "No such interface name\n");
10531 ospf_interface_clear(ifp
);
10534 return CMD_SUCCESS
;
10537 void ospf_vty_clear_init(void)
10539 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10543 /* Install OSPF related vty commands. */
10544 void ospf_vty_init(void)
10546 /* Install ospf top node. */
10547 install_node(&ospf_node
, ospf_config_write
);
10549 /* "router ospf" commands. */
10550 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10551 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10554 install_default(OSPF_NODE
);
10556 /* "ospf router-id" commands. */
10557 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10558 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10559 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10561 /* "passive-interface" commands. */
10562 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10563 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10565 /* "ospf abr-type" commands. */
10566 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10567 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10569 /* "ospf log-adjacency-changes" commands. */
10570 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10571 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10572 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10573 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10575 /* "ospf rfc1583-compatible" commands. */
10576 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10577 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10578 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10579 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10581 /* "network area" commands. */
10582 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10583 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10585 /* "area authentication" commands. */
10586 install_element(OSPF_NODE
,
10587 &ospf_area_authentication_message_digest_cmd
);
10588 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10589 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10591 /* "area range" commands. */
10592 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10593 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10594 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10595 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10596 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10597 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10599 /* "area virtual-link" commands. */
10600 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10601 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10602 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10603 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10606 /* "area stub" commands. */
10607 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10608 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10609 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10610 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10612 /* "area nssa" commands. */
10613 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10614 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10615 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10616 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10617 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10619 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10620 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10622 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10623 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10625 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10626 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10628 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10629 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10631 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10632 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10634 /* SPF timer commands */
10635 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10636 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10638 /* LSA timers commands */
10639 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10640 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10641 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10642 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10644 /* refresh timer commands */
10645 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10646 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10648 /* max-metric commands */
10649 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10650 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10651 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10652 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10653 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10654 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10656 /* reference bandwidth commands */
10657 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10658 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10660 /* "neighbor" commands. */
10661 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10662 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10663 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10664 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10666 /* write multiplier commands */
10667 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10668 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10669 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10670 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10672 /* Init interface related vty commands. */
10673 ospf_vty_if_init();
10675 /* Init zebra related vty commands. */
10676 ospf_vty_zebra_init();