2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "ospfd/ospfd.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_ism.h"
43 #include "ospfd/ospf_interface.h"
44 #include "ospfd/ospf_nsm.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_flood.h"
47 #include "ospfd/ospf_abr.h"
48 #include "ospfd/ospf_spf.h"
49 #include "ospfd/ospf_route.h"
50 #include "ospfd/ospf_zebra.h"
51 /*#include "ospfd/ospf_routemap.h" */
52 #include "ospfd/ospf_vty.h"
53 #include "ospfd/ospf_dump.h"
54 #include "ospfd/ospf_bfd.h"
56 static const char *ospf_network_type_str
[] = {
57 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
58 "VIRTUALLINK", "LOOPBACK"};
60 /* Utility functions. */
61 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
65 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
66 if (*ep
&& !inet_aton(str
, area_id
))
70 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
75 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
78 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
79 inet_ntop(AF_INET
, area_id
, buf
, length
);
81 sprintf(buf
, "%lu", (unsigned long)ntohl(area_id
->s_addr
));
84 static int str2metric(const char *str
, int *metric
)
90 *metric
= strtol(str
, NULL
, 10);
91 if (*metric
< 0 && *metric
> 16777214) {
92 /* vty_out (vty, "OSPF metric value is invalid\n"); */
99 static int str2metric_type(const char *str
, int *metric_type
)
105 if (strncmp(str
, "1", 1) == 0)
106 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
107 else if (strncmp(str
, "2", 1) == 0)
108 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
115 int ospf_oi_count(struct interface
*ifp
)
117 struct route_node
*rn
;
120 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
127 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
128 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
129 vrf_name = argv[idx_vrf + 1]->arg; \
130 all_vrf = strmatch(vrf_name, "all"); \
133 static struct ospf
*ospf_cmd_lookup_ospf(struct vty
*vty
,
134 struct cmd_token
*argv
[],
135 const int argc
, uint32_t enable
,
136 unsigned short *instance
)
138 struct ospf
*ospf
= NULL
;
139 int idx_vrf
= 0, idx_inst
= 0;
140 const char *vrf_name
= NULL
;
143 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
))
144 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
146 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
147 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
149 /* Allocate VRF aware instance */
150 ospf
= ospf_get(*instance
, vrf_name
);
152 ospf
= ospf_lookup_by_inst_name(*instance
, vrf_name
);
156 ospf
= ospf_get(*instance
, NULL
);
158 ospf
= ospf_lookup_instance(*instance
);
165 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
166 json_object
*json
, uint8_t use_vrf
)
170 if (ospf
->vrf_id
== VRF_DEFAULT
)
171 json_object_string_add(json
, "vrfName",
174 json_object_string_add(json
, "vrfName",
176 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
178 if (ospf
->vrf_id
== VRF_DEFAULT
)
179 vty_out(vty
, "VRF Name: %s\n", "default");
181 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
186 #ifndef VTYSH_EXTRACT_PL
187 #include "ospfd/ospf_vty_clippy.c"
190 DEFUN_NOSH (router_ospf
,
192 "router ospf [{(1-65535)|vrf NAME}]",
193 "Enable a routing process\n"
194 "Start OSPF configuration\n"
198 struct ospf
*ospf
= NULL
;
199 int ret
= CMD_SUCCESS
;
200 unsigned short instance
= 0;
201 struct vrf
*vrf
= NULL
;
202 struct route_node
*rn
;
203 struct interface
*ifp
;
205 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 1, &instance
);
207 return CMD_WARNING_CONFIG_FAILED
;
209 /* The following logic to set the vty qobj index is in place to be able
210 to ignore the commands which dont belong to this instance. */
211 if (ospf
->instance
!= instance
) {
212 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
213 ret
= CMD_NOT_MY_INSTANCE
;
215 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
216 ospf
->oi_running
= 1;
217 if (IS_DEBUG_OSPF_EVENT
)
219 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
220 instance
, ospf
->name
? ospf
->name
: "NIL",
221 ospf
->vrf_id
, ospf
->oi_running
);
222 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
224 /* Activate 'ip ospf area x' configured interfaces for given
225 * vrf. Activate area on vrf x aware interfaces.
226 * vrf_enable callback calls router_id_update which
227 * internally will call ospf_if_update to trigger
230 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
232 FOR_ALL_INTERFACES (vrf
, ifp
) {
233 struct ospf_if_params
*params
;
235 params
= IF_DEF_PARAMS(ifp
);
236 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
237 for (rn
= route_top(ospf
->networks
); rn
;
238 rn
= route_next(rn
)) {
239 if (rn
->info
!= NULL
) {
241 "Interface %s has area config but please remove all network commands first.\n",
246 ospf_interface_area_set(ospf
, ifp
);
247 ospf
->if_ospf_cli_count
++;
251 ospf_router_id_update(ospf
);
257 DEFUN (no_router_ospf
,
259 "no router ospf [{(1-65535)|vrf NAME}]",
261 "Enable a routing process\n"
262 "Start OSPF configuration\n"
267 unsigned short instance
= 0;
269 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 0, &instance
);
272 return CMD_NOT_MY_INSTANCE
;
282 DEFPY (ospf_router_id
,
284 "ospf router-id A.B.C.D",
285 "OSPF specific commands\n"
286 "router-id for the OSPF process\n"
287 "OSPF router-id in IP address format\n")
289 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
291 struct listnode
*node
;
292 struct ospf_area
*area
;
294 ospf
->router_id_static
= router_id
;
296 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
297 if (area
->full_nbrs
) {
299 "For this router-id change to take effect,"
300 " save config and restart ospfd\n");
304 ospf_router_id_update(ospf
);
309 DEFUN_HIDDEN (ospf_router_id_old
,
310 ospf_router_id_old_cmd
,
312 "router-id for the OSPF process\n"
313 "OSPF router-id in IP address format\n")
315 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
317 struct listnode
*node
;
318 struct ospf_area
*area
;
319 struct in_addr router_id
;
322 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
324 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
325 return CMD_WARNING_CONFIG_FAILED
;
328 ospf
->router_id_static
= router_id
;
330 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
331 if (area
->full_nbrs
) {
333 "For this router-id change to take effect,"
334 " save config and restart ospfd\n");
338 ospf_router_id_update(ospf
);
343 DEFPY (no_ospf_router_id
,
344 no_ospf_router_id_cmd
,
345 "no ospf router-id [A.B.C.D]",
347 "OSPF specific commands\n"
348 "router-id for the OSPF process\n"
349 "OSPF router-id in IP address format\n")
351 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
352 struct listnode
*node
;
353 struct ospf_area
*area
;
356 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
357 vty_out(vty
, "%% OSPF router-id doesn't match\n");
358 return CMD_WARNING_CONFIG_FAILED
;
362 ospf
->router_id_static
.s_addr
= 0;
364 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
365 if (area
->full_nbrs
) {
367 "For this router-id change to take effect,"
368 " save config and restart ospfd\n");
372 ospf_router_id_update(ospf
);
378 static void ospf_passive_interface_default(struct ospf
*ospf
, uint8_t newval
)
380 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
382 struct interface
*ifp
;
383 struct ospf_interface
*oi
;
385 ospf
->passive_interface_default
= newval
;
387 FOR_ALL_INTERFACES (vrf
, ifp
) {
388 if (ifp
&& OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
390 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp
), passive_interface
);
392 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
)) {
393 if (OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
394 UNSET_IF_PARAM(oi
->params
, passive_interface
);
395 /* update multicast memberships */
396 ospf_if_set_multicast(oi
);
400 static void ospf_passive_interface_update_addr(struct ospf
*ospf
,
401 struct interface
*ifp
,
402 struct ospf_if_params
*params
,
408 params
->passive_interface
= value
;
409 if (params
!= IF_DEF_PARAMS(ifp
)) {
410 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
412 dflt
= IF_DEF_PARAMS(ifp
)->passive_interface
;
414 dflt
= ospf
->passive_interface_default
;
417 SET_IF_PARAM(params
, passive_interface
);
419 UNSET_IF_PARAM(params
, passive_interface
);
421 ospf_free_if_params(ifp
, addr
);
422 ospf_if_update_params(ifp
, addr
);
426 static void ospf_passive_interface_update(struct ospf
*ospf
,
427 struct interface
*ifp
,
428 struct ospf_if_params
*params
,
431 params
->passive_interface
= value
;
432 if (params
== IF_DEF_PARAMS(ifp
)) {
433 if (value
!= ospf
->passive_interface_default
)
434 SET_IF_PARAM(params
, passive_interface
);
436 UNSET_IF_PARAM(params
, passive_interface
);
440 DEFUN (ospf_passive_interface
,
441 ospf_passive_interface_addr_cmd
,
442 "passive-interface <IFNAME [A.B.C.D]|default>",
443 "Suppress routing updates on an interface\n"
446 "Suppress routing updates on interfaces by default\n")
448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
450 struct interface
*ifp
= NULL
;
451 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
453 struct ospf_if_params
*params
;
454 struct route_node
*rn
;
456 if (strmatch(argv
[1]->text
, "default")) {
457 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
460 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
461 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, 0);
464 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
465 return CMD_WARNING_CONFIG_FAILED
;
468 params
= IF_DEF_PARAMS(ifp
);
471 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
474 "Please specify interface address by A.B.C.D\n");
475 return CMD_WARNING_CONFIG_FAILED
;
478 params
= ospf_get_if_params(ifp
, addr
);
479 ospf_if_update_params(ifp
, addr
);
480 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
481 OSPF_IF_PASSIVE
, addr
);
484 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
486 /* XXX We should call ospf_if_set_multicast on exactly those
487 * interfaces for which the passive property changed. It is too much
488 * work to determine this set, so we do this for every interface.
489 * This is safe and reasonable because ospf_if_set_multicast uses a
490 * record of joined groups to avoid systems calls if the desired
491 * memberships match the current memership.
494 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
495 struct ospf_interface
*oi
= rn
->info
;
497 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
499 ospf_if_set_multicast(oi
);
502 * XXX It is not clear what state transitions the interface needs to
503 * undergo when going from active to passive. Fixing this will
504 * require precise identification of interfaces having such a
511 DEFUN (no_ospf_passive_interface
,
512 no_ospf_passive_interface_addr_cmd
,
513 "no passive-interface <IFNAME [A.B.C.D]|default>",
515 "Allow routing updates on an interface\n"
518 "Allow routing updates on interfaces by default\n")
520 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
522 struct interface
*ifp
= NULL
;
523 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
524 struct ospf_if_params
*params
;
526 struct route_node
*rn
;
528 if (strmatch(argv
[2]->text
, "default")) {
529 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
533 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
534 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, 0);
537 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
538 return CMD_WARNING_CONFIG_FAILED
;
541 params
= IF_DEF_PARAMS(ifp
);
544 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
547 "Please specify interface address by A.B.C.D\n");
548 return CMD_WARNING_CONFIG_FAILED
;
551 params
= ospf_lookup_if_params(ifp
, addr
);
554 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
555 OSPF_IF_ACTIVE
, addr
);
557 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
559 /* XXX We should call ospf_if_set_multicast on exactly those
560 * interfaces for which the passive property changed. It is too much
561 * work to determine this set, so we do this for every interface.
562 * This is safe and reasonable because ospf_if_set_multicast uses a
563 * record of joined groups to avoid systems calls if the desired
564 * memberships match the current memership.
566 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
567 struct ospf_interface
*oi
= rn
->info
;
570 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
571 ospf_if_set_multicast(oi
);
578 DEFUN (ospf_network_area
,
579 ospf_network_area_cmd
,
580 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
581 "Enable routing on an IP network\n"
582 "OSPF network prefix\n"
583 "Set the OSPF area ID\n"
584 "OSPF area ID in IP address format\n"
585 "OSPF area ID as a decimal value\n")
587 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
588 int idx_ipv4_prefixlen
= 1;
589 int idx_ipv4_number
= 3;
590 struct prefix_ipv4 p
;
591 struct in_addr area_id
;
594 if (ospf
->instance
) {
596 "The network command is not supported in multi-instance ospf\n");
597 return CMD_WARNING_CONFIG_FAILED
;
600 if (ospf
->if_ospf_cli_count
> 0) {
602 "Please remove all ip ospf area x.x.x.x commands first.\n");
603 if (IS_DEBUG_OSPF_EVENT
)
605 "%s ospf vrf %s num of %u ip osp area x config",
607 ospf
->name
? ospf
->name
: "NIL",
608 ospf
->if_ospf_cli_count
);
609 return CMD_WARNING_CONFIG_FAILED
;
612 /* Get network prefix and Area ID. */
613 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
614 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
616 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
618 vty_out(vty
, "There is already same network statement.\n");
619 return CMD_WARNING_CONFIG_FAILED
;
625 DEFUN (no_ospf_network_area
,
626 no_ospf_network_area_cmd
,
627 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
629 "Enable routing on an IP network\n"
630 "OSPF network prefix\n"
631 "Set the OSPF area ID\n"
632 "OSPF area ID in IP address format\n"
633 "OSPF area ID as a decimal value\n")
635 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
636 int idx_ipv4_prefixlen
= 2;
637 int idx_ipv4_number
= 4;
638 struct prefix_ipv4 p
;
639 struct in_addr area_id
;
642 if (ospf
->instance
) {
644 "The network command is not supported in multi-instance ospf\n");
645 return CMD_WARNING_CONFIG_FAILED
;
648 /* Get network prefix and Area ID. */
649 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
650 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
652 ret
= ospf_network_unset(ospf
, &p
, area_id
);
655 "Can't find specified network area configuration.\n");
656 return CMD_WARNING_CONFIG_FAILED
;
662 DEFUN (ospf_area_range
,
664 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
665 "OSPF area parameters\n"
666 "OSPF area ID in IP address format\n"
667 "OSPF area ID as a decimal value\n"
668 "Summarize routes matching address/mask (border routers only)\n"
669 "Area range prefix\n"
670 "Advertise this range (default)\n"
671 "User specified metric for this range\n"
672 "Advertised metric for this range\n")
674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
675 int idx_ipv4_number
= 1;
676 int idx_ipv4_prefixlen
= 3;
678 struct prefix_ipv4 p
;
679 struct in_addr area_id
;
683 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
684 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
686 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
688 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
689 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
695 DEFUN (ospf_area_range_cost
,
696 ospf_area_range_cost_cmd
,
697 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
698 "OSPF area parameters\n"
699 "OSPF area ID in IP address format\n"
700 "OSPF area ID as a decimal value\n"
701 "Summarize routes matching address/mask (border routers only)\n"
702 "Area range prefix\n"
703 "User specified metric for this range\n"
704 "Advertised metric for this range\n")
706 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
707 int idx_ipv4_number
= 1;
708 int idx_ipv4_prefixlen
= 3;
710 struct prefix_ipv4 p
;
711 struct in_addr area_id
;
715 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
716 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
718 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
719 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
722 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
723 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
728 DEFUN (ospf_area_range_not_advertise
,
729 ospf_area_range_not_advertise_cmd
,
730 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
731 "OSPF area parameters\n"
732 "OSPF area ID in IP address format\n"
733 "OSPF area ID as a decimal value\n"
734 "Summarize routes matching address/mask (border routers only)\n"
735 "Area range prefix\n"
736 "DoNotAdvertise this range\n")
738 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
739 int idx_ipv4_number
= 1;
740 int idx_ipv4_prefixlen
= 3;
741 struct prefix_ipv4 p
;
742 struct in_addr area_id
;
745 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
746 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
748 ospf_area_range_set(ospf
, area_id
, &p
, 0);
749 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
755 DEFUN (no_ospf_area_range
,
756 no_ospf_area_range_cmd
,
757 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
759 "OSPF area parameters\n"
760 "OSPF area ID in IP address format\n"
761 "OSPF area ID as a decimal value\n"
762 "Summarize routes matching address/mask (border routers only)\n"
763 "Area range prefix\n"
764 "User specified metric for this range\n"
765 "Advertised metric for this range\n"
766 "Advertise this range (default)\n"
767 "User specified metric for this range\n"
768 "Advertised metric for this range\n"
769 "DoNotAdvertise this range\n")
771 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
772 int idx_ipv4_number
= 2;
773 int idx_ipv4_prefixlen
= 4;
774 struct prefix_ipv4 p
;
775 struct in_addr area_id
;
778 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
779 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
781 ospf_area_range_unset(ospf
, area_id
, &p
);
786 DEFUN (ospf_area_range_substitute
,
787 ospf_area_range_substitute_cmd
,
788 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
789 "OSPF area parameters\n"
790 "OSPF area ID in IP address format\n"
791 "OSPF area ID as a decimal value\n"
792 "Summarize routes matching address/mask (border routers only)\n"
793 "Area range prefix\n"
794 "Announce area range as another prefix\n"
795 "Network prefix to be announced instead of range\n")
797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
798 int idx_ipv4_number
= 1;
799 int idx_ipv4_prefixlen
= 3;
800 int idx_ipv4_prefixlen_2
= 5;
801 struct prefix_ipv4 p
, s
;
802 struct in_addr area_id
;
805 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
806 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
807 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
809 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
810 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
816 DEFUN (no_ospf_area_range_substitute
,
817 no_ospf_area_range_substitute_cmd
,
818 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
820 "OSPF area parameters\n"
821 "OSPF area ID in IP address format\n"
822 "OSPF area ID as a decimal value\n"
823 "Summarize routes matching address/mask (border routers only)\n"
824 "Area range prefix\n"
825 "Announce area range as another prefix\n"
826 "Network prefix to be announced instead of range\n")
828 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
829 int idx_ipv4_number
= 2;
830 int idx_ipv4_prefixlen
= 4;
831 int idx_ipv4_prefixlen_2
= 6;
832 struct prefix_ipv4 p
, s
;
833 struct in_addr area_id
;
836 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
837 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
838 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
840 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
846 /* Command Handler Logic in VLink stuff is delicate!!
848 ALTER AT YOUR OWN RISK!!!!
850 Various dummy values are used to represent 'NoChange' state for
851 VLink configuration NOT being changed by a VLink command, and
852 special syntax is used within the command strings so that the
853 typed in command verbs can be seen in the configuration command
854 bacckend handler. This is to drastically reduce the verbeage
855 required to coe up with a reasonably compatible Cisco VLink command
857 - Matthew Grant <grantma@anathoth.gen.nz>
858 Wed, 21 Feb 2001 15:13:52 +1300
861 /* Configuration data for virtual links
863 struct ospf_vl_config_data
{
864 struct vty
*vty
; /* vty stuff */
865 struct in_addr area_id
; /* area ID from command line */
866 int area_id_fmt
; /* command line area ID format */
867 struct in_addr vl_peer
; /* command line vl_peer */
868 int auth_type
; /* Authehntication type, if given */
869 char *auth_key
; /* simple password if present */
870 int crypto_key_id
; /* Cryptographic key ID */
871 char *md5_key
; /* MD5 authentication key */
872 int hello_interval
; /* Obvious what these are... */
873 int retransmit_interval
;
878 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
881 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
882 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
883 vl_config
->vty
= vty
;
886 static struct ospf_vl_data
*
887 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
889 struct ospf_area
*area
;
890 struct ospf_vl_data
*vl_data
;
892 struct in_addr area_id
;
894 vty
= vl_config
->vty
;
895 area_id
= vl_config
->area_id
;
897 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
899 "Configuring VLs over the backbone is not allowed\n");
902 area
= ospf_area_get(ospf
, area_id
);
903 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
905 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
906 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
907 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
908 area
->external_routing
== OSPF_AREA_NSSA
912 vty_out(vty
, "Area %ld is %s\n",
913 (unsigned long)ntohl(area_id
.s_addr
),
914 area
->external_routing
== OSPF_AREA_NSSA
920 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
922 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
923 if (vl_data
->vl_oi
== NULL
) {
924 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
925 ospf_vl_add(ospf
, vl_data
);
926 ospf_spf_calculate_schedule(ospf
,
927 SPF_FLAG_CONFIG_CHANGE
);
934 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
935 struct ospf_vl_config_data
*vl_config
)
937 struct crypt_key
*ck
;
939 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
941 vty
= vl_config
->vty
;
943 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
944 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
945 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
948 if (vl_config
->auth_key
) {
949 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
950 OSPF_AUTH_SIMPLE_SIZE
+ 1);
951 strncpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
952 vl_config
->auth_key
, OSPF_AUTH_SIMPLE_SIZE
);
953 } else if (vl_config
->md5_key
) {
954 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
955 vl_config
->crypto_key_id
)
957 vty_out(vty
, "OSPF: Key %d already exists\n",
958 vl_config
->crypto_key_id
);
961 ck
= ospf_crypt_key_new();
962 ck
->key_id
= vl_config
->crypto_key_id
;
963 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
964 strncpy((char *)ck
->auth_key
, vl_config
->md5_key
,
967 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
968 } else if (vl_config
->crypto_key_id
!= 0) {
971 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
972 vl_config
->crypto_key_id
)
974 vty_out(vty
, "OSPF: Key %d does not exist\n",
975 vl_config
->crypto_key_id
);
976 return CMD_WARNING_CONFIG_FAILED
;
979 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
980 vl_config
->crypto_key_id
);
986 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
987 struct ospf_vl_config_data
*vl_config
)
989 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
990 /* Virtual Link data initialised to defaults, so only set
992 if (vl_config
->hello_interval
) {
993 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
994 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
997 if (vl_config
->dead_interval
) {
998 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
999 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1002 if (vl_config
->retransmit_interval
) {
1003 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1004 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1005 vl_config
->retransmit_interval
;
1008 if (vl_config
->transmit_delay
) {
1009 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1010 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1017 /* The business end of all of the above */
1018 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1020 struct ospf_vl_data
*vl_data
;
1023 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1025 return CMD_WARNING_CONFIG_FAILED
;
1027 /* Process this one first as it can have a fatal result, which can
1028 only logically occur if the virtual link exists already
1029 Thus a command error does not result in a change to the
1030 running configuration such as unexpectedly altered timer
1032 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1033 if (ret
!= CMD_SUCCESS
)
1036 /* Set any time based parameters, these area already range checked */
1038 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1039 if (ret
!= CMD_SUCCESS
)
1045 /* This stuff exists to make specifying all the alias commands A LOT simpler
1047 #define VLINK_HELPSTR_IPADDR \
1048 "OSPF area parameters\n" \
1049 "OSPF area ID in IP address format\n" \
1050 "OSPF area ID as a decimal value\n" \
1051 "Configure a virtual link\n" \
1052 "Router ID of the remote ABR\n"
1054 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1055 "Enable authentication on this virtual link\n" \
1058 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1059 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1060 "Use null authentication\n" \
1061 "Use message-digest authentication\n"
1063 #define VLINK_HELPSTR_TIME_PARAM \
1064 "Time between HELLO packets\n" \
1066 "Time between retransmitting lost link state advertisements\n" \
1068 "Link state transmit delay\n" \
1070 "Interval time after which a neighbor is declared down\n" \
1073 #define VLINK_HELPSTR_AUTH_SIMPLE \
1074 "Authentication password (key)\n" \
1075 "The OSPF password (key)\n"
1077 #define VLINK_HELPSTR_AUTH_MD5 \
1078 "Message digest authentication password (key)\n" \
1080 "Use MD5 algorithm\n" \
1081 "The OSPF password (key)\n"
1083 DEFUN (ospf_area_vlink
,
1084 ospf_area_vlink_cmd
,
1085 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1086 VLINK_HELPSTR_IPADDR
1087 "Enable authentication on this virtual link\n"
1088 "Use message-digest authentication\n"
1089 "Use null authentication\n"
1090 VLINK_HELPSTR_AUTH_MD5
1091 VLINK_HELPSTR_AUTH_SIMPLE
)
1093 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1094 int idx_ipv4_number
= 1;
1096 struct ospf_vl_config_data vl_config
;
1097 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1098 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1102 ospf_vl_config_data_init(&vl_config
, vty
);
1104 /* Read off first 2 parameters and check them */
1105 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1106 &vl_config
.area_id_fmt
);
1108 vty_out(vty
, "OSPF area ID is invalid\n");
1109 return CMD_WARNING_CONFIG_FAILED
;
1112 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1114 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1115 return CMD_WARNING_CONFIG_FAILED
;
1119 /* Thats all folks! - BUGS B. strikes again!!!*/
1121 return ospf_vl_set(ospf
, &vl_config
);
1124 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1125 /* authentication - this option can only occur
1126 at start of command line */
1127 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1130 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1131 /* authentication message-digest */
1132 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1133 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1134 /* "authentication null" */
1135 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1138 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1139 vl_config
.md5_key
= NULL
;
1140 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1141 if (vl_config
.crypto_key_id
< 0)
1142 return CMD_WARNING_CONFIG_FAILED
;
1144 memset(md5_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
1145 strncpy(md5_key
, argv
[idx
+ 3]->arg
, OSPF_AUTH_MD5_SIZE
);
1146 vl_config
.md5_key
= md5_key
;
1149 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1150 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1151 strncpy(auth_key
, argv
[idx
+ 1]->arg
, OSPF_AUTH_SIMPLE_SIZE
);
1152 vl_config
.auth_key
= auth_key
;
1155 /* Action configuration */
1157 return ospf_vl_set(ospf
, &vl_config
);
1160 DEFUN (no_ospf_area_vlink
,
1161 no_ospf_area_vlink_cmd
,
1162 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1164 VLINK_HELPSTR_IPADDR
1165 "Enable authentication on this virtual link\n" \
1166 "Use message-digest authentication\n" \
1167 "Use null authentication\n" \
1168 VLINK_HELPSTR_AUTH_MD5
1169 VLINK_HELPSTR_AUTH_SIMPLE
)
1171 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1172 int idx_ipv4_number
= 2;
1174 struct ospf_area
*area
;
1175 struct ospf_vl_config_data vl_config
;
1176 struct ospf_vl_data
*vl_data
= NULL
;
1177 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1181 ospf_vl_config_data_init(&vl_config
, vty
);
1183 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1186 vty_out(vty
, "OSPF area ID is invalid\n");
1187 return CMD_WARNING_CONFIG_FAILED
;
1190 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1192 vty_out(vty
, "Area does not exist\n");
1193 return CMD_WARNING_CONFIG_FAILED
;
1196 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1198 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1199 return CMD_WARNING_CONFIG_FAILED
;
1203 /* Basic VLink no command */
1204 /* Thats all folks! - BUGS B. strikes again!!!*/
1205 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
)))
1206 ospf_vl_delete(ospf
, vl_data
);
1208 ospf_area_check_free(ospf
, vl_config
.area_id
);
1213 /* If we are down here, we are reseting parameters */
1214 /* Deal with other parameters */
1216 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1217 /* authentication - this option can only occur
1218 at start of command line */
1219 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1222 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1223 vl_config
.md5_key
= NULL
;
1224 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1225 if (vl_config
.crypto_key_id
< 0)
1226 return CMD_WARNING_CONFIG_FAILED
;
1229 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1230 /* Reset authentication-key to 0 */
1231 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1232 vl_config
.auth_key
= auth_key
;
1235 /* Action configuration */
1237 return ospf_vl_set(ospf
, &vl_config
);
1240 DEFUN (ospf_area_vlink_intervals
,
1241 ospf_area_vlink_intervals_cmd
,
1242 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1243 VLINK_HELPSTR_IPADDR
1244 VLINK_HELPSTR_TIME_PARAM
)
1246 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1247 struct ospf_vl_config_data vl_config
;
1250 ospf_vl_config_data_init(&vl_config
, vty
);
1252 char *area_id
= argv
[1]->arg
;
1253 char *router_id
= argv
[3]->arg
;
1255 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1257 vty_out(vty
, "OSPF area ID is invalid\n");
1258 return CMD_WARNING_CONFIG_FAILED
;
1261 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1263 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1264 return CMD_WARNING_CONFIG_FAILED
;
1267 for (int idx
= 4; idx
< argc
; idx
++) {
1268 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1269 vl_config
.hello_interval
=
1270 strtol(argv
[++idx
]->arg
, NULL
, 10);
1271 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1272 vl_config
.retransmit_interval
=
1273 strtol(argv
[++idx
]->arg
, NULL
, 10);
1274 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1275 vl_config
.transmit_delay
=
1276 strtol(argv
[++idx
]->arg
, NULL
, 10);
1277 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1278 vl_config
.dead_interval
=
1279 strtol(argv
[++idx
]->arg
, NULL
, 10);
1282 /* Action configuration */
1283 return ospf_vl_set(ospf
, &vl_config
);
1286 DEFUN (no_ospf_area_vlink_intervals
,
1287 no_ospf_area_vlink_intervals_cmd
,
1288 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1290 VLINK_HELPSTR_IPADDR
1291 VLINK_HELPSTR_TIME_PARAM
)
1293 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1294 struct ospf_vl_config_data vl_config
;
1297 ospf_vl_config_data_init(&vl_config
, vty
);
1299 char *area_id
= argv
[2]->arg
;
1300 char *router_id
= argv
[4]->arg
;
1302 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1304 vty_out(vty
, "OSPF area ID is invalid\n");
1305 return CMD_WARNING_CONFIG_FAILED
;
1308 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1310 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1311 return CMD_WARNING_CONFIG_FAILED
;
1314 for (int idx
= 5; idx
< argc
; idx
++) {
1315 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1316 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1317 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1318 vl_config
.retransmit_interval
=
1319 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1320 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1321 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1322 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1323 vl_config
.dead_interval
=
1324 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1327 /* Action configuration */
1328 return ospf_vl_set(ospf
, &vl_config
);
1331 DEFUN (ospf_area_shortcut
,
1332 ospf_area_shortcut_cmd
,
1333 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1334 "OSPF area parameters\n"
1335 "OSPF area ID in IP address format\n"
1336 "OSPF area ID as a decimal value\n"
1337 "Configure the area's shortcutting mode\n"
1338 "Set default shortcutting behavior\n"
1339 "Enable shortcutting through the area\n"
1340 "Disable shortcutting through the area\n")
1342 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1343 int idx_ipv4_number
= 1;
1344 int idx_enable_disable
= 3;
1345 struct ospf_area
*area
;
1346 struct in_addr area_id
;
1350 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1351 argv
[idx_ipv4_number
]->arg
);
1353 area
= ospf_area_get(ospf
, area_id
);
1354 ospf_area_display_format_set(ospf
, area
, format
);
1356 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1357 mode
= OSPF_SHORTCUT_DEFAULT
;
1358 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1359 mode
= OSPF_SHORTCUT_DISABLE
;
1360 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1361 mode
= OSPF_SHORTCUT_ENABLE
;
1363 return CMD_WARNING_CONFIG_FAILED
;
1365 ospf_area_shortcut_set(ospf
, area
, mode
);
1367 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1369 "Shortcut area setting will take effect "
1370 "only when the router is configured as Shortcut ABR\n");
1375 DEFUN (no_ospf_area_shortcut
,
1376 no_ospf_area_shortcut_cmd
,
1377 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1379 "OSPF area parameters\n"
1380 "OSPF area ID in IP address format\n"
1381 "OSPF area ID as a decimal value\n"
1382 "Deconfigure the area's shortcutting mode\n"
1383 "Deconfigure enabled shortcutting through the area\n"
1384 "Deconfigure disabled shortcutting through the area\n")
1386 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1387 int idx_ipv4_number
= 2;
1388 struct ospf_area
*area
;
1389 struct in_addr area_id
;
1392 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1393 argv
[idx_ipv4_number
]->arg
);
1395 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1399 ospf_area_shortcut_unset(ospf
, area
);
1405 DEFUN (ospf_area_stub
,
1407 "area <A.B.C.D|(0-4294967295)> stub",
1408 "OSPF area parameters\n"
1409 "OSPF area ID in IP address format\n"
1410 "OSPF area ID as a decimal value\n"
1411 "Configure OSPF area as stub\n")
1413 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1414 int idx_ipv4_number
= 1;
1415 struct in_addr area_id
;
1418 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1419 argv
[idx_ipv4_number
]->arg
);
1421 ret
= ospf_area_stub_set(ospf
, area_id
);
1422 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1426 "First deconfigure all virtual link through this area\n");
1427 return CMD_WARNING_CONFIG_FAILED
;
1430 ospf_area_no_summary_unset(ospf
, area_id
);
1435 DEFUN (ospf_area_stub_no_summary
,
1436 ospf_area_stub_no_summary_cmd
,
1437 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1438 "OSPF stub parameters\n"
1439 "OSPF area ID in IP address format\n"
1440 "OSPF area ID as a decimal value\n"
1441 "Configure OSPF area as stub\n"
1442 "Do not inject inter-area routes into stub\n")
1444 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1445 int idx_ipv4_number
= 1;
1446 struct in_addr area_id
;
1449 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1450 argv
[idx_ipv4_number
]->arg
);
1452 ret
= ospf_area_stub_set(ospf
, area_id
);
1453 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1457 "%% Area cannot be stub as it contains a virtual link\n");
1458 return CMD_WARNING_CONFIG_FAILED
;
1461 ospf_area_no_summary_set(ospf
, area_id
);
1466 DEFUN (no_ospf_area_stub
,
1467 no_ospf_area_stub_cmd
,
1468 "no area <A.B.C.D|(0-4294967295)> stub",
1470 "OSPF area parameters\n"
1471 "OSPF area ID in IP address format\n"
1472 "OSPF area ID as a decimal value\n"
1473 "Configure OSPF area as stub\n")
1475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1476 int idx_ipv4_number
= 2;
1477 struct in_addr area_id
;
1480 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1481 argv
[idx_ipv4_number
]->arg
);
1483 ospf_area_stub_unset(ospf
, area_id
);
1484 ospf_area_no_summary_unset(ospf
, area_id
);
1489 DEFUN (no_ospf_area_stub_no_summary
,
1490 no_ospf_area_stub_no_summary_cmd
,
1491 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1493 "OSPF area parameters\n"
1494 "OSPF area ID in IP address format\n"
1495 "OSPF area ID as a decimal value\n"
1496 "Configure OSPF area as stub\n"
1497 "Do not inject inter-area routes into area\n")
1499 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1500 int idx_ipv4_number
= 2;
1501 struct in_addr area_id
;
1504 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1505 argv
[idx_ipv4_number
]->arg
);
1506 ospf_area_no_summary_unset(ospf
, area_id
);
1511 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1512 struct cmd_token
**argv
, int cfg_nosum
,
1515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1516 struct in_addr area_id
;
1519 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1521 ret
= ospf_area_nssa_set(ospf
, area_id
);
1522 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1526 "%% Area cannot be nssa as it contains a virtual link\n");
1527 return CMD_WARNING_CONFIG_FAILED
;
1531 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1532 ospf_area_nssa_translator_role_set(
1533 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1534 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1535 ospf_area_nssa_translator_role_set(
1536 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1537 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1538 ospf_area_nssa_translator_role_set(
1539 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1541 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1542 OSPF_NSSA_ROLE_CANDIDATE
);
1547 ospf_area_no_summary_set(ospf
, area_id
);
1549 ospf_area_no_summary_unset(ospf
, area_id
);
1552 ospf_schedule_abr_task(ospf
);
1558 DEFUN (ospf_area_nssa_translate
,
1559 ospf_area_nssa_translate_cmd
,
1560 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1561 "OSPF area parameters\n"
1562 "OSPF area ID in IP address format\n"
1563 "OSPF area ID as a decimal value\n"
1564 "Configure OSPF area as nssa\n"
1565 "Configure NSSA-ABR for translate election (default)\n"
1566 "Configure NSSA-ABR to never translate\n"
1567 "Configure NSSA-ABR to always translate\n")
1569 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1572 DEFUN (ospf_area_nssa
,
1574 "area <A.B.C.D|(0-4294967295)> nssa",
1575 "OSPF area parameters\n"
1576 "OSPF area ID in IP address format\n"
1577 "OSPF area ID as a decimal value\n"
1578 "Configure OSPF area as nssa\n")
1580 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1583 DEFUN (ospf_area_nssa_no_summary
,
1584 ospf_area_nssa_no_summary_cmd
,
1585 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1586 "OSPF area parameters\n"
1587 "OSPF area ID in IP address format\n"
1588 "OSPF area ID as a decimal value\n"
1589 "Configure OSPF area as nssa\n"
1590 "Do not inject inter-area routes into nssa\n")
1592 int idx_ipv4_number
= 1;
1593 struct in_addr area_id
;
1596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1597 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1598 argv
[idx_ipv4_number
]->arg
);
1600 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1602 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1604 ospf_schedule_abr_task(ospf
);
1609 DEFUN (no_ospf_area_nssa_no_summary
,
1610 no_ospf_area_nssa_no_summary_cmd
,
1611 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1613 "OSPF area parameters\n"
1614 "OSPF area ID in IP address format\n"
1615 "OSPF area ID as a decimal value\n"
1616 "Configure OSPF area as nssa\n"
1617 "Do not inject inter-area routes into nssa\n")
1619 int idx_ipv4_number
= 2;
1620 struct in_addr area_id
;
1623 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1625 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1626 argv
[idx_ipv4_number
]->arg
);
1628 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1630 ospf_area_no_summary_unset(ospf
, area_id
);
1632 ospf_schedule_abr_task(ospf
);
1637 DEFUN (no_ospf_area_nssa
,
1638 no_ospf_area_nssa_cmd
,
1639 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1641 "OSPF area parameters\n"
1642 "OSPF area ID in IP address format\n"
1643 "OSPF area ID as a decimal value\n"
1644 "Configure OSPF area as nssa\n"
1645 "Configure NSSA-ABR for translate election (default)\n"
1646 "Configure NSSA-ABR to never translate\n"
1647 "Configure NSSA-ABR to always translate\n")
1649 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1650 int idx_ipv4_number
= 2;
1651 struct in_addr area_id
;
1654 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1655 argv
[idx_ipv4_number
]->arg
);
1657 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1659 ospf_schedule_abr_task(ospf
);
1665 DEFUN (ospf_area_default_cost
,
1666 ospf_area_default_cost_cmd
,
1667 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1668 "OSPF area parameters\n"
1669 "OSPF area ID in IP address format\n"
1670 "OSPF area ID as a decimal value\n"
1671 "Set the summary-default cost of a NSSA or stub area\n"
1672 "Stub's advertised default summary cost\n")
1674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1675 int idx_ipv4_number
= 1;
1677 struct ospf_area
*area
;
1678 struct in_addr area_id
;
1681 struct prefix_ipv4 p
;
1683 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1684 argv
[idx_ipv4_number
]->arg
);
1685 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1687 area
= ospf_area_get(ospf
, area_id
);
1688 ospf_area_display_format_set(ospf
, area
, format
);
1690 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1691 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1692 return CMD_WARNING_CONFIG_FAILED
;
1695 area
->default_cost
= cost
;
1698 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1700 if (IS_DEBUG_OSPF_EVENT
)
1702 "ospf_abr_announce_stub_defaults(): "
1703 "announcing 0.0.0.0/0 to area %s",
1704 inet_ntoa(area
->area_id
));
1705 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1710 DEFUN (no_ospf_area_default_cost
,
1711 no_ospf_area_default_cost_cmd
,
1712 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1714 "OSPF area parameters\n"
1715 "OSPF area ID in IP address format\n"
1716 "OSPF area ID as a decimal value\n"
1717 "Set the summary-default cost of a NSSA or stub area\n"
1718 "Stub's advertised default summary cost\n")
1720 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1721 int idx_ipv4_number
= 2;
1722 struct ospf_area
*area
;
1723 struct in_addr area_id
;
1725 struct prefix_ipv4 p
;
1727 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1728 argv
[idx_ipv4_number
]->arg
);
1730 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1734 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1735 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1736 return CMD_WARNING_CONFIG_FAILED
;
1739 area
->default_cost
= 1;
1742 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1744 if (IS_DEBUG_OSPF_EVENT
)
1746 "ospf_abr_announce_stub_defaults(): "
1747 "announcing 0.0.0.0/0 to area %s",
1748 inet_ntoa(area
->area_id
));
1749 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1752 ospf_area_check_free(ospf
, area_id
);
1757 DEFUN (ospf_area_export_list
,
1758 ospf_area_export_list_cmd
,
1759 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1760 "OSPF area parameters\n"
1761 "OSPF area ID in IP address format\n"
1762 "OSPF area ID as a decimal value\n"
1763 "Set the filter for networks announced to other areas\n"
1764 "Name of the access-list\n")
1766 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1767 int idx_ipv4_number
= 1;
1768 struct ospf_area
*area
;
1769 struct in_addr area_id
;
1772 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1774 area
= ospf_area_get(ospf
, area_id
);
1775 ospf_area_display_format_set(ospf
, area
, format
);
1776 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1781 DEFUN (no_ospf_area_export_list
,
1782 no_ospf_area_export_list_cmd
,
1783 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1785 "OSPF area parameters\n"
1786 "OSPF area ID in IP address format\n"
1787 "OSPF area ID as a decimal value\n"
1788 "Unset the filter for networks announced to other areas\n"
1789 "Name of the access-list\n")
1791 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1792 int idx_ipv4_number
= 2;
1793 struct ospf_area
*area
;
1794 struct in_addr area_id
;
1797 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1799 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1803 ospf_area_export_list_unset(ospf
, area
);
1809 DEFUN (ospf_area_import_list
,
1810 ospf_area_import_list_cmd
,
1811 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1812 "OSPF area parameters\n"
1813 "OSPF area ID in IP address format\n"
1814 "OSPF area ID as a decimal value\n"
1815 "Set the filter for networks from other areas announced to the specified one\n"
1816 "Name of the access-list\n")
1818 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1819 int idx_ipv4_number
= 1;
1820 struct ospf_area
*area
;
1821 struct in_addr area_id
;
1824 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1826 area
= ospf_area_get(ospf
, area_id
);
1827 ospf_area_display_format_set(ospf
, area
, format
);
1828 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1833 DEFUN (no_ospf_area_import_list
,
1834 no_ospf_area_import_list_cmd
,
1835 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1837 "OSPF area parameters\n"
1838 "OSPF area ID in IP address format\n"
1839 "OSPF area ID as a decimal value\n"
1840 "Unset the filter for networks announced to other areas\n"
1841 "Name of the access-list\n")
1843 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1844 int idx_ipv4_number
= 2;
1845 struct ospf_area
*area
;
1846 struct in_addr area_id
;
1849 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1851 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1855 ospf_area_import_list_unset(ospf
, area
);
1860 DEFUN (ospf_area_filter_list
,
1861 ospf_area_filter_list_cmd
,
1862 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1863 "OSPF area parameters\n"
1864 "OSPF area ID in IP address format\n"
1865 "OSPF area ID as a decimal value\n"
1866 "Filter networks between OSPF areas\n"
1867 "Filter prefixes between OSPF areas\n"
1868 "Name of an IP prefix-list\n"
1869 "Filter networks sent to this area\n"
1870 "Filter networks sent from this area\n")
1872 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1873 int idx_ipv4_number
= 1;
1876 struct ospf_area
*area
;
1877 struct in_addr area_id
;
1878 struct prefix_list
*plist
;
1881 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1883 area
= ospf_area_get(ospf
, area_id
);
1884 ospf_area_display_format_set(ospf
, area
, format
);
1885 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1886 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1887 PREFIX_LIST_IN(area
) = plist
;
1888 if (PREFIX_NAME_IN(area
))
1889 free(PREFIX_NAME_IN(area
));
1891 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1892 ospf_schedule_abr_task(ospf
);
1894 PREFIX_LIST_OUT(area
) = plist
;
1895 if (PREFIX_NAME_OUT(area
))
1896 free(PREFIX_NAME_OUT(area
));
1898 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1899 ospf_schedule_abr_task(ospf
);
1905 DEFUN (no_ospf_area_filter_list
,
1906 no_ospf_area_filter_list_cmd
,
1907 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1909 "OSPF area parameters\n"
1910 "OSPF area ID in IP address format\n"
1911 "OSPF area ID as a decimal value\n"
1912 "Filter networks between OSPF areas\n"
1913 "Filter prefixes between OSPF areas\n"
1914 "Name of an IP prefix-list\n"
1915 "Filter networks sent to this area\n"
1916 "Filter networks sent from this area\n")
1918 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1919 int idx_ipv4_number
= 2;
1922 struct ospf_area
*area
;
1923 struct in_addr area_id
;
1926 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1928 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1931 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1932 if (PREFIX_NAME_IN(area
))
1933 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1937 PREFIX_LIST_IN(area
) = NULL
;
1938 if (PREFIX_NAME_IN(area
))
1939 free(PREFIX_NAME_IN(area
));
1941 PREFIX_NAME_IN(area
) = NULL
;
1943 ospf_schedule_abr_task(ospf
);
1945 if (PREFIX_NAME_OUT(area
))
1946 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1950 PREFIX_LIST_OUT(area
) = NULL
;
1951 if (PREFIX_NAME_OUT(area
))
1952 free(PREFIX_NAME_OUT(area
));
1954 PREFIX_NAME_OUT(area
) = NULL
;
1956 ospf_schedule_abr_task(ospf
);
1963 DEFUN (ospf_area_authentication_message_digest
,
1964 ospf_area_authentication_message_digest_cmd
,
1965 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1967 "OSPF area parameters\n"
1968 "OSPF area ID in IP address format\n"
1969 "OSPF area ID as a decimal value\n"
1970 "Enable authentication\n"
1971 "Use message-digest authentication\n")
1973 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1975 struct ospf_area
*area
;
1976 struct in_addr area_id
;
1979 argv_find(argv
, argc
, "area", &idx
);
1980 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1982 area
= ospf_area_get(ospf
, area_id
);
1983 ospf_area_display_format_set(ospf
, area
, format
);
1984 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1986 : OSPF_AUTH_CRYPTOGRAPHIC
;
1991 DEFUN (ospf_area_authentication
,
1992 ospf_area_authentication_cmd
,
1993 "area <A.B.C.D|(0-4294967295)> authentication",
1994 "OSPF area parameters\n"
1995 "OSPF area ID in IP address format\n"
1996 "OSPF area ID as a decimal value\n"
1997 "Enable authentication\n")
1999 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2000 int idx_ipv4_number
= 1;
2001 struct ospf_area
*area
;
2002 struct in_addr area_id
;
2005 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2007 area
= ospf_area_get(ospf
, area_id
);
2008 ospf_area_display_format_set(ospf
, area
, format
);
2009 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2014 DEFUN (no_ospf_area_authentication
,
2015 no_ospf_area_authentication_cmd
,
2016 "no area <A.B.C.D|(0-4294967295)> authentication",
2018 "OSPF area parameters\n"
2019 "OSPF area ID in IP address format\n"
2020 "OSPF area ID as a decimal value\n"
2021 "Enable authentication\n")
2023 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2024 int idx_ipv4_number
= 2;
2025 struct ospf_area
*area
;
2026 struct in_addr area_id
;
2029 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2031 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2035 area
->auth_type
= OSPF_AUTH_NULL
;
2037 ospf_area_check_free(ospf
, area_id
);
2043 DEFUN (ospf_abr_type
,
2045 "ospf abr-type <cisco|ibm|shortcut|standard>",
2046 "OSPF specific commands\n"
2047 "Set OSPF ABR type\n"
2048 "Alternative ABR, cisco implementation\n"
2049 "Alternative ABR, IBM implementation\n"
2051 "Standard behavior (RFC2328)\n")
2053 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2055 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2057 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2058 abr_type
= OSPF_ABR_CISCO
;
2059 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2060 abr_type
= OSPF_ABR_IBM
;
2061 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2062 abr_type
= OSPF_ABR_SHORTCUT
;
2063 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2064 abr_type
= OSPF_ABR_STAND
;
2066 return CMD_WARNING_CONFIG_FAILED
;
2068 /* If ABR type value is changed, schedule ABR task. */
2069 if (ospf
->abr_type
!= abr_type
) {
2070 ospf
->abr_type
= abr_type
;
2071 ospf_schedule_abr_task(ospf
);
2077 DEFUN (no_ospf_abr_type
,
2078 no_ospf_abr_type_cmd
,
2079 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2081 "OSPF specific commands\n"
2082 "Set OSPF ABR type\n"
2083 "Alternative ABR, cisco implementation\n"
2084 "Alternative ABR, IBM implementation\n"
2088 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2090 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2092 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2093 abr_type
= OSPF_ABR_CISCO
;
2094 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2095 abr_type
= OSPF_ABR_IBM
;
2096 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2097 abr_type
= OSPF_ABR_SHORTCUT
;
2098 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2099 abr_type
= OSPF_ABR_STAND
;
2101 return CMD_WARNING_CONFIG_FAILED
;
2103 /* If ABR type value is changed, schedule ABR task. */
2104 if (ospf
->abr_type
== abr_type
) {
2105 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2106 ospf_schedule_abr_task(ospf
);
2112 DEFUN (ospf_log_adjacency_changes
,
2113 ospf_log_adjacency_changes_cmd
,
2114 "log-adjacency-changes",
2115 "Log changes in adjacency state\n")
2117 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2119 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2120 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2124 DEFUN (ospf_log_adjacency_changes_detail
,
2125 ospf_log_adjacency_changes_detail_cmd
,
2126 "log-adjacency-changes detail",
2127 "Log changes in adjacency state\n"
2128 "Log all state changes\n")
2130 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2132 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2133 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2137 DEFUN (no_ospf_log_adjacency_changes
,
2138 no_ospf_log_adjacency_changes_cmd
,
2139 "no log-adjacency-changes",
2141 "Log changes in adjacency state\n")
2143 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2145 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2146 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2150 DEFUN (no_ospf_log_adjacency_changes_detail
,
2151 no_ospf_log_adjacency_changes_detail_cmd
,
2152 "no log-adjacency-changes detail",
2154 "Log changes in adjacency state\n"
2155 "Log all state changes\n")
2157 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2159 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2163 DEFUN (ospf_compatible_rfc1583
,
2164 ospf_compatible_rfc1583_cmd
,
2165 "compatible rfc1583",
2166 "OSPF compatibility list\n"
2167 "compatible with RFC 1583\n")
2169 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2171 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2172 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2173 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2178 DEFUN (no_ospf_compatible_rfc1583
,
2179 no_ospf_compatible_rfc1583_cmd
,
2180 "no compatible rfc1583",
2182 "OSPF compatibility list\n"
2183 "compatible with RFC 1583\n")
2185 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2187 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2188 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2189 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2194 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2195 "ospf rfc1583compatibility",
2196 "OSPF specific commands\n"
2197 "Enable the RFC1583Compatibility flag\n")
2199 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2200 "no ospf rfc1583compatibility", NO_STR
2201 "OSPF specific commands\n"
2202 "Disable the RFC1583Compatibility flag\n")
2204 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2205 unsigned int hold
, unsigned int max
)
2207 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2209 ospf
->spf_delay
= delay
;
2210 ospf
->spf_holdtime
= hold
;
2211 ospf
->spf_max_holdtime
= max
;
2216 DEFUN (ospf_timers_min_ls_interval
,
2217 ospf_timers_min_ls_interval_cmd
,
2218 "timers throttle lsa all (0-5000)",
2219 "Adjust routing timers\n"
2220 "Throttling adaptive timer\n"
2221 "LSA delay between transmissions\n"
2223 "Delay (msec) between sending LSAs\n")
2225 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2227 unsigned int interval
;
2230 vty_out(vty
, "Insufficient arguments\n");
2231 return CMD_WARNING_CONFIG_FAILED
;
2234 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2236 ospf
->min_ls_interval
= interval
;
2241 DEFUN (no_ospf_timers_min_ls_interval
,
2242 no_ospf_timers_min_ls_interval_cmd
,
2243 "no timers throttle lsa all [(0-5000)]",
2245 "Adjust routing timers\n"
2246 "Throttling adaptive timer\n"
2247 "LSA delay between transmissions\n"
2249 "Delay (msec) between sending LSAs\n")
2251 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2252 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2257 DEFUN (ospf_timers_throttle_spf
,
2258 ospf_timers_throttle_spf_cmd
,
2259 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2260 "Adjust routing timers\n"
2261 "Throttling adaptive timer\n"
2263 "Delay (msec) from first change received till SPF calculation\n"
2264 "Initial hold time (msec) between consecutive SPF calculations\n"
2265 "Maximum hold time (msec)\n")
2268 int idx_number_2
= 4;
2269 int idx_number_3
= 5;
2270 unsigned int delay
, hold
, max
;
2273 vty_out(vty
, "Insufficient arguments\n");
2274 return CMD_WARNING_CONFIG_FAILED
;
2277 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2278 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2279 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2281 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2284 DEFUN (no_ospf_timers_throttle_spf
,
2285 no_ospf_timers_throttle_spf_cmd
,
2286 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2288 "Adjust routing timers\n"
2289 "Throttling adaptive timer\n"
2291 "Delay (msec) from first change received till SPF calculation\n"
2292 "Initial hold time (msec) between consecutive SPF calculations\n"
2293 "Maximum hold time (msec)\n")
2295 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2296 OSPF_SPF_HOLDTIME_DEFAULT
,
2297 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2301 DEFUN (ospf_timers_lsa_min_arrival
,
2302 ospf_timers_lsa_min_arrival_cmd
,
2303 "timers lsa min-arrival (0-600000)",
2304 "Adjust routing timers\n"
2306 "Minimum delay in receiving new version of a LSA\n"
2307 "Delay in milliseconds\n")
2309 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2310 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2314 DEFUN (no_ospf_timers_lsa_min_arrival
,
2315 no_ospf_timers_lsa_min_arrival_cmd
,
2316 "no timers lsa min-arrival [(0-600000)]",
2318 "Adjust routing timers\n"
2320 "Minimum delay in receiving new version of a LSA\n"
2321 "Delay in milliseconds\n")
2323 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2324 unsigned int minarrival
;
2327 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2329 if (ospf
->min_ls_arrival
!= minarrival
2330 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2334 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2339 DEFUN (ospf_neighbor
,
2341 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2343 "Neighbor IP address\n"
2344 "Neighbor Priority\n"
2346 "Dead Neighbor Polling interval\n"
2349 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2353 struct in_addr nbr_addr
;
2354 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2355 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2357 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2358 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2359 return CMD_WARNING_CONFIG_FAILED
;
2363 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2366 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2368 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2371 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2374 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2379 DEFUN (ospf_neighbor_poll_interval
,
2380 ospf_neighbor_poll_interval_cmd
,
2381 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2383 "Neighbor IP address\n"
2384 "Dead Neighbor Polling interval\n"
2386 "OSPF priority of non-broadcast neighbor\n"
2389 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2393 struct in_addr nbr_addr
;
2394 unsigned int priority
;
2395 unsigned int interval
;
2397 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2398 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2399 return CMD_WARNING_CONFIG_FAILED
;
2402 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2404 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2405 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2407 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2408 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2411 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2416 DEFUN (no_ospf_neighbor
,
2417 no_ospf_neighbor_cmd
,
2418 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2421 "Neighbor IP address\n"
2422 "Neighbor Priority\n"
2424 "Dead Neighbor Polling interval\n"
2427 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2429 struct in_addr nbr_addr
;
2431 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2432 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2433 return CMD_WARNING_CONFIG_FAILED
;
2436 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2441 DEFUN (no_ospf_neighbor_poll
,
2442 no_ospf_neighbor_poll_cmd
,
2443 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2446 "Neighbor IP address\n"
2447 "Dead Neighbor Polling interval\n"
2449 "Neighbor Priority\n"
2452 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2454 struct in_addr nbr_addr
;
2456 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2457 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2458 return CMD_WARNING_CONFIG_FAILED
;
2461 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2466 DEFUN (ospf_refresh_timer
,
2467 ospf_refresh_timer_cmd
,
2468 "refresh timer (10-1800)",
2469 "Adjust refresh parameters\n"
2470 "Set refresh timer\n"
2471 "Timer value in seconds\n")
2473 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2475 unsigned int interval
;
2477 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2478 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2479 * OSPF_LSA_REFRESHER_GRANULARITY
;
2481 ospf_timers_refresh_set(ospf
, interval
);
2486 DEFUN (no_ospf_refresh_timer
,
2487 no_ospf_refresh_timer_val_cmd
,
2488 "no refresh timer [(10-1800)]",
2490 "Adjust refresh parameters\n"
2491 "Unset refresh timer\n"
2492 "Timer value in seconds\n")
2494 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2496 unsigned int interval
;
2499 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2501 if (ospf
->lsa_refresh_interval
!= interval
2502 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2506 ospf_timers_refresh_unset(ospf
);
2512 DEFUN (ospf_auto_cost_reference_bandwidth
,
2513 ospf_auto_cost_reference_bandwidth_cmd
,
2514 "auto-cost reference-bandwidth (1-4294967)",
2515 "Calculate OSPF interface cost according to bandwidth\n"
2516 "Use reference bandwidth method to assign OSPF cost\n"
2517 "The reference bandwidth in terms of Mbits per second\n")
2519 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2520 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2523 struct interface
*ifp
;
2525 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2526 if (refbw
< 1 || refbw
> 4294967) {
2527 vty_out(vty
, "reference-bandwidth value is invalid\n");
2528 return CMD_WARNING_CONFIG_FAILED
;
2531 /* If reference bandwidth is changed. */
2532 if ((refbw
) == ospf
->ref_bandwidth
)
2535 ospf
->ref_bandwidth
= refbw
;
2536 FOR_ALL_INTERFACES (vrf
, ifp
)
2537 ospf_if_recalculate_output_cost(ifp
);
2542 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2543 no_ospf_auto_cost_reference_bandwidth_cmd
,
2544 "no auto-cost reference-bandwidth [(1-4294967)]",
2546 "Calculate OSPF interface cost according to bandwidth\n"
2547 "Use reference bandwidth method to assign OSPF cost\n"
2548 "The reference bandwidth in terms of Mbits per second\n")
2550 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2551 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2552 struct interface
*ifp
;
2554 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2557 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2558 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2560 " Please ensure reference bandwidth is consistent across all routers\n");
2562 FOR_ALL_INTERFACES (vrf
, ifp
)
2563 ospf_if_recalculate_output_cost(ifp
);
2568 DEFUN (ospf_write_multiplier
,
2569 ospf_write_multiplier_cmd
,
2570 "ospf write-multiplier (1-100)",
2571 "OSPF specific commands\n"
2572 "Write multiplier\n"
2573 "Maximum number of interface serviced per write\n")
2575 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2577 uint32_t write_oi_count
;
2584 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2585 if (write_oi_count
< 1 || write_oi_count
> 100) {
2586 vty_out(vty
, "write-multiplier value is invalid\n");
2587 return CMD_WARNING_CONFIG_FAILED
;
2590 ospf
->write_oi_count
= write_oi_count
;
2594 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2595 "Write multiplier\n"
2596 "Maximum number of interface serviced per write\n")
2598 DEFUN (no_ospf_write_multiplier
,
2599 no_ospf_write_multiplier_cmd
,
2600 "no ospf write-multiplier (1-100)",
2602 "OSPF specific commands\n"
2603 "Write multiplier\n"
2604 "Maximum number of interface serviced per write\n")
2606 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2608 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2612 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2613 "no write-multiplier (1-100)", NO_STR
2614 "Write multiplier\n"
2615 "Maximum number of interface serviced per write\n")
2617 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2618 "Alternative IBM", "Alternative Cisco",
2619 "Alternative Shortcut"};
2621 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2623 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2624 json_object
*json_areas
, bool use_json
)
2626 json_object
*json_area
= NULL
;
2629 json_area
= json_object_new_object();
2633 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2635 /* Show Area type/mode. */
2636 if (OSPF_IS_AREA_BACKBONE(area
)) {
2638 json_object_boolean_true_add(json_area
, "backbone");
2640 vty_out(vty
, " (Backbone)\n");
2643 if (area
->external_routing
== OSPF_AREA_STUB
) {
2644 if (area
->no_summary
)
2645 json_object_boolean_true_add(
2646 json_area
, "stubNoSummary");
2647 if (area
->shortcut_configured
)
2648 json_object_boolean_true_add(
2649 json_area
, "stubShortcut");
2650 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2651 if (area
->no_summary
)
2652 json_object_boolean_true_add(
2653 json_area
, "nssaNoSummary");
2654 if (area
->shortcut_configured
)
2655 json_object_boolean_true_add(
2656 json_area
, "nssaShortcut");
2659 json_object_string_add(
2660 json_area
, "shortcuttingMode",
2661 ospf_shortcut_mode_descr_str
2662 [area
->shortcut_configured
]);
2663 if (area
->shortcut_capability
)
2664 json_object_boolean_true_add(json_area
,
2667 if (area
->external_routing
== OSPF_AREA_STUB
)
2668 vty_out(vty
, " (Stub%s%s)",
2669 area
->no_summary
? ", no summary" : "",
2670 area
->shortcut_configured
? "; " : "");
2671 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2672 vty_out(vty
, " (NSSA%s%s)",
2673 area
->no_summary
? ", no summary" : "",
2674 area
->shortcut_configured
? "; " : "");
2677 vty_out(vty
, " Shortcutting mode: %s",
2678 ospf_shortcut_mode_descr_str
2679 [area
->shortcut_configured
]);
2680 vty_out(vty
, ", S-bit consensus: %s\n",
2681 area
->shortcut_capability
? "ok" : "no");
2685 /* Show number of interfaces */
2687 json_object_int_add(json_area
, "areaIfTotalCounter",
2688 listcount(area
->oiflist
));
2689 json_object_int_add(json_area
, "areaIfActiveCounter",
2693 " Number of interfaces in this area: Total: %d, "
2695 listcount(area
->oiflist
), area
->act_ints
);
2697 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2699 json_object_boolean_true_add(json_area
, "nssa");
2700 if (!IS_OSPF_ABR(area
->ospf
))
2701 json_object_boolean_false_add(json_area
, "abr");
2702 else if (area
->NSSATranslatorState
) {
2703 json_object_boolean_true_add(json_area
, "abr");
2704 if (area
->NSSATranslatorRole
2705 == OSPF_NSSA_ROLE_CANDIDATE
)
2706 json_object_boolean_true_add(
2708 "nssaTranslatorElected");
2709 else if (area
->NSSATranslatorRole
2710 == OSPF_NSSA_ROLE_ALWAYS
)
2711 json_object_boolean_true_add(
2713 "nssaTranslatorAlways");
2715 json_object_boolean_true_add(json_area
, "abr");
2716 if (area
->NSSATranslatorRole
2717 == OSPF_NSSA_ROLE_CANDIDATE
)
2718 json_object_boolean_false_add(
2720 "nssaTranslatorElected");
2722 json_object_boolean_true_add(
2724 "nssaTranslatorNever");
2728 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2729 if (!IS_OSPF_ABR(area
->ospf
))
2731 " It is not ABR, therefore not Translator. \n");
2732 else if (area
->NSSATranslatorState
) {
2733 vty_out(vty
, " We are an ABR and ");
2734 if (area
->NSSATranslatorRole
2735 == OSPF_NSSA_ROLE_CANDIDATE
)
2737 "the NSSA Elected Translator. \n");
2738 else if (area
->NSSATranslatorRole
2739 == OSPF_NSSA_ROLE_ALWAYS
)
2741 "always an NSSA Translator. \n");
2743 vty_out(vty
, " We are an ABR, but ");
2744 if (area
->NSSATranslatorRole
2745 == OSPF_NSSA_ROLE_CANDIDATE
)
2747 "not the NSSA Elected Translator. \n");
2750 "never an NSSA Translator. \n");
2755 /* Stub-router state for this area */
2756 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2757 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2760 json_object_boolean_true_add(
2761 json_area
, "originStubMaxDistRouterLsa");
2762 if (CHECK_FLAG(area
->stub_router_state
,
2763 OSPF_AREA_ADMIN_STUB_ROUTED
))
2764 json_object_boolean_true_add(
2765 json_area
, "indefiniteActiveAdmin");
2766 if (area
->t_stub_router
) {
2770 &area
->t_stub_router
->u
.sands
,
2773 json_object_int_add(
2775 "activeStartupRemainderMsecs",
2780 " Originating stub / maximum-distance Router-LSA\n");
2781 if (CHECK_FLAG(area
->stub_router_state
,
2782 OSPF_AREA_ADMIN_STUB_ROUTED
))
2784 " Administratively activated (indefinitely)\n");
2785 if (area
->t_stub_router
)
2787 " Active from startup, %s remaining\n",
2788 ospf_timer_dump(area
->t_stub_router
,
2795 /* Show number of fully adjacent neighbors. */
2796 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2799 /* Show authentication type. */
2800 if (area
->auth_type
== OSPF_AUTH_NULL
)
2801 json_object_string_add(json_area
, "authentication",
2802 "authenticationNone");
2803 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2804 json_object_string_add(json_area
, "authentication",
2805 "authenticationSimplePassword");
2806 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2807 json_object_string_add(json_area
, "authentication",
2808 "authenticationMessageDigest");
2810 if (!OSPF_IS_AREA_BACKBONE(area
))
2811 json_object_int_add(json_area
,
2812 "virtualAdjacenciesPassingCounter",
2815 /* Show SPF calculation times. */
2816 json_object_int_add(json_area
, "spfExecutedCounter",
2817 area
->spf_calculation
);
2818 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2819 json_object_int_add(
2820 json_area
, "lsaRouterNumber",
2821 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2822 json_object_int_add(
2823 json_area
, "lsaRouterChecksum",
2824 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2825 json_object_int_add(
2826 json_area
, "lsaNetworkNumber",
2827 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2828 json_object_int_add(
2829 json_area
, "lsaNetworkChecksum",
2830 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2831 json_object_int_add(
2832 json_area
, "lsaSummaryNumber",
2833 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2834 json_object_int_add(
2835 json_area
, "lsaSummaryChecksum",
2836 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2837 json_object_int_add(
2838 json_area
, "lsaAsbrNumber",
2839 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2840 json_object_int_add(
2841 json_area
, "lsaAsbrChecksum",
2842 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaNssaNumber",
2845 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaNssaChecksum",
2848 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2850 /* Show number of fully adjacent neighbors. */
2852 " Number of fully adjacent neighbors in this area:"
2856 /* Show authentication type. */
2857 vty_out(vty
, " Area has ");
2858 if (area
->auth_type
== OSPF_AUTH_NULL
)
2859 vty_out(vty
, "no authentication\n");
2860 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2861 vty_out(vty
, "simple password authentication\n");
2862 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2863 vty_out(vty
, "message digest authentication\n");
2865 if (!OSPF_IS_AREA_BACKBONE(area
))
2867 " Number of full virtual adjacencies going through"
2871 /* Show SPF calculation times. */
2872 vty_out(vty
, " SPF algorithm executed %d times\n",
2873 area
->spf_calculation
);
2875 /* Show number of LSA. */
2876 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2878 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2879 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2880 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2882 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2883 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2884 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2886 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2887 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2888 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2890 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2891 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2892 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2893 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2894 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2895 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2899 json_object_int_add(
2900 json_area
, "lsaOpaqueLinkNumber",
2901 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2902 json_object_int_add(
2903 json_area
, "lsaOpaqueLinkChecksum",
2904 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2905 json_object_int_add(
2906 json_area
, "lsaOpaqueAreaNumber",
2907 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2908 json_object_int_add(
2909 json_area
, "lsaOpaqueAreaChecksum",
2910 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2913 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2914 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2915 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2917 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2918 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2919 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2923 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2929 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2930 json_object
*json
, uint8_t use_vrf
)
2932 struct listnode
*node
, *nnode
;
2933 struct ospf_area
*area
;
2934 struct timeval result
;
2935 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2936 json_object
*json_vrf
= NULL
;
2937 json_object
*json_areas
= NULL
;
2941 json_vrf
= json_object_new_object();
2944 json_areas
= json_object_new_object();
2947 if (ospf
->instance
) {
2949 json_object_int_add(json
, "ospfInstance",
2952 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2956 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2958 /* Show Router ID. */
2960 json_object_string_add(json_vrf
, "routerId",
2961 inet_ntoa(ospf
->router_id
));
2963 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2964 inet_ntoa(ospf
->router_id
));
2967 /* Graceful shutdown */
2968 if (ospf
->t_deferred_shutdown
) {
2973 &ospf
->t_deferred_shutdown
->u
.sands
,
2976 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
2980 " Deferred shutdown in progress, %s remaining\n",
2981 ospf_timer_dump(ospf
->t_deferred_shutdown
,
2982 timebuf
, sizeof(timebuf
)));
2986 /* Show capability. */
2988 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
2989 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
2990 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2991 json_object_boolean_true_add(json_vrf
,
2992 "rfc1583Compatibility");
2995 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
2996 vty_out(vty
, " This implementation conforms to RFC2328\n");
2997 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
2998 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3004 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3005 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3008 vty_out(vty
, " OpaqueCapability flag is %s\n",
3009 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3014 /* Show stub-router configuration */
3015 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3016 || ospf
->stub_router_shutdown_time
3017 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3019 json_object_boolean_true_add(json_vrf
,
3020 "stubAdvertisement");
3021 if (ospf
->stub_router_startup_time
3022 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3023 json_object_int_add(
3024 json_vrf
, "postStartEnabledMsecs",
3025 ospf
->stub_router_startup_time
/ 1000);
3026 if (ospf
->stub_router_shutdown_time
3027 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3028 json_object_int_add(
3029 json_vrf
, "preShutdownEnabledMsecs",
3030 ospf
->stub_router_shutdown_time
/ 1000);
3033 " Stub router advertisement is configured\n");
3034 if (ospf
->stub_router_startup_time
3035 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3037 " Enabled for %us after start-up\n",
3038 ospf
->stub_router_startup_time
);
3039 if (ospf
->stub_router_shutdown_time
3040 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3042 " Enabled for %us prior to full shutdown\n",
3043 ospf
->stub_router_shutdown_time
);
3047 /* Show SPF timers. */
3049 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3051 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3052 ospf
->spf_holdtime
);
3053 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3054 ospf
->spf_max_holdtime
);
3055 json_object_int_add(json_vrf
, "holdtimeMultplier",
3056 ospf
->spf_hold_multiplier
);
3059 " Initial SPF scheduling delay %d millisec(s)\n"
3060 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3061 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3062 " Hold time multiplier is currently %d\n",
3063 ospf
->spf_delay
, ospf
->spf_holdtime
,
3064 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3068 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3069 long time_store
= 0;
3072 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3073 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3076 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3077 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3078 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3081 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3083 vty_out(vty
, " SPF algorithm ");
3084 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3085 monotime_since(&ospf
->ts_spf
, &result
);
3086 vty_out(vty
, "last executed %s ago\n",
3087 ospf_timeval_dump(&result
, timebuf
,
3089 vty_out(vty
, " Last SPF duration %s\n",
3090 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3091 timebuf
, sizeof(timebuf
)));
3093 vty_out(vty
, "has not been run\n");
3097 if (ospf
->t_spf_calc
) {
3100 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3102 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3106 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3107 ospf
->min_ls_interval
);
3108 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3109 ospf
->min_ls_arrival
);
3110 /* Show write multiplier values */
3111 json_object_int_add(json_vrf
, "writeMultiplier",
3112 ospf
->write_oi_count
);
3113 /* Show refresh parameters. */
3114 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3115 ospf
->lsa_refresh_interval
* 1000);
3117 vty_out(vty
, " SPF timer %s%s\n",
3118 (ospf
->t_spf_calc
? "due in " : "is "),
3119 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3122 vty_out(vty
, " LSA minimum interval %d msecs\n",
3123 ospf
->min_ls_interval
);
3124 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3125 ospf
->min_ls_arrival
);
3127 /* Show write multiplier values */
3128 vty_out(vty
, " Write Multiplier set to %d \n",
3129 ospf
->write_oi_count
);
3131 /* Show refresh parameters. */
3132 vty_out(vty
, " Refresh timer %d secs\n",
3133 ospf
->lsa_refresh_interval
);
3136 /* Show ABR/ASBR flags. */
3137 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3139 json_object_string_add(
3140 json_vrf
, "abrType",
3141 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3144 " This router is an ABR, ABR type is: %s\n",
3145 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3147 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3149 json_object_string_add(
3150 json_vrf
, "asbrRouter",
3151 "injectingExternalRoutingInformation");
3154 " This router is an ASBR "
3155 "(injecting external routing information)\n");
3158 /* Show Number of AS-external-LSAs. */
3160 json_object_int_add(
3161 json_vrf
, "lsaExternalCounter",
3162 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3163 json_object_int_add(
3164 json_vrf
, "lsaExternalChecksum",
3165 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3168 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3169 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3170 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3174 json_object_int_add(
3175 json_vrf
, "lsaAsopaqueCounter",
3176 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3177 json_object_int_add(
3178 json_vrf
, "lsaAsOpaqueChecksum",
3179 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3182 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3183 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3184 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3187 /* Show number of areas attached. */
3189 json_object_int_add(json_vrf
, "attachedAreaCounter",
3190 listcount(ospf
->areas
));
3192 vty_out(vty
, " Number of areas attached to this router: %d\n",
3193 listcount(ospf
->areas
));
3195 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3196 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3198 json_object_boolean_true_add(
3199 json_vrf
, "adjacencyChangesLoggedAll");
3202 " All adjacency changes are logged\n");
3205 json_object_boolean_true_add(
3206 json_vrf
, "adjacencyChangesLogged");
3208 vty_out(vty
, " Adjacency changes are logged\n");
3211 /* Show each area status. */
3212 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3213 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3217 json_object_object_add(json_vrf
, "areas", json_areas
);
3218 if (ospf
->vrf_id
== VRF_DEFAULT
)
3219 json_object_object_add(json
, "default",
3222 json_object_object_add(json
, ospf
->name
,
3225 json_object_object_add(json
, "areas", json_areas
);
3233 DEFUN (show_ip_ospf
,
3235 "show ip ospf [vrf <NAME|all>] [json]",
3238 "OSPF information\n"
3244 bool uj
= use_json(argc
, argv
);
3245 struct listnode
*node
= NULL
;
3246 char *vrf_name
= NULL
;
3247 bool all_vrf
= FALSE
;
3248 int ret
= CMD_SUCCESS
;
3251 json_object
*json
= NULL
;
3252 uint8_t use_vrf
= 0;
3254 if (listcount(om
->ospf
) == 0)
3257 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3260 json
= json_object_new_object();
3262 /* vrf input is provided could be all or specific vrf*/
3264 bool ospf_output
= FALSE
;
3267 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3268 if (!ospf
->oi_running
)
3271 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3275 vty_out(vty
, "%s\n",
3276 json_object_to_json_string_ext(
3277 json
, JSON_C_TO_STRING_PRETTY
));
3278 json_object_free(json
);
3279 } else if (!ospf_output
)
3280 vty_out(vty
, "%% OSPF instance not found\n");
3283 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3284 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3286 vty_out(vty
, "%s\n",
3287 json_object_to_json_string_ext(
3288 json
, JSON_C_TO_STRING_PRETTY
));
3289 json_object_free(json
);
3291 vty_out(vty
, "%% OSPF instance not found \n");
3296 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3297 /* Display default ospf (instance 0) info */
3298 if (ospf
== NULL
|| !ospf
->oi_running
) {
3300 vty_out(vty
, "%s\n",
3301 json_object_to_json_string_ext(
3302 json
, JSON_C_TO_STRING_PRETTY
));
3303 json_object_free(json
);
3305 vty_out(vty
, "%% OSPF instance not found \n");
3312 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3314 vty_out(vty
, "%s\n",
3315 json_object_to_json_string_ext(
3316 json
, JSON_C_TO_STRING_PRETTY
));
3320 json_object_free(json
);
3325 DEFUN (show_ip_ospf_instance
,
3326 show_ip_ospf_instance_cmd
,
3327 "show ip ospf (1-65535) [json]",
3330 "OSPF information\n"
3336 unsigned short instance
= 0;
3337 bool uj
= use_json(argc
, argv
);
3338 int ret
= CMD_SUCCESS
;
3339 json_object
*json
= NULL
;
3341 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3342 ospf
= ospf_lookup_instance(instance
);
3344 return CMD_NOT_MY_INSTANCE
;
3346 if (!ospf
->oi_running
)
3350 json
= json_object_new_object();
3352 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3355 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3356 json
, JSON_C_TO_STRING_PRETTY
));
3357 json_object_free(json
);
3363 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3364 struct interface
*ifp
,
3365 json_object
*json_interface_sub
,
3369 struct ospf_neighbor
*nbr
;
3370 struct route_node
*rn
;
3371 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3373 /* Is interface up? */
3375 is_up
= if_is_operative(ifp
);
3377 json_object_boolean_true_add(json_interface_sub
,
3380 json_object_boolean_false_add(json_interface_sub
,
3383 json_object_int_add(json_interface_sub
, "ifIndex",
3385 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3386 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3388 json_object_string_add(json_interface_sub
, "ifFlags",
3389 if_flag_dump(ifp
->flags
));
3391 vty_out(vty
, "%s is %s\n", ifp
->name
,
3392 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3393 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3394 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3395 if_flag_dump(ifp
->flags
));
3398 /* Is interface OSPF enabled? */
3400 if (ospf_oi_count(ifp
) == 0) {
3401 json_object_boolean_false_add(json_interface_sub
,
3404 } else if (!is_up
) {
3405 json_object_boolean_false_add(json_interface_sub
,
3409 json_object_boolean_true_add(json_interface_sub
,
3412 if (ospf_oi_count(ifp
) == 0) {
3413 vty_out(vty
, " OSPF not enabled on this interface\n");
3415 } else if (!is_up
) {
3417 " OSPF is enabled, but not running on this interface\n");
3422 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3423 struct ospf_interface
*oi
= rn
->info
;
3428 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3430 json_object_boolean_true_add(json_interface_sub
,
3433 vty_out(vty
, " This interface is UNNUMBERED,");
3435 /* Show OSPF interface information. */
3437 json_object_string_add(
3438 json_interface_sub
, "ipAddress",
3439 inet_ntoa(oi
->address
->u
.prefix4
));
3440 json_object_int_add(json_interface_sub
,
3441 "ipAddressPrefixlen",
3442 oi
->address
->prefixlen
);
3444 vty_out(vty
, " Internet Address %s/%d,",
3445 inet_ntoa(oi
->address
->u
.prefix4
),
3446 oi
->address
->prefixlen
);
3448 if (oi
->connected
->destination
3449 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3450 struct in_addr
*dest
;
3453 if (CONNECTED_PEER(oi
->connected
)
3454 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3459 /* For Vlinks, showing the peer address is
3461 * * * * * informative than the local
3462 * interface that is being used
3464 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3465 dest
= &oi
->vl_data
->peer_addr
;
3467 dest
= &oi
->connected
->destination
->u
3471 json_object_string_add(
3473 "ospfIfType", dstr
);
3474 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3475 json_object_string_add(
3480 json_object_string_add(
3485 vty_out(vty
, " %s %s,", dstr
,
3490 json_object_string_add(json_interface_sub
, "area",
3491 ospf_area_desc_string(oi
->area
));
3492 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3493 json_object_boolean_true_add(
3495 "mtuMismatchDetect");
3496 json_object_string_add(json_interface_sub
, "routerId",
3497 inet_ntoa(ospf
->router_id
));
3498 json_object_string_add(json_interface_sub
,
3500 ospf_network_type_str
[oi
->type
]);
3501 json_object_int_add(json_interface_sub
, "cost",
3503 json_object_int_add(
3504 json_interface_sub
, "transmitDelayMsecs",
3505 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3506 json_object_string_add(json_interface_sub
, "state",
3507 lookup_msg(ospf_ism_state_msg
,
3509 json_object_int_add(json_interface_sub
, "priority",
3512 vty_out(vty
, " Area %s\n",
3513 ospf_area_desc_string(oi
->area
));
3515 vty_out(vty
, " MTU mismatch detection: %s\n",
3516 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3520 " Router ID %s, Network Type %s, Cost: %d\n",
3521 inet_ntoa(ospf
->router_id
),
3522 ospf_network_type_str
[oi
->type
],
3526 " Transmit Delay is %d sec, State %s, Priority %d\n",
3527 OSPF_IF_PARAM(oi
, transmit_delay
),
3528 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3532 /* Show DR information. */
3533 if (DR(oi
).s_addr
== 0) {
3536 " No backup designated router on this network\n");
3538 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3542 " No backup designated router on this network\n");
3545 json_object_string_add(
3546 json_interface_sub
, "bdrId",
3547 inet_ntoa(nbr
->router_id
));
3548 json_object_string_add(
3551 inet_ntoa(nbr
->address
.u
3555 " Backup Designated Router (ID) %s,",
3556 inet_ntoa(nbr
->router_id
));
3557 vty_out(vty
, " Interface Address %s\n",
3558 inet_ntoa(nbr
->address
.u
3564 /* Next network-LSA sequence number we'll use, if we're elected
3567 && ntohl(oi
->params
->network_lsa_seqnum
)
3568 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3570 json_object_int_add(
3572 "networkLsaSequence",
3573 ntohl(oi
->params
->network_lsa_seqnum
));
3576 " Saved Network-LSA sequence number 0x%x\n",
3577 ntohl(oi
->params
->network_lsa_seqnum
));
3581 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3582 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3583 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3584 json_object_boolean_true_add(
3586 "mcastMemberOspfAllRouters");
3587 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3588 json_object_boolean_true_add(
3590 "mcastMemberOspfDesignatedRouters");
3593 vty_out(vty
, " Multicast group memberships:");
3594 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3595 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3596 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3597 vty_out(vty
, " OSPFAllRouters");
3598 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3599 vty_out(vty
, " OSPFDesignatedRouters");
3601 vty_out(vty
, " <None>");
3606 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3607 json_object_int_add(
3608 json_interface_sub
, "timerMsecs",
3609 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3611 json_object_int_add(
3612 json_interface_sub
, "timerMsecs",
3613 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3614 json_object_int_add(json_interface_sub
,
3616 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3617 json_object_int_add(json_interface_sub
,
3619 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3620 json_object_int_add(
3621 json_interface_sub
, "timerRetransmit",
3622 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3624 vty_out(vty
, " Timer intervals configured,");
3625 vty_out(vty
, " Hello ");
3626 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3627 vty_out(vty
, "%ds,",
3628 OSPF_IF_PARAM(oi
, v_hello
));
3630 vty_out(vty
, "%dms,",
3631 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3632 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3633 OSPF_IF_PARAM(oi
, v_wait
),
3634 OSPF_IF_PARAM(oi
, v_wait
),
3635 OSPF_IF_PARAM(oi
, retransmit_interval
));
3638 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3639 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3641 long time_store
= 0;
3645 &oi
->t_hello
->u
.sands
,
3648 json_object_int_add(json_interface_sub
,
3649 "timerHelloInMsecs",
3652 vty_out(vty
, " Hello due in %s\n",
3653 ospf_timer_dump(oi
->t_hello
, timebuf
,
3655 } else /* passive-interface is set */
3658 json_object_boolean_true_add(
3660 "timerPassiveIface");
3663 " No Hellos (Passive interface)\n");
3667 json_object_int_add(json_interface_sub
, "nbrCount",
3668 ospf_nbr_count(oi
, 0));
3669 json_object_int_add(json_interface_sub
,
3671 ospf_nbr_count(oi
, NSM_Full
));
3674 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3675 ospf_nbr_count(oi
, 0),
3676 ospf_nbr_count(oi
, NSM_Full
));
3677 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3681 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3682 char *intf_name
, uint8_t use_vrf
,
3683 json_object
*json
, bool use_json
)
3685 struct interface
*ifp
;
3686 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3687 json_object
*json_vrf
= NULL
;
3688 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3692 json_vrf
= json_object_new_object();
3695 json_interface
= json_object_new_object();
3698 if (ospf
->instance
) {
3700 json_object_int_add(json
, "ospfInstance",
3703 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3706 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3708 if (intf_name
== NULL
) {
3709 /* Show All Interfaces.*/
3710 FOR_ALL_INTERFACES (vrf
, ifp
) {
3711 if (ospf_oi_count(ifp
)) {
3713 json_interface_sub
=
3714 json_object_new_object();
3716 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3721 json_object_object_add(
3722 json_interface
, ifp
->name
,
3723 json_interface_sub
);
3728 json_object_object_add(json_vrf
, "interfaces",
3731 /* Interface name is specified. */
3732 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3735 json_object_boolean_true_add(json_vrf
,
3738 vty_out(vty
, "No such interface name\n");
3741 json_interface_sub
= json_object_new_object();
3742 json_interface
= json_object_new_object();
3745 show_ip_ospf_interface_sub(
3746 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3749 json_object_object_add(json_interface
,
3751 json_interface_sub
);
3752 json_object_object_add(json_vrf
, "interfaces",
3760 if (ospf
->vrf_id
== VRF_DEFAULT
)
3761 json_object_object_add(json
, "default",
3764 json_object_object_add(json
, ospf
->name
,
3773 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3774 struct ospf_interface
*oi
,
3775 json_object
*json_interface_sub
,
3779 json_object_int_add(json_interface_sub
, "ifIndex",
3781 json_object_int_add(json_interface_sub
, "helloIn",
3783 json_object_int_add(json_interface_sub
, "helloOut",
3785 json_object_int_add(json_interface_sub
, "dbDescIn",
3787 json_object_int_add(json_interface_sub
, "dbDescOut",
3789 json_object_int_add(json_interface_sub
, "lsReqIn",
3791 json_object_int_add(json_interface_sub
, "lsReqOut",
3793 json_object_int_add(json_interface_sub
, "lsUpdIn",
3795 json_object_int_add(json_interface_sub
, "lsUpdOut",
3797 json_object_int_add(json_interface_sub
, "lsAckIn",
3799 json_object_int_add(json_interface_sub
, "lsAckOut",
3803 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3804 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3805 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3806 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3807 oi
->ls_ack_in
, oi
->ls_ack_out
);
3811 /* OSPFv2 Packet Counters */
3812 static int show_ip_ospf_interface_traffic_common(
3813 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3814 int display_once
, uint8_t use_vrf
, bool use_json
)
3816 struct vrf
*vrf
= NULL
;
3817 struct interface
*ifp
= NULL
;
3818 json_object
*json_vrf
= NULL
;
3819 json_object
*json_interface_sub
= NULL
;
3821 if (!use_json
&& !display_once
) {
3823 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3824 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3826 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3827 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3830 "--------------------------------------------------------------------------------------------\n");
3831 } else if (use_json
) {
3833 json_vrf
= json_object_new_object();
3838 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3840 if (intf_name
== NULL
) {
3841 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3842 FOR_ALL_INTERFACES (vrf
, ifp
) {
3843 struct route_node
*rn
;
3844 struct ospf_interface
*oi
;
3846 if (ospf_oi_count(ifp
) == 0)
3849 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3850 rn
= route_next(rn
)) {
3857 json_interface_sub
=
3858 json_object_new_object();
3861 show_ip_ospf_interface_traffic_sub(
3862 vty
, oi
, json_interface_sub
, use_json
);
3864 json_object_object_add(
3865 json_vrf
, ifp
->name
,
3866 json_interface_sub
);
3871 /* Interface name is specified. */
3872 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3874 struct route_node
*rn
;
3875 struct ospf_interface
*oi
;
3877 if (ospf_oi_count(ifp
) == 0) {
3879 " OSPF not enabled on this interface %s\n",
3884 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3885 rn
= route_next(rn
)) {
3889 json_interface_sub
=
3890 json_object_new_object();
3893 show_ip_ospf_interface_traffic_sub(
3894 vty
, oi
, json_interface_sub
, use_json
);
3896 json_object_object_add(
3897 json_vrf
, ifp
->name
,
3898 json_interface_sub
);
3906 if (ospf
->vrf_id
== VRF_DEFAULT
)
3907 json_object_object_add(json
, "default",
3910 json_object_object_add(json
, ospf
->name
,
3919 DEFUN (show_ip_ospf_interface
,
3920 show_ip_ospf_interface_cmd
,
3921 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3924 "OSPF information\n"
3927 "Interface information\n"
3932 bool uj
= use_json(argc
, argv
);
3933 struct listnode
*node
= NULL
;
3934 char *vrf_name
= NULL
, *intf_name
= NULL
;
3935 bool all_vrf
= FALSE
;
3936 int ret
= CMD_SUCCESS
;
3938 int idx_vrf
= 0, idx_intf
= 0;
3939 uint8_t use_vrf
= 0;
3940 json_object
*json
= NULL
;
3942 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3944 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3945 intf_name
= argv
[idx_intf
]->arg
;
3948 json
= json_object_new_object();
3950 /* vrf input is provided could be all or specific vrf*/
3954 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3955 if (!ospf
->oi_running
)
3957 ret
= show_ip_ospf_interface_common(
3958 vty
, ospf
, intf_name
, use_vrf
, json
,
3963 vty_out(vty
, "%s\n",
3964 json_object_to_json_string_ext(
3965 json
, JSON_C_TO_STRING_PRETTY
));
3966 json_object_free(json
);
3968 vty_out(vty
, "%% OSPF instance not found \n");
3972 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3973 if (ospf
== NULL
|| !ospf
->oi_running
) {
3975 vty_out(vty
, "%s\n",
3976 json_object_to_json_string_ext(
3977 json
, JSON_C_TO_STRING_PRETTY
));
3978 json_object_free(json
);
3980 vty_out(vty
, "%% OSPF instance not found \n");
3984 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3988 /* Display default ospf (instance 0) info */
3989 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3990 if (ospf
== NULL
|| !ospf
->oi_running
) {
3992 vty_out(vty
, "%s\n",
3993 json_object_to_json_string_ext(
3994 json
, JSON_C_TO_STRING_PRETTY
));
3995 json_object_free(json
);
3997 vty_out(vty
, "%% OSPF instance not found \n");
4001 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4006 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4007 json
, JSON_C_TO_STRING_PRETTY
));
4008 json_object_free(json
);
4014 DEFUN (show_ip_ospf_instance_interface
,
4015 show_ip_ospf_instance_interface_cmd
,
4016 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4019 "OSPF information\n"
4021 "Interface information\n"
4028 unsigned short instance
= 0;
4029 bool uj
= use_json(argc
, argv
);
4030 char *intf_name
= NULL
;
4031 int ret
= CMD_SUCCESS
;
4032 json_object
*json
= NULL
;
4034 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4035 ospf
= ospf_lookup_instance(instance
);
4037 return CMD_NOT_MY_INSTANCE
;
4039 if (!ospf
->oi_running
)
4043 json
= json_object_new_object();
4045 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4046 intf_name
= argv
[idx_intf
]->arg
;
4048 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4051 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4052 json
, JSON_C_TO_STRING_PRETTY
));
4053 json_object_free(json
);
4059 DEFUN (show_ip_ospf_interface_traffic
,
4060 show_ip_ospf_interface_traffic_cmd
,
4061 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4064 "OSPF information\n"
4067 "Interface information\n"
4068 "Protocol Packet counters\n"
4072 struct ospf
*ospf
= NULL
;
4073 struct listnode
*node
= NULL
;
4074 char *vrf_name
= NULL
, *intf_name
= NULL
;
4075 bool all_vrf
= FALSE
;
4077 int idx_vrf
= 0, idx_intf
= 0;
4078 bool uj
= use_json(argc
, argv
);
4079 json_object
*json
= NULL
;
4080 int ret
= CMD_SUCCESS
;
4081 int display_once
= 0;
4082 uint8_t use_vrf
= 0;
4084 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4086 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4087 intf_name
= argv
[idx_intf
]->arg
;
4090 json
= json_object_new_object();
4095 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4096 if (!ospf
->oi_running
)
4099 ret
= show_ip_ospf_interface_traffic_common(
4100 vty
, ospf
, intf_name
, json
,
4101 display_once
, use_vrf
, uj
);
4106 vty_out(vty
, "%s\n",
4107 json_object_to_json_string_ext(
4108 json
, JSON_C_TO_STRING_PRETTY
));
4109 json_object_free(json
);
4114 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4115 if (ospf
== NULL
|| !ospf
->oi_running
) {
4117 json_object_free(json
);
4121 ret
= show_ip_ospf_interface_traffic_common(
4122 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4124 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4125 if (ospf
== NULL
|| !ospf
->oi_running
) {
4127 json_object_free(json
);
4131 ret
= show_ip_ospf_interface_traffic_common(
4132 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4136 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4137 json
, JSON_C_TO_STRING_PRETTY
));
4138 json_object_free(json
);
4145 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4147 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4148 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4149 "Interface", "RXmtL", "RqstL", "DBsmL");
4152 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4153 struct ospf_interface
*oi
,
4154 json_object
*json
, bool use_json
)
4156 struct route_node
*rn
;
4157 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4159 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4160 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4162 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4163 if ((nbr
= rn
->info
)) {
4164 /* Do not show myself. */
4165 if (nbr
== oi
->nbr_self
)
4167 /* Down state is not shown. */
4168 if (nbr
->state
== NSM_Down
)
4171 char neigh_str
[INET_ADDRSTRLEN
];
4174 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4176 /* Start new neigh list */
4177 json_neigh_array
= NULL
;
4180 if (nbr
->state
== NSM_Attempt
4181 && nbr
->router_id
.s_addr
== 0)
4182 strlcpy(neigh_str
, "neighbor",
4186 inet_ntoa(nbr
->router_id
),
4189 json_object_object_get_ex(json
, neigh_str
,
4192 if (!json_neigh_array
) {
4194 json_object_new_array();
4195 json_object_object_add(
4200 json_neighbor
= json_object_new_object();
4202 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4208 &nbr
->t_inactivity
->u
.sands
,
4212 json_object_int_add(json_neighbor
, "priority",
4214 json_object_string_add(json_neighbor
, "state",
4216 json_object_int_add(json_neighbor
,
4219 json_object_string_add(json_neighbor
, "address",
4220 inet_ntoa(nbr
->src
));
4221 json_object_string_add(json_neighbor
,
4224 json_object_int_add(
4225 json_neighbor
, "retransmitCounter",
4226 ospf_ls_retransmit_count(nbr
));
4227 json_object_int_add(json_neighbor
,
4229 ospf_ls_request_count(nbr
));
4230 json_object_int_add(json_neighbor
,
4232 ospf_db_summary_count(nbr
));
4234 json_object_array_add(json_neigh_array
,
4237 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4239 if (nbr
->state
== NSM_Attempt
4240 && nbr
->router_id
.s_addr
== 0)
4241 vty_out(vty
, "%-15s %3d %-15s ", "-",
4242 nbr
->priority
, msgbuf
);
4244 vty_out(vty
, "%-15s %3d %-15s ",
4245 inet_ntoa(nbr
->router_id
),
4246 nbr
->priority
, msgbuf
);
4248 vty_out(vty
, "%9s ",
4249 ospf_timer_dump(nbr
->t_inactivity
,
4252 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4253 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4255 ospf_ls_retransmit_count(nbr
),
4256 ospf_ls_request_count(nbr
),
4257 ospf_db_summary_count(nbr
));
4264 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4265 json_object
*json
, bool use_json
,
4268 struct ospf_interface
*oi
;
4269 struct listnode
*node
;
4270 json_object
*json_vrf
= NULL
;
4271 json_object
*json_nbr_sub
= NULL
;
4275 json_vrf
= json_object_new_object();
4278 json_nbr_sub
= json_object_new_object();
4281 if (ospf
->instance
) {
4283 json_object_int_add(json
, "ospfInstance",
4286 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4289 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4291 show_ip_ospf_neighbour_header(vty
);
4293 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4294 if (ospf_interface_neighbor_count(oi
) == 0)
4296 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4300 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4302 if (ospf
->vrf_id
== VRF_DEFAULT
)
4303 json_object_object_add(json
, "default",
4306 json_object_object_add(json
, ospf
->name
,
4315 DEFUN (show_ip_ospf_neighbor
,
4316 show_ip_ospf_neighbor_cmd
,
4317 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4320 "OSPF information\n"
4327 bool uj
= use_json(argc
, argv
);
4328 struct listnode
*node
= NULL
;
4329 char *vrf_name
= NULL
;
4330 bool all_vrf
= FALSE
;
4331 int ret
= CMD_SUCCESS
;
4334 uint8_t use_vrf
= 0;
4335 json_object
*json
= NULL
;
4337 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4340 json
= json_object_new_object();
4342 /* vrf input is provided could be all or specific vrf*/
4346 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4347 if (!ospf
->oi_running
)
4349 ret
= show_ip_ospf_neighbor_common(
4350 vty
, ospf
, json
, uj
, use_vrf
);
4354 vty_out(vty
, "%s\n",
4355 json_object_to_json_string_ext(
4356 json
, JSON_C_TO_STRING_PRETTY
));
4357 json_object_free(json
);
4359 vty_out(vty
, "OSPF instance not found\n");
4364 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4365 if (ospf
== NULL
|| !ospf
->oi_running
) {
4367 vty_out(vty
, "%s\n",
4368 json_object_to_json_string_ext(
4369 json
, JSON_C_TO_STRING_PRETTY
));
4370 json_object_free(json
);
4372 vty_out(vty
, "%% OSPF instance not found\n");
4377 /* Display default ospf (instance 0) info */
4378 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4379 if (ospf
== NULL
|| !ospf
->oi_running
) {
4381 vty_out(vty
, "%s\n",
4382 json_object_to_json_string_ext(
4383 json
, JSON_C_TO_STRING_PRETTY
));
4384 json_object_free(json
);
4386 vty_out(vty
, "%% OSPF instance not found\n");
4393 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4397 vty_out(vty
, "%s\n",
4398 json_object_to_json_string_ext(
4399 json
, JSON_C_TO_STRING_PRETTY
));
4404 json_object_free(json
);
4410 DEFUN (show_ip_ospf_instance_neighbor
,
4411 show_ip_ospf_instance_neighbor_cmd
,
4412 "show ip ospf (1-65535) neighbor [json]",
4415 "OSPF information\n"
4422 unsigned short instance
= 0;
4423 bool uj
= use_json(argc
, argv
);
4424 json_object
*json
= NULL
;
4425 int ret
= CMD_SUCCESS
;
4427 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4428 ospf
= ospf_lookup_instance(instance
);
4430 return CMD_NOT_MY_INSTANCE
;
4432 if (!ospf
->oi_running
)
4436 json
= json_object_new_object();
4438 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4441 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4442 json
, JSON_C_TO_STRING_PRETTY
));
4443 json_object_free(json
);
4449 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4450 json_object
*json
, bool use_json
,
4453 struct listnode
*node
;
4454 struct ospf_interface
*oi
;
4455 json_object
*json_vrf
= NULL
;
4456 json_object
*json_neighbor_sub
= NULL
;
4460 json_vrf
= json_object_new_object();
4463 json_neighbor_sub
= json_object_new_object();
4466 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4468 show_ip_ospf_neighbour_header(vty
);
4470 if (ospf
->instance
) {
4472 json_object_int_add(json_vrf
, "ospfInstance",
4475 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4478 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4479 struct listnode
*nbr_node
;
4480 struct ospf_nbr_nbma
*nbr_nbma
;
4482 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4484 /* print Down neighbor status */
4485 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4486 if (nbr_nbma
->nbr
== NULL
4487 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4489 json_object_int_add(json_neighbor_sub
,
4491 nbr_nbma
->priority
);
4492 json_object_boolean_true_add(
4495 json_object_string_add(
4499 json_object_int_add(
4501 "nbrNbmaRetransmitCounter", 0);
4502 json_object_int_add(
4504 "nbrNbmaRequestCounter", 0);
4505 json_object_int_add(
4507 "nbrNbmaDbSummaryCounter", 0);
4508 json_object_object_add(
4510 inet_ntoa(nbr_nbma
->addr
),
4513 vty_out(vty
, "%-15s %3d %-15s %9s ",
4514 "-", nbr_nbma
->priority
, "Down",
4517 "%-15s %-20s %5d %5d %5d\n",
4518 inet_ntoa(nbr_nbma
->addr
),
4519 IF_NAME(oi
), 0, 0, 0);
4527 if (ospf
->vrf_id
== VRF_DEFAULT
)
4528 json_object_object_add(json
, "default",
4531 json_object_object_add(json
, ospf
->name
,
4540 DEFUN (show_ip_ospf_neighbor_all
,
4541 show_ip_ospf_neighbor_all_cmd
,
4542 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4545 "OSPF information\n"
4549 "include down status neighbor\n"
4553 bool uj
= use_json(argc
, argv
);
4554 struct listnode
*node
= NULL
;
4555 char *vrf_name
= NULL
;
4556 bool all_vrf
= FALSE
;
4557 int ret
= CMD_SUCCESS
;
4560 uint8_t use_vrf
= 0;
4561 json_object
*json
= NULL
;
4563 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4566 json
= json_object_new_object();
4568 /* vrf input is provided could be all or specific vrf*/
4572 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4573 if (!ospf
->oi_running
)
4575 ret
= show_ip_ospf_neighbor_all_common(
4576 vty
, ospf
, json
, uj
, use_vrf
);
4580 vty_out(vty
, "%s\n",
4581 json_object_to_json_string_ext(
4582 json
, JSON_C_TO_STRING_PRETTY
));
4583 json_object_free(json
);
4589 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4590 if (ospf
== NULL
|| !ospf
->oi_running
) {
4592 json_object_free(json
);
4596 /* Display default ospf (instance 0) info */
4597 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4598 if (ospf
== NULL
|| !ospf
->oi_running
) {
4600 json_object_free(json
);
4606 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4609 vty_out(vty
, "%s\n",
4610 json_object_to_json_string_ext(
4611 json
, JSON_C_TO_STRING_PRETTY
));
4616 json_object_free(json
);
4621 DEFUN (show_ip_ospf_instance_neighbor_all
,
4622 show_ip_ospf_instance_neighbor_all_cmd
,
4623 "show ip ospf (1-65535) neighbor all [json]",
4626 "OSPF information\n"
4629 "include down status neighbor\n"
4634 unsigned short instance
= 0;
4635 bool uj
= use_json(argc
, argv
);
4636 json_object
*json
= NULL
;
4637 int ret
= CMD_SUCCESS
;
4639 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4640 ospf
= ospf_lookup_instance(instance
);
4642 return CMD_NOT_MY_INSTANCE
;
4644 if (!ospf
->oi_running
)
4647 json
= json_object_new_object();
4649 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4652 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4653 json
, JSON_C_TO_STRING_PRETTY
));
4654 json_object_free(json
);
4660 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4662 struct cmd_token
**argv
,
4663 bool use_json
, uint8_t use_vrf
)
4665 struct interface
*ifp
;
4666 struct route_node
*rn
;
4667 json_object
*json
= NULL
;
4670 json
= json_object_new_object();
4672 if (ospf
->instance
) {
4674 json_object_int_add(json
, "ospfInstance",
4677 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4680 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4682 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4685 json_object_boolean_true_add(json
, "noSuchIface");
4687 vty_out(vty
, "No such interface.\n");
4691 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4692 struct ospf_interface
*oi
= rn
->info
;
4697 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4701 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4702 json
, JSON_C_TO_STRING_PRETTY
));
4703 json_object_free(json
);
4710 DEFUN (show_ip_ospf_neighbor_int
,
4711 show_ip_ospf_neighbor_int_cmd
,
4712 "show ip ospf neighbor IFNAME [json]",
4715 "OSPF information\n"
4722 bool uj
= use_json(argc
, argv
);
4723 struct listnode
*node
= NULL
;
4724 int ret
= CMD_SUCCESS
;
4725 struct interface
*ifp
= NULL
;
4728 show_ip_ospf_neighbour_header(vty
);
4730 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4731 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4732 if (!ospf
->oi_running
)
4734 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4736 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4743 DEFUN (show_ip_ospf_instance_neighbor_int
,
4744 show_ip_ospf_instance_neighbor_int_cmd
,
4745 "show ip ospf (1-65535) neighbor IFNAME [json]",
4748 "OSPF information\n"
4757 unsigned short instance
= 0;
4758 bool uj
= use_json(argc
, argv
);
4761 show_ip_ospf_neighbour_header(vty
);
4763 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4764 ospf
= ospf_lookup_instance(instance
);
4766 return CMD_NOT_MY_INSTANCE
;
4768 if (!ospf
->oi_running
)
4772 show_ip_ospf_neighbour_header(vty
);
4774 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4778 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4779 struct ospf_interface
*oi
,
4780 struct ospf_nbr_nbma
*nbr_nbma
,
4781 bool use_json
, json_object
*json
)
4783 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4784 json_object
*json_sub
= NULL
;
4787 json_sub
= json_object_new_object();
4788 else /* Show neighbor ID. */
4789 vty_out(vty
, " Neighbor %s,", "-");
4791 /* Show interface address. */
4793 json_object_string_add(json_sub
, "ifaceAddress",
4794 inet_ntoa(nbr_nbma
->addr
));
4796 vty_out(vty
, " interface address %s\n",
4797 inet_ntoa(nbr_nbma
->addr
));
4801 json_object_string_add(json_sub
, "areaId",
4802 ospf_area_desc_string(oi
->area
));
4803 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4805 vty_out(vty
, " In the area %s via interface %s\n",
4806 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4808 /* Show neighbor priority and state. */
4810 json_object_int_add(json_sub
, "nbrPriority",
4811 nbr_nbma
->priority
);
4812 json_object_string_add(json_sub
, "nbrState", "down");
4814 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4815 nbr_nbma
->priority
, "Down");
4817 /* Show state changes. */
4819 json_object_int_add(json_sub
, "stateChangeCounter",
4820 nbr_nbma
->state_change
);
4822 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4824 /* Show PollInterval */
4826 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4828 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4830 /* Show poll-interval timer. */
4831 if (nbr_nbma
->t_poll
) {
4834 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4836 json_object_int_add(json_sub
,
4837 "pollIntervalTimerDueMsec",
4840 vty_out(vty
, " Poll timer due in %s\n",
4841 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4845 /* Show poll-interval timer thread. */
4847 if (nbr_nbma
->t_poll
!= NULL
)
4848 json_object_string_add(json_sub
,
4849 "pollIntervalTimerThread", "on");
4851 vty_out(vty
, " Thread Poll Timer %s\n",
4852 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4855 json_object_object_add(json
, "noNbrId", json_sub
);
4858 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4859 struct ospf_interface
*oi
,
4860 struct ospf_neighbor
*nbr
,
4861 json_object
*json
, bool use_json
)
4863 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4864 json_object
*json_sub
= NULL
;
4867 json_sub
= json_object_new_object();
4869 /* Show neighbor ID. */
4870 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4871 vty_out(vty
, " Neighbor %s,", "-");
4873 vty_out(vty
, " Neighbor %s,",
4874 inet_ntoa(nbr
->router_id
));
4877 /* Show interface address. */
4879 json_object_string_add(json_sub
, "ifaceAddress",
4880 inet_ntoa(nbr
->address
.u
.prefix4
));
4882 vty_out(vty
, " interface address %s\n",
4883 inet_ntoa(nbr
->address
.u
.prefix4
));
4887 json_object_string_add(json_sub
, "areaId",
4888 ospf_area_desc_string(oi
->area
));
4889 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4891 vty_out(vty
, " In the area %s via interface %s\n",
4892 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4894 /* Show neighbor priority and state. */
4896 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4897 json_object_string_add(
4898 json_sub
, "nbrState",
4899 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4901 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4903 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4905 /* Show state changes. */
4907 json_object_int_add(json_sub
, "stateChangeCounter",
4910 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4912 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4917 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4919 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4923 " Most recent state change statistics:\n");
4924 vty_out(vty
, " Progressive change %s ago\n",
4925 ospf_timeval_dump(&res
, timebuf
,
4930 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4935 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4937 json_object_int_add(json_sub
,
4938 "lastRegressiveChangeMsec",
4940 if (nbr
->last_regress_str
)
4941 json_object_string_add(
4942 json_sub
, "lastRegressiveChangeReason",
4943 nbr
->last_regress_str
);
4946 " Regressive change %s ago, due to %s\n",
4947 ospf_timeval_dump(&res
, timebuf
,
4949 (nbr
->last_regress_str
? nbr
->last_regress_str
4954 /* Show Designated Rotuer ID. */
4956 json_object_string_add(json_sub
, "routerDesignatedId",
4957 inet_ntoa(nbr
->d_router
));
4959 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4961 /* Show Backup Designated Rotuer ID. */
4963 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4964 inet_ntoa(nbr
->bd_router
));
4966 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4970 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4971 json_object_string_add(json_sub
, "optionsList",
4972 ospf_options_dump(nbr
->options
));
4974 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4975 ospf_options_dump(nbr
->options
));
4977 /* Show Router Dead interval timer. */
4979 if (nbr
->t_inactivity
) {
4981 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4984 json_object_int_add(json_sub
,
4985 "routerDeadIntervalTimerDueMsec",
4988 json_object_int_add(
4989 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
4991 vty_out(vty
, " Dead timer due in %s\n",
4992 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4995 /* Show Database Summary list. */
4997 json_object_int_add(json_sub
, "databaseSummaryListCounter",
4998 ospf_db_summary_count(nbr
));
5000 vty_out(vty
, " Database Summary List %d\n",
5001 ospf_db_summary_count(nbr
));
5003 /* Show Link State Request list. */
5005 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5006 ospf_ls_request_count(nbr
));
5008 vty_out(vty
, " Link State Request List %ld\n",
5009 ospf_ls_request_count(nbr
));
5011 /* Show Link State Retransmission list. */
5013 json_object_int_add(json_sub
,
5014 "linkStateRetransmissionListCounter",
5015 ospf_ls_retransmit_count(nbr
));
5017 vty_out(vty
, " Link State Retransmission List %ld\n",
5018 ospf_ls_retransmit_count(nbr
));
5020 /* Show inactivity timer thread. */
5022 if (nbr
->t_inactivity
!= NULL
)
5023 json_object_string_add(json_sub
,
5024 "threadInactivityTimer", "on");
5026 vty_out(vty
, " Thread Inactivity Timer %s\n",
5027 nbr
->t_inactivity
!= NULL
? "on" : "off");
5029 /* Show Database Description retransmission thread. */
5031 if (nbr
->t_db_desc
!= NULL
)
5032 json_object_string_add(
5034 "threadDatabaseDescriptionRetransmission",
5038 " Thread Database Description Retransmision %s\n",
5039 nbr
->t_db_desc
!= NULL
? "on" : "off");
5041 /* Show Link State Request Retransmission thread. */
5043 if (nbr
->t_ls_req
!= NULL
)
5044 json_object_string_add(
5046 "threadLinkStateRequestRetransmission", "on");
5049 " Thread Link State Request Retransmission %s\n",
5050 nbr
->t_ls_req
!= NULL
? "on" : "off");
5052 /* Show Link State Update Retransmission thread. */
5054 if (nbr
->t_ls_upd
!= NULL
)
5055 json_object_string_add(
5056 json_sub
, "threadLinkStateUpdateRetransmission",
5060 " Thread Link State Update Retransmission %s\n\n",
5061 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5064 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5065 json_object_object_add(json
, "noNbrId", json_sub
);
5067 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5071 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5074 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5076 struct cmd_token
**argv
,
5077 bool use_json
, uint8_t use_vrf
)
5079 struct listnode
*node
;
5080 struct ospf_neighbor
*nbr
;
5081 struct ospf_interface
*oi
;
5082 struct in_addr router_id
;
5084 json_object
*json
= NULL
;
5087 json
= json_object_new_object();
5089 if (ospf
->instance
) {
5091 json_object_int_add(json
, "ospfInstance",
5094 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5097 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5099 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5102 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5104 vty_out(vty
, "{}\n");
5105 json_object_free(json
);
5110 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5111 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5112 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5118 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5119 json
, JSON_C_TO_STRING_PRETTY
));
5120 json_object_free(json
);
5127 DEFUN (show_ip_ospf_neighbor_id
,
5128 show_ip_ospf_neighbor_id_cmd
,
5129 "show ip ospf neighbor A.B.C.D [json]",
5132 "OSPF information\n"
5138 bool uj
= use_json(argc
, argv
);
5139 struct listnode
*node
= NULL
;
5140 int ret
= CMD_SUCCESS
;
5142 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5143 if (!ospf
->oi_running
)
5145 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0, argv
, uj
,
5152 DEFUN (show_ip_ospf_instance_neighbor_id
,
5153 show_ip_ospf_instance_neighbor_id_cmd
,
5154 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5157 "OSPF information\n"
5164 int idx_router_id
= 5;
5166 unsigned short instance
= 0;
5167 bool uj
= use_json(argc
, argv
);
5169 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5170 ospf
= ospf_lookup_instance(instance
);
5172 return CMD_NOT_MY_INSTANCE
;
5174 if (!ospf
->oi_running
)
5177 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5181 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5183 json_object
*json
, bool use_json
,
5186 struct ospf_interface
*oi
;
5187 struct listnode
*node
;
5188 json_object
*json_vrf
= NULL
;
5192 json_vrf
= json_object_new_object();
5196 if (ospf
->instance
) {
5198 json_object_int_add(json_vrf
, "ospfInstance",
5201 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5204 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5206 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5207 struct route_node
*rn
;
5208 struct ospf_neighbor
*nbr
;
5210 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5211 if ((nbr
= rn
->info
)) {
5212 if (nbr
!= oi
->nbr_self
) {
5213 if (nbr
->state
!= NSM_Down
) {
5214 show_ip_ospf_neighbor_detail_sub(
5215 vty
, oi
, nbr
, json_vrf
,
5225 if (ospf
->vrf_id
== VRF_DEFAULT
)
5226 json_object_object_add(json
, "default",
5229 json_object_object_add(json
, ospf
->name
,
5238 DEFUN (show_ip_ospf_neighbor_detail
,
5239 show_ip_ospf_neighbor_detail_cmd
,
5240 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5243 "OSPF information\n"
5247 "detail of all neighbors\n"
5251 bool uj
= use_json(argc
, argv
);
5252 struct listnode
*node
= NULL
;
5253 char *vrf_name
= NULL
;
5254 bool all_vrf
= FALSE
;
5255 int ret
= CMD_SUCCESS
;
5258 uint8_t use_vrf
= 0;
5259 json_object
*json
= NULL
;
5261 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5264 json
= json_object_new_object();
5266 /* vrf input is provided could be all or specific vrf*/
5270 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5271 if (!ospf
->oi_running
)
5273 ret
= show_ip_ospf_neighbor_detail_common(
5274 vty
, ospf
, json
, uj
, use_vrf
);
5277 vty_out(vty
, "%s\n",
5278 json_object_to_json_string_ext(
5279 json
, JSON_C_TO_STRING_PRETTY
));
5280 json_object_free(json
);
5285 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5286 if (ospf
== NULL
|| !ospf
->oi_running
) {
5288 json_object_free(json
);
5292 /* Display default ospf (instance 0) info */
5293 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5294 if (ospf
== NULL
|| !ospf
->oi_running
) {
5296 json_object_free(json
);
5302 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5305 vty_out(vty
, "%s\n",
5306 json_object_to_json_string_ext(
5307 json
, JSON_C_TO_STRING_PRETTY
));
5312 json_object_free(json
);
5317 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5318 show_ip_ospf_instance_neighbor_detail_cmd
,
5319 "show ip ospf (1-65535) neighbor detail [json]",
5322 "OSPF information\n"
5325 "detail of all neighbors\n"
5330 unsigned short instance
= 0;
5331 bool uj
= use_json(argc
, argv
);
5332 json_object
*json
= NULL
;
5333 int ret
= CMD_SUCCESS
;
5335 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5336 ospf
= ospf_lookup_instance(instance
);
5338 return CMD_NOT_MY_INSTANCE
;
5340 if (!ospf
->oi_running
)
5344 json
= json_object_new_object();
5346 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5349 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5350 json
, JSON_C_TO_STRING_PRETTY
));
5351 json_object_free(json
);
5357 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5363 struct listnode
*node
;
5364 struct ospf_interface
*oi
;
5365 json_object
*json_vrf
= NULL
;
5369 json_vrf
= json_object_new_object();
5374 if (ospf
->instance
) {
5376 json_object_int_add(json
, "ospfInstance",
5379 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5382 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5384 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5385 struct route_node
*rn
;
5386 struct ospf_neighbor
*nbr
;
5387 struct ospf_nbr_nbma
*nbr_nbma
;
5389 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5390 if ((nbr
= rn
->info
))
5391 if (nbr
!= oi
->nbr_self
)
5392 if (nbr
->state
!= NSM_Down
)
5393 show_ip_ospf_neighbor_detail_sub(
5395 json_vrf
, use_json
);
5397 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5398 struct listnode
*nd
;
5400 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5401 if (nbr_nbma
->nbr
== NULL
5402 || nbr_nbma
->nbr
->state
== NSM_Down
)
5403 show_ip_ospf_nbr_nbma_detail_sub(
5404 vty
, oi
, nbr_nbma
, use_json
,
5412 if (ospf
->vrf_id
== VRF_DEFAULT
)
5413 json_object_object_add(json
, "default",
5416 json_object_object_add(json
, ospf
->name
,
5426 DEFUN (show_ip_ospf_neighbor_detail_all
,
5427 show_ip_ospf_neighbor_detail_all_cmd
,
5428 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5431 "OSPF information\n"
5435 "detail of all neighbors\n"
5436 "include down status neighbor\n"
5440 bool uj
= use_json(argc
, argv
);
5441 struct listnode
*node
= NULL
;
5442 char *vrf_name
= NULL
;
5443 bool all_vrf
= FALSE
;
5444 int ret
= CMD_SUCCESS
;
5447 uint8_t use_vrf
= 0;
5448 json_object
*json
= NULL
;
5450 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5453 json
= json_object_new_object();
5455 /* vrf input is provided could be all or specific vrf*/
5459 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5460 if (!ospf
->oi_running
)
5462 ret
= show_ip_ospf_neighbor_detail_all_common(
5463 vty
, ospf
, json
, uj
, use_vrf
);
5467 vty_out(vty
, "%s\n",
5468 json_object_to_json_string_ext(
5469 json
, JSON_C_TO_STRING_PRETTY
));
5470 json_object_free(json
);
5475 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5476 if (ospf
== NULL
|| !ospf
->oi_running
) {
5478 json_object_free(json
);
5482 /* Display default ospf (instance 0) info */
5483 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5484 if (ospf
== NULL
|| !ospf
->oi_running
) {
5486 json_object_free(json
);
5492 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5495 vty_out(vty
, "%s\n",
5496 json_object_to_json_string_ext(
5497 json
, JSON_C_TO_STRING_PRETTY
));
5502 json_object_free(json
);
5507 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5508 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5509 "show ip ospf (1-65535) neighbor detail all [json]",
5512 "OSPF information\n"
5515 "detail of all neighbors\n"
5516 "include down status neighbor\n"
5521 unsigned short instance
= 0;
5522 bool uj
= use_json(argc
, argv
);
5523 json_object
*json
= NULL
;
5524 int ret
= CMD_SUCCESS
;
5526 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5527 ospf
= ospf_lookup_instance(instance
);
5529 return CMD_NOT_MY_INSTANCE
;
5531 if (!ospf
->oi_running
)
5535 json
= json_object_new_object();
5537 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5540 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5541 json
, JSON_C_TO_STRING_PRETTY
));
5542 json_object_free(json
);
5548 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5551 struct cmd_token
**argv
,
5554 struct ospf_interface
*oi
;
5555 struct interface
*ifp
;
5556 struct route_node
*rn
, *nrn
;
5557 struct ospf_neighbor
*nbr
;
5558 json_object
*json
= NULL
;
5561 json
= json_object_new_object();
5563 if (ospf
->instance
) {
5565 json_object_int_add(json
, "ospfInstance",
5568 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5571 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5574 vty_out(vty
, "No such interface.\n");
5576 vty_out(vty
, "{}\n");
5577 json_object_free(json
);
5582 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5583 if ((oi
= rn
->info
)) {
5584 for (nrn
= route_top(oi
->nbrs
); nrn
;
5585 nrn
= route_next(nrn
)) {
5586 if ((nbr
= nrn
->info
)) {
5587 if (nbr
!= oi
->nbr_self
) {
5588 if (nbr
->state
!= NSM_Down
)
5589 show_ip_ospf_neighbor_detail_sub(
5599 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5600 json
, JSON_C_TO_STRING_PRETTY
));
5601 json_object_free(json
);
5608 DEFUN (show_ip_ospf_neighbor_int_detail
,
5609 show_ip_ospf_neighbor_int_detail_cmd
,
5610 "show ip ospf neighbor IFNAME detail [json]",
5613 "OSPF information\n"
5616 "detail of all neighbors\n"
5620 bool uj
= use_json(argc
, argv
);
5621 struct listnode
*node
= NULL
;
5622 int ret
= CMD_SUCCESS
;
5623 bool ospf_output
= FALSE
;
5625 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5626 if (!ospf
->oi_running
)
5629 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5634 vty_out(vty
, "%% OSPF instance not found\n");
5639 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5640 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5641 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5644 "OSPF information\n"
5648 "detail of all neighbors\n"
5654 unsigned short instance
= 0;
5655 bool uj
= use_json(argc
, argv
);
5657 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5658 ospf
= ospf_lookup_instance(instance
);
5660 return CMD_NOT_MY_INSTANCE
;
5662 if (!ospf
->oi_running
)
5665 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5669 /* Show functions */
5670 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5672 struct router_lsa
*rl
;
5673 struct summary_lsa
*sl
;
5674 struct as_external_lsa
*asel
;
5675 struct prefix_ipv4 p
;
5678 /* If self option is set, check LSA self flag. */
5679 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5680 /* LSA common part show. */
5681 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5682 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5683 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5684 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5685 ntohs(lsa
->data
->checksum
));
5686 /* LSA specific part show. */
5687 switch (lsa
->data
->type
) {
5688 case OSPF_ROUTER_LSA
:
5689 rl
= (struct router_lsa
*)lsa
->data
;
5690 vty_out(vty
, " %-d", ntohs(rl
->links
));
5692 case OSPF_SUMMARY_LSA
:
5693 sl
= (struct summary_lsa
*)lsa
->data
;
5696 p
.prefix
= sl
->header
.id
;
5697 p
.prefixlen
= ip_masklen(sl
->mask
);
5698 apply_mask_ipv4(&p
);
5700 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5703 case OSPF_AS_EXTERNAL_LSA
:
5704 case OSPF_AS_NSSA_LSA
:
5705 asel
= (struct as_external_lsa
*)lsa
->data
;
5708 p
.prefix
= asel
->header
.id
;
5709 p
.prefixlen
= ip_masklen(asel
->mask
);
5710 apply_mask_ipv4(&p
);
5712 vty_out(vty
, " %s %s/%d [0x%lx]",
5713 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5716 inet_ntoa(p
.prefix
), p
.prefixlen
,
5717 (unsigned long)ntohl(
5718 asel
->e
[0].route_tag
));
5720 case OSPF_NETWORK_LSA
:
5721 case OSPF_ASBR_SUMMARY_LSA
:
5722 case OSPF_OPAQUE_LINK_LSA
:
5723 case OSPF_OPAQUE_AREA_LSA
:
5724 case OSPF_OPAQUE_AS_LSA
:
5734 static const char *show_database_desc
[] = {
5736 "Router Link States",
5738 "Summary Link States",
5739 "ASBR-Summary Link States",
5740 "AS External Link States",
5741 "Group Membership LSA",
5742 "NSSA-external Link States",
5744 "Link-Local Opaque-LSA",
5745 "Area-Local Opaque-LSA",
5746 "AS-external Opaque-LSA",
5749 static const char *show_database_header
[] = {
5751 "Link ID ADV Router Age Seq# CkSum Link count",
5752 "Link ID ADV Router Age Seq# CkSum",
5753 "Link ID ADV Router Age Seq# CkSum Route",
5754 "Link ID ADV Router Age Seq# CkSum",
5755 "Link ID ADV Router Age Seq# CkSum Route",
5756 " --- header for Group Member ----",
5757 "Link ID ADV Router Age Seq# CkSum Route",
5759 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5760 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5761 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5764 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5766 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5768 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5769 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5770 ospf_options_dump(lsa
->data
->options
));
5771 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5772 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5775 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5776 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5779 vty_out(vty
, " :%s%s%s%s",
5780 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5781 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5782 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5784 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5789 vty_out(vty
, " LS Type: %s\n",
5790 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5791 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5792 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5793 vty_out(vty
, " Advertising Router: %s\n",
5794 inet_ntoa(lsa
->data
->adv_router
));
5795 vty_out(vty
, " LS Seq Number: %08lx\n",
5796 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5797 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5798 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5801 const char *link_type_desc
[] = {
5803 "another Router (point-to-point)",
5804 "a Transit Network",
5809 const char *link_id_desc
[] = {
5810 "(null)", "Neighboring Router ID", "Designated Router address",
5811 "Net", "Neighboring Router ID",
5814 const char *link_data_desc
[] = {
5815 "(null)", "Router Interface address", "Router Interface address",
5816 "Network Mask", "Router Interface address",
5819 /* Show router-LSA each Link information. */
5820 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5821 struct router_lsa
*rl
)
5826 len
= ntohs(rl
->header
.length
) - 4;
5827 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5828 type
= rl
->link
[i
].type
;
5830 vty_out(vty
, " Link connected to: %s\n",
5831 link_type_desc
[type
]);
5832 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5833 inet_ntoa(rl
->link
[i
].link_id
));
5834 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5835 inet_ntoa(rl
->link
[i
].link_data
));
5836 vty_out(vty
, " Number of TOS metrics: 0\n");
5837 vty_out(vty
, " TOS 0 Metric: %d\n",
5838 ntohs(rl
->link
[i
].metric
));
5843 /* Show router-LSA detail information. */
5844 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5847 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5849 show_ip_ospf_database_header(vty
, lsa
);
5851 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5853 show_ip_ospf_database_router_links(vty
, rl
);
5860 /* Show network-LSA detail information. */
5861 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5866 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5868 show_ip_ospf_database_header(vty
, lsa
);
5870 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5872 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5874 for (i
= 0; length
> 0; i
++, length
-= 4)
5875 vty_out(vty
, " Attached Router: %s\n",
5876 inet_ntoa(nl
->routers
[i
]));
5884 /* Show summary-LSA detail information. */
5885 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5888 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5890 show_ip_ospf_database_header(vty
, lsa
);
5892 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5893 vty_out(vty
, " TOS: 0 Metric: %d\n",
5894 GET_METRIC(sl
->metric
));
5901 /* Show summary-ASBR-LSA detail information. */
5902 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5905 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5907 show_ip_ospf_database_header(vty
, lsa
);
5909 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5910 vty_out(vty
, " TOS: 0 Metric: %d\n",
5911 GET_METRIC(sl
->metric
));
5918 /* Show AS-external-LSA detail information. */
5919 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5922 struct as_external_lsa
*al
=
5923 (struct as_external_lsa
*)lsa
->data
;
5925 show_ip_ospf_database_header(vty
, lsa
);
5927 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5928 vty_out(vty
, " Metric Type: %s\n",
5929 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5930 ? "2 (Larger than any link state path)"
5932 vty_out(vty
, " TOS: 0\n");
5933 vty_out(vty
, " Metric: %d\n",
5934 GET_METRIC(al
->e
[0].metric
));
5935 vty_out(vty
, " Forward Address: %s\n",
5936 inet_ntoa(al
->e
[0].fwd_addr
));
5939 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5940 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5947 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5949 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5951 /* show_ip_ospf_database_header (vty, lsa); */
5953 zlog_debug( " Network Mask: /%d%s",
5954 ip_masklen (al
->mask
), "\n");
5955 zlog_debug( " Metric Type: %s%s",
5956 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5957 "2 (Larger than any link state path)" : "1", "\n");
5958 zlog_debug( " TOS: 0%s", "\n");
5959 zlog_debug( " Metric: %d%s",
5960 GET_METRIC (al
->e
[0].metric
), "\n");
5961 zlog_debug( " Forward Address: %s%s",
5962 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5964 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5965 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5970 /* Show AS-NSSA-LSA detail information. */
5971 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5974 struct as_external_lsa
*al
=
5975 (struct as_external_lsa
*)lsa
->data
;
5977 show_ip_ospf_database_header(vty
, lsa
);
5979 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5980 vty_out(vty
, " Metric Type: %s\n",
5981 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5982 ? "2 (Larger than any link state path)"
5984 vty_out(vty
, " TOS: 0\n");
5985 vty_out(vty
, " Metric: %d\n",
5986 GET_METRIC(al
->e
[0].metric
));
5987 vty_out(vty
, " NSSA: Forward Address: %s\n",
5988 inet_ntoa(al
->e
[0].fwd_addr
));
5991 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5992 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5998 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6003 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6006 show_ip_ospf_database_header(vty
, lsa
);
6007 show_opaque_info_detail(vty
, lsa
);
6014 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6016 show_router_lsa_detail
,
6017 show_network_lsa_detail
,
6018 show_summary_lsa_detail
,
6019 show_summary_asbr_lsa_detail
,
6020 show_as_external_lsa_detail
,
6022 show_as_nssa_lsa_detail
, /* almost same as external */
6024 show_opaque_lsa_detail
,
6025 show_opaque_lsa_detail
,
6026 show_opaque_lsa_detail
,
6029 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6030 struct in_addr
*id
, struct in_addr
*adv_router
)
6032 memset(lp
, 0, sizeof(struct prefix_ls
));
6036 else if (adv_router
== NULL
) {
6042 lp
->adv_router
= *adv_router
;
6046 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6047 struct in_addr
*id
, struct in_addr
*adv_router
)
6049 struct prefix_ls lp
;
6050 struct route_node
*rn
, *start
;
6051 struct ospf_lsa
*lsa
;
6053 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6054 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6056 route_lock_node(start
);
6057 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6058 if ((lsa
= rn
->info
)) {
6059 if (show_function
[lsa
->data
->type
] != NULL
)
6060 show_function
[lsa
->data
->type
](vty
,
6063 route_unlock_node(start
);
6067 /* Show detail LSA information
6068 -- if id is NULL then show all LSAs. */
6069 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6070 struct in_addr
*id
, struct in_addr
*adv_router
)
6072 struct listnode
*node
;
6073 struct ospf_area
*area
;
6076 case OSPF_AS_EXTERNAL_LSA
:
6077 case OSPF_OPAQUE_AS_LSA
:
6078 vty_out(vty
, " %s \n\n",
6079 show_database_desc
[type
]);
6080 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6083 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6084 vty_out(vty
, "\n %s (Area %s)\n\n",
6085 show_database_desc
[type
],
6086 ospf_area_desc_string(area
));
6087 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6094 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6095 struct route_table
*rt
,
6096 struct in_addr
*adv_router
)
6098 struct route_node
*rn
;
6099 struct ospf_lsa
*lsa
;
6101 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6102 if ((lsa
= rn
->info
))
6103 if (IPV4_ADDR_SAME(adv_router
,
6104 &lsa
->data
->adv_router
)) {
6105 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6107 if (show_function
[lsa
->data
->type
] != NULL
)
6108 show_function
[lsa
->data
->type
](vty
,
6113 /* Show detail LSA information. */
6114 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6115 int type
, struct in_addr
*adv_router
)
6117 struct listnode
*node
;
6118 struct ospf_area
*area
;
6121 case OSPF_AS_EXTERNAL_LSA
:
6122 case OSPF_OPAQUE_AS_LSA
:
6123 vty_out(vty
, " %s \n\n",
6124 show_database_desc
[type
]);
6125 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6129 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6130 vty_out(vty
, "\n %s (Area %s)\n\n",
6131 show_database_desc
[type
],
6132 ospf_area_desc_string(area
));
6133 show_lsa_detail_adv_router_proc(
6134 vty
, AREA_LSDB(area
, type
), adv_router
);
6140 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6143 struct ospf_lsa
*lsa
;
6144 struct route_node
*rn
;
6145 struct ospf_area
*area
;
6146 struct listnode
*node
;
6149 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6150 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6152 case OSPF_AS_EXTERNAL_LSA
:
6153 case OSPF_OPAQUE_AS_LSA
:
6158 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6160 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6161 vty_out(vty
, " %s (Area %s)\n\n",
6162 show_database_desc
[type
],
6163 ospf_area_desc_string(area
));
6164 vty_out(vty
, "%s\n",
6165 show_database_header
[type
]);
6167 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6168 show_lsa_summary(vty
, lsa
, self
);
6175 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6177 case OSPF_AS_EXTERNAL_LSA
:
6178 case OSPF_OPAQUE_AS_LSA
:
6183 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6184 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6185 vty_out(vty
, " %s\n\n",
6186 show_database_desc
[type
]);
6187 vty_out(vty
, "%s\n", show_database_header
[type
]);
6189 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6190 show_lsa_summary(vty
, lsa
, self
);
6199 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6201 struct route_node
*rn
;
6203 vty_out(vty
, "\n MaxAge Link States:\n\n");
6205 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6206 struct ospf_lsa
*lsa
;
6208 if ((lsa
= rn
->info
) != NULL
) {
6209 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6210 vty_out(vty
, "Link State ID: %s\n",
6211 inet_ntoa(lsa
->data
->id
));
6212 vty_out(vty
, "Advertising Router: %s\n",
6213 inet_ntoa(lsa
->data
->adv_router
));
6214 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6220 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6221 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6223 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6224 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6225 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6226 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6228 #define OSPF_LSA_TYPES_DESC \
6229 "ASBR summary link states\n" \
6230 "External link states\n" \
6231 "Network link states\n" \
6232 "Router link states\n" \
6233 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6234 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6235 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6237 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6238 int arg_base
, int argc
,
6239 struct cmd_token
**argv
,
6244 struct in_addr id
, adv_router
;
6247 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6249 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6251 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6252 inet_ntoa(ospf
->router_id
));
6255 if (argc
== arg_base
+ 4) {
6256 show_ip_ospf_database_summary(vty
, ospf
, 0);
6260 /* Set database type to show. */
6261 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6262 type
= OSPF_ROUTER_LSA
;
6263 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6264 type
= OSPF_NETWORK_LSA
;
6265 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6266 type
= OSPF_AS_NSSA_LSA
;
6267 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6268 type
= OSPF_SUMMARY_LSA
;
6269 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6270 type
= OSPF_ASBR_SUMMARY_LSA
;
6271 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6272 type
= OSPF_AS_EXTERNAL_LSA
;
6273 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6274 show_ip_ospf_database_summary(vty
, ospf
, 1);
6276 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6277 show_ip_ospf_database_maxage(vty
, ospf
);
6279 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6280 type
= OSPF_OPAQUE_LINK_LSA
;
6281 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6282 type
= OSPF_OPAQUE_AREA_LSA
;
6283 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6284 type
= OSPF_OPAQUE_AS_LSA
;
6288 /* `show ip ospf database LSA'. */
6289 if (argc
== arg_base
+ 5)
6290 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6291 else if (argc
>= arg_base
+ 6) {
6292 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6296 /* `show ip ospf database LSA ID'. */
6297 if (argc
== arg_base
+ 6)
6298 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6299 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6300 else if (argc
== arg_base
+ 7) {
6301 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6302 adv_router
= ospf
->router_id
;
6304 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6309 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6316 DEFUN (show_ip_ospf_database_max
,
6317 show_ip_ospf_database_max_cmd
,
6318 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6321 "OSPF information\n"
6324 "Database summary\n"
6325 "LSAs in MaxAge list\n"
6326 "Self-originated link states\n")
6328 struct ospf
*ospf
= NULL
;
6329 struct listnode
*node
= NULL
;
6330 char *vrf_name
= NULL
;
6331 bool all_vrf
= FALSE
;
6332 int ret
= CMD_SUCCESS
;
6335 uint8_t use_vrf
= 0;
6337 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6340 bool ospf_output
= FALSE
;
6343 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6344 if (!ospf
->oi_running
)
6347 ret
= show_ip_ospf_database_common(
6348 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6353 vty_out(vty
, "%% OSPF instance not found\n");
6355 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6356 if (ospf
== NULL
|| !ospf
->oi_running
) {
6357 vty_out(vty
, "%% OSPF instance not found \n");
6360 ret
= (show_ip_ospf_database_common(
6361 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6365 /* Display default ospf (instance 0) info */
6366 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6367 if (ospf
== NULL
|| !ospf
->oi_running
) {
6368 vty_out(vty
, "%% OSPF instance not found \n");
6372 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6379 DEFUN (show_ip_ospf_instance_database
,
6380 show_ip_ospf_instance_database_cmd
,
6381 "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>]]]",
6384 "OSPF information\n"
6387 "Database summary\n"
6389 "Link State ID (as an IP address)\n"
6390 "Self-originated link states\n"
6391 "Advertising Router link states\n"
6392 "Advertising Router (as an IP address)\n")
6395 unsigned short instance
= 0;
6396 struct listnode
*node
= NULL
;
6397 char *vrf_name
= NULL
;
6398 bool all_vrf
= FALSE
;
6399 int ret
= CMD_SUCCESS
;
6402 uint8_t use_vrf
= 0;
6404 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6405 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6406 ospf
= ospf_lookup_instance(instance
);
6408 return CMD_NOT_MY_INSTANCE
;
6409 if (!ospf
->oi_running
)
6412 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6413 argc
, argv
, use_vrf
));
6414 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6415 vrf_name
= argv
[++idx
]->arg
;
6416 all_vrf
= strmatch(vrf_name
, "all");
6422 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6423 if (!ospf
->oi_running
)
6425 ret
= (show_ip_ospf_database_common(
6426 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6430 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6431 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6432 vty_out(vty
, "%% OSPF instance not found \n");
6436 ret
= (show_ip_ospf_database_common(
6437 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6440 /* Display default ospf (instance 0) info */
6441 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6442 if (ospf
== NULL
|| !ospf
->oi_running
) {
6443 vty_out(vty
, "%% OSPF instance not found \n");
6447 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6454 DEFUN (show_ip_ospf_instance_database_max
,
6455 show_ip_ospf_instance_database_max_cmd
,
6456 "show ip ospf (1-65535) database <max-age|self-originate>",
6459 "OSPF information\n"
6461 "Database summary\n"
6462 "LSAs in MaxAge list\n"
6463 "Self-originated link states\n")
6467 unsigned short instance
= 0;
6469 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6471 ospf
= ospf_lookup_instance(instance
);
6473 return CMD_NOT_MY_INSTANCE
;
6475 if (!ospf
->oi_running
) {
6476 vty_out(vty
, "%% OSPF instance not found \n");
6480 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6484 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6486 int arg_base
, int argc
,
6487 struct cmd_token
**argv
,
6492 struct in_addr adv_router
;
6495 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6497 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6499 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6500 inet_ntoa(ospf
->router_id
));
6502 /* Set database type to show. */
6503 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6504 type
= OSPF_ROUTER_LSA
;
6505 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6506 type
= OSPF_NETWORK_LSA
;
6507 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6508 type
= OSPF_AS_NSSA_LSA
;
6509 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6510 type
= OSPF_SUMMARY_LSA
;
6511 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6512 type
= OSPF_ASBR_SUMMARY_LSA
;
6513 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6514 type
= OSPF_AS_EXTERNAL_LSA
;
6515 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6516 type
= OSPF_OPAQUE_LINK_LSA
;
6517 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6518 type
= OSPF_OPAQUE_AREA_LSA
;
6519 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6520 type
= OSPF_OPAQUE_AS_LSA
;
6524 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6525 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6526 adv_router
= ospf
->router_id
;
6528 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6533 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6538 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6539 show_ip_ospf_instance_database_type_adv_router_cmd
,
6540 "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>",
6543 "OSPF information\n"
6546 "Database summary\n"
6548 "Advertising Router link states\n"
6549 "Advertising Router (as an IP address)\n"
6550 "Self-originated link states\n")
6552 struct ospf
*ospf
= NULL
;
6553 unsigned short instance
= 0;
6554 struct listnode
*node
= NULL
;
6555 char *vrf_name
= NULL
;
6556 bool all_vrf
= FALSE
;
6557 int ret
= CMD_SUCCESS
;
6559 int idx
= 0, idx_vrf
= 0;
6560 uint8_t use_vrf
= 0;
6562 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6563 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6564 ospf
= ospf_lookup_instance(instance
);
6566 return CMD_NOT_MY_INSTANCE
;
6567 if (!ospf
->oi_running
) {
6568 vty_out(vty
, "%% OSPF instance not found \n");
6572 return (show_ip_ospf_database_type_adv_router_common(
6573 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6576 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6579 bool ospf_output
= FALSE
;
6582 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6583 if (!ospf
->oi_running
)
6586 ret
= show_ip_ospf_database_type_adv_router_common(
6587 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6591 vty_out(vty
, "%% OSPF instance not found\n");
6593 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6594 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6595 vty_out(vty
, "%% OSPF instance not found \n");
6599 ret
= show_ip_ospf_database_type_adv_router_common(
6600 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6603 /* Display default ospf (instance 0) info */
6604 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6605 if (ospf
== NULL
|| !ospf
->oi_running
) {
6606 vty_out(vty
, "%% OSPF instance not found \n");
6610 ret
= show_ip_ospf_database_type_adv_router_common(
6611 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6614 /*return (show_ip_ospf_database_type_adv_router_common(
6615 vty, ospf, idx ? 1 : 0, argc, argv));*/
6618 DEFUN (ip_ospf_authentication_args
,
6619 ip_ospf_authentication_args_addr_cmd
,
6620 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6622 "OSPF interface commands\n"
6623 "Enable authentication on this interface\n"
6624 "Use null authentication\n"
6625 "Use message-digest authentication\n"
6626 "Address of interface\n")
6628 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6629 int idx_encryption
= 3;
6631 struct in_addr addr
;
6633 struct ospf_if_params
*params
;
6635 params
= IF_DEF_PARAMS(ifp
);
6638 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6641 "Please specify interface address by A.B.C.D\n");
6642 return CMD_WARNING_CONFIG_FAILED
;
6645 params
= ospf_get_if_params(ifp
, addr
);
6646 ospf_if_update_params(ifp
, addr
);
6649 /* Handle null authentication */
6650 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6651 SET_IF_PARAM(params
, auth_type
);
6652 params
->auth_type
= OSPF_AUTH_NULL
;
6656 /* Handle message-digest authentication */
6657 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6658 SET_IF_PARAM(params
, auth_type
);
6659 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6663 vty_out(vty
, "You shouldn't get here!\n");
6664 return CMD_WARNING_CONFIG_FAILED
;
6667 DEFUN (ip_ospf_authentication
,
6668 ip_ospf_authentication_addr_cmd
,
6669 "ip ospf authentication [A.B.C.D]",
6671 "OSPF interface commands\n"
6672 "Enable authentication on this interface\n"
6673 "Address of interface\n")
6675 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6677 struct in_addr addr
;
6679 struct ospf_if_params
*params
;
6681 params
= IF_DEF_PARAMS(ifp
);
6684 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6687 "Please specify interface address by A.B.C.D\n");
6688 return CMD_WARNING_CONFIG_FAILED
;
6691 params
= ospf_get_if_params(ifp
, addr
);
6692 ospf_if_update_params(ifp
, addr
);
6695 SET_IF_PARAM(params
, auth_type
);
6696 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6701 DEFUN (no_ip_ospf_authentication_args
,
6702 no_ip_ospf_authentication_args_addr_cmd
,
6703 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6706 "OSPF interface commands\n"
6707 "Enable authentication on this interface\n"
6708 "Use null authentication\n"
6709 "Use message-digest authentication\n"
6710 "Address of interface\n")
6712 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6713 int idx_encryption
= 4;
6715 struct in_addr addr
;
6717 struct ospf_if_params
*params
;
6718 struct route_node
*rn
;
6721 params
= IF_DEF_PARAMS(ifp
);
6724 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6727 "Please specify interface address by A.B.C.D\n");
6728 return CMD_WARNING_CONFIG_FAILED
;
6731 params
= ospf_lookup_if_params(ifp
, addr
);
6732 if (params
== NULL
) {
6733 vty_out(vty
, "Ip Address specified is unknown\n");
6734 return CMD_WARNING_CONFIG_FAILED
;
6736 params
->auth_type
= OSPF_AUTH_NOTSET
;
6737 UNSET_IF_PARAM(params
, auth_type
);
6738 if (params
!= IF_DEF_PARAMS(ifp
)) {
6739 ospf_free_if_params(ifp
, addr
);
6740 ospf_if_update_params(ifp
, addr
);
6743 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6744 auth_type
= OSPF_AUTH_NULL
;
6745 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6746 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6748 vty_out(vty
, "Unexpected input encountered\n");
6749 return CMD_WARNING_CONFIG_FAILED
;
6752 * Here we have a case where the user has entered
6753 * 'no ip ospf authentication (null | message_digest )'
6754 * we need to find if we have any ip addresses underneath it
6756 * correspond to the associated type.
6758 if (params
->auth_type
== auth_type
) {
6759 params
->auth_type
= OSPF_AUTH_NOTSET
;
6760 UNSET_IF_PARAM(params
, auth_type
);
6763 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6764 rn
= route_next(rn
)) {
6765 if ((params
= rn
->info
)) {
6766 if (params
->auth_type
== auth_type
) {
6767 params
->auth_type
= OSPF_AUTH_NOTSET
;
6768 UNSET_IF_PARAM(params
, auth_type
);
6769 if (params
!= IF_DEF_PARAMS(ifp
)) {
6770 ospf_free_if_params(
6771 ifp
, rn
->p
.u
.prefix4
);
6772 ospf_if_update_params(
6773 ifp
, rn
->p
.u
.prefix4
);
6783 DEFUN (no_ip_ospf_authentication
,
6784 no_ip_ospf_authentication_addr_cmd
,
6785 "no ip ospf authentication [A.B.C.D]",
6788 "OSPF interface commands\n"
6789 "Enable authentication on this interface\n"
6790 "Address of interface\n")
6792 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6794 struct in_addr addr
;
6796 struct ospf_if_params
*params
;
6797 struct route_node
*rn
;
6799 params
= IF_DEF_PARAMS(ifp
);
6802 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6805 "Please specify interface address by A.B.C.D\n");
6806 return CMD_WARNING_CONFIG_FAILED
;
6809 params
= ospf_lookup_if_params(ifp
, addr
);
6810 if (params
== NULL
) {
6811 vty_out(vty
, "Ip Address specified is unknown\n");
6812 return CMD_WARNING_CONFIG_FAILED
;
6815 params
->auth_type
= OSPF_AUTH_NOTSET
;
6816 UNSET_IF_PARAM(params
, auth_type
);
6817 if (params
!= IF_DEF_PARAMS(ifp
)) {
6818 ospf_free_if_params(ifp
, addr
);
6819 ospf_if_update_params(ifp
, addr
);
6823 * When a user enters 'no ip ospf authentication'
6824 * We should remove all authentication types from
6827 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6828 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6829 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6830 params
->auth_type
= OSPF_AUTH_NOTSET
;
6831 UNSET_IF_PARAM(params
, auth_type
);
6834 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6835 rn
= route_next(rn
)) {
6836 if ((params
= rn
->info
)) {
6838 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6839 || (params
->auth_type
6840 == OSPF_AUTH_CRYPTOGRAPHIC
)
6841 || (params
->auth_type
6842 == OSPF_AUTH_SIMPLE
)) {
6843 params
->auth_type
= OSPF_AUTH_NOTSET
;
6844 UNSET_IF_PARAM(params
, auth_type
);
6845 if (params
!= IF_DEF_PARAMS(ifp
)) {
6846 ospf_free_if_params(
6847 ifp
, rn
->p
.u
.prefix4
);
6848 ospf_if_update_params(
6849 ifp
, rn
->p
.u
.prefix4
);
6860 DEFUN (ip_ospf_authentication_key
,
6861 ip_ospf_authentication_key_addr_cmd
,
6862 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6864 "OSPF interface commands\n"
6865 "Authentication password (key)\n"
6866 "The OSPF password (key)\n"
6867 "Address of interface\n")
6869 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6871 struct in_addr addr
;
6872 struct ospf_if_params
*params
;
6874 params
= IF_DEF_PARAMS(ifp
);
6876 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6877 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6879 "Please specify interface address by A.B.C.D\n");
6880 return CMD_WARNING_CONFIG_FAILED
;
6883 params
= ospf_get_if_params(ifp
, addr
);
6884 ospf_if_update_params(ifp
, addr
);
6887 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6888 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6889 OSPF_AUTH_SIMPLE_SIZE
);
6890 SET_IF_PARAM(params
, auth_simple
);
6895 DEFUN_HIDDEN (ospf_authentication_key
,
6896 ospf_authentication_key_cmd
,
6897 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6898 "OSPF interface commands\n"
6899 VLINK_HELPSTR_AUTH_SIMPLE
6900 "Address of interface\n")
6902 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6905 DEFUN (no_ip_ospf_authentication_key
,
6906 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6907 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6910 "OSPF interface commands\n"
6911 VLINK_HELPSTR_AUTH_SIMPLE
6912 "Address of interface\n")
6914 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6916 struct in_addr addr
;
6917 struct ospf_if_params
*params
;
6918 params
= IF_DEF_PARAMS(ifp
);
6920 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6921 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6923 "Please specify interface address by A.B.C.D\n");
6924 return CMD_WARNING_CONFIG_FAILED
;
6927 params
= ospf_lookup_if_params(ifp
, addr
);
6932 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6933 UNSET_IF_PARAM(params
, auth_simple
);
6935 if (params
!= IF_DEF_PARAMS(ifp
)) {
6936 ospf_free_if_params(ifp
, addr
);
6937 ospf_if_update_params(ifp
, addr
);
6943 DEFUN_HIDDEN (no_ospf_authentication_key
,
6944 no_ospf_authentication_key_authkey_addr_cmd
,
6945 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6947 "OSPF interface commands\n"
6948 VLINK_HELPSTR_AUTH_SIMPLE
6949 "Address of interface\n")
6951 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6954 DEFUN (ip_ospf_message_digest_key
,
6955 ip_ospf_message_digest_key_cmd
,
6956 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6958 "OSPF interface commands\n"
6959 "Message digest authentication password (key)\n"
6961 "Use MD5 algorithm\n"
6962 "The OSPF password (key)\n"
6963 "Address of interface\n")
6965 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6966 struct crypt_key
*ck
;
6968 struct in_addr addr
;
6969 struct ospf_if_params
*params
;
6971 params
= IF_DEF_PARAMS(ifp
);
6974 argv_find(argv
, argc
, "(1-255)", &idx
);
6975 char *keyid
= argv
[idx
]->arg
;
6976 argv_find(argv
, argc
, "KEY", &idx
);
6977 char *cryptkey
= argv
[idx
]->arg
;
6979 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6980 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6982 "Please specify interface address by A.B.C.D\n");
6983 return CMD_WARNING_CONFIG_FAILED
;
6986 params
= ospf_get_if_params(ifp
, addr
);
6987 ospf_if_update_params(ifp
, addr
);
6990 key_id
= strtol(keyid
, NULL
, 10);
6991 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
6992 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
6996 ck
= ospf_crypt_key_new();
6997 ck
->key_id
= (uint8_t)key_id
;
6998 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
6999 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
7001 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7002 SET_IF_PARAM(params
, auth_crypt
);
7007 DEFUN_HIDDEN (ospf_message_digest_key
,
7008 ospf_message_digest_key_cmd
,
7009 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7010 "OSPF interface commands\n"
7011 "Message digest authentication password (key)\n"
7013 "Use MD5 algorithm\n"
7014 "The OSPF password (key)\n"
7015 "Address of interface\n")
7017 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7020 DEFUN (no_ip_ospf_message_digest_key
,
7021 no_ip_ospf_message_digest_key_cmd
,
7022 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7025 "OSPF interface commands\n"
7026 "Message digest authentication password (key)\n"
7028 "Use MD5 algorithm\n"
7029 "The OSPF password (key)\n"
7030 "Address of interface\n")
7032 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7034 struct crypt_key
*ck
;
7036 struct in_addr addr
;
7037 struct ospf_if_params
*params
;
7038 params
= IF_DEF_PARAMS(ifp
);
7040 argv_find(argv
, argc
, "(1-255)", &idx
);
7041 char *keyid
= argv
[idx
]->arg
;
7043 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7044 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7046 "Please specify interface address by A.B.C.D\n");
7047 return CMD_WARNING_CONFIG_FAILED
;
7050 params
= ospf_lookup_if_params(ifp
, addr
);
7055 key_id
= strtol(keyid
, NULL
, 10);
7056 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7058 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7059 return CMD_WARNING_CONFIG_FAILED
;
7062 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7064 if (params
!= IF_DEF_PARAMS(ifp
)) {
7065 ospf_free_if_params(ifp
, addr
);
7066 ospf_if_update_params(ifp
, addr
);
7072 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7073 no_ospf_message_digest_key_cmd
,
7074 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7076 "OSPF interface commands\n"
7077 "Message digest authentication password (key)\n"
7079 "Use MD5 algorithm\n"
7080 "The OSPF password (key)\n"
7081 "Address of interface\n")
7083 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7086 DEFUN (ip_ospf_cost
,
7088 "ip ospf cost (1-65535) [A.B.C.D]",
7090 "OSPF interface commands\n"
7093 "Address of interface\n")
7095 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7097 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7098 struct in_addr addr
;
7099 struct ospf_if_params
*params
;
7100 params
= IF_DEF_PARAMS(ifp
);
7103 char *coststr
= NULL
, *ifaddr
= NULL
;
7105 argv_find(argv
, argc
, "(1-65535)", &idx
);
7106 coststr
= argv
[idx
]->arg
;
7107 cost
= strtol(coststr
, NULL
, 10);
7109 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7111 if (!inet_aton(ifaddr
, &addr
)) {
7113 "Please specify interface address by A.B.C.D\n");
7114 return CMD_WARNING_CONFIG_FAILED
;
7117 params
= ospf_get_if_params(ifp
, addr
);
7118 ospf_if_update_params(ifp
, addr
);
7121 SET_IF_PARAM(params
, output_cost_cmd
);
7122 params
->output_cost_cmd
= cost
;
7124 ospf_if_recalculate_output_cost(ifp
);
7129 DEFUN_HIDDEN (ospf_cost
,
7131 "ospf cost (1-65535) [A.B.C.D]",
7132 "OSPF interface commands\n"
7135 "Address of interface\n")
7137 return ip_ospf_cost(self
, vty
, argc
, argv
);
7140 DEFUN (no_ip_ospf_cost
,
7141 no_ip_ospf_cost_cmd
,
7142 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7145 "OSPF interface commands\n"
7148 "Address of interface\n")
7150 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7152 struct in_addr addr
;
7153 struct ospf_if_params
*params
;
7155 params
= IF_DEF_PARAMS(ifp
);
7158 char *ifaddr
= NULL
;
7159 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7161 /* According to the semantics we are mimicking "no ip ospf cost N" is
7162 * always treated as "no ip ospf cost" regardless of the actual value
7163 * of N already configured for the interface. Thus ignore cost. */
7166 if (!inet_aton(ifaddr
, &addr
)) {
7168 "Please specify interface address by A.B.C.D\n");
7169 return CMD_WARNING_CONFIG_FAILED
;
7172 params
= ospf_lookup_if_params(ifp
, addr
);
7177 UNSET_IF_PARAM(params
, output_cost_cmd
);
7179 if (params
!= IF_DEF_PARAMS(ifp
)) {
7180 ospf_free_if_params(ifp
, addr
);
7181 ospf_if_update_params(ifp
, addr
);
7184 ospf_if_recalculate_output_cost(ifp
);
7189 DEFUN_HIDDEN (no_ospf_cost
,
7191 "no ospf cost [(1-65535)] [A.B.C.D]",
7193 "OSPF interface commands\n"
7196 "Address of interface\n")
7198 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7201 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7203 struct route_node
*rn
;
7204 struct ospf_neighbor
*nbr
;
7206 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7207 if ((nbr
= rn
->info
)) {
7208 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7209 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7210 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7211 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7215 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7216 const char *nbr_str
,
7217 const char *fast_hello_str
)
7219 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7222 struct in_addr addr
;
7224 struct ospf_if_params
*params
;
7225 struct ospf_interface
*oi
;
7226 struct route_node
*rn
;
7228 params
= IF_DEF_PARAMS(ifp
);
7231 ret
= inet_aton(nbr_str
, &addr
);
7234 "Please specify interface address by A.B.C.D\n");
7235 return CMD_WARNING_CONFIG_FAILED
;
7238 params
= ospf_get_if_params(ifp
, addr
);
7239 ospf_if_update_params(ifp
, addr
);
7243 seconds
= strtoul(interval_str
, NULL
, 10);
7245 /* reset fast_hello too, just to be sure */
7246 UNSET_IF_PARAM(params
, fast_hello
);
7247 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7248 } else if (fast_hello_str
) {
7249 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7250 /* 1s dead-interval with sub-second hellos desired */
7251 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7252 SET_IF_PARAM(params
, fast_hello
);
7253 params
->fast_hello
= hellomult
;
7256 "Please specify dead-interval or hello-multiplier\n");
7257 return CMD_WARNING_CONFIG_FAILED
;
7260 SET_IF_PARAM(params
, v_wait
);
7261 params
->v_wait
= seconds
;
7263 /* Update timer values in neighbor structure. */
7265 struct ospf
*ospf
= NULL
;
7267 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7269 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7271 ospf_nbr_timer_update(oi
);
7274 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7275 if ((oi
= rn
->info
))
7276 ospf_nbr_timer_update(oi
);
7282 DEFUN (ip_ospf_dead_interval
,
7283 ip_ospf_dead_interval_cmd
,
7284 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7286 "OSPF interface commands\n"
7287 "Interval time after which a neighbor is declared down\n"
7289 "Address of interface\n")
7292 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7296 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7297 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7301 DEFUN_HIDDEN (ospf_dead_interval
,
7302 ospf_dead_interval_cmd
,
7303 "ospf dead-interval (1-65535) [A.B.C.D]",
7304 "OSPF interface commands\n"
7305 "Interval time after which a neighbor is declared down\n"
7307 "Address of interface\n")
7309 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7312 DEFUN (ip_ospf_dead_interval_minimal
,
7313 ip_ospf_dead_interval_minimal_addr_cmd
,
7314 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7316 "OSPF interface commands\n"
7317 "Interval time after which a neighbor is declared down\n"
7318 "Minimal 1s dead-interval with fast sub-second hellos\n"
7319 "Hello multiplier factor\n"
7320 "Number of Hellos to send each second\n"
7321 "Address of interface\n")
7326 return ospf_vty_dead_interval_set(
7327 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7329 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7330 argv
[idx_number
]->arg
);
7333 DEFUN (no_ip_ospf_dead_interval
,
7334 no_ip_ospf_dead_interval_cmd
,
7335 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7338 "OSPF interface commands\n"
7339 "Interval time after which a neighbor is declared down\n"
7341 "Minimal 1s dead-interval with fast sub-second hellos\n"
7342 "Hello multiplier factor\n"
7343 "Number of Hellos to send each second\n"
7344 "Address of interface\n")
7346 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7347 int idx_ipv4
= argc
- 1;
7348 struct in_addr addr
= {.s_addr
= 0L};
7350 struct ospf_if_params
*params
;
7351 struct ospf_interface
*oi
;
7352 struct route_node
*rn
;
7354 params
= IF_DEF_PARAMS(ifp
);
7356 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7357 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7360 "Please specify interface address by A.B.C.D\n");
7361 return CMD_WARNING_CONFIG_FAILED
;
7364 params
= ospf_lookup_if_params(ifp
, addr
);
7369 UNSET_IF_PARAM(params
, v_wait
);
7370 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7372 UNSET_IF_PARAM(params
, fast_hello
);
7373 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7375 if (params
!= IF_DEF_PARAMS(ifp
)) {
7376 ospf_free_if_params(ifp
, addr
);
7377 ospf_if_update_params(ifp
, addr
);
7380 /* Update timer values in neighbor structure. */
7382 struct ospf
*ospf
= NULL
;
7384 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7386 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7388 ospf_nbr_timer_update(oi
);
7391 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7392 if ((oi
= rn
->info
))
7393 ospf_nbr_timer_update(oi
);
7399 DEFUN_HIDDEN (no_ospf_dead_interval
,
7400 no_ospf_dead_interval_cmd
,
7401 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7403 "OSPF interface commands\n"
7404 "Interval time after which a neighbor is declared down\n"
7406 "Minimal 1s dead-interval with fast sub-second hellos\n"
7407 "Hello multiplier factor\n"
7408 "Number of Hellos to send each second\n"
7409 "Address of interface\n")
7411 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7414 DEFUN (ip_ospf_hello_interval
,
7415 ip_ospf_hello_interval_cmd
,
7416 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7418 "OSPF interface commands\n"
7419 "Time between HELLO packets\n"
7421 "Address of interface\n")
7423 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7425 struct in_addr addr
;
7426 struct ospf_if_params
*params
;
7427 params
= IF_DEF_PARAMS(ifp
);
7428 uint32_t seconds
= 0;
7430 argv_find(argv
, argc
, "(1-65535)", &idx
);
7431 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7433 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7434 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7436 "Please specify interface address by A.B.C.D\n");
7437 return CMD_WARNING_CONFIG_FAILED
;
7440 params
= ospf_get_if_params(ifp
, addr
);
7441 ospf_if_update_params(ifp
, addr
);
7444 SET_IF_PARAM(params
, v_hello
);
7445 params
->v_hello
= seconds
;
7450 DEFUN_HIDDEN (ospf_hello_interval
,
7451 ospf_hello_interval_cmd
,
7452 "ospf hello-interval (1-65535) [A.B.C.D]",
7453 "OSPF interface commands\n"
7454 "Time between HELLO packets\n"
7456 "Address of interface\n")
7458 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7461 DEFUN (no_ip_ospf_hello_interval
,
7462 no_ip_ospf_hello_interval_cmd
,
7463 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7466 "OSPF interface commands\n"
7467 "Time between HELLO packets\n" // ignored
7469 "Address of interface\n")
7471 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7473 struct in_addr addr
;
7474 struct ospf_if_params
*params
;
7476 params
= IF_DEF_PARAMS(ifp
);
7478 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7479 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7481 "Please specify interface address by A.B.C.D\n");
7482 return CMD_WARNING_CONFIG_FAILED
;
7485 params
= ospf_lookup_if_params(ifp
, addr
);
7490 UNSET_IF_PARAM(params
, v_hello
);
7491 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7493 if (params
!= IF_DEF_PARAMS(ifp
)) {
7494 ospf_free_if_params(ifp
, addr
);
7495 ospf_if_update_params(ifp
, addr
);
7501 DEFUN_HIDDEN (no_ospf_hello_interval
,
7502 no_ospf_hello_interval_cmd
,
7503 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7505 "OSPF interface commands\n"
7506 "Time between HELLO packets\n" // ignored
7508 "Address of interface\n")
7510 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7513 DEFUN (ip_ospf_network
,
7514 ip_ospf_network_cmd
,
7515 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7517 "OSPF interface commands\n"
7519 "Specify OSPF broadcast multi-access network\n"
7520 "Specify OSPF NBMA network\n"
7521 "Specify OSPF point-to-multipoint network\n"
7522 "Specify OSPF point-to-point network\n")
7524 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7526 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7527 struct route_node
*rn
;
7529 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7531 "This is a loopback interface. Can't set network type.\n");
7532 return CMD_WARNING_CONFIG_FAILED
;
7535 if (argv_find(argv
, argc
, "broadcast", &idx
))
7536 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7537 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7538 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7539 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7540 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7541 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7542 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7544 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7547 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7549 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7550 struct ospf_interface
*oi
= rn
->info
;
7555 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7557 if (oi
->state
> ISM_Down
) {
7558 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7559 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7566 DEFUN_HIDDEN (ospf_network
,
7568 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7569 "OSPF interface commands\n"
7571 "Specify OSPF broadcast multi-access network\n"
7572 "Specify OSPF NBMA network\n"
7573 "Specify OSPF point-to-multipoint network\n"
7574 "Specify OSPF point-to-point network\n")
7576 return ip_ospf_network(self
, vty
, argc
, argv
);
7579 DEFUN (no_ip_ospf_network
,
7580 no_ip_ospf_network_cmd
,
7581 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7584 "OSPF interface commands\n"
7586 "Specify OSPF broadcast multi-access network\n"
7587 "Specify OSPF NBMA network\n"
7588 "Specify OSPF point-to-multipoint network\n"
7589 "Specify OSPF point-to-point network\n")
7591 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7592 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7593 struct route_node
*rn
;
7595 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7597 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7600 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7601 struct ospf_interface
*oi
= rn
->info
;
7606 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7608 if (oi
->state
> ISM_Down
) {
7609 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7610 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7617 DEFUN_HIDDEN (no_ospf_network
,
7618 no_ospf_network_cmd
,
7619 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7621 "OSPF interface commands\n"
7623 "Specify OSPF broadcast multi-access network\n"
7624 "Specify OSPF NBMA network\n"
7625 "Specify OSPF point-to-multipoint network\n"
7626 "Specify OSPF point-to-point network\n")
7628 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7631 DEFUN (ip_ospf_priority
,
7632 ip_ospf_priority_cmd
,
7633 "ip ospf priority (0-255) [A.B.C.D]",
7635 "OSPF interface commands\n"
7638 "Address of interface\n")
7640 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7643 struct route_node
*rn
;
7644 struct in_addr addr
;
7645 struct ospf_if_params
*params
;
7646 params
= IF_DEF_PARAMS(ifp
);
7648 argv_find(argv
, argc
, "(0-255)", &idx
);
7649 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7651 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7652 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7654 "Please specify interface address by A.B.C.D\n");
7655 return CMD_WARNING_CONFIG_FAILED
;
7658 params
= ospf_get_if_params(ifp
, addr
);
7659 ospf_if_update_params(ifp
, addr
);
7662 SET_IF_PARAM(params
, priority
);
7663 params
->priority
= priority
;
7665 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7666 struct ospf_interface
*oi
= rn
->info
;
7671 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7672 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7673 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7680 DEFUN_HIDDEN (ospf_priority
,
7682 "ospf priority (0-255) [A.B.C.D]",
7683 "OSPF interface commands\n"
7686 "Address of interface\n")
7688 return ip_ospf_priority(self
, vty
, argc
, argv
);
7691 DEFUN (no_ip_ospf_priority
,
7692 no_ip_ospf_priority_cmd
,
7693 "no ip ospf priority [(0-255) [A.B.C.D]]",
7696 "OSPF interface commands\n"
7697 "Router priority\n" // ignored
7699 "Address of interface\n")
7701 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7703 struct route_node
*rn
;
7704 struct in_addr addr
;
7705 struct ospf_if_params
*params
;
7707 params
= IF_DEF_PARAMS(ifp
);
7709 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7710 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7712 "Please specify interface address by A.B.C.D\n");
7713 return CMD_WARNING_CONFIG_FAILED
;
7716 params
= ospf_lookup_if_params(ifp
, addr
);
7721 UNSET_IF_PARAM(params
, priority
);
7722 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7724 if (params
!= IF_DEF_PARAMS(ifp
)) {
7725 ospf_free_if_params(ifp
, addr
);
7726 ospf_if_update_params(ifp
, addr
);
7729 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7730 struct ospf_interface
*oi
= rn
->info
;
7735 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7736 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7737 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7744 DEFUN_HIDDEN (no_ospf_priority
,
7745 no_ospf_priority_cmd
,
7746 "no ospf priority [(0-255) [A.B.C.D]]",
7748 "OSPF interface commands\n"
7751 "Address of interface\n")
7753 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7756 DEFUN (ip_ospf_retransmit_interval
,
7757 ip_ospf_retransmit_interval_addr_cmd
,
7758 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7760 "OSPF interface commands\n"
7761 "Time between retransmitting lost link state advertisements\n"
7763 "Address of interface\n")
7765 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7768 struct in_addr addr
;
7769 struct ospf_if_params
*params
;
7770 params
= IF_DEF_PARAMS(ifp
);
7772 argv_find(argv
, argc
, "(3-65535)", &idx
);
7773 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7775 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7776 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7778 "Please specify interface address by A.B.C.D\n");
7779 return CMD_WARNING_CONFIG_FAILED
;
7782 params
= ospf_get_if_params(ifp
, addr
);
7783 ospf_if_update_params(ifp
, addr
);
7786 SET_IF_PARAM(params
, retransmit_interval
);
7787 params
->retransmit_interval
= seconds
;
7792 DEFUN_HIDDEN (ospf_retransmit_interval
,
7793 ospf_retransmit_interval_cmd
,
7794 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7795 "OSPF interface commands\n"
7796 "Time between retransmitting lost link state advertisements\n"
7798 "Address of interface\n")
7800 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7803 DEFUN (no_ip_ospf_retransmit_interval
,
7804 no_ip_ospf_retransmit_interval_addr_cmd
,
7805 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7808 "OSPF interface commands\n"
7809 "Time between retransmitting lost link state advertisements\n"
7811 "Address of interface\n")
7813 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7815 struct in_addr addr
;
7816 struct ospf_if_params
*params
;
7818 params
= IF_DEF_PARAMS(ifp
);
7820 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7821 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7823 "Please specify interface address by A.B.C.D\n");
7824 return CMD_WARNING_CONFIG_FAILED
;
7827 params
= ospf_lookup_if_params(ifp
, addr
);
7832 UNSET_IF_PARAM(params
, retransmit_interval
);
7833 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7835 if (params
!= IF_DEF_PARAMS(ifp
)) {
7836 ospf_free_if_params(ifp
, addr
);
7837 ospf_if_update_params(ifp
, addr
);
7843 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7844 no_ospf_retransmit_interval_cmd
,
7845 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7847 "OSPF interface commands\n"
7848 "Time between retransmitting lost link state advertisements\n"
7850 "Address of interface\n")
7852 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7855 DEFUN (ip_ospf_transmit_delay
,
7856 ip_ospf_transmit_delay_addr_cmd
,
7857 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7859 "OSPF interface commands\n"
7860 "Link state transmit delay\n"
7862 "Address of interface\n")
7864 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7867 struct in_addr addr
;
7868 struct ospf_if_params
*params
;
7870 params
= IF_DEF_PARAMS(ifp
);
7871 argv_find(argv
, argc
, "(1-65535)", &idx
);
7872 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7874 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7875 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7877 "Please specify interface address by A.B.C.D\n");
7878 return CMD_WARNING_CONFIG_FAILED
;
7881 params
= ospf_get_if_params(ifp
, addr
);
7882 ospf_if_update_params(ifp
, addr
);
7885 SET_IF_PARAM(params
, transmit_delay
);
7886 params
->transmit_delay
= seconds
;
7891 DEFUN_HIDDEN (ospf_transmit_delay
,
7892 ospf_transmit_delay_cmd
,
7893 "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 ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7902 DEFUN (no_ip_ospf_transmit_delay
,
7903 no_ip_ospf_transmit_delay_addr_cmd
,
7904 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7907 "OSPF interface commands\n"
7908 "Link state transmit delay\n"
7910 "Address of interface\n")
7912 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7914 struct in_addr addr
;
7915 struct ospf_if_params
*params
;
7917 params
= IF_DEF_PARAMS(ifp
);
7919 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7920 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7922 "Please specify interface address by A.B.C.D\n");
7923 return CMD_WARNING_CONFIG_FAILED
;
7926 params
= ospf_lookup_if_params(ifp
, addr
);
7931 UNSET_IF_PARAM(params
, transmit_delay
);
7932 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7934 if (params
!= IF_DEF_PARAMS(ifp
)) {
7935 ospf_free_if_params(ifp
, addr
);
7936 ospf_if_update_params(ifp
, addr
);
7943 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7944 no_ospf_transmit_delay_cmd
,
7945 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7947 "OSPF interface commands\n"
7948 "Link state transmit delay\n"
7950 "Address of interface\n")
7952 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7955 DEFUN (ip_ospf_area
,
7957 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7959 "OSPF interface commands\n"
7961 "Enable OSPF on this interface\n"
7962 "OSPF area ID in IP address format\n"
7963 "OSPF area ID as a decimal value\n"
7964 "Address of interface\n")
7966 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7969 struct in_addr area_id
;
7970 struct in_addr addr
;
7971 struct ospf_if_params
*params
= NULL
;
7972 struct route_node
*rn
;
7973 struct ospf
*ospf
= NULL
;
7974 unsigned short instance
= 0;
7977 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7978 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7980 argv_find(argv
, argc
, "area", &idx
);
7981 areaid
= argv
[idx
+ 1]->arg
;
7983 if (ifp
->vrf_id
&& !instance
)
7984 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7986 ospf
= ospf_lookup_instance(instance
);
7988 if (instance
&& ospf
== NULL
) {
7989 params
= IF_DEF_PARAMS(ifp
);
7990 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7991 UNSET_IF_PARAM(params
, if_area
);
7992 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7993 ospf_interface_area_unset(ospf
, ifp
);
7994 ospf
->if_ospf_cli_count
--;
7996 return CMD_NOT_MY_INSTANCE
;
7999 ret
= str2area_id(areaid
, &area_id
, &format
);
8001 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8002 return CMD_WARNING_CONFIG_FAILED
;
8004 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8005 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8006 return CMD_WARNING_CONFIG_FAILED
;
8009 params
= IF_DEF_PARAMS(ifp
);
8010 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8011 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8013 "Must remove previous area config before changing ospf area \n");
8014 return CMD_WARNING_CONFIG_FAILED
;
8017 // Check if we have an address arg and proccess it
8018 if (argc
== idx
+ 3) {
8019 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8021 "Please specify Intf Address by A.B.C.D\n");
8022 return CMD_WARNING_CONFIG_FAILED
;
8024 // update/create address-level params
8025 params
= ospf_get_if_params((ifp
), (addr
));
8026 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8028 "Must remove previous area/address config before changing ospf area");
8029 return CMD_WARNING_CONFIG_FAILED
;
8031 ospf_if_update_params((ifp
), (addr
));
8035 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8036 if (rn
->info
!= NULL
) {
8038 "Please remove all network commands first.\n");
8039 return CMD_WARNING_CONFIG_FAILED
;
8044 /* enable ospf on this interface with area_id */
8046 SET_IF_PARAM(params
, if_area
);
8047 params
->if_area
= area_id
;
8048 params
->if_area_id_fmt
= format
;
8052 ospf_interface_area_set(ospf
, ifp
);
8053 ospf
->if_ospf_cli_count
++;
8059 DEFUN (no_ip_ospf_area
,
8060 no_ip_ospf_area_cmd
,
8061 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8064 "OSPF interface commands\n"
8066 "Disable OSPF on this interface\n"
8067 "OSPF area ID in IP address format\n"
8068 "OSPF area ID as a decimal value\n"
8069 "Address of interface\n")
8071 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8074 struct ospf_if_params
*params
;
8075 unsigned short instance
= 0;
8076 struct in_addr addr
;
8078 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8079 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8081 if (ifp
->vrf_id
&& !instance
)
8082 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8084 ospf
= ospf_lookup_instance(instance
);
8087 return CMD_NOT_MY_INSTANCE
;
8089 argv_find(argv
, argc
, "area", &idx
);
8091 // Check if we have an address arg and proccess it
8092 if (argc
== idx
+ 3) {
8093 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8095 "Please specify Intf Address by A.B.C.D\n");
8096 return CMD_WARNING_CONFIG_FAILED
;
8098 params
= ospf_lookup_if_params(ifp
, addr
);
8099 if ((params
) == NULL
)
8102 params
= IF_DEF_PARAMS(ifp
);
8104 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8106 "Can't find specified interface area configuration.\n");
8107 return CMD_WARNING_CONFIG_FAILED
;
8110 UNSET_IF_PARAM(params
, if_area
);
8111 if (params
!= IF_DEF_PARAMS((ifp
))) {
8112 ospf_free_if_params((ifp
), (addr
));
8113 ospf_if_update_params((ifp
), (addr
));
8116 ospf_interface_area_unset(ospf
, ifp
);
8117 ospf
->if_ospf_cli_count
--;
8121 DEFUN (ospf_redistribute_source
,
8122 ospf_redistribute_source_cmd
,
8123 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8125 FRR_REDIST_HELP_STR_OSPFD
8126 "Metric for redistributed routes\n"
8127 "OSPF default metric\n"
8128 "OSPF exterior metric type for redistributed routes\n"
8129 "Set OSPF External Type 1/2 metrics\n"
8130 "Route map reference\n"
8131 "Pointer to route-map entries\n")
8133 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8134 int idx_protocol
= 1;
8138 struct ospf_redist
*red
;
8141 /* Get distribute source. */
8142 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8144 return CMD_WARNING_CONFIG_FAILED
;
8146 red
= ospf_redist_add(ospf
, source
, 0);
8148 /* Get metric value. */
8149 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8150 if (!str2metric(argv
[idx
]->arg
, &metric
))
8151 return CMD_WARNING_CONFIG_FAILED
;
8154 /* Get metric type. */
8155 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8156 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8157 return CMD_WARNING_CONFIG_FAILED
;
8161 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8162 ospf_routemap_set(red
, argv
[idx
]->arg
);
8164 ospf_routemap_unset(red
);
8166 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8169 DEFUN (no_ospf_redistribute_source
,
8170 no_ospf_redistribute_source_cmd
,
8171 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8174 FRR_REDIST_HELP_STR_OSPFD
8175 "Metric for redistributed routes\n"
8176 "OSPF default metric\n"
8177 "OSPF exterior metric type for redistributed routes\n"
8178 "Set OSPF External Type 1/2 metrics\n"
8179 "Route map reference\n"
8180 "Pointer to route-map entries\n")
8182 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8183 int idx_protocol
= 2;
8185 struct ospf_redist
*red
;
8187 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8189 return CMD_WARNING_CONFIG_FAILED
;
8191 red
= ospf_redist_lookup(ospf
, source
, 0);
8195 ospf_routemap_unset(red
);
8196 return ospf_redistribute_unset(ospf
, source
, 0);
8199 DEFUN (ospf_redistribute_instance_source
,
8200 ospf_redistribute_instance_source_cmd
,
8201 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8203 "Open Shortest Path First\n"
8204 "Non-main Kernel Routing Table\n"
8205 "Instance ID/Table ID\n"
8206 "Metric for redistributed routes\n"
8207 "OSPF default metric\n"
8208 "OSPF exterior metric type for redistributed routes\n"
8209 "Set OSPF External Type 1/2 metrics\n"
8210 "Route map reference\n"
8211 "Pointer to route-map entries\n")
8213 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8214 int idx_ospf_table
= 1;
8220 unsigned short instance
;
8221 struct ospf_redist
*red
;
8223 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8226 vty_out(vty
, "Unknown instance redistribution\n");
8227 return CMD_WARNING_CONFIG_FAILED
;
8230 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8232 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8234 "Instance redistribution in non-instanced OSPF not allowed\n");
8235 return CMD_WARNING_CONFIG_FAILED
;
8238 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8239 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8240 return CMD_WARNING_CONFIG_FAILED
;
8243 /* Get metric value. */
8244 if (argv_find(argv
, argc
, "metric", &idx
))
8245 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8246 return CMD_WARNING_CONFIG_FAILED
;
8249 /* Get metric type. */
8250 if (argv_find(argv
, argc
, "metric-type", &idx
))
8251 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8252 return CMD_WARNING_CONFIG_FAILED
;
8254 red
= ospf_redist_add(ospf
, source
, instance
);
8257 if (argv_find(argv
, argc
, "route-map", &idx
))
8258 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8260 ospf_routemap_unset(red
);
8262 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8265 DEFUN (no_ospf_redistribute_instance_source
,
8266 no_ospf_redistribute_instance_source_cmd
,
8267 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8270 "Open Shortest Path First\n"
8271 "Non-main Kernel Routing Table\n"
8272 "Instance ID/Table Id\n"
8273 "Metric for redistributed routes\n"
8274 "OSPF default metric\n"
8275 "OSPF exterior metric type for redistributed routes\n"
8276 "Set OSPF External Type 1/2 metrics\n"
8277 "Route map reference\n"
8278 "Pointer to route-map entries\n")
8280 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8281 int idx_ospf_table
= 2;
8283 unsigned int instance
;
8284 struct ospf_redist
*red
;
8287 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8288 source
= ZEBRA_ROUTE_OSPF
;
8290 source
= ZEBRA_ROUTE_TABLE
;
8292 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8294 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8296 "Instance redistribution in non-instanced OSPF not allowed\n");
8297 return CMD_WARNING_CONFIG_FAILED
;
8300 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8301 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8302 return CMD_WARNING_CONFIG_FAILED
;
8305 red
= ospf_redist_lookup(ospf
, source
, instance
);
8309 ospf_routemap_unset(red
);
8310 return ospf_redistribute_unset(ospf
, source
, instance
);
8313 DEFUN (ospf_distribute_list_out
,
8314 ospf_distribute_list_out_cmd
,
8315 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8316 "Filter networks in routing updates\n"
8317 "Access-list name\n"
8319 FRR_REDIST_HELP_STR_OSPFD
)
8321 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8325 char *proto
= argv
[argc
- 1]->text
;
8327 /* Get distribute source. */
8328 source
= proto_redistnum(AFI_IP
, proto
);
8330 return CMD_WARNING_CONFIG_FAILED
;
8332 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8335 DEFUN (no_ospf_distribute_list_out
,
8336 no_ospf_distribute_list_out_cmd
,
8337 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8339 "Filter networks in routing updates\n"
8340 "Access-list name\n"
8342 FRR_REDIST_HELP_STR_OSPFD
)
8344 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8348 char *proto
= argv
[argc
- 1]->text
;
8349 source
= proto_redistnum(AFI_IP
, proto
);
8351 return CMD_WARNING_CONFIG_FAILED
;
8353 return ospf_distribute_list_out_unset(ospf
, source
,
8354 argv
[idx_word
]->arg
);
8357 /* Default information originate. */
8358 DEFUN (ospf_default_information_originate
,
8359 ospf_default_information_originate_cmd
,
8360 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8361 "Control distribution of default information\n"
8362 "Distribute a default route\n"
8363 "Always advertise default route\n"
8364 "OSPF default metric\n"
8366 "OSPF metric type for default routes\n"
8367 "Set OSPF External Type 1/2 metrics\n"
8368 "Route map reference\n"
8369 "Pointer to route-map entries\n")
8371 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8372 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8375 struct ospf_redist
*red
;
8378 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8380 /* Check whether "always" was specified */
8381 if (argv_find(argv
, argc
, "always", &idx
))
8382 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8384 /* Get metric value */
8385 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8386 if (!str2metric(argv
[idx
]->arg
, &metric
))
8387 return CMD_WARNING_CONFIG_FAILED
;
8390 /* Get metric type. */
8391 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8392 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8393 return CMD_WARNING_CONFIG_FAILED
;
8397 if (argv_find(argv
, argc
, "WORD", &idx
))
8398 ospf_routemap_set(red
, argv
[idx
]->arg
);
8400 ospf_routemap_unset(red
);
8402 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8406 DEFUN (no_ospf_default_information_originate
,
8407 no_ospf_default_information_originate_cmd
,
8408 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8410 "Control distribution of default information\n"
8411 "Distribute a default route\n"
8412 "Always advertise default route\n"
8413 "OSPF default metric\n"
8415 "OSPF metric type for default routes\n"
8416 "Set OSPF External Type 1/2 metrics\n"
8417 "Route map reference\n"
8418 "Pointer to route-map entries\n")
8420 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8421 struct prefix_ipv4 p
;
8422 struct ospf_external
*ext
;
8423 struct ospf_redist
*red
;
8426 p
.prefix
.s_addr
= 0;
8429 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8431 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8432 if (ext
&& EXTERNAL_INFO(ext
)) {
8433 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8434 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8437 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8441 ospf_routemap_unset(red
);
8442 return ospf_redistribute_default_unset(ospf
);
8445 DEFUN (ospf_default_metric
,
8446 ospf_default_metric_cmd
,
8447 "default-metric (0-16777214)",
8448 "Set metric of redistributed routes\n"
8451 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8455 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8456 return CMD_WARNING_CONFIG_FAILED
;
8458 ospf
->default_metric
= metric
;
8463 DEFUN (no_ospf_default_metric
,
8464 no_ospf_default_metric_cmd
,
8465 "no default-metric [(0-16777214)]",
8467 "Set metric of redistributed routes\n"
8470 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8472 ospf
->default_metric
= -1;
8478 DEFUN (ospf_distance
,
8481 "Administrative distance\n"
8482 "OSPF Administrative distance\n")
8484 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8487 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8492 DEFUN (no_ospf_distance
,
8493 no_ospf_distance_cmd
,
8494 "no distance (1-255)",
8496 "Administrative distance\n"
8497 "OSPF Administrative distance\n")
8499 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8501 ospf
->distance_all
= 0;
8506 DEFUN (no_ospf_distance_ospf
,
8507 no_ospf_distance_ospf_cmd
,
8508 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8510 "Administrative distance\n"
8511 "OSPF administrative distance\n"
8512 "Intra-area routes\n"
8513 "Distance for intra-area routes\n"
8514 "Inter-area routes\n"
8515 "Distance for inter-area routes\n"
8517 "Distance for external routes\n")
8519 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8522 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8523 idx
= ospf
->distance_intra
= 0;
8524 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8525 idx
= ospf
->distance_inter
= 0;
8526 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8527 ospf
->distance_external
= 0;
8532 DEFUN (ospf_distance_ospf
,
8533 ospf_distance_ospf_cmd
,
8534 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8535 "Administrative distance\n"
8536 "OSPF administrative distance\n"
8537 "Intra-area routes\n"
8538 "Distance for intra-area routes\n"
8539 "Inter-area routes\n"
8540 "Distance for inter-area routes\n"
8542 "Distance for external routes\n")
8544 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8547 ospf
->distance_intra
= 0;
8548 ospf
->distance_inter
= 0;
8549 ospf
->distance_external
= 0;
8551 if (argv_find(argv
, argc
, "intra-area", &idx
))
8552 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8554 if (argv_find(argv
, argc
, "inter-area", &idx
))
8555 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8557 if (argv_find(argv
, argc
, "external", &idx
))
8558 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8564 DEFUN (ospf_distance_source
,
8565 ospf_distance_source_cmd
,
8566 "distance (1-255) A.B.C.D/M",
8567 "Administrative distance\n"
8569 "IP source prefix\n")
8571 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8573 int idx_ipv4_prefixlen
= 2;
8575 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8580 DEFUN (no_ospf_distance_source
,
8581 no_ospf_distance_source_cmd
,
8582 "no distance (1-255) A.B.C.D/M",
8584 "Administrative distance\n"
8586 "IP source prefix\n")
8588 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8590 int idx_ipv4_prefixlen
= 3;
8592 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8597 DEFUN (ospf_distance_source_access_list
,
8598 ospf_distance_source_access_list_cmd
,
8599 "distance (1-255) A.B.C.D/M WORD",
8600 "Administrative distance\n"
8602 "IP source prefix\n"
8603 "Access list name\n")
8605 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8607 int idx_ipv4_prefixlen
= 2;
8610 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8615 DEFUN (no_ospf_distance_source_access_list
,
8616 no_ospf_distance_source_access_list_cmd
,
8617 "no distance (1-255) A.B.C.D/M WORD",
8619 "Administrative distance\n"
8621 "IP source prefix\n"
8622 "Access list name\n")
8624 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8626 int idx_ipv4_prefixlen
= 3;
8629 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8635 DEFUN (ip_ospf_mtu_ignore
,
8636 ip_ospf_mtu_ignore_addr_cmd
,
8637 "ip ospf mtu-ignore [A.B.C.D]",
8639 "OSPF interface commands\n"
8640 "Disable MTU mismatch detection on this interface\n"
8641 "Address of interface\n")
8643 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8645 struct in_addr addr
;
8648 struct ospf_if_params
*params
;
8649 params
= IF_DEF_PARAMS(ifp
);
8652 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8655 "Please specify interface address by A.B.C.D\n");
8656 return CMD_WARNING_CONFIG_FAILED
;
8658 params
= ospf_get_if_params(ifp
, addr
);
8659 ospf_if_update_params(ifp
, addr
);
8661 params
->mtu_ignore
= 1;
8662 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8663 SET_IF_PARAM(params
, mtu_ignore
);
8665 UNSET_IF_PARAM(params
, mtu_ignore
);
8666 if (params
!= IF_DEF_PARAMS(ifp
)) {
8667 ospf_free_if_params(ifp
, addr
);
8668 ospf_if_update_params(ifp
, addr
);
8674 DEFUN (no_ip_ospf_mtu_ignore
,
8675 no_ip_ospf_mtu_ignore_addr_cmd
,
8676 "no ip ospf mtu-ignore [A.B.C.D]",
8679 "OSPF interface commands\n"
8680 "Disable MTU mismatch detection on this interface\n"
8681 "Address of interface\n")
8683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8685 struct in_addr addr
;
8688 struct ospf_if_params
*params
;
8689 params
= IF_DEF_PARAMS(ifp
);
8692 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8695 "Please specify interface address by A.B.C.D\n");
8696 return CMD_WARNING_CONFIG_FAILED
;
8698 params
= ospf_get_if_params(ifp
, addr
);
8699 ospf_if_update_params(ifp
, addr
);
8701 params
->mtu_ignore
= 0;
8702 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8703 SET_IF_PARAM(params
, mtu_ignore
);
8705 UNSET_IF_PARAM(params
, mtu_ignore
);
8706 if (params
!= IF_DEF_PARAMS(ifp
)) {
8707 ospf_free_if_params(ifp
, addr
);
8708 ospf_if_update_params(ifp
, addr
);
8715 DEFUN (ospf_max_metric_router_lsa_admin
,
8716 ospf_max_metric_router_lsa_admin_cmd
,
8717 "max-metric router-lsa administrative",
8718 "OSPF maximum / infinite-distance metric\n"
8719 "Advertise own Router-LSA with infinite distance (stub router)\n"
8720 "Administratively applied, for an indefinite period\n")
8722 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8723 struct listnode
*ln
;
8724 struct ospf_area
*area
;
8726 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8727 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8729 if (!CHECK_FLAG(area
->stub_router_state
,
8730 OSPF_AREA_IS_STUB_ROUTED
))
8731 ospf_router_lsa_update_area(area
);
8734 /* Allows for areas configured later to get the property */
8735 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8740 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8741 no_ospf_max_metric_router_lsa_admin_cmd
,
8742 "no max-metric router-lsa administrative",
8744 "OSPF maximum / infinite-distance metric\n"
8745 "Advertise own Router-LSA with infinite distance (stub router)\n"
8746 "Administratively applied, for an indefinite period\n")
8748 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8749 struct listnode
*ln
;
8750 struct ospf_area
*area
;
8752 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8753 UNSET_FLAG(area
->stub_router_state
,
8754 OSPF_AREA_ADMIN_STUB_ROUTED
);
8756 /* Don't trample on the start-up stub timer */
8757 if (CHECK_FLAG(area
->stub_router_state
,
8758 OSPF_AREA_IS_STUB_ROUTED
)
8759 && !area
->t_stub_router
) {
8760 UNSET_FLAG(area
->stub_router_state
,
8761 OSPF_AREA_IS_STUB_ROUTED
);
8762 ospf_router_lsa_update_area(area
);
8765 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8769 DEFUN (ospf_max_metric_router_lsa_startup
,
8770 ospf_max_metric_router_lsa_startup_cmd
,
8771 "max-metric router-lsa on-startup (5-86400)",
8772 "OSPF maximum / infinite-distance metric\n"
8773 "Advertise own Router-LSA with infinite distance (stub router)\n"
8774 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8775 "Time (seconds) to advertise self as stub-router\n")
8777 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8779 unsigned int seconds
;
8782 vty_out(vty
, "%% Must supply stub-router period");
8783 return CMD_WARNING_CONFIG_FAILED
;
8786 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8788 ospf
->stub_router_startup_time
= seconds
;
8793 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8794 no_ospf_max_metric_router_lsa_startup_cmd
,
8795 "no max-metric router-lsa on-startup [(5-86400)]",
8797 "OSPF maximum / infinite-distance metric\n"
8798 "Advertise own Router-LSA with infinite distance (stub router)\n"
8799 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8800 "Time (seconds) to advertise self as stub-router\n")
8802 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8803 struct listnode
*ln
;
8804 struct ospf_area
*area
;
8806 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8808 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8809 SET_FLAG(area
->stub_router_state
,
8810 OSPF_AREA_WAS_START_STUB_ROUTED
);
8811 OSPF_TIMER_OFF(area
->t_stub_router
);
8813 /* Don't trample on admin stub routed */
8814 if (!CHECK_FLAG(area
->stub_router_state
,
8815 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8816 UNSET_FLAG(area
->stub_router_state
,
8817 OSPF_AREA_IS_STUB_ROUTED
);
8818 ospf_router_lsa_update_area(area
);
8825 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8826 ospf_max_metric_router_lsa_shutdown_cmd
,
8827 "max-metric router-lsa on-shutdown (5-100)",
8828 "OSPF maximum / infinite-distance metric\n"
8829 "Advertise own Router-LSA with infinite distance (stub router)\n"
8830 "Advertise stub-router prior to full shutdown of OSPF\n"
8831 "Time (seconds) to wait till full shutdown\n")
8833 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8835 unsigned int seconds
;
8838 vty_out(vty
, "%% Must supply stub-router shutdown period");
8839 return CMD_WARNING_CONFIG_FAILED
;
8842 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8844 ospf
->stub_router_shutdown_time
= seconds
;
8849 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8850 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8851 "no max-metric router-lsa on-shutdown [(5-100)]",
8853 "OSPF maximum / infinite-distance metric\n"
8854 "Advertise own Router-LSA with infinite distance (stub router)\n"
8855 "Advertise stub-router prior to full shutdown of OSPF\n"
8856 "Time (seconds) to wait till full shutdown\n")
8858 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8860 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8865 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8867 struct listnode
*ln
;
8868 struct ospf_area
*area
;
8870 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8871 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8872 ospf
->stub_router_startup_time
);
8873 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8874 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8875 ospf
->stub_router_shutdown_time
);
8876 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8877 if (CHECK_FLAG(area
->stub_router_state
,
8878 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8879 vty_out(vty
, " max-metric router-lsa administrative\n");
8886 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8887 struct route_table
*rt
,
8890 struct route_node
*rn
;
8891 struct ospf_route
* or ;
8892 struct listnode
*pnode
, *pnnode
;
8893 struct ospf_path
*path
;
8894 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8895 *json_nexthop
= NULL
;
8899 "============ OSPF network routing table ============\n");
8901 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8902 if ((or = rn
->info
) == NULL
)
8904 char buf1
[PREFIX2STR_BUFFER
];
8906 memset(buf1
, 0, sizeof(buf1
));
8907 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8909 json_route
= json_object_new_object();
8911 json_object_object_add(json
, buf1
, json_route
);
8912 json_object_to_json_string_ext(
8913 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8916 switch (or->path_type
) {
8917 case OSPF_PATH_INTER_AREA
:
8918 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8920 json_object_string_add(json_route
,
8923 json_object_int_add(json_route
, "cost",
8925 json_object_string_add(
8927 inet_ntoa(or->u
.std
.area_id
));
8930 "N IA %-18s [%d] area: %s\n",
8932 inet_ntoa(or->u
.std
.area_id
));
8934 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8936 json_object_string_add(json_route
,
8941 "D IA %-18s Discard entry\n",
8946 case OSPF_PATH_INTRA_AREA
:
8948 json_object_string_add(json_route
, "routeType",
8950 json_object_int_add(json_route
, "cost",
8952 json_object_string_add(
8954 inet_ntoa(or->u
.std
.area_id
));
8956 vty_out(vty
, "N %-18s [%d] area: %s\n",
8958 inet_ntoa(or->u
.std
.area_id
));
8965 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8967 json_nexthop_array
= json_object_new_array();
8968 json_object_object_add(json_route
, "nexthops",
8969 json_nexthop_array
);
8972 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8975 json_nexthop
= json_object_new_object();
8976 json_object_array_add(
8980 if (if_lookup_by_index(path
->ifindex
,
8983 if (path
->nexthop
.s_addr
== 0) {
8985 json_object_string_add(
8988 json_object_string_add(
8990 "directly attached to",
8996 "%24s directly attached to %s\n",
9004 json_object_string_add(
9009 json_object_string_add(
9017 "%24s via %s, %s\n",
9030 json_object_free(json_route
);
9036 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9037 struct route_table
*rtrs
,
9040 struct route_node
*rn
;
9041 struct ospf_route
* or ;
9042 struct listnode
*pnode
;
9043 struct listnode
*node
;
9044 struct ospf_path
*path
;
9045 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9046 *json_nexthop
= NULL
;
9050 "============ OSPF router routing table =============\n");
9052 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9053 if (rn
->info
== NULL
)
9057 json_route
= json_object_new_object();
9059 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9061 json_object_string_add(json_route
, "routeType", "R ");
9063 vty_out(vty
, "R %-15s ",
9064 inet_ntoa(rn
->p
.u
.prefix4
));
9067 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9070 vty_out(vty
, "%24s", "");
9075 json_object_int_add(json_route
, "cost",
9077 json_object_string_add(
9079 inet_ntoa(or->u
.std
.area_id
));
9080 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9081 json_object_boolean_true_add(json_route
,
9083 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9084 json_object_string_add(json_route
,
9087 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9088 json_object_string_add(json_route
,
9092 vty_out(vty
, "%s [%d] area: %s",
9093 (or->path_type
== OSPF_PATH_INTER_AREA
9096 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9098 vty_out(vty
, "%s%s\n",
9099 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9102 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9108 json_nexthop_array
= json_object_new_array();
9109 json_object_object_add(json_route
, "nexthops",
9110 json_nexthop_array
);
9113 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9115 json_nexthop
= json_object_new_object();
9116 json_object_array_add(
9120 if (if_lookup_by_index(path
->ifindex
,
9122 if (path
->nexthop
.s_addr
== 0) {
9124 json_object_string_add(
9127 json_object_string_add(
9129 "directly attached to",
9135 "%24s directly attached to %s\n",
9143 json_object_string_add(
9148 json_object_string_add(
9156 "%24s via %s, %s\n",
9169 json_object_free(json_route
);
9175 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9176 struct route_table
*rt
,
9179 struct route_node
*rn
;
9180 struct ospf_route
*er
;
9181 struct listnode
*pnode
, *pnnode
;
9182 struct ospf_path
*path
;
9183 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9184 *json_nexthop
= NULL
;
9188 "============ OSPF external routing table ===========\n");
9190 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9191 if ((er
= rn
->info
) == NULL
)
9196 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9198 json_route
= json_object_new_object();
9200 json_object_object_add(json
, buf1
, json_route
);
9201 json_object_to_json_string_ext(
9202 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9205 switch (er
->path_type
) {
9206 case OSPF_PATH_TYPE1_EXTERNAL
:
9208 json_object_string_add(json_route
, "routeType",
9210 json_object_int_add(json_route
, "cost",
9214 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9216 buf1
, er
->cost
, er
->u
.ext
.tag
);
9219 case OSPF_PATH_TYPE2_EXTERNAL
:
9221 json_object_string_add(json_route
, "routeType",
9223 json_object_int_add(json_route
, "cost",
9227 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9229 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9236 json_nexthop_array
= json_object_new_array();
9237 json_object_object_add(json_route
, "nexthops",
9238 json_nexthop_array
);
9241 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9243 json_nexthop
= json_object_new_object();
9244 json_object_array_add(json_nexthop_array
,
9248 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9249 if (path
->nexthop
.s_addr
== 0) {
9251 json_object_string_add(
9254 json_object_string_add(
9256 "directly attached to",
9262 "%24s directly attached to %s\n",
9270 json_object_string_add(
9274 json_object_string_add(
9275 json_nexthop
, "via",
9281 "%24s via %s, %s\n",
9293 json_object_free(json_route
);
9299 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9304 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9306 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9308 if (ospf
->new_table
== NULL
) {
9309 vty_out(vty
, "No OSPF routing information exist\n");
9313 /* Show Network routes.
9314 show_ip_ospf_route_network (vty, ospf->new_table); */
9316 /* Show Router routes. */
9317 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9324 DEFUN (show_ip_ospf_border_routers
,
9325 show_ip_ospf_border_routers_cmd
,
9326 "show ip ospf [vrf <NAME|all>] border-routers",
9329 "OSPF information\n"
9332 "Show all the ABR's and ASBR's\n")
9334 struct ospf
*ospf
= NULL
;
9335 struct listnode
*node
= NULL
;
9336 char *vrf_name
= NULL
;
9337 bool all_vrf
= FALSE
;
9338 int ret
= CMD_SUCCESS
;
9341 uint8_t use_vrf
= 0;
9343 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9346 bool ospf_output
= FALSE
;
9349 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9350 if (!ospf
->oi_running
)
9354 ret
= show_ip_ospf_border_routers_common(
9355 vty
, ospf
, use_vrf
);
9359 vty_out(vty
, "%% OSPF instance not found \n");
9361 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9362 if (ospf
== NULL
|| !ospf
->oi_running
) {
9363 vty_out(vty
, "%% OSPF instance not found \n");
9367 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9371 /* Display default ospf (instance 0) info */
9372 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9373 if (ospf
== NULL
|| !ospf
->oi_running
) {
9374 vty_out(vty
, "%% OSPF instance not found \n");
9378 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9384 DEFUN (show_ip_ospf_instance_border_routers
,
9385 show_ip_ospf_instance_border_routers_cmd
,
9386 "show ip ospf (1-65535) border-routers",
9389 "OSPF information\n"
9391 "Show all the ABR's and ASBR's\n")
9395 unsigned short instance
= 0;
9397 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9398 ospf
= ospf_lookup_instance(instance
);
9400 return CMD_NOT_MY_INSTANCE
;
9402 if (!ospf
->oi_running
)
9405 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9408 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9409 json_object
*json
, uint8_t use_vrf
)
9411 json_object
*json_vrf
= NULL
;
9414 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9419 json_vrf
= json_object_new_object();
9424 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9426 if (ospf
->new_table
== NULL
) {
9427 vty_out(vty
, "No OSPF routing information exist\n");
9431 /* Show Network routes. */
9432 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9434 /* Show Router routes. */
9435 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9437 /* Show AS External routes. */
9438 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9443 // json_object_object_add(json_vrf, "areas",
9445 if (ospf
->vrf_id
== VRF_DEFAULT
)
9446 json_object_object_add(json
, "default",
9449 json_object_object_add(json
, ospf
->name
,
9459 DEFUN (show_ip_ospf_route
,
9460 show_ip_ospf_route_cmd
,
9461 "show ip ospf [vrf <NAME|all>] route [json]",
9464 "OSPF information\n"
9467 "OSPF routing table\n"
9470 struct ospf
*ospf
= NULL
;
9471 struct listnode
*node
= NULL
;
9472 char *vrf_name
= NULL
;
9473 bool all_vrf
= FALSE
;
9474 int ret
= CMD_SUCCESS
;
9477 uint8_t use_vrf
= 0;
9478 bool uj
= use_json(argc
, argv
);
9479 json_object
*json
= NULL
;
9482 json
= json_object_new_object();
9484 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9486 /* vrf input is provided could be all or specific vrf*/
9488 bool ospf_output
= FALSE
;
9491 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9492 if (!ospf
->oi_running
)
9495 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9500 /* Keep Non-pretty format */
9501 vty_out(vty
, "%s\n",
9502 json_object_to_json_string(json
));
9503 json_object_free(json
);
9504 } else if (!ospf_output
)
9505 vty_out(vty
, "%% OSPF instance not found\n");
9509 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9510 if (ospf
== NULL
|| !ospf
->oi_running
) {
9512 vty_out(vty
, "%s\n",
9513 json_object_to_json_string_ext(
9514 json
, JSON_C_TO_STRING_PRETTY
));
9515 json_object_free(json
);
9517 vty_out(vty
, "%% OSPF instance not found \n");
9522 /* Display default ospf (instance 0) info */
9523 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9524 if (ospf
== NULL
|| !ospf
->oi_running
) {
9526 vty_out(vty
, "%s\n",
9527 json_object_to_json_string_ext(
9528 json
, JSON_C_TO_STRING_PRETTY
));
9529 json_object_free(json
);
9531 vty_out(vty
, "%% OSPF instance not found \n");
9538 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9539 /* Keep Non-pretty format */
9541 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9545 json_object_free(json
);
9550 DEFUN (show_ip_ospf_instance_route
,
9551 show_ip_ospf_instance_route_cmd
,
9552 "show ip ospf (1-65535) route",
9555 "OSPF information\n"
9557 "OSPF routing table\n")
9561 unsigned short instance
= 0;
9563 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9564 ospf
= ospf_lookup_instance(instance
);
9566 return CMD_NOT_MY_INSTANCE
;
9568 if (!ospf
->oi_running
)
9571 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9575 DEFUN (show_ip_ospf_vrfs
,
9576 show_ip_ospf_vrfs_cmd
,
9577 "show ip ospf vrfs [json]",
9580 "OSPF information\n"
9584 bool uj
= use_json(argc
, argv
);
9585 json_object
*json
= NULL
;
9586 json_object
*json_vrfs
= NULL
;
9587 struct ospf
*ospf
= NULL
;
9588 struct listnode
*node
= NULL
;
9590 static char header
[] = "Name Id RouterId ";
9593 json
= json_object_new_object();
9594 json_vrfs
= json_object_new_object();
9597 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9598 json_object
*json_vrf
= NULL
;
9599 const char *name
= NULL
;
9600 int64_t vrf_id_ui
= 0;
9604 if (!uj
&& count
== 1)
9605 vty_out(vty
, "%s\n", header
);
9607 json_vrf
= json_object_new_object();
9609 if (ospf
->vrf_id
== 0)
9610 name
= VRF_DEFAULT_NAME
;
9614 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9616 : (int64_t)ospf
->vrf_id
;
9619 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9620 json_object_string_add(json_vrf
, "routerId",
9621 inet_ntoa(ospf
->router_id
));
9623 json_object_object_add(json_vrfs
, name
, json_vrf
);
9626 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9627 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9632 json_object_object_add(json
, "vrfs", json_vrfs
);
9633 json_object_int_add(json
, "totalVrfs", count
);
9635 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9636 json
, JSON_C_TO_STRING_PRETTY
));
9637 json_object_free(json
);
9640 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9647 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9650 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9652 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9653 "point-to-point", "broadcast",
9654 "non-broadcast", "point-to-multipoint",
9655 "virtual-link", /* should never be used. */
9658 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9660 struct listnode
*node
;
9661 struct interface
*ifp
;
9662 struct crypt_key
*ck
;
9663 struct route_node
*rn
= NULL
;
9664 struct ospf_if_params
*params
;
9666 struct ospf
*ospf
= vrf
->info
;
9668 FOR_ALL_INTERFACES (vrf
, ifp
) {
9670 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9673 vty_frame(vty
, "!\n");
9674 if (ifp
->vrf_id
== VRF_DEFAULT
)
9675 vty_frame(vty
, "interface %s\n", ifp
->name
);
9677 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9680 vty_out(vty
, " description %s\n", ifp
->desc
);
9684 params
= IF_DEF_PARAMS(ifp
);
9687 /* Interface Network print. */
9688 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9689 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9690 if (params
->type
!= ospf_default_iftype(ifp
)) {
9691 vty_out(vty
, " ip ospf network %s",
9694 if (params
!= IF_DEF_PARAMS(ifp
))
9702 /* OSPF interface authentication print */
9703 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9704 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9705 const char *auth_str
;
9707 /* Translation tables are not that much help
9708 * here due to syntax
9709 * of the simple option */
9710 switch (params
->auth_type
) {
9712 case OSPF_AUTH_NULL
:
9716 case OSPF_AUTH_SIMPLE
:
9720 case OSPF_AUTH_CRYPTOGRAPHIC
:
9721 auth_str
= " message-digest";
9729 vty_out(vty
, " ip ospf authentication%s",
9731 if (params
!= IF_DEF_PARAMS(ifp
))
9733 inet_ntoa(rn
->p
.u
.prefix4
));
9737 /* Simple Authentication Password print. */
9738 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9739 && params
->auth_simple
[0] != '\0') {
9740 vty_out(vty
, " ip ospf authentication-key %s",
9741 params
->auth_simple
);
9742 if (params
!= IF_DEF_PARAMS(ifp
))
9744 inet_ntoa(rn
->p
.u
.prefix4
));
9748 /* Cryptographic Authentication Key print. */
9749 if (params
&& params
->auth_crypt
) {
9750 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9753 " ip ospf message-digest-key %d md5 %s",
9754 ck
->key_id
, ck
->auth_key
);
9755 if (params
!= IF_DEF_PARAMS(ifp
))
9763 /* Interface Output Cost print. */
9764 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9765 vty_out(vty
, " ip ospf cost %u",
9766 params
->output_cost_cmd
);
9767 if (params
!= IF_DEF_PARAMS(ifp
))
9769 inet_ntoa(rn
->p
.u
.prefix4
));
9773 /* Hello Interval print. */
9774 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9775 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9776 vty_out(vty
, " ip ospf hello-interval %u",
9778 if (params
!= IF_DEF_PARAMS(ifp
))
9780 inet_ntoa(rn
->p
.u
.prefix4
));
9785 /* Router Dead Interval print. */
9786 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9788 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9789 vty_out(vty
, " ip ospf dead-interval ");
9792 if (OSPF_IF_PARAM_CONFIGURED(params
,
9795 "minimal hello-multiplier %d",
9796 params
->fast_hello
);
9798 vty_out(vty
, "%u", params
->v_wait
);
9800 if (params
!= IF_DEF_PARAMS(ifp
))
9802 inet_ntoa(rn
->p
.u
.prefix4
));
9806 /* Router Priority print. */
9807 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9809 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9810 vty_out(vty
, " ip ospf priority %u",
9812 if (params
!= IF_DEF_PARAMS(ifp
))
9814 inet_ntoa(rn
->p
.u
.prefix4
));
9818 /* Retransmit Interval print. */
9819 if (OSPF_IF_PARAM_CONFIGURED(params
,
9820 retransmit_interval
)
9821 && params
->retransmit_interval
9822 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9823 vty_out(vty
, " ip ospf retransmit-interval %u",
9824 params
->retransmit_interval
);
9825 if (params
!= IF_DEF_PARAMS(ifp
))
9827 inet_ntoa(rn
->p
.u
.prefix4
));
9831 /* Transmit Delay print. */
9832 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9833 && params
->transmit_delay
9834 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9835 vty_out(vty
, " ip ospf transmit-delay %u",
9836 params
->transmit_delay
);
9837 if (params
!= IF_DEF_PARAMS(ifp
))
9839 inet_ntoa(rn
->p
.u
.prefix4
));
9844 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9845 if (ospf
&& ospf
->instance
)
9846 vty_out(vty
, " ip ospf %d",
9849 vty_out(vty
, " ip ospf");
9851 char buf
[INET_ADDRSTRLEN
];
9853 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9854 params
->if_area_id_fmt
);
9855 vty_out(vty
, " area %s", buf
);
9856 if (params
!= IF_DEF_PARAMS(ifp
))
9858 inet_ntoa(rn
->p
.u
.prefix4
));
9863 if (params
&& params
->bfd_info
)
9864 ospf_bfd_write_config(vty
, params
);
9866 /* MTU ignore print. */
9867 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9868 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9869 if (params
->mtu_ignore
== 0)
9870 vty_out(vty
, " no ip ospf mtu-ignore");
9872 vty_out(vty
, " ip ospf mtu-ignore");
9873 if (params
!= IF_DEF_PARAMS(ifp
))
9875 inet_ntoa(rn
->p
.u
.prefix4
));
9882 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9884 rn
= route_next(rn
);
9894 ospf_opaque_config_write_if(vty
, ifp
);
9896 vty_endframe(vty
, NULL
);
9902 /* Configuration write function for ospfd. */
9903 static int config_write_interface(struct vty
*vty
)
9906 struct vrf
*vrf
= NULL
;
9908 /* Display all VRF aware OSPF interface configuration */
9909 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9910 write
+= config_write_interface_one(vty
, vrf
);
9916 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9918 struct route_node
*rn
;
9919 uint8_t buf
[INET_ADDRSTRLEN
];
9921 /* `network area' print. */
9922 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9924 struct ospf_network
*n
= rn
->info
;
9926 /* Create Area ID string by specified Area ID format. */
9927 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9928 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9931 sprintf((char *)buf
, "%lu",
9932 (unsigned long int)ntohl(
9933 n
->area_id
.s_addr
));
9935 /* Network print. */
9936 vty_out(vty
, " network %s/%d area %s\n",
9937 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9944 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9946 struct listnode
*node
;
9947 struct ospf_area
*area
;
9948 uint8_t buf
[INET_ADDRSTRLEN
];
9950 /* Area configuration print. */
9951 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9952 struct route_node
*rn1
;
9954 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
9957 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9958 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9959 vty_out(vty
, " area %s authentication\n", buf
);
9962 " area %s authentication message-digest\n",
9966 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9967 vty_out(vty
, " area %s shortcut %s\n", buf
,
9968 ospf_shortcut_mode_str
9969 [area
->shortcut_configured
]);
9971 if ((area
->external_routing
== OSPF_AREA_STUB
)
9972 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9973 if (area
->external_routing
== OSPF_AREA_STUB
) {
9974 vty_out(vty
, " area %s stub", buf
);
9975 if (area
->no_summary
)
9976 vty_out(vty
, " no-summary\n");
9978 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9979 switch (area
->NSSATranslatorRole
) {
9980 case OSPF_NSSA_ROLE_NEVER
:
9982 " area %s nssa translate-never\n",
9985 case OSPF_NSSA_ROLE_ALWAYS
:
9987 " area %s nssa translate-always\n",
9990 case OSPF_NSSA_ROLE_CANDIDATE
:
9991 vty_out(vty
, " area %s nssa \n", buf
);
9994 if (area
->no_summary
)
9996 " area %s nssa no-summary\n",
10000 if (area
->default_cost
!= 1)
10001 vty_out(vty
, " area %s default-cost %d\n", buf
,
10002 area
->default_cost
);
10005 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10007 struct ospf_area_range
*range
= rn1
->info
;
10009 vty_out(vty
, " area %s range %s/%d", buf
,
10010 inet_ntoa(rn1
->p
.u
.prefix4
),
10013 if (range
->cost_config
10014 != OSPF_AREA_RANGE_COST_UNSPEC
)
10015 vty_out(vty
, " cost %d",
10016 range
->cost_config
);
10018 if (!CHECK_FLAG(range
->flags
,
10019 OSPF_AREA_RANGE_ADVERTISE
))
10020 vty_out(vty
, " not-advertise");
10022 if (CHECK_FLAG(range
->flags
,
10023 OSPF_AREA_RANGE_SUBSTITUTE
))
10024 vty_out(vty
, " substitute %s/%d",
10025 inet_ntoa(range
->subst_addr
),
10026 range
->subst_masklen
);
10028 vty_out(vty
, "\n");
10031 if (EXPORT_NAME(area
))
10032 vty_out(vty
, " area %s export-list %s\n", buf
,
10033 EXPORT_NAME(area
));
10035 if (IMPORT_NAME(area
))
10036 vty_out(vty
, " area %s import-list %s\n", buf
,
10037 IMPORT_NAME(area
));
10039 if (PREFIX_NAME_IN(area
))
10040 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10041 PREFIX_NAME_IN(area
));
10043 if (PREFIX_NAME_OUT(area
))
10044 vty_out(vty
, " area %s filter-list prefix %s out\n",
10045 buf
, PREFIX_NAME_OUT(area
));
10051 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10053 struct ospf_nbr_nbma
*nbr_nbma
;
10054 struct route_node
*rn
;
10056 /* Static Neighbor configuration print. */
10057 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10058 if ((nbr_nbma
= rn
->info
)) {
10059 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10061 if (nbr_nbma
->priority
10062 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10063 vty_out(vty
, " priority %d",
10064 nbr_nbma
->priority
);
10066 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10067 vty_out(vty
, " poll-interval %d",
10070 vty_out(vty
, "\n");
10076 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10078 struct listnode
*node
;
10079 struct ospf_vl_data
*vl_data
;
10080 char buf
[INET_ADDRSTRLEN
];
10082 /* Virtual-Link print */
10083 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10084 struct listnode
*n2
;
10085 struct crypt_key
*ck
;
10086 struct ospf_interface
*oi
;
10088 if (vl_data
!= NULL
) {
10089 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10090 vl_data
->vl_area_id_fmt
);
10091 oi
= vl_data
->vl_oi
;
10094 if (OSPF_IF_PARAM(oi
, v_hello
)
10095 != OSPF_HELLO_INTERVAL_DEFAULT
10096 || OSPF_IF_PARAM(oi
, v_wait
)
10097 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10098 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10099 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10100 || OSPF_IF_PARAM(oi
, transmit_delay
)
10101 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10103 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10104 buf
, inet_ntoa(vl_data
->vl_peer
),
10105 OSPF_IF_PARAM(oi
, v_hello
),
10106 OSPF_IF_PARAM(oi
, retransmit_interval
),
10107 OSPF_IF_PARAM(oi
, transmit_delay
),
10108 OSPF_IF_PARAM(oi
, v_wait
));
10110 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10111 inet_ntoa(vl_data
->vl_peer
));
10113 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10116 " area %s virtual-link %s authentication-key %s\n",
10117 buf
, inet_ntoa(vl_data
->vl_peer
),
10118 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10121 for (ALL_LIST_ELEMENTS_RO(
10122 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10126 " area %s virtual-link %s"
10127 " message-digest-key %d md5 %s\n",
10128 buf
, inet_ntoa(vl_data
->vl_peer
),
10129 ck
->key_id
, ck
->auth_key
);
10137 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10141 /* redistribute print. */
10142 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10143 struct list
*red_list
;
10144 struct listnode
*node
;
10145 struct ospf_redist
*red
;
10147 red_list
= ospf
->redist
[type
];
10151 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10152 vty_out(vty
, " redistribute %s",
10153 zebra_route_string(type
));
10155 vty_out(vty
, " %d", red
->instance
);
10157 if (red
->dmetric
.value
>= 0)
10158 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10160 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10161 vty_out(vty
, " metric-type 1");
10163 if (ROUTEMAP_NAME(red
))
10164 vty_out(vty
, " route-map %s",
10165 ROUTEMAP_NAME(red
));
10167 vty_out(vty
, "\n");
10174 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10176 if (ospf
->default_metric
!= -1)
10177 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10181 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10184 struct ospf_redist
*red
;
10187 /* distribute-list print. */
10188 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10189 if (DISTRIBUTE_NAME(ospf
, type
))
10190 vty_out(vty
, " distribute-list %s out %s\n",
10191 DISTRIBUTE_NAME(ospf
, type
),
10192 zebra_route_string(type
));
10194 /* default-information print. */
10195 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10196 vty_out(vty
, " default-information originate");
10197 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10198 vty_out(vty
, " always");
10200 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10202 if (red
->dmetric
.value
>= 0)
10203 vty_out(vty
, " metric %d",
10204 red
->dmetric
.value
);
10206 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10207 vty_out(vty
, " metric-type 1");
10209 if (ROUTEMAP_NAME(red
))
10210 vty_out(vty
, " route-map %s",
10211 ROUTEMAP_NAME(red
));
10214 vty_out(vty
, "\n");
10221 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10223 struct route_node
*rn
;
10224 struct ospf_distance
*odistance
;
10226 if (ospf
->distance_all
)
10227 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10229 if (ospf
->distance_intra
|| ospf
->distance_inter
10230 || ospf
->distance_external
) {
10231 vty_out(vty
, " distance ospf");
10233 if (ospf
->distance_intra
)
10234 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10235 if (ospf
->distance_inter
)
10236 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10237 if (ospf
->distance_external
)
10238 vty_out(vty
, " external %d", ospf
->distance_external
);
10240 vty_out(vty
, "\n");
10243 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10244 if ((odistance
= rn
->info
) != NULL
) {
10245 vty_out(vty
, " distance %d %s/%d %s\n",
10246 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10248 odistance
->access_list
? odistance
->access_list
10254 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10256 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10257 struct interface
*ifp
;
10258 struct ospf_interface
*oi
;
10259 struct listnode
*node
= NULL
;
10262 /* `router ospf' print. */
10263 if (ospf
->instance
&& ospf
->name
) {
10264 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10266 } else if (ospf
->instance
) {
10267 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10268 } else if (ospf
->name
) {
10269 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10271 vty_out(vty
, "router ospf\n");
10273 if (!ospf
->networks
) {
10278 /* Router ID print. */
10279 if (ospf
->router_id_static
.s_addr
!= 0)
10280 vty_out(vty
, " ospf router-id %s\n",
10281 inet_ntoa(ospf
->router_id_static
));
10283 /* ABR type print. */
10284 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10285 vty_out(vty
, " ospf abr-type %s\n",
10286 ospf_abr_type_str
[ospf
->abr_type
]);
10288 /* log-adjacency-changes flag print. */
10289 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10290 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10291 vty_out(vty
, " log-adjacency-changes detail\n");
10292 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10293 vty_out(vty
, " log-adjacency-changes\n");
10294 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10295 vty_out(vty
, " no log-adjacency-changes\n");
10298 /* RFC1583 compatibility flag print -- Compatible with CISCO
10300 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10301 vty_out(vty
, " compatible rfc1583\n");
10303 /* auto-cost reference-bandwidth configuration. */
10304 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10306 "! Important: ensure reference bandwidth "
10307 "is consistent across all routers\n");
10308 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10309 ospf
->ref_bandwidth
);
10312 /* SPF timers print. */
10313 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10314 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10315 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10316 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10317 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10319 /* LSA timers print. */
10320 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10321 vty_out(vty
, " timers throttle lsa all %d\n",
10322 ospf
->min_ls_interval
);
10323 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10324 vty_out(vty
, " timers lsa min-arrival %d\n",
10325 ospf
->min_ls_arrival
);
10327 /* Write multiplier print. */
10328 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10329 vty_out(vty
, " ospf write-multiplier %d\n",
10330 ospf
->write_oi_count
);
10332 /* Max-metric router-lsa print */
10333 config_write_stub_router(vty
, ospf
);
10335 /* SPF refresh parameters print. */
10336 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10337 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10339 /* Redistribute information print. */
10340 config_write_ospf_redistribute(vty
, ospf
);
10342 /* passive-interface print. */
10343 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10344 vty_out(vty
, " passive-interface default\n");
10346 FOR_ALL_INTERFACES (vrf
, ifp
)
10347 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10349 && IF_DEF_PARAMS(ifp
)->passive_interface
10350 != ospf
->passive_interface_default
) {
10351 vty_out(vty
, " %spassive-interface %s\n",
10352 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10356 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10357 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10359 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10360 passive_interface
)) {
10361 if (oi
->params
->passive_interface
10362 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10364 } else if (oi
->params
->passive_interface
10365 == ospf
->passive_interface_default
)
10368 vty_out(vty
, " %spassive-interface %s %s\n",
10369 oi
->params
->passive_interface
? "" : "no ",
10370 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10373 /* Network area print. */
10374 config_write_network_area(vty
, ospf
);
10376 /* Area config print. */
10377 config_write_ospf_area(vty
, ospf
);
10379 /* static neighbor print. */
10380 config_write_ospf_nbr_nbma(vty
, ospf
);
10382 /* Virtual-Link print. */
10383 config_write_virtual_link(vty
, ospf
);
10385 /* Default metric configuration. */
10386 config_write_ospf_default_metric(vty
, ospf
);
10388 /* Distribute-list and default-information print. */
10389 config_write_ospf_distribute(vty
, ospf
);
10391 /* Distance configuration. */
10392 config_write_ospf_distance(vty
, ospf
);
10394 ospf_opaque_config_write_router(vty
, ospf
);
10400 /* OSPF configuration write function. */
10401 static int ospf_config_write(struct vty
*vty
)
10404 struct listnode
*ospf_node
= NULL
;
10407 if (listcount(om
->ospf
) == 0)
10410 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10411 /* VRF Default check if it is running.
10412 * Upon daemon start, there could be default instance
10413 * in absence of 'router ospf'/oi_running is disabled. */
10414 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10415 write
+= ospf_config_write_one(vty
, ospf
);
10416 /* For Non-Default VRF simply display the configuration,
10417 * even if it is not oi_running. */
10418 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10419 write
+= ospf_config_write_one(vty
, ospf
);
10424 void ospf_vty_show_init(void)
10426 /* "show ip ospf" commands. */
10427 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10429 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10431 /* "show ip ospf database" commands. */
10432 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10434 install_element(VIEW_NODE
,
10435 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10436 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10437 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10439 /* "show ip ospf interface" commands. */
10440 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10442 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10443 /* "show ip ospf interface traffic */
10444 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10446 /* "show ip ospf neighbor" commands. */
10447 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10448 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10449 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10450 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10451 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10452 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10453 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10455 install_element(VIEW_NODE
,
10456 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10457 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10458 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10459 install_element(VIEW_NODE
,
10460 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10461 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10462 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10463 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10465 /* "show ip ospf route" commands. */
10466 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10467 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10469 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10470 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10472 /* "show ip ospf vrfs" commands. */
10473 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10477 /* ospfd's interface node. */
10478 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10480 /* Initialization of OSPF interface. */
10481 static void ospf_vty_if_init(void)
10483 /* Install interface node. */
10484 install_node(&interface_node
, config_write_interface
);
10487 /* "ip ospf authentication" commands. */
10488 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10489 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10490 install_element(INTERFACE_NODE
,
10491 &no_ip_ospf_authentication_args_addr_cmd
);
10492 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10493 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10494 install_element(INTERFACE_NODE
,
10495 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10496 install_element(INTERFACE_NODE
,
10497 &no_ospf_authentication_key_authkey_addr_cmd
);
10499 /* "ip ospf message-digest-key" commands. */
10500 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10501 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10503 /* "ip ospf cost" commands. */
10504 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10505 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10507 /* "ip ospf mtu-ignore" commands. */
10508 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10509 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10511 /* "ip ospf dead-interval" commands. */
10512 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10513 install_element(INTERFACE_NODE
,
10514 &ip_ospf_dead_interval_minimal_addr_cmd
);
10515 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10517 /* "ip ospf hello-interval" commands. */
10518 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10519 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10521 /* "ip ospf network" commands. */
10522 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10523 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10525 /* "ip ospf priority" commands. */
10526 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10527 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10529 /* "ip ospf retransmit-interval" commands. */
10530 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10531 install_element(INTERFACE_NODE
,
10532 &no_ip_ospf_retransmit_interval_addr_cmd
);
10534 /* "ip ospf transmit-delay" commands. */
10535 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10536 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10538 /* "ip ospf area" commands. */
10539 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10540 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10542 /* These commands are compatibitliy for previous version. */
10543 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10544 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10545 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10546 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10547 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10548 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10549 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10550 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10551 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10552 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10553 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10554 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10555 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10556 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10557 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10558 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10559 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10562 static void ospf_vty_zebra_init(void)
10564 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10565 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10566 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10567 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10569 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10570 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10572 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10573 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10575 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10576 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10578 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10579 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10580 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10581 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10583 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10584 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10585 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10586 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10590 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10592 static void ospf_interface_clear(struct interface
*ifp
)
10594 if (!if_is_operative(ifp
))
10597 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10598 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10600 ospf_if_reset(ifp
);
10603 DEFUN (clear_ip_ospf_interface
,
10604 clear_ip_ospf_interface_cmd
,
10605 "clear ip ospf interface [IFNAME]",
10608 "OSPF information\n"
10609 "Interface information\n"
10610 "Interface name\n")
10612 int idx_ifname
= 4;
10613 struct interface
*ifp
;
10614 struct listnode
*node
;
10615 struct ospf
*ospf
= NULL
;
10617 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10619 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10620 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10621 FOR_ALL_INTERFACES (vrf
, ifp
)
10622 ospf_interface_clear(ifp
);
10625 /* Interface name is specified. */
10626 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10628 vty_out(vty
, "No such interface name\n");
10630 ospf_interface_clear(ifp
);
10633 return CMD_SUCCESS
;
10636 void ospf_vty_clear_init(void)
10638 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10642 /* Install OSPF related vty commands. */
10643 void ospf_vty_init(void)
10645 /* Install ospf top node. */
10646 install_node(&ospf_node
, ospf_config_write
);
10648 /* "router ospf" commands. */
10649 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10650 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10653 install_default(OSPF_NODE
);
10655 /* "ospf router-id" commands. */
10656 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10657 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10658 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10660 /* "passive-interface" commands. */
10661 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10662 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10664 /* "ospf abr-type" commands. */
10665 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10666 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10668 /* "ospf log-adjacency-changes" commands. */
10669 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10670 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10671 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10672 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10674 /* "ospf rfc1583-compatible" commands. */
10675 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10676 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10677 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10678 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10680 /* "network area" commands. */
10681 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10682 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10684 /* "area authentication" commands. */
10685 install_element(OSPF_NODE
,
10686 &ospf_area_authentication_message_digest_cmd
);
10687 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10688 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10690 /* "area range" commands. */
10691 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10692 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10693 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10694 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10695 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10696 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10698 /* "area virtual-link" commands. */
10699 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10700 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10701 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10702 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10705 /* "area stub" commands. */
10706 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10707 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10708 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10709 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10711 /* "area nssa" commands. */
10712 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10713 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10714 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10715 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10716 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10718 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10719 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10721 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10722 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10724 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10725 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10727 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10728 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10730 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10731 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10733 /* SPF timer commands */
10734 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10735 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10737 /* LSA timers commands */
10738 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10739 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10740 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10741 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10743 /* refresh timer commands */
10744 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10745 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10747 /* max-metric commands */
10748 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10749 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10750 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10751 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10752 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10753 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10755 /* reference bandwidth commands */
10756 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10757 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10759 /* "neighbor" commands. */
10760 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10761 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10762 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10763 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10765 /* write multiplier commands */
10766 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10767 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10768 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10769 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10771 /* Init interface related vty commands. */
10772 ospf_vty_if_init();
10774 /* Init zebra related vty commands. */
10775 ospf_vty_zebra_init();