]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_vty.c
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / ospfd / ospf_vty.c
CommitLineData
718e3744 1/* OSPF VTY interface.
ba682537 2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
718e3744 3 * Copyright (C) 2000 Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
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
10 * later version.
11 *
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.
16 *
896014f4
DL
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
718e3744 20 */
21
22#include <zebra.h>
7ec4159b 23#include <string.h>
718e3744 24
cbf3e3eb 25#include "monotime.h"
718e3744 26#include "memory.h"
27#include "thread.h"
28#include "prefix.h"
29#include "table.h"
30#include "vty.h"
31#include "command.h"
32#include "plist.h"
33#include "log.h"
34#include "zclient.h"
bf2bfafd 35#include <lib/json.h>
8efe88ea 36#include "defaults.h"
718e3744 37
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"
7f342629 54#include "ospfd/ospf_bfd.h"
718e3744 55
30a2231a 56static const char *ospf_network_type_str[] =
718e3744 57{
58 "Null",
59 "POINTOPOINT",
60 "BROADCAST",
61 "NBMA",
62 "POINTOMULTIPOINT",
63 "VIRTUALLINK",
64 "LOOPBACK"
65};
66
718e3744 67/* Utility functions. */
16f1b9ee 68int
6c835671 69ospf_str2area_id (const char *str, struct in_addr *area_id, int *format)
718e3744 70{
71 char *endptr = NULL;
72 unsigned long ret;
73
74 /* match "A.B.C.D". */
75 if (strchr (str, '.') != NULL)
76 {
77 ret = inet_aton (str, area_id);
78 if (!ret)
79 return -1;
80 *format = OSPF_AREA_ID_FORMAT_ADDRESS;
81 }
82 /* match "<0-4294967295>". */
83 else
84 {
664711c1
UW
85 if (*str == '-')
86 return -1;
87 errno = 0;
718e3744 88 ret = strtoul (str, &endptr, 10);
664711c1 89 if (*endptr != '\0' || errno || ret > UINT32_MAX)
718e3744 90 return -1;
91
92 area_id->s_addr = htonl (ret);
93 *format = OSPF_AREA_ID_FORMAT_DECIMAL;
94 }
95
96 return 0;
97}
98
6b0655a2 99
4dadc291 100static int
6c835671 101str2metric (const char *str, int *metric)
718e3744 102{
103 /* Sanity check. */
104 if (str == NULL)
105 return 0;
106
107 *metric = strtol (str, NULL, 10);
108 if (*metric < 0 && *metric > 16777214)
109 {
110 /* vty_out (vty, "OSPF metric value is invalid%s", VTY_NEWLINE); */
111 return 0;
112 }
113
114 return 1;
115}
116
4dadc291 117static int
6c835671 118str2metric_type (const char *str, int *metric_type)
718e3744 119{
120 /* Sanity check. */
121 if (str == NULL)
122 return 0;
123
124 if (strncmp (str, "1", 1) == 0)
125 *metric_type = EXTERNAL_METRIC_TYPE_1;
126 else if (strncmp (str, "2", 1) == 0)
127 *metric_type = EXTERNAL_METRIC_TYPE_2;
128 else
129 return 0;
130
131 return 1;
132}
133
134int
135ospf_oi_count (struct interface *ifp)
136{
137 struct route_node *rn;
138 int i = 0;
139
140 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
141 if (rn->info)
142 i++;
143
144 return i;
145}
146
505e5056 147DEFUN_NOSH (router_ospf,
718e3744 148 router_ospf_cmd,
7a7be519 149 "router ospf [(1-65535)]",
718e3744 150 "Enable a routing process\n"
7a7be519 151 "Start OSPF configuration\n"
152 "Instance ID\n")
718e3744 153{
7c8ff89e
DS
154 struct ospf *ospf;
155 u_short instance = 0;
156
157 ospf = ospf_lookup();
158 if (!ospf)
159 {
160 vty_out (vty, "There isn't active ospf instance %s", VTY_NEWLINE);
161 return CMD_WARNING;
162 }
163
7a7be519 164 if (argc > 2)
165 VTY_GET_INTEGER ("Instance", instance, argv[2]->arg);
7c8ff89e 166
52c6b0e2 167 /* The following logic to set the vty qobj index is in place to be able
7c8ff89e
DS
168 to ignore the commands which dont belong to this instance. */
169 if (ospf->instance != instance)
cdc2d765 170 VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
7c8ff89e 171 else
0bad4851
DS
172 {
173 if (IS_DEBUG_OSPF_EVENT)
174 zlog_debug ("Config command 'router ospf %d' received", instance);
175 ospf->oi_running = 1;
52c6b0e2 176 VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
0bad4851
DS
177 ospf_router_id_update (ospf);
178 }
718e3744 179
180 return CMD_SUCCESS;
181}
182
183DEFUN (no_router_ospf,
184 no_router_ospf_cmd,
7a7be519 185 "no router ospf [(1-65535)]",
718e3744 186 NO_STR
187 "Enable a routing process\n"
7a7be519 188 "Start OSPF configuration\n"
189 "Instance ID\n")
718e3744 190{
020709f9 191 struct ospf *ospf;
7c8ff89e 192 u_short instance = 0;
020709f9 193
7a7be519 194 if (argc > 3)
bf2bfafd 195 VTY_GET_INTEGER ("Instance", instance, argv[3]->arg);
7c8ff89e
DS
196
197 if ((ospf = ospf_lookup_instance (instance)) == NULL)
198 return CMD_SUCCESS;
718e3744 199
020709f9 200 ospf_finish (ospf);
718e3744 201
202 return CMD_SUCCESS;
203}
204
7c8ff89e 205
718e3744 206DEFUN (ospf_router_id,
207 ospf_router_id_cmd,
208 "ospf router-id A.B.C.D",
209 "OSPF specific commands\n"
210 "router-id for the OSPF process\n"
211 "OSPF router-id in IP address format\n")
212{
cdc2d765 213 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 214 int idx_ipv4 = 2;
2c19a6ec
DS
215 struct listnode *node;
216 struct ospf_area *area;
718e3744 217 struct in_addr router_id;
68980084 218 int ret;
718e3744 219
8d769265 220 ret = inet_aton (argv[idx_ipv4]->arg, &router_id);
718e3744 221 if (!ret)
222 {
223 vty_out (vty, "Please specify Router ID by A.B.C.D%s", VTY_NEWLINE);
224 return CMD_WARNING;
225 }
226
68980084 227 ospf->router_id_static = router_id;
2c19a6ec
DS
228
229 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
230 if (area->full_nbrs)
231 {
232 vty_out (vty, "For this router-id change to take effect,"
233 " save config and restart ospfd%s", VTY_NEWLINE);
234 return CMD_SUCCESS;
235 }
236
b29800a6 237 ospf_router_id_update (ospf);
238
718e3744 239 return CMD_SUCCESS;
240}
241
7a7be519 242DEFUN_HIDDEN (ospf_router_id_old,
747e489c
DW
243 ospf_router_id_old_cmd,
244 "router-id A.B.C.D",
245 "router-id for the OSPF process\n"
246 "OSPF router-id in IP address format\n")
7a7be519 247{
cdc2d765 248 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 249 int idx_ipv4 = 1;
7a7be519 250 struct listnode *node;
251 struct ospf_area *area;
252 struct in_addr router_id;
253 int ret;
254
7a7be519 255 ret = inet_aton (argv[idx_ipv4]->arg, &router_id);
256 if (!ret)
257 {
258 vty_out (vty, "Please specify Router ID by A.B.C.D%s", VTY_NEWLINE);
259 return CMD_WARNING;
260 }
261
262 ospf->router_id_static = router_id;
263
264 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
265 if (area->full_nbrs)
266 {
267 vty_out (vty, "For this router-id change to take effect,"
268 " save config and restart ospfd%s", VTY_NEWLINE);
269 return CMD_SUCCESS;
270 }
271
272 ospf_router_id_update (ospf);
273
274 return CMD_SUCCESS;
275}
747e489c 276
718e3744 277DEFUN (no_ospf_router_id,
278 no_ospf_router_id_cmd,
7a7be519 279 "no ospf router-id [A.B.C.D]",
718e3744 280 NO_STR
281 "OSPF specific commands\n"
7a7be519 282 "router-id for the OSPF process\n"
283 "OSPF router-id in IP address format\n")
718e3744 284{
cdc2d765 285 VTY_DECLVAR_CONTEXT(ospf, ospf);
2c19a6ec
DS
286 struct listnode *node;
287 struct ospf_area *area;
68980084 288
289 ospf->router_id_static.s_addr = 0;
718e3744 290
2c19a6ec
DS
291 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
292 if (area->full_nbrs)
293 {
294 vty_out (vty, "For this router-id change to take effect,"
295 " save config and restart ospfd%s", VTY_NEWLINE);
296 return CMD_SUCCESS;
297 }
298
68980084 299 ospf_router_id_update (ospf);
718e3744 300
301 return CMD_SUCCESS;
302}
303
718e3744 304
7ffa8fa2 305static void
43540886 306ospf_passive_interface_default (struct ospf *ospf, u_char newval)
7ffa8fa2
PJ
307{
308 struct listnode *ln;
309 struct interface *ifp;
310 struct ospf_interface *oi;
311
43540886
AS
312 ospf->passive_interface_default = newval;
313
7ffa8fa2
PJ
314 for (ALL_LIST_ELEMENTS_RO (om->iflist, ln, ifp))
315 {
316 if (ifp &&
317 OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), passive_interface))
318 UNSET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface);
319 }
320 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, ln, oi))
321 {
322 if (OSPF_IF_PARAM_CONFIGURED (oi->params, passive_interface))
323 UNSET_IF_PARAM (oi->params, passive_interface);
43540886
AS
324 /* update multicast memberships */
325 ospf_if_set_multicast(oi);
7ffa8fa2
PJ
326 }
327}
328
329static void
f842f166
PJ
330ospf_passive_interface_update_addr (struct ospf *ospf, struct interface *ifp,
331 struct ospf_if_params *params, u_char value,
332 struct in_addr addr)
7ffa8fa2
PJ
333{
334 u_char dflt;
335
336 params->passive_interface = value;
337 if (params != IF_DEF_PARAMS (ifp))
338 {
339 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), passive_interface))
340 dflt = IF_DEF_PARAMS (ifp)->passive_interface;
341 else
342 dflt = ospf->passive_interface_default;
343
344 if (value != dflt)
345 SET_IF_PARAM (params, passive_interface);
346 else
347 UNSET_IF_PARAM (params, passive_interface);
348
349 ospf_free_if_params (ifp, addr);
350 ospf_if_update_params (ifp, addr);
351 }
f842f166
PJ
352}
353
354static void
355ospf_passive_interface_update (struct ospf *ospf, struct interface *ifp,
356 struct ospf_if_params *params, u_char value)
357{
358 params->passive_interface = value;
359 if (params == IF_DEF_PARAMS (ifp))
7ffa8fa2
PJ
360 {
361 if (value != ospf->passive_interface_default)
362 SET_IF_PARAM (params, passive_interface);
363 else
364 UNSET_IF_PARAM (params, passive_interface);
365 }
366}
367
a2c62831 368DEFUN (ospf_passive_interface,
369 ospf_passive_interface_addr_cmd,
7a7be519 370 "passive-interface <IFNAME [A.B.C.D]|default>",
718e3744 371 "Suppress routing updates on an interface\n"
7a7be519 372 "Interface's name\n"
3a2d747c 373 "IPv4 address\n"
7a7be519 374 "Suppress routing updates on interfaces by default\n")
718e3744 375{
cdc2d765 376 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 377 int idx_ipv4 = 2;
7ffa8fa2 378 struct interface *ifp;
cb2af5d0 379 struct in_addr addr = { .s_addr = INADDR_ANY };
7ffa8fa2
PJ
380 int ret;
381 struct ospf_if_params *params;
382 struct route_node *rn;
718e3744 383
7a7be519 384 if (strcmp (argv[1]->text, "default") == 0)
43540886
AS
385 {
386 ospf_passive_interface_default (ospf, OSPF_IF_PASSIVE);
387 return CMD_SUCCESS;
388 }
389
92a57eb2 390 ifp = if_get_by_name (argv[1]->arg, VRF_DEFAULT);
718e3744 391
392 params = IF_DEF_PARAMS (ifp);
393
7a7be519 394 if (argc == 3)
718e3744 395 {
7a7be519 396 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
43540886
AS
397 if (!ret)
398 {
399 vty_out (vty, "Please specify interface address by A.B.C.D%s",
400 VTY_NEWLINE);
401 return CMD_WARNING;
402 }
403
404 params = ospf_get_if_params (ifp, addr);
405 ospf_if_update_params (ifp, addr);
f842f166
PJ
406 ospf_passive_interface_update_addr (ospf, ifp, params,
407 OSPF_IF_PASSIVE, addr);
7ffa8fa2 408 }
f842f166
PJ
409
410 ospf_passive_interface_update (ospf, ifp, params, OSPF_IF_PASSIVE);
43540886 411
ba6454ec 412 /* XXX We should call ospf_if_set_multicast on exactly those
413 * interfaces for which the passive property changed. It is too much
414 * work to determine this set, so we do this for every interface.
415 * This is safe and reasonable because ospf_if_set_multicast uses a
416 * record of joined groups to avoid systems calls if the desired
417 * memberships match the current memership.
418 */
7ffa8fa2 419
ba6454ec 420 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next (rn))
421 {
422 struct ospf_interface *oi = rn->info;
423
424 if (oi && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_PASSIVE))
43540886 425 ospf_if_set_multicast(oi);
ba6454ec 426 }
427 /*
428 * XXX It is not clear what state transitions the interface needs to
429 * undergo when going from active to passive. Fixing this will
430 * require precise identification of interfaces having such a
431 * transition.
432 */
433
718e3744 434 return CMD_SUCCESS;
435}
436
a2c62831 437DEFUN (no_ospf_passive_interface,
438 no_ospf_passive_interface_addr_cmd,
7a7be519 439 "no passive-interface <IFNAME [A.B.C.D]|default>",
718e3744 440 NO_STR
441 "Allow routing updates on an interface\n"
7a7be519 442 "Interface's name\n"
3a2d747c 443 "IPv4 address\n"
7a7be519 444 "Allow routing updates on interfaces by default\n")
718e3744 445{
cdc2d765 446 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 447 int idx_ipv4 = 3;
718e3744 448 struct interface *ifp;
cb2af5d0 449 struct in_addr addr = { .s_addr = INADDR_ANY };
718e3744 450 struct ospf_if_params *params;
451 int ret;
ba6454ec 452 struct route_node *rn;
43540886 453
7a7be519 454 if (strcmp (argv[2]->text, "default") == 0)
43540886
AS
455 {
456 ospf_passive_interface_default (ospf, OSPF_IF_ACTIVE);
457 return CMD_SUCCESS;
458 }
718e3744 459
92a57eb2 460 ifp = if_get_by_name (argv[2]->arg, VRF_DEFAULT);
718e3744 461
462 params = IF_DEF_PARAMS (ifp);
463
7a7be519 464 if (argc == 4)
718e3744 465 {
7a7be519 466 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
43540886
AS
467 if (!ret)
468 {
469 vty_out (vty, "Please specify interface address by A.B.C.D%s",
470 VTY_NEWLINE);
471 return CMD_WARNING;
472 }
473
474 params = ospf_lookup_if_params (ifp, addr);
475 if (params == NULL)
476 return CMD_SUCCESS;
f842f166
PJ
477 ospf_passive_interface_update_addr (ospf, ifp, params, OSPF_IF_ACTIVE,
478 addr);
718e3744 479 }
f842f166
PJ
480 ospf_passive_interface_update (ospf, ifp, params, OSPF_IF_ACTIVE);
481
ba6454ec 482 /* XXX We should call ospf_if_set_multicast on exactly those
483 * interfaces for which the passive property changed. It is too much
484 * work to determine this set, so we do this for every interface.
485 * This is safe and reasonable because ospf_if_set_multicast uses a
486 * record of joined groups to avoid systems calls if the desired
487 * memberships match the current memership.
488 */
489 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next (rn))
490 {
491 struct ospf_interface *oi = rn->info;
492
493 if (oi && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
494 ospf_if_set_multicast(oi);
495 }
496
718e3744 497 return CMD_SUCCESS;
498}
499
718e3744 500
7ffa8fa2 501
a2c62831 502DEFUN (ospf_network_area,
503 ospf_network_area_cmd,
6147e2c6 504 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
718e3744 505 "Enable routing on an IP network\n"
506 "OSPF network prefix\n"
507 "Set the OSPF area ID\n"
508 "OSPF area ID in IP address format\n"
509 "OSPF area ID as a decimal value\n")
510{
cdc2d765 511 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
512 int idx_ipv4_prefixlen = 1;
513 int idx_ipv4_number = 3;
718e3744 514 struct prefix_ipv4 p;
515 struct in_addr area_id;
516 int ret, format;
517
7c8ff89e
DS
518 if (ospf->instance)
519 {
520 vty_out (vty, "The network command is not supported in multi-instance ospf%s",
521 VTY_NEWLINE);
522 return CMD_WARNING;
523 }
524
953cde65
JT
525 if (ospf->if_ospf_cli_count > 0)
526 {
527 vty_out (vty, "Please remove all ip ospf area x.x.x.x commands first.%s",
528 VTY_NEWLINE);
529 return CMD_WARNING;
530 }
531
718e3744 532 /* Get network prefix and Area ID. */
8d769265
DW
533 VTY_GET_IPV4_PREFIX ("network prefix", p, argv[idx_ipv4_prefixlen]->arg);
534 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
718e3744 535
536 ret = ospf_network_set (ospf, &p, area_id);
537 if (ret == 0)
538 {
539 vty_out (vty, "There is already same network statement.%s", VTY_NEWLINE);
540 return CMD_WARNING;
541 }
542
543 return CMD_SUCCESS;
544}
545
a2c62831 546DEFUN (no_ospf_network_area,
547 no_ospf_network_area_cmd,
6147e2c6 548 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
718e3744 549 NO_STR
550 "Enable routing on an IP network\n"
551 "OSPF network prefix\n"
552 "Set the OSPF area ID\n"
553 "OSPF area ID in IP address format\n"
554 "OSPF area ID as a decimal value\n")
555{
cdc2d765 556 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
557 int idx_ipv4_prefixlen = 2;
558 int idx_ipv4_number = 4;
718e3744 559 struct prefix_ipv4 p;
560 struct in_addr area_id;
561 int ret, format;
562
7c8ff89e
DS
563 if (ospf->instance)
564 {
565 vty_out (vty, "The network command is not supported in multi-instance ospf%s",
566 VTY_NEWLINE);
567 return CMD_WARNING;
568 }
569
718e3744 570 /* Get network prefix and Area ID. */
8d769265
DW
571 VTY_GET_IPV4_PREFIX ("network prefix", p, argv[idx_ipv4_prefixlen]->arg);
572 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
718e3744 573
574 ret = ospf_network_unset (ospf, &p, area_id);
575 if (ret == 0)
576 {
577 vty_out (vty, "Can't find specified network area configuration.%s",
578 VTY_NEWLINE);
579 return CMD_WARNING;
580 }
581
582 return CMD_SUCCESS;
583}
584
a2c62831 585DEFUN (ospf_area_range,
586 ospf_area_range_cmd,
7a7be519 587 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
718e3744 588 "OSPF area parameters\n"
589 "OSPF area ID in IP address format\n"
590 "OSPF area ID as a decimal value\n"
591 "Summarize routes matching address/mask (border routers only)\n"
7a7be519 592 "Area range prefix\n"
593 "Advertise this range (default)\n"
594 "User specified metric for this range\n"
595 "Advertised metric for this range\n")
718e3744 596{
cdc2d765 597 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
598 int idx_ipv4_number = 1;
599 int idx_ipv4_prefixlen = 3;
7a7be519 600 int idx_cost = 6;
718e3744 601 struct prefix_ipv4 p;
602 struct in_addr area_id;
603 int format;
604 u_int32_t cost;
605
8d769265
DW
606 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
607 VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
718e3744 608
609 ospf_area_range_set (ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
7a7be519 610 if (argc > 5)
718e3744 611 {
7a7be519 612 VTY_GET_INTEGER ("range cost", cost, argv[idx_cost]->arg);
718e3744 613 ospf_area_range_cost_set (ospf, area_id, &p, cost);
614 }
615
616 return CMD_SUCCESS;
617}
618
7a7be519 619DEFUN (ospf_area_range_cost,
620 ospf_area_range_cost_cmd,
621 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
622 "OSPF area parameters\n"
623 "OSPF area ID in IP address format\n"
624 "OSPF area ID as a decimal value\n"
625 "Summarize routes matching address/mask (border routers only)\n"
626 "Area range prefix\n"
627 "User specified metric for this range\n"
628 "Advertised metric for this range\n")
629{
cdc2d765 630 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 631 int idx_ipv4_number = 1;
632 int idx_ipv4_prefixlen = 3;
633 int idx_cost = 5;
7a7be519 634 struct prefix_ipv4 p;
635 struct in_addr area_id;
636 int format;
637 u_int32_t cost;
638
7a7be519 639 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
640 VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
641
642 ospf_area_range_set (ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
718e3744 643
7a7be519 644 VTY_GET_INTEGER ("range cost", cost, argv[idx_cost]->arg);
645 ospf_area_range_cost_set (ospf, area_id, &p, cost);
718e3744 646
7a7be519 647 return CMD_SUCCESS;
648}
718e3744 649
a2c62831 650DEFUN (ospf_area_range_not_advertise,
651 ospf_area_range_not_advertise_cmd,
6147e2c6 652 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
718e3744 653 "OSPF area parameters\n"
654 "OSPF area ID in IP address format\n"
655 "OSPF area ID as a decimal value\n"
656 "Summarize routes matching address/mask (border routers only)\n"
657 "Area range prefix\n"
658 "DoNotAdvertise this range\n")
659{
cdc2d765 660 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
661 int idx_ipv4_number = 1;
662 int idx_ipv4_prefixlen = 3;
718e3744 663 struct prefix_ipv4 p;
664 struct in_addr area_id;
665 int format;
666
8d769265
DW
667 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
668 VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
718e3744 669
670 ospf_area_range_set (ospf, area_id, &p, 0);
671
672 return CMD_SUCCESS;
673}
674
a2c62831 675DEFUN (no_ospf_area_range,
676 no_ospf_area_range_cmd,
3a2d747c 677 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
718e3744 678 NO_STR
679 "OSPF area parameters\n"
680 "OSPF area ID in IP address format\n"
681 "OSPF area ID as a decimal value\n"
682 "Summarize routes matching address/mask (border routers only)\n"
7a7be519 683 "Area range prefix\n"
3a2d747c
QY
684 "User specified metric for this range\n"
685 "Advertised metric for this range\n"
7a7be519 686 "Advertise this range (default)\n"
3a2d747c
QY
687 "User specified metric for this range\n"
688 "Advertised metric for this range\n"
7a7be519 689 "DoNotAdvertise this range\n")
718e3744 690{
cdc2d765 691 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
692 int idx_ipv4_number = 2;
693 int idx_ipv4_prefixlen = 4;
718e3744 694 struct prefix_ipv4 p;
695 struct in_addr area_id;
696 int format;
697
8d769265
DW
698 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
699 VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
718e3744 700
701 ospf_area_range_unset (ospf, area_id, &p);
702
703 return CMD_SUCCESS;
704}
705
a2c62831 706DEFUN (ospf_area_range_substitute,
707 ospf_area_range_substitute_cmd,
6147e2c6 708 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
718e3744 709 "OSPF area parameters\n"
710 "OSPF area ID in IP address format\n"
711 "OSPF area ID as a decimal value\n"
712 "Summarize routes matching address/mask (border routers only)\n"
713 "Area range prefix\n"
714 "Announce area range as another prefix\n"
715 "Network prefix to be announced instead of range\n")
716{
cdc2d765 717 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
718 int idx_ipv4_number = 1;
719 int idx_ipv4_prefixlen = 3;
720 int idx_ipv4_prefixlen_2 = 5;
718e3744 721 struct prefix_ipv4 p, s;
722 struct in_addr area_id;
723 int format;
724
8d769265
DW
725 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
726 VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
727 VTY_GET_IPV4_PREFIX ("substituted network prefix", s, argv[idx_ipv4_prefixlen_2]->arg);
718e3744 728
729 ospf_area_range_substitute_set (ospf, area_id, &p, &s);
730
731 return CMD_SUCCESS;
732}
733
a2c62831 734DEFUN (no_ospf_area_range_substitute,
735 no_ospf_area_range_substitute_cmd,
6147e2c6 736 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
718e3744 737 NO_STR
738 "OSPF area parameters\n"
739 "OSPF area ID in IP address format\n"
740 "OSPF area ID as a decimal value\n"
741 "Summarize routes matching address/mask (border routers only)\n"
742 "Area range prefix\n"
743 "Announce area range as another prefix\n"
744 "Network prefix to be announced instead of range\n")
745{
cdc2d765 746 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
747 int idx_ipv4_number = 2;
748 int idx_ipv4_prefixlen = 4;
749 int idx_ipv4_prefixlen_2 = 6;
718e3744 750 struct prefix_ipv4 p, s;
751 struct in_addr area_id;
752 int format;
753
8d769265
DW
754 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
755 VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
756 VTY_GET_IPV4_PREFIX ("substituted network prefix", s, argv[idx_ipv4_prefixlen_2]->arg);
718e3744 757
758 ospf_area_range_substitute_unset (ospf, area_id, &p);
759
760 return CMD_SUCCESS;
761}
762
6b0655a2 763
718e3744 764/* Command Handler Logic in VLink stuff is delicate!!
765
766 ALTER AT YOUR OWN RISK!!!!
767
768 Various dummy values are used to represent 'NoChange' state for
769 VLink configuration NOT being changed by a VLink command, and
770 special syntax is used within the command strings so that the
771 typed in command verbs can be seen in the configuration command
772 bacckend handler. This is to drastically reduce the verbeage
773 required to coe up with a reasonably compatible Cisco VLink command
774
775 - Matthew Grant <grantma@anathoth.gen.nz>
776 Wed, 21 Feb 2001 15:13:52 +1300
777 */
778
718e3744 779/* Configuration data for virtual links
780 */
781struct ospf_vl_config_data {
782 struct vty *vty; /* vty stuff */
783 struct in_addr area_id; /* area ID from command line */
784 int format; /* command line area ID format */
785 struct in_addr vl_peer; /* command line vl_peer */
786 int auth_type; /* Authehntication type, if given */
787 char *auth_key; /* simple password if present */
788 int crypto_key_id; /* Cryptographic key ID */
789 char *md5_key; /* MD5 authentication key */
790 int hello_interval; /* Obvious what these are... */
791 int retransmit_interval;
792 int transmit_delay;
793 int dead_interval;
794};
795
4dadc291 796static void
718e3744 797ospf_vl_config_data_init (struct ospf_vl_config_data *vl_config,
798 struct vty *vty)
799{
800 memset (vl_config, 0, sizeof (struct ospf_vl_config_data));
801 vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN;
802 vl_config->vty = vty;
803}
804
4dadc291 805static struct ospf_vl_data *
68980084 806ospf_find_vl_data (struct ospf *ospf, struct ospf_vl_config_data *vl_config)
718e3744 807{
808 struct ospf_area *area;
809 struct ospf_vl_data *vl_data;
810 struct vty *vty;
811 struct in_addr area_id;
812
813 vty = vl_config->vty;
814 area_id = vl_config->area_id;
815
816 if (area_id.s_addr == OSPF_AREA_BACKBONE)
817 {
818 vty_out (vty,
819 "Configuring VLs over the backbone is not allowed%s",
820 VTY_NEWLINE);
821 return NULL;
822 }
68980084 823 area = ospf_area_get (ospf, area_id, vl_config->format);
718e3744 824
825 if (area->external_routing != OSPF_AREA_DEFAULT)
826 {
827 if (vl_config->format == OSPF_AREA_ID_FORMAT_ADDRESS)
828 vty_out (vty, "Area %s is %s%s",
829 inet_ntoa (area_id),
718e3744 830 area->external_routing == OSPF_AREA_NSSA?"nssa":"stub",
718e3744 831 VTY_NEWLINE);
832 else
833 vty_out (vty, "Area %ld is %s%s",
834 (u_long)ntohl (area_id.s_addr),
718e3744 835 area->external_routing == OSPF_AREA_NSSA?"nssa":"stub",
718e3744 836 VTY_NEWLINE);
837 return NULL;
838 }
839
9c27ef9b 840 if ((vl_data = ospf_vl_lookup (ospf, area, vl_config->vl_peer)) == NULL)
718e3744 841 {
842 vl_data = ospf_vl_data_new (area, vl_config->vl_peer);
843 if (vl_data->vl_oi == NULL)
844 {
68980084 845 vl_data->vl_oi = ospf_vl_new (ospf, vl_data);
846 ospf_vl_add (ospf, vl_data);
d3a9c768 847 ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
718e3744 848 }
849 }
850 return vl_data;
851}
852
853
4dadc291 854static int
718e3744 855ospf_vl_set_security (struct ospf_vl_data *vl_data,
856 struct ospf_vl_config_data *vl_config)
857{
858 struct crypt_key *ck;
859 struct vty *vty;
860 struct interface *ifp = vl_data->vl_oi->ifp;
861
862 vty = vl_config->vty;
863
864 if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN)
865 {
866 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
867 IF_DEF_PARAMS (ifp)->auth_type = vl_config->auth_type;
868 }
869
870 if (vl_config->auth_key)
871 {
872 memset(IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE+1);
c9e52be3 873 strncpy ((char *) IF_DEF_PARAMS (ifp)->auth_simple, vl_config->auth_key,
718e3744 874 OSPF_AUTH_SIMPLE_SIZE);
875 }
876 else if (vl_config->md5_key)
877 {
878 if (ospf_crypt_key_lookup (IF_DEF_PARAMS (ifp)->auth_crypt, vl_config->crypto_key_id)
879 != NULL)
880 {
881 vty_out (vty, "OSPF: Key %d already exists%s",
882 vl_config->crypto_key_id, VTY_NEWLINE);
883 return CMD_WARNING;
884 }
885 ck = ospf_crypt_key_new ();
886 ck->key_id = vl_config->crypto_key_id;
887 memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE+1);
c9e52be3 888 strncpy ((char *) ck->auth_key, vl_config->md5_key, OSPF_AUTH_MD5_SIZE);
718e3744 889
890 ospf_crypt_key_add (IF_DEF_PARAMS (ifp)->auth_crypt, ck);
891 }
892 else if (vl_config->crypto_key_id != 0)
893 {
894 /* Delete a key */
895
896 if (ospf_crypt_key_lookup (IF_DEF_PARAMS (ifp)->auth_crypt,
897 vl_config->crypto_key_id) == NULL)
898 {
899 vty_out (vty, "OSPF: Key %d does not exist%s",
900 vl_config->crypto_key_id, VTY_NEWLINE);
901 return CMD_WARNING;
902 }
903
904 ospf_crypt_key_delete (IF_DEF_PARAMS (ifp)->auth_crypt, vl_config->crypto_key_id);
905
906 }
907
908 return CMD_SUCCESS;
909}
910
4dadc291 911static int
718e3744 912ospf_vl_set_timers (struct ospf_vl_data *vl_data,
913 struct ospf_vl_config_data *vl_config)
914{
c8cdf5c7 915 struct interface *ifp = vl_data->vl_oi->ifp;
718e3744 916 /* Virtual Link data initialised to defaults, so only set
917 if a value given */
918 if (vl_config->hello_interval)
919 {
920 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
921 IF_DEF_PARAMS (ifp)->v_hello = vl_config->hello_interval;
922 }
923
924 if (vl_config->dead_interval)
925 {
926 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
927 IF_DEF_PARAMS (ifp)->v_wait = vl_config->dead_interval;
928 }
929
930 if (vl_config->retransmit_interval)
931 {
932 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
933 IF_DEF_PARAMS (ifp)->retransmit_interval = vl_config->retransmit_interval;
934 }
935
936 if (vl_config->transmit_delay)
937 {
938 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
939 IF_DEF_PARAMS (ifp)->transmit_delay = vl_config->transmit_delay;
940 }
941
942 return CMD_SUCCESS;
943}
944
945
718e3744 946/* The business end of all of the above */
4dadc291 947static int
68980084 948ospf_vl_set (struct ospf *ospf, struct ospf_vl_config_data *vl_config)
718e3744 949{
950 struct ospf_vl_data *vl_data;
951 int ret;
952
68980084 953 vl_data = ospf_find_vl_data (ospf, vl_config);
718e3744 954 if (!vl_data)
955 return CMD_WARNING;
956
957 /* Process this one first as it can have a fatal result, which can
958 only logically occur if the virtual link exists already
959 Thus a command error does not result in a change to the
960 running configuration such as unexpectedly altered timer
961 values etc.*/
962 ret = ospf_vl_set_security (vl_data, vl_config);
963 if (ret != CMD_SUCCESS)
964 return ret;
965
966 /* Set any time based parameters, these area already range checked */
967
968 ret = ospf_vl_set_timers (vl_data, vl_config);
969 if (ret != CMD_SUCCESS)
970 return ret;
971
972 return CMD_SUCCESS;
973
974}
975
976/* This stuff exists to make specifying all the alias commands A LOT simpler
977 */
978#define VLINK_HELPSTR_IPADDR \
979 "OSPF area parameters\n" \
980 "OSPF area ID in IP address format\n" \
981 "OSPF area ID as a decimal value\n" \
982 "Configure a virtual link\n" \
983 "Router ID of the remote ABR\n"
984
985#define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
986 "Enable authentication on this virtual link\n" \
987 "dummy string \n"
988
989#define VLINK_HELPSTR_AUTHTYPE_ALL \
990 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
991 "Use null authentication\n" \
992 "Use message-digest authentication\n"
993
994#define VLINK_HELPSTR_TIME_PARAM_NOSECS \
995 "Time between HELLO packets\n" \
996 "Time between retransmitting lost link state advertisements\n" \
997 "Link state transmit delay\n" \
99a522c7 998 "Interval time after which a neighbor is declared down\n"
718e3744 999
1000#define VLINK_HELPSTR_TIME_PARAM \
1001 VLINK_HELPSTR_TIME_PARAM_NOSECS \
1002 "Seconds\n"
1003
1004#define VLINK_HELPSTR_AUTH_SIMPLE \
1005 "Authentication password (key)\n" \
1006 "The OSPF password (key)"
1007
1008#define VLINK_HELPSTR_AUTH_MD5 \
1009 "Message digest authentication password (key)\n" \
1010 "dummy string \n" \
1011 "Key ID\n" \
1012 "Use MD5 algorithm\n" \
1013 "The OSPF password (key)"
1014
a2c62831 1015DEFUN (ospf_area_vlink,
1016 ospf_area_vlink_cmd,
22b27e95 1017 "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>]",
7a7be519 1018 VLINK_HELPSTR_IPADDR
1019 "Enable authentication on this virtual link\n" \
1020 "Use null authentication\n" \
1021 "Use message-digest authentication\n"
1022 "Message digest authentication password (key)\n" \
1023 "Key ID\n" \
1024 "Use MD5 algorithm\n" \
1025 "The OSPF password (key)")
718e3744 1026{
cdc2d765 1027 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
1028 int idx_ipv4_number = 1;
1029 int idx_ipv4 = 3;
718e3744 1030 struct ospf_vl_config_data vl_config;
1031 char auth_key[OSPF_AUTH_SIMPLE_SIZE+1];
1032 char md5_key[OSPF_AUTH_MD5_SIZE+1];
1033 int i;
1034 int ret;
7c8ff89e 1035
718e3744 1036 ospf_vl_config_data_init(&vl_config, vty);
1037
1038 /* Read off first 2 parameters and check them */
8d769265 1039 ret = ospf_str2area_id (argv[idx_ipv4_number]->arg, &vl_config.area_id, &vl_config.format);
718e3744 1040 if (ret < 0)
1041 {
1042 vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
1043 return CMD_WARNING;
1044 }
1045
8d769265 1046 ret = inet_aton (argv[idx_ipv4]->arg, &vl_config.vl_peer);
718e3744 1047 if (! ret)
1048 {
1049 vty_out (vty, "Please specify valid Router ID as a.b.c.d%s",
1050 VTY_NEWLINE);
1051 return CMD_WARNING;
1052 }
1053
7a7be519 1054 if (argc <=4)
718e3744 1055 {
1056 /* Thats all folks! - BUGS B. strikes again!!!*/
1057
68980084 1058 return ospf_vl_set (ospf, &vl_config);
718e3744 1059 }
1060
1061 /* Deal with other parameters */
7a7be519 1062 for (i=5; i < argc; i++)
718e3744 1063 {
1064
7a7be519 1065 /* vty_out (vty, "argv[%d]->arg - %s%s", i, argv[i]->text, VTY_NEWLINE); */
718e3744 1066
7a7be519 1067 switch (argv[i]->arg[0])
718e3744 1068 {
1069
1070 case 'a':
7a7be519 1071 if (i >5 || strncmp (argv[i]->arg, "authentication-", 15) == 0)
718e3744 1072 {
1073 /* authentication-key - this option can occur anywhere on
1074 command line. At start of command line
1075 must check for authentication option. */
1076 memset (auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
7a7be519 1077 strncpy (auth_key, argv[i+1]->text, OSPF_AUTH_SIMPLE_SIZE);
718e3744 1078 vl_config.auth_key = auth_key;
1079 i++;
1080 }
7a7be519 1081 else if (strncmp (argv[i]->arg, "authentication", 14) == 0)
718e3744 1082 {
1083 /* authentication - this option can only occur at start
1084 of command line */
1085 vl_config.auth_type = OSPF_AUTH_SIMPLE;
1086 if ((i+1) < argc)
1087 {
7a7be519 1088 if (strncmp (argv[i+1]->arg, "n", 1) == 0)
718e3744 1089 {
1090 /* "authentication null" */
1091 vl_config.auth_type = OSPF_AUTH_NULL;
1092 i++;
1093 }
7a7be519 1094 else if (strncmp (argv[i+1]->arg, "m", 1) == 0
1095 && strcmp (argv[i+1]->arg, "message-digest-") != 0)
718e3744 1096 {
1097 /* "authentication message-digest" */
1098 vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
1099 i++;
1100 }
1101 }
1102 }
1103 break;
1104
1105 case 'm':
1106 /* message-digest-key */
1107 i++;
effe821e
DS
1108 if (i < argc)
1109 {
1110 vl_config.crypto_key_id = strtol (argv[i]->arg, NULL, 10);
1111 if (vl_config.crypto_key_id < 0)
1112 return CMD_WARNING;
1113 i++;
1114 if (i < argc)
1115 {
1116 memset(md5_key, 0, OSPF_AUTH_MD5_SIZE+1);
1117 strncpy (md5_key, argv[i]->arg, OSPF_AUTH_MD5_SIZE);
1118 vl_config.md5_key = md5_key;
1119 }
1120 }
1121 else
1122 vl_config.md5_key = NULL;
718e3744 1123 break;
7a7be519 1124 }
1125 }
1126
1127
1128 /* Action configuration */
1129
1130 return ospf_vl_set (ospf, &vl_config);
1131
1132}
1133
1134DEFUN (ospf_area_vlink_intervals,
1135 ospf_area_vlink_intervals_cmd,
bc7d452f
QY
1136 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D"
1137 "<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1138 "[<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1139 "[<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1140 "[<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1141 "]]]",
7a7be519 1142 VLINK_HELPSTR_IPADDR
1143 VLINK_HELPSTR_TIME_PARAM
1144 VLINK_HELPSTR_TIME_PARAM
1145 VLINK_HELPSTR_TIME_PARAM
1146 VLINK_HELPSTR_TIME_PARAM)
1147{
cdc2d765 1148 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 1149 struct ospf_vl_config_data vl_config;
bc7d452f 1150 int ret = 0;
7a7be519 1151
7a7be519 1152 ospf_vl_config_data_init(&vl_config, vty);
1153
bc7d452f
QY
1154 char *area_id = argv[1]->arg;
1155 char *router_id = argv[3]->arg;
1156
1157 ret = ospf_str2area_id (area_id, &vl_config.area_id, &vl_config.format);
7a7be519 1158 if (ret < 0)
1159 {
1160 vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
1161 return CMD_WARNING;
1162 }
1163
bc7d452f 1164 ret = inet_aton (router_id, &vl_config.vl_peer);
7a7be519 1165 if (! ret)
1166 {
bc7d452f 1167 vty_out (vty, "Please specify valid Router ID as a.b.c.d%s", VTY_NEWLINE);
7a7be519 1168 return CMD_WARNING;
1169 }
bc7d452f 1170 for (unsigned int i = 0; i < 4; i++)
7a7be519 1171 {
bc7d452f
QY
1172 int idx = 0;
1173 if (argv_find (argv, argc, "hello-interval", &idx))
1174 vl_config.hello_interval = strtol(argv[idx+1]->arg, NULL, 10);
1175 else if (argv_find (argv, argc, "retransmit-interval", &idx))
1176 vl_config.retransmit_interval = strtol(argv[idx+1]->arg, NULL, 10);
1177 else if (argv_find (argv, argc, "transmit-delay", &idx))
1178 vl_config.transmit_delay = strtol(argv[idx+1]->arg, NULL, 10);
1179 else if (argv_find (argv, argc, "dead-interval", &idx))
1180 vl_config.dead_interval = strtol(argv[idx+1]->arg, NULL, 10);
7a7be519 1181 }
1182
718e3744 1183 /* Action configuration */
68980084 1184 return ospf_vl_set (ospf, &vl_config);
718e3744 1185}
1186
a2c62831 1187DEFUN (no_ospf_area_vlink,
1188 no_ospf_area_vlink_cmd,
bc7d452f 1189 "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>]",
718e3744 1190 NO_STR
7a7be519 1191 VLINK_HELPSTR_IPADDR
1192 "Enable authentication on this virtual link\n" \
1193 "Use null authentication\n" \
1194 "Use message-digest authentication\n"
1195 "Message digest authentication password (key)\n" \
1196 "Key ID\n" \
1197 "Use MD5 algorithm\n" \
1198 "The OSPF password (key)")
718e3744 1199{
cdc2d765 1200 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
1201 int idx_ipv4_number = 2;
1202 int idx_ipv4 = 4;
718e3744 1203 struct ospf_area *area;
1204 struct ospf_vl_config_data vl_config;
1205 struct ospf_vl_data *vl_data = NULL;
1206 char auth_key[OSPF_AUTH_SIMPLE_SIZE+1];
1207 int i;
1208 int ret, format;
1209
1210 ospf_vl_config_data_init(&vl_config, vty);
1211
8d769265 1212 ret = ospf_str2area_id (argv[idx_ipv4_number]->arg, &vl_config.area_id, &format);
718e3744 1213 if (ret < 0)
1214 {
1215 vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
1216 return CMD_WARNING;
1217 }
1218
68980084 1219 area = ospf_area_lookup_by_area_id (ospf, vl_config.area_id);
718e3744 1220 if (!area)
1221 {
1222 vty_out (vty, "Area does not exist%s", VTY_NEWLINE);
1223 return CMD_WARNING;
1224 }
1225
8d769265 1226 ret = inet_aton (argv[idx_ipv4]->arg, &vl_config.vl_peer);
718e3744 1227 if (! ret)
1228 {
1229 vty_out (vty, "Please specify valid Router ID as a.b.c.d%s",
1230 VTY_NEWLINE);
1231 return CMD_WARNING;
1232 }
1233
7a7be519 1234 if (argc <=5)
718e3744 1235 {
1236 /* Basic VLink no command */
1237 /* Thats all folks! - BUGS B. strikes again!!!*/
9c27ef9b 1238 if ((vl_data = ospf_vl_lookup (ospf, area, vl_config.vl_peer)))
68980084 1239 ospf_vl_delete (ospf, vl_data);
718e3744 1240
68980084 1241 ospf_area_check_free (ospf, vl_config.area_id);
7a7be519 1242
718e3744 1243 return CMD_SUCCESS;
1244 }
1245
1246 /* If we are down here, we are reseting parameters */
1247
1248 /* Deal with other parameters */
effe821e 1249 for (i=6; i < argc; i++)
718e3744 1250 {
718e3744 1251 /* vty_out (vty, "argv[%d] - %s%s", i, argv[i], VTY_NEWLINE); */
1252
7a7be519 1253 switch (argv[i]->arg[0])
718e3744 1254 {
1255
1256 case 'a':
7a7be519 1257 if (i > 2 || strncmp (argv[i]->text, "authentication-", 15) == 0)
718e3744 1258 {
1259 /* authentication-key - this option can occur anywhere on
1260 command line. At start of command line
1261 must check for authentication option. */
1262 memset (auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
1263 vl_config.auth_key = auth_key;
1264 }
7a7be519 1265 else if (strncmp (argv[i]->text, "authentication", 14) == 0)
718e3744 1266 {
1267 /* authentication - this option can only occur at start
1268 of command line */
1269 vl_config.auth_type = OSPF_AUTH_NOTSET;
1270 }
1271 break;
1272
1273 case 'm':
1274 /* message-digest-key */
1275 /* Delete one key */
1276 i++;
36da0665
DS
1277 if (i < argc)
1278 {
b6f1faf0 1279 vl_config.crypto_key_id = strtol (argv[i]->arg, NULL, 10);
36da0665
DS
1280 if (vl_config.crypto_key_id < 0)
1281 return CMD_WARNING;
1282 vl_config.md5_key = NULL;
1283 }
1284 else
718e3744 1285 return CMD_WARNING;
718e3744 1286 break;
1287
7a7be519 1288 }
1289 }
1290
1291
1292 /* Action configuration */
1293
1294 return ospf_vl_set (ospf, &vl_config);
1295}
1296
1297DEFUN (no_ospf_area_vlink_intervals,
1298 no_ospf_area_vlink_intervals_cmd,
bc7d452f
QY
1299 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D"
1300 "<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1301 "[<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1302 "[<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1303 "[<hello-interval|retransmit-interval|transmit-delay|dead-interval> (1-65535)"
1304 "]]]",
3a2d747c 1305 NO_STR
7a7be519 1306 VLINK_HELPSTR_IPADDR
1307 VLINK_HELPSTR_TIME_PARAM
1308 VLINK_HELPSTR_TIME_PARAM
1309 VLINK_HELPSTR_TIME_PARAM
1310 VLINK_HELPSTR_TIME_PARAM)
1311{
cdc2d765 1312 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 1313 struct ospf_vl_config_data vl_config;
bc7d452f 1314 int ret = 0;
7a7be519 1315
7a7be519 1316 ospf_vl_config_data_init(&vl_config, vty);
1317
bc7d452f
QY
1318 char *area_id = argv[2]->arg;
1319 char *router_id = argv[4]->arg;
1320
1321 ret = ospf_str2area_id (area_id, &vl_config.area_id, &vl_config.format);
7a7be519 1322 if (ret < 0)
1323 {
1324 vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
1325 return CMD_WARNING;
1326 }
1327
bc7d452f 1328 ret = inet_aton (router_id, &vl_config.vl_peer);
7a7be519 1329 if (! ret)
1330 {
bc7d452f 1331 vty_out (vty, "Please specify valid Router ID as a.b.c.d%s", VTY_NEWLINE);
7a7be519 1332 return CMD_WARNING;
1333 }
1334
bc7d452f 1335 for (unsigned int i = 0; i < 4; i++)
7a7be519 1336 {
bc7d452f
QY
1337 int idx = 0;
1338 if (argv_find (argv, argc, "hello-interval", &idx))
1339 vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
1340 else if (argv_find (argv, argc, "retransmit-interval", &idx))
1341 vl_config.retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
1342 else if (argv_find (argv, argc, "transmit-delay", &idx))
1343 vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
1344 else if (argv_find (argv, argc, "dead-interval", &idx))
1345 vl_config.dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
718e3744 1346 }
1347
718e3744 1348 /* Action configuration */
68980084 1349 return ospf_vl_set (ospf, &vl_config);
718e3744 1350}
1351
a2c62831 1352DEFUN (ospf_area_shortcut,
1353 ospf_area_shortcut_cmd,
6147e2c6 1354 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
718e3744 1355 "OSPF area parameters\n"
1356 "OSPF area ID in IP address format\n"
1357 "OSPF area ID as a decimal value\n"
1358 "Configure the area's shortcutting mode\n"
1359 "Set default shortcutting behavior\n"
1360 "Enable shortcutting through the area\n"
1361 "Disable shortcutting through the area\n")
1362{
cdc2d765 1363 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
1364 int idx_ipv4_number = 1;
1365 int idx_enable_disable = 3;
718e3744 1366 struct ospf_area *area;
1367 struct in_addr area_id;
1368 int mode;
1369 int format;
1370
8d769265 1371 VTY_GET_OSPF_AREA_ID_NO_BB ("shortcut", area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1372
68980084 1373 area = ospf_area_get (ospf, area_id, format);
718e3744 1374
8d769265 1375 if (strncmp (argv[idx_enable_disable]->arg, "de", 2) == 0)
718e3744 1376 mode = OSPF_SHORTCUT_DEFAULT;
8d769265 1377 else if (strncmp (argv[idx_enable_disable]->arg, "di", 2) == 0)
718e3744 1378 mode = OSPF_SHORTCUT_DISABLE;
8d769265 1379 else if (strncmp (argv[idx_enable_disable]->arg, "e", 1) == 0)
718e3744 1380 mode = OSPF_SHORTCUT_ENABLE;
1381 else
1382 return CMD_WARNING;
1383
68980084 1384 ospf_area_shortcut_set (ospf, area, mode);
718e3744 1385
68980084 1386 if (ospf->abr_type != OSPF_ABR_SHORTCUT)
718e3744 1387 vty_out (vty, "Shortcut area setting will take effect "
1388 "only when the router is configured as Shortcut ABR%s",
1389 VTY_NEWLINE);
1390
1391 return CMD_SUCCESS;
1392}
1393
a2c62831 1394DEFUN (no_ospf_area_shortcut,
1395 no_ospf_area_shortcut_cmd,
6147e2c6 1396 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
718e3744 1397 NO_STR
1398 "OSPF area parameters\n"
1399 "OSPF area ID in IP address format\n"
1400 "OSPF area ID as a decimal value\n"
1401 "Deconfigure the area's shortcutting mode\n"
1402 "Deconfigure enabled shortcutting through the area\n"
1403 "Deconfigure disabled shortcutting through the area\n")
1404{
cdc2d765 1405 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1406 int idx_ipv4_number = 2;
718e3744 1407 struct ospf_area *area;
1408 struct in_addr area_id;
1409 int format;
1410
8d769265 1411 VTY_GET_OSPF_AREA_ID_NO_BB ("shortcut", area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1412
68980084 1413 area = ospf_area_lookup_by_area_id (ospf, area_id);
718e3744 1414 if (!area)
1415 return CMD_SUCCESS;
1416
68980084 1417 ospf_area_shortcut_unset (ospf, area);
718e3744 1418
1419 return CMD_SUCCESS;
1420}
1421
6b0655a2 1422
a2c62831 1423DEFUN (ospf_area_stub,
1424 ospf_area_stub_cmd,
6147e2c6 1425 "area <A.B.C.D|(0-4294967295)> stub",
718e3744 1426 "OSPF area parameters\n"
1427 "OSPF area ID in IP address format\n"
1428 "OSPF area ID as a decimal value\n"
1429 "Configure OSPF area as stub\n")
1430{
cdc2d765 1431 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1432 int idx_ipv4_number = 1;
718e3744 1433 struct in_addr area_id;
1434 int ret, format;
1435
8d769265 1436 VTY_GET_OSPF_AREA_ID_NO_BB ("stub", area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1437
1438 ret = ospf_area_stub_set (ospf, area_id);
1439 if (ret == 0)
1440 {
1441 vty_out (vty, "First deconfigure all virtual link through this area%s",
1442 VTY_NEWLINE);
1443 return CMD_WARNING;
1444 }
1445
1446 ospf_area_no_summary_unset (ospf, area_id);
1447
1448 return CMD_SUCCESS;
1449}
1450
a2c62831 1451DEFUN (ospf_area_stub_no_summary,
1452 ospf_area_stub_no_summary_cmd,
6147e2c6 1453 "area <A.B.C.D|(0-4294967295)> stub no-summary",
718e3744 1454 "OSPF stub parameters\n"
1455 "OSPF area ID in IP address format\n"
1456 "OSPF area ID as a decimal value\n"
1457 "Configure OSPF area as stub\n"
1458 "Do not inject inter-area routes into stub\n")
1459{
cdc2d765 1460 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1461 int idx_ipv4_number = 1;
718e3744 1462 struct in_addr area_id;
1463 int ret, format;
1464
8d769265 1465 VTY_GET_OSPF_AREA_ID_NO_BB ("stub", area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1466
1467 ret = ospf_area_stub_set (ospf, area_id);
1468 if (ret == 0)
1469 {
b0a053be 1470 vty_out (vty, "%% Area cannot be stub as it contains a virtual link%s",
718e3744 1471 VTY_NEWLINE);
1472 return CMD_WARNING;
1473 }
1474
1475 ospf_area_no_summary_set (ospf, area_id);
1476
1477 return CMD_SUCCESS;
1478}
1479
a2c62831 1480DEFUN (no_ospf_area_stub,
1481 no_ospf_area_stub_cmd,
6147e2c6 1482 "no area <A.B.C.D|(0-4294967295)> stub",
718e3744 1483 NO_STR
1484 "OSPF area parameters\n"
1485 "OSPF area ID in IP address format\n"
1486 "OSPF area ID as a decimal value\n"
1487 "Configure OSPF area as stub\n")
1488{
cdc2d765 1489 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1490 int idx_ipv4_number = 2;
718e3744 1491 struct in_addr area_id;
1492 int format;
1493
8d769265 1494 VTY_GET_OSPF_AREA_ID_NO_BB ("stub", area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1495
1496 ospf_area_stub_unset (ospf, area_id);
1497 ospf_area_no_summary_unset (ospf, area_id);
1498
1499 return CMD_SUCCESS;
1500}
1501
a2c62831 1502DEFUN (no_ospf_area_stub_no_summary,
1503 no_ospf_area_stub_no_summary_cmd,
6147e2c6 1504 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
718e3744 1505 NO_STR
1506 "OSPF area parameters\n"
1507 "OSPF area ID in IP address format\n"
1508 "OSPF area ID as a decimal value\n"
1509 "Configure OSPF area as stub\n"
1510 "Do not inject inter-area routes into area\n")
1511{
cdc2d765 1512 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1513 int idx_ipv4_number = 2;
718e3744 1514 struct in_addr area_id;
1515 int format;
1516
8d769265 1517 VTY_GET_OSPF_AREA_ID_NO_BB ("stub", area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1518 ospf_area_no_summary_unset (ospf, area_id);
1519
1520 return CMD_SUCCESS;
1521}
1522
4dadc291 1523static int
7a7be519 1524ospf_area_nssa_cmd_handler (struct vty *vty, int argc, struct cmd_token **argv,
6c835671 1525 int nosum)
718e3744 1526{
cdc2d765 1527 VTY_DECLVAR_CONTEXT(ospf, ospf);
718e3744 1528 struct in_addr area_id;
1529 int ret, format;
1530
7a7be519 1531 VTY_GET_OSPF_AREA_ID_NO_BB ("NSSA", area_id, format, argv[1]->arg);
718e3744 1532
1533 ret = ospf_area_nssa_set (ospf, area_id);
1534 if (ret == 0)
1535 {
1536 vty_out (vty, "%% Area cannot be nssa as it contains a virtual link%s",
1537 VTY_NEWLINE);
1538 return CMD_WARNING;
1539 }
1540
313605cb 1541 if (argc > 3)
718e3744 1542 {
7a7be519 1543 if (strncmp (argv[3]->text, "translate-c", 11) == 0)
b0a053be 1544 ospf_area_nssa_translator_role_set (ospf, area_id,
718e3744 1545 OSPF_NSSA_ROLE_CANDIDATE);
7a7be519 1546 else if (strncmp (argv[3]->text, "translate-n", 11) == 0)
b0a053be 1547 ospf_area_nssa_translator_role_set (ospf, area_id,
718e3744 1548 OSPF_NSSA_ROLE_NEVER);
7a7be519 1549 else if (strncmp (argv[3]->text, "translate-a", 11) == 0)
b0a053be 1550 ospf_area_nssa_translator_role_set (ospf, area_id,
718e3744 1551 OSPF_NSSA_ROLE_ALWAYS);
1552 }
b0a053be 1553 else
1554 {
1555 ospf_area_nssa_translator_role_set (ospf, area_id,
1556 OSPF_NSSA_ROLE_CANDIDATE);
1557 }
718e3744 1558
b0a053be 1559 if (nosum)
718e3744 1560 ospf_area_no_summary_set (ospf, area_id);
b0a053be 1561 else
1562 ospf_area_no_summary_unset (ospf, area_id);
718e3744 1563
b0a053be 1564 ospf_schedule_abr_task (ospf);
1565
718e3744 1566 return CMD_SUCCESS;
1567}
1568
b0a053be 1569DEFUN (ospf_area_nssa_translate_no_summary,
a2c62831 1570 ospf_area_nssa_translate_no_summary_cmd,
6147e2c6 1571 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always> no-summary",
718e3744 1572 "OSPF area parameters\n"
1573 "OSPF area ID in IP address format\n"
1574 "OSPF area ID as a decimal value\n"
1575 "Configure OSPF area as nssa\n"
1576 "Configure NSSA-ABR for translate election (default)\n"
1577 "Configure NSSA-ABR to never translate\n"
1578 "Configure NSSA-ABR to always translate\n"
b0a053be 1579 "Do not inject inter-area routes into nssa\n")
1580{
1581 return ospf_area_nssa_cmd_handler (vty, argc, argv, 1);
1582}
718e3744 1583
b0a053be 1584DEFUN (ospf_area_nssa_translate,
a2c62831 1585 ospf_area_nssa_translate_cmd,
6147e2c6 1586 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
718e3744 1587 "OSPF area parameters\n"
1588 "OSPF area ID in IP address format\n"
1589 "OSPF area ID as a decimal value\n"
1590 "Configure OSPF area as nssa\n"
1591 "Configure NSSA-ABR for translate election (default)\n"
1592 "Configure NSSA-ABR to never translate\n"
1593 "Configure NSSA-ABR to always translate\n")
b0a053be 1594{
1595 return ospf_area_nssa_cmd_handler (vty, argc, argv, 0);
1596}
1597
1598DEFUN (ospf_area_nssa,
1599 ospf_area_nssa_cmd,
6147e2c6 1600 "area <A.B.C.D|(0-4294967295)> nssa",
b0a053be 1601 "OSPF area parameters\n"
1602 "OSPF area ID in IP address format\n"
1603 "OSPF area ID as a decimal value\n"
1604 "Configure OSPF area as nssa\n")
1605{
1606 return ospf_area_nssa_cmd_handler (vty, argc, argv, 0);
1607}
718e3744 1608
a2c62831 1609DEFUN (ospf_area_nssa_no_summary,
1610 ospf_area_nssa_no_summary_cmd,
6147e2c6 1611 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
718e3744 1612 "OSPF area parameters\n"
1613 "OSPF area ID in IP address format\n"
1614 "OSPF area ID as a decimal value\n"
1615 "Configure OSPF area as nssa\n"
1616 "Do not inject inter-area routes into nssa\n")
1617{
b0a053be 1618 return ospf_area_nssa_cmd_handler (vty, argc, argv, 1);
718e3744 1619}
1620
a2c62831 1621DEFUN (no_ospf_area_nssa,
1622 no_ospf_area_nssa_cmd,
7a7be519 1623 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always> [no-summary]]",
718e3744 1624 NO_STR
1625 "OSPF area parameters\n"
1626 "OSPF area ID in IP address format\n"
1627 "OSPF area ID as a decimal value\n"
7a7be519 1628 "Configure OSPF area as nssa\n"
1629 "Configure NSSA-ABR for translate election (default)\n"
1630 "Configure NSSA-ABR to never translate\n"
1631 "Configure NSSA-ABR to always translate\n"
1632 "Do not inject inter-area routes into nssa\n")
22b27e95 1633{
cdc2d765 1634 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1635 int idx_ipv4_number = 2;
718e3744 1636 struct in_addr area_id;
1637 int format;
1638
8d769265 1639 VTY_GET_OSPF_AREA_ID_NO_BB ("NSSA", area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1640
1641 ospf_area_nssa_unset (ospf, area_id);
1642 ospf_area_no_summary_unset (ospf, area_id);
1643
b0a053be 1644 ospf_schedule_abr_task (ospf);
1645
718e3744 1646 return CMD_SUCCESS;
1647}
1648
718e3744 1649
a2c62831 1650DEFUN (ospf_area_default_cost,
1651 ospf_area_default_cost_cmd,
6147e2c6 1652 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
718e3744 1653 "OSPF area parameters\n"
1654 "OSPF area ID in IP address format\n"
1655 "OSPF area ID as a decimal value\n"
1656 "Set the summary-default cost of a NSSA or stub area\n"
1657 "Stub's advertised default summary cost\n")
1658{
cdc2d765 1659 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
1660 int idx_ipv4_number = 1;
1661 int idx_number = 3;
718e3744 1662 struct ospf_area *area;
1663 struct in_addr area_id;
1664 u_int32_t cost;
1665 int format;
ba682537 1666 struct prefix_ipv4 p;
718e3744 1667
8d769265
DW
1668 VTY_GET_OSPF_AREA_ID_NO_BB ("default-cost", area_id, format, argv[idx_ipv4_number]->arg);
1669 VTY_GET_INTEGER_RANGE ("stub default cost", cost, argv[idx_number]->arg, 0, 16777215);
718e3744 1670
68980084 1671 area = ospf_area_get (ospf, area_id, format);
718e3744 1672
1673 if (area->external_routing == OSPF_AREA_DEFAULT)
1674 {
1675 vty_out (vty, "The area is neither stub, nor NSSA%s", VTY_NEWLINE);
1676 return CMD_WARNING;
1677 }
1678
1679 area->default_cost = cost;
1680
ba682537 1681 p.family = AF_INET;
1682 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1683 p.prefixlen = 0;
1684 if (IS_DEBUG_OSPF_EVENT)
1685 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1686 "announcing 0.0.0.0/0 to area %s",
1687 inet_ntoa (area->area_id));
1688 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1689
718e3744 1690 return CMD_SUCCESS;
1691}
1692
a2c62831 1693DEFUN (no_ospf_area_default_cost,
1694 no_ospf_area_default_cost_cmd,
6147e2c6 1695 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
718e3744 1696 NO_STR
1697 "OSPF area parameters\n"
1698 "OSPF area ID in IP address format\n"
1699 "OSPF area ID as a decimal value\n"
1700 "Set the summary-default cost of a NSSA or stub area\n"
1701 "Stub's advertised default summary cost\n")
1702{
cdc2d765 1703 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
1704 int idx_ipv4_number = 2;
1705 int idx_number = 4;
718e3744 1706 struct ospf_area *area;
1707 struct in_addr area_id;
718e3744 1708 int format;
ba682537 1709 struct prefix_ipv4 p;
718e3744 1710
8d769265
DW
1711 VTY_GET_OSPF_AREA_ID_NO_BB ("default-cost", area_id, format, argv[idx_ipv4_number]->arg);
1712 VTY_CHECK_INTEGER_RANGE ("stub default cost", argv[idx_number]->arg, 0, OSPF_LS_INFINITY);
718e3744 1713
68980084 1714 area = ospf_area_lookup_by_area_id (ospf, area_id);
718e3744 1715 if (area == NULL)
1716 return CMD_SUCCESS;
1717
1718 if (area->external_routing == OSPF_AREA_DEFAULT)
1719 {
1720 vty_out (vty, "The area is neither stub, nor NSSA%s", VTY_NEWLINE);
1721 return CMD_WARNING;
1722 }
1723
1724 area->default_cost = 1;
1725
ba682537 1726 p.family = AF_INET;
1727 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1728 p.prefixlen = 0;
1729 if (IS_DEBUG_OSPF_EVENT)
1730 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1731 "announcing 0.0.0.0/0 to area %s",
1732 inet_ntoa (area->area_id));
1733 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1734
1735
68980084 1736 ospf_area_check_free (ospf, area_id);
718e3744 1737
1738 return CMD_SUCCESS;
1739}
1740
a2c62831 1741DEFUN (ospf_area_export_list,
1742 ospf_area_export_list_cmd,
6147e2c6 1743 "area <A.B.C.D|(0-4294967295)> export-list NAME",
718e3744 1744 "OSPF area parameters\n"
1745 "OSPF area ID in IP address format\n"
1746 "OSPF area ID as a decimal value\n"
1747 "Set the filter for networks announced to other areas\n"
1748 "Name of the access-list\n")
1749{
cdc2d765 1750 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1751 int idx_ipv4_number = 1;
718e3744 1752 struct ospf_area *area;
1753 struct in_addr area_id;
1754 int format;
1755
8d769265 1756 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
52930766 1757
68980084 1758 area = ospf_area_get (ospf, area_id, format);
7a7be519 1759 ospf_area_export_list_set (ospf, area, argv[3]->arg);
718e3744 1760
1761 return CMD_SUCCESS;
1762}
1763
a2c62831 1764DEFUN (no_ospf_area_export_list,
1765 no_ospf_area_export_list_cmd,
6147e2c6 1766 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
718e3744 1767 NO_STR
1768 "OSPF area parameters\n"
1769 "OSPF area ID in IP address format\n"
1770 "OSPF area ID as a decimal value\n"
1771 "Unset the filter for networks announced to other areas\n"
1772 "Name of the access-list\n")
1773{
cdc2d765 1774 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1775 int idx_ipv4_number = 2;
718e3744 1776 struct ospf_area *area;
1777 struct in_addr area_id;
1778 int format;
1779
8d769265 1780 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
52930766 1781
68980084 1782 area = ospf_area_lookup_by_area_id (ospf, area_id);
718e3744 1783 if (area == NULL)
1784 return CMD_SUCCESS;
1785
68980084 1786 ospf_area_export_list_unset (ospf, area);
718e3744 1787
1788 return CMD_SUCCESS;
1789}
1790
1791
a2c62831 1792DEFUN (ospf_area_import_list,
1793 ospf_area_import_list_cmd,
6147e2c6 1794 "area <A.B.C.D|(0-4294967295)> import-list NAME",
718e3744 1795 "OSPF area parameters\n"
1796 "OSPF area ID in IP address format\n"
1797 "OSPF area ID as a decimal value\n"
1798 "Set the filter for networks from other areas announced to the specified one\n"
1799 "Name of the access-list\n")
1800{
cdc2d765 1801 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1802 int idx_ipv4_number = 1;
718e3744 1803 struct ospf_area *area;
1804 struct in_addr area_id;
1805 int format;
1806
8d769265 1807 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
52930766 1808
68980084 1809 area = ospf_area_get (ospf, area_id, format);
7a7be519 1810 ospf_area_import_list_set (ospf, area, argv[3]->arg);
718e3744 1811
1812 return CMD_SUCCESS;
1813}
1814
a2c62831 1815DEFUN (no_ospf_area_import_list,
1816 no_ospf_area_import_list_cmd,
6147e2c6 1817 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
718e3744 1818 NO_STR
1819 "OSPF area parameters\n"
1820 "OSPF area ID in IP address format\n"
1821 "OSPF area ID as a decimal value\n"
1822 "Unset the filter for networks announced to other areas\n"
1823 "Name of the access-list\n")
1824{
cdc2d765 1825 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1826 int idx_ipv4_number = 2;
718e3744 1827 struct ospf_area *area;
1828 struct in_addr area_id;
1829 int format;
1830
8d769265 1831 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
52930766 1832
68980084 1833 area = ospf_area_lookup_by_area_id (ospf, area_id);
718e3744 1834 if (area == NULL)
1835 return CMD_SUCCESS;
1836
68980084 1837 ospf_area_import_list_unset (ospf, area);
718e3744 1838
1839 return CMD_SUCCESS;
1840}
1841
a2c62831 1842DEFUN (ospf_area_filter_list,
1843 ospf_area_filter_list_cmd,
6147e2c6 1844 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
718e3744 1845 "OSPF area parameters\n"
1846 "OSPF area ID in IP address format\n"
1847 "OSPF area ID as a decimal value\n"
1848 "Filter networks between OSPF areas\n"
1849 "Filter prefixes between OSPF areas\n"
1850 "Name of an IP prefix-list\n"
1851 "Filter networks sent to this area\n"
1852 "Filter networks sent from this area\n")
1853{
cdc2d765 1854 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
1855 int idx_ipv4_number = 1;
1856 int idx_word = 4;
1857 int idx_in_out = 5;
718e3744 1858 struct ospf_area *area;
1859 struct in_addr area_id;
1860 struct prefix_list *plist;
1861 int format;
1862
8d769265 1863 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1864
68980084 1865 area = ospf_area_get (ospf, area_id, format);
8d769265
DW
1866 plist = prefix_list_lookup (AFI_IP, argv[idx_word]->arg);
1867 if (strncmp (argv[idx_in_out]->arg, "in", 2) == 0)
718e3744 1868 {
1869 PREFIX_LIST_IN (area) = plist;
1870 if (PREFIX_NAME_IN (area))
1871 free (PREFIX_NAME_IN (area));
1872
8d769265 1873 PREFIX_NAME_IN (area) = strdup (argv[idx_word]->arg);
68980084 1874 ospf_schedule_abr_task (ospf);
718e3744 1875 }
1876 else
1877 {
1878 PREFIX_LIST_OUT (area) = plist;
1879 if (PREFIX_NAME_OUT (area))
1880 free (PREFIX_NAME_OUT (area));
1881
8d769265 1882 PREFIX_NAME_OUT (area) = strdup (argv[idx_word]->arg);
68980084 1883 ospf_schedule_abr_task (ospf);
718e3744 1884 }
1885
1886 return CMD_SUCCESS;
1887}
1888
a2c62831 1889DEFUN (no_ospf_area_filter_list,
1890 no_ospf_area_filter_list_cmd,
6147e2c6 1891 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
718e3744 1892 NO_STR
1893 "OSPF area parameters\n"
1894 "OSPF area ID in IP address format\n"
1895 "OSPF area ID as a decimal value\n"
1896 "Filter networks between OSPF areas\n"
1897 "Filter prefixes between OSPF areas\n"
1898 "Name of an IP prefix-list\n"
1899 "Filter networks sent to this area\n"
1900 "Filter networks sent from this area\n")
1901{
cdc2d765 1902 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
1903 int idx_ipv4_number = 2;
1904 int idx_word = 5;
1905 int idx_in_out = 6;
718e3744 1906 struct ospf_area *area;
1907 struct in_addr area_id;
718e3744 1908 int format;
1909
8d769265 1910 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1911
1a8ec2b9
PJ
1912 if ((area = ospf_area_lookup_by_area_id (ospf, area_id)) == NULL)
1913 return CMD_SUCCESS;
1914
8d769265 1915 if (strncmp (argv[idx_in_out]->arg, "in", 2) == 0)
718e3744 1916 {
1917 if (PREFIX_NAME_IN (area))
8d769265 1918 if (strcmp (PREFIX_NAME_IN (area), argv[idx_word]->arg) != 0)
718e3744 1919 return CMD_SUCCESS;
1920
1921 PREFIX_LIST_IN (area) = NULL;
1922 if (PREFIX_NAME_IN (area))
1923 free (PREFIX_NAME_IN (area));
1924
1925 PREFIX_NAME_IN (area) = NULL;
1926
68980084 1927 ospf_schedule_abr_task (ospf);
718e3744 1928 }
1929 else
1930 {
1931 if (PREFIX_NAME_OUT (area))
8d769265 1932 if (strcmp (PREFIX_NAME_OUT (area), argv[idx_word]->arg) != 0)
718e3744 1933 return CMD_SUCCESS;
1934
1935 PREFIX_LIST_OUT (area) = NULL;
1936 if (PREFIX_NAME_OUT (area))
1937 free (PREFIX_NAME_OUT (area));
1938
1939 PREFIX_NAME_OUT (area) = NULL;
1940
68980084 1941 ospf_schedule_abr_task (ospf);
718e3744 1942 }
1943
1944 return CMD_SUCCESS;
1945}
1946
6b0655a2 1947
a2c62831 1948DEFUN (ospf_area_authentication_message_digest,
1949 ospf_area_authentication_message_digest_cmd,
6147e2c6 1950 "area <A.B.C.D|(0-4294967295)> authentication message-digest",
718e3744 1951 "OSPF area parameters\n"
2b00515a
CF
1952 "OSPF area ID in IP address format\n"
1953 "OSPF area ID as a decimal value\n"
718e3744 1954 "Enable authentication\n"
1955 "Use message-digest authentication\n")
1956{
cdc2d765 1957 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1958 int idx_ipv4_number = 1;
718e3744 1959 struct ospf_area *area;
1960 struct in_addr area_id;
1961 int format;
1962
8d769265 1963 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1964
68980084 1965 area = ospf_area_get (ospf, area_id, format);
718e3744 1966 area->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
1967
1968 return CMD_SUCCESS;
1969}
1970
a2c62831 1971DEFUN (ospf_area_authentication,
1972 ospf_area_authentication_cmd,
6147e2c6 1973 "area <A.B.C.D|(0-4294967295)> authentication",
718e3744 1974 "OSPF area parameters\n"
1975 "OSPF area ID in IP address format\n"
1976 "OSPF area ID as a decimal value\n"
1977 "Enable authentication\n")
1978{
cdc2d765 1979 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 1980 int idx_ipv4_number = 1;
718e3744 1981 struct ospf_area *area;
1982 struct in_addr area_id;
1983 int format;
1984
8d769265 1985 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
718e3744 1986
68980084 1987 area = ospf_area_get (ospf, area_id, format);
718e3744 1988 area->auth_type = OSPF_AUTH_SIMPLE;
1989
1990 return CMD_SUCCESS;
1991}
1992
a2c62831 1993DEFUN (no_ospf_area_authentication,
1994 no_ospf_area_authentication_cmd,
6147e2c6 1995 "no area <A.B.C.D|(0-4294967295)> authentication",
718e3744 1996 NO_STR
1997 "OSPF area parameters\n"
1998 "OSPF area ID in IP address format\n"
1999 "OSPF area ID as a decimal value\n"
2000 "Enable authentication\n")
2001{
cdc2d765 2002 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2003 int idx_ipv4_number = 2;
718e3744 2004 struct ospf_area *area;
2005 struct in_addr area_id;
2006 int format;
2007
8d769265 2008 VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
718e3744 2009
68980084 2010 area = ospf_area_lookup_by_area_id (ospf, area_id);
718e3744 2011 if (area == NULL)
2012 return CMD_SUCCESS;
2013
2014 area->auth_type = OSPF_AUTH_NULL;
2015
68980084 2016 ospf_area_check_free (ospf, area_id);
718e3744 2017
2018 return CMD_SUCCESS;
2019}
2020
6b0655a2 2021
718e3744 2022DEFUN (ospf_abr_type,
2023 ospf_abr_type_cmd,
6147e2c6 2024 "ospf abr-type <cisco|ibm|shortcut|standard>",
718e3744 2025 "OSPF specific commands\n"
2026 "Set OSPF ABR type\n"
2027 "Alternative ABR, cisco implementation\n"
2028 "Alternative ABR, IBM implementation\n"
2029 "Shortcut ABR\n"
2030 "Standard behavior (RFC2328)\n")
2031{
cdc2d765 2032 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2033 int idx_vendor = 2;
718e3744 2034 u_char abr_type = OSPF_ABR_UNKNOWN;
2035
8d769265 2036 if (strncmp (argv[idx_vendor]->arg, "c", 1) == 0)
718e3744 2037 abr_type = OSPF_ABR_CISCO;
8d769265 2038 else if (strncmp (argv[idx_vendor]->arg, "i", 1) == 0)
718e3744 2039 abr_type = OSPF_ABR_IBM;
8d769265 2040 else if (strncmp (argv[idx_vendor]->arg, "sh", 2) == 0)
718e3744 2041 abr_type = OSPF_ABR_SHORTCUT;
8d769265 2042 else if (strncmp (argv[idx_vendor]->arg, "st", 2) == 0)
718e3744 2043 abr_type = OSPF_ABR_STAND;
2044 else
2045 return CMD_WARNING;
2046
2047 /* If ABR type value is changed, schedule ABR task. */
68980084 2048 if (ospf->abr_type != abr_type)
718e3744 2049 {
68980084 2050 ospf->abr_type = abr_type;
2051 ospf_schedule_abr_task (ospf);
718e3744 2052 }
2053
2054 return CMD_SUCCESS;
2055}
2056
2057DEFUN (no_ospf_abr_type,
2058 no_ospf_abr_type_cmd,
6147e2c6 2059 "no ospf abr-type <cisco|ibm|shortcut|standard>",
718e3744 2060 NO_STR
2061 "OSPF specific commands\n"
2062 "Set OSPF ABR type\n"
2063 "Alternative ABR, cisco implementation\n"
2064 "Alternative ABR, IBM implementation\n"
3a2d747c
QY
2065 "Shortcut ABR\n"
2066 "Standard ABR\n")
718e3744 2067{
cdc2d765 2068 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2069 int idx_vendor = 3;
718e3744 2070 u_char abr_type = OSPF_ABR_UNKNOWN;
2071
8d769265 2072 if (strncmp (argv[idx_vendor]->arg, "c", 1) == 0)
718e3744 2073 abr_type = OSPF_ABR_CISCO;
8d769265 2074 else if (strncmp (argv[idx_vendor]->arg, "i", 1) == 0)
718e3744 2075 abr_type = OSPF_ABR_IBM;
8d769265 2076 else if (strncmp (argv[idx_vendor]->arg, "sh", 2) == 0)
718e3744 2077 abr_type = OSPF_ABR_SHORTCUT;
8d769265 2078 else if (strncmp (argv[idx_vendor]->arg, "st", 2) == 0)
04d23314 2079 abr_type = OSPF_ABR_STAND;
718e3744 2080 else
2081 return CMD_WARNING;
2082
2083 /* If ABR type value is changed, schedule ABR task. */
68980084 2084 if (ospf->abr_type == abr_type)
718e3744 2085 {
d57834f6 2086 ospf->abr_type = OSPF_ABR_DEFAULT;
68980084 2087 ospf_schedule_abr_task (ospf);
718e3744 2088 }
2089
2090 return CMD_SUCCESS;
2091}
2092
d7e60dd7
AS
2093DEFUN (ospf_log_adjacency_changes,
2094 ospf_log_adjacency_changes_cmd,
2095 "log-adjacency-changes",
2096 "Log changes in adjacency state\n")
2097{
cdc2d765 2098 VTY_DECLVAR_CONTEXT(ospf, ospf);
d7e60dd7
AS
2099
2100 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
692c7954 2101 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
d7e60dd7
AS
2102 return CMD_SUCCESS;
2103}
2104
2105DEFUN (ospf_log_adjacency_changes_detail,
2106 ospf_log_adjacency_changes_detail_cmd,
2107 "log-adjacency-changes detail",
2108 "Log changes in adjacency state\n"
2109 "Log all state changes\n")
2110{
cdc2d765 2111 VTY_DECLVAR_CONTEXT(ospf, ospf);
d7e60dd7
AS
2112
2113 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2114 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2115 return CMD_SUCCESS;
2116}
2117
2118DEFUN (no_ospf_log_adjacency_changes,
2119 no_ospf_log_adjacency_changes_cmd,
2120 "no log-adjacency-changes",
2121 NO_STR
2122 "Log changes in adjacency state\n")
2123{
cdc2d765 2124 VTY_DECLVAR_CONTEXT(ospf, ospf);
d7e60dd7
AS
2125
2126 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2127 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2128 return CMD_SUCCESS;
2129}
2130
2131DEFUN (no_ospf_log_adjacency_changes_detail,
2132 no_ospf_log_adjacency_changes_detail_cmd,
2133 "no log-adjacency-changes detail",
2134 NO_STR
2135 "Log changes in adjacency state\n"
2136 "Log all state changes\n")
2137{
cdc2d765 2138 VTY_DECLVAR_CONTEXT(ospf, ospf);
d7e60dd7
AS
2139
2140 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2141 return CMD_SUCCESS;
2142}
2143
718e3744 2144DEFUN (ospf_compatible_rfc1583,
2145 ospf_compatible_rfc1583_cmd,
2146 "compatible rfc1583",
2147 "OSPF compatibility list\n"
2148 "compatible with RFC 1583\n")
2149{
cdc2d765 2150 VTY_DECLVAR_CONTEXT(ospf, ospf);
718e3744 2151
2152 if (!CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
2153 {
2154 SET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
d3a9c768 2155 ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
718e3744 2156 }
2157 return CMD_SUCCESS;
2158}
2159
2160DEFUN (no_ospf_compatible_rfc1583,
2161 no_ospf_compatible_rfc1583_cmd,
2162 "no compatible rfc1583",
2163 NO_STR
2164 "OSPF compatibility list\n"
2165 "compatible with RFC 1583\n")
2166{
cdc2d765 2167 VTY_DECLVAR_CONTEXT(ospf, ospf);
718e3744 2168
2169 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
2170 {
2171 UNSET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
d3a9c768 2172 ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
718e3744 2173 }
2174 return CMD_SUCCESS;
2175}
2176
7a7be519 2177ALIAS (ospf_compatible_rfc1583,
2178 ospf_rfc1583_flag_cmd,
2179 "ospf rfc1583compatibility",
2180 "OSPF specific commands\n"
2181 "Enable the RFC1583Compatibility flag\n")
718e3744 2182
7a7be519 2183ALIAS (no_ospf_compatible_rfc1583,
2184 no_ospf_rfc1583_flag_cmd,
2185 "no ospf rfc1583compatibility",
2186 NO_STR
2187 "OSPF specific commands\n"
2188 "Disable the RFC1583Compatibility flag\n")
6b0655a2 2189
d24f6e2a 2190static int
2191ospf_timers_spf_set (struct vty *vty, unsigned int delay,
2192 unsigned int hold,
2193 unsigned int max)
2194{
cdc2d765 2195 VTY_DECLVAR_CONTEXT(ospf, ospf);
7c8ff89e 2196
d24f6e2a 2197 ospf->spf_delay = delay;
2198 ospf->spf_holdtime = hold;
2199 ospf->spf_max_holdtime = max;
2200
2201 return CMD_SUCCESS;
2202}
718e3744 2203
ac7424f9
MR
2204DEFUN (ospf_timers_min_ls_interval,
2205 ospf_timers_min_ls_interval_cmd,
6147e2c6 2206 "timers throttle lsa all (0-5000)",
ac7424f9
MR
2207 "Adjust routing timers\n"
2208 "Throttling adaptive timer\n"
2209 "LSA delay between transmissions\n"
813d4307 2210 "All LSA types\n"
ac7424f9
MR
2211 "Delay (msec) between sending LSAs\n")
2212{
cdc2d765 2213 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2214 int idx_number = 4;
ac7424f9
MR
2215 unsigned int interval;
2216
2217 if (argc != 1)
2218 {
2219 vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE);
2220 return CMD_WARNING;
2221 }
2222
8d769265 2223 VTY_GET_INTEGER ("LSA interval", interval, argv[idx_number]->arg);
ac7424f9
MR
2224
2225 ospf->min_ls_interval = interval;
2226
2227 return CMD_SUCCESS;
2228}
2229
2230DEFUN (no_ospf_timers_min_ls_interval,
2231 no_ospf_timers_min_ls_interval_cmd,
7a7be519 2232 "no timers throttle lsa all [(0-5000)]",
ac7424f9
MR
2233 NO_STR
2234 "Adjust routing timers\n"
2235 "Throttling adaptive timer\n"
813d4307 2236 "LSA delay between transmissions\n"
7a7be519 2237 "All LSA types\n"
2238 "Delay (msec) between sending LSAs\n")
ac7424f9 2239{
cdc2d765 2240 VTY_DECLVAR_CONTEXT(ospf, ospf);
ac7424f9
MR
2241 ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL;
2242
2243 return CMD_SUCCESS;
2244}
2245
813d4307 2246
ac7424f9
MR
2247DEFUN (ospf_timers_min_ls_arrival,
2248 ospf_timers_min_ls_arrival_cmd,
6147e2c6 2249 "timers lsa arrival (0-1000)",
ac7424f9
MR
2250 "Adjust routing timers\n"
2251 "Throttling link state advertisement delays\n"
2252 "OSPF minimum arrival interval delay\n"
2253 "Delay (msec) between accepted LSAs\n")
2254{
cdc2d765 2255 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2256 int idx_number = 3;
ac7424f9
MR
2257 unsigned int arrival;
2258
2259 if (argc != 1)
2260 {
2261 vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE);
2262 return CMD_WARNING;
2263 }
2264
8d769265 2265 VTY_GET_INTEGER_RANGE ("minimum LSA inter-arrival time", arrival, argv[idx_number]->arg, 0, 1000);
ac7424f9
MR
2266
2267 ospf->min_ls_arrival = arrival;
2268
2269 return CMD_SUCCESS;
2270}
2271
2272DEFUN (no_ospf_timers_min_ls_arrival,
2273 no_ospf_timers_min_ls_arrival_cmd,
7a7be519 2274 "no timers lsa arrival [(0-1000)]",
ac7424f9
MR
2275 NO_STR
2276 "Adjust routing timers\n"
2277 "Throttling link state advertisement delays\n"
7a7be519 2278 "OSPF minimum arrival interval delay\n"
2279 "Delay (msec) between accepted LSAs\n")
ac7424f9 2280{
cdc2d765 2281 VTY_DECLVAR_CONTEXT(ospf, ospf);
d8f70b86 2282
ac7424f9
MR
2283 ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
2284
2285 return CMD_SUCCESS;
2286}
2287
813d4307 2288
d24f6e2a 2289DEFUN (ospf_timers_throttle_spf,
2290 ospf_timers_throttle_spf_cmd,
6147e2c6 2291 "timers throttle spf (0-600000) (0-600000) (0-600000)",
d24f6e2a 2292 "Adjust routing timers\n"
2293 "Throttling adaptive timer\n"
2294 "OSPF SPF timers\n"
2295 "Delay (msec) from first change received till SPF calculation\n"
2296 "Initial hold time (msec) between consecutive SPF calculations\n"
2297 "Maximum hold time (msec)\n")
2298{
8d769265
DW
2299 int idx_number = 3;
2300 int idx_number_2 = 4;
2301 int idx_number_3 = 5;
d24f6e2a 2302 unsigned int delay, hold, max;
2303
2304 if (argc != 3)
2305 {
2306 vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE);
2307 return CMD_WARNING;
2308 }
2309
8d769265
DW
2310 VTY_GET_INTEGER_RANGE ("SPF delay timer", delay, argv[idx_number]->arg, 0, 600000);
2311 VTY_GET_INTEGER_RANGE ("SPF hold timer", hold, argv[idx_number_2]->arg, 0, 600000);
2312 VTY_GET_INTEGER_RANGE ("SPF max-hold timer", max, argv[idx_number_3]->arg, 0, 600000);
d24f6e2a 2313
2314 return ospf_timers_spf_set (vty, delay, hold, max);
2315}
2316
d24f6e2a 2317DEFUN (no_ospf_timers_throttle_spf,
2318 no_ospf_timers_throttle_spf_cmd,
7a7be519 2319 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
718e3744 2320 NO_STR
2321 "Adjust routing timers\n"
d24f6e2a 2322 "Throttling adaptive timer\n"
7a7be519 2323 "OSPF SPF timers\n"
2324 "Delay (msec) from first change received till SPF calculation\n"
2325 "Initial hold time (msec) between consecutive SPF calculations\n"
2326 "Maximum hold time (msec)\n")
22b27e95 2327{
d24f6e2a 2328 return ospf_timers_spf_set (vty,
2329 OSPF_SPF_DELAY_DEFAULT,
2330 OSPF_SPF_HOLDTIME_DEFAULT,
2331 OSPF_SPF_MAX_HOLDTIME_DEFAULT);
718e3744 2332}
2333
b4a039bf 2334
b6927875
DS
2335DEFUN (ospf_timers_lsa,
2336 ospf_timers_lsa_cmd,
6147e2c6 2337 "timers lsa min-arrival (0-600000)",
b6927875
DS
2338 "Adjust routing timers\n"
2339 "OSPF LSA timers\n"
2340 "Minimum delay in receiving new version of a LSA\n"
2341 "Delay in milliseconds\n")
2342{
cdc2d765 2343 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2344 int idx_number = 3;
b6927875 2345 unsigned int minarrival;
b6927875 2346
b6927875
DS
2347 if (argc != 1)
2348 {
2349 vty_out (vty, "Insufficient number of arguments%s", VTY_NEWLINE);
2350 return CMD_WARNING;
2351 }
2352
8d769265 2353 VTY_GET_INTEGER ("LSA min-arrival", minarrival, argv[idx_number]->arg);
b6927875 2354
ac7424f9 2355 ospf->min_ls_arrival = minarrival;
b6927875
DS
2356
2357 return CMD_SUCCESS;
2358}
2359
2360DEFUN (no_ospf_timers_lsa,
2361 no_ospf_timers_lsa_cmd,
7a7be519 2362 "no timers lsa min-arrival [(0-600000)]",
b6927875
DS
2363 NO_STR
2364 "Adjust routing timers\n"
2365 "OSPF LSA timers\n"
7a7be519 2366 "Minimum delay in receiving new version of a LSA\n"
2367 "Delay in milliseconds\n")
b6927875 2368{
cdc2d765 2369 VTY_DECLVAR_CONTEXT(ospf, ospf);
b6927875 2370 unsigned int minarrival;
b6927875 2371
7a7be519 2372 if (argc > 4)
b6927875 2373 {
7a7be519 2374 VTY_GET_INTEGER ("LSA min-arrival", minarrival, argv[4]->arg);
b6927875 2375
ac7424f9 2376 if (ospf->min_ls_arrival != minarrival ||
b6927875
DS
2377 minarrival == OSPF_MIN_LS_ARRIVAL)
2378 return CMD_SUCCESS;
2379 }
2380
ac7424f9 2381 ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
b6927875
DS
2382
2383 return CMD_SUCCESS;
2384}
2385
a2c62831 2386DEFUN (ospf_neighbor,
2387 ospf_neighbor_cmd,
7a7be519 2388 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
718e3744 2389 NEIGHBOR_STR
7a7be519 2390 "Neighbor IP address\n"
2391 "Neighbor Priority\n"
2392 "Priority\n"
2393 "Dead Neighbor Polling interval\n"
2394 "Seconds\n")
718e3744 2395{
cdc2d765 2396 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2397 int idx_ipv4 = 1;
7a7be519 2398 int idx_pri = 3;
2399 int idx_poll = 5;
718e3744 2400 struct in_addr nbr_addr;
eb1ce605 2401 unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2402 unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
718e3744 2403
8d769265 2404 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2405
718e3744 2406 if (argc > 2)
7a7be519 2407 VTY_GET_INTEGER_RANGE ("neighbor priority", priority, argv[idx_pri]->arg, 0, 255);
2408
2409 if (argc > 4)
2410 VTY_GET_INTEGER_RANGE ("poll interval", interval, argv[idx_poll]->arg, 1, 65535);
718e3744 2411
2412 ospf_nbr_nbma_set (ospf, nbr_addr);
7a7be519 2413
718e3744 2414 if (argc > 2)
7a7be519 2415 ospf_nbr_nbma_priority_set (ospf, nbr_addr, priority);
2416
2417 if (argc > 4)
1a61ad10 2418 ospf_nbr_nbma_poll_interval_set (ospf, nbr_addr, interval);
718e3744 2419
2420 return CMD_SUCCESS;
2421}
2422
a2c62831 2423DEFUN (ospf_neighbor_poll_interval,
2424 ospf_neighbor_poll_interval_cmd,
7a7be519 2425 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
718e3744 2426 NEIGHBOR_STR
2427 "Neighbor IP address\n"
2428 "Dead Neighbor Polling interval\n"
7a7be519 2429 "Seconds\n"
2430 "OSPF priority of non-broadcast neighbor\n"
2431 "Priority\n")
22b27e95 2432{
cdc2d765 2433 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2434 int idx_ipv4 = 1;
7a7be519 2435 int idx_poll = 3;
2436 int idx_pri = 5;
718e3744 2437 struct in_addr nbr_addr;
eb1ce605 2438 unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2439 unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
718e3744 2440
8d769265 2441 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2442
7a7be519 2443 VTY_GET_INTEGER_RANGE ("poll interval", interval, argv[idx_poll]->arg, 1, 65535);
718e3744 2444
7a7be519 2445 if (argc > 4)
2446 VTY_GET_INTEGER_RANGE ("neighbor priority", priority, argv[idx_pri]->arg, 0, 255);
718e3744 2447
2448 ospf_nbr_nbma_set (ospf, nbr_addr);
7a7be519 2449 ospf_nbr_nbma_poll_interval_set (ospf, nbr_addr, interval);
2450
2451 if (argc > 4)
718e3744 2452 ospf_nbr_nbma_priority_set (ospf, nbr_addr, priority);
2453
2454 return CMD_SUCCESS;
2455}
2456
a2c62831 2457DEFUN (no_ospf_neighbor,
2458 no_ospf_neighbor_cmd,
7a7be519 2459 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
718e3744 2460 NO_STR
2461 NEIGHBOR_STR
7a7be519 2462 "Neighbor IP address\n"
2463 "Neighbor Priority\n"
2464 "Priority\n"
2465 "Dead Neighbor Polling interval\n"
2466 "Seconds\n")
718e3744 2467{
cdc2d765 2468 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2469 int idx_ipv4 = 2;
718e3744 2470 struct in_addr nbr_addr;
718e3744 2471
8d769265 2472 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2473
0798cee3 2474 (void)ospf_nbr_nbma_unset (ospf, nbr_addr);
718e3744 2475
2476 return CMD_SUCCESS;
2477}
2478
7a7be519 2479DEFUN (no_ospf_neighbor_poll,
2480 no_ospf_neighbor_poll_cmd,
2481 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2482 NO_STR
2483 NEIGHBOR_STR
2484 "Neighbor IP address\n"
2485 "Dead Neighbor Polling interval\n"
2486 "Seconds\n"
2487 "Neighbor Priority\n"
2488 "Priority\n")
2489{
cdc2d765 2490 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 2491 int idx_ipv4 = 2;
7a7be519 2492 struct in_addr nbr_addr;
2493
7a7be519 2494 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2495
7a7be519 2496 (void)ospf_nbr_nbma_unset (ospf, nbr_addr);
813d4307 2497
7a7be519 2498 return CMD_SUCCESS;
2499}
718e3744 2500
bf2bfafd
DW
2501DEFUN (ospf_refresh_timer,
2502 ospf_refresh_timer_cmd,
6147e2c6 2503 "refresh timer (10-1800)",
718e3744 2504 "Adjust refresh parameters\n"
2505 "Set refresh timer\n"
2506 "Timer value in seconds\n")
2507{
cdc2d765 2508 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2509 int idx_number = 2;
eb1ce605 2510 unsigned int interval;
7c8ff89e 2511
8d769265 2512 VTY_GET_INTEGER_RANGE ("refresh timer", interval, argv[idx_number]->arg, 10, 1800);
535c84b1 2513 interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) * OSPF_LSA_REFRESHER_GRANULARITY;
718e3744 2514
2515 ospf_timers_refresh_set (ospf, interval);
2516
2517 return CMD_SUCCESS;
2518}
2519
bf2bfafd
DW
2520DEFUN (no_ospf_refresh_timer,
2521 no_ospf_refresh_timer_val_cmd,
7a7be519 2522 "no refresh timer [(10-1800)]",
3a2d747c 2523 NO_STR
718e3744 2524 "Adjust refresh parameters\n"
2525 "Unset refresh timer\n"
2526 "Timer value in seconds\n")
2527{
cdc2d765 2528 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2529 int idx_number = 3;
eb1ce605 2530 unsigned int interval;
718e3744 2531
2532 if (argc == 1)
2533 {
8d769265 2534 VTY_GET_INTEGER_RANGE ("refresh timer", interval, argv[idx_number]->arg, 10, 1800);
718e3744 2535
2536 if (ospf->lsa_refresh_interval != interval ||
2537 interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
2538 return CMD_SUCCESS;
2539 }
2540
2541 ospf_timers_refresh_unset (ospf);
2542
2543 return CMD_SUCCESS;
2544}
2545
718e3744 2546
a2c62831 2547DEFUN (ospf_auto_cost_reference_bandwidth,
2548 ospf_auto_cost_reference_bandwidth_cmd,
6147e2c6 2549 "auto-cost reference-bandwidth (1-4294967)",
718e3744 2550 "Calculate OSPF interface cost according to bandwidth\n"
2551 "Use reference bandwidth method to assign OSPF cost\n"
2552 "The reference bandwidth in terms of Mbits per second\n")
2553{
cdc2d765 2554 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2555 int idx_number = 2;
718e3744 2556 u_int32_t refbw;
52dc7ee6 2557 struct listnode *node;
1eb8ef25 2558 struct interface *ifp;
718e3744 2559
8d769265 2560 refbw = strtol (argv[idx_number]->arg, NULL, 10);
718e3744 2561 if (refbw < 1 || refbw > 4294967)
2562 {
2563 vty_out (vty, "reference-bandwidth value is invalid%s", VTY_NEWLINE);
2564 return CMD_WARNING;
2565 }
2566
2567 /* If reference bandwidth is changed. */
70bd3c43 2568 if ((refbw) == ospf->ref_bandwidth)
718e3744 2569 return CMD_SUCCESS;
2570
70bd3c43 2571 ospf->ref_bandwidth = refbw;
1eb8ef25 2572 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
2573 ospf_if_recalculate_output_cost (ifp);
718e3744 2574
2575 return CMD_SUCCESS;
2576}
2577
a2c62831 2578DEFUN (no_ospf_auto_cost_reference_bandwidth,
2579 no_ospf_auto_cost_reference_bandwidth_cmd,
7a7be519 2580 "no auto-cost reference-bandwidth [(1-4294967)]",
718e3744 2581 NO_STR
2582 "Calculate OSPF interface cost according to bandwidth\n"
7a7be519 2583 "Use reference bandwidth method to assign OSPF cost\n"
2584 "The reference bandwidth in terms of Mbits per second\n")
718e3744 2585{
cdc2d765 2586 VTY_DECLVAR_CONTEXT(ospf, ospf);
1eb8ef25 2587 struct listnode *node, *nnode;
2588 struct interface *ifp;
718e3744 2589
68980084 2590 if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH)
718e3744 2591 return CMD_SUCCESS;
2592
68980084 2593 ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
718e3744 2594 vty_out (vty, "%% OSPF: Reference bandwidth is changed.%s", VTY_NEWLINE);
2595 vty_out (vty, " Please ensure reference bandwidth is consistent across all routers%s", VTY_NEWLINE);
2596
1eb8ef25 2597 for (ALL_LIST_ELEMENTS (om->iflist, node, nnode, ifp))
2598 ospf_if_recalculate_output_cost (ifp);
718e3744 2599
2600 return CMD_SUCCESS;
2601}
2602
2f8f370e
DS
2603DEFUN (ospf_write_multiplier,
2604 ospf_write_multiplier_cmd,
6147e2c6 2605 "ospf write-multiplier (1-100)",
e8f45e82
DS
2606 "OSPF specific commands\n"
2607 "Write multiplier\n"
2608 "Maximum number of interface serviced per write\n")
2f8f370e 2609{
cdc2d765 2610 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 2611 int idx_number;
e8f45e82 2612 u_int32_t write_oi_count;
2f8f370e 2613
7a7be519 2614 if (argc == 3)
2615 idx_number = 2;
2616 else
2617 idx_number = 1;
2618
8d769265 2619 write_oi_count = strtol (argv[idx_number]->arg, NULL, 10);
e8f45e82 2620 if (write_oi_count < 1 || write_oi_count > 100)
2f8f370e
DS
2621 {
2622 vty_out (vty, "write-multiplier value is invalid%s", VTY_NEWLINE);
2623 return CMD_WARNING;
2624 }
2625
e8f45e82 2626 ospf->write_oi_count = write_oi_count;
2f8f370e
DS
2627 return CMD_SUCCESS;
2628}
2629
7a7be519 2630ALIAS (ospf_write_multiplier,
2631 write_multiplier_cmd,
2632 "write-multiplier (1-100)",
2633 "Write multiplier\n"
2634 "Maximum number of interface serviced per write\n")
e8f45e82 2635
2f8f370e
DS
2636DEFUN (no_ospf_write_multiplier,
2637 no_ospf_write_multiplier_cmd,
6147e2c6 2638 "no ospf write-multiplier (1-100)",
2f8f370e 2639 NO_STR
e8f45e82 2640 "OSPF specific commands\n"
813d4307
DW
2641 "Write multiplier\n"
2642 "Maximum number of interface serviced per write\n")
2f8f370e 2643{
cdc2d765 2644 VTY_DECLVAR_CONTEXT(ospf, ospf);
2f8f370e 2645
e8f45e82 2646 ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
2f8f370e
DS
2647 return CMD_SUCCESS;
2648}
2649
7a7be519 2650ALIAS (no_ospf_write_multiplier,
2651 no_write_multiplier_cmd,
2652 "no write-multiplier (1-100)",
2653 NO_STR
2654 "Write multiplier\n"
2655 "Maximum number of interface serviced per write\n")
813d4307 2656
eb1ce605 2657const char *ospf_abr_type_descr_str[] =
718e3744 2658{
2659 "Unknown",
2660 "Standard (RFC2328)",
2661 "Alternative IBM",
2662 "Alternative Cisco",
2663 "Alternative Shortcut"
2664};
2665
eb1ce605 2666const char *ospf_shortcut_mode_descr_str[] =
718e3744 2667{
2668 "Default",
2669 "Enabled",
2670 "Disabled"
2671};
2672
4dadc291 2673static void
ca08c43d 2674show_ip_ospf_area (struct vty *vty, struct ospf_area *area, json_object *json_areas, u_char use_json)
718e3744 2675{
ca08c43d
DS
2676 json_object *json_area = NULL;
2677
2678 if (use_json)
2679 json_area = json_object_new_object();
2680
718e3744 2681 /* Show Area ID. */
ca08c43d
DS
2682 if (!use_json)
2683 vty_out (vty, " Area ID: %s", inet_ntoa (area->area_id));
718e3744 2684
2685 /* Show Area type/mode. */
2686 if (OSPF_IS_AREA_BACKBONE (area))
ca08c43d
DS
2687 {
2688 if (use_json)
2689 json_object_boolean_true_add(json_area, "backbone");
2690 else
2691 vty_out (vty, " (Backbone)%s", VTY_NEWLINE);
2692 }
718e3744 2693 else
2694 {
ca08c43d
DS
2695 if (use_json)
2696 {
2697 if (area->external_routing == OSPF_AREA_STUB)
2698 {
2699 if (area->no_summary)
2700 json_object_boolean_true_add(json_area, "stubNoSummary");
2701 if (area->shortcut_configured)
2702 json_object_boolean_true_add(json_area, "stubShortcut");
2703 }
2704 else if (area->external_routing == OSPF_AREA_NSSA)
2705 {
2706 if (area->no_summary)
2707 json_object_boolean_true_add(json_area, "nssaNoSummary");
2708 if (area->shortcut_configured)
2709 json_object_boolean_true_add(json_area, "nssaShortcut");
2710 }
2711
2712 json_object_string_add(json_area,"shortcuttingMode",
2713 ospf_shortcut_mode_descr_str[area->shortcut_configured]);
2714 if (area->shortcut_capability)
2715 json_object_boolean_true_add(json_area,"sBitConcensus");
2716 }
2717 else
2718 {
2719 if (area->external_routing == OSPF_AREA_STUB)
2720 vty_out (vty, " (Stub%s%s)",
2721 area->no_summary ? ", no summary" : "",
2722 area->shortcut_configured ? "; " : "");
2723 else if (area->external_routing == OSPF_AREA_NSSA)
2724 vty_out (vty, " (NSSA%s%s)",
2725 area->no_summary ? ", no summary" : "",
2726 area->shortcut_configured ? "; " : "");
2727
2728 vty_out (vty, "%s", VTY_NEWLINE);
2729 vty_out (vty, " Shortcutting mode: %s",
2730 ospf_shortcut_mode_descr_str[area->shortcut_configured]);
2731 vty_out (vty, ", S-bit consensus: %s%s",
2732 area->shortcut_capability ? "ok" : "no", VTY_NEWLINE);
2733 }
2734 }
2735
2736 /* Show number of interfaces */
2737 if (use_json)
2738 {
3ac237f8
MS
2739 json_object_int_add(json_area, "areaIfTotalCounter", listcount (area->oiflist));
2740 json_object_int_add(json_area, "areaIfActiveCounter", area->act_ints);
718e3744 2741 }
ca08c43d
DS
2742 else
2743 vty_out (vty, " Number of interfaces in this area: Total: %d, "
2744 "Active: %d%s", listcount (area->oiflist),
2745 area->act_ints, VTY_NEWLINE);
718e3744 2746
718e3744 2747 if (area->external_routing == OSPF_AREA_NSSA)
2748 {
ca08c43d
DS
2749 if (use_json)
2750 {
2751 json_object_boolean_true_add(json_area, "nssa");
2752 if (! IS_OSPF_ABR (area->ospf))
2753 json_object_boolean_false_add(json_area, "abr");
2754 else if (area->NSSATranslatorState)
2755 {
2756 json_object_boolean_true_add(json_area, "abr");
2757 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2758 json_object_boolean_true_add(json_area, "nssaTranslatorElected");
2759 else if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_ALWAYS)
2760 json_object_boolean_true_add(json_area, "nssaTranslatorAlways");
2761 }
2762 else
2763 {
2764 json_object_boolean_true_add(json_area, "abr");
2765 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2766 json_object_boolean_false_add(json_area, "nssaTranslatorElected");
2767 else
2768 json_object_boolean_true_add(json_area, "nssaTranslatorNever");
2769 }
2770 }
718e3744 2771 else
ca08c43d
DS
2772 {
2773 vty_out (vty, " It is an NSSA configuration. %s Elected NSSA/ABR performs type-7/type-5 LSA translation. %s", VTY_NEWLINE, VTY_NEWLINE);
2774 if (! IS_OSPF_ABR (area->ospf))
2775 vty_out (vty, " It is not ABR, therefore not Translator. %s",
2776 VTY_NEWLINE);
2777 else if (area->NSSATranslatorState)
2778 {
2779 vty_out (vty, " We are an ABR and ");
2780 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2781 vty_out (vty, "the NSSA Elected Translator. %s",
2782 VTY_NEWLINE);
2783 else if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_ALWAYS)
2784 vty_out (vty, "always an NSSA Translator. %s",
2785 VTY_NEWLINE);
2786 }
2787 else
2788 {
2789 vty_out (vty, " We are an ABR, but ");
2790 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2791 vty_out (vty, "not the NSSA Elected Translator. %s",
2792 VTY_NEWLINE);
2793 else
2794 vty_out (vty, "never an NSSA Translator. %s",
2795 VTY_NEWLINE);
2796 }
2797 }
718e3744 2798 }
ca08c43d 2799
88d6cf37 2800 /* Stub-router state for this area */
2801 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
2802 {
649654ab 2803 char timebuf[OSPF_TIME_DUMP_SIZE];
ca08c43d
DS
2804
2805 if (use_json)
2806 {
2807 json_object_boolean_true_add(json_area, "originStubMaxDistRouterLsa");
2808 if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
2809 json_object_boolean_true_add(json_area, "indefiniteActiveAdmin");
2810 if (area->t_stub_router)
2811 {
cbf3e3eb
DL
2812 long time_store;
2813 time_store = monotime_until(&area->t_stub_router->u.sands, NULL) / 1000LL;
ca08c43d
DS
2814 json_object_int_add(json_area, "activeStartupRemainderMsecs", time_store);
2815 }
2816 }
2817 else
2818 {
2819 vty_out (vty, " Originating stub / maximum-distance Router-LSA%s",
2820 VTY_NEWLINE);
2821 if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
2822 vty_out (vty, " Administratively activated (indefinitely)%s",
2823 VTY_NEWLINE);
2824 if (area->t_stub_router)
2825 vty_out (vty, " Active from startup, %s remaining%s",
2826 ospf_timer_dump (area->t_stub_router, timebuf,
2827 sizeof(timebuf)), VTY_NEWLINE);
2828 }
2829 }
2830
2831 if (use_json)
2832 {
2833 /* Show number of fully adjacent neighbors. */
3ac237f8 2834 json_object_int_add(json_area, "nbrFullAdjacentCounter", area->full_nbrs);
ca08c43d
DS
2835
2836 /* Show authentication type. */
2837 if (area->auth_type == OSPF_AUTH_NULL)
2838 json_object_string_add(json_area, "authentication", "authenticationNone");
2839 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2840 json_object_string_add(json_area, "authentication", "authenticationSimplePassword");
2841 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2842 json_object_string_add(json_area, "authentication", "authenticationMessageDigest");
2843
2844 if (!OSPF_IS_AREA_BACKBONE (area))
3ac237f8 2845 json_object_int_add(json_area, "virtualAdjacenciesPassingCounter", area->full_vls);
ca08c43d
DS
2846
2847 /* Show SPF calculation times. */
3ac237f8 2848 json_object_int_add(json_area, "spfExecutedCounter", area->spf_calculation);
ca08c43d
DS
2849 json_object_int_add(json_area, "lsaNumber", area->lsdb->total);
2850 json_object_int_add(json_area, "lsaRouterNumber", ospf_lsdb_count (area->lsdb, OSPF_ROUTER_LSA));
2851 json_object_int_add(json_area, "lsaRouterChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_ROUTER_LSA));
2852 json_object_int_add(json_area, "lsaNetworkNumber", ospf_lsdb_count (area->lsdb, OSPF_NETWORK_LSA));
2853 json_object_int_add(json_area, "lsaNetworkChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_NETWORK_LSA));
2854 json_object_int_add(json_area, "lsaSummaryNumber", ospf_lsdb_count (area->lsdb, OSPF_SUMMARY_LSA));
2855 json_object_int_add(json_area, "lsaSummaryChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_SUMMARY_LSA));
2856 json_object_int_add(json_area, "lsaAsbrNumber", ospf_lsdb_count (area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2857 json_object_int_add(json_area, "lsaAsbrChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2858 json_object_int_add(json_area, "lsaNssaNumber", ospf_lsdb_count (area->lsdb, OSPF_AS_NSSA_LSA));
2859 json_object_int_add(json_area, "lsaNssaChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_AS_NSSA_LSA));
88d6cf37 2860 }
ca08c43d
DS
2861 else
2862 {
2863 /* Show number of fully adjacent neighbors. */
2864 vty_out (vty, " Number of fully adjacent neighbors in this area:"
2865 " %d%s", area->full_nbrs, VTY_NEWLINE);
2866
2867 /* Show authentication type. */
2868 vty_out (vty, " Area has ");
2869 if (area->auth_type == OSPF_AUTH_NULL)
2870 vty_out (vty, "no authentication%s", VTY_NEWLINE);
2871 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2872 vty_out (vty, "simple password authentication%s", VTY_NEWLINE);
2873 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2874 vty_out (vty, "message digest authentication%s", VTY_NEWLINE);
2875
2876 if (!OSPF_IS_AREA_BACKBONE (area))
2877 vty_out (vty, " Number of full virtual adjacencies going through"
2878 " this area: %d%s", area->full_vls, VTY_NEWLINE);
2879
2880 /* Show SPF calculation times. */
2881 vty_out (vty, " SPF algorithm executed %d times%s",
2882 area->spf_calculation, VTY_NEWLINE);
2883
2884 /* Show number of LSA. */
2885 vty_out (vty, " Number of LSA %ld%s", area->lsdb->total, VTY_NEWLINE);
2886 vty_out (vty, " Number of router LSA %ld. Checksum Sum 0x%08x%s",
2887 ospf_lsdb_count (area->lsdb, OSPF_ROUTER_LSA),
2888 ospf_lsdb_checksum (area->lsdb, OSPF_ROUTER_LSA), VTY_NEWLINE);
2889 vty_out (vty, " Number of network LSA %ld. Checksum Sum 0x%08x%s",
2890 ospf_lsdb_count (area->lsdb, OSPF_NETWORK_LSA),
2891 ospf_lsdb_checksum (area->lsdb, OSPF_NETWORK_LSA), VTY_NEWLINE);
2892 vty_out (vty, " Number of summary LSA %ld. Checksum Sum 0x%08x%s",
2893 ospf_lsdb_count (area->lsdb, OSPF_SUMMARY_LSA),
2894 ospf_lsdb_checksum (area->lsdb, OSPF_SUMMARY_LSA), VTY_NEWLINE);
2895 vty_out (vty, " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x%s",
2896 ospf_lsdb_count (area->lsdb, OSPF_ASBR_SUMMARY_LSA),
2897 ospf_lsdb_checksum (area->lsdb, OSPF_ASBR_SUMMARY_LSA), VTY_NEWLINE);
2898 vty_out (vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x%s",
2899 ospf_lsdb_count (area->lsdb, OSPF_AS_NSSA_LSA),
2900 ospf_lsdb_checksum (area->lsdb, OSPF_AS_NSSA_LSA), VTY_NEWLINE);
2901 }
2902
ca08c43d
DS
2903 if (use_json)
2904 {
2905 json_object_int_add(json_area, "lsaOpaqueLinkNumber", ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_LINK_LSA));
2906 json_object_int_add(json_area, "lsaOpaqueLinkChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_LINK_LSA));
2907 json_object_int_add(json_area, "lsaOpaqueAreaNumber", ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_AREA_LSA));
2908 json_object_int_add(json_area, "lsaOpaqueAreaChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_AREA_LSA));
2909 }
2910 else
2911 {
2912 vty_out (vty, " Number of opaque link LSA %ld. Checksum Sum 0x%08x%s",
2913 ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_LINK_LSA),
2914 ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_LINK_LSA), VTY_NEWLINE);
2915 vty_out (vty, " Number of opaque area LSA %ld. Checksum Sum 0x%08x%s",
2916 ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_AREA_LSA),
2917 ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_AREA_LSA), VTY_NEWLINE);
2918 }
ca08c43d
DS
2919
2920 if (use_json)
2921 json_object_object_add(json_areas, inet_ntoa (area->area_id), json_area);
2922 else
2923 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 2924}
2925
7c8ff89e 2926static int
ca08c43d 2927show_ip_ospf_common (struct vty *vty, struct ospf *ospf, u_char use_json)
718e3744 2928{
1eb8ef25 2929 struct listnode *node, *nnode;
718e3744 2930 struct ospf_area * area;
d24f6e2a 2931 struct timeval result;
649654ab 2932 char timebuf[OSPF_TIME_DUMP_SIZE];
ca08c43d
DS
2933 json_object *json = NULL;
2934 json_object *json_areas = NULL;
2935
2936 if (use_json)
0cad6e26
DS
2937 {
2938 json = json_object_new_object();
2939 json_areas = json_object_new_object();
2940 }
718e3744 2941
7c8ff89e 2942 if (ospf->instance)
ca08c43d
DS
2943 {
2944 if (use_json)
2945 {
2946 json_object_int_add(json, "ospfInstance", ospf->instance);
2947 }
2948 else
2949 {
2950 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
2951 VTY_NEWLINE, VTY_NEWLINE);
2952 }
2953 }
718e3744 2954
2955 /* Show Router ID. */
ca08c43d
DS
2956 if (use_json)
2957 {
2958 json_object_string_add(json, "routerId", inet_ntoa (ospf->router_id));
2959 }
2960 else
2961 {
2962 vty_out (vty, " OSPF Routing Process, Router ID: %s%s",
2963 inet_ntoa (ospf->router_id),
2964 VTY_NEWLINE);
2965 }
7c8ff89e 2966
88d6cf37 2967 /* Graceful shutdown */
c9c93d50 2968 if (ospf->t_deferred_shutdown)
ca08c43d
DS
2969 {
2970 if (use_json)
2971 {
cbf3e3eb
DL
2972 long time_store;
2973 time_store = monotime_until(&ospf->t_deferred_shutdown->u.sands, NULL) / 1000LL;
ca08c43d
DS
2974 json_object_int_add(json, "deferredShutdownMsecs", time_store);
2975 }
2976 else
2977 {
2978 vty_out (vty, " Deferred shutdown in progress, %s remaining%s",
2979 ospf_timer_dump (ospf->t_deferred_shutdown,
2980 timebuf, sizeof (timebuf)), VTY_NEWLINE);
2981 }
2982 }
2983
718e3744 2984 /* Show capability. */
ca08c43d
DS
2985 if (use_json)
2986 {
2987 json_object_boolean_true_add(json, "tosRoutesOnly");
2988 json_object_boolean_true_add(json, "rfc2328Conform");
2989 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
2990 {
2991 json_object_boolean_true_add(json, "rfc1583Compatibility");
2992 }
2993 }
2994 else
2995 {
2996 vty_out (vty, " Supports only single TOS (TOS0) routes%s", VTY_NEWLINE);
2997 vty_out (vty, " This implementation conforms to RFC2328%s", VTY_NEWLINE);
2998 vty_out (vty, " RFC1583Compatibility flag is %s%s",
2999 CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE) ?
3000 "enabled" : "disabled", VTY_NEWLINE);
3001 }
3002
ca08c43d
DS
3003 if (use_json)
3004 {
3005 if (CHECK_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE))
3006 {
3007 json_object_boolean_true_add(json, "opaqueCapable");
3008 }
ca08c43d
DS
3009 }
3010 else
3011 {
801e0e14 3012 vty_out (vty, " OpaqueCapability flag is %s%s",
ca08c43d 3013 CHECK_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE) ? "enabled" : "disabled",
ca08c43d
DS
3014 VTY_NEWLINE);
3015 }
ca08c43d 3016
88d6cf37 3017 /* Show stub-router configuration */
3018 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED
3019 || ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3020 {
ca08c43d
DS
3021 if (use_json)
3022 {
3023 json_object_boolean_true_add(json, "stubAdvertisement");
3024 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3025 json_object_int_add(json,"postStartEnabledMsecs", ospf->stub_router_startup_time / 1000);
3026 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3027 json_object_int_add(json,"preShutdownEnabledMsecs", ospf->stub_router_shutdown_time / 1000);
3028 }
3029 else
3030 {
3031 vty_out (vty, " Stub router advertisement is configured%s",
3032 VTY_NEWLINE);
3033 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3034 vty_out (vty, " Enabled for %us after start-up%s",
3035 ospf->stub_router_startup_time, VTY_NEWLINE);
3036 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3037 vty_out (vty, " Enabled for %us prior to full shutdown%s",
3038 ospf->stub_router_shutdown_time, VTY_NEWLINE);
3039 }
88d6cf37 3040 }
ca08c43d 3041
718e3744 3042 /* Show SPF timers. */
ca08c43d
DS
3043 if (use_json)
3044 {
3045 json_object_int_add(json, "spfScheduleDelayMsecs", ospf->spf_delay);
3046 json_object_int_add(json, "holdtimeMinMsecs", ospf->spf_holdtime);
3047 json_object_int_add(json, "holdtimeMaxMsecs", ospf->spf_max_holdtime);
3048 json_object_int_add(json, "holdtimeMultplier", ospf->spf_hold_multiplier);
b8ad39d4 3049 }
3050 else
ca08c43d
DS
3051 {
3052 vty_out (vty, " Initial SPF scheduling delay %d millisec(s)%s"
3053 " Minimum hold time between consecutive SPFs %d millisec(s)%s"
3054 " Maximum hold time between consecutive SPFs %d millisec(s)%s"
3055 " Hold time multiplier is currently %d%s",
3056 ospf->spf_delay, VTY_NEWLINE,
3057 ospf->spf_holdtime, VTY_NEWLINE,
3058 ospf->spf_max_holdtime, VTY_NEWLINE,
3059 ospf->spf_hold_multiplier, VTY_NEWLINE);
3060 }
b6927875 3061
ca08c43d
DS
3062 if (use_json)
3063 {
3064 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec)
3065 {
cbf3e3eb 3066 long time_store = 0;
ca08c43d 3067
cbf3e3eb 3068 time_store = monotime_since(&ospf->ts_spf, NULL) / 1000LL;
ca08c43d
DS
3069 json_object_int_add(json, "spfLastExecutedMsecs", time_store);
3070
3071 time_store = (1000 * ospf->ts_spf_duration.tv_sec) + (ospf->ts_spf_duration.tv_usec / 1000);
3072 json_object_int_add(json, "spfLastDurationMsecs", time_store);
3073 }
3074 else
3075 json_object_boolean_true_add(json, "spfHasNotRun");
3076 }
3077 else
3078 {
3079 vty_out (vty, " SPF algorithm ");
3080 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec)
3081 {
cbf3e3eb 3082 monotime_since(&ospf->ts_spf, &result);
ca08c43d
DS
3083 vty_out (vty, "last executed %s ago%s",
3084 ospf_timeval_dump (&result, timebuf, sizeof (timebuf)),
3085 VTY_NEWLINE);
3086 vty_out (vty, " Last SPF duration %s%s",
3087 ospf_timeval_dump (&ospf->ts_spf_duration, timebuf, sizeof (timebuf)),
3088 VTY_NEWLINE);
3089 }
3090 else
3091 vty_out (vty, "has not been run%s", VTY_NEWLINE);
3092 }
3093
3094 if (use_json)
3095 {
ca08c43d
DS
3096 if (ospf->t_spf_calc)
3097 {
cbf3e3eb
DL
3098 long time_store;
3099 time_store = monotime_until(&ospf->t_spf_calc->u.sands, NULL) / 1000LL;
ca08c43d
DS
3100 json_object_int_add(json, "spfTimerDueInMsecs", time_store);
3101 }
3102
ac7424f9
MR
3103 json_object_int_add(json, "lsaMinIntervalMsecs", ospf->min_ls_interval);
3104 json_object_int_add(json, "lsaMinArrivalMsecs", ospf->min_ls_arrival);
ca08c43d
DS
3105 /* Show write multiplier values */
3106 json_object_int_add(json, "writeMultiplier", ospf->write_oi_count);
3107 /* Show refresh parameters. */
54b7214f 3108 json_object_int_add(json, "refreshTimerMsecs", ospf->lsa_refresh_interval * 1000);
ca08c43d
DS
3109 }
3110 else
3111 {
3112 vty_out (vty, " SPF timer %s%s%s",
3113 (ospf->t_spf_calc ? "due in " : "is "),
3114 ospf_timer_dump (ospf->t_spf_calc, timebuf, sizeof (timebuf)),
3115 VTY_NEWLINE);
3116
ac7424f9
MR
3117 vty_out (vty, " LSA minimum interval %d msecs%s",
3118 ospf->min_ls_interval, VTY_NEWLINE);
ca08c43d 3119 vty_out (vty, " LSA minimum arrival %d msecs%s",
ac7424f9 3120 ospf->min_ls_arrival, VTY_NEWLINE);
ca08c43d
DS
3121
3122 /* Show write multiplier values */
3123 vty_out (vty, " Write Multiplier set to %d %s",
3124 ospf->write_oi_count, VTY_NEWLINE);
3125
3126 /* Show refresh parameters. */
3127 vty_out (vty, " Refresh timer %d secs%s",
3128 ospf->lsa_refresh_interval, VTY_NEWLINE);
3129 }
2f8f370e 3130
718e3744 3131 /* Show ABR/ASBR flags. */
68980084 3132 if (CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR))
ca08c43d
DS
3133 {
3134 if (use_json)
3135 json_object_string_add(json, "abrType", ospf_abr_type_descr_str[ospf->abr_type]);
3136 else
3137 vty_out (vty, " This router is an ABR, ABR type is: %s%s",
3138 ospf_abr_type_descr_str[ospf->abr_type], VTY_NEWLINE);
3139 }
68980084 3140 if (CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR))
ca08c43d
DS
3141 {
3142 if (use_json)
3143 json_object_string_add(json, "asbrRouter", "injectingExternalRoutingInformation");
3144 else
3145 vty_out (vty, " This router is an ASBR "
3146 "(injecting external routing information)%s", VTY_NEWLINE);
3147 }
718e3744 3148
3149 /* Show Number of AS-external-LSAs. */
ca08c43d
DS
3150 if (use_json)
3151 {
3ac237f8 3152 json_object_int_add(json, "lsaExternalCounter",
ca08c43d
DS
3153 ospf_lsdb_count (ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3154 json_object_int_add(json, "lsaExternalChecksum",
3155 ospf_lsdb_checksum (ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3156 }
3157 else
3158 {
3159 vty_out (vty, " Number of external LSA %ld. Checksum Sum 0x%08x%s",
3160 ospf_lsdb_count (ospf->lsdb, OSPF_AS_EXTERNAL_LSA),
3161 ospf_lsdb_checksum (ospf->lsdb, OSPF_AS_EXTERNAL_LSA), VTY_NEWLINE);
3162 }
3163
ca08c43d
DS
3164 if (use_json)
3165 {
3ac237f8 3166 json_object_int_add(json, "lsaAsopaqueCounter",
ca08c43d
DS
3167 ospf_lsdb_count (ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3168 json_object_int_add(json, "lsaAsOpaqueChecksum",
3169 ospf_lsdb_checksum (ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3170 }
3171 else
3172 {
3173 vty_out (vty, " Number of opaque AS LSA %ld. Checksum Sum 0x%08x%s",
3174 ospf_lsdb_count (ospf->lsdb, OSPF_OPAQUE_AS_LSA),
3175 ospf_lsdb_checksum (ospf->lsdb, OSPF_OPAQUE_AS_LSA), VTY_NEWLINE);
3176 }
ca08c43d 3177
718e3744 3178 /* Show number of areas attached. */
ca08c43d 3179 if (use_json)
3ac237f8 3180 json_object_int_add(json, "attachedAreaCounter", listcount (ospf->areas));
ca08c43d
DS
3181 else
3182 vty_out (vty, " Number of areas attached to this router: %d%s",
3183 listcount (ospf->areas), VTY_NEWLINE);
d7e60dd7
AS
3184
3185 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES))
3186 {
3187 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
ca08c43d
DS
3188 {
3189 if (use_json)
3190 json_object_boolean_true_add(json, "adjacencyChangesLoggedAll");
3191 else
3192 vty_out(vty, " All adjacency changes are logged%s",VTY_NEWLINE);
3193 }
d7e60dd7 3194 else
ca08c43d
DS
3195 {
3196 if (use_json)
3197 json_object_boolean_true_add(json, "adjacencyChangesLogged");
3198 else
3199 vty_out(vty, " Adjacency changes are logged%s",VTY_NEWLINE);
3200 }
d7e60dd7 3201 }
718e3744 3202 /* Show each area status. */
1eb8ef25 3203 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
ca08c43d
DS
3204 show_ip_ospf_area (vty, area, json_areas, use_json);
3205
3206 if (use_json)
3207 {
3208 json_object_object_add(json, "areas", json_areas);
2aac5767 3209 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
ca08c43d
DS
3210 json_object_free(json);
3211 }
3212 else
3213 vty_out (vty, "%s",VTY_NEWLINE);
718e3744 3214
3215 return CMD_SUCCESS;
3216}
3217
7c8ff89e
DS
3218DEFUN (show_ip_ospf,
3219 show_ip_ospf_cmd,
b162fa78 3220 "show ip ospf [json]",
7c8ff89e
DS
3221 SHOW_STR
3222 IP_STR
ca08c43d 3223 "OSPF information\n"
9973d184 3224 JSON_STR)
7c8ff89e
DS
3225{
3226 struct ospf *ospf;
db7c8528 3227 u_char uj = use_json(argc, argv);
7c8ff89e 3228
0bad4851 3229 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3230 return CMD_SUCCESS;
3231
db7c8528 3232 return (show_ip_ospf_common(vty, ospf, uj));
7c8ff89e
DS
3233}
3234
3235DEFUN (show_ip_ospf_instance,
3236 show_ip_ospf_instance_cmd,
6147e2c6 3237 "show ip ospf (1-65535) [json]",
7c8ff89e
DS
3238 SHOW_STR
3239 IP_STR
3240 "OSPF information\n"
ca08c43d 3241 "Instance ID\n"
9973d184 3242 JSON_STR)
7c8ff89e 3243{
8d769265 3244 int idx_number = 3;
7c8ff89e
DS
3245 struct ospf *ospf;
3246 u_short instance = 0;
db7c8528 3247 u_char uj = use_json(argc, argv);
7c8ff89e 3248
8d769265 3249 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3250 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3251 return CMD_SUCCESS;
3252
db7c8528 3253 return (show_ip_ospf_common(vty, ospf, uj));
7c8ff89e
DS
3254}
3255
fd651fa6 3256static void
7ec4159b
DS
3257show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface *ifp,
3258 json_object *json_interface_sub, u_char use_json)
718e3744 3259{
fd651fa6 3260 int is_up;
718e3744 3261 struct ospf_neighbor *nbr;
718e3744 3262 struct route_node *rn;
718e3744 3263
718e3744 3264 /* Is interface up? */
7ec4159b
DS
3265 if (use_json)
3266 {
3267 is_up = if_is_operative(ifp);
3268 if (is_up)
3269 json_object_boolean_true_add(json_interface_sub, "ifUp");
3270 else
3271 json_object_boolean_false_add(json_interface_sub, "ifDown");
3272
3273 json_object_int_add(json_interface_sub, "ifIndex", ifp->ifindex);
3274 json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu);
70bd3c43 3275 json_object_int_add(json_interface_sub, "bandwidthMbit", ifp->bandwidth);
7ec4159b
DS
3276 json_object_string_add(json_interface_sub, "ifFlags", if_flag_dump(ifp->flags));
3277 }
3278 else
3279 {
3280 vty_out (vty, "%s is %s%s", ifp->name,
3281 ((is_up = if_is_operative(ifp)) ? "up" : "down"), VTY_NEWLINE);
70bd3c43 3282 vty_out (vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s%s",
7ec4159b
DS
3283 ifp->ifindex, ifp->mtu, ifp->bandwidth, if_flag_dump(ifp->flags),
3284 VTY_NEWLINE);
3285 }
718e3744 3286
3287 /* Is interface OSPF enabled? */
7ec4159b 3288 if (use_json)
718e3744 3289 {
7ec4159b
DS
3290 if (ospf_oi_count(ifp) == 0)
3291 {
3292 json_object_boolean_false_add(json_interface_sub, "ospfEnabled");
3293 return;
3294 }
3295 else if (!is_up)
3296 {
3297 json_object_boolean_false_add(json_interface_sub, "ospfRunning");
3298 return;
3299 }
3300 else
3301 json_object_boolean_true_add(json_interface_sub, "ospfEnabled");
718e3744 3302 }
7ec4159b 3303 else
fd651fa6 3304 {
7ec4159b
DS
3305 if (ospf_oi_count(ifp) == 0)
3306 {
3307 vty_out (vty, " OSPF not enabled on this interface%s", VTY_NEWLINE);
3308 return;
3309 }
3310 else if (!is_up)
3311 {
3312 vty_out (vty, " OSPF is enabled, but not running on this interface%s",
3313 VTY_NEWLINE);
3314 return;
3315 }
fd651fa6 3316 }
3317
718e3744 3318 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
3319 {
3320 struct ospf_interface *oi = rn->info;
7ec4159b 3321
718e3744 3322 if (oi == NULL)
7ec4159b
DS
3323 continue;
3324
525c1839
DS
3325 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
3326 {
7ec4159b
DS
3327 if (use_json)
3328 json_object_boolean_true_add(json_interface_sub, "ifUnnumbered");
3329 else
3330 vty_out (vty, " This interface is UNNUMBERED,");
525c1839
DS
3331 }
3332 else
9c27ef9b 3333 {
525c1839 3334 /* Show OSPF interface information. */
7ec4159b
DS
3335 if (use_json)
3336 {
3337 json_object_string_add(json_interface_sub, "ipAddress", inet_ntoa (oi->address->u.prefix4));
3338 json_object_int_add(json_interface_sub, "ipAddressPrefixlen", oi->address->prefixlen);
3339 }
3340 else
3341 vty_out (vty, " Internet Address %s/%d,",
3342 inet_ntoa (oi->address->u.prefix4), oi->address->prefixlen);
525c1839
DS
3343
3344 if (oi->connected->destination || oi->type == OSPF_IFTYPE_VIRTUALLINK)
3345 {
3346 struct in_addr *dest;
3347 const char *dstr;
3348
3349 if (CONNECTED_PEER(oi->connected)
3350 || oi->type == OSPF_IFTYPE_VIRTUALLINK)
3351 dstr = "Peer";
3352 else
3353 dstr = "Broadcast";
3354
3355 /* For Vlinks, showing the peer address is probably more
7ec4159b
DS
3356 * * * * * informative than the local interface that is being used
3357 * * * * */
525c1839
DS
3358 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3359 dest = &oi->vl_data->peer_addr;
3360 else
3361 dest = &oi->connected->destination->u.prefix4;
3362
7ec4159b
DS
3363 if (use_json)
3364 {
3365 json_object_string_add(json_interface_sub, "ospfIfType", dstr);
3366 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3367 json_object_string_add(json_interface_sub, "vlinkPeer", inet_ntoa (*dest));
3368 else
3369 json_object_string_add(json_interface_sub, "localIfUsed", inet_ntoa (*dest));
3370 }
3371 else
3372 vty_out (vty, " %s %s,", dstr, inet_ntoa (*dest));
525c1839 3373 }
9c27ef9b 3374 }
7ec4159b
DS
3375 if (use_json)
3376 {
3377 json_object_string_add(json_interface_sub, "area", ospf_area_desc_string (oi->area));
3378 if (OSPF_IF_PARAM(oi, mtu_ignore))
3379 json_object_boolean_true_add(json_interface_sub, "mtuMismatchDetect");
3380 json_object_string_add(json_interface_sub, "routerId", inet_ntoa (ospf->router_id));
3381 json_object_string_add(json_interface_sub, "networkType", ospf_network_type_str[oi->type]);
3382 json_object_int_add(json_interface_sub, "cost", oi->output_cost);
3383 json_object_int_add(json_interface_sub, "transmitDelayMsecs", 1000 / OSPF_IF_PARAM (oi,transmit_delay));
3384 json_object_string_add(json_interface_sub, "state", LOOKUP (ospf_ism_state_msg, oi->state));
3385 json_object_int_add(json_interface_sub, "priority", PRIORITY (oi));
3386 }
3387 else
3388 {
3389 vty_out (vty, " Area %s%s", ospf_area_desc_string (oi->area),
3390 VTY_NEWLINE);
3fb9cd6e 3391
7ec4159b
DS
3392 vty_out (vty, " MTU mismatch detection:%s%s",
3393 OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" : "enabled", VTY_NEWLINE);
ba682537 3394
7ec4159b
DS
3395 vty_out (vty, " Router ID %s, Network Type %s, Cost: %d%s",
3396 inet_ntoa (ospf->router_id), ospf_network_type_str[oi->type],
3397 oi->output_cost, VTY_NEWLINE);
718e3744 3398
7ec4159b
DS
3399 vty_out (vty, " Transmit Delay is %d sec, State %s, Priority %d%s",
3400 OSPF_IF_PARAM (oi,transmit_delay), LOOKUP (ospf_ism_state_msg, oi->state),
3401 PRIORITY (oi), VTY_NEWLINE);
3402 }
718e3744 3403
3404 /* Show DR information. */
3405 if (DR (oi).s_addr == 0)
7ec4159b
DS
3406 {
3407 if (!use_json)
3408 vty_out (vty, " No backup designated router on this network%s",
3409 VTY_NEWLINE);
3410 }
718e3744 3411 else
7ec4159b
DS
3412 {
3413 nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &BDR (oi));
3414 if (nbr == NULL)
3415 {
3416 if (!use_json)
3417 vty_out (vty, " No backup designated router on this network%s",
3418 VTY_NEWLINE);
3419 }
3420 else
3421 {
3422 if (use_json)
3423 {
3424 json_object_string_add(json_interface_sub, "bdrId", inet_ntoa (nbr->router_id));
3425 json_object_string_add(json_interface_sub, "bdrAddress", inet_ntoa (nbr->address.u.prefix4));
3426 }
3427 else
3428 {
3429 vty_out (vty, " Backup Designated Router (ID) %s,",
3430 inet_ntoa (nbr->router_id));
3431 vty_out (vty, " Interface Address %s%s",
3432 inet_ntoa (nbr->address.u.prefix4), VTY_NEWLINE);
3433 }
3434 }
3435 }
525c1839 3436
7eb5b47e 3437 /* Next network-LSA sequence number we'll use, if we're elected DR */
7ec4159b 3438 if (oi->params && ntohl (oi->params->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER)
429ac78c 3439 {
7ec4159b
DS
3440 if (use_json)
3441 json_object_int_add(json_interface_sub, "networkLsaSequence", ntohl (oi->params->network_lsa_seqnum));
3442 else
3443 vty_out (vty, " Saved Network-LSA sequence number 0x%x%s",
3444 ntohl (oi->params->network_lsa_seqnum), VTY_NEWLINE);
3445 }
3446
3447 if (use_json)
3448 {
3449 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3450 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3451 {
3452 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3453 json_object_boolean_true_add(json_interface_sub, "mcastMemberOspfAllRouters");
3454 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3455 json_object_boolean_true_add(json_interface_sub, "mcastMemberOspfDesignatedRouters");
3456 }
429ac78c
PJ
3457 }
3458 else
7ec4159b
DS
3459 {
3460 vty_out (vty, " Multicast group memberships:");
3461 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3462 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3463 {
3464 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3465 vty_out (vty, " OSPFAllRouters");
3466 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3467 vty_out (vty, " OSPFDesignatedRouters");
3468 }
3469 else
3470 vty_out (vty, " <None>");
3471 vty_out (vty, "%s", VTY_NEWLINE);
3472 }
ba6454ec 3473
7ec4159b
DS
3474 if (use_json)
3475 {
3476 if (OSPF_IF_PARAM (oi, fast_hello) == 0)
3477 json_object_int_add(json_interface_sub, "timerMsecs", 1000 /OSPF_IF_PARAM (oi, v_hello));
3478 else
3479 json_object_int_add(json_interface_sub, "timerMsecs", 1000 / OSPF_IF_PARAM (oi, fast_hello));
3480 json_object_int_add(json_interface_sub, "timerDeadMsecs", 1000 / OSPF_IF_PARAM (oi, v_wait));
3481 json_object_int_add(json_interface_sub, "timerWaitMsecs", 1000 / OSPF_IF_PARAM (oi, v_wait));
3482 json_object_int_add(json_interface_sub, "timerRetransmit", 1000 / OSPF_IF_PARAM (oi, retransmit_interval));
3483 }
f9ad937f 3484 else
7ec4159b
DS
3485 {
3486 vty_out (vty, " Timer intervals configured,");
3487 vty_out (vty, " Hello ");
3488 if (OSPF_IF_PARAM (oi, fast_hello) == 0)
3489 vty_out (vty, "%ds,", OSPF_IF_PARAM (oi, v_hello));
3490 else
3491 vty_out (vty, "%dms,", 1000 / OSPF_IF_PARAM (oi, fast_hello));
3492 vty_out (vty, " Dead %ds, Wait %ds, Retransmit %d%s",
3493 OSPF_IF_PARAM (oi, v_wait),
3494 OSPF_IF_PARAM (oi, v_wait),
3495 OSPF_IF_PARAM (oi, retransmit_interval),
3496 VTY_NEWLINE);
3497 }
3498
7ffa8fa2 3499 if (OSPF_IF_PASSIVE_STATUS (oi) == OSPF_IF_ACTIVE)
f9ad937f 3500 {
7ec4159b
DS
3501 char timebuf[OSPF_TIME_DUMP_SIZE];
3502 if (use_json)
3503 {
cbf3e3eb
DL
3504 long time_store = 0;
3505 if (oi->t_hello)
3506 time_store = monotime_until(&oi->t_hello->u.sands, NULL) / 1000LL;
7ec4159b
DS
3507 json_object_int_add(json_interface_sub, "timerHelloInMsecs", time_store);
3508 }
3509 else
3510 vty_out (vty, " Hello due in %s%s",
3511 ospf_timer_dump (oi->t_hello, timebuf, sizeof(timebuf)),
3512 VTY_NEWLINE);
f9ad937f 3513 }
7ffa8fa2 3514 else /* passive-interface is set */
7ec4159b
DS
3515 {
3516 if (use_json)
3517 json_object_boolean_true_add(json_interface_sub, "timerPassiveIface");
3518 else
3519 vty_out (vty, " No Hellos (Passive interface)%s", VTY_NEWLINE);
3520 }
3521
3522 if (use_json)
3523 {
3524 json_object_int_add(json_interface_sub, "nbrCount", ospf_nbr_count (oi, 0));
3525 json_object_int_add(json_interface_sub, "nbrAdjacentCount", ospf_nbr_count (oi, NSM_Full));
3526 }
3527 else
3528 vty_out (vty, " Neighbor Count is %d, Adjacent neighbor count is %d%s",
3529 ospf_nbr_count (oi, 0), ospf_nbr_count (oi, NSM_Full),
3530 VTY_NEWLINE);
68fe91d6 3531 ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json);
718e3744 3532 }
3533}
3534
7c8ff89e 3535static int
7ec4159b 3536show_ip_ospf_interface_common (struct vty *vty, struct ospf *ospf, int argc,
7a7be519 3537 struct cmd_token **argv, int iface_argv, u_char use_json)
718e3744 3538{
3539 struct interface *ifp;
52dc7ee6 3540 struct listnode *node;
7ec4159b
DS
3541 json_object *json = NULL;
3542 json_object *json_interface_sub = NULL;
3543
3544 if (use_json)
3545 {
3546 json = json_object_new_object();
3547 json_interface_sub = json_object_new_object();
3548 }
718e3744 3549
7c8ff89e 3550 if (ospf->instance)
7ec4159b
DS
3551 {
3552 if (use_json)
3553 json_object_int_add(json, "ospfInstance", ospf->instance);
3554 else
3555 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3556 VTY_NEWLINE, VTY_NEWLINE);
3557 }
7c8ff89e 3558
6be4da3d 3559 if (argc == iface_argv)
7ec4159b
DS
3560 {
3561 /* Show All Interfaces.*/
b2d7c082 3562 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
7ec4159b
DS
3563 {
3564 if (ospf_oi_count(ifp))
3565 {
3566 show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
b8dfa544
DS
3567 if (use_json)
3568 json_object_object_add (json, ifp->name, json_interface_sub);
7ec4159b
DS
3569 }
3570 }
3571 }
718e3744 3572 else
3573 {
7c8ff89e 3574 /* Interface name is specified. */
1306c09a 3575 if ((ifp = if_lookup_by_name (argv[iface_argv]->arg, VRF_DEFAULT)) == NULL)
7ec4159b
DS
3576 {
3577 if (use_json)
3578 json_object_boolean_true_add(json, "noSuchIface");
3579 else
3580 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
3581 }
718e3744 3582 else
7ec4159b
DS
3583 {
3584 show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
3585 if (use_json)
3586 json_object_object_add(json, ifp->name, json_interface_sub);
3587 }
718e3744 3588 }
3589
7ec4159b
DS
3590 if (use_json)
3591 {
2aac5767 3592 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
7ec4159b
DS
3593 json_object_free(json);
3594 }
3595 else
3596 vty_out (vty, "%s", VTY_NEWLINE);
7c8ff89e 3597
718e3744 3598 return CMD_SUCCESS;
3599}
3600
7c8ff89e
DS
3601DEFUN (show_ip_ospf_interface,
3602 show_ip_ospf_interface_cmd,
b162fa78 3603 "show ip ospf interface [INTERFACE] [json]",
7c8ff89e
DS
3604 SHOW_STR
3605 IP_STR
3606 "OSPF information\n"
3607 "Interface information\n"
7ec4159b 3608 "Interface name\n"
9973d184 3609 JSON_STR)
7c8ff89e
DS
3610{
3611 struct ospf *ospf;
db7c8528 3612 u_char uj = use_json(argc, argv);
7c8ff89e 3613
0bad4851 3614 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3615 return CMD_SUCCESS;
3616
6be4da3d
DS
3617 if (uj)
3618 argc--;
3619
3620 return show_ip_ospf_interface_common(vty, ospf, argc, argv, 4, uj);
7c8ff89e
DS
3621}
3622
3623DEFUN (show_ip_ospf_instance_interface,
3624 show_ip_ospf_instance_interface_cmd,
6147e2c6 3625 "show ip ospf (1-65535) interface [INTERFACE] [json]",
7c8ff89e
DS
3626 SHOW_STR
3627 IP_STR
3628 "OSPF information\n"
3629 "Instance ID\n"
3630 "Interface information\n"
7ec4159b 3631 "Interface name\n"
9973d184 3632 JSON_STR)
7c8ff89e 3633{
8d769265 3634 int idx_number = 3;
7c8ff89e
DS
3635 struct ospf *ospf;
3636 u_short instance = 0;
db7c8528 3637 u_char uj = use_json(argc, argv);
7c8ff89e 3638
8d769265 3639 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3640 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3641 return CMD_SUCCESS;
3642
6be4da3d
DS
3643 if (uj)
3644 argc--;
3645
3646 return show_ip_ospf_interface_common(vty, ospf, argc, argv, 5, uj);
7c8ff89e
DS
3647}
3648
d24f6e2a 3649static void
3650show_ip_ospf_neighbour_header (struct vty *vty)
3651{
490578f3 3652 vty_out (vty, "%s%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s%s",
d24f6e2a 3653 VTY_NEWLINE,
3654 "Neighbor ID", "Pri", "State", "Dead Time",
3655 "Address", "Interface", "RXmtL", "RqstL", "DBsmL",
3656 VTY_NEWLINE);
3657}
3658
4dadc291 3659static void
91756b38 3660show_ip_ospf_neighbor_sub (struct vty *vty, struct ospf_interface *oi, json_object *json, u_char use_json)
718e3744 3661{
3662 struct route_node *rn;
3663 struct ospf_neighbor *nbr;
3664 char msgbuf[16];
649654ab 3665 char timebuf[OSPF_TIME_DUMP_SIZE];
91756b38 3666 json_object *json_neighbor = NULL;
718e3744 3667
3668 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
91756b38
DS
3669 {
3670 if ((nbr = rn->info))
3671 {
3672 /* Do not show myself. */
3673 if (nbr != oi->nbr_self)
3674 {
3675 /* Down state is not shown. */
3676 if (nbr->state != NSM_Down)
3677 {
3678 if (use_json)
3679 {
3680 json_neighbor = json_object_new_object();
3681 ospf_nbr_state_message (nbr, msgbuf, 16);
3682
cbf3e3eb 3683 long time_store;
91756b38 3684
cbf3e3eb 3685 time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
91756b38
DS
3686
3687 json_object_int_add (json_neighbor, "priority", nbr->priority);
3688 json_object_string_add (json_neighbor, "state", msgbuf);
3689 json_object_int_add (json_neighbor, "deadTimeMsecs", time_store);
3690 json_object_string_add (json_neighbor, "address", inet_ntoa (nbr->src));
3691 json_object_string_add (json_neighbor, "ifaceName", IF_NAME (oi));
3ac237f8
MS
3692 json_object_int_add (json_neighbor, "retransmitCounter", ospf_ls_retransmit_count (nbr));
3693 json_object_int_add (json_neighbor, "requestCounter", ospf_ls_request_count (nbr));
3694 json_object_int_add (json_neighbor, "dbSummaryCounter", ospf_db_summary_count (nbr));
91756b38
DS
3695 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
3696 json_object_object_add(json, "neighbor", json_neighbor);
3697 else
3698 json_object_object_add(json, inet_ntoa (nbr->router_id), json_neighbor);
3699 }
3700 else
3701 {
3702 ospf_nbr_state_message (nbr, msgbuf, 16);
3703
3704 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
3705 vty_out (vty, "%-15s %3d %-15s ",
3706 "-", nbr->priority,
3707 msgbuf);
3708 else
3709 vty_out (vty, "%-15s %3d %-15s ",
3710 inet_ntoa (nbr->router_id), nbr->priority,
3711 msgbuf);
3712
3713 vty_out (vty, "%9s ",
3714 ospf_timer_dump (nbr->t_inactivity, timebuf,
3715 sizeof(timebuf)));
3716 vty_out (vty, "%-15s ", inet_ntoa (nbr->src));
3717 vty_out (vty, "%-20s %5ld %5ld %5d%s",
3718 IF_NAME (oi), ospf_ls_retransmit_count (nbr),
3719 ospf_ls_request_count (nbr), ospf_db_summary_count (nbr),
3720 VTY_NEWLINE);
3721 }
3722 }
3723 }
3724 }
3725 }
718e3744 3726}
3727
7c8ff89e 3728static int
91756b38 3729show_ip_ospf_neighbor_common (struct vty *vty, struct ospf *ospf, u_char use_json)
718e3744 3730{
1eb8ef25 3731 struct ospf_interface *oi;
52dc7ee6 3732 struct listnode *node;
91756b38 3733 json_object *json = NULL;
718e3744 3734
91756b38
DS
3735 if (use_json)
3736 json = json_object_new_object();
3737 else
3738 show_ip_ospf_neighbour_header (vty);
718e3744 3739
91756b38
DS
3740 if (ospf->instance)
3741 {
3742 if (use_json)
3743 json_object_int_add(json, "ospfInstance", ospf->instance);
3744 else
3745 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3746 VTY_NEWLINE, VTY_NEWLINE);
3747 }
718e3744 3748
1eb8ef25 3749 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
91756b38 3750 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
718e3744 3751
91756b38
DS
3752 if (use_json)
3753 {
2aac5767 3754 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
91756b38
DS
3755 json_object_free(json);
3756 }
3757 else
3758 vty_out (vty, "%s", VTY_NEWLINE);
7c8ff89e 3759
718e3744 3760 return CMD_SUCCESS;
3761}
3762
7c8ff89e
DS
3763DEFUN (show_ip_ospf_neighbor,
3764 show_ip_ospf_neighbor_cmd,
b162fa78 3765 "show ip ospf neighbor [json]",
718e3744 3766 SHOW_STR
3767 IP_STR
3768 "OSPF information\n"
91756b38 3769 "Neighbor list\n"
9973d184 3770 JSON_STR)
718e3744 3771{
7c8ff89e 3772 struct ospf *ospf;
db7c8528 3773 u_char uj = use_json(argc, argv);
718e3744 3774
0bad4851 3775 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3776 return CMD_SUCCESS;
3777
db7c8528 3778 return show_ip_ospf_neighbor_common(vty, ospf, uj);
7c8ff89e
DS
3779}
3780
3781
3782DEFUN (show_ip_ospf_instance_neighbor,
3783 show_ip_ospf_instance_neighbor_cmd,
6147e2c6 3784 "show ip ospf (1-65535) neighbor [json]",
7c8ff89e
DS
3785 SHOW_STR
3786 IP_STR
3787 "OSPF information\n"
3788 "Instance ID\n"
91756b38 3789 "Neighbor list\n"
9973d184 3790 JSON_STR)
7c8ff89e 3791{
8d769265 3792 int idx_number = 3;
7c8ff89e
DS
3793 struct ospf *ospf;
3794 u_short instance = 0;
db7c8528 3795 u_char uj = use_json(argc, argv);
7c8ff89e 3796
8d769265 3797 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3798 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3799 return CMD_SUCCESS;
3800
db7c8528 3801 return show_ip_ospf_neighbor_common(vty, ospf, uj);
7c8ff89e
DS
3802}
3803
3804static int
91756b38 3805show_ip_ospf_neighbor_all_common (struct vty *vty, struct ospf *ospf, u_char use_json)
7c8ff89e
DS
3806{
3807 struct listnode *node;
3808 struct ospf_interface *oi;
91756b38
DS
3809 json_object *json = NULL;
3810 json_object *json_neighbor_sub = NULL;
7c8ff89e 3811
91756b38
DS
3812 if (use_json)
3813 {
3814 json = json_object_new_object();
3815 json_neighbor_sub = json_object_new_object();
3816 }
3817 else
3818 show_ip_ospf_neighbour_header (vty);
7c8ff89e 3819
91756b38
DS
3820 if (ospf->instance)
3821 {
3822 if (use_json)
3823 json_object_int_add(json, "ospfInstance", ospf->instance);
3824 else
3825 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3826 VTY_NEWLINE, VTY_NEWLINE);
3827 }
7c8ff89e
DS
3828
3829 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
3830 {
52dc7ee6 3831 struct listnode *nbr_node;
1eb8ef25 3832 struct ospf_nbr_nbma *nbr_nbma;
718e3744 3833
91756b38 3834 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
718e3744 3835
91756b38
DS
3836 /* print Down neighbor status */
3837 for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nbr_node, nbr_nbma))
3838 {
3839 if (nbr_nbma->nbr == NULL
3840 || nbr_nbma->nbr->state == NSM_Down)
3841 {
3842 if (use_json)
3843 {
3844 json_object_int_add (json_neighbor_sub, "nbrNbmaPriority", nbr_nbma->priority);
3845 json_object_boolean_true_add (json_neighbor_sub, "nbrNbmaDown");
3846 json_object_string_add (json_neighbor_sub, "nbrNbmaIfaceName", IF_NAME (oi));
3ac237f8
MS
3847 json_object_int_add (json_neighbor_sub, "nbrNbmaRetransmitCounter", 0);
3848 json_object_int_add (json_neighbor_sub, "nbrNbmaRequestCounter", 0);
3849 json_object_int_add (json_neighbor_sub, "nbrNbmaDbSummaryCounter", 0);
91756b38
DS
3850 json_object_object_add(json, inet_ntoa (nbr_nbma->addr), json_neighbor_sub);
3851 }
3852 else
3853 {
3854 vty_out (vty, "%-15s %3d %-15s %9s ",
3855 "-", nbr_nbma->priority, "Down", "-");
3856 vty_out (vty, "%-15s %-20s %5d %5d %5d%s",
3857 inet_ntoa (nbr_nbma->addr), IF_NAME (oi),
3858 0, 0, 0, VTY_NEWLINE);
3859 }
3860 }
3861 }
718e3744 3862 }
3863
91756b38
DS
3864 if (use_json)
3865 {
2aac5767 3866 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
91756b38
DS
3867 json_object_free(json);
3868 }
3869 else
3870 vty_out (vty, "%s", VTY_NEWLINE);
7c8ff89e 3871
718e3744 3872 return CMD_SUCCESS;
3873}
3874
7c8ff89e
DS
3875DEFUN (show_ip_ospf_neighbor_all,
3876 show_ip_ospf_neighbor_all_cmd,
b162fa78 3877 "show ip ospf neighbor all [json]",
718e3744 3878 SHOW_STR
3879 IP_STR
3880 "OSPF information\n"
3881 "Neighbor list\n"
91756b38 3882 "include down status neighbor\n"
9973d184 3883 JSON_STR)
7c8ff89e
DS
3884{
3885 struct ospf *ospf;
db7c8528 3886 u_char uj = use_json(argc, argv);
7c8ff89e 3887
0bad4851 3888 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3889 return CMD_SUCCESS;
3890
db7c8528 3891 return show_ip_ospf_neighbor_all_common(vty, ospf, uj);
7c8ff89e
DS
3892}
3893
3894DEFUN (show_ip_ospf_instance_neighbor_all,
3895 show_ip_ospf_instance_neighbor_all_cmd,
6147e2c6 3896 "show ip ospf (1-65535) neighbor all [json]",
7c8ff89e
DS
3897 SHOW_STR
3898 IP_STR
3899 "OSPF information\n"
3900 "Instance ID\n"
3901 "Neighbor list\n"
91756b38 3902 "include down status neighbor\n"
9973d184 3903 JSON_STR)
718e3744 3904{
8d769265 3905 int idx_number = 3;
020709f9 3906 struct ospf *ospf;
7c8ff89e 3907 u_short instance = 0;
db7c8528 3908 u_char uj = use_json(argc, argv);
7c8ff89e 3909
8d769265 3910 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3911 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3912 return CMD_SUCCESS;
3913
db7c8528 3914 return show_ip_ospf_neighbor_all_common(vty, ospf, uj);
7c8ff89e
DS
3915}
3916
3917static int
3918show_ip_ospf_neighbor_int_common (struct vty *vty, struct ospf *ospf, int arg_base,
7a7be519 3919 struct cmd_token **argv, u_char use_json)
7c8ff89e 3920{
bb5b7552 3921 struct interface *ifp;
3922 struct route_node *rn;
91756b38
DS
3923 json_object *json = NULL;
3924
3925 if (use_json)
3926 json = json_object_new_object();
3927 else
3928 show_ip_ospf_neighbour_header (vty);
7c8ff89e
DS
3929
3930 if (ospf->instance)
91756b38
DS
3931 {
3932 if (use_json)
3933 json_object_int_add(json, "ospfInstance", ospf->instance);
3934 else
3935 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3936 VTY_NEWLINE, VTY_NEWLINE);
3937 }
7c8ff89e 3938
1306c09a 3939 ifp = if_lookup_by_name (argv[arg_base]->arg, VRF_DEFAULT);
bb5b7552 3940 if (!ifp)
718e3744 3941 {
91756b38
DS
3942 if (use_json)
3943 json_object_boolean_true_add(json, "noSuchIface");
3944 else
3945 vty_out (vty, "No such interface.%s", VTY_NEWLINE);
718e3744 3946 return CMD_WARNING;
3947 }
d24f6e2a 3948
bb5b7552 3949 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
718e3744 3950 {
bb5b7552 3951 struct ospf_interface *oi = rn->info;
3952
3953 if (oi == NULL)
91756b38 3954 continue;
bb5b7552 3955
91756b38 3956 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
718e3744 3957 }
3958
91756b38
DS
3959 if (use_json)
3960 {
2aac5767 3961 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
91756b38
DS
3962 json_object_free(json);
3963 }
3964 else
3965 vty_out (vty, "%s", VTY_NEWLINE);
3966
718e3744 3967 return CMD_SUCCESS;
3968}
3969
7c8ff89e
DS
3970DEFUN (show_ip_ospf_neighbor_int,
3971 show_ip_ospf_neighbor_int_cmd,
b162fa78 3972 "show ip ospf neighbor IFNAME [json]",
7c8ff89e
DS
3973 SHOW_STR
3974 IP_STR
3975 "OSPF information\n"
3976 "Neighbor list\n"
91756b38 3977 "Interface name\n"
9973d184 3978 JSON_STR)
7c8ff89e
DS
3979{
3980 struct ospf *ospf;
db7c8528 3981 u_char uj = use_json(argc, argv);
7c8ff89e 3982
0bad4851 3983 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3984 return CMD_SUCCESS;
3985
db7c8528 3986 return show_ip_ospf_neighbor_int_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
3987}
3988
3989DEFUN (show_ip_ospf_instance_neighbor_int,
3990 show_ip_ospf_instance_neighbor_int_cmd,
6147e2c6 3991 "show ip ospf (1-65535) neighbor IFNAME [json]",
7c8ff89e
DS
3992 SHOW_STR
3993 IP_STR
3994 "OSPF information\n"
3995 "Instance ID\n"
3996 "Neighbor list\n"
91756b38 3997 "Interface name\n"
9973d184 3998 JSON_STR)
7c8ff89e 3999{
8d769265 4000 int idx_number = 3;
7c8ff89e
DS
4001 struct ospf *ospf;
4002 u_short instance = 0;
db7c8528 4003 u_char uj = use_json(argc, argv);
7c8ff89e 4004
8d769265 4005 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4006 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4007 return CMD_SUCCESS;
4008
db7c8528 4009 return show_ip_ospf_neighbor_int_common(vty, ospf, 1, argv, uj);
7c8ff89e
DS
4010}
4011
4dadc291 4012static void
3ac237f8
MS
4013show_ip_ospf_nbr_nbma_detail_sub (struct vty *vty, struct ospf_interface *oi, struct ospf_nbr_nbma *nbr_nbma,
4014 u_char use_json, json_object *json)
718e3744 4015{
649654ab 4016 char timebuf[OSPF_TIME_DUMP_SIZE];
3ac237f8 4017 json_object *json_sub = NULL;
718e3744 4018
3ac237f8
MS
4019 if (use_json)
4020 json_sub = json_object_new_object();
4021 else /* Show neighbor ID. */
4022 vty_out (vty, " Neighbor %s,", "-");
718e3744 4023
4024 /* Show interface address. */
3ac237f8
MS
4025 if (use_json)
4026 json_object_string_add(json_sub, "ifaceAddress", inet_ntoa (nbr_nbma->addr));
4027 else
4028 vty_out (vty, " interface address %s%s",
4029 inet_ntoa (nbr_nbma->addr), VTY_NEWLINE);
4030
718e3744 4031 /* Show Area ID. */
3ac237f8
MS
4032 if (use_json)
4033 {
4034 json_object_string_add(json_sub, "areaId", ospf_area_desc_string (oi->area));
4035 json_object_string_add(json_sub, "iface", IF_NAME (oi));
4036 }
4037 else
4038 vty_out (vty, " In the area %s via interface %s%s",
4039 ospf_area_desc_string (oi->area), IF_NAME (oi), VTY_NEWLINE);
4040
718e3744 4041 /* Show neighbor priority and state. */
3ac237f8
MS
4042 if (use_json)
4043 {
4044 json_object_int_add(json_sub, "nbrPriority", nbr_nbma->priority);
4045 json_object_string_add(json_sub, "nbrState", "down");
4046 }
4047 else
4048 vty_out (vty, " Neighbor priority is %d, State is %s,",
4049 nbr_nbma->priority, "Down");
4050
718e3744 4051 /* Show state changes. */
3ac237f8
MS
4052 if (use_json)
4053 json_object_int_add(json_sub, "stateChangeCounter", nbr_nbma->state_change);
4054 else
4055 vty_out (vty, " %d state changes%s", nbr_nbma->state_change, VTY_NEWLINE);
718e3744 4056
4057 /* Show PollInterval */
3ac237f8
MS
4058 if (use_json)
4059 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
4060 else
4061 vty_out (vty, " Poll interval %d%s", nbr_nbma->v_poll, VTY_NEWLINE);
718e3744 4062
4063 /* Show poll-interval timer. */
3ac237f8
MS
4064 if (use_json)
4065 {
cbf3e3eb
DL
4066 long time_store;
4067 time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL) / 1000LL;
3ac237f8
MS
4068 json_object_int_add(json_sub, "pollIntervalTimerDueMsec", time_store);
4069 }
4070 else
4071 vty_out (vty, " Poll timer due in %s%s",
4072 ospf_timer_dump (nbr_nbma->t_poll, timebuf, sizeof(timebuf)),
4073 VTY_NEWLINE);
718e3744 4074
4075 /* Show poll-interval timer thread. */
3ac237f8
MS
4076 if (use_json)
4077 {
4078 if (nbr_nbma->t_poll != NULL)
4079 json_object_string_add(json_sub, "pollIntervalTimerThread", "on");
4080 }
4081 else
4082 vty_out (vty, " Thread Poll Timer %s%s",
4083 nbr_nbma->t_poll != NULL ? "on" : "off", VTY_NEWLINE);
4084
4085 if (use_json)
4086 json_object_object_add(json, "noNbrId", json_sub);
718e3744 4087}
4088
4dadc291 4089static void
718e3744 4090show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi,
3ac237f8 4091 struct ospf_neighbor *nbr, u_char use_json, json_object *json)
718e3744 4092{
649654ab 4093 char timebuf[OSPF_TIME_DUMP_SIZE];
3ac237f8 4094 json_object *json_sub = NULL;
718e3744 4095
3ac237f8
MS
4096 if (use_json)
4097 json_sub = json_object_new_object();
718e3744 4098 else
3ac237f8
MS
4099 {
4100 /* Show neighbor ID. */
4101 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4102 vty_out (vty, " Neighbor %s,", "-");
4103 else
4104 vty_out (vty, " Neighbor %s,", inet_ntoa (nbr->router_id));
4105 }
718e3744 4106
4107 /* Show interface address. */
3ac237f8
MS
4108 if (use_json)
4109 json_object_string_add(json_sub, "ifaceAddress", inet_ntoa (nbr->address.u.prefix4));
4110 else
4111 vty_out (vty, " interface address %s%s",
4112 inet_ntoa (nbr->address.u.prefix4), VTY_NEWLINE);
4113
718e3744 4114 /* Show Area ID. */
3ac237f8
MS
4115 if (use_json)
4116 {
4117 json_object_string_add(json_sub, "areaId", ospf_area_desc_string (oi->area));
4118 json_object_string_add(json_sub, "ifaceName", oi->ifp->name);
4119 }
4120 else
4121 vty_out (vty, " In the area %s via interface %s%s",
4122 ospf_area_desc_string (oi->area), oi->ifp->name, VTY_NEWLINE);
4123
718e3744 4124 /* Show neighbor priority and state. */
3ac237f8
MS
4125 if (use_json)
4126 {
4127 json_object_int_add(json_sub, "nbrPriority", nbr->priority);
4128 json_object_string_add(json_sub, "nbrState", LOOKUP (ospf_nsm_state_msg, nbr->state));
4129 }
4130 else
4131 vty_out (vty, " Neighbor priority is %d, State is %s,",
4132 nbr->priority, LOOKUP (ospf_nsm_state_msg, nbr->state));
4133
718e3744 4134 /* Show state changes. */
3ac237f8
MS
4135 if (use_json)
4136 json_object_int_add(json_sub, "stateChangeCounter", nbr->state_change);
4137 else
4138 vty_out (vty, " %d state changes%s", nbr->state_change, VTY_NEWLINE);
4139
3fed4160 4140 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
90c33177 4141 {
cbf3e3eb
DL
4142 struct timeval res;
4143 long time_store;
4144
4145 time_store = monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
3ac237f8
MS
4146 if (use_json)
4147 {
3ac237f8
MS
4148 json_object_int_add(json_sub, "lastPrgrsvChangeMsec", time_store);
4149 }
4150 else
4151 {
4152 vty_out (vty, " Most recent state change statistics:%s",
4153 VTY_NEWLINE);
4154 vty_out (vty, " Progressive change %s ago%s",
4155 ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
4156 VTY_NEWLINE);
4157 }
3fed4160 4158 }
3ac237f8 4159
3fed4160
PJ
4160 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec)
4161 {
cbf3e3eb
DL
4162 struct timeval res;
4163 long time_store;
4164
4165 time_store = monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
3ac237f8
MS
4166 if (use_json)
4167 {
3ac237f8
MS
4168 json_object_int_add(json_sub, "lastRegressiveChangeMsec", time_store);
4169 if (nbr->last_regress_str)
4170 json_object_string_add(json_sub, "lastRegressiveChangeReason", nbr->last_regress_str);
4171 }
4172 else
4173 {
4174 vty_out (vty, " Regressive change %s ago, due to %s%s",
4175 ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
4176 (nbr->last_regress_str ? nbr->last_regress_str : "??"),
4177 VTY_NEWLINE);
4178 }
90c33177 4179 }
3ac237f8 4180
718e3744 4181 /* Show Designated Rotuer ID. */
3ac237f8
MS
4182 if (use_json)
4183 json_object_string_add(json_sub, "routerDesignatedId", inet_ntoa (nbr->d_router));
4184 else
4185 vty_out (vty, " DR is %s,", inet_ntoa (nbr->d_router));
4186
718e3744 4187 /* Show Backup Designated Rotuer ID. */
3ac237f8
MS
4188 if (use_json)
4189 json_object_string_add(json_sub, "routerDesignatedBackupId", inet_ntoa (nbr->bd_router));
4190 else
4191 vty_out (vty, " BDR is %s%s", inet_ntoa (nbr->bd_router), VTY_NEWLINE);
4192
718e3744 4193 /* Show options. */
3ac237f8
MS
4194 if (use_json)
4195 {
4196 json_object_int_add(json_sub, "optionsCounter", nbr->options);
4197 json_object_string_add(json_sub, "optionsList", ospf_options_dump (nbr->options));
4198 }
4199 else
4200 vty_out (vty, " Options %d %s%s", nbr->options,
4201 ospf_options_dump (nbr->options), VTY_NEWLINE);
4202
718e3744 4203 /* Show Router Dead interval timer. */
3ac237f8
MS
4204 if (use_json)
4205 {
45d430e8
DS
4206 if (nbr->t_inactivity)
4207 {
cbf3e3eb
DL
4208 long time_store;
4209 time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
45d430e8
DS
4210 json_object_int_add(json_sub, "routerDeadIntervalTimerDueMsec", time_store);
4211 }
4212 else
4213 json_object_int_add(json_sub, "routerDeadIntervalTimerDueMsec", -1);
3ac237f8
MS
4214 }
4215 else
4216 vty_out (vty, " Dead timer due in %s%s",
4217 ospf_timer_dump (nbr->t_inactivity, timebuf, sizeof (timebuf)),
4218 VTY_NEWLINE);
4219
718e3744 4220 /* Show Database Summary list. */
3ac237f8
MS
4221 if (use_json)
4222 json_object_int_add(json_sub, "databaseSummaryListCounter", ospf_db_summary_count (nbr));
4223 else
4224 vty_out (vty, " Database Summary List %d%s",
4225 ospf_db_summary_count (nbr), VTY_NEWLINE);
4226
718e3744 4227 /* Show Link State Request list. */
3ac237f8
MS
4228 if (use_json)
4229 json_object_int_add(json_sub, "linkStateRequestListCounter", ospf_ls_request_count (nbr));
4230 else
4231 vty_out (vty, " Link State Request List %ld%s",
4232 ospf_ls_request_count (nbr), VTY_NEWLINE);
4233
718e3744 4234 /* Show Link State Retransmission list. */
3ac237f8
MS
4235 if (use_json)
4236 json_object_int_add(json_sub, "linkStateRetransmissionListCounter", ospf_ls_retransmit_count (nbr));
4237 else
4238 vty_out (vty, " Link State Retransmission List %ld%s",
4239 ospf_ls_retransmit_count (nbr), VTY_NEWLINE);
4240
718e3744 4241 /* Show inactivity timer thread. */
3ac237f8
MS
4242 if (use_json)
4243 {
4244 if (nbr->t_inactivity != NULL)
4245 json_object_string_add(json_sub, "threadInactivityTimer", "on");
4246 }
4247 else
4248 vty_out (vty, " Thread Inactivity Timer %s%s",
4249 nbr->t_inactivity != NULL ? "on" : "off", VTY_NEWLINE);
4250
718e3744 4251 /* Show Database Description retransmission thread. */
3ac237f8
MS
4252 if (use_json)
4253 {
4254 if (nbr->t_db_desc != NULL)
4255 json_object_string_add(json_sub, "threadDatabaseDescriptionRetransmission", "on");
4256 }
4257 else
4258 vty_out (vty, " Thread Database Description Retransmision %s%s",
4259 nbr->t_db_desc != NULL ? "on" : "off", VTY_NEWLINE);
4260
718e3744 4261 /* Show Link State Request Retransmission thread. */
3ac237f8
MS
4262 if (use_json)
4263 {
4264 if (nbr->t_ls_req != NULL)
4265 json_object_string_add(json_sub, "threadLinkStateRequestRetransmission", "on");
4266 }
4267 else
4268 vty_out (vty, " Thread Link State Request Retransmission %s%s",
4269 nbr->t_ls_req != NULL ? "on" : "off", VTY_NEWLINE);
4270
718e3744 4271 /* Show Link State Update Retransmission thread. */
3ac237f8
MS
4272 if (use_json)
4273 {
4274 if (nbr->t_ls_upd != NULL)
4275 json_object_string_add(json_sub, "threadLinkStateUpdateRetransmission", "on");
4276 }
4277 else
4278 vty_out (vty, " Thread Link State Update Retransmission %s%s%s",
4279 nbr->t_ls_upd != NULL ? "on" : "off", VTY_NEWLINE, VTY_NEWLINE);
4280
4281 if (use_json)
4282 {
4283 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4284 json_object_object_add(json, "noNbrId", json_sub);
4285 else
4286 json_object_object_add(json, inet_ntoa (nbr->router_id), json_sub);
4287 }
68fe91d6 4288
4289 ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0);
718e3744 4290}
4291
7c8ff89e
DS
4292static int
4293show_ip_ospf_neighbor_id_common (struct vty *vty, struct ospf *ospf,
7a7be519 4294 int arg_base, struct cmd_token **argv, u_char use_json)
718e3744 4295{
52dc7ee6 4296 struct listnode *node;
718e3744 4297 struct ospf_neighbor *nbr;
1eb8ef25 4298 struct ospf_interface *oi;
718e3744 4299 struct in_addr router_id;
4300 int ret;
3ac237f8
MS
4301 json_object *json = NULL;
4302
4303 if (use_json)
4304 json = json_object_new_object();
718e3744 4305
7c8ff89e 4306 if (ospf->instance)
3ac237f8
MS
4307 {
4308 if (use_json)
4309 json_object_int_add(json, "ospfInstance", ospf->instance);
4310 else
4311 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4312 VTY_NEWLINE, VTY_NEWLINE);
4313 }
7c8ff89e 4314
7a7be519 4315 ret = inet_aton (argv[arg_base]->arg, &router_id);
718e3744 4316 if (!ret)
4317 {
3ac237f8
MS
4318 if (!use_json)
4319 vty_out (vty, "Please specify Neighbor ID by A.B.C.D%s", VTY_NEWLINE);
718e3744 4320 return CMD_WARNING;
4321 }
4322
1eb8ef25 4323 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
3ac237f8
MS
4324 {
4325 if ((nbr = ospf_nbr_lookup_by_routerid (oi->nbrs, &router_id)))
4326 {
4327 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4328 }
4329 }
4330
4331 if (use_json)
4332 {
2aac5767 4333 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4334 json_object_free(json);
4335 }
4336 else
4337 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4338
718e3744 4339 return CMD_SUCCESS;
4340}
4341
7c8ff89e
DS
4342DEFUN (show_ip_ospf_neighbor_id,
4343 show_ip_ospf_neighbor_id_cmd,
b162fa78 4344 "show ip ospf neighbor A.B.C.D [json]",
718e3744 4345 SHOW_STR
4346 IP_STR
4347 "OSPF information\n"
4348 "Neighbor list\n"
3ac237f8 4349 "Neighbor ID\n"
9973d184 4350 JSON_STR)
718e3744 4351{
020709f9 4352 struct ospf *ospf;
db7c8528 4353 u_char uj = use_json(argc, argv);
7c8ff89e 4354
0bad4851 4355 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4356 return CMD_SUCCESS;
4357
db7c8528 4358 return show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
4359}
4360
4361DEFUN (show_ip_ospf_instance_neighbor_id,
4362 show_ip_ospf_instance_neighbor_id_cmd,
6147e2c6 4363 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
7c8ff89e
DS
4364 SHOW_STR
4365 IP_STR
4366 "OSPF information\n"
4367 "Instance ID\n"
4368 "Neighbor list\n"
3ac237f8 4369 "Neighbor ID\n"
9973d184 4370 JSON_STR)
7c8ff89e 4371{
8d769265 4372 int idx_number = 3;
7c8ff89e
DS
4373 struct ospf *ospf;
4374 u_short instance = 0;
db7c8528 4375 u_char uj = use_json(argc, argv);
7c8ff89e 4376
8d769265 4377 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4378 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4379 return CMD_SUCCESS;
4380
db7c8528 4381 return show_ip_ospf_neighbor_id_common(vty, ospf, 1, argv, uj);
7c8ff89e
DS
4382}
4383
4384static int
3ac237f8 4385show_ip_ospf_neighbor_detail_common (struct vty *vty, struct ospf *ospf, u_char use_json)
7c8ff89e 4386{
1eb8ef25 4387 struct ospf_interface *oi;
52dc7ee6 4388 struct listnode *node;
3ac237f8
MS
4389 json_object *json = NULL;
4390
4391 if (use_json)
4392 json = json_object_new_object();
718e3744 4393
7c8ff89e 4394 if (ospf->instance)
3ac237f8
MS
4395 {
4396 if (use_json)
4397 json_object_int_add(json, "ospfInstance", ospf->instance);
4398 else
4399 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4400 VTY_NEWLINE, VTY_NEWLINE);
4401 }
718e3744 4402
1eb8ef25 4403 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
718e3744 4404 {
718e3744 4405 struct route_node *rn;
4406 struct ospf_neighbor *nbr;
4407
4408 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
3ac237f8
MS
4409 {
4410 if ((nbr = rn->info))
4411 {
4412 if (nbr != oi->nbr_self)
4413 {
4414 if (nbr->state != NSM_Down)
4415 {
4416 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4417 }
4418 }
4419 }
4420 }
718e3744 4421 }
4422
3ac237f8
MS
4423 if (use_json)
4424 {
2aac5767 4425 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4426 json_object_free(json);
4427 }
4428 else
4429 vty_out (vty, "%s", VTY_NEWLINE);
4430
718e3744 4431 return CMD_SUCCESS;
4432}
4433
7c8ff89e
DS
4434DEFUN (show_ip_ospf_neighbor_detail,
4435 show_ip_ospf_neighbor_detail_cmd,
b162fa78 4436 "show ip ospf neighbor detail [json]",
718e3744 4437 SHOW_STR
4438 IP_STR
4439 "OSPF information\n"
4440 "Neighbor list\n"
3ac237f8 4441 "detail of all neighbors\n"
9973d184 4442 JSON_STR)
718e3744 4443{
020709f9 4444 struct ospf *ospf;
db7c8528 4445 u_char uj = use_json(argc, argv);
7c8ff89e 4446
0bad4851 4447 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4448 return CMD_SUCCESS;
4449
db7c8528 4450 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
7c8ff89e
DS
4451}
4452
4453DEFUN (show_ip_ospf_instance_neighbor_detail,
4454 show_ip_ospf_instance_neighbor_detail_cmd,
6147e2c6 4455 "show ip ospf (1-65535) neighbor detail [json]",
7c8ff89e
DS
4456 SHOW_STR
4457 IP_STR
4458 "OSPF information\n"
4459 "Instance ID\n"
4460 "Neighbor list\n"
3ac237f8 4461 "detail of all neighbors\n"
9973d184 4462 JSON_STR)
7c8ff89e 4463{
8d769265 4464 int idx_number = 3;
7c8ff89e
DS
4465 struct ospf *ospf;
4466 u_short instance = 0;
db7c8528 4467 u_char uj = use_json(argc, argv);
7c8ff89e 4468
8d769265 4469 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4470 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4471 return CMD_SUCCESS;
4472
db7c8528 4473 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
7c8ff89e
DS
4474}
4475
4476static int
3ac237f8 4477show_ip_ospf_neighbor_detail_all_common (struct vty *vty, struct ospf *ospf, u_char use_json)
7c8ff89e 4478{
52dc7ee6 4479 struct listnode *node;
1eb8ef25 4480 struct ospf_interface *oi;
3ac237f8
MS
4481 json_object *json = NULL;
4482
4483 if (use_json)
4484 json = json_object_new_object();
718e3744 4485
7c8ff89e 4486 if (ospf->instance)
3ac237f8
MS
4487 {
4488 if (use_json)
4489 json_object_int_add(json, "ospfInstance", ospf->instance);
4490 else
4491 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4492 VTY_NEWLINE, VTY_NEWLINE);
4493 }
718e3744 4494
1eb8ef25 4495 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
718e3744 4496 {
718e3744 4497 struct route_node *rn;
4498 struct ospf_neighbor *nbr;
1eb8ef25 4499 struct ospf_nbr_nbma *nbr_nbma;
718e3744 4500
4501 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
4502 if ((nbr = rn->info))
4503 if (nbr != oi->nbr_self)
a452df33 4504 if (nbr->state != NSM_Down)
3ac237f8 4505 show_ip_ospf_neighbor_detail_sub (vty, oi, rn->info, use_json, json);
718e3744 4506
4507 if (oi->type == OSPF_IFTYPE_NBMA)
3ac237f8
MS
4508 {
4509 struct listnode *nd;
718e3744 4510
3ac237f8
MS
4511 for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nd, nbr_nbma))
4512 {
4513 if (nbr_nbma->nbr == NULL || nbr_nbma->nbr->state == NSM_Down)
4514 show_ip_ospf_nbr_nbma_detail_sub (vty, oi, nbr_nbma, use_json, json);
4515 }
4516 }
4517 }
4518
4519 if (use_json)
4520 {
2aac5767 4521 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4522 json_object_free(json);
4523 }
4524 else
4525 {
4526 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4527 }
4528
4529 return CMD_SUCCESS;
4530}
4531
7c8ff89e
DS
4532DEFUN (show_ip_ospf_neighbor_detail_all,
4533 show_ip_ospf_neighbor_detail_all_cmd,
b162fa78 4534 "show ip ospf neighbor detail all [json]",
718e3744 4535 SHOW_STR
4536 IP_STR
4537 "OSPF information\n"
4538 "Neighbor list\n"
7c8ff89e 4539 "detail of all neighbors\n"
3ac237f8 4540 "include down status neighbor\n"
9973d184 4541 JSON_STR)
718e3744 4542{
020709f9 4543 struct ospf *ospf;
db7c8528 4544 u_char uj = use_json(argc, argv);
7c8ff89e 4545
0bad4851 4546 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4547 return CMD_SUCCESS;
4548
db7c8528 4549 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
7c8ff89e
DS
4550}
4551
4552DEFUN (show_ip_ospf_instance_neighbor_detail_all,
4553 show_ip_ospf_instance_neighbor_detail_all_cmd,
6147e2c6 4554 "show ip ospf (1-65535) neighbor detail all [json]",
7c8ff89e
DS
4555 SHOW_STR
4556 IP_STR
4557 "OSPF information\n"
4558 "Instance ID\n"
4559 "Neighbor list\n"
4560 "detail of all neighbors\n"
3ac237f8 4561 "include down status neighbor\n"
9973d184 4562 JSON_STR)
7c8ff89e 4563{
8d769265 4564 int idx_number = 3;
7c8ff89e
DS
4565 struct ospf *ospf;
4566 u_short instance = 0;
db7c8528 4567 u_char uj = use_json(argc, argv);
7c8ff89e 4568
8d769265 4569 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4570 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4571 return CMD_SUCCESS;
4572
db7c8528 4573 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
7c8ff89e
DS
4574}
4575
4576static int
4577show_ip_ospf_neighbor_int_detail_common (struct vty *vty, struct ospf *ospf,
7a7be519 4578 int arg_base, struct cmd_token **argv, u_char use_json)
7c8ff89e 4579{
718e3744 4580 struct ospf_interface *oi;
bb5b7552 4581 struct interface *ifp;
4582 struct route_node *rn, *nrn;
4583 struct ospf_neighbor *nbr;
3ac237f8
MS
4584 json_object *json = NULL;
4585
4586 if (use_json)
4587 json = json_object_new_object();
bb5b7552 4588
7c8ff89e 4589 if (ospf->instance)
3ac237f8
MS
4590 {
4591 if (use_json)
4592 json_object_int_add(json, "ospfInstance", ospf->instance);
4593 else
4594 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4595 VTY_NEWLINE, VTY_NEWLINE);
4596 }
7c8ff89e 4597
1306c09a 4598 ifp = if_lookup_by_name (argv[arg_base]->arg, VRF_DEFAULT);
bb5b7552 4599 if (!ifp)
718e3744 4600 {
3ac237f8
MS
4601 if (!use_json)
4602 vty_out (vty, "No such interface.%s", VTY_NEWLINE);
718e3744 4603 return CMD_WARNING;
4604 }
4605
bb5b7552 4606 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
3ac237f8
MS
4607 {
4608 if ((oi = rn->info))
4609 {
4610 for (nrn = route_top (oi->nbrs); nrn; nrn = route_next (nrn))
4611 {
4612 if ((nbr = nrn->info))
4613 {
4614 if (nbr != oi->nbr_self)
4615 {
4616 if (nbr->state != NSM_Down)
4617 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4618 }
4619 }
4620 }
4621 }
4622 }
4623
4624 if (use_json)
4625 {
2aac5767 4626 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4627 json_object_free(json);
4628 }
4629 else
4630 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4631
4632 return CMD_SUCCESS;
4633}
4634
7c8ff89e
DS
4635DEFUN (show_ip_ospf_neighbor_int_detail,
4636 show_ip_ospf_neighbor_int_detail_cmd,
b162fa78 4637 "show ip ospf neighbor IFNAME detail [json]",
7c8ff89e
DS
4638 SHOW_STR
4639 IP_STR
4640 "OSPF information\n"
4641 "Neighbor list\n"
4642 "Interface name\n"
3ac237f8 4643 "detail of all neighbors\n"
9973d184 4644 JSON_STR)
7c8ff89e
DS
4645{
4646 struct ospf *ospf;
db7c8528 4647 u_char uj = use_json(argc, argv);
7c8ff89e 4648
0bad4851 4649 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4650 return CMD_SUCCESS;
4651
db7c8528 4652 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
4653}
4654
4655DEFUN (show_ip_ospf_instance_neighbor_int_detail,
4656 show_ip_ospf_instance_neighbor_int_detail_cmd,
6147e2c6 4657 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
7c8ff89e
DS
4658 SHOW_STR
4659 IP_STR
4660 "OSPF information\n"
4661 "Instance ID\n"
4662 "Neighbor list\n"
4663 "Interface name\n"
3ac237f8 4664 "detail of all neighbors\n"
9973d184 4665 JSON_STR)
7c8ff89e 4666{
8d769265 4667 int idx_number = 3;
7c8ff89e
DS
4668 struct ospf *ospf;
4669 u_short instance = 0;
db7c8528 4670 u_char uj = use_json(argc, argv);
7c8ff89e 4671
8d769265 4672 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4673 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4674 return CMD_SUCCESS;
4675
db7c8528 4676 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 1, argv, uj);
7c8ff89e 4677}
6b0655a2 4678
718e3744 4679/* Show functions */
4dadc291 4680static int
020709f9 4681show_lsa_summary (struct vty *vty, struct ospf_lsa *lsa, int self)
718e3744 4682{
718e3744 4683 struct router_lsa *rl;
4684 struct summary_lsa *sl;
4685 struct as_external_lsa *asel;
4686 struct prefix_ipv4 p;
4687
4688 if (lsa != NULL)
4689 /* If self option is set, check LSA self flag. */
4690 if (self == 0 || IS_LSA_SELF (lsa))
4691 {
4692 /* LSA common part show. */
4693 vty_out (vty, "%-15s ", inet_ntoa (lsa->data->id));
4694 vty_out (vty, "%-15s %4d 0x%08lx 0x%04x",
4695 inet_ntoa (lsa->data->adv_router), LS_AGE (lsa),
4696 (u_long)ntohl (lsa->data->ls_seqnum), ntohs (lsa->data->checksum));
4697 /* LSA specific part show. */
4698 switch (lsa->data->type)
4699 {
4700 case OSPF_ROUTER_LSA:
4701 rl = (struct router_lsa *) lsa->data;
4702 vty_out (vty, " %-d", ntohs (rl->links));
4703 break;
4704 case OSPF_SUMMARY_LSA:
4705 sl = (struct summary_lsa *) lsa->data;
4706
4707 p.family = AF_INET;
4708 p.prefix = sl->header.id;
4709 p.prefixlen = ip_masklen (sl->mask);
4710 apply_mask_ipv4 (&p);
4711
4712 vty_out (vty, " %s/%d", inet_ntoa (p.prefix), p.prefixlen);
4713 break;
4714 case OSPF_AS_EXTERNAL_LSA:
551a8979 4715 case OSPF_AS_NSSA_LSA:
718e3744 4716 asel = (struct as_external_lsa *) lsa->data;
4717
4718 p.family = AF_INET;
4719 p.prefix = asel->header.id;
4720 p.prefixlen = ip_masklen (asel->mask);
4721 apply_mask_ipv4 (&p);
4722
4723 vty_out (vty, " %s %s/%d [0x%lx]",
4724 IS_EXTERNAL_METRIC (asel->e[0].tos) ? "E2" : "E1",
4725 inet_ntoa (p.prefix), p.prefixlen,
4726 (u_long)ntohl (asel->e[0].route_tag));
4727 break;
4728 case OSPF_NETWORK_LSA:
4729 case OSPF_ASBR_SUMMARY_LSA:
718e3744 4730 case OSPF_OPAQUE_LINK_LSA:
4731 case OSPF_OPAQUE_AREA_LSA:
4732 case OSPF_OPAQUE_AS_LSA:
718e3744 4733 default:
4734 break;
4735 }
4736 vty_out (vty, VTY_NEWLINE);
4737 }
4738
4739 return 0;
4740}
4741
8b6a15b2 4742static const char *show_database_desc[] =
718e3744 4743{
4744 "unknown",
4745 "Router Link States",
4746 "Net Link States",
4747 "Summary Link States",
4748 "ASBR-Summary Link States",
4749 "AS External Link States",
718e3744 4750 "Group Membership LSA",
4751 "NSSA-external Link States",
718e3744 4752 "Type-8 LSA",
4753 "Link-Local Opaque-LSA",
4754 "Area-Local Opaque-LSA",
4755 "AS-external Opaque-LSA",
718e3744 4756};
4757
8b6a15b2 4758static const char *show_database_header[] =
718e3744 4759{
4760 "",
4761 "Link ID ADV Router Age Seq# CkSum Link count",
4762 "Link ID ADV Router Age Seq# CkSum",
4763 "Link ID ADV Router Age Seq# CkSum Route",
4764 "Link ID ADV Router Age Seq# CkSum",
4765 "Link ID ADV Router Age Seq# CkSum Route",
718e3744 4766 " --- header for Group Member ----",
4767 "Link ID ADV Router Age Seq# CkSum Route",
718e3744 4768 " --- type-8 ---",
4769 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4770 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4771 "Opaque-Type/Id ADV Router Age Seq# CkSum",
718e3744 4772};
4773
4dadc291 4774static void
718e3744 4775show_ip_ospf_database_header (struct vty *vty, struct ospf_lsa *lsa)
4776{
4777 struct router_lsa *rlsa = (struct router_lsa*) lsa->data;
4957f494 4778
718e3744 4779 vty_out (vty, " LS age: %d%s", LS_AGE (lsa), VTY_NEWLINE);
4957f494 4780 vty_out (vty, " Options: 0x%-2x : %s%s",
4781 lsa->data->options,
4782 ospf_options_dump(lsa->data->options),
4783 VTY_NEWLINE);
4784 vty_out (vty, " LS Flags: 0x%-2x %s%s",
9d526037 4785 lsa->flags,
4957f494 4786 ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" : ""),
4787 VTY_NEWLINE);
718e3744 4788
4789 if (lsa->data->type == OSPF_ROUTER_LSA)
4790 {
4791 vty_out (vty, " Flags: 0x%x" , rlsa->flags);
4792
4793 if (rlsa->flags)
4794 vty_out (vty, " :%s%s%s%s",
4795 IS_ROUTER_LSA_BORDER (rlsa) ? " ABR" : "",
4796 IS_ROUTER_LSA_EXTERNAL (rlsa) ? " ASBR" : "",
4797 IS_ROUTER_LSA_VIRTUAL (rlsa) ? " VL-endpoint" : "",
4798 IS_ROUTER_LSA_SHORTCUT (rlsa) ? " Shortcut" : "");
4799
4800 vty_out (vty, "%s", VTY_NEWLINE);
4801 }
4802 vty_out (vty, " LS Type: %s%s",
4803 LOOKUP (ospf_lsa_type_msg, lsa->data->type), VTY_NEWLINE);
4804 vty_out (vty, " Link State ID: %s %s%s", inet_ntoa (lsa->data->id),
4805 LOOKUP (ospf_link_state_id_type_msg, lsa->data->type), VTY_NEWLINE);
4806 vty_out (vty, " Advertising Router: %s%s",
4807 inet_ntoa (lsa->data->adv_router), VTY_NEWLINE);
4808 vty_out (vty, " LS Seq Number: %08lx%s", (u_long)ntohl (lsa->data->ls_seqnum),
4809 VTY_NEWLINE);
4810 vty_out (vty, " Checksum: 0x%04x%s", ntohs (lsa->data->checksum),
4811 VTY_NEWLINE);
4812 vty_out (vty, " Length: %d%s", ntohs (lsa->data->length), VTY_NEWLINE);
4813}
4814
eb1ce605 4815const char *link_type_desc[] =
718e3744 4816{
4817 "(null)",
4818 "another Router (point-to-point)",
4819 "a Transit Network",
4820 "Stub Network",
4821 "a Virtual Link",
4822};
4823
eb1ce605 4824const char *link_id_desc[] =
718e3744 4825{
4826 "(null)",
4827 "Neighboring Router ID",
4828 "Designated Router address",
68980084 4829 "Net",
718e3744 4830 "Neighboring Router ID",
4831};
4832
eb1ce605 4833const char *link_data_desc[] =
718e3744 4834{
4835 "(null)",
4836 "Router Interface address",
4837 "Router Interface address",
4838 "Network Mask",
4839 "Router Interface address",
4840};
4841
4842/* Show router-LSA each Link information. */
4dadc291 4843static void
718e3744 4844show_ip_ospf_database_router_links (struct vty *vty,
4845 struct router_lsa *rl)
4846{
b07c4cb3
DS
4847 int len, type;
4848 unsigned int i;
718e3744 4849
4850 len = ntohs (rl->header.length) - 4;
4851 for (i = 0; i < ntohs (rl->links) && len > 0; len -= 12, i++)
4852 {
4853 type = rl->link[i].type;
4854
4855 vty_out (vty, " Link connected to: %s%s",
4856 link_type_desc[type], VTY_NEWLINE);
4857 vty_out (vty, " (Link ID) %s: %s%s", link_id_desc[type],
4858 inet_ntoa (rl->link[i].link_id), VTY_NEWLINE);
4859 vty_out (vty, " (Link Data) %s: %s%s", link_data_desc[type],
4860 inet_ntoa (rl->link[i].link_data), VTY_NEWLINE);
4861 vty_out (vty, " Number of TOS metrics: 0%s", VTY_NEWLINE);
4862 vty_out (vty, " TOS 0 Metric: %d%s",
4863 ntohs (rl->link[i].metric), VTY_NEWLINE);
4864 vty_out (vty, "%s", VTY_NEWLINE);
4865 }
4866}
4867
4868/* Show router-LSA detail information. */
4dadc291 4869static int
718e3744 4870show_router_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4871{
4872 if (lsa != NULL)
4873 {
4874 struct router_lsa *rl = (struct router_lsa *) lsa->data;
4875
4876 show_ip_ospf_database_header (vty, lsa);
4877
4878 vty_out (vty, " Number of Links: %d%s%s", ntohs (rl->links),
4879 VTY_NEWLINE, VTY_NEWLINE);
4880
4881 show_ip_ospf_database_router_links (vty, rl);
b0a053be 4882 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4883 }
4884
4885 return 0;
4886}
4887
4888/* Show network-LSA detail information. */
4dadc291 4889static int
718e3744 4890show_network_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4891{
4892 int length, i;
4893
4894 if (lsa != NULL)
4895 {
4896 struct network_lsa *nl = (struct network_lsa *) lsa->data;
4897
4898 show_ip_ospf_database_header (vty, lsa);
4899
4900 vty_out (vty, " Network Mask: /%d%s",
4901 ip_masklen (nl->mask), VTY_NEWLINE);
4902
4903 length = ntohs (lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4;
4904
4905 for (i = 0; length > 0; i++, length -= 4)
4906 vty_out (vty, " Attached Router: %s%s",
4907 inet_ntoa (nl->routers[i]), VTY_NEWLINE);
4908
4909 vty_out (vty, "%s", VTY_NEWLINE);
4910 }
4911
4912 return 0;
4913}
4914
4915/* Show summary-LSA detail information. */
4dadc291 4916static int
718e3744 4917show_summary_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4918{
4919 if (lsa != NULL)
4920 {
4921 struct summary_lsa *sl = (struct summary_lsa *) lsa->data;
4922
4923 show_ip_ospf_database_header (vty, lsa);
4924
4925 vty_out (vty, " Network Mask: /%d%s", ip_masklen (sl->mask),
4926 VTY_NEWLINE);
4927 vty_out (vty, " TOS: 0 Metric: %d%s", GET_METRIC (sl->metric),
4928 VTY_NEWLINE);
b0a053be 4929 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4930 }
4931
4932 return 0;
4933}
4934
4935/* Show summary-ASBR-LSA detail information. */
4dadc291 4936static int
718e3744 4937show_summary_asbr_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4938{
4939 if (lsa != NULL)
4940 {
4941 struct summary_lsa *sl = (struct summary_lsa *) lsa->data;
4942
4943 show_ip_ospf_database_header (vty, lsa);
4944
4945 vty_out (vty, " Network Mask: /%d%s",
4946 ip_masklen (sl->mask), VTY_NEWLINE);
4947 vty_out (vty, " TOS: 0 Metric: %d%s", GET_METRIC (sl->metric),
4948 VTY_NEWLINE);
b0a053be 4949 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4950 }
4951
4952 return 0;
4953}
4954
4955/* Show AS-external-LSA detail information. */
4dadc291 4956static int
718e3744 4957show_as_external_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4958{
4959 if (lsa != NULL)
4960 {
4961 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
4962
4963 show_ip_ospf_database_header (vty, lsa);
4964
4965 vty_out (vty, " Network Mask: /%d%s",
4966 ip_masklen (al->mask), VTY_NEWLINE);
4967 vty_out (vty, " Metric Type: %s%s",
4968 IS_EXTERNAL_METRIC (al->e[0].tos) ?
4969 "2 (Larger than any link state path)" : "1", VTY_NEWLINE);
4970 vty_out (vty, " TOS: 0%s", VTY_NEWLINE);
4971 vty_out (vty, " Metric: %d%s",
4972 GET_METRIC (al->e[0].metric), VTY_NEWLINE);
4973 vty_out (vty, " Forward Address: %s%s",
4974 inet_ntoa (al->e[0].fwd_addr), VTY_NEWLINE);
4975
dc9ffce8
CF
4976 vty_out (vty, " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
4977 (route_tag_t)ntohl (al->e[0].route_tag), VTY_NEWLINE, VTY_NEWLINE);
718e3744 4978 }
4979
4980 return 0;
4981}
075e12f5 4982#if 0
4dadc291 4983static int
718e3744 4984show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
4985{
4986 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
4987
4988 /* show_ip_ospf_database_header (vty, lsa); */
4989
2a42e285 4990 zlog_debug( " Network Mask: /%d%s",
718e3744 4991 ip_masklen (al->mask), "\n");
2a42e285 4992 zlog_debug( " Metric Type: %s%s",
718e3744 4993 IS_EXTERNAL_METRIC (al->e[0].tos) ?
4994 "2 (Larger than any link state path)" : "1", "\n");
2a42e285 4995 zlog_debug( " TOS: 0%s", "\n");
4996 zlog_debug( " Metric: %d%s",
718e3744 4997 GET_METRIC (al->e[0].metric), "\n");
2a42e285 4998 zlog_debug( " Forward Address: %s%s",
718e3744 4999 inet_ntoa (al->e[0].fwd_addr), "\n");
5000
dc9ffce8
CF
5001 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5002 (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n");
718e3744 5003
5004 return 0;
5005}
075e12f5 5006#endif
718e3744 5007/* Show AS-NSSA-LSA detail information. */
4dadc291 5008static int
718e3744 5009show_as_nssa_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
5010{
5011 if (lsa != NULL)
5012 {
5013 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
5014
5015 show_ip_ospf_database_header (vty, lsa);
5016
5017 vty_out (vty, " Network Mask: /%d%s",
5018 ip_masklen (al->mask), VTY_NEWLINE);
5019 vty_out (vty, " Metric Type: %s%s",
5020 IS_EXTERNAL_METRIC (al->e[0].tos) ?
5021 "2 (Larger than any link state path)" : "1", VTY_NEWLINE);
5022 vty_out (vty, " TOS: 0%s", VTY_NEWLINE);
5023 vty_out (vty, " Metric: %d%s",
5024 GET_METRIC (al->e[0].metric), VTY_NEWLINE);
5025 vty_out (vty, " NSSA: Forward Address: %s%s",
5026 inet_ntoa (al->e[0].fwd_addr), VTY_NEWLINE);
5027
dc9ffce8
CF
5028 vty_out (vty, " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5029 (route_tag_t)ntohl (al->e[0].route_tag), VTY_NEWLINE, VTY_NEWLINE);
718e3744 5030 }
5031
5032 return 0;
5033}
5034
4dadc291 5035static int
718e3744 5036show_func_dummy (struct vty *vty, struct ospf_lsa *lsa)
5037{
5038 return 0;
5039}
5040
4dadc291 5041static int
718e3744 5042show_opaque_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
5043{
5044 if (lsa != NULL)
5045 {
5046 show_ip_ospf_database_header (vty, lsa);
5047 show_opaque_info_detail (vty, lsa);
5048
5049 vty_out (vty, "%s", VTY_NEWLINE);
5050 }
5051 return 0;
5052}
718e3744 5053
5054int (*show_function[])(struct vty *, struct ospf_lsa *) =
5055{
5056 NULL,
5057 show_router_lsa_detail,
5058 show_network_lsa_detail,
5059 show_summary_lsa_detail,
5060 show_summary_asbr_lsa_detail,
5061 show_as_external_lsa_detail,
718e3744 5062 show_func_dummy,
5063 show_as_nssa_lsa_detail, /* almost same as external */
718e3744 5064 NULL, /* type-8 */
5065 show_opaque_lsa_detail,
5066 show_opaque_lsa_detail,
5067 show_opaque_lsa_detail,
718e3744 5068};
5069
4dadc291 5070static void
718e3744 5071show_lsa_prefix_set (struct vty *vty, struct prefix_ls *lp, struct in_addr *id,
5072 struct in_addr *adv_router)
5073{
5074 memset (lp, 0, sizeof (struct prefix_ls));
5075 lp->family = 0;
5076 if (id == NULL)
5077 lp->prefixlen = 0;
5078 else if (adv_router == NULL)
5079 {
5080 lp->prefixlen = 32;
5081 lp->id = *id;
5082 }
5083 else
5084 {
5085 lp->prefixlen = 64;
5086 lp->id = *id;
5087 lp->adv_router = *adv_router;
5088 }
5089}
5090
4dadc291 5091static void
718e3744 5092show_lsa_detail_proc (struct vty *vty, struct route_table *rt,
5093 struct in_addr *id, struct in_addr *adv_router)
5094{
5095 struct prefix_ls lp;
5096 struct route_node *rn, *start;
5097 struct ospf_lsa *lsa;
5098
5099 show_lsa_prefix_set (vty, &lp, id, adv_router);
5100 start = route_node_get (rt, (struct prefix *) &lp);
5101 if (start)
5102 {
5103 route_lock_node (start);
5104 for (rn = start; rn; rn = route_next_until (rn, start))
5105 if ((lsa = rn->info))
5106 {
718e3744 5107 if (show_function[lsa->data->type] != NULL)
5108 show_function[lsa->data->type] (vty, lsa);
5109 }
5110 route_unlock_node (start);
5111 }
5112}
5113
5114/* Show detail LSA information
5115 -- if id is NULL then show all LSAs. */
4dadc291 5116static void
020709f9 5117show_lsa_detail (struct vty *vty, struct ospf *ospf, int type,
718e3744 5118 struct in_addr *id, struct in_addr *adv_router)
5119{
52dc7ee6 5120 struct listnode *node;
1eb8ef25 5121 struct ospf_area *area;
5122
718e3744 5123 switch (type)
5124 {
5125 case OSPF_AS_EXTERNAL_LSA:
718e3744 5126 case OSPF_OPAQUE_AS_LSA:
718e3744 5127 vty_out (vty, " %s %s%s",
5128 show_database_desc[type],
5129 VTY_NEWLINE, VTY_NEWLINE);
68980084 5130 show_lsa_detail_proc (vty, AS_LSDB (ospf, type), id, adv_router);
718e3744 5131 break;
5132 default:
1eb8ef25 5133 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 5134 {
718e3744 5135 vty_out (vty, "%s %s (Area %s)%s%s",
5136 VTY_NEWLINE, show_database_desc[type],
5137 ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE);
5138 show_lsa_detail_proc (vty, AREA_LSDB (area, type), id, adv_router);
5139 }
5140 break;
5141 }
5142}
5143
4dadc291 5144static void
718e3744 5145show_lsa_detail_adv_router_proc (struct vty *vty, struct route_table *rt,
5146 struct in_addr *adv_router)
5147{
5148 struct route_node *rn;
5149 struct ospf_lsa *lsa;
5150
5151 for (rn = route_top (rt); rn; rn = route_next (rn))
5152 if ((lsa = rn->info))
5153 if (IPV4_ADDR_SAME (adv_router, &lsa->data->adv_router))
5154 {
718e3744 5155 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
5156 continue;
718e3744 5157 if (show_function[lsa->data->type] != NULL)
5158 show_function[lsa->data->type] (vty, lsa);
5159 }
5160}
5161
5162/* Show detail LSA information. */
4dadc291 5163static void
020709f9 5164show_lsa_detail_adv_router (struct vty *vty, struct ospf *ospf, int type,
718e3744 5165 struct in_addr *adv_router)
5166{
52dc7ee6 5167 struct listnode *node;
1eb8ef25 5168 struct ospf_area *area;
718e3744 5169
5170 switch (type)
5171 {
5172 case OSPF_AS_EXTERNAL_LSA:
718e3744 5173 case OSPF_OPAQUE_AS_LSA:
718e3744 5174 vty_out (vty, " %s %s%s",
5175 show_database_desc[type],
5176 VTY_NEWLINE, VTY_NEWLINE);
68980084 5177 show_lsa_detail_adv_router_proc (vty, AS_LSDB (ospf, type),
718e3744 5178 adv_router);
5179 break;
5180 default:
1eb8ef25 5181 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 5182 {
718e3744 5183 vty_out (vty, "%s %s (Area %s)%s%s",
5184 VTY_NEWLINE, show_database_desc[type],
5185 ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE);
5186 show_lsa_detail_adv_router_proc (vty, AREA_LSDB (area, type),
5187 adv_router);
5188 }
5189 break;
5190 }
5191}
5192
4dadc291 5193static void
020709f9 5194show_ip_ospf_database_summary (struct vty *vty, struct ospf *ospf, int self)
718e3744 5195{
020709f9 5196 struct ospf_lsa *lsa;
5197 struct route_node *rn;
1eb8ef25 5198 struct ospf_area *area;
52dc7ee6 5199 struct listnode *node;
718e3744 5200 int type;
5201
1eb8ef25 5202 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 5203 {
718e3744 5204 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++)
5205 {
5206 switch (type)
5207 {
5208 case OSPF_AS_EXTERNAL_LSA:
718e3744 5209 case OSPF_OPAQUE_AS_LSA:
718e3744 5210 continue;
5211 default:
5212 break;
5213 }
5214 if (ospf_lsdb_count_self (area->lsdb, type) > 0 ||
5215 (!self && ospf_lsdb_count (area->lsdb, type) > 0))
5216 {
5217 vty_out (vty, " %s (Area %s)%s%s",
5218 show_database_desc[type],
5219 ospf_area_desc_string (area),
5220 VTY_NEWLINE, VTY_NEWLINE);
5221 vty_out (vty, "%s%s", show_database_header[type], VTY_NEWLINE);
5222
020709f9 5223 LSDB_LOOP (AREA_LSDB (area, type), rn, lsa)
5224 show_lsa_summary (vty, lsa, self);
718e3744 5225
5226 vty_out (vty, "%s", VTY_NEWLINE);
5227 }
5228 }
5229 }
5230
5231 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++)
5232 {
5233 switch (type)
5234 {
5235 case OSPF_AS_EXTERNAL_LSA:
718e3744 5236 case OSPF_OPAQUE_AS_LSA:
e8e1946e 5237 break;
718e3744 5238 default:
5239 continue;
5240 }
68980084 5241 if (ospf_lsdb_count_self (ospf->lsdb, type) ||
5242 (!self && ospf_lsdb_count (ospf->lsdb, type)))
718e3744 5243 {
5244 vty_out (vty, " %s%s%s",
5245 show_database_desc[type],
5246 VTY_NEWLINE, VTY_NEWLINE);
5247 vty_out (vty, "%s%s", show_database_header[type],
5248 VTY_NEWLINE);
020709f9 5249
5250 LSDB_LOOP (AS_LSDB (ospf, type), rn, lsa)
5251 show_lsa_summary (vty, lsa, self);
5252
718e3744 5253 vty_out (vty, "%s", VTY_NEWLINE);
5254 }
5255 }
5256
5257 vty_out (vty, "%s", VTY_NEWLINE);
5258}
5259
4dadc291 5260static void
020709f9 5261show_ip_ospf_database_maxage (struct vty *vty, struct ospf *ospf)
718e3744 5262{
91e6a0e5 5263 struct route_node *rn;
718e3744 5264
5265 vty_out (vty, "%s MaxAge Link States:%s%s",
5266 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
5267
91e6a0e5 5268 for (rn = route_top (ospf->maxage_lsa); rn; rn = route_next (rn))
1eb8ef25 5269 {
91e6a0e5
DD
5270 struct ospf_lsa *lsa;
5271
5272 if ((lsa = rn->info) != NULL)
5273 {
5274 vty_out (vty, "Link type: %d%s", lsa->data->type, VTY_NEWLINE);
5275 vty_out (vty, "Link State ID: %s%s",
5276 inet_ntoa (lsa->data->id), VTY_NEWLINE);
5277 vty_out (vty, "Advertising Router: %s%s",
5278 inet_ntoa (lsa->data->adv_router), VTY_NEWLINE);
5279 vty_out (vty, "LSA lock count: %d%s", lsa->lock, VTY_NEWLINE);
5280 vty_out (vty, "%s", VTY_NEWLINE);
5281 }
1eb8ef25 5282 }
718e3744 5283}
5284
718e3744 5285#define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
5286#define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
718e3744 5287
718e3744 5288#define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
5289#define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
5290#define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
5291#define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
718e3744 5292
718e3744 5293#define OSPF_LSA_TYPES_DESC \
5294 "ASBR summary link states\n" \
5295 "External link states\n" \
5296 "Network link states\n" \
5297 "Router link states\n" \
5298 "Network summary link states\n" \
5299 OSPF_LSA_TYPE_NSSA_DESC \
5300 OSPF_LSA_TYPE_OPAQUE_LINK_DESC \
5301 OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
5302 OSPF_LSA_TYPE_OPAQUE_AS_DESC
5303
7c8ff89e
DS
5304static int
5305show_ip_ospf_database_common (struct vty *vty, struct ospf *ospf,
7a7be519 5306 int arg_base, int argc, struct cmd_token **argv)
718e3744 5307{
7a7be519 5308 int idx_type = 4;
718e3744 5309 int type, ret;
5310 struct in_addr id, adv_router;
5311
7c8ff89e
DS
5312 if (ospf->instance)
5313 vty_out (vty, "%sOSPF Instance: %d%s", VTY_NEWLINE, ospf->instance,
5314 VTY_NEWLINE);
718e3744 5315
5316 vty_out (vty, "%s OSPF Router with ID (%s)%s%s", VTY_NEWLINE,
68980084 5317 inet_ntoa (ospf->router_id), VTY_NEWLINE, VTY_NEWLINE);
718e3744 5318
5319 /* Show all LSA. */
7a7be519 5320 if (argc == arg_base + 4)
718e3744 5321 {
020709f9 5322 show_ip_ospf_database_summary (vty, ospf, 0);
718e3744 5323 return CMD_SUCCESS;
5324 }
5325
5326 /* Set database type to show. */
7a7be519 5327 if (strncmp (argv[arg_base + idx_type]->text, "r", 1) == 0)
718e3744 5328 type = OSPF_ROUTER_LSA;
7a7be519 5329 else if (strncmp (argv[arg_base + idx_type]->text, "ne", 2) == 0)
718e3744 5330 type = OSPF_NETWORK_LSA;
7a7be519 5331 else if (strncmp (argv[arg_base + idx_type]->text, "ns", 2) == 0)
718e3744 5332 type = OSPF_AS_NSSA_LSA;
7a7be519 5333 else if (strncmp (argv[arg_base + idx_type]->text, "su", 2) == 0)
718e3744 5334 type = OSPF_SUMMARY_LSA;
7a7be519 5335 else if (strncmp (argv[arg_base + idx_type]->text, "a", 1) == 0)
718e3744 5336 type = OSPF_ASBR_SUMMARY_LSA;
7a7be519 5337 else if (strncmp (argv[arg_base + idx_type]->text, "e", 1) == 0)
718e3744 5338 type = OSPF_AS_EXTERNAL_LSA;
7a7be519 5339 else if (strncmp (argv[arg_base + idx_type]->text, "se", 2) == 0)
718e3744 5340 {
020709f9 5341 show_ip_ospf_database_summary (vty, ospf, 1);
718e3744 5342 return CMD_SUCCESS;
5343 }
7a7be519 5344 else if (strncmp (argv[arg_base + idx_type]->text, "m", 1) == 0)
718e3744 5345 {
020709f9 5346 show_ip_ospf_database_maxage (vty, ospf);
718e3744 5347 return CMD_SUCCESS;
5348 }
7a7be519 5349 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
718e3744 5350 type = OSPF_OPAQUE_LINK_LSA;
7a7be519 5351 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
718e3744 5352 type = OSPF_OPAQUE_AREA_LSA;
7a7be519 5353 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
718e3744 5354 type = OSPF_OPAQUE_AS_LSA;
718e3744 5355 else
5356 return CMD_WARNING;
5357
5358 /* `show ip ospf database LSA'. */
7a7be519 5359 if (argc == arg_base + 5)
020709f9 5360 show_lsa_detail (vty, ospf, type, NULL, NULL);
7a7be519 5361 else if (argc >= arg_base + 6)
718e3744 5362 {
7a7be519 5363 ret = inet_aton (argv[arg_base + 5]->arg, &id);
718e3744 5364 if (!ret)
5365 return CMD_WARNING;
5366
5367 /* `show ip ospf database LSA ID'. */
7a7be519 5368 if (argc == arg_base + 6)
020709f9 5369 show_lsa_detail (vty, ospf, type, &id, NULL);
718e3744 5370 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7a7be519 5371 else if (argc == arg_base + 7)
718e3744 5372 {
7a7be519 5373 if (strncmp (argv[arg_base + 6]->text, "s", 1) == 0)
68980084 5374 adv_router = ospf->router_id;
718e3744 5375 else
5376 {
7a7be519 5377 ret = inet_aton (argv[arg_base + 7]->arg, &adv_router);
718e3744 5378 if (!ret)
5379 return CMD_WARNING;
5380 }
020709f9 5381 show_lsa_detail (vty, ospf, type, &id, &adv_router);
718e3744 5382 }
5383 }
5384
5385 return CMD_SUCCESS;
5386}
5387
7a7be519 5388DEFUN (show_ip_ospf_database_max,
5389 show_ip_ospf_database_max_cmd,
5390 "show ip ospf database <max-age|self-originate>",
5391 SHOW_STR
5392 IP_STR
5393 "OSPF information\n"
5394 "Database summary\n"
5395 "LSAs in MaxAge list\n"
5396 "Self-originated link states\n")
5397{
5398 struct ospf *ospf;
f412b39a 5399
7a7be519 5400 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
5401 return CMD_SUCCESS;
f412b39a 5402
7a7be519 5403 return (show_ip_ospf_database_common(vty, ospf, 0, argc, argv));
5404}
f412b39a 5405
f412b39a
DW
5406DEFUN (show_ip_ospf_instance_database,
5407 show_ip_ospf_instance_database_cmd,
3a2d747c 5408 "show ip ospf [(1-65535)] 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>]]]",
718e3744 5409 SHOW_STR
5410 IP_STR
5411 "OSPF information\n"
7c8ff89e 5412 "Instance ID\n"
7a7be519 5413 "Database summary\n"
5414 OSPF_LSA_TYPES_DESC
5415 "Link State ID (as an IP address)\n"
5416 "Self-originated link states\n"
5417 "Advertising Router link states\n"
5418 "Advertising Router (as an IP address)\n")
7c8ff89e
DS
5419{
5420 struct ospf *ospf;
5421 u_short instance = 0;
5422
3a2d747c
QY
5423 int idx = 0;
5424 if (argv_find (argv, argc, "(1-65535)", &idx))
5425 {
5426 VTY_GET_INTEGER ("Instance", instance, argv[idx]->arg);
5427 ospf = ospf_lookup_instance (instance);
5428 }
5429 else {
5430 ospf = ospf_lookup();
5431 }
7c8ff89e 5432
3a2d747c 5433 if (!ospf || !ospf->oi_running)
7c8ff89e
DS
5434 return CMD_SUCCESS;
5435
3a2d747c 5436 return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, argc, argv));
7c8ff89e
DS
5437}
5438
7a7be519 5439DEFUN (show_ip_ospf_instance_database_max,
5440 show_ip_ospf_instance_database_max_cmd,
5441 "show ip ospf (1-65535) database <max-age|self-originate>",
5442 SHOW_STR
5443 IP_STR
5444 "OSPF information\n"
5445 "Instance ID\n"
5446 "Database summary\n"
5447 "LSAs in MaxAge list\n"
5448 "Self-originated link states\n")
5449{
5450 int idx_number = 3;
5451 struct ospf *ospf;
5452 u_short instance = 0;
7c8ff89e 5453
7a7be519 5454 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e 5455
7a7be519 5456 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
5457 return CMD_SUCCESS;
7c8ff89e 5458
7a7be519 5459 return (show_ip_ospf_database_common(vty, ospf, 1, argc, argv));
5460}
7c8ff89e
DS
5461
5462
5463static int
5464show_ip_ospf_database_type_adv_router_common (struct vty *vty, struct ospf *ospf,
7a7be519 5465 int arg_base, int argc, struct cmd_token **argv)
718e3744 5466{
7a7be519 5467 int idx_type = 4;
718e3744 5468 int type, ret;
5469 struct in_addr adv_router;
5470
7c8ff89e
DS
5471 if (ospf->instance)
5472 vty_out (vty, "%sOSPF Instance: %d%s", VTY_NEWLINE, ospf->instance,
5473 VTY_NEWLINE);
718e3744 5474
5475 vty_out (vty, "%s OSPF Router with ID (%s)%s%s", VTY_NEWLINE,
68980084 5476 inet_ntoa (ospf->router_id), VTY_NEWLINE, VTY_NEWLINE);
718e3744 5477
7a7be519 5478 if (argc != arg_base + 7)
718e3744 5479 return CMD_WARNING;
5480
5481 /* Set database type to show. */
7a7be519 5482 if (strncmp (argv[arg_base + idx_type]->text, "r", 1) == 0)
718e3744 5483 type = OSPF_ROUTER_LSA;
7a7be519 5484 else if (strncmp (argv[arg_base + idx_type]->text, "ne", 2) == 0)
718e3744 5485 type = OSPF_NETWORK_LSA;
7a7be519 5486 else if (strncmp (argv[arg_base + idx_type]->text, "ns", 2) == 0)
718e3744 5487 type = OSPF_AS_NSSA_LSA;
7a7be519 5488 else if (strncmp (argv[arg_base + idx_type]->text, "s", 1) == 0)
718e3744 5489 type = OSPF_SUMMARY_LSA;
7a7be519 5490 else if (strncmp (argv[arg_base + idx_type]->text, "a", 1) == 0)
718e3744 5491 type = OSPF_ASBR_SUMMARY_LSA;
7a7be519 5492 else if (strncmp (argv[arg_base + idx_type]->text, "e", 1) == 0)
718e3744 5493 type = OSPF_AS_EXTERNAL_LSA;
7a7be519 5494 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
718e3744 5495 type = OSPF_OPAQUE_LINK_LSA;
7a7be519 5496 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
718e3744 5497 type = OSPF_OPAQUE_AREA_LSA;
7a7be519 5498 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
718e3744 5499 type = OSPF_OPAQUE_AS_LSA;
718e3744 5500 else
5501 return CMD_WARNING;
5502
7c8ff89e 5503 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7a7be519 5504 if (strncmp (argv[arg_base + 5]->text, "s", 1) == 0)
7c8ff89e
DS
5505 adv_router = ospf->router_id;
5506 else
5507 {
7a7be519 5508 ret = inet_aton (argv[arg_base + 6]->arg, &adv_router);
7c8ff89e
DS
5509 if (!ret)
5510 return CMD_WARNING;
5511 }
5512
5513 show_lsa_detail_adv_router (vty, ospf, type, &adv_router);
5514
5515 return CMD_SUCCESS;
5516}
5517
5518DEFUN (show_ip_ospf_database_type_adv_router,
5519 show_ip_ospf_database_type_adv_router_cmd,
7a7be519 5520 "show ip ospf database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate>",
7c8ff89e
DS
5521 SHOW_STR
5522 IP_STR
5523 "OSPF information\n"
5524 "Database summary\n"
5525 OSPF_LSA_TYPES_DESC
5526 "Advertising Router link states\n"
16cedbb0
QY
5527 "Advertising Router (as an IP address)\n"
5528 "Self-originated link states\n")
7c8ff89e
DS
5529{
5530 struct ospf *ospf;
5531
0bad4851 5532 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
5533 return CMD_SUCCESS;
5534
5535 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 0, argc, argv));
5536}
5537
7c8ff89e
DS
5538DEFUN (show_ip_ospf_instance_database_type_adv_router,
5539 show_ip_ospf_instance_database_type_adv_router_cmd,
7a7be519 5540 "show ip ospf (1-65535) database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate>",
7c8ff89e
DS
5541 SHOW_STR
5542 IP_STR
5543 "OSPF information\n"
5544 "Instance ID\n"
5545 "Database summary\n"
5546 OSPF_LSA_TYPES_DESC
5547 "Advertising Router link states\n"
3a2d747c
QY
5548 "Advertising Router (as an IP address)\n"
5549 "Self-originated link states\n")
7c8ff89e 5550{
8d769265 5551 int idx_number = 3;
7c8ff89e
DS
5552 struct ospf *ospf;
5553 u_short instance = 0;
5554
8d769265 5555 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
718e3744 5556
0bad4851 5557 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e 5558 return CMD_SUCCESS;
718e3744 5559
7c8ff89e 5560 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv));
718e3744 5561}
5562
718e3744 5563DEFUN (ip_ospf_authentication_args,
5564 ip_ospf_authentication_args_addr_cmd,
7a7be519 5565 "ip ospf authentication <null|message-digest> [A.B.C.D]",
718e3744 5566 "IP Information\n"
5567 "OSPF interface commands\n"
5568 "Enable authentication on this interface\n"
5569 "Use null authentication\n"
5570 "Use message-digest authentication\n"
7a7be519 5571 "Address of interface\n")
718e3744 5572{
cdc2d765 5573 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265
DW
5574 int idx_encryption = 3;
5575 int idx_ipv4 = 4;
718e3744 5576 struct in_addr addr;
5577 int ret;
5578 struct ospf_if_params *params;
5579
718e3744 5580 params = IF_DEF_PARAMS (ifp);
5581
7a7be519 5582 if (argc == 5)
718e3744 5583 {
8d769265 5584 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 5585 if (!ret)
5586 {
5587 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5588 VTY_NEWLINE);
5589 return CMD_WARNING;
5590 }
5591
5592 params = ospf_get_if_params (ifp, addr);
5593 ospf_if_update_params (ifp, addr);
5594 }
5595
5596 /* Handle null authentication */
8d769265 5597 if ( argv[idx_encryption]->arg[0] == 'n' )
718e3744 5598 {
5599 SET_IF_PARAM (params, auth_type);
5600 params->auth_type = OSPF_AUTH_NULL;
5601 return CMD_SUCCESS;
5602 }
5603
5604 /* Handle message-digest authentication */
8d769265 5605 if ( argv[idx_encryption]->arg[0] == 'm' )
718e3744 5606 {
5607 SET_IF_PARAM (params, auth_type);
5608 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5609 return CMD_SUCCESS;
5610 }
5611
5612 vty_out (vty, "You shouldn't get here!%s", VTY_NEWLINE);
5613 return CMD_WARNING;
5614}
5615
718e3744 5616DEFUN (ip_ospf_authentication,
5617 ip_ospf_authentication_addr_cmd,
7a7be519 5618 "ip ospf authentication [A.B.C.D]",
718e3744 5619 "IP Information\n"
5620 "OSPF interface commands\n"
5621 "Enable authentication on this interface\n"
5622 "Address of interface")
5623{
cdc2d765 5624 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 5625 int idx_ipv4 = 3;
718e3744 5626 struct in_addr addr;
5627 int ret;
5628 struct ospf_if_params *params;
5629
718e3744 5630 params = IF_DEF_PARAMS (ifp);
5631
7a7be519 5632 if (argc == 4)
718e3744 5633 {
8d769265 5634 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 5635 if (!ret)
5636 {
5637 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5638 VTY_NEWLINE);
5639 return CMD_WARNING;
5640 }
5641
5642 params = ospf_get_if_params (ifp, addr);
5643 ospf_if_update_params (ifp, addr);
5644 }
5645
5646 SET_IF_PARAM (params, auth_type);
5647 params->auth_type = OSPF_AUTH_SIMPLE;
5648
5649 return CMD_SUCCESS;
5650}
5651
b4a039bf
DS
5652DEFUN (no_ip_ospf_authentication_args,
5653 no_ip_ospf_authentication_args_addr_cmd,
7a7be519 5654 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
b4a039bf
DS
5655 NO_STR
5656 "IP Information\n"
5657 "OSPF interface commands\n"
5658 "Enable authentication on this interface\n"
5659 "Use null authentication\n"
5660 "Use message-digest authentication\n"
5661 "Address of interface")
5662{
cdc2d765 5663 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265
DW
5664 int idx_encryption = 4;
5665 int idx_ipv4 = 5;
b4a039bf
DS
5666 struct in_addr addr;
5667 int ret;
5668 struct ospf_if_params *params;
5669 struct route_node *rn;
5670 int auth_type;
5671
b4a039bf
DS
5672 params = IF_DEF_PARAMS (ifp);
5673
7a7be519 5674 if (argc == 6)
b4a039bf 5675 {
8d769265 5676 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
b4a039bf
DS
5677 if (!ret)
5678 {
5679 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5680 VTY_NEWLINE);
5681 return CMD_WARNING;
5682 }
5683
5684 params = ospf_lookup_if_params (ifp, addr);
5685 if (params == NULL)
5686 {
5687 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
5688 return CMD_WARNING;
5689 }
5690 params->auth_type = OSPF_AUTH_NOTSET;
5691 UNSET_IF_PARAM (params, auth_type);
5692 if (params != IF_DEF_PARAMS (ifp))
5693 {
5694 ospf_free_if_params (ifp, addr);
5695 ospf_if_update_params (ifp, addr);
5696 }
5697 }
5698 else
5699 {
8d769265 5700 if ( argv[idx_encryption]->arg[0] == 'n' )
b4a039bf
DS
5701 {
5702 auth_type = OSPF_AUTH_NULL;
5703 }
8d769265 5704 else if ( argv[idx_encryption]->arg[0] == 'm' )
b4a039bf
DS
5705 {
5706 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5707 }
5708 else
5709 {
5710 vty_out (vty, "Unexpected input encountered%s", VTY_NEWLINE);
5711 return CMD_WARNING;
5712 }
5713 /*
5714 * Here we have a case where the user has entered
5715 * 'no ip ospf authentication (null | message_digest )'
5716 * we need to find if we have any ip addresses underneath it that
5717 * correspond to the associated type.
5718 */
813d4307
DW
5719 if (params->auth_type == auth_type)
5720 {
5721 params->auth_type = OSPF_AUTH_NOTSET;
5722 UNSET_IF_PARAM (params, auth_type);
5723 }
5724
b4a039bf
DS
5725 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
5726 {
5727 if ((params = rn->info))
5728 {
5729 if (params->auth_type == auth_type)
5730 {
5731 params->auth_type = OSPF_AUTH_NOTSET;
5732 UNSET_IF_PARAM (params, auth_type);
5733 if (params != IF_DEF_PARAMS (ifp))
5734 {
5735 ospf_free_if_params (ifp, rn->p.u.prefix4);
5736 ospf_if_update_params(ifp, rn->p.u.prefix4);
5737 }
5738 }
5739 }
5740 }
5741 }
5742
5743 return CMD_SUCCESS;
5744}
5745
718e3744 5746DEFUN (no_ip_ospf_authentication,
5747 no_ip_ospf_authentication_addr_cmd,
7a7be519 5748 "no ip ospf authentication [A.B.C.D]",
718e3744 5749 NO_STR
5750 "IP Information\n"
5751 "OSPF interface commands\n"
5752 "Enable authentication on this interface\n"
5753 "Address of interface")
5754{
cdc2d765 5755 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 5756 int idx_ipv4 = 4;
718e3744 5757 struct in_addr addr;
5758 int ret;
5759 struct ospf_if_params *params;
b4a039bf
DS
5760 struct route_node *rn;
5761
718e3744 5762 params = IF_DEF_PARAMS (ifp);
5763
7a7be519 5764 if (argc == 5)
718e3744 5765 {
8d769265 5766 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 5767 if (!ret)
5768 {
5769 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5770 VTY_NEWLINE);
5771 return CMD_WARNING;
5772 }
5773
5774 params = ospf_lookup_if_params (ifp, addr);
5775 if (params == NULL)
b4a039bf
DS
5776 {
5777 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
5778 return CMD_WARNING;
5779 }
718e3744 5780
b4a039bf
DS
5781 params->auth_type = OSPF_AUTH_NOTSET;
5782 UNSET_IF_PARAM (params, auth_type);
5783 if (params != IF_DEF_PARAMS (ifp))
5784 {
5785 ospf_free_if_params (ifp, addr);
5786 ospf_if_update_params (ifp, addr);
5787 }
5788 }
5789 else
718e3744 5790 {
b4a039bf
DS
5791 /*
5792 * When a user enters 'no ip ospf authentication'
5793 * We should remove all authentication types from
5794 * the interface.
5795 */
813d4307
DW
5796 if ((params->auth_type == OSPF_AUTH_NULL) ||
5797 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
5798 (params->auth_type == OSPF_AUTH_SIMPLE))
5799 {
5800 params->auth_type = OSPF_AUTH_NOTSET;
5801 UNSET_IF_PARAM (params, auth_type);
5802 }
5803
b4a039bf
DS
5804 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
5805 {
5806 if ((params = rn->info))
5807 {
813d4307 5808
b4a039bf
DS
5809 if ((params->auth_type == OSPF_AUTH_NULL) ||
5810 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
5811 (params->auth_type == OSPF_AUTH_SIMPLE))
5812 {
5813 params->auth_type = OSPF_AUTH_NOTSET;
5814 UNSET_IF_PARAM (params, auth_type);
5815 if (params != IF_DEF_PARAMS (ifp))
5816 {
5817 ospf_free_if_params (ifp, rn->p.u.prefix4);
5818 ospf_if_update_params(ifp, rn->p.u.prefix4);
5819 }
5820 }
5821 }
5822 }
718e3744 5823 }
5824
5825 return CMD_SUCCESS;
5826}
5827
0d829fa7 5828
718e3744 5829DEFUN (ip_ospf_authentication_key,
5830 ip_ospf_authentication_key_addr_cmd,
7a7be519 5831 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
718e3744 5832 "IP Information\n"
5833 "OSPF interface commands\n"
5834 "Authentication password (key)\n"
5835 "The OSPF password (key)\n"
5836 "Address of interface")
5837{
cdc2d765 5838 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 5839 int idx = 0;
718e3744 5840 struct in_addr addr;
718e3744 5841 struct ospf_if_params *params;
5842
718e3744 5843 params = IF_DEF_PARAMS (ifp);
5844
0d829fa7 5845 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 5846 {
0d829fa7 5847 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 5848 {
5849 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5850 VTY_NEWLINE);
5851 return CMD_WARNING;
5852 }
5853
5854 params = ospf_get_if_params (ifp, addr);
5855 ospf_if_update_params (ifp, addr);
5856 }
5857
718e3744 5858 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
7a7be519 5859 strncpy ((char *) params->auth_simple, argv[3]->arg, OSPF_AUTH_SIMPLE_SIZE);
718e3744 5860 SET_IF_PARAM (params, auth_simple);
5861
5862 return CMD_SUCCESS;
5863}
5864
7a7be519 5865DEFUN_HIDDEN (ospf_authentication_key,
747e489c 5866 ospf_authentication_key_cmd,
0d829fa7 5867 "ospf authentication-key AUTH_KEY [A.B.C.D]",
747e489c
DW
5868 "OSPF interface commands\n"
5869 "Authentication password (key)\n"
0d829fa7
QY
5870 "The OSPF password (key)\n"
5871 "Address of interface\n")
718e3744 5872{
0d829fa7 5873 return ip_ospf_authentication_key (self, vty, argc, argv);
718e3744 5874}
5875
7a7be519 5876DEFUN (no_ip_ospf_authentication_key,
5877 no_ip_ospf_authentication_key_authkey_addr_cmd,
5878 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5879 NO_STR
5880 "IP Information\n"
5881 "OSPF interface commands\n"
5882 "Authentication password (key)\n"
5883 "The OSPF password (key)")
5884{
cdc2d765 5885 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 5886 int idx = 0;
7a7be519 5887 struct in_addr addr;
5888 struct ospf_if_params *params;
7a7be519 5889 params = IF_DEF_PARAMS (ifp);
5890
0d829fa7 5891 if (argv_find (argv, argc, "A.B.C.D", &idx))
7a7be519 5892 {
0d829fa7 5893 if (!inet_aton(argv[idx]->arg, &addr))
7a7be519 5894 {
5895 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5896 VTY_NEWLINE);
5897 return CMD_WARNING;
5898 }
813d4307 5899
7a7be519 5900 params = ospf_lookup_if_params (ifp, addr);
5901 if (params == NULL)
5902 return CMD_SUCCESS;
5903 }
718e3744 5904
7a7be519 5905 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
5906 UNSET_IF_PARAM (params, auth_simple);
718e3744 5907
7a7be519 5908 if (params != IF_DEF_PARAMS (ifp))
5909 {
5910 ospf_free_if_params (ifp, addr);
5911 ospf_if_update_params (ifp, addr);
5912 }
813d4307 5913
7a7be519 5914 return CMD_SUCCESS;
5915}
813d4307 5916
0d829fa7
QY
5917DEFUN_HIDDEN (no_ospf_authentication_key,
5918 no_ospf_authentication_key_authkey_addr_cmd,
5919 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5920 NO_STR
5921 "OSPF interface commands\n"
5922 "Authentication password (key)\n"
5923 "The OSPF password (key)")
5924{
5925 return no_ip_ospf_authentication_key (self, vty, argc, argv);
5926}
5927
718e3744 5928DEFUN (ip_ospf_message_digest_key,
537eae3f 5929 ip_ospf_message_digest_key_cmd,
7a7be519 5930 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
718e3744 5931 "IP Information\n"
5932 "OSPF interface commands\n"
5933 "Message digest authentication password (key)\n"
5934 "Key ID\n"
5935 "Use MD5 algorithm\n"
fefa0d82
QY
5936 "The OSPF password (key)\n"
5937 "Address of interface\n")
718e3744 5938{
cdc2d765 5939 VTY_DECLVAR_CONTEXT(interface, ifp);
718e3744 5940 struct crypt_key *ck;
5941 u_char key_id;
5942 struct in_addr addr;
718e3744 5943 struct ospf_if_params *params;
5944
718e3744 5945 params = IF_DEF_PARAMS (ifp);
fefa0d82
QY
5946 int idx = 0;
5947
5948 argv_find (argv, argc, "(1-255)", &idx);
0d829fa7 5949 char *keyid = argv[idx]->arg;
fefa0d82
QY
5950 argv_find (argv, argc, "KEY", &idx);
5951 char *cryptkey = argv[idx]->arg;
718e3744 5952
0d829fa7 5953 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 5954 {
0d829fa7 5955 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 5956 {
5957 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5958 VTY_NEWLINE);
5959 return CMD_WARNING;
5960 }
5961
5962 params = ospf_get_if_params (ifp, addr);
5963 ospf_if_update_params (ifp, addr);
5964 }
5965
fefa0d82 5966 key_id = strtol (keyid, NULL, 10);
718e3744 5967 if (ospf_crypt_key_lookup (params->auth_crypt, key_id) != NULL)
5968 {
5969 vty_out (vty, "OSPF: Key %d already exists%s", key_id, VTY_NEWLINE);
5970 return CMD_WARNING;
5971 }
5972
5973 ck = ospf_crypt_key_new ();
5974 ck->key_id = (u_char) key_id;
5975 memset (ck->auth_key, 0, OSPF_AUTH_MD5_SIZE+1);
fefa0d82 5976 strncpy ((char *) ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE);
718e3744 5977
5978 ospf_crypt_key_add (params->auth_crypt, ck);
5979 SET_IF_PARAM (params, auth_crypt);
5980
5981 return CMD_SUCCESS;
5982}
5983
7a7be519 5984DEFUN_HIDDEN (ospf_message_digest_key,
747e489c 5985 ospf_message_digest_key_cmd,
0d829fa7 5986 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
747e489c
DW
5987 "OSPF interface commands\n"
5988 "Message digest authentication password (key)\n"
5989 "Key ID\n"
5990 "Use MD5 algorithm\n"
0d829fa7
QY
5991 "The OSPF password (key)\n"
5992 "Address of interface\n")
7a7be519 5993{
0d829fa7 5994 return ip_ospf_message_digest_key (self, vty, argc, argv);
7a7be519 5995}
718e3744 5996
537eae3f
QY
5997DEFUN (no_ip_ospf_message_digest_key,
5998 no_ip_ospf_message_digest_key_cmd,
0d829fa7 5999 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
813d4307
DW
6000 NO_STR
6001 "IP Information\n"
6002 "OSPF interface commands\n"
6003 "Message digest authentication password (key)\n"
6004 "Key ID\n"
6005 "Use MD5 algorithm\n"
0d829fa7
QY
6006 "The OSPF password (key)\n"
6007 "Address of interface\n")
813d4307 6008{
cdc2d765 6009 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6010 int idx = 0;
813d4307
DW
6011 struct crypt_key *ck;
6012 int key_id;
6013 struct in_addr addr;
813d4307 6014 struct ospf_if_params *params;
813d4307
DW
6015 params = IF_DEF_PARAMS (ifp);
6016
0d829fa7
QY
6017 argv_find (argv, argc, "(1-255)", &idx);
6018 char *keyid = argv[idx]->arg;
7a7be519 6019
0d829fa7 6020 if (argv_find (argv, argc, "A.B.C.D", &idx))
7a7be519 6021 {
0d829fa7 6022 if (!inet_aton(argv[idx]->arg, &addr))
7a7be519 6023 {
6024 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6025 VTY_NEWLINE);
6026 return CMD_WARNING;
6027 }
6028
6029 params = ospf_lookup_if_params (ifp, addr);
6030 if (params == NULL)
6031 return CMD_SUCCESS;
6032 }
6033
0d829fa7 6034 key_id = strtol (keyid, NULL, 10);
7a7be519 6035 ck = ospf_crypt_key_lookup (params->auth_crypt, key_id);
6036 if (ck == NULL)
6037 {
6038 vty_out (vty, "OSPF: Key %d does not exist%s", key_id, VTY_NEWLINE);
6039 return CMD_WARNING;
6040 }
6041
6042 ospf_crypt_key_delete (params->auth_crypt, key_id);
6043
6044 if (params != IF_DEF_PARAMS (ifp))
6045 {
6046 ospf_free_if_params (ifp, addr);
6047 ospf_if_update_params (ifp, addr);
6048 }
6049
6050 return CMD_SUCCESS;
6051}
813d4307 6052
0d829fa7 6053DEFUN_HIDDEN (no_ospf_message_digest_key,
537eae3f 6054 no_ospf_message_digest_key_cmd,
0d829fa7
QY
6055 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6056 NO_STR
6057 "OSPF interface commands\n"
6058 "Message digest authentication password (key)\n"
6059 "Key ID\n"
6060 "Address of interface")
718e3744 6061{
537eae3f 6062 return no_ip_ospf_message_digest_key (self, vty, argc, argv);
718e3744 6063}
6064
718e3744 6065DEFUN (ip_ospf_cost,
5c2fc921 6066 ip_ospf_cost_cmd,
7a7be519 6067 "ip ospf cost (1-65535) [A.B.C.D]",
718e3744 6068 "IP Information\n"
6069 "OSPF interface commands\n"
6070 "Interface cost\n"
6071 "Cost\n"
5c2fc921 6072 "Address of interface\n")
718e3744 6073{
cdc2d765 6074 VTY_DECLVAR_CONTEXT(interface, ifp);
5c2fc921 6075 int idx = 0;
718e3744 6076 u_int32_t cost;
6077 struct in_addr addr;
718e3744 6078 struct ospf_if_params *params;
718e3744 6079 params = IF_DEF_PARAMS (ifp);
6080
5c2fc921
QY
6081 // get arguments
6082 char *coststr = NULL, *ifaddr = NULL;
6083 coststr = argv_find (argv, argc, "(1-65535)", &idx) ? argv[idx]->arg : NULL;
6084 ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
718e3744 6085
5c2fc921 6086 cost = strtol (coststr, NULL, 10);
718e3744 6087
5c2fc921 6088 if (ifaddr)
718e3744 6089 {
5c2fc921 6090 if(!inet_aton(ifaddr, &addr))
718e3744 6091 {
6092 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6093 VTY_NEWLINE);
6094 return CMD_WARNING;
6095 }
6096
6097 params = ospf_get_if_params (ifp, addr);
6098 ospf_if_update_params (ifp, addr);
6099 }
6100
6101 SET_IF_PARAM (params, output_cost_cmd);
6102 params->output_cost_cmd = cost;
6103
6104 ospf_if_recalculate_output_cost (ifp);
5c2fc921 6105
718e3744 6106 return CMD_SUCCESS;
6107}
6108
7a7be519 6109DEFUN_HIDDEN (ospf_cost,
5c2fc921
QY
6110 ospf_cost_cmd,
6111 "ospf cost (1-65535) [A.B.C.D]",
747e489c
DW
6112 "OSPF interface commands\n"
6113 "Interface cost\n"
6114 "Cost\n"
5c2fc921 6115 "Address of interface\n")
7a7be519 6116{
5c2fc921 6117 return ip_ospf_cost (self, vty, argc, argv);
7a7be519 6118}
9eff36b3 6119
718e3744 6120DEFUN (no_ip_ospf_cost,
5c2fc921
QY
6121 no_ip_ospf_cost_cmd,
6122 "no ip ospf cost [(1-65535)] [A.B.C.D]",
718e3744 6123 NO_STR
718e3744 6124 "OSPF interface commands\n"
6125 "Interface cost\n"
6126 "Address of interface")
6127{
cdc2d765 6128 VTY_DECLVAR_CONTEXT(interface, ifp);
5c2fc921 6129 int idx = 0;
718e3744 6130 struct in_addr addr;
718e3744 6131 struct ospf_if_params *params;
7a7be519 6132
718e3744 6133 params = IF_DEF_PARAMS (ifp);
6134
5c2fc921
QY
6135 // get arguments
6136 char *ifaddr = NULL;
6137 ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
718e3744 6138
7a7be519 6139 /* According to the semantics we are mimicking "no ip ospf cost N" is
6140 * always treated as "no ip ospf cost" regardless of the actual value
5c2fc921 6141 * of N already configured for the interface. Thus ignore cost. */
7a7be519 6142
5c2fc921 6143 if (ifaddr)
7a7be519 6144 {
5c2fc921 6145 if (!inet_aton(ifaddr, &addr))
7a7be519 6146 {
6147 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6148 VTY_NEWLINE);
6149 return CMD_WARNING;
6150 }
6151
6152 params = ospf_lookup_if_params (ifp, addr);
6153 if (params == NULL)
6154 return CMD_SUCCESS;
6155 }
6156
6157 UNSET_IF_PARAM (params, output_cost_cmd);
6158
6159 if (params != IF_DEF_PARAMS (ifp))
6160 {
6161 ospf_free_if_params (ifp, addr);
6162 ospf_if_update_params (ifp, addr);
6163 }
6164
6165 ospf_if_recalculate_output_cost (ifp);
6166
6167 return CMD_SUCCESS;
6168}
9eff36b3 6169
5c2fc921
QY
6170DEFUN_HIDDEN (no_ospf_cost,
6171 no_ospf_cost_cmd,
6172 "no ospf cost [(1-65535)] [A.B.C.D]",
6173 NO_STR
6174 "OSPF interface commands\n"
6175 "Interface cost\n"
6176 "Cost\n"
6177 "Address of interface\n")
827341b7 6178{
5c2fc921 6179 return no_ip_ospf_cost (self, vty, argc, argv);
827341b7
DO
6180}
6181
4dadc291 6182static void
718e3744 6183ospf_nbr_timer_update (struct ospf_interface *oi)
6184{
6185 struct route_node *rn;
6186 struct ospf_neighbor *nbr;
6187
6188 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
6189 if ((nbr = rn->info))
6190 {
6191 nbr->v_inactivity = OSPF_IF_PARAM (oi, v_wait);
6192 nbr->v_db_desc = OSPF_IF_PARAM (oi, retransmit_interval);
6193 nbr->v_ls_req = OSPF_IF_PARAM (oi, retransmit_interval);
6194 nbr->v_ls_upd = OSPF_IF_PARAM (oi, retransmit_interval);
6195 }
6196}
6197
f9ad937f 6198static int
6199ospf_vty_dead_interval_set (struct vty *vty, const char *interval_str,
6200 const char *nbr_str,
6201 const char *fast_hello_str)
718e3744 6202{
cdc2d765 6203 VTY_DECLVAR_CONTEXT(interface, ifp);
718e3744 6204 u_int32_t seconds;
f9ad937f 6205 u_char hellomult;
718e3744 6206 struct in_addr addr;
6207 int ret;
6208 struct ospf_if_params *params;
6209 struct ospf_interface *oi;
6210 struct route_node *rn;
6211
6212 params = IF_DEF_PARAMS (ifp);
f9ad937f 6213
6214 if (nbr_str)
718e3744 6215 {
f9ad937f 6216 ret = inet_aton(nbr_str, &addr);
718e3744 6217 if (!ret)
6218 {
6219 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6220 VTY_NEWLINE);
6221 return CMD_WARNING;
6222 }
6223
6224 params = ospf_get_if_params (ifp, addr);
6225 ospf_if_update_params (ifp, addr);
6226 }
6227
f9ad937f 6228 if (interval_str)
6229 {
6230 VTY_GET_INTEGER_RANGE ("Router Dead Interval", seconds, interval_str,
6231 1, 65535);
6232
6233 /* reset fast_hello too, just to be sure */
6234 UNSET_IF_PARAM (params, fast_hello);
6235 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6236 }
6237 else if (fast_hello_str)
6238 {
6239 VTY_GET_INTEGER_RANGE ("Hello Multiplier", hellomult, fast_hello_str,
6240 1, 10);
6241 /* 1s dead-interval with sub-second hellos desired */
6242 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
6243 SET_IF_PARAM (params, fast_hello);
6244 params->fast_hello = hellomult;
6245 }
6246 else
6247 {
6248 vty_out (vty, "Please specify dead-interval or hello-multiplier%s",
6249 VTY_NEWLINE);
6250 return CMD_WARNING;
6251 }
6252
718e3744 6253 SET_IF_PARAM (params, v_wait);
6254 params->v_wait = seconds;
6255
6256 /* Update timer values in neighbor structure. */
f9ad937f 6257 if (nbr_str)
718e3744 6258 {
cac3b5c4
PJ
6259 struct ospf *ospf;
6260 if ((ospf = ospf_lookup()))
68980084 6261 {
6262 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
6263 if (oi)
6264 ospf_nbr_timer_update (oi);
6265 }
718e3744 6266 }
6267 else
6268 {
6269 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6270 if ((oi = rn->info))
6271 ospf_nbr_timer_update (oi);
6272 }
6273
6274 return CMD_SUCCESS;
6275}
6276
f9ad937f 6277DEFUN (ip_ospf_dead_interval,
0d829fa7 6278 ip_ospf_dead_interval_cmd,
7a7be519 6279 "ip ospf dead-interval (1-65535) [A.B.C.D]",
f9ad937f 6280 "IP Information\n"
6281 "OSPF interface commands\n"
99a522c7 6282 "Interval time after which a neighbor is declared down\n"
f9ad937f 6283 "Seconds\n"
6284 "Address of interface\n")
6285{
0d829fa7
QY
6286 int idx = 0;
6287 char *interval = argv_find (argv, argc, "(1-65535)", &idx) ? argv[idx]->arg : NULL;
6288 char *ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
6289 return ospf_vty_dead_interval_set (vty, interval, ifaddr, NULL);
f9ad937f 6290}
6291
718e3744 6292
7a7be519 6293DEFUN_HIDDEN (ospf_dead_interval,
747e489c 6294 ospf_dead_interval_cmd,
0d829fa7 6295 "ospf dead-interval (1-65535) [A.B.C.D]",
747e489c 6296 "OSPF interface commands\n"
99a522c7 6297 "Interval time after which a neighbor is declared down\n"
0d829fa7
QY
6298 "Seconds\n"
6299 "Address of interface\n")
7a7be519 6300{
0d829fa7 6301 return ip_ospf_dead_interval (self, vty, argc, argv);
7a7be519 6302}
718e3744 6303
f9ad937f 6304DEFUN (ip_ospf_dead_interval_minimal,
6305 ip_ospf_dead_interval_minimal_addr_cmd,
7a7be519 6306 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
f9ad937f 6307 "IP Information\n"
6308 "OSPF interface commands\n"
99a522c7 6309 "Interval time after which a neighbor is declared down\n"
f9ad937f 6310 "Minimal 1s dead-interval with fast sub-second hellos\n"
6311 "Hello multiplier factor\n"
6312 "Number of Hellos to send each second\n"
6313 "Address of interface\n")
6314{
8d769265
DW
6315 int idx_number = 5;
6316 int idx_ipv4 = 6;
7a7be519 6317 if (argc == 7)
8d769265 6318 return ospf_vty_dead_interval_set (vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
f9ad937f 6319 else
8d769265 6320 return ospf_vty_dead_interval_set (vty, NULL, NULL, argv[idx_number]->arg);
f9ad937f 6321}
6322
718e3744 6323DEFUN (no_ip_ospf_dead_interval,
0d829fa7 6324 no_ip_ospf_dead_interval_cmd,
e83a9414 6325 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
718e3744 6326 NO_STR
6327 "IP Information\n"
6328 "OSPF interface commands\n"
99a522c7 6329 "Interval time after which a neighbor is declared down\n"
f9dfba8d 6330 "Seconds\n"
718e3744 6331 "Address of interface")
6332{
cdc2d765 6333 VTY_DECLVAR_CONTEXT(interface, ifp);
7a7be519 6334 int idx_ipv4 = argc - 1;
c604467a 6335 struct in_addr addr = { .s_addr = 0L};
718e3744 6336 int ret;
6337 struct ospf_if_params *params;
6338 struct ospf_interface *oi;
6339 struct route_node *rn;
020709f9 6340
718e3744 6341 params = IF_DEF_PARAMS (ifp);
6342
7a7be519 6343 if (argv[idx_ipv4]->type == IPV4_TKN)
718e3744 6344 {
8d769265 6345 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 6346 if (!ret)
6347 {
6348 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6349 VTY_NEWLINE);
6350 return CMD_WARNING;
6351 }
6352
6353 params = ospf_lookup_if_params (ifp, addr);
6354 if (params == NULL)
6355 return CMD_SUCCESS;
6356 }
6357
6358 UNSET_IF_PARAM (params, v_wait);
6359 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
f9ad937f 6360
6361 UNSET_IF_PARAM (params, fast_hello);
6362 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6363
718e3744 6364 if (params != IF_DEF_PARAMS (ifp))
6365 {
6366 ospf_free_if_params (ifp, addr);
6367 ospf_if_update_params (ifp, addr);
6368 }
6369
6370 /* Update timer values in neighbor structure. */
6371 if (argc == 1)
6372 {
cac3b5c4
PJ
6373 struct ospf *ospf;
6374
6375 if ((ospf = ospf_lookup()))
68980084 6376 {
6377 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
6378 if (oi)
6379 ospf_nbr_timer_update (oi);
6380 }
718e3744 6381 }
6382 else
6383 {
6384 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6385 if ((oi = rn->info))
6386 ospf_nbr_timer_update (oi);
6387 }
6388
6389 return CMD_SUCCESS;
6390}
6391
0d829fa7
QY
6392DEFUN_HIDDEN (no_ospf_dead_interval,
6393 no_ospf_dead_interval_cmd,
6394 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
6395 NO_STR
6396 "OSPF interface commands\n"
99a522c7 6397 "Interval time after which a neighbor is declared down\n"
0d829fa7
QY
6398 "Seconds\n"
6399 "Address of interface")
6400{
6401 return no_ip_ospf_dead_interval (self, vty, argc, argv);
6402}
6403
718e3744 6404DEFUN (ip_ospf_hello_interval,
0d829fa7 6405 ip_ospf_hello_interval_cmd,
7a7be519 6406 "ip ospf hello-interval (1-65535) [A.B.C.D]",
718e3744 6407 "IP Information\n"
6408 "OSPF interface commands\n"
6409 "Time between HELLO packets\n"
6410 "Seconds\n"
0d829fa7 6411 "Address of interface\n")
718e3744 6412{
cdc2d765 6413 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6414 int idx = 0;
718e3744 6415 struct in_addr addr;
718e3744 6416 struct ospf_if_params *params;
718e3744 6417 params = IF_DEF_PARAMS (ifp);
0d829fa7 6418 u_int32_t seconds = 0;
718e3744 6419
0d829fa7
QY
6420 argv_find (argv, argc, "(1-65535)", &idx);
6421 seconds = strtol (argv[idx]->arg, NULL, 10);
718e3744 6422
0d829fa7 6423 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6424 {
0d829fa7 6425 if(!inet_aton(argv[idx]->arg, &addr))
718e3744 6426 {
6427 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6428 VTY_NEWLINE);
6429 return CMD_WARNING;
6430 }
6431
6432 params = ospf_get_if_params (ifp, addr);
6433 ospf_if_update_params (ifp, addr);
6434 }
6435
f9ad937f 6436 SET_IF_PARAM (params, v_hello);
718e3744 6437 params->v_hello = seconds;
6438
6439 return CMD_SUCCESS;
6440}
6441
7a7be519 6442DEFUN_HIDDEN (ospf_hello_interval,
747e489c 6443 ospf_hello_interval_cmd,
0d829fa7 6444 "ospf hello-interval (1-65535) [A.B.C.D]",
747e489c
DW
6445 "OSPF interface commands\n"
6446 "Time between HELLO packets\n"
0d829fa7
QY
6447 "Seconds\n"
6448 "Address of interface\n")
7a7be519 6449{
0d829fa7 6450 return ip_ospf_hello_interval (self, vty, argc, argv);
7a7be519 6451}
718e3744 6452
6453DEFUN (no_ip_ospf_hello_interval,
0d829fa7
QY
6454 no_ip_ospf_hello_interval_cmd,
6455 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
718e3744 6456 NO_STR
6457 "IP Information\n"
6458 "OSPF interface commands\n"
0d829fa7 6459 "Time between HELLO packets\n" // ignored
f9dfba8d 6460 "Seconds\n"
0d829fa7 6461 "Address of interface\n")
718e3744 6462{
cdc2d765 6463 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6464 int idx = 0;
718e3744 6465 struct in_addr addr;
718e3744 6466 struct ospf_if_params *params;
df581cd3 6467
718e3744 6468 params = IF_DEF_PARAMS (ifp);
6469
0d829fa7 6470 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6471 {
0d829fa7 6472 if(!inet_aton(argv[idx]->arg, &addr))
718e3744 6473 {
6474 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6475 VTY_NEWLINE);
6476 return CMD_WARNING;
6477 }
6478
6479 params = ospf_lookup_if_params (ifp, addr);
6480 if (params == NULL)
6481 return CMD_SUCCESS;
6482 }
6483
6484 UNSET_IF_PARAM (params, v_hello);
f9ad937f 6485 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
718e3744 6486
6487 if (params != IF_DEF_PARAMS (ifp))
6488 {
6489 ospf_free_if_params (ifp, addr);
6490 ospf_if_update_params (ifp, addr);
6491 }
6492
6493 return CMD_SUCCESS;
6494}
6495
0d829fa7
QY
6496DEFUN_HIDDEN (no_ospf_hello_interval,
6497 no_ospf_hello_interval_cmd,
6498 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
6499 NO_STR
6500 "OSPF interface commands\n"
6501 "Time between HELLO packets\n" // ignored
6502 "Seconds\n"
6503 "Address of interface\n")
6504{
030204c7 6505 return no_ip_ospf_hello_interval (self, vty, argc, argv);
0d829fa7 6506}
718e3744 6507
6508DEFUN (ip_ospf_network,
6509 ip_ospf_network_cmd,
6147e2c6 6510 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
718e3744 6511 "IP Information\n"
6512 "OSPF interface commands\n"
6513 "Network type\n"
6514 "Specify OSPF broadcast multi-access network\n"
6515 "Specify OSPF NBMA network\n"
6516 "Specify OSPF point-to-multipoint network\n"
6517 "Specify OSPF point-to-point network\n")
6518{
cdc2d765 6519 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6520 int idx = 0;
718e3744 6521 int old_type = IF_DEF_PARAMS (ifp)->type;
6522 struct route_node *rn;
4b4bda9b
CF
6523
6524 if (old_type == OSPF_IFTYPE_LOOPBACK)
6525 {
6526 vty_out (vty, "This is a loopback interface. Can't set network type.%s", VTY_NEWLINE);
6527 return CMD_WARNING;
6528 }
6529
0d829fa7 6530 if (argv_find (argv, argc, "broadcast", &idx))
718e3744 6531 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_BROADCAST;
0d829fa7 6532 else if (argv_find (argv, argc, "non-broadcast", &idx))
718e3744 6533 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_NBMA;
0d829fa7 6534 else if (argv_find (argv, argc, "point-to-multipoint", &idx))
718e3744 6535 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
0d829fa7 6536 else if (argv_find (argv, argc, "point-to-point", &idx))
718e3744 6537 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOPOINT;
6538
6539 if (IF_DEF_PARAMS (ifp)->type == old_type)
6540 return CMD_SUCCESS;
6541
6542 SET_IF_PARAM (IF_DEF_PARAMS (ifp), type);
6543
6544 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6545 {
6546 struct ospf_interface *oi = rn->info;
6547
6548 if (!oi)
6549 continue;
6550
6551 oi->type = IF_DEF_PARAMS (ifp)->type;
6552
6553 if (oi->state > ISM_Down)
6554 {
7a7be519 6555 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
6556 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
6557 }
6558 }
6559
6560 return CMD_SUCCESS;
6561}
6562
6563DEFUN_HIDDEN (ospf_network,
6564 ospf_network_cmd,
e83a9414 6565 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7a7be519 6566 "OSPF interface commands\n"
6567 "Network type\n"
6568 "Specify OSPF broadcast multi-access network\n"
6569 "Specify OSPF NBMA network\n"
6570 "Specify OSPF point-to-multipoint network\n"
6571 "Specify OSPF point-to-point network\n")
6572{
0d829fa7 6573 return ip_ospf_network (self, vty, argc, argv);
7a7be519 6574}
6575
6576DEFUN (no_ip_ospf_network,
6577 no_ip_ospf_network_cmd,
6578 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6579 NO_STR
6580 "IP Information\n"
6581 "OSPF interface commands\n"
6582 "Network type\n"
6583 "Specify OSPF broadcast multi-access network\n"
6584 "Specify OSPF NBMA network\n"
6585 "Specify OSPF point-to-multipoint network\n"
6586 "Specify OSPF point-to-point network\n")
22b27e95 6587{
cdc2d765 6588 VTY_DECLVAR_CONTEXT(interface, ifp);
7a7be519 6589 int old_type = IF_DEF_PARAMS (ifp)->type;
6590 struct route_node *rn;
6591
6592 IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp);
6593
6594 if (IF_DEF_PARAMS (ifp)->type == old_type)
6595 return CMD_SUCCESS;
6596
6597 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6598 {
6599 struct ospf_interface *oi = rn->info;
6600
6601 if (!oi)
6602 continue;
6603
6604 oi->type = IF_DEF_PARAMS (ifp)->type;
6605
6606 if (oi->state > ISM_Down)
6607 {
6608 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
6609 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
6610 }
6611 }
6612
6613 return CMD_SUCCESS;
6614}
6615
0d829fa7
QY
6616DEFUN_HIDDEN (no_ospf_network,
6617 no_ospf_network_cmd,
6618 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6619 NO_STR
6620 "OSPF interface commands\n"
6621 "Network type\n"
6622 "Specify OSPF broadcast multi-access network\n"
6623 "Specify OSPF NBMA network\n"
6624 "Specify OSPF point-to-multipoint network\n"
6625 "Specify OSPF point-to-point network\n")
6626{
6627 return no_ip_ospf_network (self, vty, argc, argv);
6628}
6629
7a7be519 6630DEFUN (ip_ospf_priority,
537eae3f 6631 ip_ospf_priority_cmd,
7a7be519 6632 "ip ospf priority (0-255) [A.B.C.D]",
6633 "IP Information\n"
6634 "OSPF interface commands\n"
6635 "Router priority\n"
6636 "Priority\n"
6637 "Address of interface")
6638{
cdc2d765 6639 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6640 int idx = 0;
7a7be519 6641 long priority;
6642 struct route_node *rn;
6643 struct in_addr addr;
7a7be519 6644 struct ospf_if_params *params;
7a7be519 6645 params = IF_DEF_PARAMS (ifp);
6646
0d829fa7
QY
6647 argv_find (argv, argc, "(0-255)", &idx);
6648 priority = strtol (argv[idx]->arg, NULL, 10);
7a7be519 6649
0d829fa7 6650 if (argv_find (argv, argc, "A.B.C.D", &idx))
7a7be519 6651 {
0d829fa7 6652 if (!inet_aton(argv[idx]->arg, &addr))
7a7be519 6653 {
6654 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6655 VTY_NEWLINE);
6656 return CMD_WARNING;
6657 }
6658
6659 params = ospf_get_if_params (ifp, addr);
6660 ospf_if_update_params (ifp, addr);
6661 }
6662
6663 SET_IF_PARAM (params, priority);
6664 params->priority = priority;
6665
6666 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6667 {
6668 struct ospf_interface *oi = rn->info;
6669
6670 if (!oi)
6671 continue;
6672
6673 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
6674 {
6675 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
6676 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
718e3744 6677 }
6678 }
6679
6680 return CMD_SUCCESS;
6681}
6682
7a7be519 6683DEFUN_HIDDEN (ospf_priority,
6684 ospf_priority_cmd,
0d829fa7 6685 "ospf priority (0-255) [A.B.C.D]",
7a7be519 6686 "OSPF interface commands\n"
6687 "Router priority\n"
3a2d747c
QY
6688 "Priority\n"
6689 "Address of interface")
718e3744 6690{
0d829fa7 6691 return ip_ospf_priority (self, vty, argc, argv);
718e3744 6692}
6693
718e3744 6694DEFUN (no_ip_ospf_priority,
537eae3f 6695 no_ip_ospf_priority_cmd,
7a7be519 6696 "no ip ospf priority [(0-255) [A.B.C.D]]",
718e3744 6697 NO_STR
6698 "IP Information\n"
6699 "OSPF interface commands\n"
0d829fa7 6700 "Router priority\n" // ignored
813d4307 6701 "Priority\n"
718e3744 6702 "Address of interface")
6703{
cdc2d765 6704 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6705 int idx = 0;
718e3744 6706 struct route_node *rn;
6707 struct in_addr addr;
718e3744 6708 struct ospf_if_params *params;
6709
718e3744 6710 params = IF_DEF_PARAMS (ifp);
6711
0d829fa7 6712 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6713 {
0d829fa7 6714 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6715 {
6716 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6717 VTY_NEWLINE);
6718 return CMD_WARNING;
6719 }
6720
6721 params = ospf_lookup_if_params (ifp, addr);
6722 if (params == NULL)
6723 return CMD_SUCCESS;
6724 }
6725
6726 UNSET_IF_PARAM (params, priority);
6727 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
6728
6729 if (params != IF_DEF_PARAMS (ifp))
6730 {
6731 ospf_free_if_params (ifp, addr);
6732 ospf_if_update_params (ifp, addr);
6733 }
6734
6735 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6736 {
6737 struct ospf_interface *oi = rn->info;
6738
6739 if (!oi)
6740 continue;
6741
718e3744 6742 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
6743 {
6744 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
6745 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
6746 }
6747 }
6748
6749 return CMD_SUCCESS;
6750}
6751
0d829fa7 6752DEFUN_HIDDEN (no_ospf_priority,
537eae3f 6753 no_ospf_priority_cmd,
0d829fa7
QY
6754 "no ospf priority [(0-255) [A.B.C.D]]",
6755 NO_STR
6756 "OSPF interface commands\n"
6757 "Router priority\n"
6758 "Priority\n"
6759 "Address of interface")
6760{
6761 return no_ip_ospf_priority (self, vty, argc, argv);
6762}
a1afa410 6763
718e3744 6764DEFUN (ip_ospf_retransmit_interval,
6765 ip_ospf_retransmit_interval_addr_cmd,
7a7be519 6766 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
718e3744 6767 "IP Information\n"
6768 "OSPF interface commands\n"
6769 "Time between retransmitting lost link state advertisements\n"
6770 "Seconds\n"
6771 "Address of interface")
6772{
cdc2d765 6773 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6774 int idx = 0;
718e3744 6775 u_int32_t seconds;
6776 struct in_addr addr;
718e3744 6777 struct ospf_if_params *params;
718e3744 6778 params = IF_DEF_PARAMS (ifp);
718e3744 6779
0d829fa7
QY
6780 argv_find (argv, argc, "(3-65535)", &idx);
6781 seconds = strtol (argv[idx]->arg, NULL, 10);
718e3744 6782
0d829fa7 6783 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6784 {
0d829fa7 6785 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6786 {
6787 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6788 VTY_NEWLINE);
6789 return CMD_WARNING;
6790 }
6791
6792 params = ospf_get_if_params (ifp, addr);
6793 ospf_if_update_params (ifp, addr);
6794 }
6795
6796 SET_IF_PARAM (params, retransmit_interval);
6797 params->retransmit_interval = seconds;
6798
6799 return CMD_SUCCESS;
6800}
6801
7a7be519 6802DEFUN_HIDDEN (ospf_retransmit_interval,
747e489c 6803 ospf_retransmit_interval_cmd,
0d829fa7 6804 "ospf retransmit-interval (3-65535) [A.B.C.D]",
747e489c
DW
6805 "OSPF interface commands\n"
6806 "Time between retransmitting lost link state advertisements\n"
3a2d747c
QY
6807 "Seconds\n"
6808 "Address of interface")
7a7be519 6809{
0d829fa7 6810 return ip_ospf_retransmit_interval (self, vty, argc, argv);
7a7be519 6811}
718e3744 6812
6813DEFUN (no_ip_ospf_retransmit_interval,
6814 no_ip_ospf_retransmit_interval_addr_cmd,
0d829fa7 6815 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
718e3744 6816 NO_STR
6817 "IP Information\n"
6818 "OSPF interface commands\n"
3a2d747c
QY
6819 "Time between retransmitting lost link state advertisements\n"
6820 "Seconds\n"
0d829fa7 6821 "Address of interface\n")
718e3744 6822{
cdc2d765 6823 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6824 int idx = 0;
718e3744 6825 struct in_addr addr;
718e3744 6826 struct ospf_if_params *params;
47b91972 6827
718e3744 6828 params = IF_DEF_PARAMS (ifp);
6829
47b91972 6830 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6831 {
0d829fa7 6832 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6833 {
6834 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6835 VTY_NEWLINE);
6836 return CMD_WARNING;
6837 }
6838
6839 params = ospf_lookup_if_params (ifp, addr);
6840 if (params == NULL)
6841 return CMD_SUCCESS;
6842 }
6843
6844 UNSET_IF_PARAM (params, retransmit_interval);
6845 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
6846
6847 if (params != IF_DEF_PARAMS (ifp))
6848 {
6849 ospf_free_if_params (ifp, addr);
6850 ospf_if_update_params (ifp, addr);
6851 }
6852
6853 return CMD_SUCCESS;
6854}
6855
0d829fa7
QY
6856DEFUN_HIDDEN (no_ospf_retransmit_interval,
6857 no_ospf_retransmit_interval_cmd,
6858 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
6859 NO_STR
6860 "OSPF interface commands\n"
3a2d747c
QY
6861 "Time between retransmitting lost link state advertisements\n"
6862 "Seconds\n"
6863 "Address of interface\n")
0d829fa7
QY
6864{
6865 return no_ip_ospf_retransmit_interval (self, vty, argc, argv);
6866}
813d4307 6867
718e3744 6868DEFUN (ip_ospf_transmit_delay,
6869 ip_ospf_transmit_delay_addr_cmd,
7a7be519 6870 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
718e3744 6871 "IP Information\n"
6872 "OSPF interface commands\n"
6873 "Link state transmit delay\n"
6874 "Seconds\n"
6875 "Address of interface")
6876{
cdc2d765 6877 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6878 int idx = 0;
718e3744 6879 u_int32_t seconds;
6880 struct in_addr addr;
718e3744 6881 struct ospf_if_params *params;
47b91972 6882
718e3744 6883 params = IF_DEF_PARAMS (ifp);
0d829fa7
QY
6884 argv_find (argv, argc, "(1-65535)", &idx);
6885 seconds = strtol (argv[idx]->arg, NULL, 10);
718e3744 6886
0d829fa7 6887 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6888 {
0d829fa7 6889 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6890 {
6891 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6892 VTY_NEWLINE);
6893 return CMD_WARNING;
6894 }
6895
6896 params = ospf_get_if_params (ifp, addr);
6897 ospf_if_update_params (ifp, addr);
6898 }
6899
47b91972 6900 SET_IF_PARAM (params, transmit_delay);
718e3744 6901 params->transmit_delay = seconds;
6902
6903 return CMD_SUCCESS;
6904}
6905
7a7be519 6906DEFUN_HIDDEN (ospf_transmit_delay,
747e489c 6907 ospf_transmit_delay_cmd,
0d829fa7 6908 "ospf transmit-delay (1-65535) [A.B.C.D]",
747e489c
DW
6909 "OSPF interface commands\n"
6910 "Link state transmit delay\n"
3a2d747c
QY
6911 "Seconds\n"
6912 "Address of interface")
7a7be519 6913{
0d829fa7 6914 return ip_ospf_transmit_delay (self, vty, argc, argv);
7a7be519 6915}
718e3744 6916
6917DEFUN (no_ip_ospf_transmit_delay,
6918 no_ip_ospf_transmit_delay_addr_cmd,
0d829fa7 6919 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
718e3744 6920 NO_STR
6921 "IP Information\n"
6922 "OSPF interface commands\n"
6923 "Link state transmit delay\n"
6924 "Address of interface")
6925{
cdc2d765 6926 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6927 int idx = 0;
718e3744 6928 struct in_addr addr;
718e3744 6929 struct ospf_if_params *params;
6930
718e3744 6931 params = IF_DEF_PARAMS (ifp);
6932
0d829fa7 6933 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6934 {
0d829fa7 6935 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6936 {
6937 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6938 VTY_NEWLINE);
6939 return CMD_WARNING;
6940 }
6941
6942 params = ospf_lookup_if_params (ifp, addr);
6943 if (params == NULL)
6944 return CMD_SUCCESS;
6945 }
6946
6947 UNSET_IF_PARAM (params, transmit_delay);
6948 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
6949
6950 if (params != IF_DEF_PARAMS (ifp))
6951 {
6952 ospf_free_if_params (ifp, addr);
6953 ospf_if_update_params (ifp, addr);
6954 }
6955
6956 return CMD_SUCCESS;
6957}
6958
813d4307 6959
0d829fa7
QY
6960DEFUN_HIDDEN (no_ospf_transmit_delay,
6961 no_ospf_transmit_delay_cmd,
6962 "no ospf transmit-delay",
6963 NO_STR
6964 "OSPF interface commands\n"
6965 "Link state transmit delay\n")
813d4307 6966{
0d829fa7 6967 return no_ip_ospf_transmit_delay (self, vty, argc, argv);
813d4307
DW
6968}
6969
e723861d
DS
6970DEFUN (ip_ospf_area,
6971 ip_ospf_area_cmd,
22b27e95 6972 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)>",
e723861d
DS
6973 "IP Information\n"
6974 "OSPF interface commands\n"
7a7be519 6975 "Instance ID\n"
e723861d
DS
6976 "Enable OSPF on this interface\n"
6977 "OSPF area ID in IP address format\n"
6978 "OSPF area ID as a decimal value\n")
6979{
cdc2d765 6980 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6981 int idx = 0;
e723861d
DS
6982 int format, ret;
6983 struct in_addr area_id;
6984 struct ospf *ospf;
6985 struct ospf_if_params *params;
6986 struct route_node *rn;
7c8ff89e 6987 u_short instance = 0;
e723861d 6988
0d829fa7
QY
6989 if (argv_find (argv, argc, "(1-65535)", &idx))
6990 instance = strtol (argv[idx]->arg, NULL, 10);
6991 char *areaid = argv[argc - 1]->arg;
7c8ff89e
DS
6992
6993 ospf = ospf_lookup_instance (instance);
e723861d
DS
6994 if (ospf == NULL)
6995 {
7c8ff89e
DS
6996 params = IF_DEF_PARAMS (ifp);
6997 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
6998 {
6999 ospf_interface_unset (ifp);
7000 ospf = ospf_lookup();
7001 ospf->if_ospf_cli_count--;
7002 }
e723861d
DS
7003 return CMD_SUCCESS;
7004 }
7005
0d829fa7 7006 ret = ospf_str2area_id (areaid, &area_id, &format);
e723861d
DS
7007 if (ret < 0)
7008 {
7009 vty_out (vty, "Please specify area by A.B.C.D|<0-4294967295>%s",
7010 VTY_NEWLINE);
7011 return CMD_WARNING;
7012 }
7013 if (memcmp (ifp->name, "VLINK", 5) == 0)
7014 {
7015 vty_out (vty, "Cannot enable OSPF on a virtual link.%s", VTY_NEWLINE);
7016 return CMD_WARNING;
7017 }
7018
7019 params = IF_DEF_PARAMS (ifp);
7020 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
7021 {
73b9f703
VK
7022 vty_out (vty,
7023 "Must remove previous area config before changing ospf area %s",
7024 VTY_NEWLINE);
e723861d
DS
7025 return CMD_WARNING;
7026 }
7027
7028 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
7029 {
7030 if (rn->info != NULL)
7031 {
7032 vty_out (vty, "Please remove all network commands first.%s", VTY_NEWLINE);
7033 return CMD_WARNING;
7034 }
7035 }
7036
7037 /* enable ospf on this interface with area_id */
7038 ospf_interface_set (ifp, area_id);
7039 ospf->if_ospf_cli_count++;
7040
7041 return CMD_SUCCESS;
7042}
7043
7044DEFUN (no_ip_ospf_area,
7045 no_ip_ospf_area_cmd,
0d829fa7 7046 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)>]",
e723861d
DS
7047 NO_STR
7048 "IP Information\n"
7049 "OSPF interface commands\n"
3a2d747c 7050 "Instance ID\n"
7a7be519 7051 "Disable OSPF on this interface\n"
7052 "OSPF area ID in IP address format\n"
7053 "OSPF area ID as a decimal value\n")
e723861d 7054{
cdc2d765 7055 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 7056 int idx = 0;
e723861d
DS
7057 struct ospf *ospf;
7058 struct ospf_if_params *params;
7c8ff89e 7059 u_short instance = 0;
e723861d 7060
0d829fa7
QY
7061 if (argv_find (argv, argc, "(1-65535)", &idx))
7062 instance = strtol (argv[idx]->arg, NULL, 10);
813d4307
DW
7063
7064 if ((ospf = ospf_lookup_instance (instance)) == NULL)
7065 return CMD_SUCCESS;
7066
7067 params = IF_DEF_PARAMS (ifp);
7068 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area))
7069 {
0d829fa7 7070 vty_out (vty, "Can't find specified interface area configuration.%s", VTY_NEWLINE);
813d4307
DW
7071 return CMD_WARNING;
7072 }
7073
7074 ospf_interface_unset (ifp);
7075 ospf->if_ospf_cli_count--;
7076 return CMD_SUCCESS;
7077}
7078
6f2a6703
CF
7079DEFUN (ospf_redistribute_source,
7080 ospf_redistribute_source_cmd,
40d1cbfb 7081 "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
d1c65c21 7082 REDIST_STR
ab0181ee 7083 FRR_REDIST_HELP_STR_OSPFD
718e3744 7084 "Metric for redistributed routes\n"
7085 "OSPF default metric\n"
7086 "OSPF exterior metric type for redistributed routes\n"
7087 "Set OSPF External Type 1 metrics\n"
7088 "Set OSPF External Type 2 metrics\n"
7089 "Route map reference\n"
7090 "Pointer to route-map entries\n")
7091{
cdc2d765 7092 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7093 int idx_protocol = 1;
718e3744 7094 int source;
7095 int type = -1;
7096 int metric = -1;
7c8ff89e 7097 struct ospf_redist *red;
6d681bd8 7098 int idx = 0;
6f2a6703 7099
7c8ff89e
DS
7100 if (!ospf)
7101 return CMD_SUCCESS;
7102
718e3744 7103 /* Get distribute source. */
6d681bd8
QY
7104 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7105 if (source < 0)
718e3744 7106 return CMD_WARNING;
7107
6d681bd8
QY
7108 red = ospf_redist_add(ospf, source, 0);
7109
718e3744 7110 /* Get metric value. */
6d681bd8
QY
7111 if (argv_find (argv, argc, "(0-16777214)", &idx)) {
7112 if (!str2metric (argv[idx]->arg, &metric))
718e3744 7113 return CMD_WARNING;
6d681bd8 7114 }
718e3744 7115 /* Get metric type. */
6d681bd8
QY
7116 else if (argv_find (argv, argc, "(1-2)", &idx)) {
7117 if (!str2metric_type (argv[idx]->arg, &type))
718e3744 7118 return CMD_WARNING;
6d681bd8
QY
7119 }
7120 /* Get route-map */
7121 else if (argv_find (argv, argc, "WORD", &idx)) {
7122 ospf_routemap_set (red, argv[idx]->arg);
7123 }
718e3744 7124 else
7c8ff89e 7125 ospf_routemap_unset (red);
718e3744 7126
7c8ff89e 7127 return ospf_redistribute_set (ospf, source, 0, type, metric);
718e3744 7128}
7129
718e3744 7130DEFUN (no_ospf_redistribute_source,
7131 no_ospf_redistribute_source_cmd,
40d1cbfb 7132 "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7133 NO_STR
d1c65c21 7134 REDIST_STR
ab0181ee 7135 FRR_REDIST_HELP_STR_OSPFD
813d4307
DW
7136 "Metric for redistributed routes\n"
7137 "OSPF default metric\n"
7138 "OSPF exterior metric type for redistributed routes\n"
7139 "Set OSPF External Type 1 metrics\n"
7140 "Set OSPF External Type 2 metrics\n"
7141 "Route map reference\n"
7142 "Pointer to route-map entries\n")
718e3744 7143{
cdc2d765 7144 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7145 int idx_protocol = 2;
718e3744 7146 int source;
7c8ff89e 7147 struct ospf_redist *red;
718e3744 7148
6d681bd8
QY
7149 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7150 if (source < 0)
718e3744 7151 return CMD_WARNING;
7152
7c8ff89e
DS
7153 red = ospf_redist_lookup(ospf, source, 0);
7154 if (!red)
7155 return CMD_SUCCESS;
7156
7157 ospf_routemap_unset (red);
7158 return ospf_redistribute_unset (ospf, source, 0);
7159}
7160
7161DEFUN (ospf_redistribute_instance_source,
7162 ospf_redistribute_instance_source_cmd,
6cf3661d 7163 "redistribute <ospf|table> (1-65535) {metric (0-16777214)|metric-type (1-2)|route-map WORD}",
7c8ff89e
DS
7164 REDIST_STR
7165 "Open Shortest Path First\n"
2d627ff5
DS
7166 "Non-main Kernel Routing Table\n"
7167 "Instance ID/Table ID\n"
7c8ff89e
DS
7168 "Metric for redistributed routes\n"
7169 "OSPF default metric\n"
7170 "OSPF exterior metric type for redistributed routes\n"
7171 "Set OSPF External Type 1 metrics\n"
7172 "Set OSPF External Type 2 metrics\n"
7173 "Route map reference\n"
7174 "Pointer to route-map entries\n")
7175{
cdc2d765 7176 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7177 int idx_ospf_table = 1;
7178 int idx_number = 2;
f4d78586 7179 int idx = 3;
7c8ff89e
DS
7180 int source;
7181 int type = -1;
7182 int metric = -1;
7183 u_short instance;
7184 struct ospf_redist *red;
7185
d8f70b86
DS
7186 if (!ospf)
7187 return CMD_SUCCESS;
7188
6d681bd8 7189 source = proto_redistnum (AFI_IP, argv[idx_ospf_table]->text);
2d627ff5 7190
8d769265 7191 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7c8ff89e
DS
7192
7193 if (!ospf)
7194 return CMD_SUCCESS;
7195
2d627ff5 7196 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
7c8ff89e
DS
7197 {
7198 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
7199 VTY_NEWLINE);
7200 return CMD_WARNING;
7201 }
7202
2d627ff5 7203 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
7c8ff89e
DS
7204 {
7205 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
7206 VTY_NEWLINE);
7207 return CMD_WARNING;
7208 }
7209
7c8ff89e 7210 /* Get metric value. */
f4d78586
DS
7211 if (argv_find (argv, argc, "metric", &idx))
7212 if (!str2metric (argv[idx+1]->arg, &metric))
7c8ff89e
DS
7213 return CMD_WARNING;
7214
f4d78586 7215 idx = 3;
7c8ff89e 7216 /* Get metric type. */
f4d78586
DS
7217 if (argv_find (argv, argc, "metric-type", &idx))
7218 if (!str2metric_type (argv[idx+1]->arg, &type))
7c8ff89e
DS
7219 return CMD_WARNING;
7220
7221 red = ospf_redist_add(ospf, source, instance);
7a7be519 7222
f4d78586
DS
7223 idx = 3;
7224 if (argv_find (argv, argc, "route-map", &idx))
7225 ospf_routemap_set (red, argv[idx+1]->arg);
7c8ff89e
DS
7226 else
7227 ospf_routemap_unset (red);
7228
7229 return ospf_redistribute_set (ospf, source, instance, type, metric);
7230}
7231
7232DEFUN (no_ospf_redistribute_instance_source,
7233 no_ospf_redistribute_instance_source_cmd,
6cf3661d 7234 "no redistribute <ospf|table> (1-65535) {metric (0-16777214)|metric-type (1-2)|route-map WORD}",
7c8ff89e
DS
7235 NO_STR
7236 REDIST_STR
7237 "Open Shortest Path First\n"
2d627ff5
DS
7238 "Non-main Kernel Routing Table\n"
7239 "Instance ID/Table Id\n"
7c8ff89e
DS
7240 "Metric for redistributed routes\n"
7241 "OSPF default metric\n"
7242 "OSPF exterior metric type for redistributed routes\n"
7243 "Set OSPF External Type 1 metrics\n"
7244 "Set OSPF External Type 2 metrics\n"
7245 "Route map reference\n"
7246 "Pointer to route-map entries\n")
7247{
cdc2d765 7248 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7249 int idx_ospf_table = 2;
7250 int idx_number = 3;
7c8ff89e
DS
7251 u_int instance;
7252 struct ospf_redist *red;
7253 int source;
7254
8d769265 7255 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
2d627ff5
DS
7256 source = ZEBRA_ROUTE_OSPF;
7257 else
7258 source = ZEBRA_ROUTE_TABLE;
7259
8d769265 7260 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7c8ff89e 7261
2d627ff5 7262 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
7c8ff89e
DS
7263 {
7264 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
7265 VTY_NEWLINE);
7266 return CMD_WARNING;
7267 }
7268
2d627ff5 7269 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
7c8ff89e
DS
7270 {
7271 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
7272 VTY_NEWLINE);
7273 return CMD_WARNING;
7274 }
7275
7c8ff89e
DS
7276 red = ospf_redist_lookup(ospf, source, instance);
7277 if (!red)
7278 return CMD_SUCCESS;
7279
7280 ospf_routemap_unset (red);
7281 return ospf_redistribute_unset (ospf, source, instance);
718e3744 7282}
7283
7284DEFUN (ospf_distribute_list_out,
7285 ospf_distribute_list_out_cmd,
40d1cbfb 7286 "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
718e3744 7287 "Filter networks in routing updates\n"
6f2a6703
CF
7288 "Access-list name\n"
7289 OUT_STR
ab0181ee 7290 FRR_REDIST_HELP_STR_OSPFD)
718e3744 7291{
cdc2d765 7292 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7293 int idx_word = 1;
6f2a6703 7294 int source;
718e3744 7295
6d681bd8
QY
7296 char *proto = argv[argc - 1]->text;
7297
6f2a6703 7298 /* Get distribute source. */
6d681bd8
QY
7299 source = proto_redistnum(AFI_IP, proto);
7300 if (source < 0)
6f2a6703 7301 return CMD_WARNING;
718e3744 7302
8d769265 7303 return ospf_distribute_list_out_set (ospf, source, argv[idx_word]->arg);
718e3744 7304}
7305
6f2a6703
CF
7306DEFUN (no_ospf_distribute_list_out,
7307 no_ospf_distribute_list_out_cmd,
40d1cbfb 7308 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
6f2a6703
CF
7309 NO_STR
7310 "Filter networks in routing updates\n"
7311 "Access-list name\n"
7312 OUT_STR
ab0181ee 7313 FRR_REDIST_HELP_STR_OSPFD)
718e3744 7314{
cdc2d765 7315 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7316 int idx_word = 2;
6f2a6703 7317 int source;
020709f9 7318
6d681bd8
QY
7319 char *proto = argv[argc - 1]->text;
7320 source = proto_redistnum(AFI_IP, proto);
7321 if (source < 0)
6f2a6703 7322 return CMD_WARNING;
718e3744 7323
8d769265 7324 return ospf_distribute_list_out_unset (ospf, source, argv[idx_word]->arg);
718e3744 7325}
7326
6f2a6703
CF
7327/* Default information originate. */
7328DEFUN (ospf_default_information_originate,
7329 ospf_default_information_originate_cmd,
e83a9414 7330 "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7331 "Control distribution of default information\n"
7332 "Distribute a default route\n"
7333 "Always advertise default route\n"
6f2a6703
CF
7334 "OSPF default metric\n"
7335 "OSPF metric\n"
718e3744 7336 "OSPF metric type for default routes\n"
7337 "Set OSPF External Type 1 metrics\n"
7338 "Set OSPF External Type 2 metrics\n"
718e3744 7339 "Route map reference\n"
7340 "Pointer to route-map entries\n")
7341{
cdc2d765 7342 VTY_DECLVAR_CONTEXT(ospf, ospf);
6f2a6703 7343 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
718e3744 7344 int type = -1;
7345 int metric = -1;
7c8ff89e 7346 struct ospf_redist *red;
6d681bd8 7347 int idx = 0;
7c8ff89e 7348
6d681bd8 7349 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
6f2a6703
CF
7350
7351 /* Check whether "always" was specified */
6d681bd8 7352 if (argv_find (argv, argc, "always", &idx))
6f2a6703 7353 default_originate = DEFAULT_ORIGINATE_ALWAYS;
6d681bd8
QY
7354 /* Get metric value */
7355 else if (argv_find (argv, argc, "(0-16777214)", &idx)) {
7356 if (!str2metric (argv[idx]->arg, &metric))
718e3744 7357 return CMD_WARNING;
6d681bd8 7358 }
718e3744 7359 /* Get metric type. */
6d681bd8
QY
7360 else if (argv_find (argv, argc, "(1-2)", &idx)) {
7361 if (!str2metric_type (argv[idx]->arg, &type))
718e3744 7362 return CMD_WARNING;
6d681bd8
QY
7363 }
7364 /* Get route-map */
7365 else if (argv_find (argv, argc, "WORD", &idx))
7366 ospf_routemap_set (red, argv[idx]->arg);
718e3744 7367 else
7c8ff89e 7368 ospf_routemap_unset (red);
718e3744 7369
6f2a6703
CF
7370 return ospf_redistribute_default_set (ospf, default_originate,
7371 type, metric);
718e3744 7372}
7373
7374DEFUN (no_ospf_default_information_originate,
7375 no_ospf_default_information_originate_cmd,
12dcf78e 7376 "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7377 NO_STR
7378 "Control distribution of default information\n"
813d4307
DW
7379 "Distribute a default route\n"
7380 "Always advertise default route\n"
7381 "OSPF default metric\n"
7382 "OSPF metric\n"
7383 "OSPF metric type for default routes\n"
7384 "Set OSPF External Type 1 metrics\n"
7385 "Set OSPF External Type 2 metrics\n"
7386 "Route map reference\n"
7387 "Pointer to route-map entries\n")
718e3744 7388{
cdc2d765 7389 VTY_DECLVAR_CONTEXT(ospf, ospf);
718e3744 7390 struct prefix_ipv4 p;
7c8ff89e
DS
7391 struct ospf_external *ext;
7392 struct ospf_redist *red;
7c8ff89e 7393
718e3744 7394 p.family = AF_INET;
7395 p.prefix.s_addr = 0;
7396 p.prefixlen = 0;
7397
5339cfdb 7398 ospf_external_lsa_flush (ospf, DEFAULT_ROUTE, &p, 0);
718e3744 7399
7c8ff89e
DS
7400 if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) &&
7401 EXTERNAL_INFO (ext)) {
7402 ospf_external_info_delete (DEFAULT_ROUTE, 0, p);
7403 ospf_external_del (DEFAULT_ROUTE, 0);
718e3744 7404 }
7405
7c8ff89e
DS
7406 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
7407 if (!red)
7408 return CMD_SUCCESS;
7409
7410 ospf_routemap_unset (red);
020709f9 7411 return ospf_redistribute_default_unset (ospf);
718e3744 7412}
7413
7414DEFUN (ospf_default_metric,
7415 ospf_default_metric_cmd,
6147e2c6 7416 "default-metric (0-16777214)",
718e3744 7417 "Set metric of redistributed routes\n"
7418 "Default metric\n")
7419{
cdc2d765 7420 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7421 int idx_number = 1;
718e3744 7422 int metric = -1;
7423
8d769265 7424 if (!str2metric (argv[idx_number]->arg, &metric))
718e3744 7425 return CMD_WARNING;
7426
68980084 7427 ospf->default_metric = metric;
718e3744 7428
7429 return CMD_SUCCESS;
7430}
7431
7432DEFUN (no_ospf_default_metric,
7433 no_ospf_default_metric_cmd,
7a7be519 7434 "no default-metric [(0-16777214)]",
718e3744 7435 NO_STR
7a7be519 7436 "Set metric of redistributed routes\n"
7437 "Default metric\n")
718e3744 7438{
cdc2d765 7439 VTY_DECLVAR_CONTEXT(ospf, ospf);
68980084 7440
7441 ospf->default_metric = -1;
7442
718e3744 7443 return CMD_SUCCESS;
7444}
7445
718e3744 7446
7447DEFUN (ospf_distance,
7448 ospf_distance_cmd,
6147e2c6 7449 "distance (1-255)",
eaa1ae0d 7450 "Administrative distance\n"
718e3744 7451 "OSPF Administrative distance\n")
7452{
cdc2d765 7453 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7454 int idx_number = 1;
68980084 7455
8d769265 7456 ospf->distance_all = atoi (argv[idx_number]->arg);
68980084 7457
718e3744 7458 return CMD_SUCCESS;
7459}
7460
7461DEFUN (no_ospf_distance,
7462 no_ospf_distance_cmd,
6147e2c6 7463 "no distance (1-255)",
718e3744 7464 NO_STR
eaa1ae0d 7465 "Administrative distance\n"
718e3744 7466 "OSPF Administrative distance\n")
7467{
cdc2d765 7468 VTY_DECLVAR_CONTEXT(ospf, ospf);
68980084 7469
7470 ospf->distance_all = 0;
7471
718e3744 7472 return CMD_SUCCESS;
7473}
7474
7475DEFUN (no_ospf_distance_ospf,
7476 no_ospf_distance_ospf_cmd,
eaa1ae0d 7477 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
718e3744 7478 NO_STR
eaa1ae0d
QY
7479 "Administrative distance\n"
7480 "OSPF administrative distance\n"
718e3744 7481 "Intra-area routes\n"
813d4307 7482 "Distance for intra-area routes\n"
718e3744 7483 "Inter-area routes\n"
813d4307
DW
7484 "Distance for inter-area routes\n"
7485 "External routes\n"
7486 "Distance for external routes\n")
718e3744 7487{
cdc2d765 7488 VTY_DECLVAR_CONTEXT(ospf, ospf);
eaa1ae0d 7489 int idx = 0;
718e3744 7490
7c8ff89e
DS
7491 if (!ospf)
7492 return CMD_SUCCESS;
7493
eaa1ae0d
QY
7494 if (argv_find (argv, argc, "intra-area", &idx) || argc == 3)
7495 idx = ospf->distance_intra = 0;
7496 if (argv_find (argv, argc, "inter-area", &idx) || argc == 3)
7497 idx = ospf->distance_inter = 0;
7498 if (argv_find (argv, argc, "external", &idx) || argc == 3)
6f2a6703 7499 ospf->distance_external = 0;
718e3744 7500
718e3744 7501 return CMD_SUCCESS;
7502}
7503
6f2a6703
CF
7504DEFUN (ospf_distance_ospf,
7505 ospf_distance_ospf_cmd,
eaa1ae0d
QY
7506 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
7507 "Administrative distance\n"
7508 "OSPF administrative distance\n"
718e3744 7509 "Intra-area routes\n"
7510 "Distance for intra-area routes\n"
718e3744 7511 "Inter-area routes\n"
7512 "Distance for inter-area routes\n"
7513 "External routes\n"
718e3744 7514 "Distance for external routes\n")
7515{
cdc2d765 7516 VTY_DECLVAR_CONTEXT(ospf, ospf);
eaa1ae0d 7517 int idx = 0;
68980084 7518
eaa1ae0d
QY
7519 if (argv_find (argv, argc, "intra-area", &idx))
7520 ospf->distance_intra = atoi(argv[idx + 1]->arg);
7521 idx = 0;
7522 if (argv_find (argv, argc, "inter-area", &idx))
7523 ospf->distance_inter = atoi(argv[idx + 1]->arg);
7524 idx = 0;
7525 if (argv_find (argv, argc, "external", &idx))
7526 ospf->distance_external = atoi(argv[idx + 1]->arg);
68980084 7527
718e3744 7528 return CMD_SUCCESS;
7529}
7530
d7d73ffc 7531#if 0
718e3744 7532DEFUN (ospf_distance_source,
7533 ospf_distance_source_cmd,
6147e2c6 7534 "distance (1-255) A.B.C.D/M",
718e3744 7535 "Administrative distance\n"
7536 "Distance value\n"
7537 "IP source prefix\n")
7538{
cdc2d765 7539 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7540 int idx_number = 1;
7541 int idx_ipv4_prefixlen = 2;
020709f9 7542
7c8ff89e
DS
7543 if (!ospf)
7544 return CMD_SUCCESS;
7545
8d769265 7546 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
68980084 7547
718e3744 7548 return CMD_SUCCESS;
7549}
7550
7551DEFUN (no_ospf_distance_source,
7552 no_ospf_distance_source_cmd,
6147e2c6 7553 "no distance (1-255) A.B.C.D/M",
718e3744 7554 NO_STR
7555 "Administrative distance\n"
7556 "Distance value\n"
7557 "IP source prefix\n")
7558{
cdc2d765 7559 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7560 int idx_number = 2;
7561 int idx_ipv4_prefixlen = 3;
020709f9 7562
7c8ff89e
DS
7563 if (!ospf)
7564 return CMD_SUCCESS;
7565
8d769265 7566 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
020709f9 7567
718e3744 7568 return CMD_SUCCESS;
7569}
7570
7571DEFUN (ospf_distance_source_access_list,
7572 ospf_distance_source_access_list_cmd,
6147e2c6 7573 "distance (1-255) A.B.C.D/M WORD",
718e3744 7574 "Administrative distance\n"
7575 "Distance value\n"
7576 "IP source prefix\n"
7577 "Access list name\n")
7578{
cdc2d765 7579 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7580 int idx_number = 1;
7581 int idx_ipv4_prefixlen = 2;
7582 int idx_word = 3;
020709f9 7583
7c8ff89e
DS
7584 if (!ospf)
7585 return CMD_SUCCESS;
7586
8d769265 7587 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 7588
718e3744 7589 return CMD_SUCCESS;
7590}
7591
7592DEFUN (no_ospf_distance_source_access_list,
7593 no_ospf_distance_source_access_list_cmd,
6147e2c6 7594 "no distance (1-255) A.B.C.D/M WORD",
718e3744 7595 NO_STR
7596 "Administrative distance\n"
7597 "Distance value\n"
7598 "IP source prefix\n"
7599 "Access list name\n")
7600{
cdc2d765 7601 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7602 int idx_number = 2;
7603 int idx_ipv4_prefixlen = 3;
7604 int idx_word = 4;
020709f9 7605
7c8ff89e
DS
7606 if (!ospf)
7607 return CMD_SUCCESS;
7608
8d769265 7609 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 7610
718e3744 7611 return CMD_SUCCESS;
7612}
d7d73ffc 7613#endif
718e3744 7614
ba682537 7615DEFUN (ip_ospf_mtu_ignore,
7616 ip_ospf_mtu_ignore_addr_cmd,
7a7be519 7617 "ip ospf mtu-ignore [A.B.C.D]",
ba682537 7618 "IP Information\n"
7619 "OSPF interface commands\n"
99a522c7 7620 "Disable MTU mismatch detection on this interface\n"
ba682537 7621 "Address of interface")
7622{
cdc2d765 7623 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 7624 int idx_ipv4 = 3;
ba682537 7625 struct in_addr addr;
7626 int ret;
7627
7628 struct ospf_if_params *params;
7629 params = IF_DEF_PARAMS (ifp);
7630
7a7be519 7631 if (argc == 4)
ba682537 7632 {
8d769265 7633 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
ba682537 7634 if (!ret)
7635 {
7636 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7637 VTY_NEWLINE);
7638 return CMD_WARNING;
7639 }
7640 params = ospf_get_if_params (ifp, addr);
7641 ospf_if_update_params (ifp, addr);
7642 }
7643 params->mtu_ignore = 1;
7644 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7645 SET_IF_PARAM (params, mtu_ignore);
7646 else
7647 {
7648 UNSET_IF_PARAM (params, mtu_ignore);
7649 if (params != IF_DEF_PARAMS (ifp))
7650 {
7651 ospf_free_if_params (ifp, addr);
7652 ospf_if_update_params (ifp, addr);
7653 }
7654 }
7655 return CMD_SUCCESS;
7656}
7657
ba682537 7658DEFUN (no_ip_ospf_mtu_ignore,
7659 no_ip_ospf_mtu_ignore_addr_cmd,
7a7be519 7660 "no ip ospf mtu-ignore [A.B.C.D]",
ba682537 7661 "IP Information\n"
7662 "OSPF interface commands\n"
99a522c7 7663 "Disable MTU mismatch detection on this interface\n"
ba682537 7664 "Address of interface")
7665{
cdc2d765 7666 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 7667 int idx_ipv4 = 4;
ba682537 7668 struct in_addr addr;
7669 int ret;
7670
7671 struct ospf_if_params *params;
7672 params = IF_DEF_PARAMS (ifp);
7673
7a7be519 7674 if (argc == 5)
ba682537 7675 {
8d769265 7676 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
ba682537 7677 if (!ret)
7678 {
7679 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7680 VTY_NEWLINE);
7681 return CMD_WARNING;
7682 }
7683 params = ospf_get_if_params (ifp, addr);
7684 ospf_if_update_params (ifp, addr);
7685 }
7686 params->mtu_ignore = 0;
7687 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7688 SET_IF_PARAM (params, mtu_ignore);
7689 else
7690 {
7691 UNSET_IF_PARAM (params, mtu_ignore);
7692 if (params != IF_DEF_PARAMS (ifp))
7693 {
7694 ospf_free_if_params (ifp, addr);
7695 ospf_if_update_params (ifp, addr);
7696 }
7697 }
7698 return CMD_SUCCESS;
7699}
7700
6b0655a2 7701
88d6cf37 7702DEFUN (ospf_max_metric_router_lsa_admin,
7703 ospf_max_metric_router_lsa_admin_cmd,
7704 "max-metric router-lsa administrative",
7705 "OSPF maximum / infinite-distance metric\n"
7706 "Advertise own Router-LSA with infinite distance (stub router)\n"
7707 "Administratively applied, for an indefinite period\n")
7708{
cdc2d765 7709 VTY_DECLVAR_CONTEXT(ospf, ospf);
88d6cf37 7710 struct listnode *ln;
7711 struct ospf_area *area;
7c8ff89e 7712
88d6cf37 7713 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7714 {
7715 SET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
7716
7717 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
c363d386 7718 ospf_router_lsa_update_area (area);
88d6cf37 7719 }
4ba4fc85
AB
7720
7721 /* Allows for areas configured later to get the property */
7722 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
7723
88d6cf37 7724 return CMD_SUCCESS;
7725}
7726
7727DEFUN (no_ospf_max_metric_router_lsa_admin,
7728 no_ospf_max_metric_router_lsa_admin_cmd,
7729 "no max-metric router-lsa administrative",
7730 NO_STR
7731 "OSPF maximum / infinite-distance metric\n"
7732 "Advertise own Router-LSA with infinite distance (stub router)\n"
7733 "Administratively applied, for an indefinite period\n")
7734{
cdc2d765 7735 VTY_DECLVAR_CONTEXT(ospf, ospf);
88d6cf37 7736 struct listnode *ln;
7737 struct ospf_area *area;
7c8ff89e 7738
88d6cf37 7739 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7740 {
7741 UNSET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
7742
7743 /* Don't trample on the start-up stub timer */
7744 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)
7745 && !area->t_stub_router)
7746 {
7747 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
c363d386 7748 ospf_router_lsa_update_area (area);
88d6cf37 7749 }
7750 }
4ba4fc85 7751 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
88d6cf37 7752 return CMD_SUCCESS;
7753}
7754
7755DEFUN (ospf_max_metric_router_lsa_startup,
7756 ospf_max_metric_router_lsa_startup_cmd,
6147e2c6 7757 "max-metric router-lsa on-startup (5-86400)",
88d6cf37 7758 "OSPF maximum / infinite-distance metric\n"
7759 "Advertise own Router-LSA with infinite distance (stub router)\n"
7760 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7761 "Time (seconds) to advertise self as stub-router\n")
7762{
cdc2d765 7763 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7764 int idx_number = 3;
88d6cf37 7765 unsigned int seconds;
7c8ff89e 7766
88d6cf37 7767 if (argc != 1)
7768 {
7769 vty_out (vty, "%% Must supply stub-router period");
7770 return CMD_WARNING;
7771 }
7772
8d769265 7773 VTY_GET_INTEGER ("stub-router startup period", seconds, argv[idx_number]->arg);
88d6cf37 7774
7775 ospf->stub_router_startup_time = seconds;
7776
7777 return CMD_SUCCESS;
7778}
7779
7780DEFUN (no_ospf_max_metric_router_lsa_startup,
7781 no_ospf_max_metric_router_lsa_startup_cmd,
7a7be519 7782 "no max-metric router-lsa on-startup [(5-86400)]",
88d6cf37 7783 NO_STR
7784 "OSPF maximum / infinite-distance metric\n"
7785 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
7786 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7787 "Time (seconds) to advertise self as stub-router\n")
88d6cf37 7788{
cdc2d765 7789 VTY_DECLVAR_CONTEXT(ospf, ospf);
88d6cf37 7790 struct listnode *ln;
7791 struct ospf_area *area;
7c8ff89e 7792
88d6cf37 7793 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7794
7795 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7796 {
7797 SET_FLAG (area->stub_router_state, OSPF_AREA_WAS_START_STUB_ROUTED);
7798 OSPF_TIMER_OFF (area->t_stub_router);
7799
7800 /* Don't trample on admin stub routed */
7801 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
7802 {
7803 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
c363d386 7804 ospf_router_lsa_update_area (area);
88d6cf37 7805 }
7806 }
7807 return CMD_SUCCESS;
7808}
7809
a1afa410 7810
88d6cf37 7811DEFUN (ospf_max_metric_router_lsa_shutdown,
7812 ospf_max_metric_router_lsa_shutdown_cmd,
6147e2c6 7813 "max-metric router-lsa on-shutdown (5-100)",
88d6cf37 7814 "OSPF maximum / infinite-distance metric\n"
7815 "Advertise own Router-LSA with infinite distance (stub router)\n"
7816 "Advertise stub-router prior to full shutdown of OSPF\n"
7817 "Time (seconds) to wait till full shutdown\n")
7818{
cdc2d765 7819 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7820 int idx_number = 3;
88d6cf37 7821 unsigned int seconds;
7c8ff89e 7822
88d6cf37 7823 if (argc != 1)
7824 {
7825 vty_out (vty, "%% Must supply stub-router shutdown period");
7826 return CMD_WARNING;
7827 }
7828
8d769265 7829 VTY_GET_INTEGER ("stub-router shutdown wait period", seconds, argv[idx_number]->arg);
88d6cf37 7830
7831 ospf->stub_router_shutdown_time = seconds;
7832
7833 return CMD_SUCCESS;
7834}
7835
7836DEFUN (no_ospf_max_metric_router_lsa_shutdown,
7837 no_ospf_max_metric_router_lsa_shutdown_cmd,
7a7be519 7838 "no max-metric router-lsa on-shutdown [(5-100)]",
88d6cf37 7839 NO_STR
7840 "OSPF maximum / infinite-distance metric\n"
7841 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
7842 "Advertise stub-router prior to full shutdown of OSPF\n"
7843 "Time (seconds) to wait till full shutdown\n")
88d6cf37 7844{
cdc2d765 7845 VTY_DECLVAR_CONTEXT(ospf, ospf);
7c8ff89e 7846
88d6cf37 7847 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7848
7849 return CMD_SUCCESS;
7850}
7851
a636c635
DW
7852static void
7853config_write_stub_router (struct vty *vty, struct ospf *ospf)
88d6cf37 7854{
7855 struct listnode *ln;
7856 struct ospf_area *area;
7857
7858 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7859 vty_out (vty, " max-metric router-lsa on-startup %u%s",
7860 ospf->stub_router_startup_time, VTY_NEWLINE);
7861 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7862 vty_out (vty, " max-metric router-lsa on-shutdown %u%s",
7863 ospf->stub_router_shutdown_time, VTY_NEWLINE);
7864 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7865 {
7866 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
7867 {
7868 vty_out (vty, " max-metric router-lsa administrative%s",
7869 VTY_NEWLINE);
7870 break;
7871 }
7872 }
7873 return;
7874}
6b0655a2 7875
4dadc291 7876static void
718e3744 7877show_ip_ospf_route_network (struct vty *vty, struct route_table *rt)
7878{
7879 struct route_node *rn;
7880 struct ospf_route *or;
1eb8ef25 7881 struct listnode *pnode, *pnnode;
718e3744 7882 struct ospf_path *path;
7883
7884 vty_out (vty, "============ OSPF network routing table ============%s",
7885 VTY_NEWLINE);
7886
7887 for (rn = route_top (rt); rn; rn = route_next (rn))
7888 if ((or = rn->info) != NULL)
7889 {
7890 char buf1[19];
7891 snprintf (buf1, 19, "%s/%d",
7892 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
7893
7894 switch (or->path_type)
7895 {
7896 case OSPF_PATH_INTER_AREA:
7897 if (or->type == OSPF_DESTINATION_NETWORK)
7898 vty_out (vty, "N IA %-18s [%d] area: %s%s", buf1, or->cost,
7899 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
7900 else if (or->type == OSPF_DESTINATION_DISCARD)
7901 vty_out (vty, "D IA %-18s Discard entry%s", buf1, VTY_NEWLINE);
7902 break;
7903 case OSPF_PATH_INTRA_AREA:
7904 vty_out (vty, "N %-18s [%d] area: %s%s", buf1, or->cost,
7905 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
7906 break;
7907 default:
7908 break;
7909 }
7910
7911 if (or->type == OSPF_DESTINATION_NETWORK)
1eb8ef25 7912 for (ALL_LIST_ELEMENTS (or->paths, pnode, pnnode, path))
96735eea 7913 {
7e2b7603 7914 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
96735eea 7915 {
7916 if (path->nexthop.s_addr == 0)
7917 vty_out (vty, "%24s directly attached to %s%s",
baaea325 7918 "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
96735eea 7919 else
7920 vty_out (vty, "%24s via %s, %s%s", "",
a8ba847f 7921 inet_ntoa (path->nexthop),
baaea325 7922 ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
96735eea 7923 }
7924 }
718e3744 7925 }
7926 vty_out (vty, "%s", VTY_NEWLINE);
7927}
7928
4dadc291 7929static void
718e3744 7930show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs)
7931{
7932 struct route_node *rn;
7933 struct ospf_route *or;
1eb8ef25 7934 struct listnode *pnode;
7935 struct listnode *node;
718e3744 7936 struct ospf_path *path;
7937
7938 vty_out (vty, "============ OSPF router routing table =============%s",
7939 VTY_NEWLINE);
7940 for (rn = route_top (rtrs); rn; rn = route_next (rn))
7941 if (rn->info)
7942 {
7943 int flag = 0;
7944
7945 vty_out (vty, "R %-15s ", inet_ntoa (rn->p.u.prefix4));
7946
1eb8ef25 7947 for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, or))
7948 {
7949 if (flag++)
7950 vty_out (vty, "%24s", "");
7951
7952 /* Show path. */
7953 vty_out (vty, "%s [%d] area: %s",
7954 (or->path_type == OSPF_PATH_INTER_AREA ? "IA" : " "),
7955 or->cost, inet_ntoa (or->u.std.area_id));
7956 /* Show flags. */
7957 vty_out (vty, "%s%s%s",
7958 (or->u.std.flags & ROUTER_LSA_BORDER ? ", ABR" : ""),
7959 (or->u.std.flags & ROUTER_LSA_EXTERNAL ? ", ASBR" : ""),
7960 VTY_NEWLINE);
7961
7962 for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path))
7963 {
7e2b7603 7964 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
54bedb55 7965 {
7966 if (path->nexthop.s_addr == 0)
7967 vty_out (vty, "%24s directly attached to %s%s",
baaea325 7968 "", ifindex2ifname (path->ifindex, VRF_DEFAULT),
a8ba847f 7969 VTY_NEWLINE);
54bedb55 7970 else
7971 vty_out (vty, "%24s via %s, %s%s", "",
7972 inet_ntoa (path->nexthop),
baaea325 7973 ifindex2ifname (path->ifindex, VRF_DEFAULT),
a8ba847f 7974 VTY_NEWLINE);
54bedb55 7975 }
1eb8ef25 7976 }
7977 }
718e3744 7978 }
7979 vty_out (vty, "%s", VTY_NEWLINE);
7980}
7981
4dadc291 7982static void
718e3744 7983show_ip_ospf_route_external (struct vty *vty, struct route_table *rt)
7984{
7985 struct route_node *rn;
7986 struct ospf_route *er;
1eb8ef25 7987 struct listnode *pnode, *pnnode;
718e3744 7988 struct ospf_path *path;
7989
7990 vty_out (vty, "============ OSPF external routing table ===========%s",
7991 VTY_NEWLINE);
7992 for (rn = route_top (rt); rn; rn = route_next (rn))
7993 if ((er = rn->info) != NULL)
7994 {
7995 char buf1[19];
7996 snprintf (buf1, 19, "%s/%d",
7997 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
7998
7999 switch (er->path_type)
8000 {
8001 case OSPF_PATH_TYPE1_EXTERNAL:
dc9ffce8 8002 vty_out (vty, "N E1 %-18s [%d] tag: %"ROUTE_TAG_PRI"%s", buf1,
718e3744 8003 er->cost, er->u.ext.tag, VTY_NEWLINE);
8004 break;
8005 case OSPF_PATH_TYPE2_EXTERNAL:
dc9ffce8 8006 vty_out (vty, "N E2 %-18s [%d/%d] tag: %"ROUTE_TAG_PRI"%s", buf1, er->cost,
718e3744 8007 er->u.ext.type2_cost, er->u.ext.tag, VTY_NEWLINE);
8008 break;
8009 }
8010
1eb8ef25 8011 for (ALL_LIST_ELEMENTS (er->paths, pnode, pnnode, path))
718e3744 8012 {
7e2b7603 8013 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
718e3744 8014 {
8015 if (path->nexthop.s_addr == 0)
96735eea 8016 vty_out (vty, "%24s directly attached to %s%s",
baaea325 8017 "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
96735eea 8018 else
8019 vty_out (vty, "%24s via %s, %s%s", "",
a8ba847f 8020 inet_ntoa (path->nexthop),
baaea325 8021 ifindex2ifname (path->ifindex, VRF_DEFAULT),
96735eea 8022 VTY_NEWLINE);
718e3744 8023 }
8024 }
8025 }
8026 vty_out (vty, "%s", VTY_NEWLINE);
8027}
8028
7c8ff89e
DS
8029static int
8030show_ip_ospf_border_routers_common (struct vty *vty, struct ospf *ospf)
718e3744 8031{
7c8ff89e
DS
8032 if (ospf->instance)
8033 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
8034 VTY_NEWLINE, VTY_NEWLINE);
718e3744 8035
68980084 8036 if (ospf->new_table == NULL)
718e3744 8037 {
8038 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
8039 return CMD_SUCCESS;
8040 }
8041
8042 /* Show Network routes.
020709f9 8043 show_ip_ospf_route_network (vty, ospf->new_table); */
718e3744 8044
8045 /* Show Router routes. */
68980084 8046 show_ip_ospf_route_router (vty, ospf->new_rtrs);
718e3744 8047
7c8ff89e
DS
8048 vty_out (vty, "%s", VTY_NEWLINE);
8049
718e3744 8050 return CMD_SUCCESS;
8051}
718e3744 8052
7c8ff89e
DS
8053DEFUN (show_ip_ospf_border_routers,
8054 show_ip_ospf_border_routers_cmd,
8055 "show ip ospf border-routers",
718e3744 8056 SHOW_STR
8057 IP_STR
8058 "OSPF information\n"
7c8ff89e 8059 "Show all the ABR's and ASBR's\n")
718e3744 8060{
020709f9 8061 struct ospf *ospf;
68980084 8062
0bad4851 8063 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
7c8ff89e
DS
8064 return CMD_SUCCESS;
8065
8066 return show_ip_ospf_border_routers_common(vty, ospf);
8067}
8068
8069DEFUN (show_ip_ospf_instance_border_routers,
8070 show_ip_ospf_instance_border_routers_cmd,
6147e2c6 8071 "show ip ospf (1-65535) border-routers",
7c8ff89e
DS
8072 SHOW_STR
8073 IP_STR
8074 "OSPF information\n"
8075 "Instance ID\n"
8076 "Show all the ABR's and ASBR's\n")
8077{
8d769265 8078 int idx_number = 3;
7c8ff89e
DS
8079 struct ospf *ospf;
8080 u_short instance = 0;
8081
8d769265 8082 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 8083 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
8084 return CMD_SUCCESS;
8085
8086 return show_ip_ospf_border_routers_common(vty, ospf);
8087}
8088
8089static int
8090show_ip_ospf_route_common (struct vty *vty, struct ospf *ospf)
8091{
8092 if (ospf->instance)
8093 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
8094 VTY_NEWLINE, VTY_NEWLINE);
718e3744 8095
68980084 8096 if (ospf->new_table == NULL)
718e3744 8097 {
8098 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
8099 return CMD_SUCCESS;
8100 }
8101
8102 /* Show Network routes. */
68980084 8103 show_ip_ospf_route_network (vty, ospf->new_table);
718e3744 8104
8105 /* Show Router routes. */
68980084 8106 show_ip_ospf_route_router (vty, ospf->new_rtrs);
718e3744 8107
8108 /* Show AS External routes. */
68980084 8109 show_ip_ospf_route_external (vty, ospf->old_external_route);
718e3744 8110
7c8ff89e
DS
8111 vty_out (vty, "%s", VTY_NEWLINE);
8112
718e3744 8113 return CMD_SUCCESS;
8114}
8115
7c8ff89e
DS
8116DEFUN (show_ip_ospf_route,
8117 show_ip_ospf_route_cmd,
8118 "show ip ospf route",
8119 SHOW_STR
8120 IP_STR
8121 "OSPF information\n"
8122 "OSPF routing table\n")
8123{
8124 struct ospf *ospf;
8125
0bad4851 8126 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
7c8ff89e
DS
8127 return CMD_SUCCESS;
8128
8129 return show_ip_ospf_route_common(vty, ospf);
8130}
8131
8132DEFUN (show_ip_ospf_instance_route,
8133 show_ip_ospf_instance_route_cmd,
6147e2c6 8134 "show ip ospf (1-65535) route",
7c8ff89e
DS
8135 SHOW_STR
8136 IP_STR
8137 "OSPF information\n"
8138 "Instance ID\n"
8139 "OSPF routing table\n")
8140{
8d769265 8141 int idx_number = 3;
7c8ff89e
DS
8142 struct ospf *ospf;
8143 u_short instance = 0;
8144
8d769265 8145 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 8146 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
8147 return CMD_SUCCESS;
8148
8149 return show_ip_ospf_route_common(vty, ospf);
8150}
6b0655a2 8151
eb1ce605 8152const char *ospf_abr_type_str[] =
718e3744 8153{
8154 "unknown",
8155 "standard",
8156 "ibm",
8157 "cisco",
8158 "shortcut"
8159};
8160
eb1ce605 8161const char *ospf_shortcut_mode_str[] =
718e3744 8162{
8163 "default",
8164 "enable",
8165 "disable"
8166};
8167
8168
4dadc291 8169static void
718e3744 8170area_id2str (char *buf, int length, struct ospf_area *area)
8171{
8172 memset (buf, 0, length);
8173
8174 if (area->format == OSPF_AREA_ID_FORMAT_ADDRESS)
8175 strncpy (buf, inet_ntoa (area->area_id), length);
8176 else
8177 sprintf (buf, "%lu", (unsigned long) ntohl (area->area_id.s_addr));
8178}
8179
6b0655a2 8180
eb1ce605 8181const char *ospf_int_type_str[] =
718e3744 8182{
8183 "unknown", /* should never be used. */
8184 "point-to-point",
8185 "broadcast",
8186 "non-broadcast",
8187 "point-to-multipoint",
8188 "virtual-link", /* should never be used. */
8189 "loopback"
8190};
8191
8192/* Configuration write function for ospfd. */
4dadc291 8193static int
718e3744 8194config_write_interface (struct vty *vty)
8195{
52dc7ee6 8196 struct listnode *n1, *n2;
718e3744 8197 struct interface *ifp;
8198 struct crypt_key *ck;
8199 int write = 0;
8200 struct route_node *rn = NULL;
8201 struct ospf_if_params *params;
7c8ff89e 8202 struct ospf *ospf = ospf_lookup();
718e3744 8203
b2d7c082 8204 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), n1, ifp))
718e3744 8205 {
718e3744 8206 if (memcmp (ifp->name, "VLINK", 5) == 0)
8207 continue;
8208
84361d61
DS
8209 if (ifp->ifindex == IFINDEX_DELETED)
8210 continue;
8211
718e3744 8212 vty_out (vty, "!%s", VTY_NEWLINE);
8213 vty_out (vty, "interface %s%s", ifp->name,
8214 VTY_NEWLINE);
8215 if (ifp->desc)
8216 vty_out (vty, " description %s%s", ifp->desc,
8217 VTY_NEWLINE);
8218
8219 write++;
8220
8221 params = IF_DEF_PARAMS (ifp);
8222
8223 do {
8224 /* Interface Network print. */
8225 if (OSPF_IF_PARAM_CONFIGURED (params, type) &&
718e3744 8226 params->type != OSPF_IFTYPE_LOOPBACK)
8227 {
bc18d616 8228 if (params->type != ospf_default_iftype(ifp))
7b90143f 8229 {
8230 vty_out (vty, " ip ospf network %s",
8231 ospf_int_type_str[params->type]);
8232 if (params != IF_DEF_PARAMS (ifp))
8233 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8234 vty_out (vty, "%s", VTY_NEWLINE);
8235 }
718e3744 8236 }
8237
8238 /* OSPF interface authentication print */
8239 if (OSPF_IF_PARAM_CONFIGURED (params, auth_type) &&
8240 params->auth_type != OSPF_AUTH_NOTSET)
8241 {
eb1ce605 8242 const char *auth_str;
718e3744 8243
8244 /* Translation tables are not that much help here due to syntax
8245 of the simple option */
8246 switch (params->auth_type)
8247 {
8248
8249 case OSPF_AUTH_NULL:
8250 auth_str = " null";
8251 break;
8252
8253 case OSPF_AUTH_SIMPLE:
8254 auth_str = "";
8255 break;
8256
8257 case OSPF_AUTH_CRYPTOGRAPHIC:
8258 auth_str = " message-digest";
8259 break;
8260
8261 default:
8262 auth_str = "";
8263 break;
8264 }
8265
8266 vty_out (vty, " ip ospf authentication%s", auth_str);
8267 if (params != IF_DEF_PARAMS (ifp))
8268 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8269 vty_out (vty, "%s", VTY_NEWLINE);
8270 }
8271
8272 /* Simple Authentication Password print. */
8273 if (OSPF_IF_PARAM_CONFIGURED (params, auth_simple) &&
8274 params->auth_simple[0] != '\0')
8275 {
8276 vty_out (vty, " ip ospf authentication-key %s",
8277 params->auth_simple);
8278 if (params != IF_DEF_PARAMS (ifp))
8279 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8280 vty_out (vty, "%s", VTY_NEWLINE);
8281 }
8282
8283 /* Cryptographic Authentication Key print. */
1eb8ef25 8284 for (ALL_LIST_ELEMENTS_RO (params->auth_crypt, n2, ck))
718e3744 8285 {
718e3744 8286 vty_out (vty, " ip ospf message-digest-key %d md5 %s",
7c8ff89e 8287 ck->key_id, ck->auth_key);
718e3744 8288 if (params != IF_DEF_PARAMS (ifp))
8289 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8290 vty_out (vty, "%s", VTY_NEWLINE);
8291 }
8292
8293 /* Interface Output Cost print. */
8294 if (OSPF_IF_PARAM_CONFIGURED (params, output_cost_cmd))
8295 {
8296 vty_out (vty, " ip ospf cost %u", params->output_cost_cmd);
8297 if (params != IF_DEF_PARAMS (ifp))
8298 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8299 vty_out (vty, "%s", VTY_NEWLINE);
8300 }
8301
8302 /* Hello Interval print. */
8303 if (OSPF_IF_PARAM_CONFIGURED (params, v_hello) &&
8304 params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT)
8305 {
8306 vty_out (vty, " ip ospf hello-interval %u", params->v_hello);
8307 if (params != IF_DEF_PARAMS (ifp))
8308 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8309 vty_out (vty, "%s", VTY_NEWLINE);
8310 }
8311
8312
8313 /* Router Dead Interval print. */
8314 if (OSPF_IF_PARAM_CONFIGURED (params, v_wait) &&
8315 params->v_wait != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT)
8316 {
f9ad937f 8317 vty_out (vty, " ip ospf dead-interval ");
8318
8319 /* fast hello ? */
8320 if (OSPF_IF_PARAM_CONFIGURED (params, fast_hello))
8321 vty_out (vty, "minimal hello-multiplier %d",
8322 params->fast_hello);
8323 else
8324 vty_out (vty, "%u", params->v_wait);
8325
718e3744 8326 if (params != IF_DEF_PARAMS (ifp))
8327 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8328 vty_out (vty, "%s", VTY_NEWLINE);
8329 }
8330
8331 /* Router Priority print. */
8332 if (OSPF_IF_PARAM_CONFIGURED (params, priority) &&
8333 params->priority != OSPF_ROUTER_PRIORITY_DEFAULT)
8334 {
8335 vty_out (vty, " ip ospf priority %u", params->priority);
8336 if (params != IF_DEF_PARAMS (ifp))
8337 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8338 vty_out (vty, "%s", VTY_NEWLINE);
8339 }
8340
8341 /* Retransmit Interval print. */
8342 if (OSPF_IF_PARAM_CONFIGURED (params, retransmit_interval) &&
8343 params->retransmit_interval != OSPF_RETRANSMIT_INTERVAL_DEFAULT)
8344 {
8345 vty_out (vty, " ip ospf retransmit-interval %u",
8346 params->retransmit_interval);
8347 if (params != IF_DEF_PARAMS (ifp))
8348 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8349 vty_out (vty, "%s", VTY_NEWLINE);
8350 }
8351
8352 /* Transmit Delay print. */
8353 if (OSPF_IF_PARAM_CONFIGURED (params, transmit_delay) &&
8354 params->transmit_delay != OSPF_TRANSMIT_DELAY_DEFAULT)
8355 {
8356 vty_out (vty, " ip ospf transmit-delay %u", params->transmit_delay);
8357 if (params != IF_DEF_PARAMS (ifp))
8358 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8359 vty_out (vty, "%s", VTY_NEWLINE);
8360 }
8361
953cde65
JT
8362 /* Area print. */
8363 if (OSPF_IF_PARAM_CONFIGURED (params, if_area))
8364 {
8365 if (ospf->instance)
8366 vty_out (vty, " ip ospf %d area %s%s", ospf->instance,
8367 inet_ntoa (params->if_area), VTY_NEWLINE);
8368 else
8369 vty_out (vty, " ip ospf area %s%s",
8370 inet_ntoa (params->if_area), VTY_NEWLINE);
8371
8372 }
8373
d5a5c8f0 8374 /* bfd print. */
7f342629 8375 ospf_bfd_write_config(vty, params);
d5a5c8f0 8376
ba682537 8377 /* MTU ignore print. */
8378 if (OSPF_IF_PARAM_CONFIGURED (params, mtu_ignore) &&
8379 params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8380 {
8381 if (params->mtu_ignore == 0)
8382 vty_out (vty, " no ip ospf mtu-ignore");
8383 else
8384 vty_out (vty, " ip ospf mtu-ignore");
8385 if (params != IF_DEF_PARAMS (ifp))
8386 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8387 vty_out (vty, "%s", VTY_NEWLINE);
8388 }
8389
8390
718e3744 8391 while (1)
8392 {
8393 if (rn == NULL)
8394 rn = route_top (IF_OIFS_PARAMS (ifp));
8395 else
8396 rn = route_next (rn);
8397
8398 if (rn == NULL)
8399 break;
8400 params = rn->info;
8401 if (params != NULL)
8402 break;
8403 }
8404 } while (rn);
8405
718e3744 8406 ospf_opaque_config_write_if (vty, ifp);
718e3744 8407 }
8408
8409 return write;
8410}
8411
4dadc291 8412static int
68980084 8413config_write_network_area (struct vty *vty, struct ospf *ospf)
718e3744 8414{
8415 struct route_node *rn;
8416 u_char buf[INET_ADDRSTRLEN];
8417
8418 /* `network area' print. */
68980084 8419 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
718e3744 8420 if (rn->info)
8421 {
8422 struct ospf_network *n = rn->info;
8423
8424 memset (buf, 0, INET_ADDRSTRLEN);
8425
8426 /* Create Area ID string by specified Area ID format. */
8427 if (n->format == OSPF_AREA_ID_FORMAT_ADDRESS)
c9e52be3 8428 strncpy ((char *) buf, inet_ntoa (n->area_id), INET_ADDRSTRLEN);
718e3744 8429 else
c9e52be3 8430 sprintf ((char *) buf, "%lu",
718e3744 8431 (unsigned long int) ntohl (n->area_id.s_addr));
8432
8433 /* Network print. */
8434 vty_out (vty, " network %s/%d area %s%s",
8435 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8436 buf, VTY_NEWLINE);
8437 }
8438
8439 return 0;
8440}
8441
4dadc291 8442static int
68980084 8443config_write_ospf_area (struct vty *vty, struct ospf *ospf)
718e3744 8444{
52dc7ee6 8445 struct listnode *node;
1eb8ef25 8446 struct ospf_area *area;
718e3744 8447 u_char buf[INET_ADDRSTRLEN];
8448
8449 /* Area configuration print. */
1eb8ef25 8450 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 8451 {
718e3744 8452 struct route_node *rn1;
8453
c9e52be3 8454 area_id2str ((char *) buf, INET_ADDRSTRLEN, area);
718e3744 8455
8456 if (area->auth_type != OSPF_AUTH_NULL)
8457 {
8458 if (area->auth_type == OSPF_AUTH_SIMPLE)
8459 vty_out (vty, " area %s authentication%s", buf, VTY_NEWLINE);
8460 else
8461 vty_out (vty, " area %s authentication message-digest%s",
8462 buf, VTY_NEWLINE);
8463 }
8464
8465 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
8466 vty_out (vty, " area %s shortcut %s%s", buf,
8467 ospf_shortcut_mode_str[area->shortcut_configured],
8468 VTY_NEWLINE);
8469
8470 if ((area->external_routing == OSPF_AREA_STUB)
718e3744 8471 || (area->external_routing == OSPF_AREA_NSSA)
718e3744 8472 )
8473 {
b0a053be 8474 if (area->external_routing == OSPF_AREA_STUB)
8475 vty_out (vty, " area %s stub", buf);
b0a053be 8476 else if (area->external_routing == OSPF_AREA_NSSA)
8477 {
8478 vty_out (vty, " area %s nssa", buf);
8479 switch (area->NSSATranslatorRole)
8480 {
8481 case OSPF_NSSA_ROLE_NEVER:
8482 vty_out (vty, " translate-never");
8483 break;
8484 case OSPF_NSSA_ROLE_ALWAYS:
8485 vty_out (vty, " translate-always");
8486 break;
8487 case OSPF_NSSA_ROLE_CANDIDATE:
8488 default:
8489 vty_out (vty, " translate-candidate");
8490 }
8491 }
718e3744 8492
8493 if (area->no_summary)
8494 vty_out (vty, " no-summary");
8495
8496 vty_out (vty, "%s", VTY_NEWLINE);
8497
8498 if (area->default_cost != 1)
8499 vty_out (vty, " area %s default-cost %d%s", buf,
8500 area->default_cost, VTY_NEWLINE);
8501 }
8502
8503 for (rn1 = route_top (area->ranges); rn1; rn1 = route_next (rn1))
8504 if (rn1->info)
8505 {
8506 struct ospf_area_range *range = rn1->info;
8507
8508 vty_out (vty, " area %s range %s/%d", buf,
8509 inet_ntoa (rn1->p.u.prefix4), rn1->p.prefixlen);
8510
6c835671 8511 if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
718e3744 8512 vty_out (vty, " cost %d", range->cost_config);
8513
8514 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
8515 vty_out (vty, " not-advertise");
8516
8517 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
8518 vty_out (vty, " substitute %s/%d",
8519 inet_ntoa (range->subst_addr), range->subst_masklen);
8520
8521 vty_out (vty, "%s", VTY_NEWLINE);
8522 }
8523
8524 if (EXPORT_NAME (area))
8525 vty_out (vty, " area %s export-list %s%s", buf,
8526 EXPORT_NAME (area), VTY_NEWLINE);
8527
8528 if (IMPORT_NAME (area))
8529 vty_out (vty, " area %s import-list %s%s", buf,
8530 IMPORT_NAME (area), VTY_NEWLINE);
8531
8532 if (PREFIX_NAME_IN (area))
8533 vty_out (vty, " area %s filter-list prefix %s in%s", buf,
8534 PREFIX_NAME_IN (area), VTY_NEWLINE);
8535
8536 if (PREFIX_NAME_OUT (area))
8537 vty_out (vty, " area %s filter-list prefix %s out%s", buf,
8538 PREFIX_NAME_OUT (area), VTY_NEWLINE);
8539 }
8540
8541 return 0;
8542}
8543
4dadc291 8544static int
68980084 8545config_write_ospf_nbr_nbma (struct vty *vty, struct ospf *ospf)
718e3744 8546{
8547 struct ospf_nbr_nbma *nbr_nbma;
8548 struct route_node *rn;
8549
8550 /* Static Neighbor configuration print. */
68980084 8551 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
718e3744 8552 if ((nbr_nbma = rn->info))
8553 {
8554 vty_out (vty, " neighbor %s", inet_ntoa (nbr_nbma->addr));
8555
8556 if (nbr_nbma->priority != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
8557 vty_out (vty, " priority %d", nbr_nbma->priority);
8558
8559 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
8560 vty_out (vty, " poll-interval %d", nbr_nbma->v_poll);
8561
8562 vty_out (vty, "%s", VTY_NEWLINE);
8563 }
8564
8565 return 0;
8566}
8567
4dadc291 8568static int
68980084 8569config_write_virtual_link (struct vty *vty, struct ospf *ospf)
718e3744 8570{
52dc7ee6 8571 struct listnode *node;
1eb8ef25 8572 struct ospf_vl_data *vl_data;
718e3744 8573 u_char buf[INET_ADDRSTRLEN];
8574
8575 /* Virtual-Link print */
1eb8ef25 8576 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
718e3744 8577 {
52dc7ee6 8578 struct listnode *n2;
718e3744 8579 struct crypt_key *ck;
718e3744 8580 struct ospf_interface *oi;
8581
8582 if (vl_data != NULL)
8583 {
8584 memset (buf, 0, INET_ADDRSTRLEN);
8585
8586 if (vl_data->format == OSPF_AREA_ID_FORMAT_ADDRESS)
c9e52be3 8587 strncpy ((char *) buf, inet_ntoa (vl_data->vl_area_id), INET_ADDRSTRLEN);
718e3744 8588 else
c9e52be3 8589 sprintf ((char *) buf, "%lu",
718e3744 8590 (unsigned long int) ntohl (vl_data->vl_area_id.s_addr));
8591 oi = vl_data->vl_oi;
8592
8593 /* timers */
8594 if (OSPF_IF_PARAM (oi, v_hello) != OSPF_HELLO_INTERVAL_DEFAULT ||
8595 OSPF_IF_PARAM (oi, v_wait) != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT ||
8596 OSPF_IF_PARAM (oi, retransmit_interval) != OSPF_RETRANSMIT_INTERVAL_DEFAULT ||
8597 OSPF_IF_PARAM (oi, transmit_delay) != OSPF_TRANSMIT_DELAY_DEFAULT)
8598 vty_out (vty, " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d%s",
8599 buf,
8600 inet_ntoa (vl_data->vl_peer),
8601 OSPF_IF_PARAM (oi, v_hello),
8602 OSPF_IF_PARAM (oi, retransmit_interval),
8603 OSPF_IF_PARAM (oi, transmit_delay),
8604 OSPF_IF_PARAM (oi, v_wait),
8605 VTY_NEWLINE);
8606 else
8607 vty_out (vty, " area %s virtual-link %s%s", buf,
8608 inet_ntoa (vl_data->vl_peer), VTY_NEWLINE);
8609 /* Auth key */
8610 if (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple[0] != '\0')
8611 vty_out (vty, " area %s virtual-link %s authentication-key %s%s",
8612 buf,
8613 inet_ntoa (vl_data->vl_peer),
8614 IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple,
8615 VTY_NEWLINE);
8616 /* md5 keys */
1eb8ef25 8617 for (ALL_LIST_ELEMENTS_RO (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_crypt,
8618 n2, ck))
8619 vty_out (vty, " area %s virtual-link %s"
8620 " message-digest-key %d md5 %s%s",
8621 buf,
8622 inet_ntoa (vl_data->vl_peer),
8623 ck->key_id, ck->auth_key, VTY_NEWLINE);
718e3744 8624
8625 }
8626 }
8627
8628 return 0;
8629}
8630
6b0655a2 8631
4dadc291 8632static int
68980084 8633config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
718e3744 8634{
8635 int type;
8636
8637 /* redistribute print. */
8638 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
7c8ff89e
DS
8639 {
8640 struct list *red_list;
8641 struct listnode *node;
8642 struct ospf_redist *red;
718e3744 8643
7c8ff89e
DS
8644 red_list = ospf->redist[type];
8645 if (!red_list)
8646 continue;
8647
8648 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
8649 {
8650 vty_out (vty, " redistribute %s", zebra_route_string(type));
8651 if (red->instance)
8652 vty_out (vty, " %d", red->instance);
8653
8654 if (red->dmetric.value >= 0)
8655 vty_out (vty, " metric %d", red->dmetric.value);
8656
8657 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8658 vty_out (vty, " metric-type 1");
8659
8660 if (ROUTEMAP_NAME (red))
8661 vty_out (vty, " route-map %s", ROUTEMAP_NAME (red));
8662
8663 vty_out (vty, "%s", VTY_NEWLINE);
8664 }
8665 }
718e3744 8666
8667 return 0;
8668}
8669
4dadc291 8670static int
68980084 8671config_write_ospf_default_metric (struct vty *vty, struct ospf *ospf)
718e3744 8672{
68980084 8673 if (ospf->default_metric != -1)
8674 vty_out (vty, " default-metric %d%s", ospf->default_metric,
718e3744 8675 VTY_NEWLINE);
8676 return 0;
8677}
8678
4dadc291 8679static int
68980084 8680config_write_ospf_distribute (struct vty *vty, struct ospf *ospf)
718e3744 8681{
8682 int type;
7c8ff89e 8683 struct ospf_redist *red;
718e3744 8684
68980084 8685 if (ospf)
718e3744 8686 {
8687 /* distribute-list print. */
8688 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
171c9a99 8689 if (DISTRIBUTE_NAME (ospf, type))
718e3744 8690 vty_out (vty, " distribute-list %s out %s%s",
171c9a99 8691 DISTRIBUTE_NAME (ospf, type),
f52d13cb 8692 zebra_route_string(type), VTY_NEWLINE);
718e3744 8693
8694 /* default-information print. */
68980084 8695 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE)
718e3744 8696 {
c42c177d 8697 vty_out (vty, " default-information originate");
8698 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
8699 vty_out (vty, " always");
718e3744 8700
7c8ff89e
DS
8701 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
8702 if (red)
8703 {
8704 if (red->dmetric.value >= 0)
8705 vty_out (vty, " metric %d",
8706 red->dmetric.value);
8707 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8708 vty_out (vty, " metric-type 1");
8709
8710 if (ROUTEMAP_NAME (red))
8711 vty_out (vty, " route-map %s",
8712 ROUTEMAP_NAME (red));
8713 }
718e3744 8714
8715 vty_out (vty, "%s", VTY_NEWLINE);
8716 }
8717
8718 }
8719
8720 return 0;
8721}
8722
4dadc291 8723static int
68980084 8724config_write_ospf_distance (struct vty *vty, struct ospf *ospf)
718e3744 8725{
8726 struct route_node *rn;
8727 struct ospf_distance *odistance;
8728
68980084 8729 if (ospf->distance_all)
8730 vty_out (vty, " distance %d%s", ospf->distance_all, VTY_NEWLINE);
718e3744 8731
68980084 8732 if (ospf->distance_intra
8733 || ospf->distance_inter
8734 || ospf->distance_external)
718e3744 8735 {
8736 vty_out (vty, " distance ospf");
8737
68980084 8738 if (ospf->distance_intra)
8739 vty_out (vty, " intra-area %d", ospf->distance_intra);
8740 if (ospf->distance_inter)
8741 vty_out (vty, " inter-area %d", ospf->distance_inter);
8742 if (ospf->distance_external)
8743 vty_out (vty, " external %d", ospf->distance_external);
718e3744 8744
8745 vty_out (vty, "%s", VTY_NEWLINE);
8746 }
8747
68980084 8748 for (rn = route_top (ospf->distance_table); rn; rn = route_next (rn))
718e3744 8749 if ((odistance = rn->info) != NULL)
8750 {
8751 vty_out (vty, " distance %d %s/%d %s%s", odistance->distance,
8752 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8753 odistance->access_list ? odistance->access_list : "",
8754 VTY_NEWLINE);
8755 }
8756 return 0;
8757}
8758
8759/* OSPF configuration write function. */
4dadc291 8760static int
718e3744 8761ospf_config_write (struct vty *vty)
8762{
020709f9 8763 struct ospf *ospf;
1eb8ef25 8764 struct interface *ifp;
8765 struct ospf_interface *oi;
52dc7ee6 8766 struct listnode *node;
718e3744 8767 int write = 0;
8768
020709f9 8769 ospf = ospf_lookup ();
0bad4851 8770 if (ospf != NULL && ospf->oi_running)
718e3744 8771 {
8772 /* `router ospf' print. */
7c8ff89e
DS
8773 if (ospf->instance)
8774 vty_out (vty, "router ospf %d%s", ospf->instance, VTY_NEWLINE);
8775 else
8776 vty_out (vty, "router ospf%s", VTY_NEWLINE);
718e3744 8777
8778 write++;
8779
68980084 8780 if (!ospf->networks)
718e3744 8781 return write;
8782
8783 /* Router ID print. */
68980084 8784 if (ospf->router_id_static.s_addr != 0)
718e3744 8785 vty_out (vty, " ospf router-id %s%s",
68980084 8786 inet_ntoa (ospf->router_id_static), VTY_NEWLINE);
718e3744 8787
8788 /* ABR type print. */
d57834f6 8789 if (ospf->abr_type != OSPF_ABR_DEFAULT)
718e3744 8790 vty_out (vty, " ospf abr-type %s%s",
68980084 8791 ospf_abr_type_str[ospf->abr_type], VTY_NEWLINE);
718e3744 8792
d7e60dd7
AS
8793 /* log-adjacency-changes flag print. */
8794 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES))
8795 {
d7e60dd7 8796 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
692c7954 8797 vty_out(vty, " log-adjacency-changes detail%s", VTY_NEWLINE);
8efe88ea
DL
8798 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES)
8799 vty_out(vty, " log-adjacency-changes%s", VTY_NEWLINE);
d7e60dd7 8800 }
8efe88ea 8801 else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
692c7954
DW
8802 {
8803 vty_out(vty, " no log-adjacency-changes%s", VTY_NEWLINE);
8804 }
d7e60dd7 8805
718e3744 8806 /* RFC1583 compatibility flag print -- Compatible with CISCO 12.1. */
68980084 8807 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
718e3744 8808 vty_out (vty, " compatible rfc1583%s", VTY_NEWLINE);
8809
8810 /* auto-cost reference-bandwidth configuration. */
68980084 8811 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH)
f9ad937f 8812 {
8813 vty_out (vty, "! Important: ensure reference bandwidth "
8814 "is consistent across all routers%s", VTY_NEWLINE);
8815 vty_out (vty, " auto-cost reference-bandwidth %d%s",
70bd3c43 8816 ospf->ref_bandwidth, VTY_NEWLINE);
f9ad937f 8817 }
718e3744 8818
8819 /* SPF timers print. */
68980084 8820 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT ||
ea4ffc90 8821 ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT ||
8822 ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
8823 vty_out (vty, " timers throttle spf %d %d %d%s",
88d6cf37 8824 ospf->spf_delay, ospf->spf_holdtime,
ea4ffc90 8825 ospf->spf_max_holdtime, VTY_NEWLINE);
b6927875
DS
8826
8827 /* LSA timers print. */
ac7424f9
MR
8828 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
8829 vty_out (vty, " timers throttle lsa all %d%s",
8830 ospf->min_ls_interval, VTY_NEWLINE);
8831 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
b6927875 8832 vty_out (vty, " timers lsa min-arrival %d%s",
ac7424f9 8833 ospf->min_ls_arrival, VTY_NEWLINE);
b6927875 8834
2f8f370e 8835 /* Write multiplier print. */
e8f45e82 8836 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
2f8f370e 8837 vty_out (vty, " ospf write-multiplier %d%s",
e8f45e82 8838 ospf->write_oi_count, VTY_NEWLINE);
2f8f370e 8839
88d6cf37 8840 /* Max-metric router-lsa print */
8841 config_write_stub_router (vty, ospf);
8842
718e3744 8843 /* SPF refresh parameters print. */
68980084 8844 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
718e3744 8845 vty_out (vty, " refresh timer %d%s",
68980084 8846 ospf->lsa_refresh_interval, VTY_NEWLINE);
718e3744 8847
8848 /* Redistribute information print. */
68980084 8849 config_write_ospf_redistribute (vty, ospf);
718e3744 8850
8851 /* passive-interface print. */
7ffa8fa2
PJ
8852 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
8853 vty_out (vty, " passive-interface default%s", VTY_NEWLINE);
8854
1eb8ef25 8855 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
7ffa8fa2
PJ
8856 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), passive_interface)
8857 && IF_DEF_PARAMS (ifp)->passive_interface !=
8858 ospf->passive_interface_default)
8859 {
8860 vty_out (vty, " %spassive-interface %s%s",
8861 IF_DEF_PARAMS (ifp)->passive_interface ? "" : "no ",
8862 ifp->name, VTY_NEWLINE);
8863 }
1eb8ef25 8864 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
7ffa8fa2
PJ
8865 {
8866 if (!OSPF_IF_PARAM_CONFIGURED (oi->params, passive_interface))
8867 continue;
8868 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp),
8869 passive_interface))
8870 {
8871 if (oi->params->passive_interface == IF_DEF_PARAMS (oi->ifp)->passive_interface)
8872 continue;
8873 }
8874 else if (oi->params->passive_interface == ospf->passive_interface_default)
8875 continue;
8876
8877 vty_out (vty, " %spassive-interface %s %s%s",
8878 oi->params->passive_interface ? "" : "no ",
1eb8ef25 8879 oi->ifp->name,
8880 inet_ntoa (oi->address->u.prefix4), VTY_NEWLINE);
7ffa8fa2 8881 }
718e3744 8882
8883 /* Network area print. */
68980084 8884 config_write_network_area (vty, ospf);
718e3744 8885
8886 /* Area config print. */
68980084 8887 config_write_ospf_area (vty, ospf);
718e3744 8888
8889 /* static neighbor print. */
68980084 8890 config_write_ospf_nbr_nbma (vty, ospf);
718e3744 8891
8892 /* Virtual-Link print. */
68980084 8893 config_write_virtual_link (vty, ospf);
718e3744 8894
8895 /* Default metric configuration. */
68980084 8896 config_write_ospf_default_metric (vty, ospf);
718e3744 8897
8898 /* Distribute-list and default-information print. */
68980084 8899 config_write_ospf_distribute (vty, ospf);
718e3744 8900
8901 /* Distance configuration. */
68980084 8902 config_write_ospf_distance (vty, ospf);
718e3744 8903
68980084 8904 ospf_opaque_config_write_router (vty, ospf);
718e3744 8905 }
8906
8907 return write;
8908}
8909
8910void
4dadc291 8911ospf_vty_show_init (void)
718e3744 8912{
8913 /* "show ip ospf" commands. */
8914 install_element (VIEW_NODE, &show_ip_ospf_cmd);
718e3744 8915
7c8ff89e 8916 install_element (VIEW_NODE, &show_ip_ospf_instance_cmd);
7c8ff89e 8917
718e3744 8918 /* "show ip ospf database" commands. */
718e3744 8919 install_element (VIEW_NODE, &show_ip_ospf_database_type_adv_router_cmd);
7a7be519 8920 install_element (VIEW_NODE, &show_ip_ospf_database_max_cmd);
718e3744 8921
7c8ff89e 8922 install_element (VIEW_NODE, &show_ip_ospf_instance_database_type_adv_router_cmd);
7c8ff89e 8923 install_element (VIEW_NODE, &show_ip_ospf_instance_database_cmd);
7a7be519 8924 install_element (VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
7c8ff89e 8925
718e3744 8926 /* "show ip ospf interface" commands. */
8927 install_element (VIEW_NODE, &show_ip_ospf_interface_cmd);
718e3744 8928
7c8ff89e 8929 install_element (VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
7c8ff89e 8930
718e3744 8931 /* "show ip ospf neighbor" commands. */
8932 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
8933 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
8934 install_element (VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
8935 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
8936 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
8937 install_element (VIEW_NODE, &show_ip_ospf_neighbor_cmd);
8938 install_element (VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
718e3744 8939
7c8ff89e
DS
8940 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_detail_cmd);
8941 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
8942 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
8943 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_all_cmd);
8944 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
8945 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
8946 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
7c8ff89e 8947
718e3744 8948 /* "show ip ospf route" commands. */
8949 install_element (VIEW_NODE, &show_ip_ospf_route_cmd);
718e3744 8950 install_element (VIEW_NODE, &show_ip_ospf_border_routers_cmd);
7c8ff89e
DS
8951
8952 install_element (VIEW_NODE, &show_ip_ospf_instance_route_cmd);
7c8ff89e 8953 install_element (VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
718e3744 8954}
8955
6b0655a2 8956
718e3744 8957/* ospfd's interface node. */
7fc626de 8958static struct cmd_node interface_node =
718e3744 8959{
8960 INTERFACE_NODE,
8961 "%s(config-if)# ",
8962 1
8963};
8964
8965/* Initialization of OSPF interface. */
4dadc291 8966static void
8967ospf_vty_if_init (void)
718e3744 8968{
8969 /* Install interface node. */
8970 install_node (&interface_node, config_write_interface);
0b84f294 8971 if_cmd_init ();
718e3744 8972
8973 /* "ip ospf authentication" commands. */
8974 install_element (INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
718e3744 8975 install_element (INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
b4a039bf 8976 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_args_addr_cmd);
718e3744 8977 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
718e3744 8978 install_element (INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
813d4307 8979 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_key_authkey_addr_cmd);
7a7be519 8980 install_element (INTERFACE_NODE, &no_ospf_authentication_key_authkey_addr_cmd);
718e3744 8981
8982 /* "ip ospf message-digest-key" commands. */
537eae3f
QY
8983 install_element (INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
8984 install_element (INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
718e3744 8985
8986 /* "ip ospf cost" commands. */
5c2fc921
QY
8987 install_element (INTERFACE_NODE, &ip_ospf_cost_cmd);
8988 install_element (INTERFACE_NODE, &no_ip_ospf_cost_cmd);
718e3744 8989
ba682537 8990 /* "ip ospf mtu-ignore" commands. */
8991 install_element (INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
ba682537 8992 install_element (INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
ba682537 8993
718e3744 8994 /* "ip ospf dead-interval" commands. */
0d829fa7 8995 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
f9ad937f 8996 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_minimal_addr_cmd);
0d829fa7 8997 install_element (INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
f9ad937f 8998
718e3744 8999 /* "ip ospf hello-interval" commands. */
0d829fa7
QY
9000 install_element (INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
9001 install_element (INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
718e3744 9002
9003 /* "ip ospf network" commands. */
9004 install_element (INTERFACE_NODE, &ip_ospf_network_cmd);
9005 install_element (INTERFACE_NODE, &no_ip_ospf_network_cmd);
9006
9007 /* "ip ospf priority" commands. */
537eae3f
QY
9008 install_element (INTERFACE_NODE, &ip_ospf_priority_cmd);
9009 install_element (INTERFACE_NODE, &no_ip_ospf_priority_cmd);
718e3744 9010
9011 /* "ip ospf retransmit-interval" commands. */
9012 install_element (INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
718e3744 9013 install_element (INTERFACE_NODE, &no_ip_ospf_retransmit_interval_addr_cmd);
718e3744 9014
9015 /* "ip ospf transmit-delay" commands. */
9016 install_element (INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
718e3744 9017 install_element (INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
718e3744 9018
953cde65
JT
9019 /* "ip ospf area" commands. */
9020 install_element (INTERFACE_NODE, &ip_ospf_area_cmd);
9021 install_element (INTERFACE_NODE, &no_ip_ospf_area_cmd);
953cde65 9022
718e3744 9023 /* These commands are compatibitliy for previous version. */
9024 install_element (INTERFACE_NODE, &ospf_authentication_key_cmd);
718e3744 9025 install_element (INTERFACE_NODE, &ospf_message_digest_key_cmd);
537eae3f 9026 install_element (INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
718e3744 9027 install_element (INTERFACE_NODE, &ospf_dead_interval_cmd);
537eae3f 9028 install_element (INTERFACE_NODE, &no_ospf_dead_interval_cmd);
718e3744 9029 install_element (INTERFACE_NODE, &ospf_hello_interval_cmd);
537eae3f
QY
9030 install_element (INTERFACE_NODE, &no_ospf_hello_interval_cmd);
9031 install_element (INTERFACE_NODE, &ospf_cost_cmd);
9032 install_element (INTERFACE_NODE, &no_ospf_cost_cmd);
718e3744 9033 install_element (INTERFACE_NODE, &ospf_network_cmd);
537eae3f 9034 install_element (INTERFACE_NODE, &no_ospf_network_cmd);
718e3744 9035 install_element (INTERFACE_NODE, &ospf_priority_cmd);
537eae3f 9036 install_element (INTERFACE_NODE, &no_ospf_priority_cmd);
718e3744 9037 install_element (INTERFACE_NODE, &ospf_retransmit_interval_cmd);
537eae3f 9038 install_element (INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
718e3744 9039 install_element (INTERFACE_NODE, &ospf_transmit_delay_cmd);
537eae3f 9040 install_element (INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
718e3744 9041}
9042
4dadc291 9043static void
9044ospf_vty_zebra_init (void)
718e3744 9045{
718e3744 9046 install_element (OSPF_NODE, &ospf_redistribute_source_cmd);
718e3744 9047 install_element (OSPF_NODE, &no_ospf_redistribute_source_cmd);
7c8ff89e
DS
9048 install_element (OSPF_NODE, &ospf_redistribute_instance_source_cmd);
9049 install_element (OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
718e3744 9050
9051 install_element (OSPF_NODE, &ospf_distribute_list_out_cmd);
9052 install_element (OSPF_NODE, &no_ospf_distribute_list_out_cmd);
9053
718e3744 9054 install_element (OSPF_NODE, &ospf_default_information_originate_cmd);
718e3744 9055 install_element (OSPF_NODE, &no_ospf_default_information_originate_cmd);
9056
9057 install_element (OSPF_NODE, &ospf_default_metric_cmd);
9058 install_element (OSPF_NODE, &no_ospf_default_metric_cmd);
718e3744 9059
9060 install_element (OSPF_NODE, &ospf_distance_cmd);
9061 install_element (OSPF_NODE, &no_ospf_distance_cmd);
9062 install_element (OSPF_NODE, &no_ospf_distance_ospf_cmd);
6f2a6703 9063 install_element (OSPF_NODE, &ospf_distance_ospf_cmd);
718e3744 9064#if 0
9065 install_element (OSPF_NODE, &ospf_distance_source_cmd);
9066 install_element (OSPF_NODE, &no_ospf_distance_source_cmd);
9067 install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd);
9068 install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd);
9069#endif /* 0 */
9070}
9071
7fc626de 9072static struct cmd_node ospf_node =
718e3744 9073{
9074 OSPF_NODE,
9075 "%s(config-router)# ",
9076 1
9077};
9078
09f35f8c
DS
9079static void
9080ospf_interface_clear (struct interface *ifp)
9081{
9082 if (!if_is_operative (ifp)) return;
9083
9084 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
4525281a 9085 zlog_debug("ISM[%s]: clear by reset", ifp->name);
09f35f8c
DS
9086
9087 ospf_if_reset(ifp);
9088}
9089
9090DEFUN (clear_ip_ospf_interface,
9091 clear_ip_ospf_interface_cmd,
9092 "clear ip ospf interface [IFNAME]",
9093 CLEAR_STR
9094 IP_STR
9095 "OSPF information\n"
9096 "Interface information\n"
9097 "Interface name\n")
9098{
8d769265 9099 int idx_ifname = 4;
09f35f8c
DS
9100 struct interface *ifp;
9101 struct listnode *node;
9102
7a7be519 9103 if (argc == 4) /* Clear all the ospfv2 interfaces. */
09f35f8c 9104 {
b2d7c082 9105 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
09f35f8c
DS
9106 ospf_interface_clear(ifp);
9107 }
9108 else /* Interface name is specified. */
9109 {
1306c09a 9110 if ((ifp = if_lookup_by_name (argv[idx_ifname]->text, VRF_DEFAULT)) == NULL)
09f35f8c
DS
9111 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
9112 else
9113 ospf_interface_clear(ifp);
9114 }
9115
9116 return CMD_SUCCESS;
9117}
9118
9119void
9120ospf_vty_clear_init (void)
9121{
9122 install_element (ENABLE_NODE, &clear_ip_ospf_interface_cmd);
9123}
9124
6b0655a2 9125
718e3744 9126/* Install OSPF related vty commands. */
9127void
4dadc291 9128ospf_vty_init (void)
718e3744 9129{
9130 /* Install ospf top node. */
9131 install_node (&ospf_node, ospf_config_write);
9132
9133 /* "router ospf" commands. */
9134 install_element (CONFIG_NODE, &router_ospf_cmd);
9135 install_element (CONFIG_NODE, &no_router_ospf_cmd);
9136
7c8ff89e 9137
718e3744 9138 install_default (OSPF_NODE);
9139
9140 /* "ospf router-id" commands. */
9141 install_element (OSPF_NODE, &ospf_router_id_cmd);
747e489c 9142 install_element (OSPF_NODE, &ospf_router_id_old_cmd);
718e3744 9143 install_element (OSPF_NODE, &no_ospf_router_id_cmd);
718e3744 9144
9145 /* "passive-interface" commands. */
a2c62831 9146 install_element (OSPF_NODE, &ospf_passive_interface_addr_cmd);
a2c62831 9147 install_element (OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
718e3744 9148
9149 /* "ospf abr-type" commands. */
9150 install_element (OSPF_NODE, &ospf_abr_type_cmd);
9151 install_element (OSPF_NODE, &no_ospf_abr_type_cmd);
9152
d7e60dd7
AS
9153 /* "ospf log-adjacency-changes" commands. */
9154 install_element (OSPF_NODE, &ospf_log_adjacency_changes_cmd);
9155 install_element (OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
9156 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
9157 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
9158
718e3744 9159 /* "ospf rfc1583-compatible" commands. */
718e3744 9160 install_element (OSPF_NODE, &ospf_compatible_rfc1583_cmd);
9161 install_element (OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
7a7be519 9162 install_element (OSPF_NODE, &ospf_rfc1583_flag_cmd);
9163 install_element (OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
718e3744 9164
9165 /* "network area" commands. */
a2c62831 9166 install_element (OSPF_NODE, &ospf_network_area_cmd);
9167 install_element (OSPF_NODE, &no_ospf_network_area_cmd);
718e3744 9168
9169 /* "area authentication" commands. */
a2c62831 9170 install_element (OSPF_NODE, &ospf_area_authentication_message_digest_cmd);
9171 install_element (OSPF_NODE, &ospf_area_authentication_cmd);
9172 install_element (OSPF_NODE, &no_ospf_area_authentication_cmd);
718e3744 9173
9174 /* "area range" commands. */
a2c62831 9175 install_element (OSPF_NODE, &ospf_area_range_cmd);
7a7be519 9176 install_element (OSPF_NODE, &ospf_area_range_cost_cmd);
a2c62831 9177 install_element (OSPF_NODE, &ospf_area_range_not_advertise_cmd);
9178 install_element (OSPF_NODE, &no_ospf_area_range_cmd);
a2c62831 9179 install_element (OSPF_NODE, &ospf_area_range_substitute_cmd);
9180 install_element (OSPF_NODE, &no_ospf_area_range_substitute_cmd);
718e3744 9181
9182 /* "area virtual-link" commands. */
a2c62831 9183 install_element (OSPF_NODE, &ospf_area_vlink_cmd);
7a7be519 9184 install_element (OSPF_NODE, &ospf_area_vlink_intervals_cmd);
a2c62831 9185 install_element (OSPF_NODE, &no_ospf_area_vlink_cmd);
7a7be519 9186 install_element (OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
718e3744 9187
718e3744 9188
718e3744 9189
718e3744 9190
718e3744 9191
718e3744 9192
718e3744 9193
718e3744 9194
718e3744 9195
718e3744 9196
9197 /* "area stub" commands. */
a2c62831 9198 install_element (OSPF_NODE, &ospf_area_stub_no_summary_cmd);
9199 install_element (OSPF_NODE, &ospf_area_stub_cmd);
9200 install_element (OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
9201 install_element (OSPF_NODE, &no_ospf_area_stub_cmd);
718e3744 9202
718e3744 9203 /* "area nssa" commands. */
a2c62831 9204 install_element (OSPF_NODE, &ospf_area_nssa_cmd);
9205 install_element (OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd);
9206 install_element (OSPF_NODE, &ospf_area_nssa_translate_cmd);
9207 install_element (OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
9208 install_element (OSPF_NODE, &no_ospf_area_nssa_cmd);
718e3744 9209
a2c62831 9210 install_element (OSPF_NODE, &ospf_area_default_cost_cmd);
9211 install_element (OSPF_NODE, &no_ospf_area_default_cost_cmd);
718e3744 9212
a2c62831 9213 install_element (OSPF_NODE, &ospf_area_shortcut_cmd);
9214 install_element (OSPF_NODE, &no_ospf_area_shortcut_cmd);
718e3744 9215
a2c62831 9216 install_element (OSPF_NODE, &ospf_area_export_list_cmd);
9217 install_element (OSPF_NODE, &no_ospf_area_export_list_cmd);
718e3744 9218
a2c62831 9219 install_element (OSPF_NODE, &ospf_area_filter_list_cmd);
9220 install_element (OSPF_NODE, &no_ospf_area_filter_list_cmd);
718e3744 9221
a2c62831 9222 install_element (OSPF_NODE, &ospf_area_import_list_cmd);
9223 install_element (OSPF_NODE, &no_ospf_area_import_list_cmd);
88d6cf37 9224
9225 /* SPF timer commands */
d24f6e2a 9226 install_element (OSPF_NODE, &ospf_timers_throttle_spf_cmd);
9227 install_element (OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
9228
b6927875 9229 /* LSA timers commands */
ac7424f9
MR
9230 install_element (OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
9231 install_element (OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
9232 install_element (OSPF_NODE, &ospf_timers_min_ls_arrival_cmd);
9233 install_element (OSPF_NODE, &no_ospf_timers_min_ls_arrival_cmd);
b6927875
DS
9234 install_element (OSPF_NODE, &ospf_timers_lsa_cmd);
9235 install_element (OSPF_NODE, &no_ospf_timers_lsa_cmd);
b6927875 9236
88d6cf37 9237 /* refresh timer commands */
a2c62831 9238 install_element (OSPF_NODE, &ospf_refresh_timer_cmd);
9239 install_element (OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
718e3744 9240
88d6cf37 9241 /* max-metric commands */
9242 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
9243 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
9244 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
9245 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
9246 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
9247 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
9248
9249 /* reference bandwidth commands */
a2c62831 9250 install_element (OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
9251 install_element (OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
718e3744 9252
9253 /* "neighbor" commands. */
a2c62831 9254 install_element (OSPF_NODE, &ospf_neighbor_cmd);
a2c62831 9255 install_element (OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
a2c62831 9256 install_element (OSPF_NODE, &no_ospf_neighbor_cmd);
7a7be519 9257 install_element (OSPF_NODE, &no_ospf_neighbor_poll_cmd);
718e3744 9258
2f8f370e
DS
9259 /* write multiplier commands */
9260 install_element (OSPF_NODE, &ospf_write_multiplier_cmd);
7a7be519 9261 install_element (OSPF_NODE, &write_multiplier_cmd);
2f8f370e 9262 install_element (OSPF_NODE, &no_ospf_write_multiplier_cmd);
7a7be519 9263 install_element (OSPF_NODE, &no_write_multiplier_cmd);
2f8f370e 9264
718e3744 9265 /* Init interface related vty commands. */
9266 ospf_vty_if_init ();
9267
9268 /* Init zebra related vty commands. */
9269 ospf_vty_zebra_init ();
9270}