2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "ospfd/ospfd.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_ism.h"
43 #include "ospfd/ospf_interface.h"
44 #include "ospfd/ospf_nsm.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_flood.h"
47 #include "ospfd/ospf_abr.h"
48 #include "ospfd/ospf_spf.h"
49 #include "ospfd/ospf_route.h"
50 #include "ospfd/ospf_zebra.h"
51 /*#include "ospfd/ospf_routemap.h" */
52 #include "ospfd/ospf_vty.h"
53 #include "ospfd/ospf_dump.h"
54 #include "ospfd/ospf_bfd.h"
56 static const char *ospf_network_type_str
[] = {
57 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
58 "VIRTUALLINK", "LOOPBACK"};
60 /* Utility functions. */
61 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
65 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
66 if (*ep
&& !inet_aton(str
, area_id
))
70 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
75 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
78 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
79 inet_ntop(AF_INET
, area_id
, buf
, length
);
81 sprintf(buf
, "%lu", (unsigned long)ntohl(area_id
->s_addr
));
84 static int str2metric(const char *str
, int *metric
)
90 *metric
= strtol(str
, NULL
, 10);
91 if (*metric
< 0 && *metric
> 16777214) {
92 /* vty_out (vty, "OSPF metric value is invalid\n"); */
99 static int str2metric_type(const char *str
, int *metric_type
)
105 if (strncmp(str
, "1", 1) == 0)
106 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
107 else if (strncmp(str
, "2", 1) == 0)
108 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
115 int ospf_oi_count(struct interface
*ifp
)
117 struct route_node
*rn
;
120 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
127 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
128 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
129 vrf_name = argv[idx_vrf + 1]->arg; \
130 all_vrf = strmatch(vrf_name, "all"); \
133 static struct ospf
*ospf_cmd_lookup_ospf(struct vty
*vty
,
134 struct cmd_token
*argv
[],
135 const int argc
, uint32_t enable
,
136 unsigned short *instance
)
138 struct ospf
*ospf
= NULL
;
139 int idx_vrf
= 0, idx_inst
= 0;
140 const char *vrf_name
= NULL
;
143 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
))
144 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
146 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
147 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
149 /* Allocate VRF aware instance */
150 ospf
= ospf_get(*instance
, vrf_name
);
152 ospf
= ospf_lookup_by_inst_name(*instance
, vrf_name
);
156 ospf
= ospf_get(*instance
, NULL
);
158 ospf
= ospf_lookup_instance(*instance
);
165 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
166 json_object
*json
, uint8_t use_vrf
)
170 if (ospf
->vrf_id
== VRF_DEFAULT
)
171 json_object_string_add(json
, "vrfName",
174 json_object_string_add(json
, "vrfName",
176 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
178 if (ospf
->vrf_id
== VRF_DEFAULT
)
179 vty_out(vty
, "VRF Name: %s\n", "default");
181 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
186 #ifndef VTYSH_EXTRACT_PL
187 #include "ospfd/ospf_vty_clippy.c"
190 DEFUN_NOSH (router_ospf
,
192 "router ospf [{(1-65535)|vrf NAME}]",
193 "Enable a routing process\n"
194 "Start OSPF configuration\n"
198 struct ospf
*ospf
= NULL
;
199 int ret
= CMD_SUCCESS
;
200 unsigned short instance
= 0;
201 struct vrf
*vrf
= NULL
;
202 struct route_node
*rn
;
203 struct interface
*ifp
;
205 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 1, &instance
);
207 return CMD_WARNING_CONFIG_FAILED
;
209 /* The following logic to set the vty qobj index is in place to be able
210 to ignore the commands which dont belong to this instance. */
211 if (ospf
->instance
!= instance
) {
212 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
213 ret
= CMD_NOT_MY_INSTANCE
;
215 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
216 ospf
->oi_running
= 1;
217 if (IS_DEBUG_OSPF_EVENT
)
219 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
220 instance
, ospf
->name
? ospf
->name
: "NIL",
221 ospf
->vrf_id
, ospf
->oi_running
);
222 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
224 /* Activate 'ip ospf area x' configured interfaces for given
225 * vrf. Activate area on vrf x aware interfaces.
226 * vrf_enable callback calls router_id_update which
227 * internally will call ospf_if_update to trigger
230 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
232 FOR_ALL_INTERFACES (vrf
, ifp
) {
233 struct ospf_if_params
*params
;
235 params
= IF_DEF_PARAMS(ifp
);
236 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
237 for (rn
= route_top(ospf
->networks
); rn
;
238 rn
= route_next(rn
)) {
239 if (rn
->info
!= NULL
) {
241 "Interface %s has area config but please remove all network commands first.\n",
246 ospf_interface_area_set(ospf
, ifp
);
247 ospf
->if_ospf_cli_count
++;
251 ospf_router_id_update(ospf
);
257 DEFUN (no_router_ospf
,
259 "no router ospf [{(1-65535)|vrf NAME}]",
261 "Enable a routing process\n"
262 "Start OSPF configuration\n"
267 unsigned short instance
= 0;
269 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 0, &instance
);
272 return CMD_NOT_MY_INSTANCE
;
282 DEFPY (ospf_router_id
,
284 "ospf router-id A.B.C.D",
285 "OSPF specific commands\n"
286 "router-id for the OSPF process\n"
287 "OSPF router-id in IP address format\n")
289 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
291 struct listnode
*node
;
292 struct ospf_area
*area
;
294 ospf
->router_id_static
= router_id
;
296 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
297 if (area
->full_nbrs
) {
299 "For this router-id change to take effect,"
300 " save config and restart ospfd\n");
304 ospf_router_id_update(ospf
);
309 DEFUN_HIDDEN (ospf_router_id_old
,
310 ospf_router_id_old_cmd
,
312 "router-id for the OSPF process\n"
313 "OSPF router-id in IP address format\n")
315 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
317 struct listnode
*node
;
318 struct ospf_area
*area
;
319 struct in_addr router_id
;
322 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
324 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
325 return CMD_WARNING_CONFIG_FAILED
;
328 ospf
->router_id_static
= router_id
;
330 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
331 if (area
->full_nbrs
) {
333 "For this router-id change to take effect,"
334 " save config and restart ospfd\n");
338 ospf_router_id_update(ospf
);
343 DEFPY (no_ospf_router_id
,
344 no_ospf_router_id_cmd
,
345 "no ospf router-id [A.B.C.D]",
347 "OSPF specific commands\n"
348 "router-id for the OSPF process\n"
349 "OSPF router-id in IP address format\n")
351 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
352 struct listnode
*node
;
353 struct ospf_area
*area
;
356 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
357 vty_out(vty
, "%% OSPF router-id doesn't match\n");
358 return CMD_WARNING_CONFIG_FAILED
;
362 ospf
->router_id_static
.s_addr
= 0;
364 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
365 if (area
->full_nbrs
) {
367 "For this router-id change to take effect,"
368 " save config and restart ospfd\n");
372 ospf_router_id_update(ospf
);
378 static void ospf_passive_interface_default(struct ospf
*ospf
, uint8_t newval
)
380 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
382 struct interface
*ifp
;
383 struct ospf_interface
*oi
;
385 ospf
->passive_interface_default
= newval
;
387 FOR_ALL_INTERFACES (vrf
, ifp
) {
388 if (ifp
&& OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
390 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp
), passive_interface
);
392 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
)) {
393 if (OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
394 UNSET_IF_PARAM(oi
->params
, passive_interface
);
395 /* update multicast memberships */
396 ospf_if_set_multicast(oi
);
400 static void ospf_passive_interface_update_addr(struct ospf
*ospf
,
401 struct interface
*ifp
,
402 struct ospf_if_params
*params
,
408 params
->passive_interface
= value
;
409 if (params
!= IF_DEF_PARAMS(ifp
)) {
410 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
412 dflt
= IF_DEF_PARAMS(ifp
)->passive_interface
;
414 dflt
= ospf
->passive_interface_default
;
417 SET_IF_PARAM(params
, passive_interface
);
419 UNSET_IF_PARAM(params
, passive_interface
);
421 ospf_free_if_params(ifp
, addr
);
422 ospf_if_update_params(ifp
, addr
);
426 static void ospf_passive_interface_update(struct ospf
*ospf
,
427 struct interface
*ifp
,
428 struct ospf_if_params
*params
,
431 params
->passive_interface
= value
;
432 if (params
== IF_DEF_PARAMS(ifp
)) {
433 if (value
!= ospf
->passive_interface_default
)
434 SET_IF_PARAM(params
, passive_interface
);
436 UNSET_IF_PARAM(params
, passive_interface
);
440 DEFUN (ospf_passive_interface
,
441 ospf_passive_interface_addr_cmd
,
442 "passive-interface <IFNAME [A.B.C.D]|default>",
443 "Suppress routing updates on an interface\n"
446 "Suppress routing updates on interfaces by default\n")
448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
450 struct interface
*ifp
= NULL
;
451 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
453 struct ospf_if_params
*params
;
454 struct route_node
*rn
;
456 if (strmatch(argv
[1]->text
, "default")) {
457 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
460 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
461 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, 0);
464 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
465 return CMD_WARNING_CONFIG_FAILED
;
468 params
= IF_DEF_PARAMS(ifp
);
471 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
474 "Please specify interface address by A.B.C.D\n");
475 return CMD_WARNING_CONFIG_FAILED
;
478 params
= ospf_get_if_params(ifp
, addr
);
479 ospf_if_update_params(ifp
, addr
);
480 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
481 OSPF_IF_PASSIVE
, addr
);
484 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
486 /* XXX We should call ospf_if_set_multicast on exactly those
487 * interfaces for which the passive property changed. It is too much
488 * work to determine this set, so we do this for every interface.
489 * This is safe and reasonable because ospf_if_set_multicast uses a
490 * record of joined groups to avoid systems calls if the desired
491 * memberships match the current memership.
494 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
495 struct ospf_interface
*oi
= rn
->info
;
497 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
499 ospf_if_set_multicast(oi
);
502 * XXX It is not clear what state transitions the interface needs to
503 * undergo when going from active to passive. Fixing this will
504 * require precise identification of interfaces having such a
511 DEFUN (no_ospf_passive_interface
,
512 no_ospf_passive_interface_addr_cmd
,
513 "no passive-interface <IFNAME [A.B.C.D]|default>",
515 "Allow routing updates on an interface\n"
518 "Allow routing updates on interfaces by default\n")
520 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
522 struct interface
*ifp
= NULL
;
523 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
524 struct ospf_if_params
*params
;
526 struct route_node
*rn
;
528 if (strmatch(argv
[2]->text
, "default")) {
529 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
533 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
534 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, 0);
537 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
538 return CMD_WARNING_CONFIG_FAILED
;
541 params
= IF_DEF_PARAMS(ifp
);
544 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
547 "Please specify interface address by A.B.C.D\n");
548 return CMD_WARNING_CONFIG_FAILED
;
551 params
= ospf_lookup_if_params(ifp
, addr
);
554 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
555 OSPF_IF_ACTIVE
, addr
);
557 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
559 /* XXX We should call ospf_if_set_multicast on exactly those
560 * interfaces for which the passive property changed. It is too much
561 * work to determine this set, so we do this for every interface.
562 * This is safe and reasonable because ospf_if_set_multicast uses a
563 * record of joined groups to avoid systems calls if the desired
564 * memberships match the current memership.
566 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
567 struct ospf_interface
*oi
= rn
->info
;
570 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
571 ospf_if_set_multicast(oi
);
578 DEFUN (ospf_network_area
,
579 ospf_network_area_cmd
,
580 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
581 "Enable routing on an IP network\n"
582 "OSPF network prefix\n"
583 "Set the OSPF area ID\n"
584 "OSPF area ID in IP address format\n"
585 "OSPF area ID as a decimal value\n")
587 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
588 int idx_ipv4_prefixlen
= 1;
589 int idx_ipv4_number
= 3;
590 struct prefix_ipv4 p
;
591 struct in_addr area_id
;
594 if (ospf
->instance
) {
596 "The network command is not supported in multi-instance ospf\n");
597 return CMD_WARNING_CONFIG_FAILED
;
600 if (ospf
->if_ospf_cli_count
> 0) {
602 "Please remove all ip ospf area x.x.x.x commands first.\n");
603 if (IS_DEBUG_OSPF_EVENT
)
605 "%s ospf vrf %s num of %u ip osp area x config",
607 ospf
->name
? ospf
->name
: "NIL",
608 ospf
->if_ospf_cli_count
);
609 return CMD_WARNING_CONFIG_FAILED
;
612 /* Get network prefix and Area ID. */
613 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
614 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
616 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
618 vty_out(vty
, "There is already same network statement.\n");
619 return CMD_WARNING_CONFIG_FAILED
;
625 DEFUN (no_ospf_network_area
,
626 no_ospf_network_area_cmd
,
627 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
629 "Enable routing on an IP network\n"
630 "OSPF network prefix\n"
631 "Set the OSPF area ID\n"
632 "OSPF area ID in IP address format\n"
633 "OSPF area ID as a decimal value\n")
635 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
636 int idx_ipv4_prefixlen
= 2;
637 int idx_ipv4_number
= 4;
638 struct prefix_ipv4 p
;
639 struct in_addr area_id
;
642 if (ospf
->instance
) {
644 "The network command is not supported in multi-instance ospf\n");
645 return CMD_WARNING_CONFIG_FAILED
;
648 /* Get network prefix and Area ID. */
649 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
650 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
652 ret
= ospf_network_unset(ospf
, &p
, area_id
);
655 "Can't find specified network area configuration.\n");
656 return CMD_WARNING_CONFIG_FAILED
;
662 DEFUN (ospf_area_range
,
664 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
665 "OSPF area parameters\n"
666 "OSPF area ID in IP address format\n"
667 "OSPF area ID as a decimal value\n"
668 "Summarize routes matching address/mask (border routers only)\n"
669 "Area range prefix\n"
670 "Advertise this range (default)\n"
671 "User specified metric for this range\n"
672 "Advertised metric for this range\n")
674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
675 int idx_ipv4_number
= 1;
676 int idx_ipv4_prefixlen
= 3;
678 struct prefix_ipv4 p
;
679 struct in_addr area_id
;
683 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
684 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
686 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
688 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
689 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
695 DEFUN (ospf_area_range_cost
,
696 ospf_area_range_cost_cmd
,
697 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
698 "OSPF area parameters\n"
699 "OSPF area ID in IP address format\n"
700 "OSPF area ID as a decimal value\n"
701 "Summarize routes matching address/mask (border routers only)\n"
702 "Area range prefix\n"
703 "User specified metric for this range\n"
704 "Advertised metric for this range\n")
706 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
707 int idx_ipv4_number
= 1;
708 int idx_ipv4_prefixlen
= 3;
710 struct prefix_ipv4 p
;
711 struct in_addr area_id
;
715 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
716 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
718 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
719 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
722 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
723 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
728 DEFUN (ospf_area_range_not_advertise
,
729 ospf_area_range_not_advertise_cmd
,
730 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
731 "OSPF area parameters\n"
732 "OSPF area ID in IP address format\n"
733 "OSPF area ID as a decimal value\n"
734 "Summarize routes matching address/mask (border routers only)\n"
735 "Area range prefix\n"
736 "DoNotAdvertise this range\n")
738 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
739 int idx_ipv4_number
= 1;
740 int idx_ipv4_prefixlen
= 3;
741 struct prefix_ipv4 p
;
742 struct in_addr area_id
;
745 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
746 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
748 ospf_area_range_set(ospf
, area_id
, &p
, 0);
749 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
755 DEFUN (no_ospf_area_range
,
756 no_ospf_area_range_cmd
,
757 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
759 "OSPF area parameters\n"
760 "OSPF area ID in IP address format\n"
761 "OSPF area ID as a decimal value\n"
762 "Summarize routes matching address/mask (border routers only)\n"
763 "Area range prefix\n"
764 "User specified metric for this range\n"
765 "Advertised metric for this range\n"
766 "Advertise this range (default)\n"
767 "User specified metric for this range\n"
768 "Advertised metric for this range\n"
769 "DoNotAdvertise this range\n")
771 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
772 int idx_ipv4_number
= 2;
773 int idx_ipv4_prefixlen
= 4;
774 struct prefix_ipv4 p
;
775 struct in_addr area_id
;
778 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
779 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
781 ospf_area_range_unset(ospf
, area_id
, &p
);
786 DEFUN (ospf_area_range_substitute
,
787 ospf_area_range_substitute_cmd
,
788 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
789 "OSPF area parameters\n"
790 "OSPF area ID in IP address format\n"
791 "OSPF area ID as a decimal value\n"
792 "Summarize routes matching address/mask (border routers only)\n"
793 "Area range prefix\n"
794 "Announce area range as another prefix\n"
795 "Network prefix to be announced instead of range\n")
797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
798 int idx_ipv4_number
= 1;
799 int idx_ipv4_prefixlen
= 3;
800 int idx_ipv4_prefixlen_2
= 5;
801 struct prefix_ipv4 p
, s
;
802 struct in_addr area_id
;
805 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
806 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
807 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
809 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
810 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
816 DEFUN (no_ospf_area_range_substitute
,
817 no_ospf_area_range_substitute_cmd
,
818 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
820 "OSPF area parameters\n"
821 "OSPF area ID in IP address format\n"
822 "OSPF area ID as a decimal value\n"
823 "Summarize routes matching address/mask (border routers only)\n"
824 "Area range prefix\n"
825 "Announce area range as another prefix\n"
826 "Network prefix to be announced instead of range\n")
828 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
829 int idx_ipv4_number
= 2;
830 int idx_ipv4_prefixlen
= 4;
831 int idx_ipv4_prefixlen_2
= 6;
832 struct prefix_ipv4 p
, s
;
833 struct in_addr area_id
;
836 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
837 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
838 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
840 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
846 /* Command Handler Logic in VLink stuff is delicate!!
848 ALTER AT YOUR OWN RISK!!!!
850 Various dummy values are used to represent 'NoChange' state for
851 VLink configuration NOT being changed by a VLink command, and
852 special syntax is used within the command strings so that the
853 typed in command verbs can be seen in the configuration command
854 bacckend handler. This is to drastically reduce the verbeage
855 required to coe up with a reasonably compatible Cisco VLink command
857 - Matthew Grant <grantma@anathoth.gen.nz>
858 Wed, 21 Feb 2001 15:13:52 +1300
861 /* Configuration data for virtual links
863 struct ospf_vl_config_data
{
864 struct vty
*vty
; /* vty stuff */
865 struct in_addr area_id
; /* area ID from command line */
866 int area_id_fmt
; /* command line area ID format */
867 struct in_addr vl_peer
; /* command line vl_peer */
868 int auth_type
; /* Authehntication type, if given */
869 char *auth_key
; /* simple password if present */
870 int crypto_key_id
; /* Cryptographic key ID */
871 char *md5_key
; /* MD5 authentication key */
872 int hello_interval
; /* Obvious what these are... */
873 int retransmit_interval
;
878 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
881 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
882 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
883 vl_config
->vty
= vty
;
886 static struct ospf_vl_data
*
887 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
889 struct ospf_area
*area
;
890 struct ospf_vl_data
*vl_data
;
892 struct in_addr area_id
;
894 vty
= vl_config
->vty
;
895 area_id
= vl_config
->area_id
;
897 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
899 "Configuring VLs over the backbone is not allowed\n");
902 area
= ospf_area_get(ospf
, area_id
);
903 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
905 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
906 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
907 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
908 area
->external_routing
== OSPF_AREA_NSSA
912 vty_out(vty
, "Area %ld is %s\n",
913 (unsigned long)ntohl(area_id
.s_addr
),
914 area
->external_routing
== OSPF_AREA_NSSA
920 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
922 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
923 if (vl_data
->vl_oi
== NULL
) {
924 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
925 ospf_vl_add(ospf
, vl_data
);
926 ospf_spf_calculate_schedule(ospf
,
927 SPF_FLAG_CONFIG_CHANGE
);
934 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
935 struct ospf_vl_config_data
*vl_config
)
937 struct crypt_key
*ck
;
939 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
941 vty
= vl_config
->vty
;
943 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
944 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
945 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
948 if (vl_config
->auth_key
) {
949 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
950 OSPF_AUTH_SIMPLE_SIZE
+ 1);
951 strncpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
952 vl_config
->auth_key
, OSPF_AUTH_SIMPLE_SIZE
);
953 } else if (vl_config
->md5_key
) {
954 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
955 vl_config
->crypto_key_id
)
957 vty_out(vty
, "OSPF: Key %d already exists\n",
958 vl_config
->crypto_key_id
);
961 ck
= ospf_crypt_key_new();
962 ck
->key_id
= vl_config
->crypto_key_id
;
963 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
964 strncpy((char *)ck
->auth_key
, vl_config
->md5_key
,
967 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
968 } else if (vl_config
->crypto_key_id
!= 0) {
971 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
972 vl_config
->crypto_key_id
)
974 vty_out(vty
, "OSPF: Key %d does not exist\n",
975 vl_config
->crypto_key_id
);
976 return CMD_WARNING_CONFIG_FAILED
;
979 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
980 vl_config
->crypto_key_id
);
986 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
987 struct ospf_vl_config_data
*vl_config
)
989 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
990 /* Virtual Link data initialised to defaults, so only set
992 if (vl_config
->hello_interval
) {
993 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
994 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
997 if (vl_config
->dead_interval
) {
998 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
999 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1002 if (vl_config
->retransmit_interval
) {
1003 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1004 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1005 vl_config
->retransmit_interval
;
1008 if (vl_config
->transmit_delay
) {
1009 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1010 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1017 /* The business end of all of the above */
1018 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1020 struct ospf_vl_data
*vl_data
;
1023 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1025 return CMD_WARNING_CONFIG_FAILED
;
1027 /* Process this one first as it can have a fatal result, which can
1028 only logically occur if the virtual link exists already
1029 Thus a command error does not result in a change to the
1030 running configuration such as unexpectedly altered timer
1032 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1033 if (ret
!= CMD_SUCCESS
)
1036 /* Set any time based parameters, these area already range checked */
1038 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1039 if (ret
!= CMD_SUCCESS
)
1045 /* This stuff exists to make specifying all the alias commands A LOT simpler
1047 #define VLINK_HELPSTR_IPADDR \
1048 "OSPF area parameters\n" \
1049 "OSPF area ID in IP address format\n" \
1050 "OSPF area ID as a decimal value\n" \
1051 "Configure a virtual link\n" \
1052 "Router ID of the remote ABR\n"
1054 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1055 "Enable authentication on this virtual link\n" \
1058 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1059 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1060 "Use null authentication\n" \
1061 "Use message-digest authentication\n"
1063 #define VLINK_HELPSTR_TIME_PARAM \
1064 "Time between HELLO packets\n" \
1066 "Time between retransmitting lost link state advertisements\n" \
1068 "Link state transmit delay\n" \
1070 "Interval time after which a neighbor is declared down\n" \
1073 #define VLINK_HELPSTR_AUTH_SIMPLE \
1074 "Authentication password (key)\n" \
1075 "The OSPF password (key)\n"
1077 #define VLINK_HELPSTR_AUTH_MD5 \
1078 "Message digest authentication password (key)\n" \
1080 "Use MD5 algorithm\n" \
1081 "The OSPF password (key)\n"
1083 DEFUN (ospf_area_vlink
,
1084 ospf_area_vlink_cmd
,
1085 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1086 VLINK_HELPSTR_IPADDR
1087 "Enable authentication on this virtual link\n"
1088 "Use message-digest authentication\n"
1089 "Use null authentication\n"
1090 VLINK_HELPSTR_AUTH_MD5
1091 VLINK_HELPSTR_AUTH_SIMPLE
)
1093 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1094 int idx_ipv4_number
= 1;
1096 struct ospf_vl_config_data vl_config
;
1097 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1098 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1102 ospf_vl_config_data_init(&vl_config
, vty
);
1104 /* Read off first 2 parameters and check them */
1105 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1106 &vl_config
.area_id_fmt
);
1108 vty_out(vty
, "OSPF area ID is invalid\n");
1109 return CMD_WARNING_CONFIG_FAILED
;
1112 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1114 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1115 return CMD_WARNING_CONFIG_FAILED
;
1119 /* Thats all folks! - BUGS B. strikes again!!!*/
1121 return ospf_vl_set(ospf
, &vl_config
);
1124 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1125 /* authentication - this option can only occur
1126 at start of command line */
1127 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1130 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1131 /* authentication message-digest */
1132 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1133 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1134 /* "authentication null" */
1135 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1138 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1139 vl_config
.md5_key
= NULL
;
1140 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1141 if (vl_config
.crypto_key_id
< 0)
1142 return CMD_WARNING_CONFIG_FAILED
;
1144 memset(md5_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
1145 strncpy(md5_key
, argv
[idx
+ 3]->arg
, OSPF_AUTH_MD5_SIZE
);
1146 vl_config
.md5_key
= md5_key
;
1149 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1150 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1151 strncpy(auth_key
, argv
[idx
+ 1]->arg
, OSPF_AUTH_SIMPLE_SIZE
);
1152 vl_config
.auth_key
= auth_key
;
1155 /* Action configuration */
1157 return ospf_vl_set(ospf
, &vl_config
);
1160 DEFUN (no_ospf_area_vlink
,
1161 no_ospf_area_vlink_cmd
,
1162 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1164 VLINK_HELPSTR_IPADDR
1165 "Enable authentication on this virtual link\n" \
1166 "Use message-digest authentication\n" \
1167 "Use null authentication\n" \
1168 VLINK_HELPSTR_AUTH_MD5
1169 VLINK_HELPSTR_AUTH_SIMPLE
)
1171 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1172 int idx_ipv4_number
= 2;
1174 struct ospf_area
*area
;
1175 struct ospf_vl_config_data vl_config
;
1176 struct ospf_vl_data
*vl_data
= NULL
;
1177 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1181 ospf_vl_config_data_init(&vl_config
, vty
);
1183 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1186 vty_out(vty
, "OSPF area ID is invalid\n");
1187 return CMD_WARNING_CONFIG_FAILED
;
1190 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1192 vty_out(vty
, "Area does not exist\n");
1193 return CMD_WARNING_CONFIG_FAILED
;
1196 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1198 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1199 return CMD_WARNING_CONFIG_FAILED
;
1203 /* Basic VLink no command */
1204 /* Thats all folks! - BUGS B. strikes again!!!*/
1205 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
)))
1206 ospf_vl_delete(ospf
, vl_data
);
1208 ospf_area_check_free(ospf
, vl_config
.area_id
);
1213 /* If we are down here, we are reseting parameters */
1214 /* Deal with other parameters */
1216 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1217 /* authentication - this option can only occur
1218 at start of command line */
1219 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1222 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1223 vl_config
.md5_key
= NULL
;
1224 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1225 if (vl_config
.crypto_key_id
< 0)
1226 return CMD_WARNING_CONFIG_FAILED
;
1229 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1230 /* Reset authentication-key to 0 */
1231 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1232 vl_config
.auth_key
= auth_key
;
1235 /* Action configuration */
1237 return ospf_vl_set(ospf
, &vl_config
);
1240 DEFUN (ospf_area_vlink_intervals
,
1241 ospf_area_vlink_intervals_cmd
,
1242 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1243 VLINK_HELPSTR_IPADDR
1244 VLINK_HELPSTR_TIME_PARAM
)
1246 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1247 struct ospf_vl_config_data vl_config
;
1250 ospf_vl_config_data_init(&vl_config
, vty
);
1252 char *area_id
= argv
[1]->arg
;
1253 char *router_id
= argv
[3]->arg
;
1255 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1257 vty_out(vty
, "OSPF area ID is invalid\n");
1258 return CMD_WARNING_CONFIG_FAILED
;
1261 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1263 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1264 return CMD_WARNING_CONFIG_FAILED
;
1267 for (int idx
= 4; idx
< argc
; idx
++) {
1268 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1269 vl_config
.hello_interval
=
1270 strtol(argv
[++idx
]->arg
, NULL
, 10);
1271 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1272 vl_config
.retransmit_interval
=
1273 strtol(argv
[++idx
]->arg
, NULL
, 10);
1274 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1275 vl_config
.transmit_delay
=
1276 strtol(argv
[++idx
]->arg
, NULL
, 10);
1277 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1278 vl_config
.dead_interval
=
1279 strtol(argv
[++idx
]->arg
, NULL
, 10);
1282 /* Action configuration */
1283 return ospf_vl_set(ospf
, &vl_config
);
1286 DEFUN (no_ospf_area_vlink_intervals
,
1287 no_ospf_area_vlink_intervals_cmd
,
1288 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1290 VLINK_HELPSTR_IPADDR
1291 VLINK_HELPSTR_TIME_PARAM
)
1293 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1294 struct ospf_vl_config_data vl_config
;
1297 ospf_vl_config_data_init(&vl_config
, vty
);
1299 char *area_id
= argv
[2]->arg
;
1300 char *router_id
= argv
[4]->arg
;
1302 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1304 vty_out(vty
, "OSPF area ID is invalid\n");
1305 return CMD_WARNING_CONFIG_FAILED
;
1308 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1310 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1311 return CMD_WARNING_CONFIG_FAILED
;
1314 for (int idx
= 5; idx
< argc
; idx
++) {
1315 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1316 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1317 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1318 vl_config
.retransmit_interval
=
1319 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1320 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1321 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1322 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1323 vl_config
.dead_interval
=
1324 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1327 /* Action configuration */
1328 return ospf_vl_set(ospf
, &vl_config
);
1331 DEFUN (ospf_area_shortcut
,
1332 ospf_area_shortcut_cmd
,
1333 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1334 "OSPF area parameters\n"
1335 "OSPF area ID in IP address format\n"
1336 "OSPF area ID as a decimal value\n"
1337 "Configure the area's shortcutting mode\n"
1338 "Set default shortcutting behavior\n"
1339 "Enable shortcutting through the area\n"
1340 "Disable shortcutting through the area\n")
1342 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1343 int idx_ipv4_number
= 1;
1344 int idx_enable_disable
= 3;
1345 struct ospf_area
*area
;
1346 struct in_addr area_id
;
1350 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1351 argv
[idx_ipv4_number
]->arg
);
1353 area
= ospf_area_get(ospf
, area_id
);
1354 ospf_area_display_format_set(ospf
, area
, format
);
1356 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1357 mode
= OSPF_SHORTCUT_DEFAULT
;
1358 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1359 mode
= OSPF_SHORTCUT_DISABLE
;
1360 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1361 mode
= OSPF_SHORTCUT_ENABLE
;
1363 return CMD_WARNING_CONFIG_FAILED
;
1365 ospf_area_shortcut_set(ospf
, area
, mode
);
1367 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1369 "Shortcut area setting will take effect "
1370 "only when the router is configured as Shortcut ABR\n");
1375 DEFUN (no_ospf_area_shortcut
,
1376 no_ospf_area_shortcut_cmd
,
1377 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1379 "OSPF area parameters\n"
1380 "OSPF area ID in IP address format\n"
1381 "OSPF area ID as a decimal value\n"
1382 "Deconfigure the area's shortcutting mode\n"
1383 "Deconfigure enabled shortcutting through the area\n"
1384 "Deconfigure disabled shortcutting through the area\n")
1386 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1387 int idx_ipv4_number
= 2;
1388 struct ospf_area
*area
;
1389 struct in_addr area_id
;
1392 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1393 argv
[idx_ipv4_number
]->arg
);
1395 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1399 ospf_area_shortcut_unset(ospf
, area
);
1405 DEFUN (ospf_area_stub
,
1407 "area <A.B.C.D|(0-4294967295)> stub",
1408 "OSPF area parameters\n"
1409 "OSPF area ID in IP address format\n"
1410 "OSPF area ID as a decimal value\n"
1411 "Configure OSPF area as stub\n")
1413 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1414 int idx_ipv4_number
= 1;
1415 struct in_addr area_id
;
1418 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1419 argv
[idx_ipv4_number
]->arg
);
1421 ret
= ospf_area_stub_set(ospf
, area_id
);
1422 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1426 "First deconfigure all virtual link through this area\n");
1427 return CMD_WARNING_CONFIG_FAILED
;
1430 ospf_area_no_summary_unset(ospf
, area_id
);
1435 DEFUN (ospf_area_stub_no_summary
,
1436 ospf_area_stub_no_summary_cmd
,
1437 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1438 "OSPF stub parameters\n"
1439 "OSPF area ID in IP address format\n"
1440 "OSPF area ID as a decimal value\n"
1441 "Configure OSPF area as stub\n"
1442 "Do not inject inter-area routes into stub\n")
1444 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1445 int idx_ipv4_number
= 1;
1446 struct in_addr area_id
;
1449 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1450 argv
[idx_ipv4_number
]->arg
);
1452 ret
= ospf_area_stub_set(ospf
, area_id
);
1453 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1457 "%% Area cannot be stub as it contains a virtual link\n");
1458 return CMD_WARNING_CONFIG_FAILED
;
1461 ospf_area_no_summary_set(ospf
, area_id
);
1466 DEFUN (no_ospf_area_stub
,
1467 no_ospf_area_stub_cmd
,
1468 "no area <A.B.C.D|(0-4294967295)> stub",
1470 "OSPF area parameters\n"
1471 "OSPF area ID in IP address format\n"
1472 "OSPF area ID as a decimal value\n"
1473 "Configure OSPF area as stub\n")
1475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1476 int idx_ipv4_number
= 2;
1477 struct in_addr area_id
;
1480 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1481 argv
[idx_ipv4_number
]->arg
);
1483 ospf_area_stub_unset(ospf
, area_id
);
1484 ospf_area_no_summary_unset(ospf
, area_id
);
1489 DEFUN (no_ospf_area_stub_no_summary
,
1490 no_ospf_area_stub_no_summary_cmd
,
1491 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1493 "OSPF area parameters\n"
1494 "OSPF area ID in IP address format\n"
1495 "OSPF area ID as a decimal value\n"
1496 "Configure OSPF area as stub\n"
1497 "Do not inject inter-area routes into area\n")
1499 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1500 int idx_ipv4_number
= 2;
1501 struct in_addr area_id
;
1504 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1505 argv
[idx_ipv4_number
]->arg
);
1506 ospf_area_no_summary_unset(ospf
, area_id
);
1511 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1512 struct cmd_token
**argv
, int cfg_nosum
,
1515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1516 struct in_addr area_id
;
1519 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1521 ret
= ospf_area_nssa_set(ospf
, area_id
);
1522 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1526 "%% Area cannot be nssa as it contains a virtual link\n");
1527 return CMD_WARNING_CONFIG_FAILED
;
1531 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1532 ospf_area_nssa_translator_role_set(
1533 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1534 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1535 ospf_area_nssa_translator_role_set(
1536 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1537 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1538 ospf_area_nssa_translator_role_set(
1539 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1541 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1542 OSPF_NSSA_ROLE_CANDIDATE
);
1547 ospf_area_no_summary_set(ospf
, area_id
);
1549 ospf_area_no_summary_unset(ospf
, area_id
);
1552 ospf_schedule_abr_task(ospf
);
1558 DEFUN (ospf_area_nssa_translate
,
1559 ospf_area_nssa_translate_cmd
,
1560 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1561 "OSPF area parameters\n"
1562 "OSPF area ID in IP address format\n"
1563 "OSPF area ID as a decimal value\n"
1564 "Configure OSPF area as nssa\n"
1565 "Configure NSSA-ABR for translate election (default)\n"
1566 "Configure NSSA-ABR to never translate\n"
1567 "Configure NSSA-ABR to always translate\n")
1569 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1572 DEFUN (ospf_area_nssa
,
1574 "area <A.B.C.D|(0-4294967295)> nssa",
1575 "OSPF area parameters\n"
1576 "OSPF area ID in IP address format\n"
1577 "OSPF area ID as a decimal value\n"
1578 "Configure OSPF area as nssa\n")
1580 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1583 DEFUN (ospf_area_nssa_no_summary
,
1584 ospf_area_nssa_no_summary_cmd
,
1585 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1586 "OSPF area parameters\n"
1587 "OSPF area ID in IP address format\n"
1588 "OSPF area ID as a decimal value\n"
1589 "Configure OSPF area as nssa\n"
1590 "Do not inject inter-area routes into nssa\n")
1592 int idx_ipv4_number
= 1;
1593 struct in_addr area_id
;
1596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1597 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1598 argv
[idx_ipv4_number
]->arg
);
1600 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1602 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1604 ospf_schedule_abr_task(ospf
);
1609 DEFUN (no_ospf_area_nssa_no_summary
,
1610 no_ospf_area_nssa_no_summary_cmd
,
1611 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1613 "OSPF area parameters\n"
1614 "OSPF area ID in IP address format\n"
1615 "OSPF area ID as a decimal value\n"
1616 "Configure OSPF area as nssa\n"
1617 "Do not inject inter-area routes into nssa\n")
1619 int idx_ipv4_number
= 2;
1620 struct in_addr area_id
;
1623 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1625 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1626 argv
[idx_ipv4_number
]->arg
);
1628 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1630 ospf_area_no_summary_unset(ospf
, area_id
);
1632 ospf_schedule_abr_task(ospf
);
1637 DEFUN (no_ospf_area_nssa
,
1638 no_ospf_area_nssa_cmd
,
1639 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1641 "OSPF area parameters\n"
1642 "OSPF area ID in IP address format\n"
1643 "OSPF area ID as a decimal value\n"
1644 "Configure OSPF area as nssa\n"
1645 "Configure NSSA-ABR for translate election (default)\n"
1646 "Configure NSSA-ABR to never translate\n"
1647 "Configure NSSA-ABR to always translate\n")
1649 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1650 int idx_ipv4_number
= 2;
1651 struct in_addr area_id
;
1654 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1655 argv
[idx_ipv4_number
]->arg
);
1657 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1659 ospf_schedule_abr_task(ospf
);
1665 DEFUN (ospf_area_default_cost
,
1666 ospf_area_default_cost_cmd
,
1667 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1668 "OSPF area parameters\n"
1669 "OSPF area ID in IP address format\n"
1670 "OSPF area ID as a decimal value\n"
1671 "Set the summary-default cost of a NSSA or stub area\n"
1672 "Stub's advertised default summary cost\n")
1674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1675 int idx_ipv4_number
= 1;
1677 struct ospf_area
*area
;
1678 struct in_addr area_id
;
1681 struct prefix_ipv4 p
;
1683 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1684 argv
[idx_ipv4_number
]->arg
);
1685 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1687 area
= ospf_area_get(ospf
, area_id
);
1688 ospf_area_display_format_set(ospf
, area
, format
);
1690 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1691 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1692 return CMD_WARNING_CONFIG_FAILED
;
1695 area
->default_cost
= cost
;
1698 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1700 if (IS_DEBUG_OSPF_EVENT
)
1702 "ospf_abr_announce_stub_defaults(): "
1703 "announcing 0.0.0.0/0 to area %s",
1704 inet_ntoa(area
->area_id
));
1705 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1710 DEFUN (no_ospf_area_default_cost
,
1711 no_ospf_area_default_cost_cmd
,
1712 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1714 "OSPF area parameters\n"
1715 "OSPF area ID in IP address format\n"
1716 "OSPF area ID as a decimal value\n"
1717 "Set the summary-default cost of a NSSA or stub area\n"
1718 "Stub's advertised default summary cost\n")
1720 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1721 int idx_ipv4_number
= 2;
1722 struct ospf_area
*area
;
1723 struct in_addr area_id
;
1725 struct prefix_ipv4 p
;
1727 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1728 argv
[idx_ipv4_number
]->arg
);
1730 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1734 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1735 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1736 return CMD_WARNING_CONFIG_FAILED
;
1739 area
->default_cost
= 1;
1742 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1744 if (IS_DEBUG_OSPF_EVENT
)
1746 "ospf_abr_announce_stub_defaults(): "
1747 "announcing 0.0.0.0/0 to area %s",
1748 inet_ntoa(area
->area_id
));
1749 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1752 ospf_area_check_free(ospf
, area_id
);
1757 DEFUN (ospf_area_export_list
,
1758 ospf_area_export_list_cmd
,
1759 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1760 "OSPF area parameters\n"
1761 "OSPF area ID in IP address format\n"
1762 "OSPF area ID as a decimal value\n"
1763 "Set the filter for networks announced to other areas\n"
1764 "Name of the access-list\n")
1766 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1767 int idx_ipv4_number
= 1;
1768 struct ospf_area
*area
;
1769 struct in_addr area_id
;
1772 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1774 area
= ospf_area_get(ospf
, area_id
);
1775 ospf_area_display_format_set(ospf
, area
, format
);
1776 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1781 DEFUN (no_ospf_area_export_list
,
1782 no_ospf_area_export_list_cmd
,
1783 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1785 "OSPF area parameters\n"
1786 "OSPF area ID in IP address format\n"
1787 "OSPF area ID as a decimal value\n"
1788 "Unset the filter for networks announced to other areas\n"
1789 "Name of the access-list\n")
1791 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1792 int idx_ipv4_number
= 2;
1793 struct ospf_area
*area
;
1794 struct in_addr area_id
;
1797 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1799 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1803 ospf_area_export_list_unset(ospf
, area
);
1809 DEFUN (ospf_area_import_list
,
1810 ospf_area_import_list_cmd
,
1811 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1812 "OSPF area parameters\n"
1813 "OSPF area ID in IP address format\n"
1814 "OSPF area ID as a decimal value\n"
1815 "Set the filter for networks from other areas announced to the specified one\n"
1816 "Name of the access-list\n")
1818 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1819 int idx_ipv4_number
= 1;
1820 struct ospf_area
*area
;
1821 struct in_addr area_id
;
1824 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1826 area
= ospf_area_get(ospf
, area_id
);
1827 ospf_area_display_format_set(ospf
, area
, format
);
1828 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1833 DEFUN (no_ospf_area_import_list
,
1834 no_ospf_area_import_list_cmd
,
1835 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1837 "OSPF area parameters\n"
1838 "OSPF area ID in IP address format\n"
1839 "OSPF area ID as a decimal value\n"
1840 "Unset the filter for networks announced to other areas\n"
1841 "Name of the access-list\n")
1843 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1844 int idx_ipv4_number
= 2;
1845 struct ospf_area
*area
;
1846 struct in_addr area_id
;
1849 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1851 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1855 ospf_area_import_list_unset(ospf
, area
);
1860 DEFUN (ospf_area_filter_list
,
1861 ospf_area_filter_list_cmd
,
1862 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1863 "OSPF area parameters\n"
1864 "OSPF area ID in IP address format\n"
1865 "OSPF area ID as a decimal value\n"
1866 "Filter networks between OSPF areas\n"
1867 "Filter prefixes between OSPF areas\n"
1868 "Name of an IP prefix-list\n"
1869 "Filter networks sent to this area\n"
1870 "Filter networks sent from this area\n")
1872 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1873 int idx_ipv4_number
= 1;
1876 struct ospf_area
*area
;
1877 struct in_addr area_id
;
1878 struct prefix_list
*plist
;
1881 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1883 area
= ospf_area_get(ospf
, area_id
);
1884 ospf_area_display_format_set(ospf
, area
, format
);
1885 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1886 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1887 PREFIX_LIST_IN(area
) = plist
;
1888 if (PREFIX_NAME_IN(area
))
1889 free(PREFIX_NAME_IN(area
));
1891 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1892 ospf_schedule_abr_task(ospf
);
1894 PREFIX_LIST_OUT(area
) = plist
;
1895 if (PREFIX_NAME_OUT(area
))
1896 free(PREFIX_NAME_OUT(area
));
1898 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1899 ospf_schedule_abr_task(ospf
);
1905 DEFUN (no_ospf_area_filter_list
,
1906 no_ospf_area_filter_list_cmd
,
1907 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1909 "OSPF area parameters\n"
1910 "OSPF area ID in IP address format\n"
1911 "OSPF area ID as a decimal value\n"
1912 "Filter networks between OSPF areas\n"
1913 "Filter prefixes between OSPF areas\n"
1914 "Name of an IP prefix-list\n"
1915 "Filter networks sent to this area\n"
1916 "Filter networks sent from this area\n")
1918 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1919 int idx_ipv4_number
= 2;
1922 struct ospf_area
*area
;
1923 struct in_addr area_id
;
1926 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1928 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1931 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1932 if (PREFIX_NAME_IN(area
))
1933 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1937 PREFIX_LIST_IN(area
) = NULL
;
1938 if (PREFIX_NAME_IN(area
))
1939 free(PREFIX_NAME_IN(area
));
1941 PREFIX_NAME_IN(area
) = NULL
;
1943 ospf_schedule_abr_task(ospf
);
1945 if (PREFIX_NAME_OUT(area
))
1946 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1950 PREFIX_LIST_OUT(area
) = NULL
;
1951 if (PREFIX_NAME_OUT(area
))
1952 free(PREFIX_NAME_OUT(area
));
1954 PREFIX_NAME_OUT(area
) = NULL
;
1956 ospf_schedule_abr_task(ospf
);
1963 DEFUN (ospf_area_authentication_message_digest
,
1964 ospf_area_authentication_message_digest_cmd
,
1965 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1967 "OSPF area parameters\n"
1968 "OSPF area ID in IP address format\n"
1969 "OSPF area ID as a decimal value\n"
1970 "Enable authentication\n"
1971 "Use message-digest authentication\n")
1973 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1975 struct ospf_area
*area
;
1976 struct in_addr area_id
;
1979 argv_find(argv
, argc
, "area", &idx
);
1980 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1982 area
= ospf_area_get(ospf
, area_id
);
1983 ospf_area_display_format_set(ospf
, area
, format
);
1984 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1986 : OSPF_AUTH_CRYPTOGRAPHIC
;
1991 DEFUN (ospf_area_authentication
,
1992 ospf_area_authentication_cmd
,
1993 "area <A.B.C.D|(0-4294967295)> authentication",
1994 "OSPF area parameters\n"
1995 "OSPF area ID in IP address format\n"
1996 "OSPF area ID as a decimal value\n"
1997 "Enable authentication\n")
1999 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2000 int idx_ipv4_number
= 1;
2001 struct ospf_area
*area
;
2002 struct in_addr area_id
;
2005 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2007 area
= ospf_area_get(ospf
, area_id
);
2008 ospf_area_display_format_set(ospf
, area
, format
);
2009 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2014 DEFUN (no_ospf_area_authentication
,
2015 no_ospf_area_authentication_cmd
,
2016 "no area <A.B.C.D|(0-4294967295)> authentication",
2018 "OSPF area parameters\n"
2019 "OSPF area ID in IP address format\n"
2020 "OSPF area ID as a decimal value\n"
2021 "Enable authentication\n")
2023 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2024 int idx_ipv4_number
= 2;
2025 struct ospf_area
*area
;
2026 struct in_addr area_id
;
2029 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2031 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2035 area
->auth_type
= OSPF_AUTH_NULL
;
2037 ospf_area_check_free(ospf
, area_id
);
2043 DEFUN (ospf_abr_type
,
2045 "ospf abr-type <cisco|ibm|shortcut|standard>",
2046 "OSPF specific commands\n"
2047 "Set OSPF ABR type\n"
2048 "Alternative ABR, cisco implementation\n"
2049 "Alternative ABR, IBM implementation\n"
2051 "Standard behavior (RFC2328)\n")
2053 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2055 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2057 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2058 abr_type
= OSPF_ABR_CISCO
;
2059 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2060 abr_type
= OSPF_ABR_IBM
;
2061 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2062 abr_type
= OSPF_ABR_SHORTCUT
;
2063 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2064 abr_type
= OSPF_ABR_STAND
;
2066 return CMD_WARNING_CONFIG_FAILED
;
2068 /* If ABR type value is changed, schedule ABR task. */
2069 if (ospf
->abr_type
!= abr_type
) {
2070 ospf
->abr_type
= abr_type
;
2071 ospf_schedule_abr_task(ospf
);
2077 DEFUN (no_ospf_abr_type
,
2078 no_ospf_abr_type_cmd
,
2079 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2081 "OSPF specific commands\n"
2082 "Set OSPF ABR type\n"
2083 "Alternative ABR, cisco implementation\n"
2084 "Alternative ABR, IBM implementation\n"
2088 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2090 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2092 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2093 abr_type
= OSPF_ABR_CISCO
;
2094 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2095 abr_type
= OSPF_ABR_IBM
;
2096 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2097 abr_type
= OSPF_ABR_SHORTCUT
;
2098 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2099 abr_type
= OSPF_ABR_STAND
;
2101 return CMD_WARNING_CONFIG_FAILED
;
2103 /* If ABR type value is changed, schedule ABR task. */
2104 if (ospf
->abr_type
== abr_type
) {
2105 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2106 ospf_schedule_abr_task(ospf
);
2112 DEFUN (ospf_log_adjacency_changes
,
2113 ospf_log_adjacency_changes_cmd
,
2114 "log-adjacency-changes",
2115 "Log changes in adjacency state\n")
2117 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2119 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2120 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2124 DEFUN (ospf_log_adjacency_changes_detail
,
2125 ospf_log_adjacency_changes_detail_cmd
,
2126 "log-adjacency-changes detail",
2127 "Log changes in adjacency state\n"
2128 "Log all state changes\n")
2130 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2132 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2133 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2137 DEFUN (no_ospf_log_adjacency_changes
,
2138 no_ospf_log_adjacency_changes_cmd
,
2139 "no log-adjacency-changes",
2141 "Log changes in adjacency state\n")
2143 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2145 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2146 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2150 DEFUN (no_ospf_log_adjacency_changes_detail
,
2151 no_ospf_log_adjacency_changes_detail_cmd
,
2152 "no log-adjacency-changes detail",
2154 "Log changes in adjacency state\n"
2155 "Log all state changes\n")
2157 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2159 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2163 DEFUN (ospf_compatible_rfc1583
,
2164 ospf_compatible_rfc1583_cmd
,
2165 "compatible rfc1583",
2166 "OSPF compatibility list\n"
2167 "compatible with RFC 1583\n")
2169 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2171 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2172 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2173 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2178 DEFUN (no_ospf_compatible_rfc1583
,
2179 no_ospf_compatible_rfc1583_cmd
,
2180 "no compatible rfc1583",
2182 "OSPF compatibility list\n"
2183 "compatible with RFC 1583\n")
2185 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2187 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2188 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2189 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2194 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2195 "ospf rfc1583compatibility",
2196 "OSPF specific commands\n"
2197 "Enable the RFC1583Compatibility flag\n")
2199 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2200 "no ospf rfc1583compatibility", NO_STR
2201 "OSPF specific commands\n"
2202 "Disable the RFC1583Compatibility flag\n")
2204 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2205 unsigned int hold
, unsigned int max
)
2207 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2209 ospf
->spf_delay
= delay
;
2210 ospf
->spf_holdtime
= hold
;
2211 ospf
->spf_max_holdtime
= max
;
2216 DEFUN (ospf_timers_min_ls_interval
,
2217 ospf_timers_min_ls_interval_cmd
,
2218 "timers throttle lsa all (0-5000)",
2219 "Adjust routing timers\n"
2220 "Throttling adaptive timer\n"
2221 "LSA delay between transmissions\n"
2223 "Delay (msec) between sending LSAs\n")
2225 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2227 unsigned int interval
;
2230 vty_out(vty
, "Insufficient arguments\n");
2231 return CMD_WARNING_CONFIG_FAILED
;
2234 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2236 ospf
->min_ls_interval
= interval
;
2241 DEFUN (no_ospf_timers_min_ls_interval
,
2242 no_ospf_timers_min_ls_interval_cmd
,
2243 "no timers throttle lsa all [(0-5000)]",
2245 "Adjust routing timers\n"
2246 "Throttling adaptive timer\n"
2247 "LSA delay between transmissions\n"
2249 "Delay (msec) between sending LSAs\n")
2251 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2252 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2257 DEFUN (ospf_timers_throttle_spf
,
2258 ospf_timers_throttle_spf_cmd
,
2259 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2260 "Adjust routing timers\n"
2261 "Throttling adaptive timer\n"
2263 "Delay (msec) from first change received till SPF calculation\n"
2264 "Initial hold time (msec) between consecutive SPF calculations\n"
2265 "Maximum hold time (msec)\n")
2268 int idx_number_2
= 4;
2269 int idx_number_3
= 5;
2270 unsigned int delay
, hold
, max
;
2273 vty_out(vty
, "Insufficient arguments\n");
2274 return CMD_WARNING_CONFIG_FAILED
;
2277 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2278 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2279 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2281 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2284 DEFUN (no_ospf_timers_throttle_spf
,
2285 no_ospf_timers_throttle_spf_cmd
,
2286 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2288 "Adjust routing timers\n"
2289 "Throttling adaptive timer\n"
2291 "Delay (msec) from first change received till SPF calculation\n"
2292 "Initial hold time (msec) between consecutive SPF calculations\n"
2293 "Maximum hold time (msec)\n")
2295 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2296 OSPF_SPF_HOLDTIME_DEFAULT
,
2297 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2301 DEFUN (ospf_timers_lsa_min_arrival
,
2302 ospf_timers_lsa_min_arrival_cmd
,
2303 "timers lsa min-arrival (0-600000)",
2304 "Adjust routing timers\n"
2306 "Minimum delay in receiving new version of a LSA\n"
2307 "Delay in milliseconds\n")
2309 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2310 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2314 DEFUN (no_ospf_timers_lsa_min_arrival
,
2315 no_ospf_timers_lsa_min_arrival_cmd
,
2316 "no timers lsa min-arrival [(0-600000)]",
2318 "Adjust routing timers\n"
2320 "Minimum delay in receiving new version of a LSA\n"
2321 "Delay in milliseconds\n")
2323 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2324 unsigned int minarrival
;
2327 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2329 if (ospf
->min_ls_arrival
!= minarrival
2330 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2334 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2339 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
2340 CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08")
2342 ALIAS_HIDDEN(ospf_timers_lsa_min_arrival
, ospf_timers_lsa_arrival_cmd
,
2343 "timers lsa arrival (0-1000)",
2344 "adjust routing timers\n"
2345 "throttling link state advertisement delays\n"
2346 "ospf minimum arrival interval delay\n"
2347 "delay (msec) between accepted lsas\n");
2349 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
2350 CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08")
2352 ALIAS_HIDDEN(no_ospf_timers_lsa_min_arrival
, no_ospf_timers_lsa_arrival_cmd
,
2353 "no timers lsa arrival (0-1000)", NO_STR
2354 "adjust routing timers\n"
2355 "throttling link state advertisement delays\n"
2356 "ospf minimum arrival interval delay\n"
2357 "delay (msec) between accepted lsas\n");
2360 DEFUN (ospf_neighbor
,
2362 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2364 "Neighbor IP address\n"
2365 "Neighbor Priority\n"
2367 "Dead Neighbor Polling interval\n"
2370 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2374 struct in_addr nbr_addr
;
2375 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2376 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2378 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2379 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2380 return CMD_WARNING_CONFIG_FAILED
;
2384 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2387 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2389 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2392 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2395 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2400 DEFUN (ospf_neighbor_poll_interval
,
2401 ospf_neighbor_poll_interval_cmd
,
2402 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2404 "Neighbor IP address\n"
2405 "Dead Neighbor Polling interval\n"
2407 "OSPF priority of non-broadcast neighbor\n"
2410 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2414 struct in_addr nbr_addr
;
2415 unsigned int priority
;
2416 unsigned int interval
;
2418 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2419 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2420 return CMD_WARNING_CONFIG_FAILED
;
2423 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2425 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2426 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2428 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2429 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2432 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2437 DEFUN (no_ospf_neighbor
,
2438 no_ospf_neighbor_cmd
,
2439 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2442 "Neighbor IP address\n"
2443 "Neighbor Priority\n"
2445 "Dead Neighbor Polling interval\n"
2448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2450 struct in_addr nbr_addr
;
2452 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2453 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2454 return CMD_WARNING_CONFIG_FAILED
;
2457 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2462 DEFUN (no_ospf_neighbor_poll
,
2463 no_ospf_neighbor_poll_cmd
,
2464 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2467 "Neighbor IP address\n"
2468 "Dead Neighbor Polling interval\n"
2470 "Neighbor Priority\n"
2473 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2475 struct in_addr nbr_addr
;
2477 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2478 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2479 return CMD_WARNING_CONFIG_FAILED
;
2482 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2487 DEFUN (ospf_refresh_timer
,
2488 ospf_refresh_timer_cmd
,
2489 "refresh timer (10-1800)",
2490 "Adjust refresh parameters\n"
2491 "Set refresh timer\n"
2492 "Timer value in seconds\n")
2494 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2496 unsigned int interval
;
2498 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2499 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2500 * OSPF_LSA_REFRESHER_GRANULARITY
;
2502 ospf_timers_refresh_set(ospf
, interval
);
2507 DEFUN (no_ospf_refresh_timer
,
2508 no_ospf_refresh_timer_val_cmd
,
2509 "no refresh timer [(10-1800)]",
2511 "Adjust refresh parameters\n"
2512 "Unset refresh timer\n"
2513 "Timer value in seconds\n")
2515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2517 unsigned int interval
;
2520 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2522 if (ospf
->lsa_refresh_interval
!= interval
2523 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2527 ospf_timers_refresh_unset(ospf
);
2533 DEFUN (ospf_auto_cost_reference_bandwidth
,
2534 ospf_auto_cost_reference_bandwidth_cmd
,
2535 "auto-cost reference-bandwidth (1-4294967)",
2536 "Calculate OSPF interface cost according to bandwidth\n"
2537 "Use reference bandwidth method to assign OSPF cost\n"
2538 "The reference bandwidth in terms of Mbits per second\n")
2540 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2541 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2544 struct interface
*ifp
;
2546 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2547 if (refbw
< 1 || refbw
> 4294967) {
2548 vty_out(vty
, "reference-bandwidth value is invalid\n");
2549 return CMD_WARNING_CONFIG_FAILED
;
2552 /* If reference bandwidth is changed. */
2553 if ((refbw
) == ospf
->ref_bandwidth
)
2556 ospf
->ref_bandwidth
= refbw
;
2557 FOR_ALL_INTERFACES (vrf
, ifp
)
2558 ospf_if_recalculate_output_cost(ifp
);
2563 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2564 no_ospf_auto_cost_reference_bandwidth_cmd
,
2565 "no auto-cost reference-bandwidth [(1-4294967)]",
2567 "Calculate OSPF interface cost according to bandwidth\n"
2568 "Use reference bandwidth method to assign OSPF cost\n"
2569 "The reference bandwidth in terms of Mbits per second\n")
2571 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2572 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2573 struct interface
*ifp
;
2575 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2578 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2579 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2581 " Please ensure reference bandwidth is consistent across all routers\n");
2583 FOR_ALL_INTERFACES (vrf
, ifp
)
2584 ospf_if_recalculate_output_cost(ifp
);
2589 DEFUN (ospf_write_multiplier
,
2590 ospf_write_multiplier_cmd
,
2591 "ospf write-multiplier (1-100)",
2592 "OSPF specific commands\n"
2593 "Write multiplier\n"
2594 "Maximum number of interface serviced per write\n")
2596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2598 uint32_t write_oi_count
;
2605 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2606 if (write_oi_count
< 1 || write_oi_count
> 100) {
2607 vty_out(vty
, "write-multiplier value is invalid\n");
2608 return CMD_WARNING_CONFIG_FAILED
;
2611 ospf
->write_oi_count
= write_oi_count
;
2615 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2616 "Write multiplier\n"
2617 "Maximum number of interface serviced per write\n")
2619 DEFUN (no_ospf_write_multiplier
,
2620 no_ospf_write_multiplier_cmd
,
2621 "no ospf write-multiplier (1-100)",
2623 "OSPF specific commands\n"
2624 "Write multiplier\n"
2625 "Maximum number of interface serviced per write\n")
2627 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2629 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2633 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2634 "no write-multiplier (1-100)", NO_STR
2635 "Write multiplier\n"
2636 "Maximum number of interface serviced per write\n")
2638 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2639 "Alternative IBM", "Alternative Cisco",
2640 "Alternative Shortcut"};
2642 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2644 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2645 json_object
*json_areas
, uint8_t use_json
)
2647 json_object
*json_area
= NULL
;
2650 json_area
= json_object_new_object();
2654 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2656 /* Show Area type/mode. */
2657 if (OSPF_IS_AREA_BACKBONE(area
)) {
2659 json_object_boolean_true_add(json_area
, "backbone");
2661 vty_out(vty
, " (Backbone)\n");
2664 if (area
->external_routing
== OSPF_AREA_STUB
) {
2665 if (area
->no_summary
)
2666 json_object_boolean_true_add(
2667 json_area
, "stubNoSummary");
2668 if (area
->shortcut_configured
)
2669 json_object_boolean_true_add(
2670 json_area
, "stubShortcut");
2671 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2672 if (area
->no_summary
)
2673 json_object_boolean_true_add(
2674 json_area
, "nssaNoSummary");
2675 if (area
->shortcut_configured
)
2676 json_object_boolean_true_add(
2677 json_area
, "nssaShortcut");
2680 json_object_string_add(
2681 json_area
, "shortcuttingMode",
2682 ospf_shortcut_mode_descr_str
2683 [area
->shortcut_configured
]);
2684 if (area
->shortcut_capability
)
2685 json_object_boolean_true_add(json_area
,
2688 if (area
->external_routing
== OSPF_AREA_STUB
)
2689 vty_out(vty
, " (Stub%s%s)",
2690 area
->no_summary
? ", no summary" : "",
2691 area
->shortcut_configured
? "; " : "");
2692 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2693 vty_out(vty
, " (NSSA%s%s)",
2694 area
->no_summary
? ", no summary" : "",
2695 area
->shortcut_configured
? "; " : "");
2698 vty_out(vty
, " Shortcutting mode: %s",
2699 ospf_shortcut_mode_descr_str
2700 [area
->shortcut_configured
]);
2701 vty_out(vty
, ", S-bit consensus: %s\n",
2702 area
->shortcut_capability
? "ok" : "no");
2706 /* Show number of interfaces */
2708 json_object_int_add(json_area
, "areaIfTotalCounter",
2709 listcount(area
->oiflist
));
2710 json_object_int_add(json_area
, "areaIfActiveCounter",
2714 " Number of interfaces in this area: Total: %d, "
2716 listcount(area
->oiflist
), area
->act_ints
);
2718 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2720 json_object_boolean_true_add(json_area
, "nssa");
2721 if (!IS_OSPF_ABR(area
->ospf
))
2722 json_object_boolean_false_add(json_area
, "abr");
2723 else if (area
->NSSATranslatorState
) {
2724 json_object_boolean_true_add(json_area
, "abr");
2725 if (area
->NSSATranslatorRole
2726 == OSPF_NSSA_ROLE_CANDIDATE
)
2727 json_object_boolean_true_add(
2729 "nssaTranslatorElected");
2730 else if (area
->NSSATranslatorRole
2731 == OSPF_NSSA_ROLE_ALWAYS
)
2732 json_object_boolean_true_add(
2734 "nssaTranslatorAlways");
2736 json_object_boolean_true_add(json_area
, "abr");
2737 if (area
->NSSATranslatorRole
2738 == OSPF_NSSA_ROLE_CANDIDATE
)
2739 json_object_boolean_false_add(
2741 "nssaTranslatorElected");
2743 json_object_boolean_true_add(
2745 "nssaTranslatorNever");
2749 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2750 if (!IS_OSPF_ABR(area
->ospf
))
2752 " It is not ABR, therefore not Translator. \n");
2753 else if (area
->NSSATranslatorState
) {
2754 vty_out(vty
, " We are an ABR and ");
2755 if (area
->NSSATranslatorRole
2756 == OSPF_NSSA_ROLE_CANDIDATE
)
2758 "the NSSA Elected Translator. \n");
2759 else if (area
->NSSATranslatorRole
2760 == OSPF_NSSA_ROLE_ALWAYS
)
2762 "always an NSSA Translator. \n");
2764 vty_out(vty
, " We are an ABR, but ");
2765 if (area
->NSSATranslatorRole
2766 == OSPF_NSSA_ROLE_CANDIDATE
)
2768 "not the NSSA Elected Translator. \n");
2771 "never an NSSA Translator. \n");
2776 /* Stub-router state for this area */
2777 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2778 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2781 json_object_boolean_true_add(
2782 json_area
, "originStubMaxDistRouterLsa");
2783 if (CHECK_FLAG(area
->stub_router_state
,
2784 OSPF_AREA_ADMIN_STUB_ROUTED
))
2785 json_object_boolean_true_add(
2786 json_area
, "indefiniteActiveAdmin");
2787 if (area
->t_stub_router
) {
2791 &area
->t_stub_router
->u
.sands
,
2794 json_object_int_add(
2796 "activeStartupRemainderMsecs",
2801 " Originating stub / maximum-distance Router-LSA\n");
2802 if (CHECK_FLAG(area
->stub_router_state
,
2803 OSPF_AREA_ADMIN_STUB_ROUTED
))
2805 " Administratively activated (indefinitely)\n");
2806 if (area
->t_stub_router
)
2808 " Active from startup, %s remaining\n",
2809 ospf_timer_dump(area
->t_stub_router
,
2816 /* Show number of fully adjacent neighbors. */
2817 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2820 /* Show authentication type. */
2821 if (area
->auth_type
== OSPF_AUTH_NULL
)
2822 json_object_string_add(json_area
, "authentication",
2823 "authenticationNone");
2824 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2825 json_object_string_add(json_area
, "authentication",
2826 "authenticationSimplePassword");
2827 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2828 json_object_string_add(json_area
, "authentication",
2829 "authenticationMessageDigest");
2831 if (!OSPF_IS_AREA_BACKBONE(area
))
2832 json_object_int_add(json_area
,
2833 "virtualAdjacenciesPassingCounter",
2836 /* Show SPF calculation times. */
2837 json_object_int_add(json_area
, "spfExecutedCounter",
2838 area
->spf_calculation
);
2839 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2840 json_object_int_add(
2841 json_area
, "lsaRouterNumber",
2842 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaRouterChecksum",
2845 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaNetworkNumber",
2848 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2849 json_object_int_add(
2850 json_area
, "lsaNetworkChecksum",
2851 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2852 json_object_int_add(
2853 json_area
, "lsaSummaryNumber",
2854 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2855 json_object_int_add(
2856 json_area
, "lsaSummaryChecksum",
2857 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2858 json_object_int_add(
2859 json_area
, "lsaAsbrNumber",
2860 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2861 json_object_int_add(
2862 json_area
, "lsaAsbrChecksum",
2863 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2864 json_object_int_add(
2865 json_area
, "lsaNssaNumber",
2866 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2867 json_object_int_add(
2868 json_area
, "lsaNssaChecksum",
2869 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2871 /* Show number of fully adjacent neighbors. */
2873 " Number of fully adjacent neighbors in this area:"
2877 /* Show authentication type. */
2878 vty_out(vty
, " Area has ");
2879 if (area
->auth_type
== OSPF_AUTH_NULL
)
2880 vty_out(vty
, "no authentication\n");
2881 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2882 vty_out(vty
, "simple password authentication\n");
2883 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2884 vty_out(vty
, "message digest authentication\n");
2886 if (!OSPF_IS_AREA_BACKBONE(area
))
2888 " Number of full virtual adjacencies going through"
2892 /* Show SPF calculation times. */
2893 vty_out(vty
, " SPF algorithm executed %d times\n",
2894 area
->spf_calculation
);
2896 /* Show number of LSA. */
2897 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2899 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2900 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2901 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2903 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2904 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2905 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2907 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2908 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2909 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2911 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2912 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2913 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2914 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2915 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2916 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2920 json_object_int_add(
2921 json_area
, "lsaOpaqueLinkNumber",
2922 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2923 json_object_int_add(
2924 json_area
, "lsaOpaqueLinkChecksum",
2925 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2926 json_object_int_add(
2927 json_area
, "lsaOpaqueAreaNumber",
2928 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2929 json_object_int_add(
2930 json_area
, "lsaOpaqueAreaChecksum",
2931 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2934 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2935 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2936 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2938 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2939 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2940 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2944 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2950 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2951 json_object
*json
, uint8_t use_vrf
)
2953 struct listnode
*node
, *nnode
;
2954 struct ospf_area
*area
;
2955 struct timeval result
;
2956 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2957 json_object
*json_vrf
= NULL
;
2958 json_object
*json_areas
= NULL
;
2962 json_vrf
= json_object_new_object();
2965 json_areas
= json_object_new_object();
2968 if (ospf
->instance
) {
2970 json_object_int_add(json
, "ospfInstance",
2973 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2977 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2979 /* Show Router ID. */
2981 json_object_string_add(json_vrf
, "routerId",
2982 inet_ntoa(ospf
->router_id
));
2984 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2985 inet_ntoa(ospf
->router_id
));
2988 /* Graceful shutdown */
2989 if (ospf
->t_deferred_shutdown
) {
2994 &ospf
->t_deferred_shutdown
->u
.sands
,
2997 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3001 " Deferred shutdown in progress, %s remaining\n",
3002 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3003 timebuf
, sizeof(timebuf
)));
3007 /* Show capability. */
3009 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3010 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3011 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3012 json_object_boolean_true_add(json_vrf
,
3013 "rfc1583Compatibility");
3016 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3017 vty_out(vty
, " This implementation conforms to RFC2328\n");
3018 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3019 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3025 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3026 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3029 vty_out(vty
, " OpaqueCapability flag is %s\n",
3030 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3035 /* Show stub-router configuration */
3036 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3037 || ospf
->stub_router_shutdown_time
3038 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3040 json_object_boolean_true_add(json_vrf
,
3041 "stubAdvertisement");
3042 if (ospf
->stub_router_startup_time
3043 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3044 json_object_int_add(
3045 json_vrf
, "postStartEnabledMsecs",
3046 ospf
->stub_router_startup_time
/ 1000);
3047 if (ospf
->stub_router_shutdown_time
3048 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3049 json_object_int_add(
3050 json_vrf
, "preShutdownEnabledMsecs",
3051 ospf
->stub_router_shutdown_time
/ 1000);
3054 " Stub router advertisement is configured\n");
3055 if (ospf
->stub_router_startup_time
3056 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3058 " Enabled for %us after start-up\n",
3059 ospf
->stub_router_startup_time
);
3060 if (ospf
->stub_router_shutdown_time
3061 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3063 " Enabled for %us prior to full shutdown\n",
3064 ospf
->stub_router_shutdown_time
);
3068 /* Show SPF timers. */
3070 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3072 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3073 ospf
->spf_holdtime
);
3074 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3075 ospf
->spf_max_holdtime
);
3076 json_object_int_add(json_vrf
, "holdtimeMultplier",
3077 ospf
->spf_hold_multiplier
);
3080 " Initial SPF scheduling delay %d millisec(s)\n"
3081 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3082 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3083 " Hold time multiplier is currently %d\n",
3084 ospf
->spf_delay
, ospf
->spf_holdtime
,
3085 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3089 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3090 long time_store
= 0;
3093 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3094 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3097 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3098 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3099 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3102 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3104 vty_out(vty
, " SPF algorithm ");
3105 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3106 monotime_since(&ospf
->ts_spf
, &result
);
3107 vty_out(vty
, "last executed %s ago\n",
3108 ospf_timeval_dump(&result
, timebuf
,
3110 vty_out(vty
, " Last SPF duration %s\n",
3111 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3112 timebuf
, sizeof(timebuf
)));
3114 vty_out(vty
, "has not been run\n");
3118 if (ospf
->t_spf_calc
) {
3121 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3123 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3127 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3128 ospf
->min_ls_interval
);
3129 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3130 ospf
->min_ls_arrival
);
3131 /* Show write multiplier values */
3132 json_object_int_add(json_vrf
, "writeMultiplier",
3133 ospf
->write_oi_count
);
3134 /* Show refresh parameters. */
3135 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3136 ospf
->lsa_refresh_interval
* 1000);
3138 vty_out(vty
, " SPF timer %s%s\n",
3139 (ospf
->t_spf_calc
? "due in " : "is "),
3140 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3143 vty_out(vty
, " LSA minimum interval %d msecs\n",
3144 ospf
->min_ls_interval
);
3145 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3146 ospf
->min_ls_arrival
);
3148 /* Show write multiplier values */
3149 vty_out(vty
, " Write Multiplier set to %d \n",
3150 ospf
->write_oi_count
);
3152 /* Show refresh parameters. */
3153 vty_out(vty
, " Refresh timer %d secs\n",
3154 ospf
->lsa_refresh_interval
);
3157 /* Show ABR/ASBR flags. */
3158 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3160 json_object_string_add(
3161 json_vrf
, "abrType",
3162 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3165 " This router is an ABR, ABR type is: %s\n",
3166 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3168 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3170 json_object_string_add(
3171 json_vrf
, "asbrRouter",
3172 "injectingExternalRoutingInformation");
3175 " This router is an ASBR "
3176 "(injecting external routing information)\n");
3179 /* Show Number of AS-external-LSAs. */
3181 json_object_int_add(
3182 json_vrf
, "lsaExternalCounter",
3183 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3184 json_object_int_add(
3185 json_vrf
, "lsaExternalChecksum",
3186 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3189 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3190 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3191 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3195 json_object_int_add(
3196 json_vrf
, "lsaAsopaqueCounter",
3197 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3198 json_object_int_add(
3199 json_vrf
, "lsaAsOpaqueChecksum",
3200 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3203 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3204 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3205 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3208 /* Show number of areas attached. */
3210 json_object_int_add(json_vrf
, "attachedAreaCounter",
3211 listcount(ospf
->areas
));
3213 vty_out(vty
, " Number of areas attached to this router: %d\n",
3214 listcount(ospf
->areas
));
3216 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3217 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3219 json_object_boolean_true_add(
3220 json_vrf
, "adjacencyChangesLoggedAll");
3223 " All adjacency changes are logged\n");
3226 json_object_boolean_true_add(
3227 json_vrf
, "adjacencyChangesLogged");
3229 vty_out(vty
, " Adjacency changes are logged\n");
3232 /* Show each area status. */
3233 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3234 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3238 json_object_object_add(json_vrf
, "areas", json_areas
);
3239 if (ospf
->vrf_id
== VRF_DEFAULT
)
3240 json_object_object_add(json
, "default",
3243 json_object_object_add(json
, ospf
->name
,
3246 json_object_object_add(json
, "areas", json_areas
);
3254 DEFUN (show_ip_ospf
,
3256 "show ip ospf [vrf <NAME|all>] [json]",
3259 "OSPF information\n"
3265 uint8_t uj
= use_json(argc
, argv
);
3266 struct listnode
*node
= NULL
;
3267 char *vrf_name
= NULL
;
3268 bool all_vrf
= FALSE
;
3269 int ret
= CMD_SUCCESS
;
3272 json_object
*json
= NULL
;
3273 uint8_t use_vrf
= 0;
3275 if (listcount(om
->ospf
) == 0)
3278 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3281 json
= json_object_new_object();
3283 /* vrf input is provided could be all or specific vrf*/
3287 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3288 if (!ospf
->oi_running
)
3290 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3294 vty_out(vty
, "%s\n",
3295 json_object_to_json_string_ext(
3296 json
, JSON_C_TO_STRING_PRETTY
));
3297 json_object_free(json
);
3301 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3302 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3304 json_object_free(json
);
3308 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3309 /* Display default ospf (instance 0) info */
3310 if (ospf
== NULL
|| !ospf
->oi_running
) {
3312 json_object_free(json
);
3318 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3320 vty_out(vty
, "%s\n",
3321 json_object_to_json_string_ext(
3322 json
, JSON_C_TO_STRING_PRETTY
));
3326 json_object_free(json
);
3331 DEFUN (show_ip_ospf_instance
,
3332 show_ip_ospf_instance_cmd
,
3333 "show ip ospf (1-65535) [json]",
3336 "OSPF information\n"
3342 unsigned short instance
= 0;
3343 uint8_t uj
= use_json(argc
, argv
);
3344 int ret
= CMD_SUCCESS
;
3345 json_object
*json
= NULL
;
3347 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3348 ospf
= ospf_lookup_instance(instance
);
3350 return CMD_NOT_MY_INSTANCE
;
3352 if (!ospf
->oi_running
)
3356 json
= json_object_new_object();
3358 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3361 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3362 json
, JSON_C_TO_STRING_PRETTY
));
3363 json_object_free(json
);
3369 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3370 struct interface
*ifp
,
3371 json_object
*json_interface_sub
,
3375 struct ospf_neighbor
*nbr
;
3376 struct route_node
*rn
;
3377 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3379 /* Is interface up? */
3381 is_up
= if_is_operative(ifp
);
3383 json_object_boolean_true_add(json_interface_sub
,
3386 json_object_boolean_false_add(json_interface_sub
,
3389 json_object_int_add(json_interface_sub
, "ifIndex",
3391 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3392 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3394 json_object_string_add(json_interface_sub
, "ifFlags",
3395 if_flag_dump(ifp
->flags
));
3397 vty_out(vty
, "%s is %s\n", ifp
->name
,
3398 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3399 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3400 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3401 if_flag_dump(ifp
->flags
));
3404 /* Is interface OSPF enabled? */
3406 if (ospf_oi_count(ifp
) == 0) {
3407 json_object_boolean_false_add(json_interface_sub
,
3410 } else if (!is_up
) {
3411 json_object_boolean_false_add(json_interface_sub
,
3415 json_object_boolean_true_add(json_interface_sub
,
3418 if (ospf_oi_count(ifp
) == 0) {
3419 vty_out(vty
, " OSPF not enabled on this interface\n");
3421 } else if (!is_up
) {
3423 " OSPF is enabled, but not running on this interface\n");
3428 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3429 struct ospf_interface
*oi
= rn
->info
;
3434 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3436 json_object_boolean_true_add(json_interface_sub
,
3439 vty_out(vty
, " This interface is UNNUMBERED,");
3441 /* Show OSPF interface information. */
3443 json_object_string_add(
3444 json_interface_sub
, "ipAddress",
3445 inet_ntoa(oi
->address
->u
.prefix4
));
3446 json_object_int_add(json_interface_sub
,
3447 "ipAddressPrefixlen",
3448 oi
->address
->prefixlen
);
3450 vty_out(vty
, " Internet Address %s/%d,",
3451 inet_ntoa(oi
->address
->u
.prefix4
),
3452 oi
->address
->prefixlen
);
3454 if (oi
->connected
->destination
3455 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3456 struct in_addr
*dest
;
3459 if (CONNECTED_PEER(oi
->connected
)
3460 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3465 /* For Vlinks, showing the peer address is
3467 * * * * * informative than the local
3468 * interface that is being used
3470 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3471 dest
= &oi
->vl_data
->peer_addr
;
3473 dest
= &oi
->connected
->destination
->u
3477 json_object_string_add(
3479 "ospfIfType", dstr
);
3480 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3481 json_object_string_add(
3486 json_object_string_add(
3491 vty_out(vty
, " %s %s,", dstr
,
3496 json_object_string_add(json_interface_sub
, "area",
3497 ospf_area_desc_string(oi
->area
));
3498 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3499 json_object_boolean_true_add(
3501 "mtuMismatchDetect");
3502 json_object_string_add(json_interface_sub
, "routerId",
3503 inet_ntoa(ospf
->router_id
));
3504 json_object_string_add(json_interface_sub
,
3506 ospf_network_type_str
[oi
->type
]);
3507 json_object_int_add(json_interface_sub
, "cost",
3509 json_object_int_add(
3510 json_interface_sub
, "transmitDelayMsecs",
3511 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3512 json_object_string_add(json_interface_sub
, "state",
3513 lookup_msg(ospf_ism_state_msg
,
3515 json_object_int_add(json_interface_sub
, "priority",
3518 vty_out(vty
, " Area %s\n",
3519 ospf_area_desc_string(oi
->area
));
3521 vty_out(vty
, " MTU mismatch detection: %s\n",
3522 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3526 " Router ID %s, Network Type %s, Cost: %d\n",
3527 inet_ntoa(ospf
->router_id
),
3528 ospf_network_type_str
[oi
->type
],
3532 " Transmit Delay is %d sec, State %s, Priority %d\n",
3533 OSPF_IF_PARAM(oi
, transmit_delay
),
3534 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3538 /* Show DR information. */
3539 if (DR(oi
).s_addr
== 0) {
3542 " No backup designated router on this network\n");
3544 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3548 " No backup designated router on this network\n");
3551 json_object_string_add(
3552 json_interface_sub
, "bdrId",
3553 inet_ntoa(nbr
->router_id
));
3554 json_object_string_add(
3557 inet_ntoa(nbr
->address
.u
3561 " Backup Designated Router (ID) %s,",
3562 inet_ntoa(nbr
->router_id
));
3563 vty_out(vty
, " Interface Address %s\n",
3564 inet_ntoa(nbr
->address
.u
3570 /* Next network-LSA sequence number we'll use, if we're elected
3573 && ntohl(oi
->params
->network_lsa_seqnum
)
3574 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3576 json_object_int_add(
3578 "networkLsaSequence",
3579 ntohl(oi
->params
->network_lsa_seqnum
));
3582 " Saved Network-LSA sequence number 0x%x\n",
3583 ntohl(oi
->params
->network_lsa_seqnum
));
3587 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3588 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3589 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3590 json_object_boolean_true_add(
3592 "mcastMemberOspfAllRouters");
3593 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3594 json_object_boolean_true_add(
3596 "mcastMemberOspfDesignatedRouters");
3599 vty_out(vty
, " Multicast group memberships:");
3600 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3601 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3602 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3603 vty_out(vty
, " OSPFAllRouters");
3604 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3605 vty_out(vty
, " OSPFDesignatedRouters");
3607 vty_out(vty
, " <None>");
3612 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3613 json_object_int_add(
3614 json_interface_sub
, "timerMsecs",
3615 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3617 json_object_int_add(
3618 json_interface_sub
, "timerMsecs",
3619 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3620 json_object_int_add(json_interface_sub
,
3622 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3623 json_object_int_add(json_interface_sub
,
3625 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3626 json_object_int_add(
3627 json_interface_sub
, "timerRetransmit",
3628 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3630 vty_out(vty
, " Timer intervals configured,");
3631 vty_out(vty
, " Hello ");
3632 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3633 vty_out(vty
, "%ds,",
3634 OSPF_IF_PARAM(oi
, v_hello
));
3636 vty_out(vty
, "%dms,",
3637 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3638 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3639 OSPF_IF_PARAM(oi
, v_wait
),
3640 OSPF_IF_PARAM(oi
, v_wait
),
3641 OSPF_IF_PARAM(oi
, retransmit_interval
));
3644 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3645 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3647 long time_store
= 0;
3651 &oi
->t_hello
->u
.sands
,
3654 json_object_int_add(json_interface_sub
,
3655 "timerHelloInMsecs",
3658 vty_out(vty
, " Hello due in %s\n",
3659 ospf_timer_dump(oi
->t_hello
, timebuf
,
3661 } else /* passive-interface is set */
3664 json_object_boolean_true_add(
3666 "timerPassiveIface");
3669 " No Hellos (Passive interface)\n");
3673 json_object_int_add(json_interface_sub
, "nbrCount",
3674 ospf_nbr_count(oi
, 0));
3675 json_object_int_add(json_interface_sub
,
3677 ospf_nbr_count(oi
, NSM_Full
));
3680 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3681 ospf_nbr_count(oi
, 0),
3682 ospf_nbr_count(oi
, NSM_Full
));
3683 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3687 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3688 char *intf_name
, uint8_t use_vrf
,
3689 json_object
*json
, uint8_t use_json
)
3691 struct interface
*ifp
;
3692 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3693 json_object
*json_vrf
= NULL
;
3694 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3698 json_vrf
= json_object_new_object();
3701 json_interface
= json_object_new_object();
3704 if (ospf
->instance
) {
3706 json_object_int_add(json
, "ospfInstance",
3709 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3712 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3714 if (intf_name
== NULL
) {
3715 /* Show All Interfaces.*/
3716 FOR_ALL_INTERFACES (vrf
, ifp
) {
3717 if (ospf_oi_count(ifp
)) {
3719 json_interface_sub
=
3720 json_object_new_object();
3722 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3727 json_object_object_add(
3728 json_interface
, ifp
->name
,
3729 json_interface_sub
);
3734 json_object_object_add(json_vrf
, "interfaces",
3737 /* Interface name is specified. */
3738 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3741 json_object_boolean_true_add(json_vrf
,
3744 vty_out(vty
, "No such interface name\n");
3747 json_interface_sub
= json_object_new_object();
3748 json_interface
= json_object_new_object();
3751 show_ip_ospf_interface_sub(
3752 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3755 json_object_object_add(json_interface
,
3757 json_interface_sub
);
3758 json_object_object_add(json_vrf
, "interfaces",
3766 if (ospf
->vrf_id
== VRF_DEFAULT
)
3767 json_object_object_add(json
, "default",
3770 json_object_object_add(json
, ospf
->name
,
3779 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3780 struct ospf_interface
*oi
,
3781 json_object
*json_interface_sub
,
3785 json_object_int_add(json_interface_sub
, "ifIndex",
3787 json_object_int_add(json_interface_sub
, "helloIn",
3789 json_object_int_add(json_interface_sub
, "helloOut",
3791 json_object_int_add(json_interface_sub
, "dbDescIn",
3793 json_object_int_add(json_interface_sub
, "dbDescOut",
3795 json_object_int_add(json_interface_sub
, "lsReqIn",
3797 json_object_int_add(json_interface_sub
, "lsReqOut",
3799 json_object_int_add(json_interface_sub
, "lsUpdIn",
3801 json_object_int_add(json_interface_sub
, "lsUpdOut",
3803 json_object_int_add(json_interface_sub
, "lsAckIn",
3805 json_object_int_add(json_interface_sub
, "lsAckOut",
3809 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3810 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3811 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3812 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3813 oi
->ls_ack_in
, oi
->ls_ack_out
);
3817 /* OSPFv2 Packet Counters */
3818 static int show_ip_ospf_interface_traffic_common(
3819 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3820 int display_once
, uint8_t use_vrf
, uint8_t use_json
)
3822 struct vrf
*vrf
= NULL
;
3823 struct interface
*ifp
= NULL
;
3824 json_object
*json_vrf
= NULL
;
3825 json_object
*json_interface_sub
= NULL
;
3827 if (!use_json
&& !display_once
) {
3829 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3830 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3832 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3833 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3836 "--------------------------------------------------------------------------------------------\n");
3837 } else if (use_json
) {
3839 json_vrf
= json_object_new_object();
3844 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3846 if (intf_name
== NULL
) {
3847 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3848 FOR_ALL_INTERFACES (vrf
, ifp
) {
3849 struct route_node
*rn
;
3850 struct ospf_interface
*oi
;
3852 if (ospf_oi_count(ifp
) == 0)
3855 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3856 rn
= route_next(rn
)) {
3863 json_interface_sub
=
3864 json_object_new_object();
3867 show_ip_ospf_interface_traffic_sub(
3868 vty
, oi
, json_interface_sub
, use_json
);
3870 json_object_object_add(
3871 json_vrf
, ifp
->name
,
3872 json_interface_sub
);
3877 /* Interface name is specified. */
3878 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3880 struct route_node
*rn
;
3881 struct ospf_interface
*oi
;
3883 if (ospf_oi_count(ifp
) == 0) {
3885 " OSPF not enabled on this interface %s\n",
3890 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3891 rn
= route_next(rn
)) {
3895 json_interface_sub
=
3896 json_object_new_object();
3899 show_ip_ospf_interface_traffic_sub(
3900 vty
, oi
, json_interface_sub
, use_json
);
3902 json_object_object_add(
3903 json_vrf
, ifp
->name
,
3904 json_interface_sub
);
3912 if (ospf
->vrf_id
== VRF_DEFAULT
)
3913 json_object_object_add(json
, "default",
3916 json_object_object_add(json
, ospf
->name
,
3925 DEFUN (show_ip_ospf_interface
,
3926 show_ip_ospf_interface_cmd
,
3927 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3930 "OSPF information\n"
3933 "Interface information\n"
3938 uint8_t uj
= use_json(argc
, argv
);
3939 struct listnode
*node
= NULL
;
3940 char *vrf_name
= NULL
, *intf_name
= NULL
;
3941 bool all_vrf
= FALSE
;
3942 int ret
= CMD_SUCCESS
;
3944 int idx_vrf
= 0, idx_intf
= 0;
3945 uint8_t use_vrf
= 0;
3946 json_object
*json
= NULL
;
3948 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3950 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3951 intf_name
= argv
[idx_intf
]->arg
;
3954 json
= json_object_new_object();
3956 /* vrf input is provided could be all or specific vrf*/
3960 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3961 if (!ospf
->oi_running
)
3963 ret
= show_ip_ospf_interface_common(
3964 vty
, ospf
, intf_name
, use_vrf
, json
,
3969 vty_out(vty
, "%s\n",
3970 json_object_to_json_string_ext(
3971 json
, JSON_C_TO_STRING_PRETTY
));
3972 json_object_free(json
);
3977 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3978 if (ospf
== NULL
|| !ospf
->oi_running
) {
3980 json_object_free(json
);
3983 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3987 /* Display default ospf (instance 0) info */
3988 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3989 if (ospf
== NULL
|| !ospf
->oi_running
) {
3991 json_object_free(json
);
3994 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3999 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4000 json
, JSON_C_TO_STRING_PRETTY
));
4001 json_object_free(json
);
4007 DEFUN (show_ip_ospf_instance_interface
,
4008 show_ip_ospf_instance_interface_cmd
,
4009 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4012 "OSPF information\n"
4014 "Interface information\n"
4021 unsigned short instance
= 0;
4022 uint8_t uj
= use_json(argc
, argv
);
4023 char *intf_name
= NULL
;
4024 int ret
= CMD_SUCCESS
;
4025 json_object
*json
= NULL
;
4027 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4028 ospf
= ospf_lookup_instance(instance
);
4030 return CMD_NOT_MY_INSTANCE
;
4032 if (!ospf
->oi_running
)
4036 json
= json_object_new_object();
4038 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4039 intf_name
= argv
[idx_intf
]->arg
;
4041 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4044 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4045 json
, JSON_C_TO_STRING_PRETTY
));
4046 json_object_free(json
);
4052 DEFUN (show_ip_ospf_interface_traffic
,
4053 show_ip_ospf_interface_traffic_cmd
,
4054 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4057 "OSPF information\n"
4060 "Interface information\n"
4061 "Protocol Packet counters\n"
4065 struct ospf
*ospf
= NULL
;
4066 struct listnode
*node
= NULL
;
4067 char *vrf_name
= NULL
, *intf_name
= NULL
;
4068 bool all_vrf
= FALSE
;
4070 int idx_vrf
= 0, idx_intf
= 0;
4071 uint8_t uj
= use_json(argc
, argv
);
4072 json_object
*json
= NULL
;
4073 int ret
= CMD_SUCCESS
;
4074 int display_once
= 0;
4075 uint8_t use_vrf
= 0;
4077 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4079 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4080 intf_name
= argv
[idx_intf
]->arg
;
4083 json
= json_object_new_object();
4088 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4089 if (!ospf
->oi_running
)
4092 ret
= show_ip_ospf_interface_traffic_common(
4093 vty
, ospf
, intf_name
, json
,
4094 display_once
, use_vrf
, uj
);
4099 vty_out(vty
, "%s\n",
4100 json_object_to_json_string_ext(
4101 json
, JSON_C_TO_STRING_PRETTY
));
4102 json_object_free(json
);
4107 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4108 if (ospf
== NULL
|| !ospf
->oi_running
) {
4110 json_object_free(json
);
4114 ret
= show_ip_ospf_interface_traffic_common(
4115 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4117 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4118 if (ospf
== NULL
|| !ospf
->oi_running
) {
4120 json_object_free(json
);
4124 ret
= show_ip_ospf_interface_traffic_common(
4125 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4129 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4130 json
, JSON_C_TO_STRING_PRETTY
));
4131 json_object_free(json
);
4138 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4140 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4141 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4142 "Interface", "RXmtL", "RqstL", "DBsmL");
4145 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4146 struct ospf_interface
*oi
,
4147 json_object
*json
, uint8_t use_json
)
4149 struct route_node
*rn
;
4150 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4152 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4153 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4155 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4156 if ((nbr
= rn
->info
)) {
4157 /* Do not show myself. */
4158 if (nbr
== oi
->nbr_self
)
4160 /* Down state is not shown. */
4161 if (nbr
->state
== NSM_Down
)
4164 char neigh_str
[INET_ADDRSTRLEN
];
4167 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4169 /* Start new neigh list */
4170 json_neigh_array
= NULL
;
4173 if (nbr
->state
== NSM_Attempt
4174 && nbr
->router_id
.s_addr
== 0)
4175 strlcpy(neigh_str
, "neighbor",
4179 inet_ntoa(nbr
->router_id
),
4182 json_object_object_get_ex(json
, neigh_str
,
4185 if (!json_neigh_array
) {
4187 json_object_new_array();
4188 json_object_object_add(
4193 json_neighbor
= json_object_new_object();
4195 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4201 &nbr
->t_inactivity
->u
.sands
,
4205 json_object_int_add(json_neighbor
, "priority",
4207 json_object_string_add(json_neighbor
, "state",
4209 json_object_int_add(json_neighbor
,
4212 json_object_string_add(json_neighbor
, "address",
4213 inet_ntoa(nbr
->src
));
4214 json_object_string_add(json_neighbor
,
4217 json_object_int_add(
4218 json_neighbor
, "retransmitCounter",
4219 ospf_ls_retransmit_count(nbr
));
4220 json_object_int_add(json_neighbor
,
4222 ospf_ls_request_count(nbr
));
4223 json_object_int_add(json_neighbor
,
4225 ospf_db_summary_count(nbr
));
4227 json_object_array_add(json_neigh_array
,
4230 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4232 if (nbr
->state
== NSM_Attempt
4233 && nbr
->router_id
.s_addr
== 0)
4234 vty_out(vty
, "%-15s %3d %-15s ", "-",
4235 nbr
->priority
, msgbuf
);
4237 vty_out(vty
, "%-15s %3d %-15s ",
4238 inet_ntoa(nbr
->router_id
),
4239 nbr
->priority
, msgbuf
);
4241 vty_out(vty
, "%9s ",
4242 ospf_timer_dump(nbr
->t_inactivity
,
4245 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4246 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4248 ospf_ls_retransmit_count(nbr
),
4249 ospf_ls_request_count(nbr
),
4250 ospf_db_summary_count(nbr
));
4257 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4258 json_object
*json
, uint8_t use_json
,
4261 struct ospf_interface
*oi
;
4262 struct listnode
*node
;
4263 json_object
*json_vrf
= NULL
;
4264 json_object
*json_nbr_sub
= NULL
;
4268 json_vrf
= json_object_new_object();
4271 json_nbr_sub
= json_object_new_object();
4274 if (ospf
->instance
) {
4276 json_object_int_add(json
, "ospfInstance",
4279 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4282 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4284 show_ip_ospf_neighbour_header(vty
);
4286 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4287 if (ospf_interface_neighbor_count(oi
) == 0)
4289 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4293 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4295 if (ospf
->vrf_id
== VRF_DEFAULT
)
4296 json_object_object_add(json
, "default",
4299 json_object_object_add(json
, ospf
->name
,
4308 DEFUN (show_ip_ospf_neighbor
,
4309 show_ip_ospf_neighbor_cmd
,
4310 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4313 "OSPF information\n"
4320 uint8_t uj
= use_json(argc
, argv
);
4321 struct listnode
*node
= NULL
;
4322 char *vrf_name
= NULL
;
4323 bool all_vrf
= FALSE
;
4324 int ret
= CMD_SUCCESS
;
4327 uint8_t use_vrf
= 0;
4328 json_object
*json
= NULL
;
4330 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4333 json
= json_object_new_object();
4335 /* vrf input is provided could be all or specific vrf*/
4339 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4340 if (!ospf
->oi_running
)
4342 ret
= show_ip_ospf_neighbor_common(
4343 vty
, ospf
, json
, uj
, use_vrf
);
4347 vty_out(vty
, "%s\n",
4348 json_object_to_json_string_ext(
4349 json
, JSON_C_TO_STRING_PRETTY
));
4350 json_object_free(json
);
4356 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4357 if (ospf
== NULL
|| !ospf
->oi_running
) {
4359 json_object_free(json
);
4363 /* Display default ospf (instance 0) info */
4364 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4365 if (ospf
== NULL
|| !ospf
->oi_running
) {
4367 json_object_free(json
);
4373 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4377 vty_out(vty
, "%s\n",
4378 json_object_to_json_string_ext(
4379 json
, JSON_C_TO_STRING_PRETTY
));
4384 json_object_free(json
);
4390 DEFUN (show_ip_ospf_instance_neighbor
,
4391 show_ip_ospf_instance_neighbor_cmd
,
4392 "show ip ospf (1-65535) neighbor [json]",
4395 "OSPF information\n"
4402 unsigned short instance
= 0;
4403 uint8_t uj
= use_json(argc
, argv
);
4404 json_object
*json
= NULL
;
4405 int ret
= CMD_SUCCESS
;
4407 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4408 ospf
= ospf_lookup_instance(instance
);
4410 return CMD_NOT_MY_INSTANCE
;
4412 if (!ospf
->oi_running
)
4416 json
= json_object_new_object();
4418 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4421 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4422 json
, JSON_C_TO_STRING_PRETTY
));
4423 json_object_free(json
);
4429 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4430 json_object
*json
, uint8_t use_json
,
4433 struct listnode
*node
;
4434 struct ospf_interface
*oi
;
4435 json_object
*json_vrf
= NULL
;
4436 json_object
*json_neighbor_sub
= NULL
;
4440 json_vrf
= json_object_new_object();
4443 json_neighbor_sub
= json_object_new_object();
4446 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4448 show_ip_ospf_neighbour_header(vty
);
4450 if (ospf
->instance
) {
4452 json_object_int_add(json_vrf
, "ospfInstance",
4455 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4458 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4459 struct listnode
*nbr_node
;
4460 struct ospf_nbr_nbma
*nbr_nbma
;
4462 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4464 /* print Down neighbor status */
4465 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4466 if (nbr_nbma
->nbr
== NULL
4467 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4469 json_object_int_add(json_neighbor_sub
,
4471 nbr_nbma
->priority
);
4472 json_object_boolean_true_add(
4475 json_object_string_add(
4479 json_object_int_add(
4481 "nbrNbmaRetransmitCounter", 0);
4482 json_object_int_add(
4484 "nbrNbmaRequestCounter", 0);
4485 json_object_int_add(
4487 "nbrNbmaDbSummaryCounter", 0);
4488 json_object_object_add(
4490 inet_ntoa(nbr_nbma
->addr
),
4493 vty_out(vty
, "%-15s %3d %-15s %9s ",
4494 "-", nbr_nbma
->priority
, "Down",
4497 "%-15s %-20s %5d %5d %5d\n",
4498 inet_ntoa(nbr_nbma
->addr
),
4499 IF_NAME(oi
), 0, 0, 0);
4507 if (ospf
->vrf_id
== VRF_DEFAULT
)
4508 json_object_object_add(json
, "default",
4511 json_object_object_add(json
, ospf
->name
,
4520 DEFUN (show_ip_ospf_neighbor_all
,
4521 show_ip_ospf_neighbor_all_cmd
,
4522 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4525 "OSPF information\n"
4529 "include down status neighbor\n"
4533 uint8_t uj
= use_json(argc
, argv
);
4534 struct listnode
*node
= NULL
;
4535 char *vrf_name
= NULL
;
4536 bool all_vrf
= FALSE
;
4537 int ret
= CMD_SUCCESS
;
4540 uint8_t use_vrf
= 0;
4541 json_object
*json
= NULL
;
4543 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4546 json
= json_object_new_object();
4548 /* vrf input is provided could be all or specific vrf*/
4552 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4553 if (!ospf
->oi_running
)
4555 ret
= show_ip_ospf_neighbor_all_common(
4556 vty
, ospf
, json
, uj
, use_vrf
);
4560 vty_out(vty
, "%s\n",
4561 json_object_to_json_string_ext(
4562 json
, JSON_C_TO_STRING_PRETTY
));
4563 json_object_free(json
);
4569 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4570 if (ospf
== NULL
|| !ospf
->oi_running
) {
4572 json_object_free(json
);
4576 /* Display default ospf (instance 0) info */
4577 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4578 if (ospf
== NULL
|| !ospf
->oi_running
) {
4580 json_object_free(json
);
4586 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4589 vty_out(vty
, "%s\n",
4590 json_object_to_json_string_ext(
4591 json
, JSON_C_TO_STRING_PRETTY
));
4596 json_object_free(json
);
4601 DEFUN (show_ip_ospf_instance_neighbor_all
,
4602 show_ip_ospf_instance_neighbor_all_cmd
,
4603 "show ip ospf (1-65535) neighbor all [json]",
4606 "OSPF information\n"
4609 "include down status neighbor\n"
4614 unsigned short instance
= 0;
4615 uint8_t uj
= use_json(argc
, argv
);
4616 json_object
*json
= NULL
;
4617 int ret
= CMD_SUCCESS
;
4619 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4620 ospf
= ospf_lookup_instance(instance
);
4622 return CMD_NOT_MY_INSTANCE
;
4624 if (!ospf
->oi_running
)
4627 json
= json_object_new_object();
4629 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4632 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4633 json
, JSON_C_TO_STRING_PRETTY
));
4634 json_object_free(json
);
4640 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4642 struct cmd_token
**argv
,
4643 uint8_t use_json
, uint8_t use_vrf
)
4645 struct interface
*ifp
;
4646 struct route_node
*rn
;
4647 json_object
*json
= NULL
;
4650 json
= json_object_new_object();
4652 if (ospf
->instance
) {
4654 json_object_int_add(json
, "ospfInstance",
4657 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4660 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4662 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4665 json_object_boolean_true_add(json
, "noSuchIface");
4667 vty_out(vty
, "No such interface.\n");
4671 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4672 struct ospf_interface
*oi
= rn
->info
;
4677 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4681 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4682 json
, JSON_C_TO_STRING_PRETTY
));
4683 json_object_free(json
);
4690 DEFUN (show_ip_ospf_neighbor_int
,
4691 show_ip_ospf_neighbor_int_cmd
,
4692 "show ip ospf neighbor IFNAME [json]",
4695 "OSPF information\n"
4702 uint8_t uj
= use_json(argc
, argv
);
4703 struct listnode
*node
= NULL
;
4704 int ret
= CMD_SUCCESS
;
4705 struct interface
*ifp
= NULL
;
4708 show_ip_ospf_neighbour_header(vty
);
4710 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4711 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4712 if (!ospf
->oi_running
)
4714 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4716 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4723 DEFUN (show_ip_ospf_instance_neighbor_int
,
4724 show_ip_ospf_instance_neighbor_int_cmd
,
4725 "show ip ospf (1-65535) neighbor IFNAME [json]",
4728 "OSPF information\n"
4737 unsigned short instance
= 0;
4738 uint8_t uj
= use_json(argc
, argv
);
4741 show_ip_ospf_neighbour_header(vty
);
4743 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4744 ospf
= ospf_lookup_instance(instance
);
4746 return CMD_NOT_MY_INSTANCE
;
4748 if (!ospf
->oi_running
)
4752 show_ip_ospf_neighbour_header(vty
);
4754 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4758 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4759 struct ospf_interface
*oi
,
4760 struct ospf_nbr_nbma
*nbr_nbma
,
4764 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4765 json_object
*json_sub
= NULL
;
4768 json_sub
= json_object_new_object();
4769 else /* Show neighbor ID. */
4770 vty_out(vty
, " Neighbor %s,", "-");
4772 /* Show interface address. */
4774 json_object_string_add(json_sub
, "ifaceAddress",
4775 inet_ntoa(nbr_nbma
->addr
));
4777 vty_out(vty
, " interface address %s\n",
4778 inet_ntoa(nbr_nbma
->addr
));
4782 json_object_string_add(json_sub
, "areaId",
4783 ospf_area_desc_string(oi
->area
));
4784 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4786 vty_out(vty
, " In the area %s via interface %s\n",
4787 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4789 /* Show neighbor priority and state. */
4791 json_object_int_add(json_sub
, "nbrPriority",
4792 nbr_nbma
->priority
);
4793 json_object_string_add(json_sub
, "nbrState", "down");
4795 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4796 nbr_nbma
->priority
, "Down");
4798 /* Show state changes. */
4800 json_object_int_add(json_sub
, "stateChangeCounter",
4801 nbr_nbma
->state_change
);
4803 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4805 /* Show PollInterval */
4807 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4809 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4811 /* Show poll-interval timer. */
4812 if (nbr_nbma
->t_poll
) {
4815 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4817 json_object_int_add(json_sub
,
4818 "pollIntervalTimerDueMsec",
4821 vty_out(vty
, " Poll timer due in %s\n",
4822 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4826 /* Show poll-interval timer thread. */
4828 if (nbr_nbma
->t_poll
!= NULL
)
4829 json_object_string_add(json_sub
,
4830 "pollIntervalTimerThread", "on");
4832 vty_out(vty
, " Thread Poll Timer %s\n",
4833 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4836 json_object_object_add(json
, "noNbrId", json_sub
);
4839 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4840 struct ospf_interface
*oi
,
4841 struct ospf_neighbor
*nbr
,
4845 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4846 json_object
*json_sub
= NULL
;
4849 json_sub
= json_object_new_object();
4851 /* Show neighbor ID. */
4852 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4853 vty_out(vty
, " Neighbor %s,", "-");
4855 vty_out(vty
, " Neighbor %s,",
4856 inet_ntoa(nbr
->router_id
));
4859 /* Show interface address. */
4861 json_object_string_add(json_sub
, "ifaceAddress",
4862 inet_ntoa(nbr
->address
.u
.prefix4
));
4864 vty_out(vty
, " interface address %s\n",
4865 inet_ntoa(nbr
->address
.u
.prefix4
));
4869 json_object_string_add(json_sub
, "areaId",
4870 ospf_area_desc_string(oi
->area
));
4871 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4873 vty_out(vty
, " In the area %s via interface %s\n",
4874 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4876 /* Show neighbor priority and state. */
4878 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4879 json_object_string_add(
4880 json_sub
, "nbrState",
4881 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4883 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4885 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4887 /* Show state changes. */
4889 json_object_int_add(json_sub
, "stateChangeCounter",
4892 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4894 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4899 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4901 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4905 " Most recent state change statistics:\n");
4906 vty_out(vty
, " Progressive change %s ago\n",
4907 ospf_timeval_dump(&res
, timebuf
,
4912 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4917 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4919 json_object_int_add(json_sub
,
4920 "lastRegressiveChangeMsec",
4922 if (nbr
->last_regress_str
)
4923 json_object_string_add(
4924 json_sub
, "lastRegressiveChangeReason",
4925 nbr
->last_regress_str
);
4928 " Regressive change %s ago, due to %s\n",
4929 ospf_timeval_dump(&res
, timebuf
,
4931 (nbr
->last_regress_str
? nbr
->last_regress_str
4936 /* Show Designated Rotuer ID. */
4938 json_object_string_add(json_sub
, "routerDesignatedId",
4939 inet_ntoa(nbr
->d_router
));
4941 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4943 /* Show Backup Designated Rotuer ID. */
4945 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4946 inet_ntoa(nbr
->bd_router
));
4948 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4952 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4953 json_object_string_add(json_sub
, "optionsList",
4954 ospf_options_dump(nbr
->options
));
4956 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4957 ospf_options_dump(nbr
->options
));
4959 /* Show Router Dead interval timer. */
4961 if (nbr
->t_inactivity
) {
4963 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4966 json_object_int_add(json_sub
,
4967 "routerDeadIntervalTimerDueMsec",
4970 json_object_int_add(
4971 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
4973 vty_out(vty
, " Dead timer due in %s\n",
4974 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4977 /* Show Database Summary list. */
4979 json_object_int_add(json_sub
, "databaseSummaryListCounter",
4980 ospf_db_summary_count(nbr
));
4982 vty_out(vty
, " Database Summary List %d\n",
4983 ospf_db_summary_count(nbr
));
4985 /* Show Link State Request list. */
4987 json_object_int_add(json_sub
, "linkStateRequestListCounter",
4988 ospf_ls_request_count(nbr
));
4990 vty_out(vty
, " Link State Request List %ld\n",
4991 ospf_ls_request_count(nbr
));
4993 /* Show Link State Retransmission list. */
4995 json_object_int_add(json_sub
,
4996 "linkStateRetransmissionListCounter",
4997 ospf_ls_retransmit_count(nbr
));
4999 vty_out(vty
, " Link State Retransmission List %ld\n",
5000 ospf_ls_retransmit_count(nbr
));
5002 /* Show inactivity timer thread. */
5004 if (nbr
->t_inactivity
!= NULL
)
5005 json_object_string_add(json_sub
,
5006 "threadInactivityTimer", "on");
5008 vty_out(vty
, " Thread Inactivity Timer %s\n",
5009 nbr
->t_inactivity
!= NULL
? "on" : "off");
5011 /* Show Database Description retransmission thread. */
5013 if (nbr
->t_db_desc
!= NULL
)
5014 json_object_string_add(
5016 "threadDatabaseDescriptionRetransmission",
5020 " Thread Database Description Retransmision %s\n",
5021 nbr
->t_db_desc
!= NULL
? "on" : "off");
5023 /* Show Link State Request Retransmission thread. */
5025 if (nbr
->t_ls_req
!= NULL
)
5026 json_object_string_add(
5028 "threadLinkStateRequestRetransmission", "on");
5031 " Thread Link State Request Retransmission %s\n",
5032 nbr
->t_ls_req
!= NULL
? "on" : "off");
5034 /* Show Link State Update Retransmission thread. */
5036 if (nbr
->t_ls_upd
!= NULL
)
5037 json_object_string_add(
5038 json_sub
, "threadLinkStateUpdateRetransmission",
5042 " Thread Link State Update Retransmission %s\n\n",
5043 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5046 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5047 json_object_object_add(json
, "noNbrId", json_sub
);
5049 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5053 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5056 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5058 struct cmd_token
**argv
,
5059 uint8_t use_json
, uint8_t use_vrf
)
5061 struct listnode
*node
;
5062 struct ospf_neighbor
*nbr
;
5063 struct ospf_interface
*oi
;
5064 struct in_addr router_id
;
5066 json_object
*json
= NULL
;
5069 json
= json_object_new_object();
5071 if (ospf
->instance
) {
5073 json_object_int_add(json
, "ospfInstance",
5076 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5079 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5081 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5084 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5086 vty_out(vty
, "{}\n");
5087 json_object_free(json
);
5092 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5093 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5094 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5100 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5101 json
, JSON_C_TO_STRING_PRETTY
));
5102 json_object_free(json
);
5109 DEFUN (show_ip_ospf_neighbor_id
,
5110 show_ip_ospf_neighbor_id_cmd
,
5111 "show ip ospf neighbor A.B.C.D [json]",
5114 "OSPF information\n"
5120 uint8_t uj
= use_json(argc
, argv
);
5121 struct listnode
*node
= NULL
;
5122 int ret
= CMD_SUCCESS
;
5124 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5125 if (!ospf
->oi_running
)
5127 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0, argv
, uj
,
5134 DEFUN (show_ip_ospf_instance_neighbor_id
,
5135 show_ip_ospf_instance_neighbor_id_cmd
,
5136 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5139 "OSPF information\n"
5146 int idx_router_id
= 5;
5148 unsigned short instance
= 0;
5149 uint8_t uj
= use_json(argc
, argv
);
5151 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5152 ospf
= ospf_lookup_instance(instance
);
5154 return CMD_NOT_MY_INSTANCE
;
5156 if (!ospf
->oi_running
)
5159 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5163 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5169 struct ospf_interface
*oi
;
5170 struct listnode
*node
;
5171 json_object
*json_vrf
= NULL
;
5175 json_vrf
= json_object_new_object();
5179 if (ospf
->instance
) {
5181 json_object_int_add(json_vrf
, "ospfInstance",
5184 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5187 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5189 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5190 struct route_node
*rn
;
5191 struct ospf_neighbor
*nbr
;
5193 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5194 if ((nbr
= rn
->info
)) {
5195 if (nbr
!= oi
->nbr_self
) {
5196 if (nbr
->state
!= NSM_Down
) {
5197 show_ip_ospf_neighbor_detail_sub(
5198 vty
, oi
, nbr
, json_vrf
,
5208 if (ospf
->vrf_id
== VRF_DEFAULT
)
5209 json_object_object_add(json
, "default",
5212 json_object_object_add(json
, ospf
->name
,
5221 DEFUN (show_ip_ospf_neighbor_detail
,
5222 show_ip_ospf_neighbor_detail_cmd
,
5223 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5226 "OSPF information\n"
5230 "detail of all neighbors\n"
5234 uint8_t uj
= use_json(argc
, argv
);
5235 struct listnode
*node
= NULL
;
5236 char *vrf_name
= NULL
;
5237 bool all_vrf
= FALSE
;
5238 int ret
= CMD_SUCCESS
;
5241 uint8_t use_vrf
= 0;
5242 json_object
*json
= NULL
;
5244 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5247 json
= json_object_new_object();
5249 /* vrf input is provided could be all or specific vrf*/
5253 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5254 if (!ospf
->oi_running
)
5256 ret
= show_ip_ospf_neighbor_detail_common(
5257 vty
, ospf
, json
, uj
, use_vrf
);
5260 vty_out(vty
, "%s\n",
5261 json_object_to_json_string_ext(
5262 json
, JSON_C_TO_STRING_PRETTY
));
5263 json_object_free(json
);
5268 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5269 if (ospf
== NULL
|| !ospf
->oi_running
) {
5271 json_object_free(json
);
5275 /* Display default ospf (instance 0) info */
5276 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5277 if (ospf
== NULL
|| !ospf
->oi_running
) {
5279 json_object_free(json
);
5285 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5288 vty_out(vty
, "%s\n",
5289 json_object_to_json_string_ext(
5290 json
, JSON_C_TO_STRING_PRETTY
));
5295 json_object_free(json
);
5300 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5301 show_ip_ospf_instance_neighbor_detail_cmd
,
5302 "show ip ospf (1-65535) neighbor detail [json]",
5305 "OSPF information\n"
5308 "detail of all neighbors\n"
5313 unsigned short instance
= 0;
5314 uint8_t uj
= use_json(argc
, argv
);
5315 json_object
*json
= NULL
;
5316 int ret
= CMD_SUCCESS
;
5318 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5319 ospf
= ospf_lookup_instance(instance
);
5321 return CMD_NOT_MY_INSTANCE
;
5323 if (!ospf
->oi_running
)
5327 json
= json_object_new_object();
5329 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5332 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5333 json
, JSON_C_TO_STRING_PRETTY
));
5334 json_object_free(json
);
5340 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5346 struct listnode
*node
;
5347 struct ospf_interface
*oi
;
5348 json_object
*json_vrf
= NULL
;
5352 json_vrf
= json_object_new_object();
5357 if (ospf
->instance
) {
5359 json_object_int_add(json
, "ospfInstance",
5362 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5365 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5367 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5368 struct route_node
*rn
;
5369 struct ospf_neighbor
*nbr
;
5370 struct ospf_nbr_nbma
*nbr_nbma
;
5372 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5373 if ((nbr
= rn
->info
))
5374 if (nbr
!= oi
->nbr_self
)
5375 if (nbr
->state
!= NSM_Down
)
5376 show_ip_ospf_neighbor_detail_sub(
5378 json_vrf
, use_json
);
5380 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5381 struct listnode
*nd
;
5383 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5384 if (nbr_nbma
->nbr
== NULL
5385 || nbr_nbma
->nbr
->state
== NSM_Down
)
5386 show_ip_ospf_nbr_nbma_detail_sub(
5387 vty
, oi
, nbr_nbma
, use_json
,
5395 if (ospf
->vrf_id
== VRF_DEFAULT
)
5396 json_object_object_add(json
, "default",
5399 json_object_object_add(json
, ospf
->name
,
5409 DEFUN (show_ip_ospf_neighbor_detail_all
,
5410 show_ip_ospf_neighbor_detail_all_cmd
,
5411 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5414 "OSPF information\n"
5418 "detail of all neighbors\n"
5419 "include down status neighbor\n"
5423 uint8_t uj
= use_json(argc
, argv
);
5424 struct listnode
*node
= NULL
;
5425 char *vrf_name
= NULL
;
5426 bool all_vrf
= FALSE
;
5427 int ret
= CMD_SUCCESS
;
5430 uint8_t use_vrf
= 0;
5431 json_object
*json
= NULL
;
5433 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5436 json
= json_object_new_object();
5438 /* vrf input is provided could be all or specific vrf*/
5442 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5443 if (!ospf
->oi_running
)
5445 ret
= show_ip_ospf_neighbor_detail_all_common(
5446 vty
, ospf
, json
, uj
, use_vrf
);
5450 vty_out(vty
, "%s\n",
5451 json_object_to_json_string_ext(
5452 json
, JSON_C_TO_STRING_PRETTY
));
5453 json_object_free(json
);
5458 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5459 if (ospf
== NULL
|| !ospf
->oi_running
) {
5461 json_object_free(json
);
5465 /* Display default ospf (instance 0) info */
5466 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5467 if (ospf
== NULL
|| !ospf
->oi_running
) {
5469 json_object_free(json
);
5475 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5478 vty_out(vty
, "%s\n",
5479 json_object_to_json_string_ext(
5480 json
, JSON_C_TO_STRING_PRETTY
));
5485 json_object_free(json
);
5490 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5491 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5492 "show ip ospf (1-65535) neighbor detail all [json]",
5495 "OSPF information\n"
5498 "detail of all neighbors\n"
5499 "include down status neighbor\n"
5504 unsigned short instance
= 0;
5505 uint8_t uj
= use_json(argc
, argv
);
5506 json_object
*json
= NULL
;
5507 int ret
= CMD_SUCCESS
;
5509 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5510 ospf
= ospf_lookup_instance(instance
);
5512 return CMD_NOT_MY_INSTANCE
;
5514 if (!ospf
->oi_running
)
5518 json
= json_object_new_object();
5520 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5523 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5524 json
, JSON_C_TO_STRING_PRETTY
));
5525 json_object_free(json
);
5531 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5534 struct cmd_token
**argv
,
5537 struct ospf_interface
*oi
;
5538 struct interface
*ifp
;
5539 struct route_node
*rn
, *nrn
;
5540 struct ospf_neighbor
*nbr
;
5541 json_object
*json
= NULL
;
5544 json
= json_object_new_object();
5546 if (ospf
->instance
) {
5548 json_object_int_add(json
, "ospfInstance",
5551 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5554 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5557 vty_out(vty
, "No such interface.\n");
5559 vty_out(vty
, "{}\n");
5560 json_object_free(json
);
5565 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5566 if ((oi
= rn
->info
)) {
5567 for (nrn
= route_top(oi
->nbrs
); nrn
;
5568 nrn
= route_next(nrn
)) {
5569 if ((nbr
= nrn
->info
)) {
5570 if (nbr
!= oi
->nbr_self
) {
5571 if (nbr
->state
!= NSM_Down
)
5572 show_ip_ospf_neighbor_detail_sub(
5582 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5583 json
, JSON_C_TO_STRING_PRETTY
));
5584 json_object_free(json
);
5591 DEFUN (show_ip_ospf_neighbor_int_detail
,
5592 show_ip_ospf_neighbor_int_detail_cmd
,
5593 "show ip ospf neighbor IFNAME detail [json]",
5596 "OSPF information\n"
5599 "detail of all neighbors\n"
5603 uint8_t uj
= use_json(argc
, argv
);
5604 struct listnode
*node
= NULL
;
5605 int ret
= CMD_SUCCESS
;
5607 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5608 if (!ospf
->oi_running
)
5610 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5617 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5618 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5619 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5622 "OSPF information\n"
5626 "detail of all neighbors\n"
5632 unsigned short instance
= 0;
5633 uint8_t uj
= use_json(argc
, argv
);
5635 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5636 ospf
= ospf_lookup_instance(instance
);
5638 return CMD_NOT_MY_INSTANCE
;
5640 if (!ospf
->oi_running
)
5643 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5647 /* Show functions */
5648 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5650 struct router_lsa
*rl
;
5651 struct summary_lsa
*sl
;
5652 struct as_external_lsa
*asel
;
5653 struct prefix_ipv4 p
;
5656 /* If self option is set, check LSA self flag. */
5657 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5658 /* LSA common part show. */
5659 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5660 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5661 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5662 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5663 ntohs(lsa
->data
->checksum
));
5664 /* LSA specific part show. */
5665 switch (lsa
->data
->type
) {
5666 case OSPF_ROUTER_LSA
:
5667 rl
= (struct router_lsa
*)lsa
->data
;
5668 vty_out(vty
, " %-d", ntohs(rl
->links
));
5670 case OSPF_SUMMARY_LSA
:
5671 sl
= (struct summary_lsa
*)lsa
->data
;
5674 p
.prefix
= sl
->header
.id
;
5675 p
.prefixlen
= ip_masklen(sl
->mask
);
5676 apply_mask_ipv4(&p
);
5678 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5681 case OSPF_AS_EXTERNAL_LSA
:
5682 case OSPF_AS_NSSA_LSA
:
5683 asel
= (struct as_external_lsa
*)lsa
->data
;
5686 p
.prefix
= asel
->header
.id
;
5687 p
.prefixlen
= ip_masklen(asel
->mask
);
5688 apply_mask_ipv4(&p
);
5690 vty_out(vty
, " %s %s/%d [0x%lx]",
5691 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5694 inet_ntoa(p
.prefix
), p
.prefixlen
,
5695 (unsigned long)ntohl(
5696 asel
->e
[0].route_tag
));
5698 case OSPF_NETWORK_LSA
:
5699 case OSPF_ASBR_SUMMARY_LSA
:
5700 case OSPF_OPAQUE_LINK_LSA
:
5701 case OSPF_OPAQUE_AREA_LSA
:
5702 case OSPF_OPAQUE_AS_LSA
:
5712 static const char *show_database_desc
[] = {
5714 "Router Link States",
5716 "Summary Link States",
5717 "ASBR-Summary Link States",
5718 "AS External Link States",
5719 "Group Membership LSA",
5720 "NSSA-external Link States",
5722 "Link-Local Opaque-LSA",
5723 "Area-Local Opaque-LSA",
5724 "AS-external Opaque-LSA",
5727 static const char *show_database_header
[] = {
5729 "Link ID ADV Router Age Seq# CkSum Link count",
5730 "Link ID ADV Router Age Seq# CkSum",
5731 "Link ID ADV Router Age Seq# CkSum Route",
5732 "Link ID ADV Router Age Seq# CkSum",
5733 "Link ID ADV Router Age Seq# CkSum Route",
5734 " --- header for Group Member ----",
5735 "Link ID ADV Router Age Seq# CkSum Route",
5737 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5738 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5739 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5742 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5744 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5746 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5747 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5748 ospf_options_dump(lsa
->data
->options
));
5749 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5750 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5753 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5754 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5757 vty_out(vty
, " :%s%s%s%s",
5758 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5759 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5760 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5762 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5767 vty_out(vty
, " LS Type: %s\n",
5768 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5769 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5770 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5771 vty_out(vty
, " Advertising Router: %s\n",
5772 inet_ntoa(lsa
->data
->adv_router
));
5773 vty_out(vty
, " LS Seq Number: %08lx\n",
5774 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5775 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5776 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5779 const char *link_type_desc
[] = {
5781 "another Router (point-to-point)",
5782 "a Transit Network",
5787 const char *link_id_desc
[] = {
5788 "(null)", "Neighboring Router ID", "Designated Router address",
5789 "Net", "Neighboring Router ID",
5792 const char *link_data_desc
[] = {
5793 "(null)", "Router Interface address", "Router Interface address",
5794 "Network Mask", "Router Interface address",
5797 /* Show router-LSA each Link information. */
5798 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5799 struct router_lsa
*rl
)
5804 len
= ntohs(rl
->header
.length
) - 4;
5805 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5806 type
= rl
->link
[i
].type
;
5808 vty_out(vty
, " Link connected to: %s\n",
5809 link_type_desc
[type
]);
5810 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5811 inet_ntoa(rl
->link
[i
].link_id
));
5812 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5813 inet_ntoa(rl
->link
[i
].link_data
));
5814 vty_out(vty
, " Number of TOS metrics: 0\n");
5815 vty_out(vty
, " TOS 0 Metric: %d\n",
5816 ntohs(rl
->link
[i
].metric
));
5821 /* Show router-LSA detail information. */
5822 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5825 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5827 show_ip_ospf_database_header(vty
, lsa
);
5829 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5831 show_ip_ospf_database_router_links(vty
, rl
);
5838 /* Show network-LSA detail information. */
5839 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5844 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5846 show_ip_ospf_database_header(vty
, lsa
);
5848 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5850 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5852 for (i
= 0; length
> 0; i
++, length
-= 4)
5853 vty_out(vty
, " Attached Router: %s\n",
5854 inet_ntoa(nl
->routers
[i
]));
5862 /* Show summary-LSA detail information. */
5863 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5866 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5868 show_ip_ospf_database_header(vty
, lsa
);
5870 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5871 vty_out(vty
, " TOS: 0 Metric: %d\n",
5872 GET_METRIC(sl
->metric
));
5879 /* Show summary-ASBR-LSA detail information. */
5880 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5883 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5885 show_ip_ospf_database_header(vty
, lsa
);
5887 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5888 vty_out(vty
, " TOS: 0 Metric: %d\n",
5889 GET_METRIC(sl
->metric
));
5896 /* Show AS-external-LSA detail information. */
5897 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5900 struct as_external_lsa
*al
=
5901 (struct as_external_lsa
*)lsa
->data
;
5903 show_ip_ospf_database_header(vty
, lsa
);
5905 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5906 vty_out(vty
, " Metric Type: %s\n",
5907 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5908 ? "2 (Larger than any link state path)"
5910 vty_out(vty
, " TOS: 0\n");
5911 vty_out(vty
, " Metric: %d\n",
5912 GET_METRIC(al
->e
[0].metric
));
5913 vty_out(vty
, " Forward Address: %s\n",
5914 inet_ntoa(al
->e
[0].fwd_addr
));
5917 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5918 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5925 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5927 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5929 /* show_ip_ospf_database_header (vty, lsa); */
5931 zlog_debug( " Network Mask: /%d%s",
5932 ip_masklen (al
->mask
), "\n");
5933 zlog_debug( " Metric Type: %s%s",
5934 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5935 "2 (Larger than any link state path)" : "1", "\n");
5936 zlog_debug( " TOS: 0%s", "\n");
5937 zlog_debug( " Metric: %d%s",
5938 GET_METRIC (al
->e
[0].metric
), "\n");
5939 zlog_debug( " Forward Address: %s%s",
5940 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5942 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5943 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5948 /* Show AS-NSSA-LSA detail information. */
5949 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5952 struct as_external_lsa
*al
=
5953 (struct as_external_lsa
*)lsa
->data
;
5955 show_ip_ospf_database_header(vty
, lsa
);
5957 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5958 vty_out(vty
, " Metric Type: %s\n",
5959 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5960 ? "2 (Larger than any link state path)"
5962 vty_out(vty
, " TOS: 0\n");
5963 vty_out(vty
, " Metric: %d\n",
5964 GET_METRIC(al
->e
[0].metric
));
5965 vty_out(vty
, " NSSA: Forward Address: %s\n",
5966 inet_ntoa(al
->e
[0].fwd_addr
));
5969 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5970 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5976 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
5981 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5984 show_ip_ospf_database_header(vty
, lsa
);
5985 show_opaque_info_detail(vty
, lsa
);
5992 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
5994 show_router_lsa_detail
,
5995 show_network_lsa_detail
,
5996 show_summary_lsa_detail
,
5997 show_summary_asbr_lsa_detail
,
5998 show_as_external_lsa_detail
,
6000 show_as_nssa_lsa_detail
, /* almost same as external */
6002 show_opaque_lsa_detail
,
6003 show_opaque_lsa_detail
,
6004 show_opaque_lsa_detail
,
6007 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6008 struct in_addr
*id
, struct in_addr
*adv_router
)
6010 memset(lp
, 0, sizeof(struct prefix_ls
));
6014 else if (adv_router
== NULL
) {
6020 lp
->adv_router
= *adv_router
;
6024 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6025 struct in_addr
*id
, struct in_addr
*adv_router
)
6027 struct prefix_ls lp
;
6028 struct route_node
*rn
, *start
;
6029 struct ospf_lsa
*lsa
;
6031 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6032 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6034 route_lock_node(start
);
6035 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6036 if ((lsa
= rn
->info
)) {
6037 if (show_function
[lsa
->data
->type
] != NULL
)
6038 show_function
[lsa
->data
->type
](vty
,
6041 route_unlock_node(start
);
6045 /* Show detail LSA information
6046 -- if id is NULL then show all LSAs. */
6047 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6048 struct in_addr
*id
, struct in_addr
*adv_router
)
6050 struct listnode
*node
;
6051 struct ospf_area
*area
;
6054 case OSPF_AS_EXTERNAL_LSA
:
6055 case OSPF_OPAQUE_AS_LSA
:
6056 vty_out(vty
, " %s \n\n",
6057 show_database_desc
[type
]);
6058 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6061 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6062 vty_out(vty
, "\n %s (Area %s)\n\n",
6063 show_database_desc
[type
],
6064 ospf_area_desc_string(area
));
6065 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6072 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6073 struct route_table
*rt
,
6074 struct in_addr
*adv_router
)
6076 struct route_node
*rn
;
6077 struct ospf_lsa
*lsa
;
6079 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6080 if ((lsa
= rn
->info
))
6081 if (IPV4_ADDR_SAME(adv_router
,
6082 &lsa
->data
->adv_router
)) {
6083 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6085 if (show_function
[lsa
->data
->type
] != NULL
)
6086 show_function
[lsa
->data
->type
](vty
,
6091 /* Show detail LSA information. */
6092 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6093 int type
, struct in_addr
*adv_router
)
6095 struct listnode
*node
;
6096 struct ospf_area
*area
;
6099 case OSPF_AS_EXTERNAL_LSA
:
6100 case OSPF_OPAQUE_AS_LSA
:
6101 vty_out(vty
, " %s \n\n",
6102 show_database_desc
[type
]);
6103 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6107 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6108 vty_out(vty
, "\n %s (Area %s)\n\n",
6109 show_database_desc
[type
],
6110 ospf_area_desc_string(area
));
6111 show_lsa_detail_adv_router_proc(
6112 vty
, AREA_LSDB(area
, type
), adv_router
);
6118 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6121 struct ospf_lsa
*lsa
;
6122 struct route_node
*rn
;
6123 struct ospf_area
*area
;
6124 struct listnode
*node
;
6127 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6128 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6130 case OSPF_AS_EXTERNAL_LSA
:
6131 case OSPF_OPAQUE_AS_LSA
:
6136 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6138 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6139 vty_out(vty
, " %s (Area %s)\n\n",
6140 show_database_desc
[type
],
6141 ospf_area_desc_string(area
));
6142 vty_out(vty
, "%s\n",
6143 show_database_header
[type
]);
6145 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6146 show_lsa_summary(vty
, lsa
, self
);
6153 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6155 case OSPF_AS_EXTERNAL_LSA
:
6156 case OSPF_OPAQUE_AS_LSA
:
6161 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6162 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6163 vty_out(vty
, " %s\n\n",
6164 show_database_desc
[type
]);
6165 vty_out(vty
, "%s\n", show_database_header
[type
]);
6167 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6168 show_lsa_summary(vty
, lsa
, self
);
6177 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6179 struct route_node
*rn
;
6181 vty_out(vty
, "\n MaxAge Link States:\n\n");
6183 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6184 struct ospf_lsa
*lsa
;
6186 if ((lsa
= rn
->info
) != NULL
) {
6187 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6188 vty_out(vty
, "Link State ID: %s\n",
6189 inet_ntoa(lsa
->data
->id
));
6190 vty_out(vty
, "Advertising Router: %s\n",
6191 inet_ntoa(lsa
->data
->adv_router
));
6192 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6198 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6199 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6201 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6202 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6203 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6204 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6206 #define OSPF_LSA_TYPES_DESC \
6207 "ASBR summary link states\n" \
6208 "External link states\n" \
6209 "Network link states\n" \
6210 "Router link states\n" \
6211 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6212 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6213 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6215 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6216 int arg_base
, int argc
,
6217 struct cmd_token
**argv
,
6222 struct in_addr id
, adv_router
;
6225 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6227 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6229 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6230 inet_ntoa(ospf
->router_id
));
6233 if (argc
== arg_base
+ 4) {
6234 show_ip_ospf_database_summary(vty
, ospf
, 0);
6238 /* Set database type to show. */
6239 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6240 type
= OSPF_ROUTER_LSA
;
6241 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6242 type
= OSPF_NETWORK_LSA
;
6243 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6244 type
= OSPF_AS_NSSA_LSA
;
6245 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6246 type
= OSPF_SUMMARY_LSA
;
6247 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6248 type
= OSPF_ASBR_SUMMARY_LSA
;
6249 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6250 type
= OSPF_AS_EXTERNAL_LSA
;
6251 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6252 show_ip_ospf_database_summary(vty
, ospf
, 1);
6254 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6255 show_ip_ospf_database_maxage(vty
, ospf
);
6257 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6258 type
= OSPF_OPAQUE_LINK_LSA
;
6259 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6260 type
= OSPF_OPAQUE_AREA_LSA
;
6261 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6262 type
= OSPF_OPAQUE_AS_LSA
;
6266 /* `show ip ospf database LSA'. */
6267 if (argc
== arg_base
+ 5)
6268 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6269 else if (argc
>= arg_base
+ 6) {
6270 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6274 /* `show ip ospf database LSA ID'. */
6275 if (argc
== arg_base
+ 6)
6276 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6277 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6278 else if (argc
== arg_base
+ 7) {
6279 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6280 adv_router
= ospf
->router_id
;
6282 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6287 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6294 DEFUN (show_ip_ospf_database_max
,
6295 show_ip_ospf_database_max_cmd
,
6296 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6299 "OSPF information\n"
6302 "Database summary\n"
6303 "LSAs in MaxAge list\n"
6304 "Self-originated link states\n")
6306 struct ospf
*ospf
= NULL
;
6307 struct listnode
*node
= NULL
;
6308 char *vrf_name
= NULL
;
6309 bool all_vrf
= FALSE
;
6310 int ret
= CMD_SUCCESS
;
6313 uint8_t use_vrf
= 0;
6315 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6320 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6321 if (!ospf
->oi_running
)
6323 ret
= show_ip_ospf_database_common(
6324 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6328 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6329 if (ospf
== NULL
|| !ospf
->oi_running
)
6331 ret
= (show_ip_ospf_database_common(
6332 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6336 /* Display default ospf (instance 0) info */
6337 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6338 if (ospf
== NULL
|| !ospf
->oi_running
)
6340 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6347 DEFUN (show_ip_ospf_instance_database
,
6348 show_ip_ospf_instance_database_cmd
,
6349 "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>]]]",
6352 "OSPF information\n"
6355 "Database summary\n"
6357 "Link State ID (as an IP address)\n"
6358 "Self-originated link states\n"
6359 "Advertising Router link states\n"
6360 "Advertising Router (as an IP address)\n")
6363 unsigned short instance
= 0;
6364 struct listnode
*node
= NULL
;
6365 char *vrf_name
= NULL
;
6366 bool all_vrf
= FALSE
;
6367 int ret
= CMD_SUCCESS
;
6370 uint8_t use_vrf
= 0;
6372 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6373 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6374 ospf
= ospf_lookup_instance(instance
);
6376 return CMD_NOT_MY_INSTANCE
;
6377 if (!ospf
->oi_running
)
6380 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6381 argc
, argv
, use_vrf
));
6382 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6383 vrf_name
= argv
[++idx
]->arg
;
6384 all_vrf
= strmatch(vrf_name
, "all");
6390 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6391 if (!ospf
->oi_running
)
6393 ret
= (show_ip_ospf_database_common(
6394 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6398 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6399 if ((ospf
== NULL
) || !ospf
->oi_running
)
6401 ret
= (show_ip_ospf_database_common(
6402 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6405 /* Display default ospf (instance 0) info */
6406 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6407 if (ospf
== NULL
|| !ospf
->oi_running
)
6409 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6416 DEFUN (show_ip_ospf_instance_database_max
,
6417 show_ip_ospf_instance_database_max_cmd
,
6418 "show ip ospf (1-65535) database <max-age|self-originate>",
6421 "OSPF information\n"
6423 "Database summary\n"
6424 "LSAs in MaxAge list\n"
6425 "Self-originated link states\n")
6429 unsigned short instance
= 0;
6431 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6433 ospf
= ospf_lookup_instance(instance
);
6435 return CMD_NOT_MY_INSTANCE
;
6437 if (!ospf
->oi_running
)
6440 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6444 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6446 int arg_base
, int argc
,
6447 struct cmd_token
**argv
,
6452 struct in_addr adv_router
;
6455 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6457 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6459 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6460 inet_ntoa(ospf
->router_id
));
6462 /* Set database type to show. */
6463 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6464 type
= OSPF_ROUTER_LSA
;
6465 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6466 type
= OSPF_NETWORK_LSA
;
6467 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6468 type
= OSPF_AS_NSSA_LSA
;
6469 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6470 type
= OSPF_SUMMARY_LSA
;
6471 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6472 type
= OSPF_ASBR_SUMMARY_LSA
;
6473 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6474 type
= OSPF_AS_EXTERNAL_LSA
;
6475 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6476 type
= OSPF_OPAQUE_LINK_LSA
;
6477 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6478 type
= OSPF_OPAQUE_AREA_LSA
;
6479 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6480 type
= OSPF_OPAQUE_AS_LSA
;
6484 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6485 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6486 adv_router
= ospf
->router_id
;
6488 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6493 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6498 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6499 show_ip_ospf_instance_database_type_adv_router_cmd
,
6500 "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>",
6503 "OSPF information\n"
6506 "Database summary\n"
6508 "Advertising Router link states\n"
6509 "Advertising Router (as an IP address)\n"
6510 "Self-originated link states\n")
6512 struct ospf
*ospf
= NULL
;
6513 unsigned short instance
= 0;
6514 struct listnode
*node
= NULL
;
6515 char *vrf_name
= NULL
;
6516 bool all_vrf
= FALSE
;
6517 int ret
= CMD_SUCCESS
;
6519 int idx
= 0, idx_vrf
= 0;
6520 uint8_t use_vrf
= 0;
6522 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6523 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6524 ospf
= ospf_lookup_instance(instance
);
6526 return CMD_NOT_MY_INSTANCE
;
6527 if (!ospf
->oi_running
)
6529 return (show_ip_ospf_database_type_adv_router_common(
6530 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6533 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6538 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6539 if (!ospf
->oi_running
)
6541 ret
= show_ip_ospf_database_type_adv_router_common(
6542 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6546 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6547 if ((ospf
== NULL
) || !ospf
->oi_running
)
6549 ret
= show_ip_ospf_database_type_adv_router_common(
6550 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6553 /* Display default ospf (instance 0) info */
6554 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6555 if (ospf
== NULL
|| !ospf
->oi_running
)
6557 ret
= show_ip_ospf_database_type_adv_router_common(
6558 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6561 /*return (show_ip_ospf_database_type_adv_router_common(
6562 vty, ospf, idx ? 1 : 0, argc, argv));*/
6565 DEFUN (ip_ospf_authentication_args
,
6566 ip_ospf_authentication_args_addr_cmd
,
6567 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6569 "OSPF interface commands\n"
6570 "Enable authentication on this interface\n"
6571 "Use null authentication\n"
6572 "Use message-digest authentication\n"
6573 "Address of interface\n")
6575 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6576 int idx_encryption
= 3;
6578 struct in_addr addr
;
6580 struct ospf_if_params
*params
;
6582 params
= IF_DEF_PARAMS(ifp
);
6585 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6588 "Please specify interface address by A.B.C.D\n");
6589 return CMD_WARNING_CONFIG_FAILED
;
6592 params
= ospf_get_if_params(ifp
, addr
);
6593 ospf_if_update_params(ifp
, addr
);
6596 /* Handle null authentication */
6597 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6598 SET_IF_PARAM(params
, auth_type
);
6599 params
->auth_type
= OSPF_AUTH_NULL
;
6603 /* Handle message-digest authentication */
6604 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6605 SET_IF_PARAM(params
, auth_type
);
6606 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6610 vty_out(vty
, "You shouldn't get here!\n");
6611 return CMD_WARNING_CONFIG_FAILED
;
6614 DEFUN (ip_ospf_authentication
,
6615 ip_ospf_authentication_addr_cmd
,
6616 "ip ospf authentication [A.B.C.D]",
6618 "OSPF interface commands\n"
6619 "Enable authentication on this interface\n"
6620 "Address of interface\n")
6622 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6624 struct in_addr addr
;
6626 struct ospf_if_params
*params
;
6628 params
= IF_DEF_PARAMS(ifp
);
6631 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6634 "Please specify interface address by A.B.C.D\n");
6635 return CMD_WARNING_CONFIG_FAILED
;
6638 params
= ospf_get_if_params(ifp
, addr
);
6639 ospf_if_update_params(ifp
, addr
);
6642 SET_IF_PARAM(params
, auth_type
);
6643 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6648 DEFUN (no_ip_ospf_authentication_args
,
6649 no_ip_ospf_authentication_args_addr_cmd
,
6650 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6653 "OSPF interface commands\n"
6654 "Enable authentication on this interface\n"
6655 "Use null authentication\n"
6656 "Use message-digest authentication\n"
6657 "Address of interface\n")
6659 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6660 int idx_encryption
= 4;
6662 struct in_addr addr
;
6664 struct ospf_if_params
*params
;
6665 struct route_node
*rn
;
6668 params
= IF_DEF_PARAMS(ifp
);
6671 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6674 "Please specify interface address by A.B.C.D\n");
6675 return CMD_WARNING_CONFIG_FAILED
;
6678 params
= ospf_lookup_if_params(ifp
, addr
);
6679 if (params
== NULL
) {
6680 vty_out(vty
, "Ip Address specified is unknown\n");
6681 return CMD_WARNING_CONFIG_FAILED
;
6683 params
->auth_type
= OSPF_AUTH_NOTSET
;
6684 UNSET_IF_PARAM(params
, auth_type
);
6685 if (params
!= IF_DEF_PARAMS(ifp
)) {
6686 ospf_free_if_params(ifp
, addr
);
6687 ospf_if_update_params(ifp
, addr
);
6690 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6691 auth_type
= OSPF_AUTH_NULL
;
6692 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6693 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6695 vty_out(vty
, "Unexpected input encountered\n");
6696 return CMD_WARNING_CONFIG_FAILED
;
6699 * Here we have a case where the user has entered
6700 * 'no ip ospf authentication (null | message_digest )'
6701 * we need to find if we have any ip addresses underneath it
6703 * correspond to the associated type.
6705 if (params
->auth_type
== auth_type
) {
6706 params
->auth_type
= OSPF_AUTH_NOTSET
;
6707 UNSET_IF_PARAM(params
, auth_type
);
6710 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6711 rn
= route_next(rn
)) {
6712 if ((params
= rn
->info
)) {
6713 if (params
->auth_type
== auth_type
) {
6714 params
->auth_type
= OSPF_AUTH_NOTSET
;
6715 UNSET_IF_PARAM(params
, auth_type
);
6716 if (params
!= IF_DEF_PARAMS(ifp
)) {
6717 ospf_free_if_params(
6718 ifp
, rn
->p
.u
.prefix4
);
6719 ospf_if_update_params(
6720 ifp
, rn
->p
.u
.prefix4
);
6730 DEFUN (no_ip_ospf_authentication
,
6731 no_ip_ospf_authentication_addr_cmd
,
6732 "no ip ospf authentication [A.B.C.D]",
6735 "OSPF interface commands\n"
6736 "Enable authentication on this interface\n"
6737 "Address of interface\n")
6739 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6741 struct in_addr addr
;
6743 struct ospf_if_params
*params
;
6744 struct route_node
*rn
;
6746 params
= IF_DEF_PARAMS(ifp
);
6749 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6752 "Please specify interface address by A.B.C.D\n");
6753 return CMD_WARNING_CONFIG_FAILED
;
6756 params
= ospf_lookup_if_params(ifp
, addr
);
6757 if (params
== NULL
) {
6758 vty_out(vty
, "Ip Address specified is unknown\n");
6759 return CMD_WARNING_CONFIG_FAILED
;
6762 params
->auth_type
= OSPF_AUTH_NOTSET
;
6763 UNSET_IF_PARAM(params
, auth_type
);
6764 if (params
!= IF_DEF_PARAMS(ifp
)) {
6765 ospf_free_if_params(ifp
, addr
);
6766 ospf_if_update_params(ifp
, addr
);
6770 * When a user enters 'no ip ospf authentication'
6771 * We should remove all authentication types from
6774 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6775 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6776 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6777 params
->auth_type
= OSPF_AUTH_NOTSET
;
6778 UNSET_IF_PARAM(params
, auth_type
);
6781 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6782 rn
= route_next(rn
)) {
6783 if ((params
= rn
->info
)) {
6785 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6786 || (params
->auth_type
6787 == OSPF_AUTH_CRYPTOGRAPHIC
)
6788 || (params
->auth_type
6789 == OSPF_AUTH_SIMPLE
)) {
6790 params
->auth_type
= OSPF_AUTH_NOTSET
;
6791 UNSET_IF_PARAM(params
, auth_type
);
6792 if (params
!= IF_DEF_PARAMS(ifp
)) {
6793 ospf_free_if_params(
6794 ifp
, rn
->p
.u
.prefix4
);
6795 ospf_if_update_params(
6796 ifp
, rn
->p
.u
.prefix4
);
6807 DEFUN (ip_ospf_authentication_key
,
6808 ip_ospf_authentication_key_addr_cmd
,
6809 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6811 "OSPF interface commands\n"
6812 "Authentication password (key)\n"
6813 "The OSPF password (key)\n"
6814 "Address of interface\n")
6816 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6818 struct in_addr addr
;
6819 struct ospf_if_params
*params
;
6821 params
= IF_DEF_PARAMS(ifp
);
6823 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6824 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6826 "Please specify interface address by A.B.C.D\n");
6827 return CMD_WARNING_CONFIG_FAILED
;
6830 params
= ospf_get_if_params(ifp
, addr
);
6831 ospf_if_update_params(ifp
, addr
);
6834 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6835 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6836 OSPF_AUTH_SIMPLE_SIZE
);
6837 SET_IF_PARAM(params
, auth_simple
);
6842 DEFUN_HIDDEN (ospf_authentication_key
,
6843 ospf_authentication_key_cmd
,
6844 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6845 "OSPF interface commands\n"
6846 VLINK_HELPSTR_AUTH_SIMPLE
6847 "Address of interface\n")
6849 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6852 DEFUN (no_ip_ospf_authentication_key
,
6853 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6854 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6857 "OSPF interface commands\n"
6858 VLINK_HELPSTR_AUTH_SIMPLE
6859 "Address of interface\n")
6861 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6863 struct in_addr addr
;
6864 struct ospf_if_params
*params
;
6865 params
= IF_DEF_PARAMS(ifp
);
6867 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6868 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6870 "Please specify interface address by A.B.C.D\n");
6871 return CMD_WARNING_CONFIG_FAILED
;
6874 params
= ospf_lookup_if_params(ifp
, addr
);
6879 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6880 UNSET_IF_PARAM(params
, auth_simple
);
6882 if (params
!= IF_DEF_PARAMS(ifp
)) {
6883 ospf_free_if_params(ifp
, addr
);
6884 ospf_if_update_params(ifp
, addr
);
6890 DEFUN_HIDDEN (no_ospf_authentication_key
,
6891 no_ospf_authentication_key_authkey_addr_cmd
,
6892 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6894 "OSPF interface commands\n"
6895 VLINK_HELPSTR_AUTH_SIMPLE
6896 "Address of interface\n")
6898 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6901 DEFUN (ip_ospf_message_digest_key
,
6902 ip_ospf_message_digest_key_cmd
,
6903 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6905 "OSPF interface commands\n"
6906 "Message digest authentication password (key)\n"
6908 "Use MD5 algorithm\n"
6909 "The OSPF password (key)\n"
6910 "Address of interface\n")
6912 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6913 struct crypt_key
*ck
;
6915 struct in_addr addr
;
6916 struct ospf_if_params
*params
;
6918 params
= IF_DEF_PARAMS(ifp
);
6921 argv_find(argv
, argc
, "(1-255)", &idx
);
6922 char *keyid
= argv
[idx
]->arg
;
6923 argv_find(argv
, argc
, "KEY", &idx
);
6924 char *cryptkey
= argv
[idx
]->arg
;
6926 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6927 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6929 "Please specify interface address by A.B.C.D\n");
6930 return CMD_WARNING_CONFIG_FAILED
;
6933 params
= ospf_get_if_params(ifp
, addr
);
6934 ospf_if_update_params(ifp
, addr
);
6937 key_id
= strtol(keyid
, NULL
, 10);
6938 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
6939 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
6943 ck
= ospf_crypt_key_new();
6944 ck
->key_id
= (uint8_t)key_id
;
6945 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
6946 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
6948 ospf_crypt_key_add(params
->auth_crypt
, ck
);
6949 SET_IF_PARAM(params
, auth_crypt
);
6954 DEFUN_HIDDEN (ospf_message_digest_key
,
6955 ospf_message_digest_key_cmd
,
6956 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6957 "OSPF interface commands\n"
6958 "Message digest authentication password (key)\n"
6960 "Use MD5 algorithm\n"
6961 "The OSPF password (key)\n"
6962 "Address of interface\n")
6964 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
6967 DEFUN (no_ip_ospf_message_digest_key
,
6968 no_ip_ospf_message_digest_key_cmd
,
6969 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6972 "OSPF interface commands\n"
6973 "Message digest authentication password (key)\n"
6975 "Use MD5 algorithm\n"
6976 "The OSPF password (key)\n"
6977 "Address of interface\n")
6979 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6981 struct crypt_key
*ck
;
6983 struct in_addr addr
;
6984 struct ospf_if_params
*params
;
6985 params
= IF_DEF_PARAMS(ifp
);
6987 argv_find(argv
, argc
, "(1-255)", &idx
);
6988 char *keyid
= argv
[idx
]->arg
;
6990 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6991 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6993 "Please specify interface address by A.B.C.D\n");
6994 return CMD_WARNING_CONFIG_FAILED
;
6997 params
= ospf_lookup_if_params(ifp
, addr
);
7002 key_id
= strtol(keyid
, NULL
, 10);
7003 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7005 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7006 return CMD_WARNING_CONFIG_FAILED
;
7009 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7011 if (params
!= IF_DEF_PARAMS(ifp
)) {
7012 ospf_free_if_params(ifp
, addr
);
7013 ospf_if_update_params(ifp
, addr
);
7019 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7020 no_ospf_message_digest_key_cmd
,
7021 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7023 "OSPF interface commands\n"
7024 "Message digest authentication password (key)\n"
7026 "Use MD5 algorithm\n"
7027 "The OSPF password (key)\n"
7028 "Address of interface\n")
7030 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7033 DEFUN (ip_ospf_cost
,
7035 "ip ospf cost (1-65535) [A.B.C.D]",
7037 "OSPF interface commands\n"
7040 "Address of interface\n")
7042 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7044 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7045 struct in_addr addr
;
7046 struct ospf_if_params
*params
;
7047 params
= IF_DEF_PARAMS(ifp
);
7050 char *coststr
= NULL
, *ifaddr
= NULL
;
7052 argv_find(argv
, argc
, "(1-65535)", &idx
);
7053 coststr
= argv
[idx
]->arg
;
7054 cost
= strtol(coststr
, NULL
, 10);
7056 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7058 if (!inet_aton(ifaddr
, &addr
)) {
7060 "Please specify interface address by A.B.C.D\n");
7061 return CMD_WARNING_CONFIG_FAILED
;
7064 params
= ospf_get_if_params(ifp
, addr
);
7065 ospf_if_update_params(ifp
, addr
);
7068 SET_IF_PARAM(params
, output_cost_cmd
);
7069 params
->output_cost_cmd
= cost
;
7071 ospf_if_recalculate_output_cost(ifp
);
7076 DEFUN_HIDDEN (ospf_cost
,
7078 "ospf cost (1-65535) [A.B.C.D]",
7079 "OSPF interface commands\n"
7082 "Address of interface\n")
7084 return ip_ospf_cost(self
, vty
, argc
, argv
);
7087 DEFUN (no_ip_ospf_cost
,
7088 no_ip_ospf_cost_cmd
,
7089 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7092 "OSPF interface commands\n"
7095 "Address of interface\n")
7097 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7099 struct in_addr addr
;
7100 struct ospf_if_params
*params
;
7102 params
= IF_DEF_PARAMS(ifp
);
7105 char *ifaddr
= NULL
;
7106 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7108 /* According to the semantics we are mimicking "no ip ospf cost N" is
7109 * always treated as "no ip ospf cost" regardless of the actual value
7110 * of N already configured for the interface. Thus ignore cost. */
7113 if (!inet_aton(ifaddr
, &addr
)) {
7115 "Please specify interface address by A.B.C.D\n");
7116 return CMD_WARNING_CONFIG_FAILED
;
7119 params
= ospf_lookup_if_params(ifp
, addr
);
7124 UNSET_IF_PARAM(params
, output_cost_cmd
);
7126 if (params
!= IF_DEF_PARAMS(ifp
)) {
7127 ospf_free_if_params(ifp
, addr
);
7128 ospf_if_update_params(ifp
, addr
);
7131 ospf_if_recalculate_output_cost(ifp
);
7136 DEFUN_HIDDEN (no_ospf_cost
,
7138 "no ospf cost [(1-65535)] [A.B.C.D]",
7140 "OSPF interface commands\n"
7143 "Address of interface\n")
7145 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7148 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7150 struct route_node
*rn
;
7151 struct ospf_neighbor
*nbr
;
7153 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7154 if ((nbr
= rn
->info
)) {
7155 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7156 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7157 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7158 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7162 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7163 const char *nbr_str
,
7164 const char *fast_hello_str
)
7166 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7169 struct in_addr addr
;
7171 struct ospf_if_params
*params
;
7172 struct ospf_interface
*oi
;
7173 struct route_node
*rn
;
7175 params
= IF_DEF_PARAMS(ifp
);
7178 ret
= inet_aton(nbr_str
, &addr
);
7181 "Please specify interface address by A.B.C.D\n");
7182 return CMD_WARNING_CONFIG_FAILED
;
7185 params
= ospf_get_if_params(ifp
, addr
);
7186 ospf_if_update_params(ifp
, addr
);
7190 seconds
= strtoul(interval_str
, NULL
, 10);
7192 /* reset fast_hello too, just to be sure */
7193 UNSET_IF_PARAM(params
, fast_hello
);
7194 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7195 } else if (fast_hello_str
) {
7196 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7197 /* 1s dead-interval with sub-second hellos desired */
7198 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7199 SET_IF_PARAM(params
, fast_hello
);
7200 params
->fast_hello
= hellomult
;
7203 "Please specify dead-interval or hello-multiplier\n");
7204 return CMD_WARNING_CONFIG_FAILED
;
7207 SET_IF_PARAM(params
, v_wait
);
7208 params
->v_wait
= seconds
;
7210 /* Update timer values in neighbor structure. */
7212 struct ospf
*ospf
= NULL
;
7214 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7216 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7218 ospf_nbr_timer_update(oi
);
7221 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7222 if ((oi
= rn
->info
))
7223 ospf_nbr_timer_update(oi
);
7229 DEFUN (ip_ospf_dead_interval
,
7230 ip_ospf_dead_interval_cmd
,
7231 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7233 "OSPF interface commands\n"
7234 "Interval time after which a neighbor is declared down\n"
7236 "Address of interface\n")
7239 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7243 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7244 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7248 DEFUN_HIDDEN (ospf_dead_interval
,
7249 ospf_dead_interval_cmd
,
7250 "ospf dead-interval (1-65535) [A.B.C.D]",
7251 "OSPF interface commands\n"
7252 "Interval time after which a neighbor is declared down\n"
7254 "Address of interface\n")
7256 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7259 DEFUN (ip_ospf_dead_interval_minimal
,
7260 ip_ospf_dead_interval_minimal_addr_cmd
,
7261 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7263 "OSPF interface commands\n"
7264 "Interval time after which a neighbor is declared down\n"
7265 "Minimal 1s dead-interval with fast sub-second hellos\n"
7266 "Hello multiplier factor\n"
7267 "Number of Hellos to send each second\n"
7268 "Address of interface\n")
7273 return ospf_vty_dead_interval_set(
7274 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7276 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7277 argv
[idx_number
]->arg
);
7280 DEFUN (no_ip_ospf_dead_interval
,
7281 no_ip_ospf_dead_interval_cmd
,
7282 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7285 "OSPF interface commands\n"
7286 "Interval time after which a neighbor is declared down\n"
7288 "Minimal 1s dead-interval with fast sub-second hellos\n"
7289 "Hello multiplier factor\n"
7290 "Number of Hellos to send each second\n"
7291 "Address of interface\n")
7293 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7294 int idx_ipv4
= argc
- 1;
7295 struct in_addr addr
= {.s_addr
= 0L};
7297 struct ospf_if_params
*params
;
7298 struct ospf_interface
*oi
;
7299 struct route_node
*rn
;
7301 params
= IF_DEF_PARAMS(ifp
);
7303 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7304 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7307 "Please specify interface address by A.B.C.D\n");
7308 return CMD_WARNING_CONFIG_FAILED
;
7311 params
= ospf_lookup_if_params(ifp
, addr
);
7316 UNSET_IF_PARAM(params
, v_wait
);
7317 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7319 UNSET_IF_PARAM(params
, fast_hello
);
7320 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7322 if (params
!= IF_DEF_PARAMS(ifp
)) {
7323 ospf_free_if_params(ifp
, addr
);
7324 ospf_if_update_params(ifp
, addr
);
7327 /* Update timer values in neighbor structure. */
7329 struct ospf
*ospf
= NULL
;
7331 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7333 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7335 ospf_nbr_timer_update(oi
);
7338 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7339 if ((oi
= rn
->info
))
7340 ospf_nbr_timer_update(oi
);
7346 DEFUN_HIDDEN (no_ospf_dead_interval
,
7347 no_ospf_dead_interval_cmd
,
7348 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7350 "OSPF interface commands\n"
7351 "Interval time after which a neighbor is declared down\n"
7353 "Minimal 1s dead-interval with fast sub-second hellos\n"
7354 "Hello multiplier factor\n"
7355 "Number of Hellos to send each second\n"
7356 "Address of interface\n")
7358 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7361 DEFUN (ip_ospf_hello_interval
,
7362 ip_ospf_hello_interval_cmd
,
7363 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7365 "OSPF interface commands\n"
7366 "Time between HELLO packets\n"
7368 "Address of interface\n")
7370 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7372 struct in_addr addr
;
7373 struct ospf_if_params
*params
;
7374 params
= IF_DEF_PARAMS(ifp
);
7375 uint32_t seconds
= 0;
7377 argv_find(argv
, argc
, "(1-65535)", &idx
);
7378 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7380 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7381 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7383 "Please specify interface address by A.B.C.D\n");
7384 return CMD_WARNING_CONFIG_FAILED
;
7387 params
= ospf_get_if_params(ifp
, addr
);
7388 ospf_if_update_params(ifp
, addr
);
7391 SET_IF_PARAM(params
, v_hello
);
7392 params
->v_hello
= seconds
;
7397 DEFUN_HIDDEN (ospf_hello_interval
,
7398 ospf_hello_interval_cmd
,
7399 "ospf hello-interval (1-65535) [A.B.C.D]",
7400 "OSPF interface commands\n"
7401 "Time between HELLO packets\n"
7403 "Address of interface\n")
7405 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7408 DEFUN (no_ip_ospf_hello_interval
,
7409 no_ip_ospf_hello_interval_cmd
,
7410 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7413 "OSPF interface commands\n"
7414 "Time between HELLO packets\n" // ignored
7416 "Address of interface\n")
7418 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7420 struct in_addr addr
;
7421 struct ospf_if_params
*params
;
7423 params
= IF_DEF_PARAMS(ifp
);
7425 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7426 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7428 "Please specify interface address by A.B.C.D\n");
7429 return CMD_WARNING_CONFIG_FAILED
;
7432 params
= ospf_lookup_if_params(ifp
, addr
);
7437 UNSET_IF_PARAM(params
, v_hello
);
7438 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7440 if (params
!= IF_DEF_PARAMS(ifp
)) {
7441 ospf_free_if_params(ifp
, addr
);
7442 ospf_if_update_params(ifp
, addr
);
7448 DEFUN_HIDDEN (no_ospf_hello_interval
,
7449 no_ospf_hello_interval_cmd
,
7450 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7452 "OSPF interface commands\n"
7453 "Time between HELLO packets\n" // ignored
7455 "Address of interface\n")
7457 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7460 DEFUN (ip_ospf_network
,
7461 ip_ospf_network_cmd
,
7462 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7464 "OSPF interface commands\n"
7466 "Specify OSPF broadcast multi-access network\n"
7467 "Specify OSPF NBMA network\n"
7468 "Specify OSPF point-to-multipoint network\n"
7469 "Specify OSPF point-to-point network\n")
7471 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7473 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7474 struct route_node
*rn
;
7476 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7478 "This is a loopback interface. Can't set network type.\n");
7479 return CMD_WARNING_CONFIG_FAILED
;
7482 if (argv_find(argv
, argc
, "broadcast", &idx
))
7483 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7484 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7485 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7486 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7487 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7488 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7489 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7491 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7494 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7496 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7497 struct ospf_interface
*oi
= rn
->info
;
7502 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7504 if (oi
->state
> ISM_Down
) {
7505 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7506 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7513 DEFUN_HIDDEN (ospf_network
,
7515 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7516 "OSPF interface commands\n"
7518 "Specify OSPF broadcast multi-access network\n"
7519 "Specify OSPF NBMA network\n"
7520 "Specify OSPF point-to-multipoint network\n"
7521 "Specify OSPF point-to-point network\n")
7523 return ip_ospf_network(self
, vty
, argc
, argv
);
7526 DEFUN (no_ip_ospf_network
,
7527 no_ip_ospf_network_cmd
,
7528 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7531 "OSPF interface commands\n"
7533 "Specify OSPF broadcast multi-access network\n"
7534 "Specify OSPF NBMA network\n"
7535 "Specify OSPF point-to-multipoint network\n"
7536 "Specify OSPF point-to-point network\n")
7538 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7539 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7540 struct route_node
*rn
;
7542 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7544 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7547 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7548 struct ospf_interface
*oi
= rn
->info
;
7553 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7555 if (oi
->state
> ISM_Down
) {
7556 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7557 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7564 DEFUN_HIDDEN (no_ospf_network
,
7565 no_ospf_network_cmd
,
7566 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7568 "OSPF interface commands\n"
7570 "Specify OSPF broadcast multi-access network\n"
7571 "Specify OSPF NBMA network\n"
7572 "Specify OSPF point-to-multipoint network\n"
7573 "Specify OSPF point-to-point network\n")
7575 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7578 DEFUN (ip_ospf_priority
,
7579 ip_ospf_priority_cmd
,
7580 "ip ospf priority (0-255) [A.B.C.D]",
7582 "OSPF interface commands\n"
7585 "Address of interface\n")
7587 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7590 struct route_node
*rn
;
7591 struct in_addr addr
;
7592 struct ospf_if_params
*params
;
7593 params
= IF_DEF_PARAMS(ifp
);
7595 argv_find(argv
, argc
, "(0-255)", &idx
);
7596 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7598 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7599 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7601 "Please specify interface address by A.B.C.D\n");
7602 return CMD_WARNING_CONFIG_FAILED
;
7605 params
= ospf_get_if_params(ifp
, addr
);
7606 ospf_if_update_params(ifp
, addr
);
7609 SET_IF_PARAM(params
, priority
);
7610 params
->priority
= priority
;
7612 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7613 struct ospf_interface
*oi
= rn
->info
;
7618 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7619 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7620 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7627 DEFUN_HIDDEN (ospf_priority
,
7629 "ospf priority (0-255) [A.B.C.D]",
7630 "OSPF interface commands\n"
7633 "Address of interface\n")
7635 return ip_ospf_priority(self
, vty
, argc
, argv
);
7638 DEFUN (no_ip_ospf_priority
,
7639 no_ip_ospf_priority_cmd
,
7640 "no ip ospf priority [(0-255) [A.B.C.D]]",
7643 "OSPF interface commands\n"
7644 "Router priority\n" // ignored
7646 "Address of interface\n")
7648 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7650 struct route_node
*rn
;
7651 struct in_addr addr
;
7652 struct ospf_if_params
*params
;
7654 params
= IF_DEF_PARAMS(ifp
);
7656 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7657 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7659 "Please specify interface address by A.B.C.D\n");
7660 return CMD_WARNING_CONFIG_FAILED
;
7663 params
= ospf_lookup_if_params(ifp
, addr
);
7668 UNSET_IF_PARAM(params
, priority
);
7669 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7671 if (params
!= IF_DEF_PARAMS(ifp
)) {
7672 ospf_free_if_params(ifp
, addr
);
7673 ospf_if_update_params(ifp
, addr
);
7676 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7677 struct ospf_interface
*oi
= rn
->info
;
7682 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7683 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7684 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7691 DEFUN_HIDDEN (no_ospf_priority
,
7692 no_ospf_priority_cmd
,
7693 "no ospf priority [(0-255) [A.B.C.D]]",
7695 "OSPF interface commands\n"
7698 "Address of interface\n")
7700 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7703 DEFUN (ip_ospf_retransmit_interval
,
7704 ip_ospf_retransmit_interval_addr_cmd
,
7705 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7707 "OSPF interface commands\n"
7708 "Time between retransmitting lost link state advertisements\n"
7710 "Address of interface\n")
7712 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7715 struct in_addr addr
;
7716 struct ospf_if_params
*params
;
7717 params
= IF_DEF_PARAMS(ifp
);
7719 argv_find(argv
, argc
, "(3-65535)", &idx
);
7720 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7722 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7723 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7725 "Please specify interface address by A.B.C.D\n");
7726 return CMD_WARNING_CONFIG_FAILED
;
7729 params
= ospf_get_if_params(ifp
, addr
);
7730 ospf_if_update_params(ifp
, addr
);
7733 SET_IF_PARAM(params
, retransmit_interval
);
7734 params
->retransmit_interval
= seconds
;
7739 DEFUN_HIDDEN (ospf_retransmit_interval
,
7740 ospf_retransmit_interval_cmd
,
7741 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7742 "OSPF interface commands\n"
7743 "Time between retransmitting lost link state advertisements\n"
7745 "Address of interface\n")
7747 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7750 DEFUN (no_ip_ospf_retransmit_interval
,
7751 no_ip_ospf_retransmit_interval_addr_cmd
,
7752 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7755 "OSPF interface commands\n"
7756 "Time between retransmitting lost link state advertisements\n"
7758 "Address of interface\n")
7760 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7762 struct in_addr addr
;
7763 struct ospf_if_params
*params
;
7765 params
= IF_DEF_PARAMS(ifp
);
7767 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7768 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7770 "Please specify interface address by A.B.C.D\n");
7771 return CMD_WARNING_CONFIG_FAILED
;
7774 params
= ospf_lookup_if_params(ifp
, addr
);
7779 UNSET_IF_PARAM(params
, retransmit_interval
);
7780 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7782 if (params
!= IF_DEF_PARAMS(ifp
)) {
7783 ospf_free_if_params(ifp
, addr
);
7784 ospf_if_update_params(ifp
, addr
);
7790 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7791 no_ospf_retransmit_interval_cmd
,
7792 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7794 "OSPF interface commands\n"
7795 "Time between retransmitting lost link state advertisements\n"
7797 "Address of interface\n")
7799 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7802 DEFUN (ip_ospf_transmit_delay
,
7803 ip_ospf_transmit_delay_addr_cmd
,
7804 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7806 "OSPF interface commands\n"
7807 "Link state transmit delay\n"
7809 "Address of interface\n")
7811 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7814 struct in_addr addr
;
7815 struct ospf_if_params
*params
;
7817 params
= IF_DEF_PARAMS(ifp
);
7818 argv_find(argv
, argc
, "(1-65535)", &idx
);
7819 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7821 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7822 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7824 "Please specify interface address by A.B.C.D\n");
7825 return CMD_WARNING_CONFIG_FAILED
;
7828 params
= ospf_get_if_params(ifp
, addr
);
7829 ospf_if_update_params(ifp
, addr
);
7832 SET_IF_PARAM(params
, transmit_delay
);
7833 params
->transmit_delay
= seconds
;
7838 DEFUN_HIDDEN (ospf_transmit_delay
,
7839 ospf_transmit_delay_cmd
,
7840 "ospf transmit-delay (1-65535) [A.B.C.D]",
7841 "OSPF interface commands\n"
7842 "Link state transmit delay\n"
7844 "Address of interface\n")
7846 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7849 DEFUN (no_ip_ospf_transmit_delay
,
7850 no_ip_ospf_transmit_delay_addr_cmd
,
7851 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7854 "OSPF interface commands\n"
7855 "Link state transmit delay\n"
7857 "Address of interface\n")
7859 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7861 struct in_addr addr
;
7862 struct ospf_if_params
*params
;
7864 params
= IF_DEF_PARAMS(ifp
);
7866 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7867 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7869 "Please specify interface address by A.B.C.D\n");
7870 return CMD_WARNING_CONFIG_FAILED
;
7873 params
= ospf_lookup_if_params(ifp
, addr
);
7878 UNSET_IF_PARAM(params
, transmit_delay
);
7879 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7881 if (params
!= IF_DEF_PARAMS(ifp
)) {
7882 ospf_free_if_params(ifp
, addr
);
7883 ospf_if_update_params(ifp
, addr
);
7890 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7891 no_ospf_transmit_delay_cmd
,
7892 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7894 "OSPF interface commands\n"
7895 "Link state transmit delay\n"
7897 "Address of interface\n")
7899 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7902 DEFUN (ip_ospf_area
,
7904 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7906 "OSPF interface commands\n"
7908 "Enable OSPF on this interface\n"
7909 "OSPF area ID in IP address format\n"
7910 "OSPF area ID as a decimal value\n"
7911 "Address of interface\n")
7913 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7916 struct in_addr area_id
;
7917 struct in_addr addr
;
7918 struct ospf_if_params
*params
= NULL
;
7919 struct route_node
*rn
;
7920 struct ospf
*ospf
= NULL
;
7921 unsigned short instance
= 0;
7924 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7925 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7927 argv_find(argv
, argc
, "area", &idx
);
7928 areaid
= argv
[idx
+ 1]->arg
;
7930 if (ifp
->vrf_id
&& !instance
)
7931 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7933 ospf
= ospf_lookup_instance(instance
);
7935 if (instance
&& ospf
== NULL
) {
7936 params
= IF_DEF_PARAMS(ifp
);
7937 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7938 UNSET_IF_PARAM(params
, if_area
);
7939 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7940 ospf_interface_area_unset(ospf
, ifp
);
7941 ospf
->if_ospf_cli_count
--;
7943 return CMD_NOT_MY_INSTANCE
;
7946 ret
= str2area_id(areaid
, &area_id
, &format
);
7948 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
7949 return CMD_WARNING_CONFIG_FAILED
;
7951 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
7952 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
7953 return CMD_WARNING_CONFIG_FAILED
;
7956 params
= IF_DEF_PARAMS(ifp
);
7957 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
7958 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
7960 "Must remove previous area config before changing ospf area \n");
7961 return CMD_WARNING_CONFIG_FAILED
;
7964 // Check if we have an address arg and proccess it
7965 if (argc
== idx
+ 3) {
7966 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
7968 "Please specify Intf Address by A.B.C.D\n");
7969 return CMD_WARNING_CONFIG_FAILED
;
7971 // update/create address-level params
7972 params
= ospf_get_if_params((ifp
), (addr
));
7973 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7975 "Must remove previous area/address config before changing ospf area");
7976 return CMD_WARNING_CONFIG_FAILED
;
7978 ospf_if_update_params((ifp
), (addr
));
7982 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
7983 if (rn
->info
!= NULL
) {
7985 "Please remove all network commands first.\n");
7986 return CMD_WARNING_CONFIG_FAILED
;
7991 /* enable ospf on this interface with area_id */
7993 SET_IF_PARAM(params
, if_area
);
7994 params
->if_area
= area_id
;
7995 params
->if_area_id_fmt
= format
;
7999 ospf_interface_area_set(ospf
, ifp
);
8000 ospf
->if_ospf_cli_count
++;
8006 DEFUN (no_ip_ospf_area
,
8007 no_ip_ospf_area_cmd
,
8008 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8011 "OSPF interface commands\n"
8013 "Disable OSPF on this interface\n"
8014 "OSPF area ID in IP address format\n"
8015 "OSPF area ID as a decimal value\n"
8016 "Address of interface\n")
8018 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8021 struct ospf_if_params
*params
;
8022 unsigned short instance
= 0;
8023 struct in_addr addr
;
8025 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8026 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8028 if (ifp
->vrf_id
&& !instance
)
8029 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8031 ospf
= ospf_lookup_instance(instance
);
8034 return CMD_NOT_MY_INSTANCE
;
8036 argv_find(argv
, argc
, "area", &idx
);
8038 // Check if we have an address arg and proccess it
8039 if (argc
== idx
+ 3) {
8040 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8042 "Please specify Intf Address by A.B.C.D\n");
8043 return CMD_WARNING_CONFIG_FAILED
;
8045 params
= ospf_lookup_if_params(ifp
, addr
);
8046 if ((params
) == NULL
)
8049 params
= IF_DEF_PARAMS(ifp
);
8051 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8053 "Can't find specified interface area configuration.\n");
8054 return CMD_WARNING_CONFIG_FAILED
;
8057 UNSET_IF_PARAM(params
, if_area
);
8058 if (params
!= IF_DEF_PARAMS((ifp
))) {
8059 ospf_free_if_params((ifp
), (addr
));
8060 ospf_if_update_params((ifp
), (addr
));
8063 ospf_interface_area_unset(ospf
, ifp
);
8064 ospf
->if_ospf_cli_count
--;
8068 DEFUN (ospf_redistribute_source
,
8069 ospf_redistribute_source_cmd
,
8070 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8072 FRR_REDIST_HELP_STR_OSPFD
8073 "Metric for redistributed routes\n"
8074 "OSPF default metric\n"
8075 "OSPF exterior metric type for redistributed routes\n"
8076 "Set OSPF External Type 1/2 metrics\n"
8077 "Route map reference\n"
8078 "Pointer to route-map entries\n")
8080 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8081 int idx_protocol
= 1;
8085 struct ospf_redist
*red
;
8088 /* Get distribute source. */
8089 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8091 return CMD_WARNING_CONFIG_FAILED
;
8093 red
= ospf_redist_add(ospf
, source
, 0);
8095 /* Get metric value. */
8096 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8097 if (!str2metric(argv
[idx
]->arg
, &metric
))
8098 return CMD_WARNING_CONFIG_FAILED
;
8101 /* Get metric type. */
8102 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8103 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8104 return CMD_WARNING_CONFIG_FAILED
;
8108 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8109 ospf_routemap_set(red
, argv
[idx
]->arg
);
8111 ospf_routemap_unset(red
);
8113 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8116 DEFUN (no_ospf_redistribute_source
,
8117 no_ospf_redistribute_source_cmd
,
8118 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8121 FRR_REDIST_HELP_STR_OSPFD
8122 "Metric for redistributed routes\n"
8123 "OSPF default metric\n"
8124 "OSPF exterior metric type for redistributed routes\n"
8125 "Set OSPF External Type 1/2 metrics\n"
8126 "Route map reference\n"
8127 "Pointer to route-map entries\n")
8129 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8130 int idx_protocol
= 2;
8132 struct ospf_redist
*red
;
8134 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8136 return CMD_WARNING_CONFIG_FAILED
;
8138 red
= ospf_redist_lookup(ospf
, source
, 0);
8142 ospf_routemap_unset(red
);
8143 return ospf_redistribute_unset(ospf
, source
, 0);
8146 DEFUN (ospf_redistribute_instance_source
,
8147 ospf_redistribute_instance_source_cmd
,
8148 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8150 "Open Shortest Path First\n"
8151 "Non-main Kernel Routing Table\n"
8152 "Instance ID/Table ID\n"
8153 "Metric for redistributed routes\n"
8154 "OSPF default metric\n"
8155 "OSPF exterior metric type for redistributed routes\n"
8156 "Set OSPF External Type 1/2 metrics\n"
8157 "Route map reference\n"
8158 "Pointer to route-map entries\n")
8160 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8161 int idx_ospf_table
= 1;
8167 unsigned short instance
;
8168 struct ospf_redist
*red
;
8170 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8173 vty_out(vty
, "Unknown instance redistribution\n");
8174 return CMD_WARNING_CONFIG_FAILED
;
8177 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8179 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8181 "Instance redistribution in non-instanced OSPF not allowed\n");
8182 return CMD_WARNING_CONFIG_FAILED
;
8185 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8186 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8187 return CMD_WARNING_CONFIG_FAILED
;
8190 /* Get metric value. */
8191 if (argv_find(argv
, argc
, "metric", &idx
))
8192 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8193 return CMD_WARNING_CONFIG_FAILED
;
8196 /* Get metric type. */
8197 if (argv_find(argv
, argc
, "metric-type", &idx
))
8198 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8199 return CMD_WARNING_CONFIG_FAILED
;
8201 red
= ospf_redist_add(ospf
, source
, instance
);
8204 if (argv_find(argv
, argc
, "route-map", &idx
))
8205 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8207 ospf_routemap_unset(red
);
8209 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8212 DEFUN (no_ospf_redistribute_instance_source
,
8213 no_ospf_redistribute_instance_source_cmd
,
8214 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8217 "Open Shortest Path First\n"
8218 "Non-main Kernel Routing Table\n"
8219 "Instance ID/Table Id\n"
8220 "Metric for redistributed routes\n"
8221 "OSPF default metric\n"
8222 "OSPF exterior metric type for redistributed routes\n"
8223 "Set OSPF External Type 1/2 metrics\n"
8224 "Route map reference\n"
8225 "Pointer to route-map entries\n")
8227 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8228 int idx_ospf_table
= 2;
8230 unsigned int instance
;
8231 struct ospf_redist
*red
;
8234 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8235 source
= ZEBRA_ROUTE_OSPF
;
8237 source
= ZEBRA_ROUTE_TABLE
;
8239 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8241 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8243 "Instance redistribution in non-instanced OSPF not allowed\n");
8244 return CMD_WARNING_CONFIG_FAILED
;
8247 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8248 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8249 return CMD_WARNING_CONFIG_FAILED
;
8252 red
= ospf_redist_lookup(ospf
, source
, instance
);
8256 ospf_routemap_unset(red
);
8257 return ospf_redistribute_unset(ospf
, source
, instance
);
8260 DEFUN (ospf_distribute_list_out
,
8261 ospf_distribute_list_out_cmd
,
8262 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8263 "Filter networks in routing updates\n"
8264 "Access-list name\n"
8266 FRR_REDIST_HELP_STR_OSPFD
)
8268 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8272 char *proto
= argv
[argc
- 1]->text
;
8274 /* Get distribute source. */
8275 source
= proto_redistnum(AFI_IP
, proto
);
8277 return CMD_WARNING_CONFIG_FAILED
;
8279 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8282 DEFUN (no_ospf_distribute_list_out
,
8283 no_ospf_distribute_list_out_cmd
,
8284 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8286 "Filter networks in routing updates\n"
8287 "Access-list name\n"
8289 FRR_REDIST_HELP_STR_OSPFD
)
8291 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8295 char *proto
= argv
[argc
- 1]->text
;
8296 source
= proto_redistnum(AFI_IP
, proto
);
8298 return CMD_WARNING_CONFIG_FAILED
;
8300 return ospf_distribute_list_out_unset(ospf
, source
,
8301 argv
[idx_word
]->arg
);
8304 /* Default information originate. */
8305 DEFUN (ospf_default_information_originate
,
8306 ospf_default_information_originate_cmd
,
8307 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8308 "Control distribution of default information\n"
8309 "Distribute a default route\n"
8310 "Always advertise default route\n"
8311 "OSPF default metric\n"
8313 "OSPF metric type for default routes\n"
8314 "Set OSPF External Type 1/2 metrics\n"
8315 "Route map reference\n"
8316 "Pointer to route-map entries\n")
8318 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8319 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8322 struct ospf_redist
*red
;
8325 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8327 /* Check whether "always" was specified */
8328 if (argv_find(argv
, argc
, "always", &idx
))
8329 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8331 /* Get metric value */
8332 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8333 if (!str2metric(argv
[idx
]->arg
, &metric
))
8334 return CMD_WARNING_CONFIG_FAILED
;
8337 /* Get metric type. */
8338 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8339 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8340 return CMD_WARNING_CONFIG_FAILED
;
8344 if (argv_find(argv
, argc
, "WORD", &idx
))
8345 ospf_routemap_set(red
, argv
[idx
]->arg
);
8347 ospf_routemap_unset(red
);
8349 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8353 DEFUN (no_ospf_default_information_originate
,
8354 no_ospf_default_information_originate_cmd
,
8355 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8357 "Control distribution of default information\n"
8358 "Distribute a default route\n"
8359 "Always advertise default route\n"
8360 "OSPF default metric\n"
8362 "OSPF metric type for default routes\n"
8363 "Set OSPF External Type 1/2 metrics\n"
8364 "Route map reference\n"
8365 "Pointer to route-map entries\n")
8367 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8368 struct prefix_ipv4 p
;
8369 struct ospf_external
*ext
;
8370 struct ospf_redist
*red
;
8373 p
.prefix
.s_addr
= 0;
8376 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8378 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8379 if (ext
&& EXTERNAL_INFO(ext
)) {
8380 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8381 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8384 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8388 ospf_routemap_unset(red
);
8389 return ospf_redistribute_default_unset(ospf
);
8392 DEFUN (ospf_default_metric
,
8393 ospf_default_metric_cmd
,
8394 "default-metric (0-16777214)",
8395 "Set metric of redistributed routes\n"
8398 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8402 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8403 return CMD_WARNING_CONFIG_FAILED
;
8405 ospf
->default_metric
= metric
;
8410 DEFUN (no_ospf_default_metric
,
8411 no_ospf_default_metric_cmd
,
8412 "no default-metric [(0-16777214)]",
8414 "Set metric of redistributed routes\n"
8417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8419 ospf
->default_metric
= -1;
8425 DEFUN (ospf_distance
,
8428 "Administrative distance\n"
8429 "OSPF Administrative distance\n")
8431 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8434 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8439 DEFUN (no_ospf_distance
,
8440 no_ospf_distance_cmd
,
8441 "no distance (1-255)",
8443 "Administrative distance\n"
8444 "OSPF Administrative distance\n")
8446 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8448 ospf
->distance_all
= 0;
8453 DEFUN (no_ospf_distance_ospf
,
8454 no_ospf_distance_ospf_cmd
,
8455 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8457 "Administrative distance\n"
8458 "OSPF administrative distance\n"
8459 "Intra-area routes\n"
8460 "Distance for intra-area routes\n"
8461 "Inter-area routes\n"
8462 "Distance for inter-area routes\n"
8464 "Distance for external routes\n")
8466 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8469 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8470 idx
= ospf
->distance_intra
= 0;
8471 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8472 idx
= ospf
->distance_inter
= 0;
8473 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8474 ospf
->distance_external
= 0;
8479 DEFUN (ospf_distance_ospf
,
8480 ospf_distance_ospf_cmd
,
8481 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8482 "Administrative distance\n"
8483 "OSPF administrative distance\n"
8484 "Intra-area routes\n"
8485 "Distance for intra-area routes\n"
8486 "Inter-area routes\n"
8487 "Distance for inter-area routes\n"
8489 "Distance for external routes\n")
8491 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8494 ospf
->distance_intra
= 0;
8495 ospf
->distance_inter
= 0;
8496 ospf
->distance_external
= 0;
8498 if (argv_find(argv
, argc
, "intra-area", &idx
))
8499 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8501 if (argv_find(argv
, argc
, "inter-area", &idx
))
8502 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8504 if (argv_find(argv
, argc
, "external", &idx
))
8505 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8511 DEFUN (ospf_distance_source
,
8512 ospf_distance_source_cmd
,
8513 "distance (1-255) A.B.C.D/M",
8514 "Administrative distance\n"
8516 "IP source prefix\n")
8518 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8520 int idx_ipv4_prefixlen
= 2;
8522 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8527 DEFUN (no_ospf_distance_source
,
8528 no_ospf_distance_source_cmd
,
8529 "no distance (1-255) A.B.C.D/M",
8531 "Administrative distance\n"
8533 "IP source prefix\n")
8535 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8537 int idx_ipv4_prefixlen
= 3;
8539 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8544 DEFUN (ospf_distance_source_access_list
,
8545 ospf_distance_source_access_list_cmd
,
8546 "distance (1-255) A.B.C.D/M WORD",
8547 "Administrative distance\n"
8549 "IP source prefix\n"
8550 "Access list name\n")
8552 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8554 int idx_ipv4_prefixlen
= 2;
8557 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8562 DEFUN (no_ospf_distance_source_access_list
,
8563 no_ospf_distance_source_access_list_cmd
,
8564 "no distance (1-255) A.B.C.D/M WORD",
8566 "Administrative distance\n"
8568 "IP source prefix\n"
8569 "Access list name\n")
8571 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8573 int idx_ipv4_prefixlen
= 3;
8576 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8582 DEFUN (ip_ospf_mtu_ignore
,
8583 ip_ospf_mtu_ignore_addr_cmd
,
8584 "ip ospf mtu-ignore [A.B.C.D]",
8586 "OSPF interface commands\n"
8587 "Disable MTU mismatch detection on this interface\n"
8588 "Address of interface\n")
8590 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8592 struct in_addr addr
;
8595 struct ospf_if_params
*params
;
8596 params
= IF_DEF_PARAMS(ifp
);
8599 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8602 "Please specify interface address by A.B.C.D\n");
8603 return CMD_WARNING_CONFIG_FAILED
;
8605 params
= ospf_get_if_params(ifp
, addr
);
8606 ospf_if_update_params(ifp
, addr
);
8608 params
->mtu_ignore
= 1;
8609 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8610 SET_IF_PARAM(params
, mtu_ignore
);
8612 UNSET_IF_PARAM(params
, mtu_ignore
);
8613 if (params
!= IF_DEF_PARAMS(ifp
)) {
8614 ospf_free_if_params(ifp
, addr
);
8615 ospf_if_update_params(ifp
, addr
);
8621 DEFUN (no_ip_ospf_mtu_ignore
,
8622 no_ip_ospf_mtu_ignore_addr_cmd
,
8623 "no ip ospf mtu-ignore [A.B.C.D]",
8626 "OSPF interface commands\n"
8627 "Disable MTU mismatch detection on this interface\n"
8628 "Address of interface\n")
8630 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8632 struct in_addr addr
;
8635 struct ospf_if_params
*params
;
8636 params
= IF_DEF_PARAMS(ifp
);
8639 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8642 "Please specify interface address by A.B.C.D\n");
8643 return CMD_WARNING_CONFIG_FAILED
;
8645 params
= ospf_get_if_params(ifp
, addr
);
8646 ospf_if_update_params(ifp
, addr
);
8648 params
->mtu_ignore
= 0;
8649 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8650 SET_IF_PARAM(params
, mtu_ignore
);
8652 UNSET_IF_PARAM(params
, mtu_ignore
);
8653 if (params
!= IF_DEF_PARAMS(ifp
)) {
8654 ospf_free_if_params(ifp
, addr
);
8655 ospf_if_update_params(ifp
, addr
);
8662 DEFUN (ospf_max_metric_router_lsa_admin
,
8663 ospf_max_metric_router_lsa_admin_cmd
,
8664 "max-metric router-lsa administrative",
8665 "OSPF maximum / infinite-distance metric\n"
8666 "Advertise own Router-LSA with infinite distance (stub router)\n"
8667 "Administratively applied, for an indefinite period\n")
8669 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8670 struct listnode
*ln
;
8671 struct ospf_area
*area
;
8673 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8674 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8676 if (!CHECK_FLAG(area
->stub_router_state
,
8677 OSPF_AREA_IS_STUB_ROUTED
))
8678 ospf_router_lsa_update_area(area
);
8681 /* Allows for areas configured later to get the property */
8682 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8687 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8688 no_ospf_max_metric_router_lsa_admin_cmd
,
8689 "no max-metric router-lsa administrative",
8691 "OSPF maximum / infinite-distance metric\n"
8692 "Advertise own Router-LSA with infinite distance (stub router)\n"
8693 "Administratively applied, for an indefinite period\n")
8695 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8696 struct listnode
*ln
;
8697 struct ospf_area
*area
;
8699 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8700 UNSET_FLAG(area
->stub_router_state
,
8701 OSPF_AREA_ADMIN_STUB_ROUTED
);
8703 /* Don't trample on the start-up stub timer */
8704 if (CHECK_FLAG(area
->stub_router_state
,
8705 OSPF_AREA_IS_STUB_ROUTED
)
8706 && !area
->t_stub_router
) {
8707 UNSET_FLAG(area
->stub_router_state
,
8708 OSPF_AREA_IS_STUB_ROUTED
);
8709 ospf_router_lsa_update_area(area
);
8712 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8716 DEFUN (ospf_max_metric_router_lsa_startup
,
8717 ospf_max_metric_router_lsa_startup_cmd
,
8718 "max-metric router-lsa on-startup (5-86400)",
8719 "OSPF maximum / infinite-distance metric\n"
8720 "Advertise own Router-LSA with infinite distance (stub router)\n"
8721 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8722 "Time (seconds) to advertise self as stub-router\n")
8724 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8726 unsigned int seconds
;
8729 vty_out(vty
, "%% Must supply stub-router period");
8730 return CMD_WARNING_CONFIG_FAILED
;
8733 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8735 ospf
->stub_router_startup_time
= seconds
;
8740 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8741 no_ospf_max_metric_router_lsa_startup_cmd
,
8742 "no max-metric router-lsa on-startup [(5-86400)]",
8744 "OSPF maximum / infinite-distance metric\n"
8745 "Advertise own Router-LSA with infinite distance (stub router)\n"
8746 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8747 "Time (seconds) to advertise self as stub-router\n")
8749 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8750 struct listnode
*ln
;
8751 struct ospf_area
*area
;
8753 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8755 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8756 SET_FLAG(area
->stub_router_state
,
8757 OSPF_AREA_WAS_START_STUB_ROUTED
);
8758 OSPF_TIMER_OFF(area
->t_stub_router
);
8760 /* Don't trample on admin stub routed */
8761 if (!CHECK_FLAG(area
->stub_router_state
,
8762 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8763 UNSET_FLAG(area
->stub_router_state
,
8764 OSPF_AREA_IS_STUB_ROUTED
);
8765 ospf_router_lsa_update_area(area
);
8772 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8773 ospf_max_metric_router_lsa_shutdown_cmd
,
8774 "max-metric router-lsa on-shutdown (5-100)",
8775 "OSPF maximum / infinite-distance metric\n"
8776 "Advertise own Router-LSA with infinite distance (stub router)\n"
8777 "Advertise stub-router prior to full shutdown of OSPF\n"
8778 "Time (seconds) to wait till full shutdown\n")
8780 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8782 unsigned int seconds
;
8785 vty_out(vty
, "%% Must supply stub-router shutdown period");
8786 return CMD_WARNING_CONFIG_FAILED
;
8789 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8791 ospf
->stub_router_shutdown_time
= seconds
;
8796 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8797 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8798 "no max-metric router-lsa on-shutdown [(5-100)]",
8800 "OSPF maximum / infinite-distance metric\n"
8801 "Advertise own Router-LSA with infinite distance (stub router)\n"
8802 "Advertise stub-router prior to full shutdown of OSPF\n"
8803 "Time (seconds) to wait till full shutdown\n")
8805 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8807 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8812 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8814 struct listnode
*ln
;
8815 struct ospf_area
*area
;
8817 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8818 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8819 ospf
->stub_router_startup_time
);
8820 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8821 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8822 ospf
->stub_router_shutdown_time
);
8823 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8824 if (CHECK_FLAG(area
->stub_router_state
,
8825 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8826 vty_out(vty
, " max-metric router-lsa administrative\n");
8833 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8834 struct route_table
*rt
,
8837 struct route_node
*rn
;
8838 struct ospf_route
* or ;
8839 struct listnode
*pnode
, *pnnode
;
8840 struct ospf_path
*path
;
8841 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8842 *json_nexthop
= NULL
;
8846 "============ OSPF network routing table ============\n");
8848 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8849 if ((or = rn
->info
) == NULL
)
8851 char buf1
[PREFIX2STR_BUFFER
];
8853 memset(buf1
, 0, sizeof(buf1
));
8854 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8856 json_route
= json_object_new_object();
8858 json_object_object_add(json
, buf1
, json_route
);
8859 json_object_to_json_string_ext(
8860 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8863 switch (or->path_type
) {
8864 case OSPF_PATH_INTER_AREA
:
8865 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8867 json_object_string_add(json_route
,
8870 json_object_int_add(json_route
, "cost",
8872 json_object_string_add(
8874 inet_ntoa(or->u
.std
.area_id
));
8877 "N IA %-18s [%d] area: %s\n",
8879 inet_ntoa(or->u
.std
.area_id
));
8881 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8883 json_object_string_add(json_route
,
8888 "D IA %-18s Discard entry\n",
8893 case OSPF_PATH_INTRA_AREA
:
8895 json_object_string_add(json_route
, "routeType",
8897 json_object_int_add(json_route
, "cost",
8899 json_object_string_add(
8901 inet_ntoa(or->u
.std
.area_id
));
8903 vty_out(vty
, "N %-18s [%d] area: %s\n",
8905 inet_ntoa(or->u
.std
.area_id
));
8912 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8914 json_nexthop_array
= json_object_new_array();
8915 json_object_object_add(json_route
, "nexthops",
8916 json_nexthop_array
);
8919 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8922 json_nexthop
= json_object_new_object();
8923 json_object_array_add(
8927 if (if_lookup_by_index(path
->ifindex
,
8930 if (path
->nexthop
.s_addr
== 0) {
8932 json_object_string_add(
8935 json_object_string_add(
8937 "directly attached to",
8943 "%24s directly attached to %s\n",
8951 json_object_string_add(
8956 json_object_string_add(
8964 "%24s via %s, %s\n",
8977 json_object_free(json_route
);
8983 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
8984 struct route_table
*rtrs
,
8987 struct route_node
*rn
;
8988 struct ospf_route
* or ;
8989 struct listnode
*pnode
;
8990 struct listnode
*node
;
8991 struct ospf_path
*path
;
8992 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8993 *json_nexthop
= NULL
;
8997 "============ OSPF router routing table =============\n");
8999 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9000 if (rn
->info
== NULL
)
9004 json_route
= json_object_new_object();
9006 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9008 json_object_string_add(json_route
, "routeType", "R ");
9010 vty_out(vty
, "R %-15s ",
9011 inet_ntoa(rn
->p
.u
.prefix4
));
9014 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9017 vty_out(vty
, "%24s", "");
9022 json_object_int_add(json_route
, "cost",
9024 json_object_string_add(
9026 inet_ntoa(or->u
.std
.area_id
));
9027 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9028 json_object_boolean_true_add(json_route
,
9030 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9031 json_object_string_add(json_route
,
9034 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9035 json_object_string_add(json_route
,
9039 vty_out(vty
, "%s [%d] area: %s",
9040 (or->path_type
== OSPF_PATH_INTER_AREA
9043 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9045 vty_out(vty
, "%s%s\n",
9046 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9049 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9055 json_nexthop_array
= json_object_new_array();
9056 json_object_object_add(json_route
, "nexthops",
9057 json_nexthop_array
);
9060 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9062 json_nexthop
= json_object_new_object();
9063 json_object_array_add(
9067 if (if_lookup_by_index(path
->ifindex
,
9069 if (path
->nexthop
.s_addr
== 0) {
9071 json_object_string_add(
9074 json_object_string_add(
9076 "directly attached to",
9082 "%24s directly attached to %s\n",
9090 json_object_string_add(
9095 json_object_string_add(
9103 "%24s via %s, %s\n",
9116 json_object_free(json_route
);
9122 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9123 struct route_table
*rt
,
9126 struct route_node
*rn
;
9127 struct ospf_route
*er
;
9128 struct listnode
*pnode
, *pnnode
;
9129 struct ospf_path
*path
;
9130 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9131 *json_nexthop
= NULL
;
9135 "============ OSPF external routing table ===========\n");
9137 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9138 if ((er
= rn
->info
) == NULL
)
9143 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9145 json_route
= json_object_new_object();
9147 json_object_object_add(json
, buf1
, json_route
);
9148 json_object_to_json_string_ext(
9149 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9152 switch (er
->path_type
) {
9153 case OSPF_PATH_TYPE1_EXTERNAL
:
9155 json_object_string_add(json_route
, "routeType",
9157 json_object_int_add(json_route
, "cost",
9161 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9163 buf1
, er
->cost
, er
->u
.ext
.tag
);
9166 case OSPF_PATH_TYPE2_EXTERNAL
:
9168 json_object_string_add(json_route
, "routeType",
9170 json_object_int_add(json_route
, "cost",
9174 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9176 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9183 json_nexthop_array
= json_object_new_array();
9184 json_object_object_add(json_route
, "nexthops",
9185 json_nexthop_array
);
9188 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9190 json_nexthop
= json_object_new_object();
9191 json_object_array_add(json_nexthop_array
,
9195 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9196 if (path
->nexthop
.s_addr
== 0) {
9198 json_object_string_add(
9201 json_object_string_add(
9203 "directly attached to",
9209 "%24s directly attached to %s\n",
9217 json_object_string_add(
9221 json_object_string_add(
9222 json_nexthop
, "via",
9228 "%24s via %s, %s\n",
9240 json_object_free(json_route
);
9246 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9251 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9253 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9255 if (ospf
->new_table
== NULL
) {
9256 vty_out(vty
, "No OSPF routing information exist\n");
9260 /* Show Network routes.
9261 show_ip_ospf_route_network (vty, ospf->new_table); */
9263 /* Show Router routes. */
9264 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9271 DEFUN (show_ip_ospf_border_routers
,
9272 show_ip_ospf_border_routers_cmd
,
9273 "show ip ospf [vrf <NAME|all>] border-routers",
9276 "OSPF information\n"
9279 "Show all the ABR's and ASBR's\n")
9281 struct ospf
*ospf
= NULL
;
9282 struct listnode
*node
= NULL
;
9283 char *vrf_name
= NULL
;
9284 bool all_vrf
= FALSE
;
9285 int ret
= CMD_SUCCESS
;
9288 uint8_t use_vrf
= 0;
9290 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9295 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9296 if (!ospf
->oi_running
)
9299 ret
= show_ip_ospf_border_routers_common(
9300 vty
, ospf
, use_vrf
);
9303 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9304 if (ospf
== NULL
|| !ospf
->oi_running
)
9307 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9311 /* Display default ospf (instance 0) info */
9312 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9313 if (ospf
== NULL
|| !ospf
->oi_running
)
9315 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9321 DEFUN (show_ip_ospf_instance_border_routers
,
9322 show_ip_ospf_instance_border_routers_cmd
,
9323 "show ip ospf (1-65535) border-routers",
9326 "OSPF information\n"
9328 "Show all the ABR's and ASBR's\n")
9332 unsigned short instance
= 0;
9334 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9335 ospf
= ospf_lookup_instance(instance
);
9337 return CMD_NOT_MY_INSTANCE
;
9339 if (!ospf
->oi_running
)
9342 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9345 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9346 json_object
*json
, uint8_t use_vrf
)
9348 json_object
*json_vrf
= NULL
;
9351 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9356 json_vrf
= json_object_new_object();
9361 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9363 if (ospf
->new_table
== NULL
) {
9364 vty_out(vty
, "No OSPF routing information exist\n");
9368 /* Show Network routes. */
9369 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9371 /* Show Router routes. */
9372 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9374 /* Show AS External routes. */
9375 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9380 // json_object_object_add(json_vrf, "areas",
9382 if (ospf
->vrf_id
== VRF_DEFAULT
)
9383 json_object_object_add(json
, "default",
9386 json_object_object_add(json
, ospf
->name
,
9396 DEFUN (show_ip_ospf_route
,
9397 show_ip_ospf_route_cmd
,
9398 "show ip ospf [vrf <NAME|all>] route [json]",
9401 "OSPF information\n"
9404 "OSPF routing table\n"
9407 struct ospf
*ospf
= NULL
;
9408 struct listnode
*node
= NULL
;
9409 char *vrf_name
= NULL
;
9410 bool all_vrf
= FALSE
;
9411 int ret
= CMD_SUCCESS
;
9414 uint8_t use_vrf
= 0;
9415 uint8_t uj
= use_json(argc
, argv
);
9416 json_object
*json
= NULL
;
9419 json
= json_object_new_object();
9421 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9423 /* vrf input is provided could be all or specific vrf*/
9427 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9428 if (!ospf
->oi_running
)
9430 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9435 /* Keep Non-pretty format */
9436 vty_out(vty
, "%s\n",
9437 json_object_to_json_string(json
));
9438 json_object_free(json
);
9443 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9444 if (ospf
== NULL
|| !ospf
->oi_running
) {
9446 json_object_free(json
);
9450 /* Display default ospf (instance 0) info */
9451 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9452 if (ospf
== NULL
|| !ospf
->oi_running
) {
9454 json_object_free(json
);
9460 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9461 /* Keep Non-pretty format */
9463 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9467 json_object_free(json
);
9472 DEFUN (show_ip_ospf_instance_route
,
9473 show_ip_ospf_instance_route_cmd
,
9474 "show ip ospf (1-65535) route",
9477 "OSPF information\n"
9479 "OSPF routing table\n")
9483 unsigned short instance
= 0;
9485 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9486 ospf
= ospf_lookup_instance(instance
);
9488 return CMD_NOT_MY_INSTANCE
;
9490 if (!ospf
->oi_running
)
9493 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9497 DEFUN (show_ip_ospf_vrfs
,
9498 show_ip_ospf_vrfs_cmd
,
9499 "show ip ospf vrfs [json]",
9502 "OSPF information\n"
9506 uint8_t uj
= use_json(argc
, argv
);
9507 json_object
*json
= NULL
;
9508 json_object
*json_vrfs
= NULL
;
9509 struct ospf
*ospf
= NULL
;
9510 struct listnode
*node
= NULL
;
9512 static char header
[] = "Name Id RouterId ";
9515 json
= json_object_new_object();
9516 json_vrfs
= json_object_new_object();
9519 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9520 json_object
*json_vrf
= NULL
;
9521 const char *name
= NULL
;
9522 int64_t vrf_id_ui
= 0;
9526 if (!uj
&& count
== 1)
9527 vty_out(vty
, "%s\n", header
);
9529 json_vrf
= json_object_new_object();
9531 if (ospf
->vrf_id
== 0)
9532 name
= VRF_DEFAULT_NAME
;
9536 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9538 : (int64_t)ospf
->vrf_id
;
9541 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9542 json_object_string_add(json_vrf
, "routerId",
9543 inet_ntoa(ospf
->router_id
));
9545 json_object_object_add(json_vrfs
, name
, json_vrf
);
9548 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9549 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9554 json_object_object_add(json
, "vrfs", json_vrfs
);
9555 json_object_int_add(json
, "totalVrfs", count
);
9557 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9558 json
, JSON_C_TO_STRING_PRETTY
));
9559 json_object_free(json
);
9562 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9569 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9572 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9574 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9575 "point-to-point", "broadcast",
9576 "non-broadcast", "point-to-multipoint",
9577 "virtual-link", /* should never be used. */
9580 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9582 struct listnode
*node
;
9583 struct interface
*ifp
;
9584 struct crypt_key
*ck
;
9585 struct route_node
*rn
= NULL
;
9586 struct ospf_if_params
*params
;
9588 struct ospf
*ospf
= vrf
->info
;
9590 FOR_ALL_INTERFACES (vrf
, ifp
) {
9592 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9595 vty_frame(vty
, "!\n");
9596 if (ifp
->vrf_id
== VRF_DEFAULT
)
9597 vty_frame(vty
, "interface %s\n", ifp
->name
);
9599 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9602 vty_out(vty
, " description %s\n", ifp
->desc
);
9606 params
= IF_DEF_PARAMS(ifp
);
9609 /* Interface Network print. */
9610 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9611 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9612 if (params
->type
!= ospf_default_iftype(ifp
)) {
9613 vty_out(vty
, " ip ospf network %s",
9616 if (params
!= IF_DEF_PARAMS(ifp
))
9624 /* OSPF interface authentication print */
9625 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9626 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9627 const char *auth_str
;
9629 /* Translation tables are not that much help
9630 * here due to syntax
9631 * of the simple option */
9632 switch (params
->auth_type
) {
9634 case OSPF_AUTH_NULL
:
9638 case OSPF_AUTH_SIMPLE
:
9642 case OSPF_AUTH_CRYPTOGRAPHIC
:
9643 auth_str
= " message-digest";
9651 vty_out(vty
, " ip ospf authentication%s",
9653 if (params
!= IF_DEF_PARAMS(ifp
))
9655 inet_ntoa(rn
->p
.u
.prefix4
));
9659 /* Simple Authentication Password print. */
9660 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9661 && params
->auth_simple
[0] != '\0') {
9662 vty_out(vty
, " ip ospf authentication-key %s",
9663 params
->auth_simple
);
9664 if (params
!= IF_DEF_PARAMS(ifp
))
9666 inet_ntoa(rn
->p
.u
.prefix4
));
9670 /* Cryptographic Authentication Key print. */
9671 if (params
&& params
->auth_crypt
) {
9672 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9675 " ip ospf message-digest-key %d md5 %s",
9676 ck
->key_id
, ck
->auth_key
);
9677 if (params
!= IF_DEF_PARAMS(ifp
))
9685 /* Interface Output Cost print. */
9686 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9687 vty_out(vty
, " ip ospf cost %u",
9688 params
->output_cost_cmd
);
9689 if (params
!= IF_DEF_PARAMS(ifp
))
9691 inet_ntoa(rn
->p
.u
.prefix4
));
9695 /* Hello Interval print. */
9696 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9697 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9698 vty_out(vty
, " ip ospf hello-interval %u",
9700 if (params
!= IF_DEF_PARAMS(ifp
))
9702 inet_ntoa(rn
->p
.u
.prefix4
));
9707 /* Router Dead Interval print. */
9708 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9710 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9711 vty_out(vty
, " ip ospf dead-interval ");
9714 if (OSPF_IF_PARAM_CONFIGURED(params
,
9717 "minimal hello-multiplier %d",
9718 params
->fast_hello
);
9720 vty_out(vty
, "%u", params
->v_wait
);
9722 if (params
!= IF_DEF_PARAMS(ifp
))
9724 inet_ntoa(rn
->p
.u
.prefix4
));
9728 /* Router Priority print. */
9729 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9731 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9732 vty_out(vty
, " ip ospf priority %u",
9734 if (params
!= IF_DEF_PARAMS(ifp
))
9736 inet_ntoa(rn
->p
.u
.prefix4
));
9740 /* Retransmit Interval print. */
9741 if (OSPF_IF_PARAM_CONFIGURED(params
,
9742 retransmit_interval
)
9743 && params
->retransmit_interval
9744 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9745 vty_out(vty
, " ip ospf retransmit-interval %u",
9746 params
->retransmit_interval
);
9747 if (params
!= IF_DEF_PARAMS(ifp
))
9749 inet_ntoa(rn
->p
.u
.prefix4
));
9753 /* Transmit Delay print. */
9754 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9755 && params
->transmit_delay
9756 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9757 vty_out(vty
, " ip ospf transmit-delay %u",
9758 params
->transmit_delay
);
9759 if (params
!= IF_DEF_PARAMS(ifp
))
9761 inet_ntoa(rn
->p
.u
.prefix4
));
9766 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9767 if (ospf
&& ospf
->instance
)
9768 vty_out(vty
, " ip ospf %d",
9771 vty_out(vty
, " ip ospf");
9773 char buf
[INET_ADDRSTRLEN
];
9775 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9776 params
->if_area_id_fmt
);
9777 vty_out(vty
, " area %s", buf
);
9778 if (params
!= IF_DEF_PARAMS(ifp
))
9780 inet_ntoa(rn
->p
.u
.prefix4
));
9785 if (params
&& params
->bfd_info
)
9786 ospf_bfd_write_config(vty
, params
);
9788 /* MTU ignore print. */
9789 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9790 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9791 if (params
->mtu_ignore
== 0)
9792 vty_out(vty
, " no ip ospf mtu-ignore");
9794 vty_out(vty
, " ip ospf mtu-ignore");
9795 if (params
!= IF_DEF_PARAMS(ifp
))
9797 inet_ntoa(rn
->p
.u
.prefix4
));
9804 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9806 rn
= route_next(rn
);
9816 ospf_opaque_config_write_if(vty
, ifp
);
9818 vty_endframe(vty
, NULL
);
9824 /* Configuration write function for ospfd. */
9825 static int config_write_interface(struct vty
*vty
)
9828 struct vrf
*vrf
= NULL
;
9830 /* Display all VRF aware OSPF interface configuration */
9831 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9832 write
+= config_write_interface_one(vty
, vrf
);
9838 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9840 struct route_node
*rn
;
9841 uint8_t buf
[INET_ADDRSTRLEN
];
9843 /* `network area' print. */
9844 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9846 struct ospf_network
*n
= rn
->info
;
9848 /* Create Area ID string by specified Area ID format. */
9849 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9850 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9853 sprintf((char *)buf
, "%lu",
9854 (unsigned long int)ntohl(
9855 n
->area_id
.s_addr
));
9857 /* Network print. */
9858 vty_out(vty
, " network %s/%d area %s\n",
9859 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9866 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9868 struct listnode
*node
;
9869 struct ospf_area
*area
;
9870 uint8_t buf
[INET_ADDRSTRLEN
];
9872 /* Area configuration print. */
9873 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9874 struct route_node
*rn1
;
9876 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
9879 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9880 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9881 vty_out(vty
, " area %s authentication\n", buf
);
9884 " area %s authentication message-digest\n",
9888 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9889 vty_out(vty
, " area %s shortcut %s\n", buf
,
9890 ospf_shortcut_mode_str
9891 [area
->shortcut_configured
]);
9893 if ((area
->external_routing
== OSPF_AREA_STUB
)
9894 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9895 if (area
->external_routing
== OSPF_AREA_STUB
) {
9896 vty_out(vty
, " area %s stub", buf
);
9897 if (area
->no_summary
)
9898 vty_out(vty
, " no-summary\n");
9900 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9901 switch (area
->NSSATranslatorRole
) {
9902 case OSPF_NSSA_ROLE_NEVER
:
9904 " area %s nssa translate-never\n",
9907 case OSPF_NSSA_ROLE_ALWAYS
:
9909 " area %s nssa translate-always\n",
9912 case OSPF_NSSA_ROLE_CANDIDATE
:
9913 vty_out(vty
, " area %s nssa \n", buf
);
9916 if (area
->no_summary
)
9918 " area %s nssa no-summary\n",
9922 if (area
->default_cost
!= 1)
9923 vty_out(vty
, " area %s default-cost %d\n", buf
,
9924 area
->default_cost
);
9927 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
9929 struct ospf_area_range
*range
= rn1
->info
;
9931 vty_out(vty
, " area %s range %s/%d", buf
,
9932 inet_ntoa(rn1
->p
.u
.prefix4
),
9935 if (range
->cost_config
9936 != OSPF_AREA_RANGE_COST_UNSPEC
)
9937 vty_out(vty
, " cost %d",
9938 range
->cost_config
);
9940 if (!CHECK_FLAG(range
->flags
,
9941 OSPF_AREA_RANGE_ADVERTISE
))
9942 vty_out(vty
, " not-advertise");
9944 if (CHECK_FLAG(range
->flags
,
9945 OSPF_AREA_RANGE_SUBSTITUTE
))
9946 vty_out(vty
, " substitute %s/%d",
9947 inet_ntoa(range
->subst_addr
),
9948 range
->subst_masklen
);
9953 if (EXPORT_NAME(area
))
9954 vty_out(vty
, " area %s export-list %s\n", buf
,
9957 if (IMPORT_NAME(area
))
9958 vty_out(vty
, " area %s import-list %s\n", buf
,
9961 if (PREFIX_NAME_IN(area
))
9962 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
9963 PREFIX_NAME_IN(area
));
9965 if (PREFIX_NAME_OUT(area
))
9966 vty_out(vty
, " area %s filter-list prefix %s out\n",
9967 buf
, PREFIX_NAME_OUT(area
));
9973 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
9975 struct ospf_nbr_nbma
*nbr_nbma
;
9976 struct route_node
*rn
;
9978 /* Static Neighbor configuration print. */
9979 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
9980 if ((nbr_nbma
= rn
->info
)) {
9981 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
9983 if (nbr_nbma
->priority
9984 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
9985 vty_out(vty
, " priority %d",
9986 nbr_nbma
->priority
);
9988 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
9989 vty_out(vty
, " poll-interval %d",
9998 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10000 struct listnode
*node
;
10001 struct ospf_vl_data
*vl_data
;
10002 char buf
[INET_ADDRSTRLEN
];
10004 /* Virtual-Link print */
10005 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10006 struct listnode
*n2
;
10007 struct crypt_key
*ck
;
10008 struct ospf_interface
*oi
;
10010 if (vl_data
!= NULL
) {
10011 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10012 vl_data
->vl_area_id_fmt
);
10013 oi
= vl_data
->vl_oi
;
10016 if (OSPF_IF_PARAM(oi
, v_hello
)
10017 != OSPF_HELLO_INTERVAL_DEFAULT
10018 || OSPF_IF_PARAM(oi
, v_wait
)
10019 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10020 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10021 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10022 || OSPF_IF_PARAM(oi
, transmit_delay
)
10023 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10025 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10026 buf
, inet_ntoa(vl_data
->vl_peer
),
10027 OSPF_IF_PARAM(oi
, v_hello
),
10028 OSPF_IF_PARAM(oi
, retransmit_interval
),
10029 OSPF_IF_PARAM(oi
, transmit_delay
),
10030 OSPF_IF_PARAM(oi
, v_wait
));
10032 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10033 inet_ntoa(vl_data
->vl_peer
));
10035 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10038 " area %s virtual-link %s authentication-key %s\n",
10039 buf
, inet_ntoa(vl_data
->vl_peer
),
10040 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10043 for (ALL_LIST_ELEMENTS_RO(
10044 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10048 " area %s virtual-link %s"
10049 " message-digest-key %d md5 %s\n",
10050 buf
, inet_ntoa(vl_data
->vl_peer
),
10051 ck
->key_id
, ck
->auth_key
);
10059 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10063 /* redistribute print. */
10064 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10065 struct list
*red_list
;
10066 struct listnode
*node
;
10067 struct ospf_redist
*red
;
10069 red_list
= ospf
->redist
[type
];
10073 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10074 vty_out(vty
, " redistribute %s",
10075 zebra_route_string(type
));
10077 vty_out(vty
, " %d", red
->instance
);
10079 if (red
->dmetric
.value
>= 0)
10080 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10082 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10083 vty_out(vty
, " metric-type 1");
10085 if (ROUTEMAP_NAME(red
))
10086 vty_out(vty
, " route-map %s",
10087 ROUTEMAP_NAME(red
));
10089 vty_out(vty
, "\n");
10096 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10098 if (ospf
->default_metric
!= -1)
10099 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10103 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10106 struct ospf_redist
*red
;
10109 /* distribute-list print. */
10110 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10111 if (DISTRIBUTE_NAME(ospf
, type
))
10112 vty_out(vty
, " distribute-list %s out %s\n",
10113 DISTRIBUTE_NAME(ospf
, type
),
10114 zebra_route_string(type
));
10116 /* default-information print. */
10117 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10118 vty_out(vty
, " default-information originate");
10119 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10120 vty_out(vty
, " always");
10122 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10124 if (red
->dmetric
.value
>= 0)
10125 vty_out(vty
, " metric %d",
10126 red
->dmetric
.value
);
10128 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10129 vty_out(vty
, " metric-type 1");
10131 if (ROUTEMAP_NAME(red
))
10132 vty_out(vty
, " route-map %s",
10133 ROUTEMAP_NAME(red
));
10136 vty_out(vty
, "\n");
10143 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10145 struct route_node
*rn
;
10146 struct ospf_distance
*odistance
;
10148 if (ospf
->distance_all
)
10149 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10151 if (ospf
->distance_intra
|| ospf
->distance_inter
10152 || ospf
->distance_external
) {
10153 vty_out(vty
, " distance ospf");
10155 if (ospf
->distance_intra
)
10156 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10157 if (ospf
->distance_inter
)
10158 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10159 if (ospf
->distance_external
)
10160 vty_out(vty
, " external %d", ospf
->distance_external
);
10162 vty_out(vty
, "\n");
10165 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10166 if ((odistance
= rn
->info
) != NULL
) {
10167 vty_out(vty
, " distance %d %s/%d %s\n",
10168 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10170 odistance
->access_list
? odistance
->access_list
10176 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10178 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10179 struct interface
*ifp
;
10180 struct ospf_interface
*oi
;
10181 struct listnode
*node
= NULL
;
10184 /* `router ospf' print. */
10185 if (ospf
->instance
&& ospf
->name
) {
10186 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10188 } else if (ospf
->instance
) {
10189 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10190 } else if (ospf
->name
) {
10191 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10193 vty_out(vty
, "router ospf\n");
10195 if (!ospf
->networks
) {
10200 /* Router ID print. */
10201 if (ospf
->router_id_static
.s_addr
!= 0)
10202 vty_out(vty
, " ospf router-id %s\n",
10203 inet_ntoa(ospf
->router_id_static
));
10205 /* ABR type print. */
10206 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10207 vty_out(vty
, " ospf abr-type %s\n",
10208 ospf_abr_type_str
[ospf
->abr_type
]);
10210 /* log-adjacency-changes flag print. */
10211 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10212 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10213 vty_out(vty
, " log-adjacency-changes detail\n");
10214 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10215 vty_out(vty
, " log-adjacency-changes\n");
10216 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10217 vty_out(vty
, " no log-adjacency-changes\n");
10220 /* RFC1583 compatibility flag print -- Compatible with CISCO
10222 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10223 vty_out(vty
, " compatible rfc1583\n");
10225 /* auto-cost reference-bandwidth configuration. */
10226 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10228 "! Important: ensure reference bandwidth "
10229 "is consistent across all routers\n");
10230 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10231 ospf
->ref_bandwidth
);
10234 /* SPF timers print. */
10235 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10236 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10237 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10238 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10239 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10241 /* LSA timers print. */
10242 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10243 vty_out(vty
, " timers throttle lsa all %d\n",
10244 ospf
->min_ls_interval
);
10245 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10246 vty_out(vty
, " timers lsa min-arrival %d\n",
10247 ospf
->min_ls_arrival
);
10249 /* Write multiplier print. */
10250 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10251 vty_out(vty
, " ospf write-multiplier %d\n",
10252 ospf
->write_oi_count
);
10254 /* Max-metric router-lsa print */
10255 config_write_stub_router(vty
, ospf
);
10257 /* SPF refresh parameters print. */
10258 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10259 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10261 /* Redistribute information print. */
10262 config_write_ospf_redistribute(vty
, ospf
);
10264 /* passive-interface print. */
10265 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10266 vty_out(vty
, " passive-interface default\n");
10268 FOR_ALL_INTERFACES (vrf
, ifp
)
10269 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10271 && IF_DEF_PARAMS(ifp
)->passive_interface
10272 != ospf
->passive_interface_default
) {
10273 vty_out(vty
, " %spassive-interface %s\n",
10274 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10278 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10279 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10281 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10282 passive_interface
)) {
10283 if (oi
->params
->passive_interface
10284 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10286 } else if (oi
->params
->passive_interface
10287 == ospf
->passive_interface_default
)
10290 vty_out(vty
, " %spassive-interface %s %s\n",
10291 oi
->params
->passive_interface
? "" : "no ",
10292 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10295 /* Network area print. */
10296 config_write_network_area(vty
, ospf
);
10298 /* Area config print. */
10299 config_write_ospf_area(vty
, ospf
);
10301 /* static neighbor print. */
10302 config_write_ospf_nbr_nbma(vty
, ospf
);
10304 /* Virtual-Link print. */
10305 config_write_virtual_link(vty
, ospf
);
10307 /* Default metric configuration. */
10308 config_write_ospf_default_metric(vty
, ospf
);
10310 /* Distribute-list and default-information print. */
10311 config_write_ospf_distribute(vty
, ospf
);
10313 /* Distance configuration. */
10314 config_write_ospf_distance(vty
, ospf
);
10316 ospf_opaque_config_write_router(vty
, ospf
);
10322 /* OSPF configuration write function. */
10323 static int ospf_config_write(struct vty
*vty
)
10326 struct listnode
*ospf_node
= NULL
;
10329 if (listcount(om
->ospf
) == 0)
10332 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10333 /* VRF Default check if it is running.
10334 * Upon daemon start, there could be default instance
10335 * in absence of 'router ospf'/oi_running is disabled. */
10336 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10337 write
+= ospf_config_write_one(vty
, ospf
);
10338 /* For Non-Default VRF simply display the configuration,
10339 * even if it is not oi_running. */
10340 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10341 write
+= ospf_config_write_one(vty
, ospf
);
10346 void ospf_vty_show_init(void)
10348 /* "show ip ospf" commands. */
10349 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10351 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10353 /* "show ip ospf database" commands. */
10354 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10356 install_element(VIEW_NODE
,
10357 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10358 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10359 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10361 /* "show ip ospf interface" commands. */
10362 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10364 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10365 /* "show ip ospf interface traffic */
10366 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10368 /* "show ip ospf neighbor" commands. */
10369 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10370 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10371 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10372 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10373 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10374 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10375 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10377 install_element(VIEW_NODE
,
10378 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10379 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10380 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10381 install_element(VIEW_NODE
,
10382 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10383 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10384 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10385 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10387 /* "show ip ospf route" commands. */
10388 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10389 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10391 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10392 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10394 /* "show ip ospf vrfs" commands. */
10395 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10399 /* ospfd's interface node. */
10400 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10402 /* Initialization of OSPF interface. */
10403 static void ospf_vty_if_init(void)
10405 /* Install interface node. */
10406 install_node(&interface_node
, config_write_interface
);
10409 /* "ip ospf authentication" commands. */
10410 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10411 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10412 install_element(INTERFACE_NODE
,
10413 &no_ip_ospf_authentication_args_addr_cmd
);
10414 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10415 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10416 install_element(INTERFACE_NODE
,
10417 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10418 install_element(INTERFACE_NODE
,
10419 &no_ospf_authentication_key_authkey_addr_cmd
);
10421 /* "ip ospf message-digest-key" commands. */
10422 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10423 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10425 /* "ip ospf cost" commands. */
10426 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10427 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10429 /* "ip ospf mtu-ignore" commands. */
10430 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10431 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10433 /* "ip ospf dead-interval" commands. */
10434 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10435 install_element(INTERFACE_NODE
,
10436 &ip_ospf_dead_interval_minimal_addr_cmd
);
10437 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10439 /* "ip ospf hello-interval" commands. */
10440 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10441 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10443 /* "ip ospf network" commands. */
10444 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10445 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10447 /* "ip ospf priority" commands. */
10448 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10449 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10451 /* "ip ospf retransmit-interval" commands. */
10452 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10453 install_element(INTERFACE_NODE
,
10454 &no_ip_ospf_retransmit_interval_addr_cmd
);
10456 /* "ip ospf transmit-delay" commands. */
10457 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10458 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10460 /* "ip ospf area" commands. */
10461 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10462 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10464 /* These commands are compatibitliy for previous version. */
10465 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10466 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10467 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10468 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10469 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10470 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10471 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10472 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10473 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10474 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10475 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10476 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10477 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10478 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10479 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10480 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10481 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10484 static void ospf_vty_zebra_init(void)
10486 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10487 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10488 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10489 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10491 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10492 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10494 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10495 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10497 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10498 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10500 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10501 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10502 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10503 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10505 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10506 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10507 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10508 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10512 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10514 static void ospf_interface_clear(struct interface
*ifp
)
10516 if (!if_is_operative(ifp
))
10519 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10520 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10522 ospf_if_reset(ifp
);
10525 DEFUN (clear_ip_ospf_interface
,
10526 clear_ip_ospf_interface_cmd
,
10527 "clear ip ospf interface [IFNAME]",
10530 "OSPF information\n"
10531 "Interface information\n"
10532 "Interface name\n")
10534 int idx_ifname
= 4;
10535 struct interface
*ifp
;
10536 struct listnode
*node
;
10537 struct ospf
*ospf
= NULL
;
10539 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10541 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10542 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10543 FOR_ALL_INTERFACES (vrf
, ifp
)
10544 ospf_interface_clear(ifp
);
10547 /* Interface name is specified. */
10548 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10550 vty_out(vty
, "No such interface name\n");
10552 ospf_interface_clear(ifp
);
10555 return CMD_SUCCESS
;
10558 void ospf_vty_clear_init(void)
10560 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10564 /* Install OSPF related vty commands. */
10565 void ospf_vty_init(void)
10567 /* Install ospf top node. */
10568 install_node(&ospf_node
, ospf_config_write
);
10570 /* "router ospf" commands. */
10571 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10572 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10575 install_default(OSPF_NODE
);
10577 /* "ospf router-id" commands. */
10578 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10579 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10580 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10582 /* "passive-interface" commands. */
10583 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10584 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10586 /* "ospf abr-type" commands. */
10587 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10588 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10590 /* "ospf log-adjacency-changes" commands. */
10591 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10592 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10593 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10594 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10596 /* "ospf rfc1583-compatible" commands. */
10597 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10598 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10599 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10600 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10602 /* "network area" commands. */
10603 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10604 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10606 /* "area authentication" commands. */
10607 install_element(OSPF_NODE
,
10608 &ospf_area_authentication_message_digest_cmd
);
10609 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10610 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10612 /* "area range" commands. */
10613 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10614 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10615 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10616 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10617 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10618 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10620 /* "area virtual-link" commands. */
10621 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10622 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10623 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10624 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10627 /* "area stub" commands. */
10628 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10629 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10630 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10631 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10633 /* "area nssa" commands. */
10634 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10635 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10636 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10637 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10638 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10640 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10641 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10643 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10644 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10646 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10647 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10649 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10650 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10652 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10653 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10655 /* SPF timer commands */
10656 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10657 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10659 /* LSA timers commands */
10660 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10661 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10662 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10663 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10664 install_element(OSPF_NODE
, &ospf_timers_lsa_arrival_cmd
);
10665 install_element(OSPF_NODE
, &no_ospf_timers_lsa_arrival_cmd
);
10667 /* refresh timer commands */
10668 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10669 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10671 /* max-metric commands */
10672 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10673 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10674 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10675 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10676 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10677 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10679 /* reference bandwidth commands */
10680 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10681 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10683 /* "neighbor" commands. */
10684 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10685 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10686 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10687 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10689 /* write multiplier commands */
10690 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10691 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10692 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10693 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10695 /* Init interface related vty commands. */
10696 ospf_vty_if_init();
10698 /* Init zebra related vty commands. */
10699 ospf_vty_zebra_init();