]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_vty.c
ospfd, ospf6d: fix distance commands
[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 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#include <zebra.h>
7ec4159b 24#include <string.h>
718e3744 25
cbf3e3eb 26#include "monotime.h"
718e3744 27#include "memory.h"
28#include "thread.h"
29#include "prefix.h"
30#include "table.h"
31#include "vty.h"
32#include "command.h"
33#include "plist.h"
34#include "log.h"
35#include "zclient.h"
bf2bfafd 36#include <lib/json.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
1541 if (argc > 1)
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 2139
692c7954 2140 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
d7e60dd7
AS
2141 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2142 return CMD_SUCCESS;
2143}
2144
718e3744 2145DEFUN (ospf_compatible_rfc1583,
2146 ospf_compatible_rfc1583_cmd,
2147 "compatible rfc1583",
2148 "OSPF compatibility list\n"
2149 "compatible with RFC 1583\n")
2150{
cdc2d765 2151 VTY_DECLVAR_CONTEXT(ospf, ospf);
718e3744 2152
2153 if (!CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
2154 {
2155 SET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
d3a9c768 2156 ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
718e3744 2157 }
2158 return CMD_SUCCESS;
2159}
2160
2161DEFUN (no_ospf_compatible_rfc1583,
2162 no_ospf_compatible_rfc1583_cmd,
2163 "no compatible rfc1583",
2164 NO_STR
2165 "OSPF compatibility list\n"
2166 "compatible with RFC 1583\n")
2167{
cdc2d765 2168 VTY_DECLVAR_CONTEXT(ospf, ospf);
718e3744 2169
2170 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
2171 {
2172 UNSET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
d3a9c768 2173 ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
718e3744 2174 }
2175 return CMD_SUCCESS;
2176}
2177
7a7be519 2178ALIAS (ospf_compatible_rfc1583,
2179 ospf_rfc1583_flag_cmd,
2180 "ospf rfc1583compatibility",
2181 "OSPF specific commands\n"
2182 "Enable the RFC1583Compatibility flag\n")
718e3744 2183
7a7be519 2184ALIAS (no_ospf_compatible_rfc1583,
2185 no_ospf_rfc1583_flag_cmd,
2186 "no ospf rfc1583compatibility",
2187 NO_STR
2188 "OSPF specific commands\n"
2189 "Disable the RFC1583Compatibility flag\n")
6b0655a2 2190
d24f6e2a 2191static int
2192ospf_timers_spf_set (struct vty *vty, unsigned int delay,
2193 unsigned int hold,
2194 unsigned int max)
2195{
cdc2d765 2196 VTY_DECLVAR_CONTEXT(ospf, ospf);
7c8ff89e 2197
d24f6e2a 2198 ospf->spf_delay = delay;
2199 ospf->spf_holdtime = hold;
2200 ospf->spf_max_holdtime = max;
2201
2202 return CMD_SUCCESS;
2203}
718e3744 2204
ac7424f9
MR
2205DEFUN (ospf_timers_min_ls_interval,
2206 ospf_timers_min_ls_interval_cmd,
6147e2c6 2207 "timers throttle lsa all (0-5000)",
ac7424f9
MR
2208 "Adjust routing timers\n"
2209 "Throttling adaptive timer\n"
2210 "LSA delay between transmissions\n"
813d4307 2211 "All LSA types\n"
ac7424f9
MR
2212 "Delay (msec) between sending LSAs\n")
2213{
cdc2d765 2214 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2215 int idx_number = 4;
ac7424f9
MR
2216 unsigned int interval;
2217
2218 if (argc != 1)
2219 {
2220 vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE);
2221 return CMD_WARNING;
2222 }
2223
8d769265 2224 VTY_GET_INTEGER ("LSA interval", interval, argv[idx_number]->arg);
ac7424f9
MR
2225
2226 ospf->min_ls_interval = interval;
2227
2228 return CMD_SUCCESS;
2229}
2230
2231DEFUN (no_ospf_timers_min_ls_interval,
2232 no_ospf_timers_min_ls_interval_cmd,
7a7be519 2233 "no timers throttle lsa all [(0-5000)]",
ac7424f9
MR
2234 NO_STR
2235 "Adjust routing timers\n"
2236 "Throttling adaptive timer\n"
813d4307 2237 "LSA delay between transmissions\n"
7a7be519 2238 "All LSA types\n"
2239 "Delay (msec) between sending LSAs\n")
ac7424f9 2240{
cdc2d765 2241 VTY_DECLVAR_CONTEXT(ospf, ospf);
ac7424f9
MR
2242 ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL;
2243
2244 return CMD_SUCCESS;
2245}
2246
813d4307 2247
ac7424f9
MR
2248DEFUN (ospf_timers_min_ls_arrival,
2249 ospf_timers_min_ls_arrival_cmd,
6147e2c6 2250 "timers lsa arrival (0-1000)",
ac7424f9
MR
2251 "Adjust routing timers\n"
2252 "Throttling link state advertisement delays\n"
2253 "OSPF minimum arrival interval delay\n"
2254 "Delay (msec) between accepted LSAs\n")
2255{
cdc2d765 2256 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2257 int idx_number = 3;
ac7424f9
MR
2258 unsigned int arrival;
2259
2260 if (argc != 1)
2261 {
2262 vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE);
2263 return CMD_WARNING;
2264 }
2265
8d769265 2266 VTY_GET_INTEGER_RANGE ("minimum LSA inter-arrival time", arrival, argv[idx_number]->arg, 0, 1000);
ac7424f9
MR
2267
2268 ospf->min_ls_arrival = arrival;
2269
2270 return CMD_SUCCESS;
2271}
2272
2273DEFUN (no_ospf_timers_min_ls_arrival,
2274 no_ospf_timers_min_ls_arrival_cmd,
7a7be519 2275 "no timers lsa arrival [(0-1000)]",
ac7424f9
MR
2276 NO_STR
2277 "Adjust routing timers\n"
2278 "Throttling link state advertisement delays\n"
7a7be519 2279 "OSPF minimum arrival interval delay\n"
2280 "Delay (msec) between accepted LSAs\n")
ac7424f9 2281{
cdc2d765 2282 VTY_DECLVAR_CONTEXT(ospf, ospf);
d8f70b86 2283
ac7424f9
MR
2284 ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
2285
2286 return CMD_SUCCESS;
2287}
2288
813d4307 2289
d24f6e2a 2290DEFUN (ospf_timers_throttle_spf,
2291 ospf_timers_throttle_spf_cmd,
6147e2c6 2292 "timers throttle spf (0-600000) (0-600000) (0-600000)",
d24f6e2a 2293 "Adjust routing timers\n"
2294 "Throttling adaptive timer\n"
2295 "OSPF SPF timers\n"
2296 "Delay (msec) from first change received till SPF calculation\n"
2297 "Initial hold time (msec) between consecutive SPF calculations\n"
2298 "Maximum hold time (msec)\n")
2299{
8d769265
DW
2300 int idx_number = 3;
2301 int idx_number_2 = 4;
2302 int idx_number_3 = 5;
d24f6e2a 2303 unsigned int delay, hold, max;
2304
2305 if (argc != 3)
2306 {
2307 vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE);
2308 return CMD_WARNING;
2309 }
2310
8d769265
DW
2311 VTY_GET_INTEGER_RANGE ("SPF delay timer", delay, argv[idx_number]->arg, 0, 600000);
2312 VTY_GET_INTEGER_RANGE ("SPF hold timer", hold, argv[idx_number_2]->arg, 0, 600000);
2313 VTY_GET_INTEGER_RANGE ("SPF max-hold timer", max, argv[idx_number_3]->arg, 0, 600000);
d24f6e2a 2314
2315 return ospf_timers_spf_set (vty, delay, hold, max);
2316}
2317
d24f6e2a 2318DEFUN (no_ospf_timers_throttle_spf,
2319 no_ospf_timers_throttle_spf_cmd,
7a7be519 2320 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
718e3744 2321 NO_STR
2322 "Adjust routing timers\n"
d24f6e2a 2323 "Throttling adaptive timer\n"
7a7be519 2324 "OSPF SPF timers\n"
2325 "Delay (msec) from first change received till SPF calculation\n"
2326 "Initial hold time (msec) between consecutive SPF calculations\n"
2327 "Maximum hold time (msec)\n")
22b27e95 2328{
d24f6e2a 2329 return ospf_timers_spf_set (vty,
2330 OSPF_SPF_DELAY_DEFAULT,
2331 OSPF_SPF_HOLDTIME_DEFAULT,
2332 OSPF_SPF_MAX_HOLDTIME_DEFAULT);
718e3744 2333}
2334
b4a039bf 2335
b6927875
DS
2336DEFUN (ospf_timers_lsa,
2337 ospf_timers_lsa_cmd,
6147e2c6 2338 "timers lsa min-arrival (0-600000)",
b6927875
DS
2339 "Adjust routing timers\n"
2340 "OSPF LSA timers\n"
2341 "Minimum delay in receiving new version of a LSA\n"
2342 "Delay in milliseconds\n")
2343{
cdc2d765 2344 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2345 int idx_number = 3;
b6927875 2346 unsigned int minarrival;
b6927875 2347
b6927875
DS
2348 if (argc != 1)
2349 {
2350 vty_out (vty, "Insufficient number of arguments%s", VTY_NEWLINE);
2351 return CMD_WARNING;
2352 }
2353
8d769265 2354 VTY_GET_INTEGER ("LSA min-arrival", minarrival, argv[idx_number]->arg);
b6927875 2355
ac7424f9 2356 ospf->min_ls_arrival = minarrival;
b6927875
DS
2357
2358 return CMD_SUCCESS;
2359}
2360
2361DEFUN (no_ospf_timers_lsa,
2362 no_ospf_timers_lsa_cmd,
7a7be519 2363 "no timers lsa min-arrival [(0-600000)]",
b6927875
DS
2364 NO_STR
2365 "Adjust routing timers\n"
2366 "OSPF LSA timers\n"
7a7be519 2367 "Minimum delay in receiving new version of a LSA\n"
2368 "Delay in milliseconds\n")
b6927875 2369{
cdc2d765 2370 VTY_DECLVAR_CONTEXT(ospf, ospf);
b6927875 2371 unsigned int minarrival;
b6927875 2372
7a7be519 2373 if (argc > 4)
b6927875 2374 {
7a7be519 2375 VTY_GET_INTEGER ("LSA min-arrival", minarrival, argv[4]->arg);
b6927875 2376
ac7424f9 2377 if (ospf->min_ls_arrival != minarrival ||
b6927875
DS
2378 minarrival == OSPF_MIN_LS_ARRIVAL)
2379 return CMD_SUCCESS;
2380 }
2381
ac7424f9 2382 ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
b6927875
DS
2383
2384 return CMD_SUCCESS;
2385}
2386
a2c62831 2387DEFUN (ospf_neighbor,
2388 ospf_neighbor_cmd,
7a7be519 2389 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
718e3744 2390 NEIGHBOR_STR
7a7be519 2391 "Neighbor IP address\n"
2392 "Neighbor Priority\n"
2393 "Priority\n"
2394 "Dead Neighbor Polling interval\n"
2395 "Seconds\n")
718e3744 2396{
cdc2d765 2397 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2398 int idx_ipv4 = 1;
7a7be519 2399 int idx_pri = 3;
2400 int idx_poll = 5;
718e3744 2401 struct in_addr nbr_addr;
eb1ce605 2402 unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2403 unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
718e3744 2404
8d769265 2405 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2406
718e3744 2407 if (argc > 2)
7a7be519 2408 VTY_GET_INTEGER_RANGE ("neighbor priority", priority, argv[idx_pri]->arg, 0, 255);
2409
2410 if (argc > 4)
2411 VTY_GET_INTEGER_RANGE ("poll interval", interval, argv[idx_poll]->arg, 1, 65535);
718e3744 2412
2413 ospf_nbr_nbma_set (ospf, nbr_addr);
7a7be519 2414
718e3744 2415 if (argc > 2)
7a7be519 2416 ospf_nbr_nbma_priority_set (ospf, nbr_addr, priority);
2417
2418 if (argc > 4)
1a61ad10 2419 ospf_nbr_nbma_poll_interval_set (ospf, nbr_addr, interval);
718e3744 2420
2421 return CMD_SUCCESS;
2422}
2423
a2c62831 2424DEFUN (ospf_neighbor_poll_interval,
2425 ospf_neighbor_poll_interval_cmd,
7a7be519 2426 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
718e3744 2427 NEIGHBOR_STR
2428 "Neighbor IP address\n"
2429 "Dead Neighbor Polling interval\n"
7a7be519 2430 "Seconds\n"
2431 "OSPF priority of non-broadcast neighbor\n"
2432 "Priority\n")
22b27e95 2433{
cdc2d765 2434 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2435 int idx_ipv4 = 1;
7a7be519 2436 int idx_poll = 3;
2437 int idx_pri = 5;
718e3744 2438 struct in_addr nbr_addr;
eb1ce605 2439 unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2440 unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
718e3744 2441
8d769265 2442 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2443
7a7be519 2444 VTY_GET_INTEGER_RANGE ("poll interval", interval, argv[idx_poll]->arg, 1, 65535);
718e3744 2445
7a7be519 2446 if (argc > 4)
2447 VTY_GET_INTEGER_RANGE ("neighbor priority", priority, argv[idx_pri]->arg, 0, 255);
718e3744 2448
2449 ospf_nbr_nbma_set (ospf, nbr_addr);
7a7be519 2450 ospf_nbr_nbma_poll_interval_set (ospf, nbr_addr, interval);
2451
2452 if (argc > 4)
718e3744 2453 ospf_nbr_nbma_priority_set (ospf, nbr_addr, priority);
2454
2455 return CMD_SUCCESS;
2456}
2457
a2c62831 2458DEFUN (no_ospf_neighbor,
2459 no_ospf_neighbor_cmd,
7a7be519 2460 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
718e3744 2461 NO_STR
2462 NEIGHBOR_STR
7a7be519 2463 "Neighbor IP address\n"
2464 "Neighbor Priority\n"
2465 "Priority\n"
2466 "Dead Neighbor Polling interval\n"
2467 "Seconds\n")
718e3744 2468{
cdc2d765 2469 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2470 int idx_ipv4 = 2;
718e3744 2471 struct in_addr nbr_addr;
718e3744 2472
8d769265 2473 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2474
0798cee3 2475 (void)ospf_nbr_nbma_unset (ospf, nbr_addr);
718e3744 2476
2477 return CMD_SUCCESS;
2478}
2479
7a7be519 2480DEFUN (no_ospf_neighbor_poll,
2481 no_ospf_neighbor_poll_cmd,
2482 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2483 NO_STR
2484 NEIGHBOR_STR
2485 "Neighbor IP address\n"
2486 "Dead Neighbor Polling interval\n"
2487 "Seconds\n"
2488 "Neighbor Priority\n"
2489 "Priority\n")
2490{
cdc2d765 2491 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 2492 int idx_ipv4 = 2;
7a7be519 2493 struct in_addr nbr_addr;
2494
7a7be519 2495 VTY_GET_IPV4_ADDRESS ("neighbor address", nbr_addr, argv[idx_ipv4]->arg);
718e3744 2496
7a7be519 2497 (void)ospf_nbr_nbma_unset (ospf, nbr_addr);
813d4307 2498
7a7be519 2499 return CMD_SUCCESS;
2500}
718e3744 2501
bf2bfafd
DW
2502DEFUN (ospf_refresh_timer,
2503 ospf_refresh_timer_cmd,
6147e2c6 2504 "refresh timer (10-1800)",
718e3744 2505 "Adjust refresh parameters\n"
2506 "Set refresh timer\n"
2507 "Timer value in seconds\n")
2508{
cdc2d765 2509 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2510 int idx_number = 2;
eb1ce605 2511 unsigned int interval;
7c8ff89e 2512
8d769265 2513 VTY_GET_INTEGER_RANGE ("refresh timer", interval, argv[idx_number]->arg, 10, 1800);
535c84b1 2514 interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) * OSPF_LSA_REFRESHER_GRANULARITY;
718e3744 2515
2516 ospf_timers_refresh_set (ospf, interval);
2517
2518 return CMD_SUCCESS;
2519}
2520
bf2bfafd
DW
2521DEFUN (no_ospf_refresh_timer,
2522 no_ospf_refresh_timer_val_cmd,
7a7be519 2523 "no refresh timer [(10-1800)]",
3a2d747c 2524 NO_STR
718e3744 2525 "Adjust refresh parameters\n"
2526 "Unset refresh timer\n"
2527 "Timer value in seconds\n")
2528{
cdc2d765 2529 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2530 int idx_number = 3;
eb1ce605 2531 unsigned int interval;
718e3744 2532
2533 if (argc == 1)
2534 {
8d769265 2535 VTY_GET_INTEGER_RANGE ("refresh timer", interval, argv[idx_number]->arg, 10, 1800);
718e3744 2536
2537 if (ospf->lsa_refresh_interval != interval ||
2538 interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
2539 return CMD_SUCCESS;
2540 }
2541
2542 ospf_timers_refresh_unset (ospf);
2543
2544 return CMD_SUCCESS;
2545}
2546
718e3744 2547
a2c62831 2548DEFUN (ospf_auto_cost_reference_bandwidth,
2549 ospf_auto_cost_reference_bandwidth_cmd,
6147e2c6 2550 "auto-cost reference-bandwidth (1-4294967)",
718e3744 2551 "Calculate OSPF interface cost according to bandwidth\n"
2552 "Use reference bandwidth method to assign OSPF cost\n"
2553 "The reference bandwidth in terms of Mbits per second\n")
2554{
cdc2d765 2555 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 2556 int idx_number = 2;
718e3744 2557 u_int32_t refbw;
52dc7ee6 2558 struct listnode *node;
1eb8ef25 2559 struct interface *ifp;
718e3744 2560
8d769265 2561 refbw = strtol (argv[idx_number]->arg, NULL, 10);
718e3744 2562 if (refbw < 1 || refbw > 4294967)
2563 {
2564 vty_out (vty, "reference-bandwidth value is invalid%s", VTY_NEWLINE);
2565 return CMD_WARNING;
2566 }
2567
2568 /* If reference bandwidth is changed. */
70bd3c43 2569 if ((refbw) == ospf->ref_bandwidth)
718e3744 2570 return CMD_SUCCESS;
2571
70bd3c43 2572 ospf->ref_bandwidth = refbw;
1eb8ef25 2573 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
2574 ospf_if_recalculate_output_cost (ifp);
718e3744 2575
2576 return CMD_SUCCESS;
2577}
2578
a2c62831 2579DEFUN (no_ospf_auto_cost_reference_bandwidth,
2580 no_ospf_auto_cost_reference_bandwidth_cmd,
7a7be519 2581 "no auto-cost reference-bandwidth [(1-4294967)]",
718e3744 2582 NO_STR
2583 "Calculate OSPF interface cost according to bandwidth\n"
7a7be519 2584 "Use reference bandwidth method to assign OSPF cost\n"
2585 "The reference bandwidth in terms of Mbits per second\n")
718e3744 2586{
cdc2d765 2587 VTY_DECLVAR_CONTEXT(ospf, ospf);
1eb8ef25 2588 struct listnode *node, *nnode;
2589 struct interface *ifp;
718e3744 2590
68980084 2591 if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH)
718e3744 2592 return CMD_SUCCESS;
2593
68980084 2594 ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
718e3744 2595 vty_out (vty, "%% OSPF: Reference bandwidth is changed.%s", VTY_NEWLINE);
2596 vty_out (vty, " Please ensure reference bandwidth is consistent across all routers%s", VTY_NEWLINE);
2597
1eb8ef25 2598 for (ALL_LIST_ELEMENTS (om->iflist, node, nnode, ifp))
2599 ospf_if_recalculate_output_cost (ifp);
718e3744 2600
2601 return CMD_SUCCESS;
2602}
2603
2f8f370e
DS
2604DEFUN (ospf_write_multiplier,
2605 ospf_write_multiplier_cmd,
6147e2c6 2606 "ospf write-multiplier (1-100)",
e8f45e82
DS
2607 "OSPF specific commands\n"
2608 "Write multiplier\n"
2609 "Maximum number of interface serviced per write\n")
2f8f370e 2610{
cdc2d765 2611 VTY_DECLVAR_CONTEXT(ospf, ospf);
7a7be519 2612 int idx_number;
e8f45e82 2613 u_int32_t write_oi_count;
2f8f370e 2614
7a7be519 2615 if (argc == 3)
2616 idx_number = 2;
2617 else
2618 idx_number = 1;
2619
8d769265 2620 write_oi_count = strtol (argv[idx_number]->arg, NULL, 10);
e8f45e82 2621 if (write_oi_count < 1 || write_oi_count > 100)
2f8f370e
DS
2622 {
2623 vty_out (vty, "write-multiplier value is invalid%s", VTY_NEWLINE);
2624 return CMD_WARNING;
2625 }
2626
e8f45e82 2627 ospf->write_oi_count = write_oi_count;
2f8f370e
DS
2628 return CMD_SUCCESS;
2629}
2630
7a7be519 2631ALIAS (ospf_write_multiplier,
2632 write_multiplier_cmd,
2633 "write-multiplier (1-100)",
2634 "Write multiplier\n"
2635 "Maximum number of interface serviced per write\n")
e8f45e82 2636
2f8f370e
DS
2637DEFUN (no_ospf_write_multiplier,
2638 no_ospf_write_multiplier_cmd,
6147e2c6 2639 "no ospf write-multiplier (1-100)",
2f8f370e 2640 NO_STR
e8f45e82 2641 "OSPF specific commands\n"
813d4307
DW
2642 "Write multiplier\n"
2643 "Maximum number of interface serviced per write\n")
2f8f370e 2644{
cdc2d765 2645 VTY_DECLVAR_CONTEXT(ospf, ospf);
2f8f370e 2646
e8f45e82 2647 ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
2f8f370e
DS
2648 return CMD_SUCCESS;
2649}
2650
7a7be519 2651ALIAS (no_ospf_write_multiplier,
2652 no_write_multiplier_cmd,
2653 "no write-multiplier (1-100)",
2654 NO_STR
2655 "Write multiplier\n"
2656 "Maximum number of interface serviced per write\n")
813d4307 2657
eb1ce605 2658const char *ospf_abr_type_descr_str[] =
718e3744 2659{
2660 "Unknown",
2661 "Standard (RFC2328)",
2662 "Alternative IBM",
2663 "Alternative Cisco",
2664 "Alternative Shortcut"
2665};
2666
eb1ce605 2667const char *ospf_shortcut_mode_descr_str[] =
718e3744 2668{
2669 "Default",
2670 "Enabled",
2671 "Disabled"
2672};
2673
4dadc291 2674static void
ca08c43d 2675show_ip_ospf_area (struct vty *vty, struct ospf_area *area, json_object *json_areas, u_char use_json)
718e3744 2676{
ca08c43d
DS
2677 json_object *json_area = NULL;
2678
2679 if (use_json)
2680 json_area = json_object_new_object();
2681
718e3744 2682 /* Show Area ID. */
ca08c43d
DS
2683 if (!use_json)
2684 vty_out (vty, " Area ID: %s", inet_ntoa (area->area_id));
718e3744 2685
2686 /* Show Area type/mode. */
2687 if (OSPF_IS_AREA_BACKBONE (area))
ca08c43d
DS
2688 {
2689 if (use_json)
2690 json_object_boolean_true_add(json_area, "backbone");
2691 else
2692 vty_out (vty, " (Backbone)%s", VTY_NEWLINE);
2693 }
718e3744 2694 else
2695 {
ca08c43d
DS
2696 if (use_json)
2697 {
2698 if (area->external_routing == OSPF_AREA_STUB)
2699 {
2700 if (area->no_summary)
2701 json_object_boolean_true_add(json_area, "stubNoSummary");
2702 if (area->shortcut_configured)
2703 json_object_boolean_true_add(json_area, "stubShortcut");
2704 }
2705 else if (area->external_routing == OSPF_AREA_NSSA)
2706 {
2707 if (area->no_summary)
2708 json_object_boolean_true_add(json_area, "nssaNoSummary");
2709 if (area->shortcut_configured)
2710 json_object_boolean_true_add(json_area, "nssaShortcut");
2711 }
2712
2713 json_object_string_add(json_area,"shortcuttingMode",
2714 ospf_shortcut_mode_descr_str[area->shortcut_configured]);
2715 if (area->shortcut_capability)
2716 json_object_boolean_true_add(json_area,"sBitConcensus");
2717 }
2718 else
2719 {
2720 if (area->external_routing == OSPF_AREA_STUB)
2721 vty_out (vty, " (Stub%s%s)",
2722 area->no_summary ? ", no summary" : "",
2723 area->shortcut_configured ? "; " : "");
2724 else if (area->external_routing == OSPF_AREA_NSSA)
2725 vty_out (vty, " (NSSA%s%s)",
2726 area->no_summary ? ", no summary" : "",
2727 area->shortcut_configured ? "; " : "");
2728
2729 vty_out (vty, "%s", VTY_NEWLINE);
2730 vty_out (vty, " Shortcutting mode: %s",
2731 ospf_shortcut_mode_descr_str[area->shortcut_configured]);
2732 vty_out (vty, ", S-bit consensus: %s%s",
2733 area->shortcut_capability ? "ok" : "no", VTY_NEWLINE);
2734 }
2735 }
2736
2737 /* Show number of interfaces */
2738 if (use_json)
2739 {
3ac237f8
MS
2740 json_object_int_add(json_area, "areaIfTotalCounter", listcount (area->oiflist));
2741 json_object_int_add(json_area, "areaIfActiveCounter", area->act_ints);
718e3744 2742 }
ca08c43d
DS
2743 else
2744 vty_out (vty, " Number of interfaces in this area: Total: %d, "
2745 "Active: %d%s", listcount (area->oiflist),
2746 area->act_ints, VTY_NEWLINE);
718e3744 2747
718e3744 2748 if (area->external_routing == OSPF_AREA_NSSA)
2749 {
ca08c43d
DS
2750 if (use_json)
2751 {
2752 json_object_boolean_true_add(json_area, "nssa");
2753 if (! IS_OSPF_ABR (area->ospf))
2754 json_object_boolean_false_add(json_area, "abr");
2755 else if (area->NSSATranslatorState)
2756 {
2757 json_object_boolean_true_add(json_area, "abr");
2758 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2759 json_object_boolean_true_add(json_area, "nssaTranslatorElected");
2760 else if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_ALWAYS)
2761 json_object_boolean_true_add(json_area, "nssaTranslatorAlways");
2762 }
2763 else
2764 {
2765 json_object_boolean_true_add(json_area, "abr");
2766 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2767 json_object_boolean_false_add(json_area, "nssaTranslatorElected");
2768 else
2769 json_object_boolean_true_add(json_area, "nssaTranslatorNever");
2770 }
2771 }
718e3744 2772 else
ca08c43d
DS
2773 {
2774 vty_out (vty, " It is an NSSA configuration. %s Elected NSSA/ABR performs type-7/type-5 LSA translation. %s", VTY_NEWLINE, VTY_NEWLINE);
2775 if (! IS_OSPF_ABR (area->ospf))
2776 vty_out (vty, " It is not ABR, therefore not Translator. %s",
2777 VTY_NEWLINE);
2778 else if (area->NSSATranslatorState)
2779 {
2780 vty_out (vty, " We are an ABR and ");
2781 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2782 vty_out (vty, "the NSSA Elected Translator. %s",
2783 VTY_NEWLINE);
2784 else if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_ALWAYS)
2785 vty_out (vty, "always an NSSA Translator. %s",
2786 VTY_NEWLINE);
2787 }
2788 else
2789 {
2790 vty_out (vty, " We are an ABR, but ");
2791 if (area->NSSATranslatorRole == OSPF_NSSA_ROLE_CANDIDATE)
2792 vty_out (vty, "not the NSSA Elected Translator. %s",
2793 VTY_NEWLINE);
2794 else
2795 vty_out (vty, "never an NSSA Translator. %s",
2796 VTY_NEWLINE);
2797 }
2798 }
718e3744 2799 }
ca08c43d 2800
88d6cf37 2801 /* Stub-router state for this area */
2802 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
2803 {
649654ab 2804 char timebuf[OSPF_TIME_DUMP_SIZE];
ca08c43d
DS
2805
2806 if (use_json)
2807 {
2808 json_object_boolean_true_add(json_area, "originStubMaxDistRouterLsa");
2809 if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
2810 json_object_boolean_true_add(json_area, "indefiniteActiveAdmin");
2811 if (area->t_stub_router)
2812 {
cbf3e3eb
DL
2813 long time_store;
2814 time_store = monotime_until(&area->t_stub_router->u.sands, NULL) / 1000LL;
ca08c43d
DS
2815 json_object_int_add(json_area, "activeStartupRemainderMsecs", time_store);
2816 }
2817 }
2818 else
2819 {
2820 vty_out (vty, " Originating stub / maximum-distance Router-LSA%s",
2821 VTY_NEWLINE);
2822 if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
2823 vty_out (vty, " Administratively activated (indefinitely)%s",
2824 VTY_NEWLINE);
2825 if (area->t_stub_router)
2826 vty_out (vty, " Active from startup, %s remaining%s",
2827 ospf_timer_dump (area->t_stub_router, timebuf,
2828 sizeof(timebuf)), VTY_NEWLINE);
2829 }
2830 }
2831
2832 if (use_json)
2833 {
2834 /* Show number of fully adjacent neighbors. */
3ac237f8 2835 json_object_int_add(json_area, "nbrFullAdjacentCounter", area->full_nbrs);
ca08c43d
DS
2836
2837 /* Show authentication type. */
2838 if (area->auth_type == OSPF_AUTH_NULL)
2839 json_object_string_add(json_area, "authentication", "authenticationNone");
2840 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2841 json_object_string_add(json_area, "authentication", "authenticationSimplePassword");
2842 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2843 json_object_string_add(json_area, "authentication", "authenticationMessageDigest");
2844
2845 if (!OSPF_IS_AREA_BACKBONE (area))
3ac237f8 2846 json_object_int_add(json_area, "virtualAdjacenciesPassingCounter", area->full_vls);
ca08c43d
DS
2847
2848 /* Show SPF calculation times. */
3ac237f8 2849 json_object_int_add(json_area, "spfExecutedCounter", area->spf_calculation);
ca08c43d
DS
2850 json_object_int_add(json_area, "lsaNumber", area->lsdb->total);
2851 json_object_int_add(json_area, "lsaRouterNumber", ospf_lsdb_count (area->lsdb, OSPF_ROUTER_LSA));
2852 json_object_int_add(json_area, "lsaRouterChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_ROUTER_LSA));
2853 json_object_int_add(json_area, "lsaNetworkNumber", ospf_lsdb_count (area->lsdb, OSPF_NETWORK_LSA));
2854 json_object_int_add(json_area, "lsaNetworkChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_NETWORK_LSA));
2855 json_object_int_add(json_area, "lsaSummaryNumber", ospf_lsdb_count (area->lsdb, OSPF_SUMMARY_LSA));
2856 json_object_int_add(json_area, "lsaSummaryChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_SUMMARY_LSA));
2857 json_object_int_add(json_area, "lsaAsbrNumber", ospf_lsdb_count (area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2858 json_object_int_add(json_area, "lsaAsbrChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2859 json_object_int_add(json_area, "lsaNssaNumber", ospf_lsdb_count (area->lsdb, OSPF_AS_NSSA_LSA));
2860 json_object_int_add(json_area, "lsaNssaChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_AS_NSSA_LSA));
88d6cf37 2861 }
ca08c43d
DS
2862 else
2863 {
2864 /* Show number of fully adjacent neighbors. */
2865 vty_out (vty, " Number of fully adjacent neighbors in this area:"
2866 " %d%s", area->full_nbrs, VTY_NEWLINE);
2867
2868 /* Show authentication type. */
2869 vty_out (vty, " Area has ");
2870 if (area->auth_type == OSPF_AUTH_NULL)
2871 vty_out (vty, "no authentication%s", VTY_NEWLINE);
2872 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2873 vty_out (vty, "simple password authentication%s", VTY_NEWLINE);
2874 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2875 vty_out (vty, "message digest authentication%s", VTY_NEWLINE);
2876
2877 if (!OSPF_IS_AREA_BACKBONE (area))
2878 vty_out (vty, " Number of full virtual adjacencies going through"
2879 " this area: %d%s", area->full_vls, VTY_NEWLINE);
2880
2881 /* Show SPF calculation times. */
2882 vty_out (vty, " SPF algorithm executed %d times%s",
2883 area->spf_calculation, VTY_NEWLINE);
2884
2885 /* Show number of LSA. */
2886 vty_out (vty, " Number of LSA %ld%s", area->lsdb->total, VTY_NEWLINE);
2887 vty_out (vty, " Number of router LSA %ld. Checksum Sum 0x%08x%s",
2888 ospf_lsdb_count (area->lsdb, OSPF_ROUTER_LSA),
2889 ospf_lsdb_checksum (area->lsdb, OSPF_ROUTER_LSA), VTY_NEWLINE);
2890 vty_out (vty, " Number of network LSA %ld. Checksum Sum 0x%08x%s",
2891 ospf_lsdb_count (area->lsdb, OSPF_NETWORK_LSA),
2892 ospf_lsdb_checksum (area->lsdb, OSPF_NETWORK_LSA), VTY_NEWLINE);
2893 vty_out (vty, " Number of summary LSA %ld. Checksum Sum 0x%08x%s",
2894 ospf_lsdb_count (area->lsdb, OSPF_SUMMARY_LSA),
2895 ospf_lsdb_checksum (area->lsdb, OSPF_SUMMARY_LSA), VTY_NEWLINE);
2896 vty_out (vty, " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x%s",
2897 ospf_lsdb_count (area->lsdb, OSPF_ASBR_SUMMARY_LSA),
2898 ospf_lsdb_checksum (area->lsdb, OSPF_ASBR_SUMMARY_LSA), VTY_NEWLINE);
2899 vty_out (vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x%s",
2900 ospf_lsdb_count (area->lsdb, OSPF_AS_NSSA_LSA),
2901 ospf_lsdb_checksum (area->lsdb, OSPF_AS_NSSA_LSA), VTY_NEWLINE);
2902 }
2903
ca08c43d
DS
2904 if (use_json)
2905 {
2906 json_object_int_add(json_area, "lsaOpaqueLinkNumber", ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_LINK_LSA));
2907 json_object_int_add(json_area, "lsaOpaqueLinkChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_LINK_LSA));
2908 json_object_int_add(json_area, "lsaOpaqueAreaNumber", ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_AREA_LSA));
2909 json_object_int_add(json_area, "lsaOpaqueAreaChecksum", ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_AREA_LSA));
2910 }
2911 else
2912 {
2913 vty_out (vty, " Number of opaque link LSA %ld. Checksum Sum 0x%08x%s",
2914 ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_LINK_LSA),
2915 ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_LINK_LSA), VTY_NEWLINE);
2916 vty_out (vty, " Number of opaque area LSA %ld. Checksum Sum 0x%08x%s",
2917 ospf_lsdb_count (area->lsdb, OSPF_OPAQUE_AREA_LSA),
2918 ospf_lsdb_checksum (area->lsdb, OSPF_OPAQUE_AREA_LSA), VTY_NEWLINE);
2919 }
ca08c43d
DS
2920
2921 if (use_json)
2922 json_object_object_add(json_areas, inet_ntoa (area->area_id), json_area);
2923 else
2924 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 2925}
2926
7c8ff89e 2927static int
ca08c43d 2928show_ip_ospf_common (struct vty *vty, struct ospf *ospf, u_char use_json)
718e3744 2929{
1eb8ef25 2930 struct listnode *node, *nnode;
718e3744 2931 struct ospf_area * area;
d24f6e2a 2932 struct timeval result;
649654ab 2933 char timebuf[OSPF_TIME_DUMP_SIZE];
ca08c43d
DS
2934 json_object *json = NULL;
2935 json_object *json_areas = NULL;
2936
2937 if (use_json)
0cad6e26
DS
2938 {
2939 json = json_object_new_object();
2940 json_areas = json_object_new_object();
2941 }
718e3744 2942
7c8ff89e 2943 if (ospf->instance)
ca08c43d
DS
2944 {
2945 if (use_json)
2946 {
2947 json_object_int_add(json, "ospfInstance", ospf->instance);
2948 }
2949 else
2950 {
2951 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
2952 VTY_NEWLINE, VTY_NEWLINE);
2953 }
2954 }
718e3744 2955
2956 /* Show Router ID. */
ca08c43d
DS
2957 if (use_json)
2958 {
2959 json_object_string_add(json, "routerId", inet_ntoa (ospf->router_id));
2960 }
2961 else
2962 {
2963 vty_out (vty, " OSPF Routing Process, Router ID: %s%s",
2964 inet_ntoa (ospf->router_id),
2965 VTY_NEWLINE);
2966 }
7c8ff89e 2967
88d6cf37 2968 /* Graceful shutdown */
c9c93d50 2969 if (ospf->t_deferred_shutdown)
ca08c43d
DS
2970 {
2971 if (use_json)
2972 {
cbf3e3eb
DL
2973 long time_store;
2974 time_store = monotime_until(&ospf->t_deferred_shutdown->u.sands, NULL) / 1000LL;
ca08c43d
DS
2975 json_object_int_add(json, "deferredShutdownMsecs", time_store);
2976 }
2977 else
2978 {
2979 vty_out (vty, " Deferred shutdown in progress, %s remaining%s",
2980 ospf_timer_dump (ospf->t_deferred_shutdown,
2981 timebuf, sizeof (timebuf)), VTY_NEWLINE);
2982 }
2983 }
2984
718e3744 2985 /* Show capability. */
ca08c43d
DS
2986 if (use_json)
2987 {
2988 json_object_boolean_true_add(json, "tosRoutesOnly");
2989 json_object_boolean_true_add(json, "rfc2328Conform");
2990 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
2991 {
2992 json_object_boolean_true_add(json, "rfc1583Compatibility");
2993 }
2994 }
2995 else
2996 {
2997 vty_out (vty, " Supports only single TOS (TOS0) routes%s", VTY_NEWLINE);
2998 vty_out (vty, " This implementation conforms to RFC2328%s", VTY_NEWLINE);
2999 vty_out (vty, " RFC1583Compatibility flag is %s%s",
3000 CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE) ?
3001 "enabled" : "disabled", VTY_NEWLINE);
3002 }
3003
ca08c43d
DS
3004 if (use_json)
3005 {
3006 if (CHECK_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE))
3007 {
3008 json_object_boolean_true_add(json, "opaqueCapable");
3009 }
ca08c43d
DS
3010 }
3011 else
3012 {
801e0e14 3013 vty_out (vty, " OpaqueCapability flag is %s%s",
ca08c43d 3014 CHECK_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE) ? "enabled" : "disabled",
ca08c43d
DS
3015 VTY_NEWLINE);
3016 }
ca08c43d 3017
88d6cf37 3018 /* Show stub-router configuration */
3019 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED
3020 || ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3021 {
ca08c43d
DS
3022 if (use_json)
3023 {
3024 json_object_boolean_true_add(json, "stubAdvertisement");
3025 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3026 json_object_int_add(json,"postStartEnabledMsecs", ospf->stub_router_startup_time / 1000);
3027 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3028 json_object_int_add(json,"preShutdownEnabledMsecs", ospf->stub_router_shutdown_time / 1000);
3029 }
3030 else
3031 {
3032 vty_out (vty, " Stub router advertisement is configured%s",
3033 VTY_NEWLINE);
3034 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3035 vty_out (vty, " Enabled for %us after start-up%s",
3036 ospf->stub_router_startup_time, VTY_NEWLINE);
3037 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
3038 vty_out (vty, " Enabled for %us prior to full shutdown%s",
3039 ospf->stub_router_shutdown_time, VTY_NEWLINE);
3040 }
88d6cf37 3041 }
ca08c43d 3042
718e3744 3043 /* Show SPF timers. */
ca08c43d
DS
3044 if (use_json)
3045 {
3046 json_object_int_add(json, "spfScheduleDelayMsecs", ospf->spf_delay);
3047 json_object_int_add(json, "holdtimeMinMsecs", ospf->spf_holdtime);
3048 json_object_int_add(json, "holdtimeMaxMsecs", ospf->spf_max_holdtime);
3049 json_object_int_add(json, "holdtimeMultplier", ospf->spf_hold_multiplier);
b8ad39d4 3050 }
3051 else
ca08c43d
DS
3052 {
3053 vty_out (vty, " Initial SPF scheduling delay %d millisec(s)%s"
3054 " Minimum hold time between consecutive SPFs %d millisec(s)%s"
3055 " Maximum hold time between consecutive SPFs %d millisec(s)%s"
3056 " Hold time multiplier is currently %d%s",
3057 ospf->spf_delay, VTY_NEWLINE,
3058 ospf->spf_holdtime, VTY_NEWLINE,
3059 ospf->spf_max_holdtime, VTY_NEWLINE,
3060 ospf->spf_hold_multiplier, VTY_NEWLINE);
3061 }
b6927875 3062
ca08c43d
DS
3063 if (use_json)
3064 {
3065 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec)
3066 {
cbf3e3eb 3067 long time_store = 0;
ca08c43d 3068
cbf3e3eb 3069 time_store = monotime_since(&ospf->ts_spf, NULL) / 1000LL;
ca08c43d
DS
3070 json_object_int_add(json, "spfLastExecutedMsecs", time_store);
3071
3072 time_store = (1000 * ospf->ts_spf_duration.tv_sec) + (ospf->ts_spf_duration.tv_usec / 1000);
3073 json_object_int_add(json, "spfLastDurationMsecs", time_store);
3074 }
3075 else
3076 json_object_boolean_true_add(json, "spfHasNotRun");
3077 }
3078 else
3079 {
3080 vty_out (vty, " SPF algorithm ");
3081 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec)
3082 {
cbf3e3eb 3083 monotime_since(&ospf->ts_spf, &result);
ca08c43d
DS
3084 vty_out (vty, "last executed %s ago%s",
3085 ospf_timeval_dump (&result, timebuf, sizeof (timebuf)),
3086 VTY_NEWLINE);
3087 vty_out (vty, " Last SPF duration %s%s",
3088 ospf_timeval_dump (&ospf->ts_spf_duration, timebuf, sizeof (timebuf)),
3089 VTY_NEWLINE);
3090 }
3091 else
3092 vty_out (vty, "has not been run%s", VTY_NEWLINE);
3093 }
3094
3095 if (use_json)
3096 {
ca08c43d
DS
3097 if (ospf->t_spf_calc)
3098 {
cbf3e3eb
DL
3099 long time_store;
3100 time_store = monotime_until(&ospf->t_spf_calc->u.sands, NULL) / 1000LL;
ca08c43d
DS
3101 json_object_int_add(json, "spfTimerDueInMsecs", time_store);
3102 }
3103
ac7424f9
MR
3104 json_object_int_add(json, "lsaMinIntervalMsecs", ospf->min_ls_interval);
3105 json_object_int_add(json, "lsaMinArrivalMsecs", ospf->min_ls_arrival);
ca08c43d
DS
3106 /* Show write multiplier values */
3107 json_object_int_add(json, "writeMultiplier", ospf->write_oi_count);
3108 /* Show refresh parameters. */
54b7214f 3109 json_object_int_add(json, "refreshTimerMsecs", ospf->lsa_refresh_interval * 1000);
ca08c43d
DS
3110 }
3111 else
3112 {
3113 vty_out (vty, " SPF timer %s%s%s",
3114 (ospf->t_spf_calc ? "due in " : "is "),
3115 ospf_timer_dump (ospf->t_spf_calc, timebuf, sizeof (timebuf)),
3116 VTY_NEWLINE);
3117
ac7424f9
MR
3118 vty_out (vty, " LSA minimum interval %d msecs%s",
3119 ospf->min_ls_interval, VTY_NEWLINE);
ca08c43d 3120 vty_out (vty, " LSA minimum arrival %d msecs%s",
ac7424f9 3121 ospf->min_ls_arrival, VTY_NEWLINE);
ca08c43d
DS
3122
3123 /* Show write multiplier values */
3124 vty_out (vty, " Write Multiplier set to %d %s",
3125 ospf->write_oi_count, VTY_NEWLINE);
3126
3127 /* Show refresh parameters. */
3128 vty_out (vty, " Refresh timer %d secs%s",
3129 ospf->lsa_refresh_interval, VTY_NEWLINE);
3130 }
2f8f370e 3131
718e3744 3132 /* Show ABR/ASBR flags. */
68980084 3133 if (CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR))
ca08c43d
DS
3134 {
3135 if (use_json)
3136 json_object_string_add(json, "abrType", ospf_abr_type_descr_str[ospf->abr_type]);
3137 else
3138 vty_out (vty, " This router is an ABR, ABR type is: %s%s",
3139 ospf_abr_type_descr_str[ospf->abr_type], VTY_NEWLINE);
3140 }
68980084 3141 if (CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR))
ca08c43d
DS
3142 {
3143 if (use_json)
3144 json_object_string_add(json, "asbrRouter", "injectingExternalRoutingInformation");
3145 else
3146 vty_out (vty, " This router is an ASBR "
3147 "(injecting external routing information)%s", VTY_NEWLINE);
3148 }
718e3744 3149
3150 /* Show Number of AS-external-LSAs. */
ca08c43d
DS
3151 if (use_json)
3152 {
3ac237f8 3153 json_object_int_add(json, "lsaExternalCounter",
ca08c43d
DS
3154 ospf_lsdb_count (ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3155 json_object_int_add(json, "lsaExternalChecksum",
3156 ospf_lsdb_checksum (ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3157 }
3158 else
3159 {
3160 vty_out (vty, " Number of external LSA %ld. Checksum Sum 0x%08x%s",
3161 ospf_lsdb_count (ospf->lsdb, OSPF_AS_EXTERNAL_LSA),
3162 ospf_lsdb_checksum (ospf->lsdb, OSPF_AS_EXTERNAL_LSA), VTY_NEWLINE);
3163 }
3164
ca08c43d
DS
3165 if (use_json)
3166 {
3ac237f8 3167 json_object_int_add(json, "lsaAsopaqueCounter",
ca08c43d
DS
3168 ospf_lsdb_count (ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3169 json_object_int_add(json, "lsaAsOpaqueChecksum",
3170 ospf_lsdb_checksum (ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3171 }
3172 else
3173 {
3174 vty_out (vty, " Number of opaque AS LSA %ld. Checksum Sum 0x%08x%s",
3175 ospf_lsdb_count (ospf->lsdb, OSPF_OPAQUE_AS_LSA),
3176 ospf_lsdb_checksum (ospf->lsdb, OSPF_OPAQUE_AS_LSA), VTY_NEWLINE);
3177 }
ca08c43d 3178
718e3744 3179 /* Show number of areas attached. */
ca08c43d 3180 if (use_json)
3ac237f8 3181 json_object_int_add(json, "attachedAreaCounter", listcount (ospf->areas));
ca08c43d
DS
3182 else
3183 vty_out (vty, " Number of areas attached to this router: %d%s",
3184 listcount (ospf->areas), VTY_NEWLINE);
d7e60dd7
AS
3185
3186 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES))
3187 {
3188 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
ca08c43d
DS
3189 {
3190 if (use_json)
3191 json_object_boolean_true_add(json, "adjacencyChangesLoggedAll");
3192 else
3193 vty_out(vty, " All adjacency changes are logged%s",VTY_NEWLINE);
3194 }
d7e60dd7 3195 else
ca08c43d
DS
3196 {
3197 if (use_json)
3198 json_object_boolean_true_add(json, "adjacencyChangesLogged");
3199 else
3200 vty_out(vty, " Adjacency changes are logged%s",VTY_NEWLINE);
3201 }
d7e60dd7 3202 }
718e3744 3203 /* Show each area status. */
1eb8ef25 3204 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
ca08c43d
DS
3205 show_ip_ospf_area (vty, area, json_areas, use_json);
3206
3207 if (use_json)
3208 {
3209 json_object_object_add(json, "areas", json_areas);
2aac5767 3210 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
ca08c43d
DS
3211 json_object_free(json);
3212 }
3213 else
3214 vty_out (vty, "%s",VTY_NEWLINE);
718e3744 3215
3216 return CMD_SUCCESS;
3217}
3218
7c8ff89e
DS
3219DEFUN (show_ip_ospf,
3220 show_ip_ospf_cmd,
b162fa78 3221 "show ip ospf [json]",
7c8ff89e
DS
3222 SHOW_STR
3223 IP_STR
ca08c43d 3224 "OSPF information\n"
9973d184 3225 JSON_STR)
7c8ff89e
DS
3226{
3227 struct ospf *ospf;
db7c8528 3228 u_char uj = use_json(argc, argv);
7c8ff89e 3229
0bad4851 3230 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3231 return CMD_SUCCESS;
3232
db7c8528 3233 return (show_ip_ospf_common(vty, ospf, uj));
7c8ff89e
DS
3234}
3235
3236DEFUN (show_ip_ospf_instance,
3237 show_ip_ospf_instance_cmd,
6147e2c6 3238 "show ip ospf (1-65535) [json]",
7c8ff89e
DS
3239 SHOW_STR
3240 IP_STR
3241 "OSPF information\n"
ca08c43d 3242 "Instance ID\n"
9973d184 3243 JSON_STR)
7c8ff89e 3244{
8d769265 3245 int idx_number = 3;
7c8ff89e
DS
3246 struct ospf *ospf;
3247 u_short instance = 0;
db7c8528 3248 u_char uj = use_json(argc, argv);
7c8ff89e 3249
8d769265 3250 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3251 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3252 return CMD_SUCCESS;
3253
db7c8528 3254 return (show_ip_ospf_common(vty, ospf, uj));
7c8ff89e
DS
3255}
3256
fd651fa6 3257static void
7ec4159b
DS
3258show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface *ifp,
3259 json_object *json_interface_sub, u_char use_json)
718e3744 3260{
fd651fa6 3261 int is_up;
718e3744 3262 struct ospf_neighbor *nbr;
718e3744 3263 struct route_node *rn;
718e3744 3264
718e3744 3265 /* Is interface up? */
7ec4159b
DS
3266 if (use_json)
3267 {
3268 is_up = if_is_operative(ifp);
3269 if (is_up)
3270 json_object_boolean_true_add(json_interface_sub, "ifUp");
3271 else
3272 json_object_boolean_false_add(json_interface_sub, "ifDown");
3273
3274 json_object_int_add(json_interface_sub, "ifIndex", ifp->ifindex);
3275 json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu);
70bd3c43 3276 json_object_int_add(json_interface_sub, "bandwidthMbit", ifp->bandwidth);
7ec4159b
DS
3277 json_object_string_add(json_interface_sub, "ifFlags", if_flag_dump(ifp->flags));
3278 }
3279 else
3280 {
3281 vty_out (vty, "%s is %s%s", ifp->name,
3282 ((is_up = if_is_operative(ifp)) ? "up" : "down"), VTY_NEWLINE);
70bd3c43 3283 vty_out (vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s%s",
7ec4159b
DS
3284 ifp->ifindex, ifp->mtu, ifp->bandwidth, if_flag_dump(ifp->flags),
3285 VTY_NEWLINE);
3286 }
718e3744 3287
3288 /* Is interface OSPF enabled? */
7ec4159b 3289 if (use_json)
718e3744 3290 {
7ec4159b
DS
3291 if (ospf_oi_count(ifp) == 0)
3292 {
3293 json_object_boolean_false_add(json_interface_sub, "ospfEnabled");
3294 return;
3295 }
3296 else if (!is_up)
3297 {
3298 json_object_boolean_false_add(json_interface_sub, "ospfRunning");
3299 return;
3300 }
3301 else
3302 json_object_boolean_true_add(json_interface_sub, "ospfEnabled");
718e3744 3303 }
7ec4159b 3304 else
fd651fa6 3305 {
7ec4159b
DS
3306 if (ospf_oi_count(ifp) == 0)
3307 {
3308 vty_out (vty, " OSPF not enabled on this interface%s", VTY_NEWLINE);
3309 return;
3310 }
3311 else if (!is_up)
3312 {
3313 vty_out (vty, " OSPF is enabled, but not running on this interface%s",
3314 VTY_NEWLINE);
3315 return;
3316 }
fd651fa6 3317 }
3318
718e3744 3319 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
3320 {
3321 struct ospf_interface *oi = rn->info;
7ec4159b 3322
718e3744 3323 if (oi == NULL)
7ec4159b
DS
3324 continue;
3325
525c1839
DS
3326 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
3327 {
7ec4159b
DS
3328 if (use_json)
3329 json_object_boolean_true_add(json_interface_sub, "ifUnnumbered");
3330 else
3331 vty_out (vty, " This interface is UNNUMBERED,");
525c1839
DS
3332 }
3333 else
9c27ef9b 3334 {
525c1839 3335 /* Show OSPF interface information. */
7ec4159b
DS
3336 if (use_json)
3337 {
3338 json_object_string_add(json_interface_sub, "ipAddress", inet_ntoa (oi->address->u.prefix4));
3339 json_object_int_add(json_interface_sub, "ipAddressPrefixlen", oi->address->prefixlen);
3340 }
3341 else
3342 vty_out (vty, " Internet Address %s/%d,",
3343 inet_ntoa (oi->address->u.prefix4), oi->address->prefixlen);
525c1839
DS
3344
3345 if (oi->connected->destination || oi->type == OSPF_IFTYPE_VIRTUALLINK)
3346 {
3347 struct in_addr *dest;
3348 const char *dstr;
3349
3350 if (CONNECTED_PEER(oi->connected)
3351 || oi->type == OSPF_IFTYPE_VIRTUALLINK)
3352 dstr = "Peer";
3353 else
3354 dstr = "Broadcast";
3355
3356 /* For Vlinks, showing the peer address is probably more
7ec4159b
DS
3357 * * * * * informative than the local interface that is being used
3358 * * * * */
525c1839
DS
3359 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3360 dest = &oi->vl_data->peer_addr;
3361 else
3362 dest = &oi->connected->destination->u.prefix4;
3363
7ec4159b
DS
3364 if (use_json)
3365 {
3366 json_object_string_add(json_interface_sub, "ospfIfType", dstr);
3367 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3368 json_object_string_add(json_interface_sub, "vlinkPeer", inet_ntoa (*dest));
3369 else
3370 json_object_string_add(json_interface_sub, "localIfUsed", inet_ntoa (*dest));
3371 }
3372 else
3373 vty_out (vty, " %s %s,", dstr, inet_ntoa (*dest));
525c1839 3374 }
9c27ef9b 3375 }
7ec4159b
DS
3376 if (use_json)
3377 {
3378 json_object_string_add(json_interface_sub, "area", ospf_area_desc_string (oi->area));
3379 if (OSPF_IF_PARAM(oi, mtu_ignore))
3380 json_object_boolean_true_add(json_interface_sub, "mtuMismatchDetect");
3381 json_object_string_add(json_interface_sub, "routerId", inet_ntoa (ospf->router_id));
3382 json_object_string_add(json_interface_sub, "networkType", ospf_network_type_str[oi->type]);
3383 json_object_int_add(json_interface_sub, "cost", oi->output_cost);
3384 json_object_int_add(json_interface_sub, "transmitDelayMsecs", 1000 / OSPF_IF_PARAM (oi,transmit_delay));
3385 json_object_string_add(json_interface_sub, "state", LOOKUP (ospf_ism_state_msg, oi->state));
3386 json_object_int_add(json_interface_sub, "priority", PRIORITY (oi));
3387 }
3388 else
3389 {
3390 vty_out (vty, " Area %s%s", ospf_area_desc_string (oi->area),
3391 VTY_NEWLINE);
3fb9cd6e 3392
7ec4159b
DS
3393 vty_out (vty, " MTU mismatch detection:%s%s",
3394 OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" : "enabled", VTY_NEWLINE);
ba682537 3395
7ec4159b
DS
3396 vty_out (vty, " Router ID %s, Network Type %s, Cost: %d%s",
3397 inet_ntoa (ospf->router_id), ospf_network_type_str[oi->type],
3398 oi->output_cost, VTY_NEWLINE);
718e3744 3399
7ec4159b
DS
3400 vty_out (vty, " Transmit Delay is %d sec, State %s, Priority %d%s",
3401 OSPF_IF_PARAM (oi,transmit_delay), LOOKUP (ospf_ism_state_msg, oi->state),
3402 PRIORITY (oi), VTY_NEWLINE);
3403 }
718e3744 3404
3405 /* Show DR information. */
3406 if (DR (oi).s_addr == 0)
7ec4159b
DS
3407 {
3408 if (!use_json)
3409 vty_out (vty, " No backup designated router on this network%s",
3410 VTY_NEWLINE);
3411 }
718e3744 3412 else
7ec4159b
DS
3413 {
3414 nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &BDR (oi));
3415 if (nbr == NULL)
3416 {
3417 if (!use_json)
3418 vty_out (vty, " No backup designated router on this network%s",
3419 VTY_NEWLINE);
3420 }
3421 else
3422 {
3423 if (use_json)
3424 {
3425 json_object_string_add(json_interface_sub, "bdrId", inet_ntoa (nbr->router_id));
3426 json_object_string_add(json_interface_sub, "bdrAddress", inet_ntoa (nbr->address.u.prefix4));
3427 }
3428 else
3429 {
3430 vty_out (vty, " Backup Designated Router (ID) %s,",
3431 inet_ntoa (nbr->router_id));
3432 vty_out (vty, " Interface Address %s%s",
3433 inet_ntoa (nbr->address.u.prefix4), VTY_NEWLINE);
3434 }
3435 }
3436 }
525c1839 3437
7eb5b47e 3438 /* Next network-LSA sequence number we'll use, if we're elected DR */
7ec4159b 3439 if (oi->params && ntohl (oi->params->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER)
429ac78c 3440 {
7ec4159b
DS
3441 if (use_json)
3442 json_object_int_add(json_interface_sub, "networkLsaSequence", ntohl (oi->params->network_lsa_seqnum));
3443 else
3444 vty_out (vty, " Saved Network-LSA sequence number 0x%x%s",
3445 ntohl (oi->params->network_lsa_seqnum), VTY_NEWLINE);
3446 }
3447
3448 if (use_json)
3449 {
3450 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3451 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3452 {
3453 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3454 json_object_boolean_true_add(json_interface_sub, "mcastMemberOspfAllRouters");
3455 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3456 json_object_boolean_true_add(json_interface_sub, "mcastMemberOspfDesignatedRouters");
3457 }
429ac78c
PJ
3458 }
3459 else
7ec4159b
DS
3460 {
3461 vty_out (vty, " Multicast group memberships:");
3462 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3463 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3464 {
3465 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3466 vty_out (vty, " OSPFAllRouters");
3467 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3468 vty_out (vty, " OSPFDesignatedRouters");
3469 }
3470 else
3471 vty_out (vty, " <None>");
3472 vty_out (vty, "%s", VTY_NEWLINE);
3473 }
ba6454ec 3474
7ec4159b
DS
3475 if (use_json)
3476 {
3477 if (OSPF_IF_PARAM (oi, fast_hello) == 0)
3478 json_object_int_add(json_interface_sub, "timerMsecs", 1000 /OSPF_IF_PARAM (oi, v_hello));
3479 else
3480 json_object_int_add(json_interface_sub, "timerMsecs", 1000 / OSPF_IF_PARAM (oi, fast_hello));
3481 json_object_int_add(json_interface_sub, "timerDeadMsecs", 1000 / OSPF_IF_PARAM (oi, v_wait));
3482 json_object_int_add(json_interface_sub, "timerWaitMsecs", 1000 / OSPF_IF_PARAM (oi, v_wait));
3483 json_object_int_add(json_interface_sub, "timerRetransmit", 1000 / OSPF_IF_PARAM (oi, retransmit_interval));
3484 }
f9ad937f 3485 else
7ec4159b
DS
3486 {
3487 vty_out (vty, " Timer intervals configured,");
3488 vty_out (vty, " Hello ");
3489 if (OSPF_IF_PARAM (oi, fast_hello) == 0)
3490 vty_out (vty, "%ds,", OSPF_IF_PARAM (oi, v_hello));
3491 else
3492 vty_out (vty, "%dms,", 1000 / OSPF_IF_PARAM (oi, fast_hello));
3493 vty_out (vty, " Dead %ds, Wait %ds, Retransmit %d%s",
3494 OSPF_IF_PARAM (oi, v_wait),
3495 OSPF_IF_PARAM (oi, v_wait),
3496 OSPF_IF_PARAM (oi, retransmit_interval),
3497 VTY_NEWLINE);
3498 }
3499
7ffa8fa2 3500 if (OSPF_IF_PASSIVE_STATUS (oi) == OSPF_IF_ACTIVE)
f9ad937f 3501 {
7ec4159b
DS
3502 char timebuf[OSPF_TIME_DUMP_SIZE];
3503 if (use_json)
3504 {
cbf3e3eb
DL
3505 long time_store = 0;
3506 if (oi->t_hello)
3507 time_store = monotime_until(&oi->t_hello->u.sands, NULL) / 1000LL;
7ec4159b
DS
3508 json_object_int_add(json_interface_sub, "timerHelloInMsecs", time_store);
3509 }
3510 else
3511 vty_out (vty, " Hello due in %s%s",
3512 ospf_timer_dump (oi->t_hello, timebuf, sizeof(timebuf)),
3513 VTY_NEWLINE);
f9ad937f 3514 }
7ffa8fa2 3515 else /* passive-interface is set */
7ec4159b
DS
3516 {
3517 if (use_json)
3518 json_object_boolean_true_add(json_interface_sub, "timerPassiveIface");
3519 else
3520 vty_out (vty, " No Hellos (Passive interface)%s", VTY_NEWLINE);
3521 }
3522
3523 if (use_json)
3524 {
3525 json_object_int_add(json_interface_sub, "nbrCount", ospf_nbr_count (oi, 0));
3526 json_object_int_add(json_interface_sub, "nbrAdjacentCount", ospf_nbr_count (oi, NSM_Full));
3527 }
3528 else
3529 vty_out (vty, " Neighbor Count is %d, Adjacent neighbor count is %d%s",
3530 ospf_nbr_count (oi, 0), ospf_nbr_count (oi, NSM_Full),
3531 VTY_NEWLINE);
68fe91d6 3532 ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json);
718e3744 3533 }
3534}
3535
7c8ff89e 3536static int
7ec4159b 3537show_ip_ospf_interface_common (struct vty *vty, struct ospf *ospf, int argc,
7a7be519 3538 struct cmd_token **argv, int iface_argv, u_char use_json)
718e3744 3539{
3540 struct interface *ifp;
52dc7ee6 3541 struct listnode *node;
7ec4159b
DS
3542 json_object *json = NULL;
3543 json_object *json_interface_sub = NULL;
3544
3545 if (use_json)
3546 {
3547 json = json_object_new_object();
3548 json_interface_sub = json_object_new_object();
3549 }
718e3744 3550
7c8ff89e 3551 if (ospf->instance)
7ec4159b
DS
3552 {
3553 if (use_json)
3554 json_object_int_add(json, "ospfInstance", ospf->instance);
3555 else
3556 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3557 VTY_NEWLINE, VTY_NEWLINE);
3558 }
7c8ff89e 3559
7ec4159b
DS
3560 if (argc == (iface_argv + 1))
3561 {
3562 /* Show All Interfaces.*/
b2d7c082 3563 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
7ec4159b
DS
3564 {
3565 if (ospf_oi_count(ifp))
3566 {
3567 show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
b8dfa544
DS
3568 if (use_json)
3569 json_object_object_add (json, ifp->name, json_interface_sub);
7ec4159b
DS
3570 }
3571 }
3572 }
7a7be519 3573 else if (argv[iface_argv] && strcmp(argv[iface_argv]->arg, "json") == 0)
cac3b5c4 3574 {
b8dfa544
DS
3575 if (!use_json)
3576 {
3577 json = json_object_new_object();
3578 json_interface_sub = json_object_new_object ();
3579 use_json = 1;
3580 }
7c8ff89e 3581 /* Show All Interfaces. */
b2d7c082 3582 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
7ec4159b
DS
3583 {
3584 if (ospf_oi_count(ifp))
3585 {
3586 show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
b8dfa544
DS
3587 if (use_json)
3588 json_object_object_add(json, ifp->name, json_interface_sub);
3589 }
3590 }
cac3b5c4 3591 }
718e3744 3592 else
3593 {
7c8ff89e 3594 /* Interface name is specified. */
1306c09a 3595 if ((ifp = if_lookup_by_name (argv[iface_argv]->arg, VRF_DEFAULT)) == NULL)
7ec4159b
DS
3596 {
3597 if (use_json)
3598 json_object_boolean_true_add(json, "noSuchIface");
3599 else
3600 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
3601 }
718e3744 3602 else
7ec4159b
DS
3603 {
3604 show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
3605 if (use_json)
3606 json_object_object_add(json, ifp->name, json_interface_sub);
3607 }
718e3744 3608 }
3609
7ec4159b
DS
3610 if (use_json)
3611 {
2aac5767 3612 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
7ec4159b
DS
3613 json_object_free(json);
3614 }
3615 else
3616 vty_out (vty, "%s", VTY_NEWLINE);
7c8ff89e 3617
718e3744 3618 return CMD_SUCCESS;
3619}
3620
7c8ff89e
DS
3621DEFUN (show_ip_ospf_interface,
3622 show_ip_ospf_interface_cmd,
b162fa78 3623 "show ip ospf interface [INTERFACE] [json]",
7c8ff89e
DS
3624 SHOW_STR
3625 IP_STR
3626 "OSPF information\n"
3627 "Interface information\n"
7ec4159b 3628 "Interface name\n"
9973d184 3629 JSON_STR)
7c8ff89e
DS
3630{
3631 struct ospf *ospf;
db7c8528 3632 u_char uj = use_json(argc, argv);
7c8ff89e 3633
0bad4851 3634 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3635 return CMD_SUCCESS;
3636
db7c8528 3637 return show_ip_ospf_interface_common(vty, ospf, argc, argv, 0, uj);
7c8ff89e
DS
3638}
3639
3640DEFUN (show_ip_ospf_instance_interface,
3641 show_ip_ospf_instance_interface_cmd,
6147e2c6 3642 "show ip ospf (1-65535) interface [INTERFACE] [json]",
7c8ff89e
DS
3643 SHOW_STR
3644 IP_STR
3645 "OSPF information\n"
3646 "Instance ID\n"
3647 "Interface information\n"
7ec4159b 3648 "Interface name\n"
9973d184 3649 JSON_STR)
7c8ff89e 3650{
8d769265 3651 int idx_number = 3;
7c8ff89e
DS
3652 struct ospf *ospf;
3653 u_short instance = 0;
db7c8528 3654 u_char uj = use_json(argc, argv);
7c8ff89e 3655
8d769265 3656 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3657 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3658 return CMD_SUCCESS;
3659
db7c8528 3660 return show_ip_ospf_interface_common(vty, ospf, argc, argv, 1, uj);
7c8ff89e
DS
3661}
3662
d24f6e2a 3663static void
3664show_ip_ospf_neighbour_header (struct vty *vty)
3665{
490578f3 3666 vty_out (vty, "%s%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s%s",
d24f6e2a 3667 VTY_NEWLINE,
3668 "Neighbor ID", "Pri", "State", "Dead Time",
3669 "Address", "Interface", "RXmtL", "RqstL", "DBsmL",
3670 VTY_NEWLINE);
3671}
3672
4dadc291 3673static void
91756b38 3674show_ip_ospf_neighbor_sub (struct vty *vty, struct ospf_interface *oi, json_object *json, u_char use_json)
718e3744 3675{
3676 struct route_node *rn;
3677 struct ospf_neighbor *nbr;
3678 char msgbuf[16];
649654ab 3679 char timebuf[OSPF_TIME_DUMP_SIZE];
91756b38 3680 json_object *json_neighbor = NULL;
718e3744 3681
3682 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
91756b38
DS
3683 {
3684 if ((nbr = rn->info))
3685 {
3686 /* Do not show myself. */
3687 if (nbr != oi->nbr_self)
3688 {
3689 /* Down state is not shown. */
3690 if (nbr->state != NSM_Down)
3691 {
3692 if (use_json)
3693 {
3694 json_neighbor = json_object_new_object();
3695 ospf_nbr_state_message (nbr, msgbuf, 16);
3696
cbf3e3eb 3697 long time_store;
91756b38 3698
cbf3e3eb 3699 time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
91756b38
DS
3700
3701 json_object_int_add (json_neighbor, "priority", nbr->priority);
3702 json_object_string_add (json_neighbor, "state", msgbuf);
3703 json_object_int_add (json_neighbor, "deadTimeMsecs", time_store);
3704 json_object_string_add (json_neighbor, "address", inet_ntoa (nbr->src));
3705 json_object_string_add (json_neighbor, "ifaceName", IF_NAME (oi));
3ac237f8
MS
3706 json_object_int_add (json_neighbor, "retransmitCounter", ospf_ls_retransmit_count (nbr));
3707 json_object_int_add (json_neighbor, "requestCounter", ospf_ls_request_count (nbr));
3708 json_object_int_add (json_neighbor, "dbSummaryCounter", ospf_db_summary_count (nbr));
91756b38
DS
3709 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
3710 json_object_object_add(json, "neighbor", json_neighbor);
3711 else
3712 json_object_object_add(json, inet_ntoa (nbr->router_id), json_neighbor);
3713 }
3714 else
3715 {
3716 ospf_nbr_state_message (nbr, msgbuf, 16);
3717
3718 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
3719 vty_out (vty, "%-15s %3d %-15s ",
3720 "-", nbr->priority,
3721 msgbuf);
3722 else
3723 vty_out (vty, "%-15s %3d %-15s ",
3724 inet_ntoa (nbr->router_id), nbr->priority,
3725 msgbuf);
3726
3727 vty_out (vty, "%9s ",
3728 ospf_timer_dump (nbr->t_inactivity, timebuf,
3729 sizeof(timebuf)));
3730 vty_out (vty, "%-15s ", inet_ntoa (nbr->src));
3731 vty_out (vty, "%-20s %5ld %5ld %5d%s",
3732 IF_NAME (oi), ospf_ls_retransmit_count (nbr),
3733 ospf_ls_request_count (nbr), ospf_db_summary_count (nbr),
3734 VTY_NEWLINE);
3735 }
3736 }
3737 }
3738 }
3739 }
718e3744 3740}
3741
7c8ff89e 3742static int
91756b38 3743show_ip_ospf_neighbor_common (struct vty *vty, struct ospf *ospf, u_char use_json)
718e3744 3744{
1eb8ef25 3745 struct ospf_interface *oi;
52dc7ee6 3746 struct listnode *node;
91756b38 3747 json_object *json = NULL;
718e3744 3748
91756b38
DS
3749 if (use_json)
3750 json = json_object_new_object();
3751 else
3752 show_ip_ospf_neighbour_header (vty);
718e3744 3753
91756b38
DS
3754 if (ospf->instance)
3755 {
3756 if (use_json)
3757 json_object_int_add(json, "ospfInstance", ospf->instance);
3758 else
3759 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3760 VTY_NEWLINE, VTY_NEWLINE);
3761 }
718e3744 3762
1eb8ef25 3763 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
91756b38 3764 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
718e3744 3765
91756b38
DS
3766 if (use_json)
3767 {
2aac5767 3768 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
91756b38
DS
3769 json_object_free(json);
3770 }
3771 else
3772 vty_out (vty, "%s", VTY_NEWLINE);
7c8ff89e 3773
718e3744 3774 return CMD_SUCCESS;
3775}
3776
7c8ff89e
DS
3777DEFUN (show_ip_ospf_neighbor,
3778 show_ip_ospf_neighbor_cmd,
b162fa78 3779 "show ip ospf neighbor [json]",
718e3744 3780 SHOW_STR
3781 IP_STR
3782 "OSPF information\n"
91756b38 3783 "Neighbor list\n"
9973d184 3784 JSON_STR)
718e3744 3785{
7c8ff89e 3786 struct ospf *ospf;
db7c8528 3787 u_char uj = use_json(argc, argv);
718e3744 3788
0bad4851 3789 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3790 return CMD_SUCCESS;
3791
db7c8528 3792 return show_ip_ospf_neighbor_common(vty, ospf, uj);
7c8ff89e
DS
3793}
3794
3795
3796DEFUN (show_ip_ospf_instance_neighbor,
3797 show_ip_ospf_instance_neighbor_cmd,
6147e2c6 3798 "show ip ospf (1-65535) neighbor [json]",
7c8ff89e
DS
3799 SHOW_STR
3800 IP_STR
3801 "OSPF information\n"
3802 "Instance ID\n"
91756b38 3803 "Neighbor list\n"
9973d184 3804 JSON_STR)
7c8ff89e 3805{
8d769265 3806 int idx_number = 3;
7c8ff89e
DS
3807 struct ospf *ospf;
3808 u_short instance = 0;
db7c8528 3809 u_char uj = use_json(argc, argv);
7c8ff89e 3810
8d769265 3811 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3812 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3813 return CMD_SUCCESS;
3814
db7c8528 3815 return show_ip_ospf_neighbor_common(vty, ospf, uj);
7c8ff89e
DS
3816}
3817
3818static int
91756b38 3819show_ip_ospf_neighbor_all_common (struct vty *vty, struct ospf *ospf, u_char use_json)
7c8ff89e
DS
3820{
3821 struct listnode *node;
3822 struct ospf_interface *oi;
91756b38
DS
3823 json_object *json = NULL;
3824 json_object *json_neighbor_sub = NULL;
7c8ff89e 3825
91756b38
DS
3826 if (use_json)
3827 {
3828 json = json_object_new_object();
3829 json_neighbor_sub = json_object_new_object();
3830 }
3831 else
3832 show_ip_ospf_neighbour_header (vty);
7c8ff89e 3833
91756b38
DS
3834 if (ospf->instance)
3835 {
3836 if (use_json)
3837 json_object_int_add(json, "ospfInstance", ospf->instance);
3838 else
3839 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3840 VTY_NEWLINE, VTY_NEWLINE);
3841 }
7c8ff89e
DS
3842
3843 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
3844 {
52dc7ee6 3845 struct listnode *nbr_node;
1eb8ef25 3846 struct ospf_nbr_nbma *nbr_nbma;
718e3744 3847
91756b38 3848 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
718e3744 3849
91756b38
DS
3850 /* print Down neighbor status */
3851 for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nbr_node, nbr_nbma))
3852 {
3853 if (nbr_nbma->nbr == NULL
3854 || nbr_nbma->nbr->state == NSM_Down)
3855 {
3856 if (use_json)
3857 {
3858 json_object_int_add (json_neighbor_sub, "nbrNbmaPriority", nbr_nbma->priority);
3859 json_object_boolean_true_add (json_neighbor_sub, "nbrNbmaDown");
3860 json_object_string_add (json_neighbor_sub, "nbrNbmaIfaceName", IF_NAME (oi));
3ac237f8
MS
3861 json_object_int_add (json_neighbor_sub, "nbrNbmaRetransmitCounter", 0);
3862 json_object_int_add (json_neighbor_sub, "nbrNbmaRequestCounter", 0);
3863 json_object_int_add (json_neighbor_sub, "nbrNbmaDbSummaryCounter", 0);
91756b38
DS
3864 json_object_object_add(json, inet_ntoa (nbr_nbma->addr), json_neighbor_sub);
3865 }
3866 else
3867 {
3868 vty_out (vty, "%-15s %3d %-15s %9s ",
3869 "-", nbr_nbma->priority, "Down", "-");
3870 vty_out (vty, "%-15s %-20s %5d %5d %5d%s",
3871 inet_ntoa (nbr_nbma->addr), IF_NAME (oi),
3872 0, 0, 0, VTY_NEWLINE);
3873 }
3874 }
3875 }
718e3744 3876 }
3877
91756b38
DS
3878 if (use_json)
3879 {
2aac5767 3880 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
91756b38
DS
3881 json_object_free(json);
3882 }
3883 else
3884 vty_out (vty, "%s", VTY_NEWLINE);
7c8ff89e 3885
718e3744 3886 return CMD_SUCCESS;
3887}
3888
7c8ff89e
DS
3889DEFUN (show_ip_ospf_neighbor_all,
3890 show_ip_ospf_neighbor_all_cmd,
b162fa78 3891 "show ip ospf neighbor all [json]",
718e3744 3892 SHOW_STR
3893 IP_STR
3894 "OSPF information\n"
3895 "Neighbor list\n"
91756b38 3896 "include down status neighbor\n"
9973d184 3897 JSON_STR)
7c8ff89e
DS
3898{
3899 struct ospf *ospf;
db7c8528 3900 u_char uj = use_json(argc, argv);
7c8ff89e 3901
0bad4851 3902 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3903 return CMD_SUCCESS;
3904
db7c8528 3905 return show_ip_ospf_neighbor_all_common(vty, ospf, uj);
7c8ff89e
DS
3906}
3907
3908DEFUN (show_ip_ospf_instance_neighbor_all,
3909 show_ip_ospf_instance_neighbor_all_cmd,
6147e2c6 3910 "show ip ospf (1-65535) neighbor all [json]",
7c8ff89e
DS
3911 SHOW_STR
3912 IP_STR
3913 "OSPF information\n"
3914 "Instance ID\n"
3915 "Neighbor list\n"
91756b38 3916 "include down status neighbor\n"
9973d184 3917 JSON_STR)
718e3744 3918{
8d769265 3919 int idx_number = 3;
020709f9 3920 struct ospf *ospf;
7c8ff89e 3921 u_short instance = 0;
db7c8528 3922 u_char uj = use_json(argc, argv);
7c8ff89e 3923
8d769265 3924 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 3925 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
3926 return CMD_SUCCESS;
3927
db7c8528 3928 return show_ip_ospf_neighbor_all_common(vty, ospf, uj);
7c8ff89e
DS
3929}
3930
3931static int
3932show_ip_ospf_neighbor_int_common (struct vty *vty, struct ospf *ospf, int arg_base,
7a7be519 3933 struct cmd_token **argv, u_char use_json)
7c8ff89e 3934{
bb5b7552 3935 struct interface *ifp;
3936 struct route_node *rn;
91756b38
DS
3937 json_object *json = NULL;
3938
3939 if (use_json)
3940 json = json_object_new_object();
3941 else
3942 show_ip_ospf_neighbour_header (vty);
7c8ff89e
DS
3943
3944 if (ospf->instance)
91756b38
DS
3945 {
3946 if (use_json)
3947 json_object_int_add(json, "ospfInstance", ospf->instance);
3948 else
3949 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3950 VTY_NEWLINE, VTY_NEWLINE);
3951 }
7c8ff89e 3952
1306c09a 3953 ifp = if_lookup_by_name (argv[arg_base]->arg, VRF_DEFAULT);
bb5b7552 3954 if (!ifp)
718e3744 3955 {
91756b38
DS
3956 if (use_json)
3957 json_object_boolean_true_add(json, "noSuchIface");
3958 else
3959 vty_out (vty, "No such interface.%s", VTY_NEWLINE);
718e3744 3960 return CMD_WARNING;
3961 }
d24f6e2a 3962
bb5b7552 3963 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
718e3744 3964 {
bb5b7552 3965 struct ospf_interface *oi = rn->info;
3966
3967 if (oi == NULL)
91756b38 3968 continue;
bb5b7552 3969
91756b38 3970 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
718e3744 3971 }
3972
91756b38
DS
3973 if (use_json)
3974 {
2aac5767 3975 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
91756b38
DS
3976 json_object_free(json);
3977 }
3978 else
3979 vty_out (vty, "%s", VTY_NEWLINE);
3980
718e3744 3981 return CMD_SUCCESS;
3982}
3983
7c8ff89e
DS
3984DEFUN (show_ip_ospf_neighbor_int,
3985 show_ip_ospf_neighbor_int_cmd,
b162fa78 3986 "show ip ospf neighbor IFNAME [json]",
7c8ff89e
DS
3987 SHOW_STR
3988 IP_STR
3989 "OSPF information\n"
3990 "Neighbor list\n"
91756b38 3991 "Interface name\n"
9973d184 3992 JSON_STR)
7c8ff89e
DS
3993{
3994 struct ospf *ospf;
db7c8528 3995 u_char uj = use_json(argc, argv);
7c8ff89e 3996
0bad4851 3997 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
3998 return CMD_SUCCESS;
3999
db7c8528 4000 return show_ip_ospf_neighbor_int_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
4001}
4002
4003DEFUN (show_ip_ospf_instance_neighbor_int,
4004 show_ip_ospf_instance_neighbor_int_cmd,
6147e2c6 4005 "show ip ospf (1-65535) neighbor IFNAME [json]",
7c8ff89e
DS
4006 SHOW_STR
4007 IP_STR
4008 "OSPF information\n"
4009 "Instance ID\n"
4010 "Neighbor list\n"
91756b38 4011 "Interface name\n"
9973d184 4012 JSON_STR)
7c8ff89e 4013{
8d769265 4014 int idx_number = 3;
7c8ff89e
DS
4015 struct ospf *ospf;
4016 u_short instance = 0;
db7c8528 4017 u_char uj = use_json(argc, argv);
7c8ff89e 4018
8d769265 4019 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4020 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4021 return CMD_SUCCESS;
4022
db7c8528 4023 return show_ip_ospf_neighbor_int_common(vty, ospf, 1, argv, uj);
7c8ff89e
DS
4024}
4025
4dadc291 4026static void
3ac237f8
MS
4027show_ip_ospf_nbr_nbma_detail_sub (struct vty *vty, struct ospf_interface *oi, struct ospf_nbr_nbma *nbr_nbma,
4028 u_char use_json, json_object *json)
718e3744 4029{
649654ab 4030 char timebuf[OSPF_TIME_DUMP_SIZE];
3ac237f8 4031 json_object *json_sub = NULL;
718e3744 4032
3ac237f8
MS
4033 if (use_json)
4034 json_sub = json_object_new_object();
4035 else /* Show neighbor ID. */
4036 vty_out (vty, " Neighbor %s,", "-");
718e3744 4037
4038 /* Show interface address. */
3ac237f8
MS
4039 if (use_json)
4040 json_object_string_add(json_sub, "ifaceAddress", inet_ntoa (nbr_nbma->addr));
4041 else
4042 vty_out (vty, " interface address %s%s",
4043 inet_ntoa (nbr_nbma->addr), VTY_NEWLINE);
4044
718e3744 4045 /* Show Area ID. */
3ac237f8
MS
4046 if (use_json)
4047 {
4048 json_object_string_add(json_sub, "areaId", ospf_area_desc_string (oi->area));
4049 json_object_string_add(json_sub, "iface", IF_NAME (oi));
4050 }
4051 else
4052 vty_out (vty, " In the area %s via interface %s%s",
4053 ospf_area_desc_string (oi->area), IF_NAME (oi), VTY_NEWLINE);
4054
718e3744 4055 /* Show neighbor priority and state. */
3ac237f8
MS
4056 if (use_json)
4057 {
4058 json_object_int_add(json_sub, "nbrPriority", nbr_nbma->priority);
4059 json_object_string_add(json_sub, "nbrState", "down");
4060 }
4061 else
4062 vty_out (vty, " Neighbor priority is %d, State is %s,",
4063 nbr_nbma->priority, "Down");
4064
718e3744 4065 /* Show state changes. */
3ac237f8
MS
4066 if (use_json)
4067 json_object_int_add(json_sub, "stateChangeCounter", nbr_nbma->state_change);
4068 else
4069 vty_out (vty, " %d state changes%s", nbr_nbma->state_change, VTY_NEWLINE);
718e3744 4070
4071 /* Show PollInterval */
3ac237f8
MS
4072 if (use_json)
4073 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
4074 else
4075 vty_out (vty, " Poll interval %d%s", nbr_nbma->v_poll, VTY_NEWLINE);
718e3744 4076
4077 /* Show poll-interval timer. */
3ac237f8
MS
4078 if (use_json)
4079 {
cbf3e3eb
DL
4080 long time_store;
4081 time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL) / 1000LL;
3ac237f8
MS
4082 json_object_int_add(json_sub, "pollIntervalTimerDueMsec", time_store);
4083 }
4084 else
4085 vty_out (vty, " Poll timer due in %s%s",
4086 ospf_timer_dump (nbr_nbma->t_poll, timebuf, sizeof(timebuf)),
4087 VTY_NEWLINE);
718e3744 4088
4089 /* Show poll-interval timer thread. */
3ac237f8
MS
4090 if (use_json)
4091 {
4092 if (nbr_nbma->t_poll != NULL)
4093 json_object_string_add(json_sub, "pollIntervalTimerThread", "on");
4094 }
4095 else
4096 vty_out (vty, " Thread Poll Timer %s%s",
4097 nbr_nbma->t_poll != NULL ? "on" : "off", VTY_NEWLINE);
4098
4099 if (use_json)
4100 json_object_object_add(json, "noNbrId", json_sub);
718e3744 4101}
4102
4dadc291 4103static void
718e3744 4104show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi,
3ac237f8 4105 struct ospf_neighbor *nbr, u_char use_json, json_object *json)
718e3744 4106{
649654ab 4107 char timebuf[OSPF_TIME_DUMP_SIZE];
3ac237f8 4108 json_object *json_sub = NULL;
718e3744 4109
3ac237f8
MS
4110 if (use_json)
4111 json_sub = json_object_new_object();
718e3744 4112 else
3ac237f8
MS
4113 {
4114 /* Show neighbor ID. */
4115 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4116 vty_out (vty, " Neighbor %s,", "-");
4117 else
4118 vty_out (vty, " Neighbor %s,", inet_ntoa (nbr->router_id));
4119 }
718e3744 4120
4121 /* Show interface address. */
3ac237f8
MS
4122 if (use_json)
4123 json_object_string_add(json_sub, "ifaceAddress", inet_ntoa (nbr->address.u.prefix4));
4124 else
4125 vty_out (vty, " interface address %s%s",
4126 inet_ntoa (nbr->address.u.prefix4), VTY_NEWLINE);
4127
718e3744 4128 /* Show Area ID. */
3ac237f8
MS
4129 if (use_json)
4130 {
4131 json_object_string_add(json_sub, "areaId", ospf_area_desc_string (oi->area));
4132 json_object_string_add(json_sub, "ifaceName", oi->ifp->name);
4133 }
4134 else
4135 vty_out (vty, " In the area %s via interface %s%s",
4136 ospf_area_desc_string (oi->area), oi->ifp->name, VTY_NEWLINE);
4137
718e3744 4138 /* Show neighbor priority and state. */
3ac237f8
MS
4139 if (use_json)
4140 {
4141 json_object_int_add(json_sub, "nbrPriority", nbr->priority);
4142 json_object_string_add(json_sub, "nbrState", LOOKUP (ospf_nsm_state_msg, nbr->state));
4143 }
4144 else
4145 vty_out (vty, " Neighbor priority is %d, State is %s,",
4146 nbr->priority, LOOKUP (ospf_nsm_state_msg, nbr->state));
4147
718e3744 4148 /* Show state changes. */
3ac237f8
MS
4149 if (use_json)
4150 json_object_int_add(json_sub, "stateChangeCounter", nbr->state_change);
4151 else
4152 vty_out (vty, " %d state changes%s", nbr->state_change, VTY_NEWLINE);
4153
3fed4160 4154 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
90c33177 4155 {
cbf3e3eb
DL
4156 struct timeval res;
4157 long time_store;
4158
4159 time_store = monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
3ac237f8
MS
4160 if (use_json)
4161 {
3ac237f8
MS
4162 json_object_int_add(json_sub, "lastPrgrsvChangeMsec", time_store);
4163 }
4164 else
4165 {
4166 vty_out (vty, " Most recent state change statistics:%s",
4167 VTY_NEWLINE);
4168 vty_out (vty, " Progressive change %s ago%s",
4169 ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
4170 VTY_NEWLINE);
4171 }
3fed4160 4172 }
3ac237f8 4173
3fed4160
PJ
4174 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec)
4175 {
cbf3e3eb
DL
4176 struct timeval res;
4177 long time_store;
4178
4179 time_store = monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
3ac237f8
MS
4180 if (use_json)
4181 {
3ac237f8
MS
4182 json_object_int_add(json_sub, "lastRegressiveChangeMsec", time_store);
4183 if (nbr->last_regress_str)
4184 json_object_string_add(json_sub, "lastRegressiveChangeReason", nbr->last_regress_str);
4185 }
4186 else
4187 {
4188 vty_out (vty, " Regressive change %s ago, due to %s%s",
4189 ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
4190 (nbr->last_regress_str ? nbr->last_regress_str : "??"),
4191 VTY_NEWLINE);
4192 }
90c33177 4193 }
3ac237f8 4194
718e3744 4195 /* Show Designated Rotuer ID. */
3ac237f8
MS
4196 if (use_json)
4197 json_object_string_add(json_sub, "routerDesignatedId", inet_ntoa (nbr->d_router));
4198 else
4199 vty_out (vty, " DR is %s,", inet_ntoa (nbr->d_router));
4200
718e3744 4201 /* Show Backup Designated Rotuer ID. */
3ac237f8
MS
4202 if (use_json)
4203 json_object_string_add(json_sub, "routerDesignatedBackupId", inet_ntoa (nbr->bd_router));
4204 else
4205 vty_out (vty, " BDR is %s%s", inet_ntoa (nbr->bd_router), VTY_NEWLINE);
4206
718e3744 4207 /* Show options. */
3ac237f8
MS
4208 if (use_json)
4209 {
4210 json_object_int_add(json_sub, "optionsCounter", nbr->options);
4211 json_object_string_add(json_sub, "optionsList", ospf_options_dump (nbr->options));
4212 }
4213 else
4214 vty_out (vty, " Options %d %s%s", nbr->options,
4215 ospf_options_dump (nbr->options), VTY_NEWLINE);
4216
718e3744 4217 /* Show Router Dead interval timer. */
3ac237f8
MS
4218 if (use_json)
4219 {
45d430e8
DS
4220 if (nbr->t_inactivity)
4221 {
cbf3e3eb
DL
4222 long time_store;
4223 time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
45d430e8
DS
4224 json_object_int_add(json_sub, "routerDeadIntervalTimerDueMsec", time_store);
4225 }
4226 else
4227 json_object_int_add(json_sub, "routerDeadIntervalTimerDueMsec", -1);
3ac237f8
MS
4228 }
4229 else
4230 vty_out (vty, " Dead timer due in %s%s",
4231 ospf_timer_dump (nbr->t_inactivity, timebuf, sizeof (timebuf)),
4232 VTY_NEWLINE);
4233
718e3744 4234 /* Show Database Summary list. */
3ac237f8
MS
4235 if (use_json)
4236 json_object_int_add(json_sub, "databaseSummaryListCounter", ospf_db_summary_count (nbr));
4237 else
4238 vty_out (vty, " Database Summary List %d%s",
4239 ospf_db_summary_count (nbr), VTY_NEWLINE);
4240
718e3744 4241 /* Show Link State Request list. */
3ac237f8
MS
4242 if (use_json)
4243 json_object_int_add(json_sub, "linkStateRequestListCounter", ospf_ls_request_count (nbr));
4244 else
4245 vty_out (vty, " Link State Request List %ld%s",
4246 ospf_ls_request_count (nbr), VTY_NEWLINE);
4247
718e3744 4248 /* Show Link State Retransmission list. */
3ac237f8
MS
4249 if (use_json)
4250 json_object_int_add(json_sub, "linkStateRetransmissionListCounter", ospf_ls_retransmit_count (nbr));
4251 else
4252 vty_out (vty, " Link State Retransmission List %ld%s",
4253 ospf_ls_retransmit_count (nbr), VTY_NEWLINE);
4254
718e3744 4255 /* Show inactivity timer thread. */
3ac237f8
MS
4256 if (use_json)
4257 {
4258 if (nbr->t_inactivity != NULL)
4259 json_object_string_add(json_sub, "threadInactivityTimer", "on");
4260 }
4261 else
4262 vty_out (vty, " Thread Inactivity Timer %s%s",
4263 nbr->t_inactivity != NULL ? "on" : "off", VTY_NEWLINE);
4264
718e3744 4265 /* Show Database Description retransmission thread. */
3ac237f8
MS
4266 if (use_json)
4267 {
4268 if (nbr->t_db_desc != NULL)
4269 json_object_string_add(json_sub, "threadDatabaseDescriptionRetransmission", "on");
4270 }
4271 else
4272 vty_out (vty, " Thread Database Description Retransmision %s%s",
4273 nbr->t_db_desc != NULL ? "on" : "off", VTY_NEWLINE);
4274
718e3744 4275 /* Show Link State Request Retransmission thread. */
3ac237f8
MS
4276 if (use_json)
4277 {
4278 if (nbr->t_ls_req != NULL)
4279 json_object_string_add(json_sub, "threadLinkStateRequestRetransmission", "on");
4280 }
4281 else
4282 vty_out (vty, " Thread Link State Request Retransmission %s%s",
4283 nbr->t_ls_req != NULL ? "on" : "off", VTY_NEWLINE);
4284
718e3744 4285 /* Show Link State Update Retransmission thread. */
3ac237f8
MS
4286 if (use_json)
4287 {
4288 if (nbr->t_ls_upd != NULL)
4289 json_object_string_add(json_sub, "threadLinkStateUpdateRetransmission", "on");
4290 }
4291 else
4292 vty_out (vty, " Thread Link State Update Retransmission %s%s%s",
4293 nbr->t_ls_upd != NULL ? "on" : "off", VTY_NEWLINE, VTY_NEWLINE);
4294
4295 if (use_json)
4296 {
4297 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4298 json_object_object_add(json, "noNbrId", json_sub);
4299 else
4300 json_object_object_add(json, inet_ntoa (nbr->router_id), json_sub);
4301 }
68fe91d6 4302
4303 ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0);
718e3744 4304}
4305
7c8ff89e
DS
4306static int
4307show_ip_ospf_neighbor_id_common (struct vty *vty, struct ospf *ospf,
7a7be519 4308 int arg_base, struct cmd_token **argv, u_char use_json)
718e3744 4309{
52dc7ee6 4310 struct listnode *node;
718e3744 4311 struct ospf_neighbor *nbr;
1eb8ef25 4312 struct ospf_interface *oi;
718e3744 4313 struct in_addr router_id;
4314 int ret;
3ac237f8
MS
4315 json_object *json = NULL;
4316
4317 if (use_json)
4318 json = json_object_new_object();
718e3744 4319
7c8ff89e 4320 if (ospf->instance)
3ac237f8
MS
4321 {
4322 if (use_json)
4323 json_object_int_add(json, "ospfInstance", ospf->instance);
4324 else
4325 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4326 VTY_NEWLINE, VTY_NEWLINE);
4327 }
7c8ff89e 4328
7a7be519 4329 ret = inet_aton (argv[arg_base]->arg, &router_id);
718e3744 4330 if (!ret)
4331 {
3ac237f8
MS
4332 if (!use_json)
4333 vty_out (vty, "Please specify Neighbor ID by A.B.C.D%s", VTY_NEWLINE);
718e3744 4334 return CMD_WARNING;
4335 }
4336
1eb8ef25 4337 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
3ac237f8
MS
4338 {
4339 if ((nbr = ospf_nbr_lookup_by_routerid (oi->nbrs, &router_id)))
4340 {
4341 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4342 }
4343 }
4344
4345 if (use_json)
4346 {
2aac5767 4347 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4348 json_object_free(json);
4349 }
4350 else
4351 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4352
718e3744 4353 return CMD_SUCCESS;
4354}
4355
7c8ff89e
DS
4356DEFUN (show_ip_ospf_neighbor_id,
4357 show_ip_ospf_neighbor_id_cmd,
b162fa78 4358 "show ip ospf neighbor A.B.C.D [json]",
718e3744 4359 SHOW_STR
4360 IP_STR
4361 "OSPF information\n"
4362 "Neighbor list\n"
3ac237f8 4363 "Neighbor ID\n"
9973d184 4364 JSON_STR)
718e3744 4365{
020709f9 4366 struct ospf *ospf;
db7c8528 4367 u_char uj = use_json(argc, argv);
7c8ff89e 4368
0bad4851 4369 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4370 return CMD_SUCCESS;
4371
db7c8528 4372 return show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
4373}
4374
4375DEFUN (show_ip_ospf_instance_neighbor_id,
4376 show_ip_ospf_instance_neighbor_id_cmd,
6147e2c6 4377 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
7c8ff89e
DS
4378 SHOW_STR
4379 IP_STR
4380 "OSPF information\n"
4381 "Instance ID\n"
4382 "Neighbor list\n"
3ac237f8 4383 "Neighbor ID\n"
9973d184 4384 JSON_STR)
7c8ff89e 4385{
8d769265 4386 int idx_number = 3;
7c8ff89e
DS
4387 struct ospf *ospf;
4388 u_short instance = 0;
db7c8528 4389 u_char uj = use_json(argc, argv);
7c8ff89e 4390
8d769265 4391 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4392 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4393 return CMD_SUCCESS;
4394
db7c8528 4395 return show_ip_ospf_neighbor_id_common(vty, ospf, 1, argv, uj);
7c8ff89e
DS
4396}
4397
4398static int
3ac237f8 4399show_ip_ospf_neighbor_detail_common (struct vty *vty, struct ospf *ospf, u_char use_json)
7c8ff89e 4400{
1eb8ef25 4401 struct ospf_interface *oi;
52dc7ee6 4402 struct listnode *node;
3ac237f8
MS
4403 json_object *json = NULL;
4404
4405 if (use_json)
4406 json = json_object_new_object();
718e3744 4407
7c8ff89e 4408 if (ospf->instance)
3ac237f8
MS
4409 {
4410 if (use_json)
4411 json_object_int_add(json, "ospfInstance", ospf->instance);
4412 else
4413 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4414 VTY_NEWLINE, VTY_NEWLINE);
4415 }
718e3744 4416
1eb8ef25 4417 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
718e3744 4418 {
718e3744 4419 struct route_node *rn;
4420 struct ospf_neighbor *nbr;
4421
4422 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
3ac237f8
MS
4423 {
4424 if ((nbr = rn->info))
4425 {
4426 if (nbr != oi->nbr_self)
4427 {
4428 if (nbr->state != NSM_Down)
4429 {
4430 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4431 }
4432 }
4433 }
4434 }
718e3744 4435 }
4436
3ac237f8
MS
4437 if (use_json)
4438 {
2aac5767 4439 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4440 json_object_free(json);
4441 }
4442 else
4443 vty_out (vty, "%s", VTY_NEWLINE);
4444
718e3744 4445 return CMD_SUCCESS;
4446}
4447
7c8ff89e
DS
4448DEFUN (show_ip_ospf_neighbor_detail,
4449 show_ip_ospf_neighbor_detail_cmd,
b162fa78 4450 "show ip ospf neighbor detail [json]",
718e3744 4451 SHOW_STR
4452 IP_STR
4453 "OSPF information\n"
4454 "Neighbor list\n"
3ac237f8 4455 "detail of all neighbors\n"
9973d184 4456 JSON_STR)
718e3744 4457{
020709f9 4458 struct ospf *ospf;
db7c8528 4459 u_char uj = use_json(argc, argv);
7c8ff89e 4460
0bad4851 4461 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4462 return CMD_SUCCESS;
4463
db7c8528 4464 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
7c8ff89e
DS
4465}
4466
4467DEFUN (show_ip_ospf_instance_neighbor_detail,
4468 show_ip_ospf_instance_neighbor_detail_cmd,
6147e2c6 4469 "show ip ospf (1-65535) neighbor detail [json]",
7c8ff89e
DS
4470 SHOW_STR
4471 IP_STR
4472 "OSPF information\n"
4473 "Instance ID\n"
4474 "Neighbor list\n"
3ac237f8 4475 "detail of all neighbors\n"
9973d184 4476 JSON_STR)
7c8ff89e 4477{
8d769265 4478 int idx_number = 3;
7c8ff89e
DS
4479 struct ospf *ospf;
4480 u_short instance = 0;
db7c8528 4481 u_char uj = use_json(argc, argv);
7c8ff89e 4482
8d769265 4483 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4484 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4485 return CMD_SUCCESS;
4486
db7c8528 4487 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
7c8ff89e
DS
4488}
4489
4490static int
3ac237f8 4491show_ip_ospf_neighbor_detail_all_common (struct vty *vty, struct ospf *ospf, u_char use_json)
7c8ff89e 4492{
52dc7ee6 4493 struct listnode *node;
1eb8ef25 4494 struct ospf_interface *oi;
3ac237f8
MS
4495 json_object *json = NULL;
4496
4497 if (use_json)
4498 json = json_object_new_object();
718e3744 4499
7c8ff89e 4500 if (ospf->instance)
3ac237f8
MS
4501 {
4502 if (use_json)
4503 json_object_int_add(json, "ospfInstance", ospf->instance);
4504 else
4505 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4506 VTY_NEWLINE, VTY_NEWLINE);
4507 }
718e3744 4508
1eb8ef25 4509 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
718e3744 4510 {
718e3744 4511 struct route_node *rn;
4512 struct ospf_neighbor *nbr;
1eb8ef25 4513 struct ospf_nbr_nbma *nbr_nbma;
718e3744 4514
4515 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
4516 if ((nbr = rn->info))
4517 if (nbr != oi->nbr_self)
a452df33 4518 if (nbr->state != NSM_Down)
3ac237f8 4519 show_ip_ospf_neighbor_detail_sub (vty, oi, rn->info, use_json, json);
718e3744 4520
4521 if (oi->type == OSPF_IFTYPE_NBMA)
3ac237f8
MS
4522 {
4523 struct listnode *nd;
718e3744 4524
3ac237f8
MS
4525 for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nd, nbr_nbma))
4526 {
4527 if (nbr_nbma->nbr == NULL || nbr_nbma->nbr->state == NSM_Down)
4528 show_ip_ospf_nbr_nbma_detail_sub (vty, oi, nbr_nbma, use_json, json);
4529 }
4530 }
4531 }
4532
4533 if (use_json)
4534 {
2aac5767 4535 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4536 json_object_free(json);
4537 }
4538 else
4539 {
4540 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4541 }
4542
4543 return CMD_SUCCESS;
4544}
4545
7c8ff89e
DS
4546DEFUN (show_ip_ospf_neighbor_detail_all,
4547 show_ip_ospf_neighbor_detail_all_cmd,
b162fa78 4548 "show ip ospf neighbor detail all [json]",
718e3744 4549 SHOW_STR
4550 IP_STR
4551 "OSPF information\n"
4552 "Neighbor list\n"
7c8ff89e 4553 "detail of all neighbors\n"
3ac237f8 4554 "include down status neighbor\n"
9973d184 4555 JSON_STR)
718e3744 4556{
020709f9 4557 struct ospf *ospf;
db7c8528 4558 u_char uj = use_json(argc, argv);
7c8ff89e 4559
0bad4851 4560 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4561 return CMD_SUCCESS;
4562
db7c8528 4563 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
7c8ff89e
DS
4564}
4565
4566DEFUN (show_ip_ospf_instance_neighbor_detail_all,
4567 show_ip_ospf_instance_neighbor_detail_all_cmd,
6147e2c6 4568 "show ip ospf (1-65535) neighbor detail all [json]",
7c8ff89e
DS
4569 SHOW_STR
4570 IP_STR
4571 "OSPF information\n"
4572 "Instance ID\n"
4573 "Neighbor list\n"
4574 "detail of all neighbors\n"
3ac237f8 4575 "include down status neighbor\n"
9973d184 4576 JSON_STR)
7c8ff89e 4577{
8d769265 4578 int idx_number = 3;
7c8ff89e
DS
4579 struct ospf *ospf;
4580 u_short instance = 0;
db7c8528 4581 u_char uj = use_json(argc, argv);
7c8ff89e 4582
8d769265 4583 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4584 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4585 return CMD_SUCCESS;
4586
db7c8528 4587 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
7c8ff89e
DS
4588}
4589
4590static int
4591show_ip_ospf_neighbor_int_detail_common (struct vty *vty, struct ospf *ospf,
7a7be519 4592 int arg_base, struct cmd_token **argv, u_char use_json)
7c8ff89e 4593{
718e3744 4594 struct ospf_interface *oi;
bb5b7552 4595 struct interface *ifp;
4596 struct route_node *rn, *nrn;
4597 struct ospf_neighbor *nbr;
3ac237f8
MS
4598 json_object *json = NULL;
4599
4600 if (use_json)
4601 json = json_object_new_object();
bb5b7552 4602
7c8ff89e 4603 if (ospf->instance)
3ac237f8
MS
4604 {
4605 if (use_json)
4606 json_object_int_add(json, "ospfInstance", ospf->instance);
4607 else
4608 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4609 VTY_NEWLINE, VTY_NEWLINE);
4610 }
7c8ff89e 4611
1306c09a 4612 ifp = if_lookup_by_name (argv[arg_base]->arg, VRF_DEFAULT);
bb5b7552 4613 if (!ifp)
718e3744 4614 {
3ac237f8
MS
4615 if (!use_json)
4616 vty_out (vty, "No such interface.%s", VTY_NEWLINE);
718e3744 4617 return CMD_WARNING;
4618 }
4619
bb5b7552 4620 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
3ac237f8
MS
4621 {
4622 if ((oi = rn->info))
4623 {
4624 for (nrn = route_top (oi->nbrs); nrn; nrn = route_next (nrn))
4625 {
4626 if ((nbr = nrn->info))
4627 {
4628 if (nbr != oi->nbr_self)
4629 {
4630 if (nbr->state != NSM_Down)
4631 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4632 }
4633 }
4634 }
4635 }
4636 }
4637
4638 if (use_json)
4639 {
2aac5767 4640 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3ac237f8
MS
4641 json_object_free(json);
4642 }
4643 else
4644 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4645
4646 return CMD_SUCCESS;
4647}
4648
7c8ff89e
DS
4649DEFUN (show_ip_ospf_neighbor_int_detail,
4650 show_ip_ospf_neighbor_int_detail_cmd,
b162fa78 4651 "show ip ospf neighbor IFNAME detail [json]",
7c8ff89e
DS
4652 SHOW_STR
4653 IP_STR
4654 "OSPF information\n"
4655 "Neighbor list\n"
4656 "Interface name\n"
3ac237f8 4657 "detail of all neighbors\n"
9973d184 4658 JSON_STR)
7c8ff89e
DS
4659{
4660 struct ospf *ospf;
db7c8528 4661 u_char uj = use_json(argc, argv);
7c8ff89e 4662
0bad4851 4663 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
4664 return CMD_SUCCESS;
4665
db7c8528 4666 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
4667}
4668
4669DEFUN (show_ip_ospf_instance_neighbor_int_detail,
4670 show_ip_ospf_instance_neighbor_int_detail_cmd,
6147e2c6 4671 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
7c8ff89e
DS
4672 SHOW_STR
4673 IP_STR
4674 "OSPF information\n"
4675 "Instance ID\n"
4676 "Neighbor list\n"
4677 "Interface name\n"
3ac237f8 4678 "detail of all neighbors\n"
9973d184 4679 JSON_STR)
7c8ff89e 4680{
8d769265 4681 int idx_number = 3;
7c8ff89e
DS
4682 struct ospf *ospf;
4683 u_short instance = 0;
db7c8528 4684 u_char uj = use_json(argc, argv);
7c8ff89e 4685
8d769265 4686 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 4687 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
4688 return CMD_SUCCESS;
4689
db7c8528 4690 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 1, argv, uj);
7c8ff89e 4691}
6b0655a2 4692
718e3744 4693/* Show functions */
4dadc291 4694static int
020709f9 4695show_lsa_summary (struct vty *vty, struct ospf_lsa *lsa, int self)
718e3744 4696{
718e3744 4697 struct router_lsa *rl;
4698 struct summary_lsa *sl;
4699 struct as_external_lsa *asel;
4700 struct prefix_ipv4 p;
4701
4702 if (lsa != NULL)
4703 /* If self option is set, check LSA self flag. */
4704 if (self == 0 || IS_LSA_SELF (lsa))
4705 {
4706 /* LSA common part show. */
4707 vty_out (vty, "%-15s ", inet_ntoa (lsa->data->id));
4708 vty_out (vty, "%-15s %4d 0x%08lx 0x%04x",
4709 inet_ntoa (lsa->data->adv_router), LS_AGE (lsa),
4710 (u_long)ntohl (lsa->data->ls_seqnum), ntohs (lsa->data->checksum));
4711 /* LSA specific part show. */
4712 switch (lsa->data->type)
4713 {
4714 case OSPF_ROUTER_LSA:
4715 rl = (struct router_lsa *) lsa->data;
4716 vty_out (vty, " %-d", ntohs (rl->links));
4717 break;
4718 case OSPF_SUMMARY_LSA:
4719 sl = (struct summary_lsa *) lsa->data;
4720
4721 p.family = AF_INET;
4722 p.prefix = sl->header.id;
4723 p.prefixlen = ip_masklen (sl->mask);
4724 apply_mask_ipv4 (&p);
4725
4726 vty_out (vty, " %s/%d", inet_ntoa (p.prefix), p.prefixlen);
4727 break;
4728 case OSPF_AS_EXTERNAL_LSA:
551a8979 4729 case OSPF_AS_NSSA_LSA:
718e3744 4730 asel = (struct as_external_lsa *) lsa->data;
4731
4732 p.family = AF_INET;
4733 p.prefix = asel->header.id;
4734 p.prefixlen = ip_masklen (asel->mask);
4735 apply_mask_ipv4 (&p);
4736
4737 vty_out (vty, " %s %s/%d [0x%lx]",
4738 IS_EXTERNAL_METRIC (asel->e[0].tos) ? "E2" : "E1",
4739 inet_ntoa (p.prefix), p.prefixlen,
4740 (u_long)ntohl (asel->e[0].route_tag));
4741 break;
4742 case OSPF_NETWORK_LSA:
4743 case OSPF_ASBR_SUMMARY_LSA:
718e3744 4744 case OSPF_OPAQUE_LINK_LSA:
4745 case OSPF_OPAQUE_AREA_LSA:
4746 case OSPF_OPAQUE_AS_LSA:
718e3744 4747 default:
4748 break;
4749 }
4750 vty_out (vty, VTY_NEWLINE);
4751 }
4752
4753 return 0;
4754}
4755
8b6a15b2 4756static const char *show_database_desc[] =
718e3744 4757{
4758 "unknown",
4759 "Router Link States",
4760 "Net Link States",
4761 "Summary Link States",
4762 "ASBR-Summary Link States",
4763 "AS External Link States",
718e3744 4764 "Group Membership LSA",
4765 "NSSA-external Link States",
718e3744 4766 "Type-8 LSA",
4767 "Link-Local Opaque-LSA",
4768 "Area-Local Opaque-LSA",
4769 "AS-external Opaque-LSA",
718e3744 4770};
4771
8b6a15b2 4772static const char *show_database_header[] =
718e3744 4773{
4774 "",
4775 "Link ID ADV Router Age Seq# CkSum Link count",
4776 "Link ID ADV Router Age Seq# CkSum",
4777 "Link ID ADV Router Age Seq# CkSum Route",
4778 "Link ID ADV Router Age Seq# CkSum",
4779 "Link ID ADV Router Age Seq# CkSum Route",
718e3744 4780 " --- header for Group Member ----",
4781 "Link ID ADV Router Age Seq# CkSum Route",
718e3744 4782 " --- type-8 ---",
4783 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4784 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4785 "Opaque-Type/Id ADV Router Age Seq# CkSum",
718e3744 4786};
4787
4dadc291 4788static void
718e3744 4789show_ip_ospf_database_header (struct vty *vty, struct ospf_lsa *lsa)
4790{
4791 struct router_lsa *rlsa = (struct router_lsa*) lsa->data;
4957f494 4792
718e3744 4793 vty_out (vty, " LS age: %d%s", LS_AGE (lsa), VTY_NEWLINE);
4957f494 4794 vty_out (vty, " Options: 0x%-2x : %s%s",
4795 lsa->data->options,
4796 ospf_options_dump(lsa->data->options),
4797 VTY_NEWLINE);
4798 vty_out (vty, " LS Flags: 0x%-2x %s%s",
9d526037 4799 lsa->flags,
4957f494 4800 ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" : ""),
4801 VTY_NEWLINE);
718e3744 4802
4803 if (lsa->data->type == OSPF_ROUTER_LSA)
4804 {
4805 vty_out (vty, " Flags: 0x%x" , rlsa->flags);
4806
4807 if (rlsa->flags)
4808 vty_out (vty, " :%s%s%s%s",
4809 IS_ROUTER_LSA_BORDER (rlsa) ? " ABR" : "",
4810 IS_ROUTER_LSA_EXTERNAL (rlsa) ? " ASBR" : "",
4811 IS_ROUTER_LSA_VIRTUAL (rlsa) ? " VL-endpoint" : "",
4812 IS_ROUTER_LSA_SHORTCUT (rlsa) ? " Shortcut" : "");
4813
4814 vty_out (vty, "%s", VTY_NEWLINE);
4815 }
4816 vty_out (vty, " LS Type: %s%s",
4817 LOOKUP (ospf_lsa_type_msg, lsa->data->type), VTY_NEWLINE);
4818 vty_out (vty, " Link State ID: %s %s%s", inet_ntoa (lsa->data->id),
4819 LOOKUP (ospf_link_state_id_type_msg, lsa->data->type), VTY_NEWLINE);
4820 vty_out (vty, " Advertising Router: %s%s",
4821 inet_ntoa (lsa->data->adv_router), VTY_NEWLINE);
4822 vty_out (vty, " LS Seq Number: %08lx%s", (u_long)ntohl (lsa->data->ls_seqnum),
4823 VTY_NEWLINE);
4824 vty_out (vty, " Checksum: 0x%04x%s", ntohs (lsa->data->checksum),
4825 VTY_NEWLINE);
4826 vty_out (vty, " Length: %d%s", ntohs (lsa->data->length), VTY_NEWLINE);
4827}
4828
eb1ce605 4829const char *link_type_desc[] =
718e3744 4830{
4831 "(null)",
4832 "another Router (point-to-point)",
4833 "a Transit Network",
4834 "Stub Network",
4835 "a Virtual Link",
4836};
4837
eb1ce605 4838const char *link_id_desc[] =
718e3744 4839{
4840 "(null)",
4841 "Neighboring Router ID",
4842 "Designated Router address",
68980084 4843 "Net",
718e3744 4844 "Neighboring Router ID",
4845};
4846
eb1ce605 4847const char *link_data_desc[] =
718e3744 4848{
4849 "(null)",
4850 "Router Interface address",
4851 "Router Interface address",
4852 "Network Mask",
4853 "Router Interface address",
4854};
4855
4856/* Show router-LSA each Link information. */
4dadc291 4857static void
718e3744 4858show_ip_ospf_database_router_links (struct vty *vty,
4859 struct router_lsa *rl)
4860{
b07c4cb3
DS
4861 int len, type;
4862 unsigned int i;
718e3744 4863
4864 len = ntohs (rl->header.length) - 4;
4865 for (i = 0; i < ntohs (rl->links) && len > 0; len -= 12, i++)
4866 {
4867 type = rl->link[i].type;
4868
4869 vty_out (vty, " Link connected to: %s%s",
4870 link_type_desc[type], VTY_NEWLINE);
4871 vty_out (vty, " (Link ID) %s: %s%s", link_id_desc[type],
4872 inet_ntoa (rl->link[i].link_id), VTY_NEWLINE);
4873 vty_out (vty, " (Link Data) %s: %s%s", link_data_desc[type],
4874 inet_ntoa (rl->link[i].link_data), VTY_NEWLINE);
4875 vty_out (vty, " Number of TOS metrics: 0%s", VTY_NEWLINE);
4876 vty_out (vty, " TOS 0 Metric: %d%s",
4877 ntohs (rl->link[i].metric), VTY_NEWLINE);
4878 vty_out (vty, "%s", VTY_NEWLINE);
4879 }
4880}
4881
4882/* Show router-LSA detail information. */
4dadc291 4883static int
718e3744 4884show_router_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4885{
4886 if (lsa != NULL)
4887 {
4888 struct router_lsa *rl = (struct router_lsa *) lsa->data;
4889
4890 show_ip_ospf_database_header (vty, lsa);
4891
4892 vty_out (vty, " Number of Links: %d%s%s", ntohs (rl->links),
4893 VTY_NEWLINE, VTY_NEWLINE);
4894
4895 show_ip_ospf_database_router_links (vty, rl);
b0a053be 4896 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4897 }
4898
4899 return 0;
4900}
4901
4902/* Show network-LSA detail information. */
4dadc291 4903static int
718e3744 4904show_network_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4905{
4906 int length, i;
4907
4908 if (lsa != NULL)
4909 {
4910 struct network_lsa *nl = (struct network_lsa *) lsa->data;
4911
4912 show_ip_ospf_database_header (vty, lsa);
4913
4914 vty_out (vty, " Network Mask: /%d%s",
4915 ip_masklen (nl->mask), VTY_NEWLINE);
4916
4917 length = ntohs (lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4;
4918
4919 for (i = 0; length > 0; i++, length -= 4)
4920 vty_out (vty, " Attached Router: %s%s",
4921 inet_ntoa (nl->routers[i]), VTY_NEWLINE);
4922
4923 vty_out (vty, "%s", VTY_NEWLINE);
4924 }
4925
4926 return 0;
4927}
4928
4929/* Show summary-LSA detail information. */
4dadc291 4930static int
718e3744 4931show_summary_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4932{
4933 if (lsa != NULL)
4934 {
4935 struct summary_lsa *sl = (struct summary_lsa *) lsa->data;
4936
4937 show_ip_ospf_database_header (vty, lsa);
4938
4939 vty_out (vty, " Network Mask: /%d%s", ip_masklen (sl->mask),
4940 VTY_NEWLINE);
4941 vty_out (vty, " TOS: 0 Metric: %d%s", GET_METRIC (sl->metric),
4942 VTY_NEWLINE);
b0a053be 4943 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4944 }
4945
4946 return 0;
4947}
4948
4949/* Show summary-ASBR-LSA detail information. */
4dadc291 4950static int
718e3744 4951show_summary_asbr_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4952{
4953 if (lsa != NULL)
4954 {
4955 struct summary_lsa *sl = (struct summary_lsa *) lsa->data;
4956
4957 show_ip_ospf_database_header (vty, lsa);
4958
4959 vty_out (vty, " Network Mask: /%d%s",
4960 ip_masklen (sl->mask), VTY_NEWLINE);
4961 vty_out (vty, " TOS: 0 Metric: %d%s", GET_METRIC (sl->metric),
4962 VTY_NEWLINE);
b0a053be 4963 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 4964 }
4965
4966 return 0;
4967}
4968
4969/* Show AS-external-LSA detail information. */
4dadc291 4970static int
718e3744 4971show_as_external_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4972{
4973 if (lsa != NULL)
4974 {
4975 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
4976
4977 show_ip_ospf_database_header (vty, lsa);
4978
4979 vty_out (vty, " Network Mask: /%d%s",
4980 ip_masklen (al->mask), VTY_NEWLINE);
4981 vty_out (vty, " Metric Type: %s%s",
4982 IS_EXTERNAL_METRIC (al->e[0].tos) ?
4983 "2 (Larger than any link state path)" : "1", VTY_NEWLINE);
4984 vty_out (vty, " TOS: 0%s", VTY_NEWLINE);
4985 vty_out (vty, " Metric: %d%s",
4986 GET_METRIC (al->e[0].metric), VTY_NEWLINE);
4987 vty_out (vty, " Forward Address: %s%s",
4988 inet_ntoa (al->e[0].fwd_addr), VTY_NEWLINE);
4989
dc9ffce8
CF
4990 vty_out (vty, " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
4991 (route_tag_t)ntohl (al->e[0].route_tag), VTY_NEWLINE, VTY_NEWLINE);
718e3744 4992 }
4993
4994 return 0;
4995}
075e12f5 4996#if 0
4dadc291 4997static int
718e3744 4998show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
4999{
5000 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
5001
5002 /* show_ip_ospf_database_header (vty, lsa); */
5003
2a42e285 5004 zlog_debug( " Network Mask: /%d%s",
718e3744 5005 ip_masklen (al->mask), "\n");
2a42e285 5006 zlog_debug( " Metric Type: %s%s",
718e3744 5007 IS_EXTERNAL_METRIC (al->e[0].tos) ?
5008 "2 (Larger than any link state path)" : "1", "\n");
2a42e285 5009 zlog_debug( " TOS: 0%s", "\n");
5010 zlog_debug( " Metric: %d%s",
718e3744 5011 GET_METRIC (al->e[0].metric), "\n");
2a42e285 5012 zlog_debug( " Forward Address: %s%s",
718e3744 5013 inet_ntoa (al->e[0].fwd_addr), "\n");
5014
dc9ffce8
CF
5015 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5016 (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n");
718e3744 5017
5018 return 0;
5019}
075e12f5 5020#endif
718e3744 5021/* Show AS-NSSA-LSA detail information. */
4dadc291 5022static int
718e3744 5023show_as_nssa_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
5024{
5025 if (lsa != NULL)
5026 {
5027 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
5028
5029 show_ip_ospf_database_header (vty, lsa);
5030
5031 vty_out (vty, " Network Mask: /%d%s",
5032 ip_masklen (al->mask), VTY_NEWLINE);
5033 vty_out (vty, " Metric Type: %s%s",
5034 IS_EXTERNAL_METRIC (al->e[0].tos) ?
5035 "2 (Larger than any link state path)" : "1", VTY_NEWLINE);
5036 vty_out (vty, " TOS: 0%s", VTY_NEWLINE);
5037 vty_out (vty, " Metric: %d%s",
5038 GET_METRIC (al->e[0].metric), VTY_NEWLINE);
5039 vty_out (vty, " NSSA: Forward Address: %s%s",
5040 inet_ntoa (al->e[0].fwd_addr), VTY_NEWLINE);
5041
dc9ffce8
CF
5042 vty_out (vty, " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5043 (route_tag_t)ntohl (al->e[0].route_tag), VTY_NEWLINE, VTY_NEWLINE);
718e3744 5044 }
5045
5046 return 0;
5047}
5048
4dadc291 5049static int
718e3744 5050show_func_dummy (struct vty *vty, struct ospf_lsa *lsa)
5051{
5052 return 0;
5053}
5054
4dadc291 5055static int
718e3744 5056show_opaque_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
5057{
5058 if (lsa != NULL)
5059 {
5060 show_ip_ospf_database_header (vty, lsa);
5061 show_opaque_info_detail (vty, lsa);
5062
5063 vty_out (vty, "%s", VTY_NEWLINE);
5064 }
5065 return 0;
5066}
718e3744 5067
5068int (*show_function[])(struct vty *, struct ospf_lsa *) =
5069{
5070 NULL,
5071 show_router_lsa_detail,
5072 show_network_lsa_detail,
5073 show_summary_lsa_detail,
5074 show_summary_asbr_lsa_detail,
5075 show_as_external_lsa_detail,
718e3744 5076 show_func_dummy,
5077 show_as_nssa_lsa_detail, /* almost same as external */
718e3744 5078 NULL, /* type-8 */
5079 show_opaque_lsa_detail,
5080 show_opaque_lsa_detail,
5081 show_opaque_lsa_detail,
718e3744 5082};
5083
4dadc291 5084static void
718e3744 5085show_lsa_prefix_set (struct vty *vty, struct prefix_ls *lp, struct in_addr *id,
5086 struct in_addr *adv_router)
5087{
5088 memset (lp, 0, sizeof (struct prefix_ls));
5089 lp->family = 0;
5090 if (id == NULL)
5091 lp->prefixlen = 0;
5092 else if (adv_router == NULL)
5093 {
5094 lp->prefixlen = 32;
5095 lp->id = *id;
5096 }
5097 else
5098 {
5099 lp->prefixlen = 64;
5100 lp->id = *id;
5101 lp->adv_router = *adv_router;
5102 }
5103}
5104
4dadc291 5105static void
718e3744 5106show_lsa_detail_proc (struct vty *vty, struct route_table *rt,
5107 struct in_addr *id, struct in_addr *adv_router)
5108{
5109 struct prefix_ls lp;
5110 struct route_node *rn, *start;
5111 struct ospf_lsa *lsa;
5112
5113 show_lsa_prefix_set (vty, &lp, id, adv_router);
5114 start = route_node_get (rt, (struct prefix *) &lp);
5115 if (start)
5116 {
5117 route_lock_node (start);
5118 for (rn = start; rn; rn = route_next_until (rn, start))
5119 if ((lsa = rn->info))
5120 {
718e3744 5121 if (show_function[lsa->data->type] != NULL)
5122 show_function[lsa->data->type] (vty, lsa);
5123 }
5124 route_unlock_node (start);
5125 }
5126}
5127
5128/* Show detail LSA information
5129 -- if id is NULL then show all LSAs. */
4dadc291 5130static void
020709f9 5131show_lsa_detail (struct vty *vty, struct ospf *ospf, int type,
718e3744 5132 struct in_addr *id, struct in_addr *adv_router)
5133{
52dc7ee6 5134 struct listnode *node;
1eb8ef25 5135 struct ospf_area *area;
5136
718e3744 5137 switch (type)
5138 {
5139 case OSPF_AS_EXTERNAL_LSA:
718e3744 5140 case OSPF_OPAQUE_AS_LSA:
718e3744 5141 vty_out (vty, " %s %s%s",
5142 show_database_desc[type],
5143 VTY_NEWLINE, VTY_NEWLINE);
68980084 5144 show_lsa_detail_proc (vty, AS_LSDB (ospf, type), id, adv_router);
718e3744 5145 break;
5146 default:
1eb8ef25 5147 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 5148 {
718e3744 5149 vty_out (vty, "%s %s (Area %s)%s%s",
5150 VTY_NEWLINE, show_database_desc[type],
5151 ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE);
5152 show_lsa_detail_proc (vty, AREA_LSDB (area, type), id, adv_router);
5153 }
5154 break;
5155 }
5156}
5157
4dadc291 5158static void
718e3744 5159show_lsa_detail_adv_router_proc (struct vty *vty, struct route_table *rt,
5160 struct in_addr *adv_router)
5161{
5162 struct route_node *rn;
5163 struct ospf_lsa *lsa;
5164
5165 for (rn = route_top (rt); rn; rn = route_next (rn))
5166 if ((lsa = rn->info))
5167 if (IPV4_ADDR_SAME (adv_router, &lsa->data->adv_router))
5168 {
718e3744 5169 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
5170 continue;
718e3744 5171 if (show_function[lsa->data->type] != NULL)
5172 show_function[lsa->data->type] (vty, lsa);
5173 }
5174}
5175
5176/* Show detail LSA information. */
4dadc291 5177static void
020709f9 5178show_lsa_detail_adv_router (struct vty *vty, struct ospf *ospf, int type,
718e3744 5179 struct in_addr *adv_router)
5180{
52dc7ee6 5181 struct listnode *node;
1eb8ef25 5182 struct ospf_area *area;
718e3744 5183
5184 switch (type)
5185 {
5186 case OSPF_AS_EXTERNAL_LSA:
718e3744 5187 case OSPF_OPAQUE_AS_LSA:
718e3744 5188 vty_out (vty, " %s %s%s",
5189 show_database_desc[type],
5190 VTY_NEWLINE, VTY_NEWLINE);
68980084 5191 show_lsa_detail_adv_router_proc (vty, AS_LSDB (ospf, type),
718e3744 5192 adv_router);
5193 break;
5194 default:
1eb8ef25 5195 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 5196 {
718e3744 5197 vty_out (vty, "%s %s (Area %s)%s%s",
5198 VTY_NEWLINE, show_database_desc[type],
5199 ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE);
5200 show_lsa_detail_adv_router_proc (vty, AREA_LSDB (area, type),
5201 adv_router);
5202 }
5203 break;
5204 }
5205}
5206
4dadc291 5207static void
020709f9 5208show_ip_ospf_database_summary (struct vty *vty, struct ospf *ospf, int self)
718e3744 5209{
020709f9 5210 struct ospf_lsa *lsa;
5211 struct route_node *rn;
1eb8ef25 5212 struct ospf_area *area;
52dc7ee6 5213 struct listnode *node;
718e3744 5214 int type;
5215
1eb8ef25 5216 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 5217 {
718e3744 5218 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++)
5219 {
5220 switch (type)
5221 {
5222 case OSPF_AS_EXTERNAL_LSA:
718e3744 5223 case OSPF_OPAQUE_AS_LSA:
718e3744 5224 continue;
5225 default:
5226 break;
5227 }
5228 if (ospf_lsdb_count_self (area->lsdb, type) > 0 ||
5229 (!self && ospf_lsdb_count (area->lsdb, type) > 0))
5230 {
5231 vty_out (vty, " %s (Area %s)%s%s",
5232 show_database_desc[type],
5233 ospf_area_desc_string (area),
5234 VTY_NEWLINE, VTY_NEWLINE);
5235 vty_out (vty, "%s%s", show_database_header[type], VTY_NEWLINE);
5236
020709f9 5237 LSDB_LOOP (AREA_LSDB (area, type), rn, lsa)
5238 show_lsa_summary (vty, lsa, self);
718e3744 5239
5240 vty_out (vty, "%s", VTY_NEWLINE);
5241 }
5242 }
5243 }
5244
5245 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++)
5246 {
5247 switch (type)
5248 {
5249 case OSPF_AS_EXTERNAL_LSA:
718e3744 5250 case OSPF_OPAQUE_AS_LSA:
e8e1946e 5251 break;
718e3744 5252 default:
5253 continue;
5254 }
68980084 5255 if (ospf_lsdb_count_self (ospf->lsdb, type) ||
5256 (!self && ospf_lsdb_count (ospf->lsdb, type)))
718e3744 5257 {
5258 vty_out (vty, " %s%s%s",
5259 show_database_desc[type],
5260 VTY_NEWLINE, VTY_NEWLINE);
5261 vty_out (vty, "%s%s", show_database_header[type],
5262 VTY_NEWLINE);
020709f9 5263
5264 LSDB_LOOP (AS_LSDB (ospf, type), rn, lsa)
5265 show_lsa_summary (vty, lsa, self);
5266
718e3744 5267 vty_out (vty, "%s", VTY_NEWLINE);
5268 }
5269 }
5270
5271 vty_out (vty, "%s", VTY_NEWLINE);
5272}
5273
4dadc291 5274static void
020709f9 5275show_ip_ospf_database_maxage (struct vty *vty, struct ospf *ospf)
718e3744 5276{
91e6a0e5 5277 struct route_node *rn;
718e3744 5278
5279 vty_out (vty, "%s MaxAge Link States:%s%s",
5280 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
5281
91e6a0e5 5282 for (rn = route_top (ospf->maxage_lsa); rn; rn = route_next (rn))
1eb8ef25 5283 {
91e6a0e5
DD
5284 struct ospf_lsa *lsa;
5285
5286 if ((lsa = rn->info) != NULL)
5287 {
5288 vty_out (vty, "Link type: %d%s", lsa->data->type, VTY_NEWLINE);
5289 vty_out (vty, "Link State ID: %s%s",
5290 inet_ntoa (lsa->data->id), VTY_NEWLINE);
5291 vty_out (vty, "Advertising Router: %s%s",
5292 inet_ntoa (lsa->data->adv_router), VTY_NEWLINE);
5293 vty_out (vty, "LSA lock count: %d%s", lsa->lock, VTY_NEWLINE);
5294 vty_out (vty, "%s", VTY_NEWLINE);
5295 }
1eb8ef25 5296 }
718e3744 5297}
5298
718e3744 5299#define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
5300#define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
718e3744 5301
718e3744 5302#define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
5303#define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
5304#define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
5305#define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
718e3744 5306
718e3744 5307#define OSPF_LSA_TYPES_DESC \
5308 "ASBR summary link states\n" \
5309 "External link states\n" \
5310 "Network link states\n" \
5311 "Router link states\n" \
5312 "Network summary link states\n" \
5313 OSPF_LSA_TYPE_NSSA_DESC \
5314 OSPF_LSA_TYPE_OPAQUE_LINK_DESC \
5315 OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
5316 OSPF_LSA_TYPE_OPAQUE_AS_DESC
5317
7c8ff89e
DS
5318static int
5319show_ip_ospf_database_common (struct vty *vty, struct ospf *ospf,
7a7be519 5320 int arg_base, int argc, struct cmd_token **argv)
718e3744 5321{
7a7be519 5322 int idx_type = 4;
718e3744 5323 int type, ret;
5324 struct in_addr id, adv_router;
5325
7c8ff89e
DS
5326 if (ospf->instance)
5327 vty_out (vty, "%sOSPF Instance: %d%s", VTY_NEWLINE, ospf->instance,
5328 VTY_NEWLINE);
718e3744 5329
5330 vty_out (vty, "%s OSPF Router with ID (%s)%s%s", VTY_NEWLINE,
68980084 5331 inet_ntoa (ospf->router_id), VTY_NEWLINE, VTY_NEWLINE);
718e3744 5332
5333 /* Show all LSA. */
7a7be519 5334 if (argc == arg_base + 4)
718e3744 5335 {
020709f9 5336 show_ip_ospf_database_summary (vty, ospf, 0);
718e3744 5337 return CMD_SUCCESS;
5338 }
5339
5340 /* Set database type to show. */
7a7be519 5341 if (strncmp (argv[arg_base + idx_type]->text, "r", 1) == 0)
718e3744 5342 type = OSPF_ROUTER_LSA;
7a7be519 5343 else if (strncmp (argv[arg_base + idx_type]->text, "ne", 2) == 0)
718e3744 5344 type = OSPF_NETWORK_LSA;
7a7be519 5345 else if (strncmp (argv[arg_base + idx_type]->text, "ns", 2) == 0)
718e3744 5346 type = OSPF_AS_NSSA_LSA;
7a7be519 5347 else if (strncmp (argv[arg_base + idx_type]->text, "su", 2) == 0)
718e3744 5348 type = OSPF_SUMMARY_LSA;
7a7be519 5349 else if (strncmp (argv[arg_base + idx_type]->text, "a", 1) == 0)
718e3744 5350 type = OSPF_ASBR_SUMMARY_LSA;
7a7be519 5351 else if (strncmp (argv[arg_base + idx_type]->text, "e", 1) == 0)
718e3744 5352 type = OSPF_AS_EXTERNAL_LSA;
7a7be519 5353 else if (strncmp (argv[arg_base + idx_type]->text, "se", 2) == 0)
718e3744 5354 {
020709f9 5355 show_ip_ospf_database_summary (vty, ospf, 1);
718e3744 5356 return CMD_SUCCESS;
5357 }
7a7be519 5358 else if (strncmp (argv[arg_base + idx_type]->text, "m", 1) == 0)
718e3744 5359 {
020709f9 5360 show_ip_ospf_database_maxage (vty, ospf);
718e3744 5361 return CMD_SUCCESS;
5362 }
7a7be519 5363 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
718e3744 5364 type = OSPF_OPAQUE_LINK_LSA;
7a7be519 5365 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
718e3744 5366 type = OSPF_OPAQUE_AREA_LSA;
7a7be519 5367 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
718e3744 5368 type = OSPF_OPAQUE_AS_LSA;
718e3744 5369 else
5370 return CMD_WARNING;
5371
5372 /* `show ip ospf database LSA'. */
7a7be519 5373 if (argc == arg_base + 5)
020709f9 5374 show_lsa_detail (vty, ospf, type, NULL, NULL);
7a7be519 5375 else if (argc >= arg_base + 6)
718e3744 5376 {
7a7be519 5377 ret = inet_aton (argv[arg_base + 5]->arg, &id);
718e3744 5378 if (!ret)
5379 return CMD_WARNING;
5380
5381 /* `show ip ospf database LSA ID'. */
7a7be519 5382 if (argc == arg_base + 6)
020709f9 5383 show_lsa_detail (vty, ospf, type, &id, NULL);
718e3744 5384 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7a7be519 5385 else if (argc == arg_base + 7)
718e3744 5386 {
7a7be519 5387 if (strncmp (argv[arg_base + 6]->text, "s", 1) == 0)
68980084 5388 adv_router = ospf->router_id;
718e3744 5389 else
5390 {
7a7be519 5391 ret = inet_aton (argv[arg_base + 7]->arg, &adv_router);
718e3744 5392 if (!ret)
5393 return CMD_WARNING;
5394 }
020709f9 5395 show_lsa_detail (vty, ospf, type, &id, &adv_router);
718e3744 5396 }
5397 }
5398
5399 return CMD_SUCCESS;
5400}
5401
7a7be519 5402DEFUN (show_ip_ospf_database_max,
5403 show_ip_ospf_database_max_cmd,
5404 "show ip ospf database <max-age|self-originate>",
5405 SHOW_STR
5406 IP_STR
5407 "OSPF information\n"
5408 "Database summary\n"
5409 "LSAs in MaxAge list\n"
5410 "Self-originated link states\n")
5411{
5412 struct ospf *ospf;
f412b39a 5413
7a7be519 5414 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
5415 return CMD_SUCCESS;
f412b39a 5416
7a7be519 5417 return (show_ip_ospf_database_common(vty, ospf, 0, argc, argv));
5418}
f412b39a 5419
f412b39a
DW
5420DEFUN (show_ip_ospf_instance_database,
5421 show_ip_ospf_instance_database_cmd,
3a2d747c 5422 "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 5423 SHOW_STR
5424 IP_STR
5425 "OSPF information\n"
7c8ff89e 5426 "Instance ID\n"
7a7be519 5427 "Database summary\n"
5428 OSPF_LSA_TYPES_DESC
5429 "Link State ID (as an IP address)\n"
5430 "Self-originated link states\n"
5431 "Advertising Router link states\n"
5432 "Advertising Router (as an IP address)\n")
7c8ff89e
DS
5433{
5434 struct ospf *ospf;
5435 u_short instance = 0;
5436
3a2d747c
QY
5437 int idx = 0;
5438 if (argv_find (argv, argc, "(1-65535)", &idx))
5439 {
5440 VTY_GET_INTEGER ("Instance", instance, argv[idx]->arg);
5441 ospf = ospf_lookup_instance (instance);
5442 }
5443 else {
5444 ospf = ospf_lookup();
5445 }
7c8ff89e 5446
3a2d747c 5447 if (!ospf || !ospf->oi_running)
7c8ff89e
DS
5448 return CMD_SUCCESS;
5449
3a2d747c 5450 return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, argc, argv));
7c8ff89e
DS
5451}
5452
7a7be519 5453DEFUN (show_ip_ospf_instance_database_max,
5454 show_ip_ospf_instance_database_max_cmd,
5455 "show ip ospf (1-65535) database <max-age|self-originate>",
5456 SHOW_STR
5457 IP_STR
5458 "OSPF information\n"
5459 "Instance ID\n"
5460 "Database summary\n"
5461 "LSAs in MaxAge list\n"
5462 "Self-originated link states\n")
5463{
5464 int idx_number = 3;
5465 struct ospf *ospf;
5466 u_short instance = 0;
7c8ff89e 5467
7a7be519 5468 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e 5469
7a7be519 5470 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
5471 return CMD_SUCCESS;
7c8ff89e 5472
7a7be519 5473 return (show_ip_ospf_database_common(vty, ospf, 1, argc, argv));
5474}
7c8ff89e
DS
5475
5476
5477static int
5478show_ip_ospf_database_type_adv_router_common (struct vty *vty, struct ospf *ospf,
7a7be519 5479 int arg_base, int argc, struct cmd_token **argv)
718e3744 5480{
7a7be519 5481 int idx_type = 4;
718e3744 5482 int type, ret;
5483 struct in_addr adv_router;
5484
7c8ff89e
DS
5485 if (ospf->instance)
5486 vty_out (vty, "%sOSPF Instance: %d%s", VTY_NEWLINE, ospf->instance,
5487 VTY_NEWLINE);
718e3744 5488
5489 vty_out (vty, "%s OSPF Router with ID (%s)%s%s", VTY_NEWLINE,
68980084 5490 inet_ntoa (ospf->router_id), VTY_NEWLINE, VTY_NEWLINE);
718e3744 5491
7a7be519 5492 if (argc != arg_base + 7)
718e3744 5493 return CMD_WARNING;
5494
5495 /* Set database type to show. */
7a7be519 5496 if (strncmp (argv[arg_base + idx_type]->text, "r", 1) == 0)
718e3744 5497 type = OSPF_ROUTER_LSA;
7a7be519 5498 else if (strncmp (argv[arg_base + idx_type]->text, "ne", 2) == 0)
718e3744 5499 type = OSPF_NETWORK_LSA;
7a7be519 5500 else if (strncmp (argv[arg_base + idx_type]->text, "ns", 2) == 0)
718e3744 5501 type = OSPF_AS_NSSA_LSA;
7a7be519 5502 else if (strncmp (argv[arg_base + idx_type]->text, "s", 1) == 0)
718e3744 5503 type = OSPF_SUMMARY_LSA;
7a7be519 5504 else if (strncmp (argv[arg_base + idx_type]->text, "a", 1) == 0)
718e3744 5505 type = OSPF_ASBR_SUMMARY_LSA;
7a7be519 5506 else if (strncmp (argv[arg_base + idx_type]->text, "e", 1) == 0)
718e3744 5507 type = OSPF_AS_EXTERNAL_LSA;
7a7be519 5508 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
718e3744 5509 type = OSPF_OPAQUE_LINK_LSA;
7a7be519 5510 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
718e3744 5511 type = OSPF_OPAQUE_AREA_LSA;
7a7be519 5512 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
718e3744 5513 type = OSPF_OPAQUE_AS_LSA;
718e3744 5514 else
5515 return CMD_WARNING;
5516
7c8ff89e 5517 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7a7be519 5518 if (strncmp (argv[arg_base + 5]->text, "s", 1) == 0)
7c8ff89e
DS
5519 adv_router = ospf->router_id;
5520 else
5521 {
7a7be519 5522 ret = inet_aton (argv[arg_base + 6]->arg, &adv_router);
7c8ff89e
DS
5523 if (!ret)
5524 return CMD_WARNING;
5525 }
5526
5527 show_lsa_detail_adv_router (vty, ospf, type, &adv_router);
5528
5529 return CMD_SUCCESS;
5530}
5531
5532DEFUN (show_ip_ospf_database_type_adv_router,
5533 show_ip_ospf_database_type_adv_router_cmd,
7a7be519 5534 "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
5535 SHOW_STR
5536 IP_STR
5537 "OSPF information\n"
5538 "Database summary\n"
5539 OSPF_LSA_TYPES_DESC
5540 "Advertising Router link states\n"
16cedbb0
QY
5541 "Advertising Router (as an IP address)\n"
5542 "Self-originated link states\n")
7c8ff89e
DS
5543{
5544 struct ospf *ospf;
5545
0bad4851 5546 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
7c8ff89e
DS
5547 return CMD_SUCCESS;
5548
5549 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 0, argc, argv));
5550}
5551
7c8ff89e
DS
5552DEFUN (show_ip_ospf_instance_database_type_adv_router,
5553 show_ip_ospf_instance_database_type_adv_router_cmd,
7a7be519 5554 "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
5555 SHOW_STR
5556 IP_STR
5557 "OSPF information\n"
5558 "Instance ID\n"
5559 "Database summary\n"
5560 OSPF_LSA_TYPES_DESC
5561 "Advertising Router link states\n"
3a2d747c
QY
5562 "Advertising Router (as an IP address)\n"
5563 "Self-originated link states\n")
7c8ff89e 5564{
8d769265 5565 int idx_number = 3;
7c8ff89e
DS
5566 struct ospf *ospf;
5567 u_short instance = 0;
5568
8d769265 5569 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
718e3744 5570
0bad4851 5571 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e 5572 return CMD_SUCCESS;
718e3744 5573
7c8ff89e 5574 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv));
718e3744 5575}
5576
718e3744 5577DEFUN (ip_ospf_authentication_args,
5578 ip_ospf_authentication_args_addr_cmd,
7a7be519 5579 "ip ospf authentication <null|message-digest> [A.B.C.D]",
718e3744 5580 "IP Information\n"
5581 "OSPF interface commands\n"
5582 "Enable authentication on this interface\n"
5583 "Use null authentication\n"
5584 "Use message-digest authentication\n"
7a7be519 5585 "Address of interface\n")
718e3744 5586{
cdc2d765 5587 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265
DW
5588 int idx_encryption = 3;
5589 int idx_ipv4 = 4;
718e3744 5590 struct in_addr addr;
5591 int ret;
5592 struct ospf_if_params *params;
5593
718e3744 5594 params = IF_DEF_PARAMS (ifp);
5595
7a7be519 5596 if (argc == 5)
718e3744 5597 {
8d769265 5598 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 5599 if (!ret)
5600 {
5601 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5602 VTY_NEWLINE);
5603 return CMD_WARNING;
5604 }
5605
5606 params = ospf_get_if_params (ifp, addr);
5607 ospf_if_update_params (ifp, addr);
5608 }
5609
5610 /* Handle null authentication */
8d769265 5611 if ( argv[idx_encryption]->arg[0] == 'n' )
718e3744 5612 {
5613 SET_IF_PARAM (params, auth_type);
5614 params->auth_type = OSPF_AUTH_NULL;
5615 return CMD_SUCCESS;
5616 }
5617
5618 /* Handle message-digest authentication */
8d769265 5619 if ( argv[idx_encryption]->arg[0] == 'm' )
718e3744 5620 {
5621 SET_IF_PARAM (params, auth_type);
5622 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5623 return CMD_SUCCESS;
5624 }
5625
5626 vty_out (vty, "You shouldn't get here!%s", VTY_NEWLINE);
5627 return CMD_WARNING;
5628}
5629
718e3744 5630DEFUN (ip_ospf_authentication,
5631 ip_ospf_authentication_addr_cmd,
7a7be519 5632 "ip ospf authentication [A.B.C.D]",
718e3744 5633 "IP Information\n"
5634 "OSPF interface commands\n"
5635 "Enable authentication on this interface\n"
5636 "Address of interface")
5637{
cdc2d765 5638 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 5639 int idx_ipv4 = 3;
718e3744 5640 struct in_addr addr;
5641 int ret;
5642 struct ospf_if_params *params;
5643
718e3744 5644 params = IF_DEF_PARAMS (ifp);
5645
7a7be519 5646 if (argc == 4)
718e3744 5647 {
8d769265 5648 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 5649 if (!ret)
5650 {
5651 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5652 VTY_NEWLINE);
5653 return CMD_WARNING;
5654 }
5655
5656 params = ospf_get_if_params (ifp, addr);
5657 ospf_if_update_params (ifp, addr);
5658 }
5659
5660 SET_IF_PARAM (params, auth_type);
5661 params->auth_type = OSPF_AUTH_SIMPLE;
5662
5663 return CMD_SUCCESS;
5664}
5665
b4a039bf
DS
5666DEFUN (no_ip_ospf_authentication_args,
5667 no_ip_ospf_authentication_args_addr_cmd,
7a7be519 5668 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
b4a039bf
DS
5669 NO_STR
5670 "IP Information\n"
5671 "OSPF interface commands\n"
5672 "Enable authentication on this interface\n"
5673 "Use null authentication\n"
5674 "Use message-digest authentication\n"
5675 "Address of interface")
5676{
cdc2d765 5677 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265
DW
5678 int idx_encryption = 4;
5679 int idx_ipv4 = 5;
b4a039bf
DS
5680 struct in_addr addr;
5681 int ret;
5682 struct ospf_if_params *params;
5683 struct route_node *rn;
5684 int auth_type;
5685
b4a039bf
DS
5686 params = IF_DEF_PARAMS (ifp);
5687
7a7be519 5688 if (argc == 6)
b4a039bf 5689 {
8d769265 5690 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
b4a039bf
DS
5691 if (!ret)
5692 {
5693 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5694 VTY_NEWLINE);
5695 return CMD_WARNING;
5696 }
5697
5698 params = ospf_lookup_if_params (ifp, addr);
5699 if (params == NULL)
5700 {
5701 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
5702 return CMD_WARNING;
5703 }
5704 params->auth_type = OSPF_AUTH_NOTSET;
5705 UNSET_IF_PARAM (params, auth_type);
5706 if (params != IF_DEF_PARAMS (ifp))
5707 {
5708 ospf_free_if_params (ifp, addr);
5709 ospf_if_update_params (ifp, addr);
5710 }
5711 }
5712 else
5713 {
8d769265 5714 if ( argv[idx_encryption]->arg[0] == 'n' )
b4a039bf
DS
5715 {
5716 auth_type = OSPF_AUTH_NULL;
5717 }
8d769265 5718 else if ( argv[idx_encryption]->arg[0] == 'm' )
b4a039bf
DS
5719 {
5720 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5721 }
5722 else
5723 {
5724 vty_out (vty, "Unexpected input encountered%s", VTY_NEWLINE);
5725 return CMD_WARNING;
5726 }
5727 /*
5728 * Here we have a case where the user has entered
5729 * 'no ip ospf authentication (null | message_digest )'
5730 * we need to find if we have any ip addresses underneath it that
5731 * correspond to the associated type.
5732 */
813d4307
DW
5733 if (params->auth_type == auth_type)
5734 {
5735 params->auth_type = OSPF_AUTH_NOTSET;
5736 UNSET_IF_PARAM (params, auth_type);
5737 }
5738
b4a039bf
DS
5739 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
5740 {
5741 if ((params = rn->info))
5742 {
5743 if (params->auth_type == auth_type)
5744 {
5745 params->auth_type = OSPF_AUTH_NOTSET;
5746 UNSET_IF_PARAM (params, auth_type);
5747 if (params != IF_DEF_PARAMS (ifp))
5748 {
5749 ospf_free_if_params (ifp, rn->p.u.prefix4);
5750 ospf_if_update_params(ifp, rn->p.u.prefix4);
5751 }
5752 }
5753 }
5754 }
5755 }
5756
5757 return CMD_SUCCESS;
5758}
5759
718e3744 5760DEFUN (no_ip_ospf_authentication,
5761 no_ip_ospf_authentication_addr_cmd,
7a7be519 5762 "no ip ospf authentication [A.B.C.D]",
718e3744 5763 NO_STR
5764 "IP Information\n"
5765 "OSPF interface commands\n"
5766 "Enable authentication on this interface\n"
5767 "Address of interface")
5768{
cdc2d765 5769 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 5770 int idx_ipv4 = 4;
718e3744 5771 struct in_addr addr;
5772 int ret;
5773 struct ospf_if_params *params;
b4a039bf
DS
5774 struct route_node *rn;
5775
718e3744 5776 params = IF_DEF_PARAMS (ifp);
5777
7a7be519 5778 if (argc == 5)
718e3744 5779 {
8d769265 5780 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 5781 if (!ret)
5782 {
5783 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5784 VTY_NEWLINE);
5785 return CMD_WARNING;
5786 }
5787
5788 params = ospf_lookup_if_params (ifp, addr);
5789 if (params == NULL)
b4a039bf
DS
5790 {
5791 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
5792 return CMD_WARNING;
5793 }
718e3744 5794
b4a039bf
DS
5795 params->auth_type = OSPF_AUTH_NOTSET;
5796 UNSET_IF_PARAM (params, auth_type);
5797 if (params != IF_DEF_PARAMS (ifp))
5798 {
5799 ospf_free_if_params (ifp, addr);
5800 ospf_if_update_params (ifp, addr);
5801 }
5802 }
5803 else
718e3744 5804 {
b4a039bf
DS
5805 /*
5806 * When a user enters 'no ip ospf authentication'
5807 * We should remove all authentication types from
5808 * the interface.
5809 */
813d4307
DW
5810 if ((params->auth_type == OSPF_AUTH_NULL) ||
5811 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
5812 (params->auth_type == OSPF_AUTH_SIMPLE))
5813 {
5814 params->auth_type = OSPF_AUTH_NOTSET;
5815 UNSET_IF_PARAM (params, auth_type);
5816 }
5817
b4a039bf
DS
5818 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
5819 {
5820 if ((params = rn->info))
5821 {
813d4307 5822
b4a039bf
DS
5823 if ((params->auth_type == OSPF_AUTH_NULL) ||
5824 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
5825 (params->auth_type == OSPF_AUTH_SIMPLE))
5826 {
5827 params->auth_type = OSPF_AUTH_NOTSET;
5828 UNSET_IF_PARAM (params, auth_type);
5829 if (params != IF_DEF_PARAMS (ifp))
5830 {
5831 ospf_free_if_params (ifp, rn->p.u.prefix4);
5832 ospf_if_update_params(ifp, rn->p.u.prefix4);
5833 }
5834 }
5835 }
5836 }
718e3744 5837 }
5838
5839 return CMD_SUCCESS;
5840}
5841
0d829fa7 5842
718e3744 5843DEFUN (ip_ospf_authentication_key,
5844 ip_ospf_authentication_key_addr_cmd,
7a7be519 5845 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
718e3744 5846 "IP Information\n"
5847 "OSPF interface commands\n"
5848 "Authentication password (key)\n"
5849 "The OSPF password (key)\n"
5850 "Address of interface")
5851{
cdc2d765 5852 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 5853 int idx = 0;
718e3744 5854 struct in_addr addr;
718e3744 5855 struct ospf_if_params *params;
5856
718e3744 5857 params = IF_DEF_PARAMS (ifp);
5858
0d829fa7 5859 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 5860 {
0d829fa7 5861 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 5862 {
5863 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5864 VTY_NEWLINE);
5865 return CMD_WARNING;
5866 }
5867
5868 params = ospf_get_if_params (ifp, addr);
5869 ospf_if_update_params (ifp, addr);
5870 }
5871
718e3744 5872 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
7a7be519 5873 strncpy ((char *) params->auth_simple, argv[3]->arg, OSPF_AUTH_SIMPLE_SIZE);
718e3744 5874 SET_IF_PARAM (params, auth_simple);
5875
5876 return CMD_SUCCESS;
5877}
5878
7a7be519 5879DEFUN_HIDDEN (ospf_authentication_key,
747e489c 5880 ospf_authentication_key_cmd,
0d829fa7 5881 "ospf authentication-key AUTH_KEY [A.B.C.D]",
747e489c
DW
5882 "OSPF interface commands\n"
5883 "Authentication password (key)\n"
0d829fa7
QY
5884 "The OSPF password (key)\n"
5885 "Address of interface\n")
718e3744 5886{
0d829fa7 5887 return ip_ospf_authentication_key (self, vty, argc, argv);
718e3744 5888}
5889
7a7be519 5890DEFUN (no_ip_ospf_authentication_key,
5891 no_ip_ospf_authentication_key_authkey_addr_cmd,
5892 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5893 NO_STR
5894 "IP Information\n"
5895 "OSPF interface commands\n"
5896 "Authentication password (key)\n"
5897 "The OSPF password (key)")
5898{
cdc2d765 5899 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 5900 int idx = 0;
7a7be519 5901 struct in_addr addr;
5902 struct ospf_if_params *params;
7a7be519 5903 params = IF_DEF_PARAMS (ifp);
5904
0d829fa7 5905 if (argv_find (argv, argc, "A.B.C.D", &idx))
7a7be519 5906 {
0d829fa7 5907 if (!inet_aton(argv[idx]->arg, &addr))
7a7be519 5908 {
5909 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5910 VTY_NEWLINE);
5911 return CMD_WARNING;
5912 }
813d4307 5913
7a7be519 5914 params = ospf_lookup_if_params (ifp, addr);
5915 if (params == NULL)
5916 return CMD_SUCCESS;
5917 }
718e3744 5918
7a7be519 5919 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
5920 UNSET_IF_PARAM (params, auth_simple);
718e3744 5921
7a7be519 5922 if (params != IF_DEF_PARAMS (ifp))
5923 {
5924 ospf_free_if_params (ifp, addr);
5925 ospf_if_update_params (ifp, addr);
5926 }
813d4307 5927
7a7be519 5928 return CMD_SUCCESS;
5929}
813d4307 5930
0d829fa7
QY
5931DEFUN_HIDDEN (no_ospf_authentication_key,
5932 no_ospf_authentication_key_authkey_addr_cmd,
5933 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5934 NO_STR
5935 "OSPF interface commands\n"
5936 "Authentication password (key)\n"
5937 "The OSPF password (key)")
5938{
5939 return no_ip_ospf_authentication_key (self, vty, argc, argv);
5940}
5941
718e3744 5942DEFUN (ip_ospf_message_digest_key,
537eae3f 5943 ip_ospf_message_digest_key_cmd,
7a7be519 5944 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
718e3744 5945 "IP Information\n"
5946 "OSPF interface commands\n"
5947 "Message digest authentication password (key)\n"
5948 "Key ID\n"
5949 "Use MD5 algorithm\n"
fefa0d82
QY
5950 "The OSPF password (key)\n"
5951 "Address of interface\n")
718e3744 5952{
cdc2d765 5953 VTY_DECLVAR_CONTEXT(interface, ifp);
718e3744 5954 struct crypt_key *ck;
5955 u_char key_id;
5956 struct in_addr addr;
718e3744 5957 struct ospf_if_params *params;
5958
718e3744 5959 params = IF_DEF_PARAMS (ifp);
fefa0d82
QY
5960 int idx = 0;
5961
5962 argv_find (argv, argc, "(1-255)", &idx);
0d829fa7 5963 char *keyid = argv[idx]->arg;
fefa0d82
QY
5964 argv_find (argv, argc, "KEY", &idx);
5965 char *cryptkey = argv[idx]->arg;
718e3744 5966
0d829fa7 5967 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 5968 {
0d829fa7 5969 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 5970 {
5971 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5972 VTY_NEWLINE);
5973 return CMD_WARNING;
5974 }
5975
5976 params = ospf_get_if_params (ifp, addr);
5977 ospf_if_update_params (ifp, addr);
5978 }
5979
fefa0d82 5980 key_id = strtol (keyid, NULL, 10);
718e3744 5981 if (ospf_crypt_key_lookup (params->auth_crypt, key_id) != NULL)
5982 {
5983 vty_out (vty, "OSPF: Key %d already exists%s", key_id, VTY_NEWLINE);
5984 return CMD_WARNING;
5985 }
5986
5987 ck = ospf_crypt_key_new ();
5988 ck->key_id = (u_char) key_id;
5989 memset (ck->auth_key, 0, OSPF_AUTH_MD5_SIZE+1);
fefa0d82 5990 strncpy ((char *) ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE);
718e3744 5991
5992 ospf_crypt_key_add (params->auth_crypt, ck);
5993 SET_IF_PARAM (params, auth_crypt);
5994
5995 return CMD_SUCCESS;
5996}
5997
7a7be519 5998DEFUN_HIDDEN (ospf_message_digest_key,
747e489c 5999 ospf_message_digest_key_cmd,
0d829fa7 6000 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
747e489c
DW
6001 "OSPF interface commands\n"
6002 "Message digest authentication password (key)\n"
6003 "Key ID\n"
6004 "Use MD5 algorithm\n"
0d829fa7
QY
6005 "The OSPF password (key)\n"
6006 "Address of interface\n")
7a7be519 6007{
0d829fa7 6008 return ip_ospf_message_digest_key (self, vty, argc, argv);
7a7be519 6009}
718e3744 6010
537eae3f
QY
6011DEFUN (no_ip_ospf_message_digest_key,
6012 no_ip_ospf_message_digest_key_cmd,
0d829fa7 6013 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
813d4307
DW
6014 NO_STR
6015 "IP Information\n"
6016 "OSPF interface commands\n"
6017 "Message digest authentication password (key)\n"
6018 "Key ID\n"
6019 "Use MD5 algorithm\n"
0d829fa7
QY
6020 "The OSPF password (key)\n"
6021 "Address of interface\n")
813d4307 6022{
cdc2d765 6023 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6024 int idx = 0;
813d4307
DW
6025 struct crypt_key *ck;
6026 int key_id;
6027 struct in_addr addr;
813d4307 6028 struct ospf_if_params *params;
813d4307
DW
6029 params = IF_DEF_PARAMS (ifp);
6030
0d829fa7
QY
6031 argv_find (argv, argc, "(1-255)", &idx);
6032 char *keyid = argv[idx]->arg;
7a7be519 6033
0d829fa7 6034 if (argv_find (argv, argc, "A.B.C.D", &idx))
7a7be519 6035 {
0d829fa7 6036 if (!inet_aton(argv[idx]->arg, &addr))
7a7be519 6037 {
6038 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6039 VTY_NEWLINE);
6040 return CMD_WARNING;
6041 }
6042
6043 params = ospf_lookup_if_params (ifp, addr);
6044 if (params == NULL)
6045 return CMD_SUCCESS;
6046 }
6047
0d829fa7 6048 key_id = strtol (keyid, NULL, 10);
7a7be519 6049 ck = ospf_crypt_key_lookup (params->auth_crypt, key_id);
6050 if (ck == NULL)
6051 {
6052 vty_out (vty, "OSPF: Key %d does not exist%s", key_id, VTY_NEWLINE);
6053 return CMD_WARNING;
6054 }
6055
6056 ospf_crypt_key_delete (params->auth_crypt, key_id);
6057
6058 if (params != IF_DEF_PARAMS (ifp))
6059 {
6060 ospf_free_if_params (ifp, addr);
6061 ospf_if_update_params (ifp, addr);
6062 }
6063
6064 return CMD_SUCCESS;
6065}
813d4307 6066
0d829fa7 6067DEFUN_HIDDEN (no_ospf_message_digest_key,
537eae3f 6068 no_ospf_message_digest_key_cmd,
0d829fa7
QY
6069 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6070 NO_STR
6071 "OSPF interface commands\n"
6072 "Message digest authentication password (key)\n"
6073 "Key ID\n"
6074 "Address of interface")
718e3744 6075{
537eae3f 6076 return no_ip_ospf_message_digest_key (self, vty, argc, argv);
718e3744 6077}
6078
718e3744 6079DEFUN (ip_ospf_cost,
5c2fc921 6080 ip_ospf_cost_cmd,
7a7be519 6081 "ip ospf cost (1-65535) [A.B.C.D]",
718e3744 6082 "IP Information\n"
6083 "OSPF interface commands\n"
6084 "Interface cost\n"
6085 "Cost\n"
5c2fc921 6086 "Address of interface\n")
718e3744 6087{
cdc2d765 6088 VTY_DECLVAR_CONTEXT(interface, ifp);
5c2fc921 6089 int idx = 0;
718e3744 6090 u_int32_t cost;
6091 struct in_addr addr;
718e3744 6092 struct ospf_if_params *params;
718e3744 6093 params = IF_DEF_PARAMS (ifp);
6094
5c2fc921
QY
6095 // get arguments
6096 char *coststr = NULL, *ifaddr = NULL;
6097 coststr = argv_find (argv, argc, "(1-65535)", &idx) ? argv[idx]->arg : NULL;
6098 ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
718e3744 6099
5c2fc921 6100 cost = strtol (coststr, NULL, 10);
718e3744 6101
5c2fc921 6102 if (ifaddr)
718e3744 6103 {
5c2fc921 6104 if(!inet_aton(ifaddr, &addr))
718e3744 6105 {
6106 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6107 VTY_NEWLINE);
6108 return CMD_WARNING;
6109 }
6110
6111 params = ospf_get_if_params (ifp, addr);
6112 ospf_if_update_params (ifp, addr);
6113 }
6114
6115 SET_IF_PARAM (params, output_cost_cmd);
6116 params->output_cost_cmd = cost;
6117
6118 ospf_if_recalculate_output_cost (ifp);
5c2fc921 6119
718e3744 6120 return CMD_SUCCESS;
6121}
6122
7a7be519 6123DEFUN_HIDDEN (ospf_cost,
5c2fc921
QY
6124 ospf_cost_cmd,
6125 "ospf cost (1-65535) [A.B.C.D]",
747e489c
DW
6126 "OSPF interface commands\n"
6127 "Interface cost\n"
6128 "Cost\n"
5c2fc921 6129 "Address of interface\n")
7a7be519 6130{
5c2fc921 6131 return ip_ospf_cost (self, vty, argc, argv);
7a7be519 6132}
9eff36b3 6133
718e3744 6134DEFUN (no_ip_ospf_cost,
5c2fc921
QY
6135 no_ip_ospf_cost_cmd,
6136 "no ip ospf cost [(1-65535)] [A.B.C.D]",
718e3744 6137 NO_STR
718e3744 6138 "OSPF interface commands\n"
6139 "Interface cost\n"
6140 "Address of interface")
6141{
cdc2d765 6142 VTY_DECLVAR_CONTEXT(interface, ifp);
5c2fc921 6143 int idx = 0;
718e3744 6144 struct in_addr addr;
718e3744 6145 struct ospf_if_params *params;
7a7be519 6146
718e3744 6147 params = IF_DEF_PARAMS (ifp);
6148
5c2fc921
QY
6149 // get arguments
6150 char *ifaddr = NULL;
6151 ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
718e3744 6152
7a7be519 6153 /* According to the semantics we are mimicking "no ip ospf cost N" is
6154 * always treated as "no ip ospf cost" regardless of the actual value
5c2fc921 6155 * of N already configured for the interface. Thus ignore cost. */
7a7be519 6156
5c2fc921 6157 if (ifaddr)
7a7be519 6158 {
5c2fc921 6159 if (!inet_aton(ifaddr, &addr))
7a7be519 6160 {
6161 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6162 VTY_NEWLINE);
6163 return CMD_WARNING;
6164 }
6165
6166 params = ospf_lookup_if_params (ifp, addr);
6167 if (params == NULL)
6168 return CMD_SUCCESS;
6169 }
6170
6171 UNSET_IF_PARAM (params, output_cost_cmd);
6172
6173 if (params != IF_DEF_PARAMS (ifp))
6174 {
6175 ospf_free_if_params (ifp, addr);
6176 ospf_if_update_params (ifp, addr);
6177 }
6178
6179 ospf_if_recalculate_output_cost (ifp);
6180
6181 return CMD_SUCCESS;
6182}
9eff36b3 6183
5c2fc921
QY
6184DEFUN_HIDDEN (no_ospf_cost,
6185 no_ospf_cost_cmd,
6186 "no ospf cost [(1-65535)] [A.B.C.D]",
6187 NO_STR
6188 "OSPF interface commands\n"
6189 "Interface cost\n"
6190 "Cost\n"
6191 "Address of interface\n")
827341b7 6192{
5c2fc921 6193 return no_ip_ospf_cost (self, vty, argc, argv);
827341b7
DO
6194}
6195
4dadc291 6196static void
718e3744 6197ospf_nbr_timer_update (struct ospf_interface *oi)
6198{
6199 struct route_node *rn;
6200 struct ospf_neighbor *nbr;
6201
6202 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
6203 if ((nbr = rn->info))
6204 {
6205 nbr->v_inactivity = OSPF_IF_PARAM (oi, v_wait);
6206 nbr->v_db_desc = OSPF_IF_PARAM (oi, retransmit_interval);
6207 nbr->v_ls_req = OSPF_IF_PARAM (oi, retransmit_interval);
6208 nbr->v_ls_upd = OSPF_IF_PARAM (oi, retransmit_interval);
6209 }
6210}
6211
f9ad937f 6212static int
6213ospf_vty_dead_interval_set (struct vty *vty, const char *interval_str,
6214 const char *nbr_str,
6215 const char *fast_hello_str)
718e3744 6216{
cdc2d765 6217 VTY_DECLVAR_CONTEXT(interface, ifp);
718e3744 6218 u_int32_t seconds;
f9ad937f 6219 u_char hellomult;
718e3744 6220 struct in_addr addr;
6221 int ret;
6222 struct ospf_if_params *params;
6223 struct ospf_interface *oi;
6224 struct route_node *rn;
6225
6226 params = IF_DEF_PARAMS (ifp);
f9ad937f 6227
6228 if (nbr_str)
718e3744 6229 {
f9ad937f 6230 ret = inet_aton(nbr_str, &addr);
718e3744 6231 if (!ret)
6232 {
6233 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6234 VTY_NEWLINE);
6235 return CMD_WARNING;
6236 }
6237
6238 params = ospf_get_if_params (ifp, addr);
6239 ospf_if_update_params (ifp, addr);
6240 }
6241
f9ad937f 6242 if (interval_str)
6243 {
6244 VTY_GET_INTEGER_RANGE ("Router Dead Interval", seconds, interval_str,
6245 1, 65535);
6246
6247 /* reset fast_hello too, just to be sure */
6248 UNSET_IF_PARAM (params, fast_hello);
6249 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6250 }
6251 else if (fast_hello_str)
6252 {
6253 VTY_GET_INTEGER_RANGE ("Hello Multiplier", hellomult, fast_hello_str,
6254 1, 10);
6255 /* 1s dead-interval with sub-second hellos desired */
6256 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
6257 SET_IF_PARAM (params, fast_hello);
6258 params->fast_hello = hellomult;
6259 }
6260 else
6261 {
6262 vty_out (vty, "Please specify dead-interval or hello-multiplier%s",
6263 VTY_NEWLINE);
6264 return CMD_WARNING;
6265 }
6266
718e3744 6267 SET_IF_PARAM (params, v_wait);
6268 params->v_wait = seconds;
6269
6270 /* Update timer values in neighbor structure. */
f9ad937f 6271 if (nbr_str)
718e3744 6272 {
cac3b5c4
PJ
6273 struct ospf *ospf;
6274 if ((ospf = ospf_lookup()))
68980084 6275 {
6276 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
6277 if (oi)
6278 ospf_nbr_timer_update (oi);
6279 }
718e3744 6280 }
6281 else
6282 {
6283 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6284 if ((oi = rn->info))
6285 ospf_nbr_timer_update (oi);
6286 }
6287
6288 return CMD_SUCCESS;
6289}
6290
f9ad937f 6291DEFUN (ip_ospf_dead_interval,
0d829fa7 6292 ip_ospf_dead_interval_cmd,
7a7be519 6293 "ip ospf dead-interval (1-65535) [A.B.C.D]",
f9ad937f 6294 "IP Information\n"
6295 "OSPF interface commands\n"
99a522c7 6296 "Interval time after which a neighbor is declared down\n"
f9ad937f 6297 "Seconds\n"
6298 "Address of interface\n")
6299{
0d829fa7
QY
6300 int idx = 0;
6301 char *interval = argv_find (argv, argc, "(1-65535)", &idx) ? argv[idx]->arg : NULL;
6302 char *ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
6303 return ospf_vty_dead_interval_set (vty, interval, ifaddr, NULL);
f9ad937f 6304}
6305
718e3744 6306
7a7be519 6307DEFUN_HIDDEN (ospf_dead_interval,
747e489c 6308 ospf_dead_interval_cmd,
0d829fa7 6309 "ospf dead-interval (1-65535) [A.B.C.D]",
747e489c 6310 "OSPF interface commands\n"
99a522c7 6311 "Interval time after which a neighbor is declared down\n"
0d829fa7
QY
6312 "Seconds\n"
6313 "Address of interface\n")
7a7be519 6314{
0d829fa7 6315 return ip_ospf_dead_interval (self, vty, argc, argv);
7a7be519 6316}
718e3744 6317
f9ad937f 6318DEFUN (ip_ospf_dead_interval_minimal,
6319 ip_ospf_dead_interval_minimal_addr_cmd,
7a7be519 6320 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
f9ad937f 6321 "IP Information\n"
6322 "OSPF interface commands\n"
99a522c7 6323 "Interval time after which a neighbor is declared down\n"
f9ad937f 6324 "Minimal 1s dead-interval with fast sub-second hellos\n"
6325 "Hello multiplier factor\n"
6326 "Number of Hellos to send each second\n"
6327 "Address of interface\n")
6328{
8d769265
DW
6329 int idx_number = 5;
6330 int idx_ipv4 = 6;
7a7be519 6331 if (argc == 7)
8d769265 6332 return ospf_vty_dead_interval_set (vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
f9ad937f 6333 else
8d769265 6334 return ospf_vty_dead_interval_set (vty, NULL, NULL, argv[idx_number]->arg);
f9ad937f 6335}
6336
718e3744 6337DEFUN (no_ip_ospf_dead_interval,
0d829fa7 6338 no_ip_ospf_dead_interval_cmd,
e83a9414 6339 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
718e3744 6340 NO_STR
6341 "IP Information\n"
6342 "OSPF interface commands\n"
99a522c7 6343 "Interval time after which a neighbor is declared down\n"
f9dfba8d 6344 "Seconds\n"
718e3744 6345 "Address of interface")
6346{
cdc2d765 6347 VTY_DECLVAR_CONTEXT(interface, ifp);
7a7be519 6348 int idx_ipv4 = argc - 1;
718e3744 6349 struct in_addr addr;
6350 int ret;
6351 struct ospf_if_params *params;
6352 struct ospf_interface *oi;
6353 struct route_node *rn;
020709f9 6354
718e3744 6355 params = IF_DEF_PARAMS (ifp);
6356
7a7be519 6357 if (argv[idx_ipv4]->type == IPV4_TKN)
718e3744 6358 {
8d769265 6359 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
718e3744 6360 if (!ret)
6361 {
6362 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6363 VTY_NEWLINE);
6364 return CMD_WARNING;
6365 }
6366
6367 params = ospf_lookup_if_params (ifp, addr);
6368 if (params == NULL)
6369 return CMD_SUCCESS;
6370 }
6371
6372 UNSET_IF_PARAM (params, v_wait);
6373 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
f9ad937f 6374
6375 UNSET_IF_PARAM (params, fast_hello);
6376 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6377
718e3744 6378 if (params != IF_DEF_PARAMS (ifp))
6379 {
6380 ospf_free_if_params (ifp, addr);
6381 ospf_if_update_params (ifp, addr);
6382 }
6383
6384 /* Update timer values in neighbor structure. */
6385 if (argc == 1)
6386 {
cac3b5c4
PJ
6387 struct ospf *ospf;
6388
6389 if ((ospf = ospf_lookup()))
68980084 6390 {
6391 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
6392 if (oi)
6393 ospf_nbr_timer_update (oi);
6394 }
718e3744 6395 }
6396 else
6397 {
6398 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6399 if ((oi = rn->info))
6400 ospf_nbr_timer_update (oi);
6401 }
6402
6403 return CMD_SUCCESS;
6404}
6405
0d829fa7
QY
6406DEFUN_HIDDEN (no_ospf_dead_interval,
6407 no_ospf_dead_interval_cmd,
6408 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
6409 NO_STR
6410 "OSPF interface commands\n"
99a522c7 6411 "Interval time after which a neighbor is declared down\n"
0d829fa7
QY
6412 "Seconds\n"
6413 "Address of interface")
6414{
6415 return no_ip_ospf_dead_interval (self, vty, argc, argv);
6416}
6417
718e3744 6418DEFUN (ip_ospf_hello_interval,
0d829fa7 6419 ip_ospf_hello_interval_cmd,
7a7be519 6420 "ip ospf hello-interval (1-65535) [A.B.C.D]",
718e3744 6421 "IP Information\n"
6422 "OSPF interface commands\n"
6423 "Time between HELLO packets\n"
6424 "Seconds\n"
0d829fa7 6425 "Address of interface\n")
718e3744 6426{
cdc2d765 6427 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6428 int idx = 0;
718e3744 6429 struct in_addr addr;
718e3744 6430 struct ospf_if_params *params;
718e3744 6431 params = IF_DEF_PARAMS (ifp);
0d829fa7 6432 u_int32_t seconds = 0;
718e3744 6433
0d829fa7
QY
6434 argv_find (argv, argc, "(1-65535)", &idx);
6435 seconds = strtol (argv[idx]->arg, NULL, 10);
718e3744 6436
0d829fa7 6437 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6438 {
0d829fa7 6439 if(!inet_aton(argv[idx]->arg, &addr))
718e3744 6440 {
6441 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6442 VTY_NEWLINE);
6443 return CMD_WARNING;
6444 }
6445
6446 params = ospf_get_if_params (ifp, addr);
6447 ospf_if_update_params (ifp, addr);
6448 }
6449
f9ad937f 6450 SET_IF_PARAM (params, v_hello);
718e3744 6451 params->v_hello = seconds;
6452
6453 return CMD_SUCCESS;
6454}
6455
7a7be519 6456DEFUN_HIDDEN (ospf_hello_interval,
747e489c 6457 ospf_hello_interval_cmd,
0d829fa7 6458 "ospf hello-interval (1-65535) [A.B.C.D]",
747e489c
DW
6459 "OSPF interface commands\n"
6460 "Time between HELLO packets\n"
0d829fa7
QY
6461 "Seconds\n"
6462 "Address of interface\n")
7a7be519 6463{
0d829fa7 6464 return ip_ospf_hello_interval (self, vty, argc, argv);
7a7be519 6465}
718e3744 6466
6467DEFUN (no_ip_ospf_hello_interval,
0d829fa7
QY
6468 no_ip_ospf_hello_interval_cmd,
6469 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
718e3744 6470 NO_STR
6471 "IP Information\n"
6472 "OSPF interface commands\n"
0d829fa7 6473 "Time between HELLO packets\n" // ignored
f9dfba8d 6474 "Seconds\n"
0d829fa7 6475 "Address of interface\n")
718e3744 6476{
cdc2d765 6477 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6478 int idx = 0;
718e3744 6479 struct in_addr addr;
718e3744 6480 struct ospf_if_params *params;
718e3744 6481 params = IF_DEF_PARAMS (ifp);
6482
0d829fa7 6483 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6484 {
0d829fa7 6485 if(!inet_aton(argv[idx]->arg, &addr))
718e3744 6486 {
6487 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6488 VTY_NEWLINE);
6489 return CMD_WARNING;
6490 }
6491
6492 params = ospf_lookup_if_params (ifp, addr);
6493 if (params == NULL)
6494 return CMD_SUCCESS;
6495 }
6496
6497 UNSET_IF_PARAM (params, v_hello);
f9ad937f 6498 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
718e3744 6499
6500 if (params != IF_DEF_PARAMS (ifp))
6501 {
6502 ospf_free_if_params (ifp, addr);
6503 ospf_if_update_params (ifp, addr);
6504 }
6505
6506 return CMD_SUCCESS;
6507}
6508
0d829fa7
QY
6509DEFUN_HIDDEN (no_ospf_hello_interval,
6510 no_ospf_hello_interval_cmd,
6511 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
6512 NO_STR
6513 "OSPF interface commands\n"
6514 "Time between HELLO packets\n" // ignored
6515 "Seconds\n"
6516 "Address of interface\n")
6517{
030204c7 6518 return no_ip_ospf_hello_interval (self, vty, argc, argv);
0d829fa7 6519}
718e3744 6520
6521DEFUN (ip_ospf_network,
6522 ip_ospf_network_cmd,
6147e2c6 6523 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
718e3744 6524 "IP Information\n"
6525 "OSPF interface commands\n"
6526 "Network type\n"
6527 "Specify OSPF broadcast multi-access network\n"
6528 "Specify OSPF NBMA network\n"
6529 "Specify OSPF point-to-multipoint network\n"
6530 "Specify OSPF point-to-point network\n")
6531{
cdc2d765 6532 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6533 int idx = 0;
718e3744 6534 int old_type = IF_DEF_PARAMS (ifp)->type;
6535 struct route_node *rn;
4b4bda9b
CF
6536
6537 if (old_type == OSPF_IFTYPE_LOOPBACK)
6538 {
6539 vty_out (vty, "This is a loopback interface. Can't set network type.%s", VTY_NEWLINE);
6540 return CMD_WARNING;
6541 }
6542
0d829fa7 6543 if (argv_find (argv, argc, "broadcast", &idx))
718e3744 6544 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_BROADCAST;
0d829fa7 6545 else if (argv_find (argv, argc, "non-broadcast", &idx))
718e3744 6546 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_NBMA;
0d829fa7 6547 else if (argv_find (argv, argc, "point-to-multipoint", &idx))
718e3744 6548 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
0d829fa7 6549 else if (argv_find (argv, argc, "point-to-point", &idx))
718e3744 6550 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOPOINT;
6551
6552 if (IF_DEF_PARAMS (ifp)->type == old_type)
6553 return CMD_SUCCESS;
6554
6555 SET_IF_PARAM (IF_DEF_PARAMS (ifp), type);
6556
6557 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6558 {
6559 struct ospf_interface *oi = rn->info;
6560
6561 if (!oi)
6562 continue;
6563
6564 oi->type = IF_DEF_PARAMS (ifp)->type;
6565
6566 if (oi->state > ISM_Down)
6567 {
7a7be519 6568 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
6569 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
6570 }
6571 }
6572
6573 return CMD_SUCCESS;
6574}
6575
6576DEFUN_HIDDEN (ospf_network,
6577 ospf_network_cmd,
e83a9414 6578 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7a7be519 6579 "OSPF interface commands\n"
6580 "Network type\n"
6581 "Specify OSPF broadcast multi-access network\n"
6582 "Specify OSPF NBMA network\n"
6583 "Specify OSPF point-to-multipoint network\n"
6584 "Specify OSPF point-to-point network\n")
6585{
0d829fa7 6586 return ip_ospf_network (self, vty, argc, argv);
7a7be519 6587}
6588
6589DEFUN (no_ip_ospf_network,
6590 no_ip_ospf_network_cmd,
6591 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6592 NO_STR
6593 "IP Information\n"
6594 "OSPF interface commands\n"
6595 "Network type\n"
6596 "Specify OSPF broadcast multi-access network\n"
6597 "Specify OSPF NBMA network\n"
6598 "Specify OSPF point-to-multipoint network\n"
6599 "Specify OSPF point-to-point network\n")
22b27e95 6600{
cdc2d765 6601 VTY_DECLVAR_CONTEXT(interface, ifp);
7a7be519 6602 int old_type = IF_DEF_PARAMS (ifp)->type;
6603 struct route_node *rn;
6604
6605 IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp);
6606
6607 if (IF_DEF_PARAMS (ifp)->type == old_type)
6608 return CMD_SUCCESS;
6609
6610 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6611 {
6612 struct ospf_interface *oi = rn->info;
6613
6614 if (!oi)
6615 continue;
6616
6617 oi->type = IF_DEF_PARAMS (ifp)->type;
6618
6619 if (oi->state > ISM_Down)
6620 {
6621 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
6622 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
6623 }
6624 }
6625
6626 return CMD_SUCCESS;
6627}
6628
0d829fa7
QY
6629DEFUN_HIDDEN (no_ospf_network,
6630 no_ospf_network_cmd,
6631 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6632 NO_STR
6633 "OSPF interface commands\n"
6634 "Network type\n"
6635 "Specify OSPF broadcast multi-access network\n"
6636 "Specify OSPF NBMA network\n"
6637 "Specify OSPF point-to-multipoint network\n"
6638 "Specify OSPF point-to-point network\n")
6639{
6640 return no_ip_ospf_network (self, vty, argc, argv);
6641}
6642
7a7be519 6643DEFUN (ip_ospf_priority,
537eae3f 6644 ip_ospf_priority_cmd,
7a7be519 6645 "ip ospf priority (0-255) [A.B.C.D]",
6646 "IP Information\n"
6647 "OSPF interface commands\n"
6648 "Router priority\n"
6649 "Priority\n"
6650 "Address of interface")
6651{
cdc2d765 6652 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6653 int idx = 0;
7a7be519 6654 long priority;
6655 struct route_node *rn;
6656 struct in_addr addr;
7a7be519 6657 struct ospf_if_params *params;
7a7be519 6658 params = IF_DEF_PARAMS (ifp);
6659
0d829fa7
QY
6660 argv_find (argv, argc, "(0-255)", &idx);
6661 priority = strtol (argv[idx]->arg, NULL, 10);
7a7be519 6662
0d829fa7 6663 if (argv_find (argv, argc, "A.B.C.D", &idx))
7a7be519 6664 {
0d829fa7 6665 if (!inet_aton(argv[idx]->arg, &addr))
7a7be519 6666 {
6667 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6668 VTY_NEWLINE);
6669 return CMD_WARNING;
6670 }
6671
6672 params = ospf_get_if_params (ifp, addr);
6673 ospf_if_update_params (ifp, addr);
6674 }
6675
6676 SET_IF_PARAM (params, priority);
6677 params->priority = priority;
6678
6679 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6680 {
6681 struct ospf_interface *oi = rn->info;
6682
6683 if (!oi)
6684 continue;
6685
6686 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
6687 {
6688 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
6689 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
718e3744 6690 }
6691 }
6692
6693 return CMD_SUCCESS;
6694}
6695
7a7be519 6696DEFUN_HIDDEN (ospf_priority,
6697 ospf_priority_cmd,
0d829fa7 6698 "ospf priority (0-255) [A.B.C.D]",
7a7be519 6699 "OSPF interface commands\n"
6700 "Router priority\n"
3a2d747c
QY
6701 "Priority\n"
6702 "Address of interface")
718e3744 6703{
0d829fa7 6704 return ip_ospf_priority (self, vty, argc, argv);
718e3744 6705}
6706
718e3744 6707DEFUN (no_ip_ospf_priority,
537eae3f 6708 no_ip_ospf_priority_cmd,
7a7be519 6709 "no ip ospf priority [(0-255) [A.B.C.D]]",
718e3744 6710 NO_STR
6711 "IP Information\n"
6712 "OSPF interface commands\n"
0d829fa7 6713 "Router priority\n" // ignored
813d4307 6714 "Priority\n"
718e3744 6715 "Address of interface")
6716{
cdc2d765 6717 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6718 int idx = 0;
718e3744 6719 struct route_node *rn;
6720 struct in_addr addr;
718e3744 6721 struct ospf_if_params *params;
6722
718e3744 6723 params = IF_DEF_PARAMS (ifp);
6724
0d829fa7 6725 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6726 {
0d829fa7 6727 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6728 {
6729 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6730 VTY_NEWLINE);
6731 return CMD_WARNING;
6732 }
6733
6734 params = ospf_lookup_if_params (ifp, addr);
6735 if (params == NULL)
6736 return CMD_SUCCESS;
6737 }
6738
6739 UNSET_IF_PARAM (params, priority);
6740 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
6741
6742 if (params != IF_DEF_PARAMS (ifp))
6743 {
6744 ospf_free_if_params (ifp, addr);
6745 ospf_if_update_params (ifp, addr);
6746 }
6747
6748 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6749 {
6750 struct ospf_interface *oi = rn->info;
6751
6752 if (!oi)
6753 continue;
6754
718e3744 6755 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
6756 {
6757 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
6758 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
6759 }
6760 }
6761
6762 return CMD_SUCCESS;
6763}
6764
0d829fa7 6765DEFUN_HIDDEN (no_ospf_priority,
537eae3f 6766 no_ospf_priority_cmd,
0d829fa7
QY
6767 "no ospf priority [(0-255) [A.B.C.D]]",
6768 NO_STR
6769 "OSPF interface commands\n"
6770 "Router priority\n"
6771 "Priority\n"
6772 "Address of interface")
6773{
6774 return no_ip_ospf_priority (self, vty, argc, argv);
6775}
a1afa410 6776
718e3744 6777DEFUN (ip_ospf_retransmit_interval,
6778 ip_ospf_retransmit_interval_addr_cmd,
7a7be519 6779 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
718e3744 6780 "IP Information\n"
6781 "OSPF interface commands\n"
6782 "Time between retransmitting lost link state advertisements\n"
6783 "Seconds\n"
6784 "Address of interface")
6785{
cdc2d765 6786 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6787 int idx = 0;
718e3744 6788 u_int32_t seconds;
6789 struct in_addr addr;
718e3744 6790 struct ospf_if_params *params;
718e3744 6791 params = IF_DEF_PARAMS (ifp);
718e3744 6792
0d829fa7
QY
6793 argv_find (argv, argc, "(3-65535)", &idx);
6794 seconds = strtol (argv[idx]->arg, NULL, 10);
718e3744 6795
0d829fa7 6796 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6797 {
0d829fa7 6798 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6799 {
6800 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6801 VTY_NEWLINE);
6802 return CMD_WARNING;
6803 }
6804
6805 params = ospf_get_if_params (ifp, addr);
6806 ospf_if_update_params (ifp, addr);
6807 }
6808
6809 SET_IF_PARAM (params, retransmit_interval);
6810 params->retransmit_interval = seconds;
6811
6812 return CMD_SUCCESS;
6813}
6814
7a7be519 6815DEFUN_HIDDEN (ospf_retransmit_interval,
747e489c 6816 ospf_retransmit_interval_cmd,
0d829fa7 6817 "ospf retransmit-interval (3-65535) [A.B.C.D]",
747e489c
DW
6818 "OSPF interface commands\n"
6819 "Time between retransmitting lost link state advertisements\n"
3a2d747c
QY
6820 "Seconds\n"
6821 "Address of interface")
7a7be519 6822{
0d829fa7 6823 return ip_ospf_retransmit_interval (self, vty, argc, argv);
7a7be519 6824}
718e3744 6825
6826DEFUN (no_ip_ospf_retransmit_interval,
6827 no_ip_ospf_retransmit_interval_addr_cmd,
0d829fa7 6828 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
718e3744 6829 NO_STR
6830 "IP Information\n"
6831 "OSPF interface commands\n"
3a2d747c
QY
6832 "Time between retransmitting lost link state advertisements\n"
6833 "Seconds\n"
0d829fa7 6834 "Address of interface\n")
718e3744 6835{
cdc2d765 6836 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6837 int idx = 0;
718e3744 6838 struct in_addr addr;
718e3744 6839 struct ospf_if_params *params;
47b91972 6840
718e3744 6841 params = IF_DEF_PARAMS (ifp);
6842
47b91972 6843 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6844 {
0d829fa7 6845 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6846 {
6847 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6848 VTY_NEWLINE);
6849 return CMD_WARNING;
6850 }
6851
6852 params = ospf_lookup_if_params (ifp, addr);
6853 if (params == NULL)
6854 return CMD_SUCCESS;
6855 }
6856
6857 UNSET_IF_PARAM (params, retransmit_interval);
6858 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
6859
6860 if (params != IF_DEF_PARAMS (ifp))
6861 {
6862 ospf_free_if_params (ifp, addr);
6863 ospf_if_update_params (ifp, addr);
6864 }
6865
6866 return CMD_SUCCESS;
6867}
6868
0d829fa7
QY
6869DEFUN_HIDDEN (no_ospf_retransmit_interval,
6870 no_ospf_retransmit_interval_cmd,
6871 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
6872 NO_STR
6873 "OSPF interface commands\n"
3a2d747c
QY
6874 "Time between retransmitting lost link state advertisements\n"
6875 "Seconds\n"
6876 "Address of interface\n")
0d829fa7
QY
6877{
6878 return no_ip_ospf_retransmit_interval (self, vty, argc, argv);
6879}
813d4307 6880
718e3744 6881DEFUN (ip_ospf_transmit_delay,
6882 ip_ospf_transmit_delay_addr_cmd,
7a7be519 6883 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
718e3744 6884 "IP Information\n"
6885 "OSPF interface commands\n"
6886 "Link state transmit delay\n"
6887 "Seconds\n"
6888 "Address of interface")
6889{
cdc2d765 6890 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6891 int idx = 0;
718e3744 6892 u_int32_t seconds;
6893 struct in_addr addr;
718e3744 6894 struct ospf_if_params *params;
47b91972 6895
718e3744 6896 params = IF_DEF_PARAMS (ifp);
0d829fa7
QY
6897 argv_find (argv, argc, "(1-65535)", &idx);
6898 seconds = strtol (argv[idx]->arg, NULL, 10);
718e3744 6899
0d829fa7 6900 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6901 {
0d829fa7 6902 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6903 {
6904 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6905 VTY_NEWLINE);
6906 return CMD_WARNING;
6907 }
6908
6909 params = ospf_get_if_params (ifp, addr);
6910 ospf_if_update_params (ifp, addr);
6911 }
6912
47b91972 6913 SET_IF_PARAM (params, transmit_delay);
718e3744 6914 params->transmit_delay = seconds;
6915
6916 return CMD_SUCCESS;
6917}
6918
7a7be519 6919DEFUN_HIDDEN (ospf_transmit_delay,
747e489c 6920 ospf_transmit_delay_cmd,
0d829fa7 6921 "ospf transmit-delay (1-65535) [A.B.C.D]",
747e489c
DW
6922 "OSPF interface commands\n"
6923 "Link state transmit delay\n"
3a2d747c
QY
6924 "Seconds\n"
6925 "Address of interface")
7a7be519 6926{
0d829fa7 6927 return ip_ospf_transmit_delay (self, vty, argc, argv);
7a7be519 6928}
718e3744 6929
6930DEFUN (no_ip_ospf_transmit_delay,
6931 no_ip_ospf_transmit_delay_addr_cmd,
0d829fa7 6932 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
718e3744 6933 NO_STR
6934 "IP Information\n"
6935 "OSPF interface commands\n"
6936 "Link state transmit delay\n"
6937 "Address of interface")
6938{
cdc2d765 6939 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6940 int idx = 0;
718e3744 6941 struct in_addr addr;
718e3744 6942 struct ospf_if_params *params;
6943
718e3744 6944 params = IF_DEF_PARAMS (ifp);
6945
0d829fa7 6946 if (argv_find (argv, argc, "A.B.C.D", &idx))
718e3744 6947 {
0d829fa7 6948 if (!inet_aton(argv[idx]->arg, &addr))
718e3744 6949 {
6950 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6951 VTY_NEWLINE);
6952 return CMD_WARNING;
6953 }
6954
6955 params = ospf_lookup_if_params (ifp, addr);
6956 if (params == NULL)
6957 return CMD_SUCCESS;
6958 }
6959
6960 UNSET_IF_PARAM (params, transmit_delay);
6961 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
6962
6963 if (params != IF_DEF_PARAMS (ifp))
6964 {
6965 ospf_free_if_params (ifp, addr);
6966 ospf_if_update_params (ifp, addr);
6967 }
6968
6969 return CMD_SUCCESS;
6970}
6971
813d4307 6972
0d829fa7
QY
6973DEFUN_HIDDEN (no_ospf_transmit_delay,
6974 no_ospf_transmit_delay_cmd,
6975 "no ospf transmit-delay",
6976 NO_STR
6977 "OSPF interface commands\n"
6978 "Link state transmit delay\n")
813d4307 6979{
0d829fa7 6980 return no_ip_ospf_transmit_delay (self, vty, argc, argv);
813d4307
DW
6981}
6982
e723861d
DS
6983DEFUN (ip_ospf_area,
6984 ip_ospf_area_cmd,
22b27e95 6985 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)>",
e723861d
DS
6986 "IP Information\n"
6987 "OSPF interface commands\n"
7a7be519 6988 "Instance ID\n"
e723861d
DS
6989 "Enable OSPF on this interface\n"
6990 "OSPF area ID in IP address format\n"
6991 "OSPF area ID as a decimal value\n")
6992{
cdc2d765 6993 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 6994 int idx = 0;
e723861d
DS
6995 int format, ret;
6996 struct in_addr area_id;
6997 struct ospf *ospf;
6998 struct ospf_if_params *params;
6999 struct route_node *rn;
7c8ff89e 7000 u_short instance = 0;
e723861d 7001
0d829fa7
QY
7002 if (argv_find (argv, argc, "(1-65535)", &idx))
7003 instance = strtol (argv[idx]->arg, NULL, 10);
7004 char *areaid = argv[argc - 1]->arg;
7c8ff89e
DS
7005
7006 ospf = ospf_lookup_instance (instance);
e723861d
DS
7007 if (ospf == NULL)
7008 {
7c8ff89e
DS
7009 params = IF_DEF_PARAMS (ifp);
7010 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
7011 {
7012 ospf_interface_unset (ifp);
7013 ospf = ospf_lookup();
7014 ospf->if_ospf_cli_count--;
7015 }
e723861d
DS
7016 return CMD_SUCCESS;
7017 }
7018
0d829fa7 7019 ret = ospf_str2area_id (areaid, &area_id, &format);
e723861d
DS
7020 if (ret < 0)
7021 {
7022 vty_out (vty, "Please specify area by A.B.C.D|<0-4294967295>%s",
7023 VTY_NEWLINE);
7024 return CMD_WARNING;
7025 }
7026 if (memcmp (ifp->name, "VLINK", 5) == 0)
7027 {
7028 vty_out (vty, "Cannot enable OSPF on a virtual link.%s", VTY_NEWLINE);
7029 return CMD_WARNING;
7030 }
7031
7032 params = IF_DEF_PARAMS (ifp);
7033 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
7034 {
73b9f703
VK
7035 vty_out (vty,
7036 "Must remove previous area config before changing ospf area %s",
7037 VTY_NEWLINE);
e723861d
DS
7038 return CMD_WARNING;
7039 }
7040
7041 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
7042 {
7043 if (rn->info != NULL)
7044 {
7045 vty_out (vty, "Please remove all network commands first.%s", VTY_NEWLINE);
7046 return CMD_WARNING;
7047 }
7048 }
7049
7050 /* enable ospf on this interface with area_id */
7051 ospf_interface_set (ifp, area_id);
7052 ospf->if_ospf_cli_count++;
7053
7054 return CMD_SUCCESS;
7055}
7056
7057DEFUN (no_ip_ospf_area,
7058 no_ip_ospf_area_cmd,
0d829fa7 7059 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)>]",
e723861d
DS
7060 NO_STR
7061 "IP Information\n"
7062 "OSPF interface commands\n"
3a2d747c 7063 "Instance ID\n"
7a7be519 7064 "Disable OSPF on this interface\n"
7065 "OSPF area ID in IP address format\n"
7066 "OSPF area ID as a decimal value\n")
e723861d 7067{
cdc2d765 7068 VTY_DECLVAR_CONTEXT(interface, ifp);
0d829fa7 7069 int idx = 0;
e723861d
DS
7070 struct ospf *ospf;
7071 struct ospf_if_params *params;
7c8ff89e 7072 u_short instance = 0;
e723861d 7073
0d829fa7
QY
7074 if (argv_find (argv, argc, "(1-65535)", &idx))
7075 instance = strtol (argv[idx]->arg, NULL, 10);
813d4307
DW
7076
7077 if ((ospf = ospf_lookup_instance (instance)) == NULL)
7078 return CMD_SUCCESS;
7079
7080 params = IF_DEF_PARAMS (ifp);
7081 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area))
7082 {
0d829fa7 7083 vty_out (vty, "Can't find specified interface area configuration.%s", VTY_NEWLINE);
813d4307
DW
7084 return CMD_WARNING;
7085 }
7086
7087 ospf_interface_unset (ifp);
7088 ospf->if_ospf_cli_count--;
7089 return CMD_SUCCESS;
7090}
7091
6f2a6703
CF
7092DEFUN (ospf_redistribute_source,
7093 ospf_redistribute_source_cmd,
40d1cbfb 7094 "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
d1c65c21 7095 REDIST_STR
ab0181ee 7096 FRR_REDIST_HELP_STR_OSPFD
718e3744 7097 "Metric for redistributed routes\n"
7098 "OSPF default metric\n"
7099 "OSPF exterior metric type for redistributed routes\n"
7100 "Set OSPF External Type 1 metrics\n"
7101 "Set OSPF External Type 2 metrics\n"
7102 "Route map reference\n"
7103 "Pointer to route-map entries\n")
7104{
cdc2d765 7105 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7106 int idx_protocol = 1;
718e3744 7107 int source;
7108 int type = -1;
7109 int metric = -1;
7c8ff89e 7110 struct ospf_redist *red;
6d681bd8 7111 int idx = 0;
6f2a6703 7112
7c8ff89e
DS
7113 if (!ospf)
7114 return CMD_SUCCESS;
7115
718e3744 7116 /* Get distribute source. */
6d681bd8
QY
7117 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7118 if (source < 0)
718e3744 7119 return CMD_WARNING;
7120
6d681bd8
QY
7121 red = ospf_redist_add(ospf, source, 0);
7122
718e3744 7123 /* Get metric value. */
6d681bd8
QY
7124 if (argv_find (argv, argc, "(0-16777214)", &idx)) {
7125 if (!str2metric (argv[idx]->arg, &metric))
718e3744 7126 return CMD_WARNING;
6d681bd8 7127 }
718e3744 7128 /* Get metric type. */
6d681bd8
QY
7129 else if (argv_find (argv, argc, "(1-2)", &idx)) {
7130 if (!str2metric_type (argv[idx]->arg, &type))
718e3744 7131 return CMD_WARNING;
6d681bd8
QY
7132 }
7133 /* Get route-map */
7134 else if (argv_find (argv, argc, "WORD", &idx)) {
7135 ospf_routemap_set (red, argv[idx]->arg);
7136 }
718e3744 7137 else
7c8ff89e 7138 ospf_routemap_unset (red);
718e3744 7139
7c8ff89e 7140 return ospf_redistribute_set (ospf, source, 0, type, metric);
718e3744 7141}
7142
718e3744 7143DEFUN (no_ospf_redistribute_source,
7144 no_ospf_redistribute_source_cmd,
40d1cbfb 7145 "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7146 NO_STR
d1c65c21 7147 REDIST_STR
ab0181ee 7148 FRR_REDIST_HELP_STR_OSPFD
813d4307
DW
7149 "Metric for redistributed routes\n"
7150 "OSPF default metric\n"
7151 "OSPF exterior metric type for redistributed routes\n"
7152 "Set OSPF External Type 1 metrics\n"
7153 "Set OSPF External Type 2 metrics\n"
7154 "Route map reference\n"
7155 "Pointer to route-map entries\n")
718e3744 7156{
cdc2d765 7157 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7158 int idx_protocol = 2;
718e3744 7159 int source;
7c8ff89e 7160 struct ospf_redist *red;
718e3744 7161
6d681bd8
QY
7162 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7163 if (source < 0)
718e3744 7164 return CMD_WARNING;
7165
7c8ff89e
DS
7166 red = ospf_redist_lookup(ospf, source, 0);
7167 if (!red)
7168 return CMD_SUCCESS;
7169
7170 ospf_routemap_unset (red);
7171 return ospf_redistribute_unset (ospf, source, 0);
7172}
7173
7174DEFUN (ospf_redistribute_instance_source,
7175 ospf_redistribute_instance_source_cmd,
ccb8e0c7 7176 "redistribute <ospf|table> (1-65535) [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
7c8ff89e
DS
7177 REDIST_STR
7178 "Open Shortest Path First\n"
2d627ff5
DS
7179 "Non-main Kernel Routing Table\n"
7180 "Instance ID/Table ID\n"
7c8ff89e
DS
7181 "Metric for redistributed routes\n"
7182 "OSPF default metric\n"
7183 "OSPF exterior metric type for redistributed routes\n"
7184 "Set OSPF External Type 1 metrics\n"
7185 "Set OSPF External Type 2 metrics\n"
7186 "Route map reference\n"
7187 "Pointer to route-map entries\n")
7188{
cdc2d765 7189 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7190 int idx_ospf_table = 1;
7191 int idx_number = 2;
7192 int idx_redist_param = 3;
7c8ff89e
DS
7193 int source;
7194 int type = -1;
7195 int metric = -1;
7196 u_short instance;
7197 struct ospf_redist *red;
7198
d8f70b86
DS
7199 if (!ospf)
7200 return CMD_SUCCESS;
7201
6d681bd8 7202 source = proto_redistnum (AFI_IP, argv[idx_ospf_table]->text);
2d627ff5 7203
8d769265 7204 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7c8ff89e
DS
7205
7206 if (!ospf)
7207 return CMD_SUCCESS;
7208
2d627ff5 7209 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
7c8ff89e
DS
7210 {
7211 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
7212 VTY_NEWLINE);
7213 return CMD_WARNING;
7214 }
7215
2d627ff5 7216 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
7c8ff89e
DS
7217 {
7218 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
7219 VTY_NEWLINE);
7220 return CMD_WARNING;
7221 }
7222
7c8ff89e 7223 /* Get metric value. */
7a7be519 7224 if (strcmp (argv[idx_redist_param]->arg, "metric") == 0)
7225 if (!str2metric (argv[idx_redist_param+1]->arg, &metric))
7c8ff89e
DS
7226 return CMD_WARNING;
7227
7228 /* Get metric type. */
7a7be519 7229 if (strcmp (argv[idx_redist_param]->arg, "metric-type") == 0)
7230 if (!str2metric_type (argv[idx_redist_param+1]->arg, &type))
7c8ff89e
DS
7231 return CMD_WARNING;
7232
7233 red = ospf_redist_add(ospf, source, instance);
7a7be519 7234
7235 if (strcmp (argv[idx_redist_param]->arg, "route-map") == 0)
7236 ospf_routemap_set (red, argv[idx_redist_param+1]->arg);
7c8ff89e
DS
7237 else
7238 ospf_routemap_unset (red);
7239
7240 return ospf_redistribute_set (ospf, source, instance, type, metric);
7241}
7242
7243DEFUN (no_ospf_redistribute_instance_source,
7244 no_ospf_redistribute_instance_source_cmd,
ccb8e0c7 7245 "no redistribute <ospf|table> (1-65535) [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
7c8ff89e
DS
7246 NO_STR
7247 REDIST_STR
7248 "Open Shortest Path First\n"
2d627ff5
DS
7249 "Non-main Kernel Routing Table\n"
7250 "Instance ID/Table Id\n"
7c8ff89e
DS
7251 "Metric for redistributed routes\n"
7252 "OSPF default metric\n"
7253 "OSPF exterior metric type for redistributed routes\n"
7254 "Set OSPF External Type 1 metrics\n"
7255 "Set OSPF External Type 2 metrics\n"
7256 "Route map reference\n"
7257 "Pointer to route-map entries\n")
7258{
cdc2d765 7259 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7260 int idx_ospf_table = 2;
7261 int idx_number = 3;
7c8ff89e
DS
7262 u_int instance;
7263 struct ospf_redist *red;
7264 int source;
7265
8d769265 7266 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
2d627ff5
DS
7267 source = ZEBRA_ROUTE_OSPF;
7268 else
7269 source = ZEBRA_ROUTE_TABLE;
7270
8d769265 7271 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7c8ff89e 7272
2d627ff5 7273 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
7c8ff89e
DS
7274 {
7275 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
7276 VTY_NEWLINE);
7277 return CMD_WARNING;
7278 }
7279
2d627ff5 7280 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
7c8ff89e
DS
7281 {
7282 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
7283 VTY_NEWLINE);
7284 return CMD_WARNING;
7285 }
7286
7c8ff89e
DS
7287 red = ospf_redist_lookup(ospf, source, instance);
7288 if (!red)
7289 return CMD_SUCCESS;
7290
7291 ospf_routemap_unset (red);
7292 return ospf_redistribute_unset (ospf, source, instance);
718e3744 7293}
7294
7295DEFUN (ospf_distribute_list_out,
7296 ospf_distribute_list_out_cmd,
40d1cbfb 7297 "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
718e3744 7298 "Filter networks in routing updates\n"
6f2a6703
CF
7299 "Access-list name\n"
7300 OUT_STR
ab0181ee 7301 FRR_REDIST_HELP_STR_OSPFD)
718e3744 7302{
cdc2d765 7303 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7304 int idx_word = 1;
6f2a6703 7305 int source;
718e3744 7306
6d681bd8
QY
7307 char *proto = argv[argc - 1]->text;
7308
6f2a6703 7309 /* Get distribute source. */
6d681bd8
QY
7310 source = proto_redistnum(AFI_IP, proto);
7311 if (source < 0)
6f2a6703 7312 return CMD_WARNING;
718e3744 7313
8d769265 7314 return ospf_distribute_list_out_set (ospf, source, argv[idx_word]->arg);
718e3744 7315}
7316
6f2a6703
CF
7317DEFUN (no_ospf_distribute_list_out,
7318 no_ospf_distribute_list_out_cmd,
40d1cbfb 7319 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
6f2a6703
CF
7320 NO_STR
7321 "Filter networks in routing updates\n"
7322 "Access-list name\n"
7323 OUT_STR
ab0181ee 7324 FRR_REDIST_HELP_STR_OSPFD)
718e3744 7325{
cdc2d765 7326 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7327 int idx_word = 2;
6f2a6703 7328 int source;
020709f9 7329
6d681bd8
QY
7330 char *proto = argv[argc - 1]->text;
7331 source = proto_redistnum(AFI_IP, proto);
7332 if (source < 0)
6f2a6703 7333 return CMD_WARNING;
718e3744 7334
8d769265 7335 return ospf_distribute_list_out_unset (ospf, source, argv[idx_word]->arg);
718e3744 7336}
7337
6f2a6703
CF
7338/* Default information originate. */
7339DEFUN (ospf_default_information_originate,
7340 ospf_default_information_originate_cmd,
e83a9414 7341 "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7342 "Control distribution of default information\n"
7343 "Distribute a default route\n"
7344 "Always advertise default route\n"
6f2a6703
CF
7345 "OSPF default metric\n"
7346 "OSPF metric\n"
718e3744 7347 "OSPF metric type for default routes\n"
7348 "Set OSPF External Type 1 metrics\n"
7349 "Set OSPF External Type 2 metrics\n"
718e3744 7350 "Route map reference\n"
7351 "Pointer to route-map entries\n")
7352{
cdc2d765 7353 VTY_DECLVAR_CONTEXT(ospf, ospf);
6f2a6703 7354 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
718e3744 7355 int type = -1;
7356 int metric = -1;
7c8ff89e 7357 struct ospf_redist *red;
6d681bd8 7358 int idx = 0;
7c8ff89e 7359
6d681bd8 7360 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
6f2a6703
CF
7361
7362 /* Check whether "always" was specified */
6d681bd8 7363 if (argv_find (argv, argc, "always", &idx))
6f2a6703 7364 default_originate = DEFAULT_ORIGINATE_ALWAYS;
6d681bd8
QY
7365 /* Get metric value */
7366 else if (argv_find (argv, argc, "(0-16777214)", &idx)) {
7367 if (!str2metric (argv[idx]->arg, &metric))
718e3744 7368 return CMD_WARNING;
6d681bd8 7369 }
718e3744 7370 /* Get metric type. */
6d681bd8
QY
7371 else if (argv_find (argv, argc, "(1-2)", &idx)) {
7372 if (!str2metric_type (argv[idx]->arg, &type))
718e3744 7373 return CMD_WARNING;
6d681bd8
QY
7374 }
7375 /* Get route-map */
7376 else if (argv_find (argv, argc, "WORD", &idx))
7377 ospf_routemap_set (red, argv[idx]->arg);
718e3744 7378 else
7c8ff89e 7379 ospf_routemap_unset (red);
718e3744 7380
6f2a6703
CF
7381 return ospf_redistribute_default_set (ospf, default_originate,
7382 type, metric);
718e3744 7383}
7384
7385DEFUN (no_ospf_default_information_originate,
7386 no_ospf_default_information_originate_cmd,
12dcf78e 7387 "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7388 NO_STR
7389 "Control distribution of default information\n"
813d4307
DW
7390 "Distribute a default route\n"
7391 "Always advertise default route\n"
7392 "OSPF default metric\n"
7393 "OSPF metric\n"
7394 "OSPF metric type for default routes\n"
7395 "Set OSPF External Type 1 metrics\n"
7396 "Set OSPF External Type 2 metrics\n"
7397 "Route map reference\n"
7398 "Pointer to route-map entries\n")
718e3744 7399{
cdc2d765 7400 VTY_DECLVAR_CONTEXT(ospf, ospf);
718e3744 7401 struct prefix_ipv4 p;
7c8ff89e
DS
7402 struct ospf_external *ext;
7403 struct ospf_redist *red;
7c8ff89e 7404
718e3744 7405 p.family = AF_INET;
7406 p.prefix.s_addr = 0;
7407 p.prefixlen = 0;
7408
5339cfdb 7409 ospf_external_lsa_flush (ospf, DEFAULT_ROUTE, &p, 0);
718e3744 7410
7c8ff89e
DS
7411 if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) &&
7412 EXTERNAL_INFO (ext)) {
7413 ospf_external_info_delete (DEFAULT_ROUTE, 0, p);
7414 ospf_external_del (DEFAULT_ROUTE, 0);
718e3744 7415 }
7416
7c8ff89e
DS
7417 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
7418 if (!red)
7419 return CMD_SUCCESS;
7420
7421 ospf_routemap_unset (red);
020709f9 7422 return ospf_redistribute_default_unset (ospf);
718e3744 7423}
7424
7425DEFUN (ospf_default_metric,
7426 ospf_default_metric_cmd,
6147e2c6 7427 "default-metric (0-16777214)",
718e3744 7428 "Set metric of redistributed routes\n"
7429 "Default metric\n")
7430{
cdc2d765 7431 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7432 int idx_number = 1;
718e3744 7433 int metric = -1;
7434
8d769265 7435 if (!str2metric (argv[idx_number]->arg, &metric))
718e3744 7436 return CMD_WARNING;
7437
68980084 7438 ospf->default_metric = metric;
718e3744 7439
7440 return CMD_SUCCESS;
7441}
7442
7443DEFUN (no_ospf_default_metric,
7444 no_ospf_default_metric_cmd,
7a7be519 7445 "no default-metric [(0-16777214)]",
718e3744 7446 NO_STR
7a7be519 7447 "Set metric of redistributed routes\n"
7448 "Default metric\n")
718e3744 7449{
cdc2d765 7450 VTY_DECLVAR_CONTEXT(ospf, ospf);
68980084 7451
7452 ospf->default_metric = -1;
7453
718e3744 7454 return CMD_SUCCESS;
7455}
7456
718e3744 7457
7458DEFUN (ospf_distance,
7459 ospf_distance_cmd,
6147e2c6 7460 "distance (1-255)",
eaa1ae0d 7461 "Administrative distance\n"
718e3744 7462 "OSPF Administrative distance\n")
7463{
cdc2d765 7464 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7465 int idx_number = 1;
68980084 7466
8d769265 7467 ospf->distance_all = atoi (argv[idx_number]->arg);
68980084 7468
718e3744 7469 return CMD_SUCCESS;
7470}
7471
7472DEFUN (no_ospf_distance,
7473 no_ospf_distance_cmd,
6147e2c6 7474 "no distance (1-255)",
718e3744 7475 NO_STR
eaa1ae0d 7476 "Administrative distance\n"
718e3744 7477 "OSPF Administrative distance\n")
7478{
cdc2d765 7479 VTY_DECLVAR_CONTEXT(ospf, ospf);
68980084 7480
7481 ospf->distance_all = 0;
7482
718e3744 7483 return CMD_SUCCESS;
7484}
7485
7486DEFUN (no_ospf_distance_ospf,
7487 no_ospf_distance_ospf_cmd,
eaa1ae0d 7488 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
718e3744 7489 NO_STR
eaa1ae0d
QY
7490 "Administrative distance\n"
7491 "OSPF administrative distance\n"
718e3744 7492 "Intra-area routes\n"
813d4307 7493 "Distance for intra-area routes\n"
718e3744 7494 "Inter-area routes\n"
813d4307
DW
7495 "Distance for inter-area routes\n"
7496 "External routes\n"
7497 "Distance for external routes\n")
718e3744 7498{
cdc2d765 7499 VTY_DECLVAR_CONTEXT(ospf, ospf);
eaa1ae0d 7500 int idx = 0;
718e3744 7501
7c8ff89e
DS
7502 if (!ospf)
7503 return CMD_SUCCESS;
7504
eaa1ae0d
QY
7505 if (argv_find (argv, argc, "intra-area", &idx) || argc == 3)
7506 idx = ospf->distance_intra = 0;
7507 if (argv_find (argv, argc, "inter-area", &idx) || argc == 3)
7508 idx = ospf->distance_inter = 0;
7509 if (argv_find (argv, argc, "external", &idx) || argc == 3)
6f2a6703 7510 ospf->distance_external = 0;
718e3744 7511
718e3744 7512 return CMD_SUCCESS;
7513}
7514
6f2a6703
CF
7515DEFUN (ospf_distance_ospf,
7516 ospf_distance_ospf_cmd,
eaa1ae0d
QY
7517 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
7518 "Administrative distance\n"
7519 "OSPF administrative distance\n"
718e3744 7520 "Intra-area routes\n"
7521 "Distance for intra-area routes\n"
718e3744 7522 "Inter-area routes\n"
7523 "Distance for inter-area routes\n"
7524 "External routes\n"
718e3744 7525 "Distance for external routes\n")
7526{
cdc2d765 7527 VTY_DECLVAR_CONTEXT(ospf, ospf);
eaa1ae0d 7528 int idx = 0;
68980084 7529
eaa1ae0d
QY
7530 if (argv_find (argv, argc, "intra-area", &idx))
7531 ospf->distance_intra = atoi(argv[idx + 1]->arg);
7532 idx = 0;
7533 if (argv_find (argv, argc, "inter-area", &idx))
7534 ospf->distance_inter = atoi(argv[idx + 1]->arg);
7535 idx = 0;
7536 if (argv_find (argv, argc, "external", &idx))
7537 ospf->distance_external = atoi(argv[idx + 1]->arg);
68980084 7538
718e3744 7539 return CMD_SUCCESS;
7540}
7541
d7d73ffc 7542#if 0
718e3744 7543DEFUN (ospf_distance_source,
7544 ospf_distance_source_cmd,
6147e2c6 7545 "distance (1-255) A.B.C.D/M",
718e3744 7546 "Administrative distance\n"
7547 "Distance value\n"
7548 "IP source prefix\n")
7549{
cdc2d765 7550 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7551 int idx_number = 1;
7552 int idx_ipv4_prefixlen = 2;
020709f9 7553
7c8ff89e
DS
7554 if (!ospf)
7555 return CMD_SUCCESS;
7556
8d769265 7557 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
68980084 7558
718e3744 7559 return CMD_SUCCESS;
7560}
7561
7562DEFUN (no_ospf_distance_source,
7563 no_ospf_distance_source_cmd,
6147e2c6 7564 "no distance (1-255) A.B.C.D/M",
718e3744 7565 NO_STR
7566 "Administrative distance\n"
7567 "Distance value\n"
7568 "IP source prefix\n")
7569{
cdc2d765 7570 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7571 int idx_number = 2;
7572 int idx_ipv4_prefixlen = 3;
020709f9 7573
7c8ff89e
DS
7574 if (!ospf)
7575 return CMD_SUCCESS;
7576
8d769265 7577 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
020709f9 7578
718e3744 7579 return CMD_SUCCESS;
7580}
7581
7582DEFUN (ospf_distance_source_access_list,
7583 ospf_distance_source_access_list_cmd,
6147e2c6 7584 "distance (1-255) A.B.C.D/M WORD",
718e3744 7585 "Administrative distance\n"
7586 "Distance value\n"
7587 "IP source prefix\n"
7588 "Access list name\n")
7589{
cdc2d765 7590 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7591 int idx_number = 1;
7592 int idx_ipv4_prefixlen = 2;
7593 int idx_word = 3;
020709f9 7594
7c8ff89e
DS
7595 if (!ospf)
7596 return CMD_SUCCESS;
7597
8d769265 7598 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 7599
718e3744 7600 return CMD_SUCCESS;
7601}
7602
7603DEFUN (no_ospf_distance_source_access_list,
7604 no_ospf_distance_source_access_list_cmd,
6147e2c6 7605 "no distance (1-255) A.B.C.D/M WORD",
718e3744 7606 NO_STR
7607 "Administrative distance\n"
7608 "Distance value\n"
7609 "IP source prefix\n"
7610 "Access list name\n")
7611{
cdc2d765 7612 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7613 int idx_number = 2;
7614 int idx_ipv4_prefixlen = 3;
7615 int idx_word = 4;
020709f9 7616
7c8ff89e
DS
7617 if (!ospf)
7618 return CMD_SUCCESS;
7619
8d769265 7620 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 7621
718e3744 7622 return CMD_SUCCESS;
7623}
d7d73ffc 7624#endif
718e3744 7625
ba682537 7626DEFUN (ip_ospf_mtu_ignore,
7627 ip_ospf_mtu_ignore_addr_cmd,
7a7be519 7628 "ip ospf mtu-ignore [A.B.C.D]",
ba682537 7629 "IP Information\n"
7630 "OSPF interface commands\n"
99a522c7 7631 "Disable MTU mismatch detection on this interface\n"
ba682537 7632 "Address of interface")
7633{
cdc2d765 7634 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 7635 int idx_ipv4 = 3;
ba682537 7636 struct in_addr addr;
7637 int ret;
7638
7639 struct ospf_if_params *params;
7640 params = IF_DEF_PARAMS (ifp);
7641
7a7be519 7642 if (argc == 4)
ba682537 7643 {
8d769265 7644 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
ba682537 7645 if (!ret)
7646 {
7647 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7648 VTY_NEWLINE);
7649 return CMD_WARNING;
7650 }
7651 params = ospf_get_if_params (ifp, addr);
7652 ospf_if_update_params (ifp, addr);
7653 }
7654 params->mtu_ignore = 1;
7655 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7656 SET_IF_PARAM (params, mtu_ignore);
7657 else
7658 {
7659 UNSET_IF_PARAM (params, mtu_ignore);
7660 if (params != IF_DEF_PARAMS (ifp))
7661 {
7662 ospf_free_if_params (ifp, addr);
7663 ospf_if_update_params (ifp, addr);
7664 }
7665 }
7666 return CMD_SUCCESS;
7667}
7668
ba682537 7669DEFUN (no_ip_ospf_mtu_ignore,
7670 no_ip_ospf_mtu_ignore_addr_cmd,
7a7be519 7671 "no ip ospf mtu-ignore [A.B.C.D]",
ba682537 7672 "IP Information\n"
7673 "OSPF interface commands\n"
99a522c7 7674 "Disable MTU mismatch detection on this interface\n"
ba682537 7675 "Address of interface")
7676{
cdc2d765 7677 VTY_DECLVAR_CONTEXT(interface, ifp);
8d769265 7678 int idx_ipv4 = 4;
ba682537 7679 struct in_addr addr;
7680 int ret;
7681
7682 struct ospf_if_params *params;
7683 params = IF_DEF_PARAMS (ifp);
7684
7a7be519 7685 if (argc == 5)
ba682537 7686 {
8d769265 7687 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
ba682537 7688 if (!ret)
7689 {
7690 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7691 VTY_NEWLINE);
7692 return CMD_WARNING;
7693 }
7694 params = ospf_get_if_params (ifp, addr);
7695 ospf_if_update_params (ifp, addr);
7696 }
7697 params->mtu_ignore = 0;
7698 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7699 SET_IF_PARAM (params, mtu_ignore);
7700 else
7701 {
7702 UNSET_IF_PARAM (params, mtu_ignore);
7703 if (params != IF_DEF_PARAMS (ifp))
7704 {
7705 ospf_free_if_params (ifp, addr);
7706 ospf_if_update_params (ifp, addr);
7707 }
7708 }
7709 return CMD_SUCCESS;
7710}
7711
6b0655a2 7712
88d6cf37 7713DEFUN (ospf_max_metric_router_lsa_admin,
7714 ospf_max_metric_router_lsa_admin_cmd,
7715 "max-metric router-lsa administrative",
7716 "OSPF maximum / infinite-distance metric\n"
7717 "Advertise own Router-LSA with infinite distance (stub router)\n"
7718 "Administratively applied, for an indefinite period\n")
7719{
cdc2d765 7720 VTY_DECLVAR_CONTEXT(ospf, ospf);
88d6cf37 7721 struct listnode *ln;
7722 struct ospf_area *area;
7c8ff89e 7723
88d6cf37 7724 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7725 {
7726 SET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
7727
7728 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
c363d386 7729 ospf_router_lsa_update_area (area);
88d6cf37 7730 }
4ba4fc85
AB
7731
7732 /* Allows for areas configured later to get the property */
7733 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
7734
88d6cf37 7735 return CMD_SUCCESS;
7736}
7737
7738DEFUN (no_ospf_max_metric_router_lsa_admin,
7739 no_ospf_max_metric_router_lsa_admin_cmd,
7740 "no max-metric router-lsa administrative",
7741 NO_STR
7742 "OSPF maximum / infinite-distance metric\n"
7743 "Advertise own Router-LSA with infinite distance (stub router)\n"
7744 "Administratively applied, for an indefinite period\n")
7745{
cdc2d765 7746 VTY_DECLVAR_CONTEXT(ospf, ospf);
88d6cf37 7747 struct listnode *ln;
7748 struct ospf_area *area;
7c8ff89e 7749
88d6cf37 7750 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7751 {
7752 UNSET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
7753
7754 /* Don't trample on the start-up stub timer */
7755 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)
7756 && !area->t_stub_router)
7757 {
7758 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
c363d386 7759 ospf_router_lsa_update_area (area);
88d6cf37 7760 }
7761 }
4ba4fc85 7762 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
88d6cf37 7763 return CMD_SUCCESS;
7764}
7765
7766DEFUN (ospf_max_metric_router_lsa_startup,
7767 ospf_max_metric_router_lsa_startup_cmd,
6147e2c6 7768 "max-metric router-lsa on-startup (5-86400)",
88d6cf37 7769 "OSPF maximum / infinite-distance metric\n"
7770 "Advertise own Router-LSA with infinite distance (stub router)\n"
7771 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7772 "Time (seconds) to advertise self as stub-router\n")
7773{
cdc2d765 7774 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7775 int idx_number = 3;
88d6cf37 7776 unsigned int seconds;
7c8ff89e 7777
88d6cf37 7778 if (argc != 1)
7779 {
7780 vty_out (vty, "%% Must supply stub-router period");
7781 return CMD_WARNING;
7782 }
7783
8d769265 7784 VTY_GET_INTEGER ("stub-router startup period", seconds, argv[idx_number]->arg);
88d6cf37 7785
7786 ospf->stub_router_startup_time = seconds;
7787
7788 return CMD_SUCCESS;
7789}
7790
7791DEFUN (no_ospf_max_metric_router_lsa_startup,
7792 no_ospf_max_metric_router_lsa_startup_cmd,
7a7be519 7793 "no max-metric router-lsa on-startup [(5-86400)]",
88d6cf37 7794 NO_STR
7795 "OSPF maximum / infinite-distance metric\n"
7796 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
7797 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7798 "Time (seconds) to advertise self as stub-router\n")
88d6cf37 7799{
cdc2d765 7800 VTY_DECLVAR_CONTEXT(ospf, ospf);
88d6cf37 7801 struct listnode *ln;
7802 struct ospf_area *area;
7c8ff89e 7803
88d6cf37 7804 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7805
7806 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7807 {
7808 SET_FLAG (area->stub_router_state, OSPF_AREA_WAS_START_STUB_ROUTED);
7809 OSPF_TIMER_OFF (area->t_stub_router);
7810
7811 /* Don't trample on admin stub routed */
7812 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
7813 {
7814 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
c363d386 7815 ospf_router_lsa_update_area (area);
88d6cf37 7816 }
7817 }
7818 return CMD_SUCCESS;
7819}
7820
a1afa410 7821
88d6cf37 7822DEFUN (ospf_max_metric_router_lsa_shutdown,
7823 ospf_max_metric_router_lsa_shutdown_cmd,
6147e2c6 7824 "max-metric router-lsa on-shutdown (5-100)",
88d6cf37 7825 "OSPF maximum / infinite-distance metric\n"
7826 "Advertise own Router-LSA with infinite distance (stub router)\n"
7827 "Advertise stub-router prior to full shutdown of OSPF\n"
7828 "Time (seconds) to wait till full shutdown\n")
7829{
cdc2d765 7830 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265 7831 int idx_number = 3;
88d6cf37 7832 unsigned int seconds;
7c8ff89e 7833
88d6cf37 7834 if (argc != 1)
7835 {
7836 vty_out (vty, "%% Must supply stub-router shutdown period");
7837 return CMD_WARNING;
7838 }
7839
8d769265 7840 VTY_GET_INTEGER ("stub-router shutdown wait period", seconds, argv[idx_number]->arg);
88d6cf37 7841
7842 ospf->stub_router_shutdown_time = seconds;
7843
7844 return CMD_SUCCESS;
7845}
7846
7847DEFUN (no_ospf_max_metric_router_lsa_shutdown,
7848 no_ospf_max_metric_router_lsa_shutdown_cmd,
7a7be519 7849 "no max-metric router-lsa on-shutdown [(5-100)]",
88d6cf37 7850 NO_STR
7851 "OSPF maximum / infinite-distance metric\n"
7852 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
7853 "Advertise stub-router prior to full shutdown of OSPF\n"
7854 "Time (seconds) to wait till full shutdown\n")
88d6cf37 7855{
cdc2d765 7856 VTY_DECLVAR_CONTEXT(ospf, ospf);
7c8ff89e 7857
88d6cf37 7858 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7859
7860 return CMD_SUCCESS;
7861}
7862
a636c635
DW
7863static void
7864config_write_stub_router (struct vty *vty, struct ospf *ospf)
88d6cf37 7865{
7866 struct listnode *ln;
7867 struct ospf_area *area;
7868
7869 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7870 vty_out (vty, " max-metric router-lsa on-startup %u%s",
7871 ospf->stub_router_startup_time, VTY_NEWLINE);
7872 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7873 vty_out (vty, " max-metric router-lsa on-shutdown %u%s",
7874 ospf->stub_router_shutdown_time, VTY_NEWLINE);
7875 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7876 {
7877 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
7878 {
7879 vty_out (vty, " max-metric router-lsa administrative%s",
7880 VTY_NEWLINE);
7881 break;
7882 }
7883 }
7884 return;
7885}
6b0655a2 7886
4dadc291 7887static void
718e3744 7888show_ip_ospf_route_network (struct vty *vty, struct route_table *rt)
7889{
7890 struct route_node *rn;
7891 struct ospf_route *or;
1eb8ef25 7892 struct listnode *pnode, *pnnode;
718e3744 7893 struct ospf_path *path;
7894
7895 vty_out (vty, "============ OSPF network routing table ============%s",
7896 VTY_NEWLINE);
7897
7898 for (rn = route_top (rt); rn; rn = route_next (rn))
7899 if ((or = rn->info) != NULL)
7900 {
7901 char buf1[19];
7902 snprintf (buf1, 19, "%s/%d",
7903 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
7904
7905 switch (or->path_type)
7906 {
7907 case OSPF_PATH_INTER_AREA:
7908 if (or->type == OSPF_DESTINATION_NETWORK)
7909 vty_out (vty, "N IA %-18s [%d] area: %s%s", buf1, or->cost,
7910 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
7911 else if (or->type == OSPF_DESTINATION_DISCARD)
7912 vty_out (vty, "D IA %-18s Discard entry%s", buf1, VTY_NEWLINE);
7913 break;
7914 case OSPF_PATH_INTRA_AREA:
7915 vty_out (vty, "N %-18s [%d] area: %s%s", buf1, or->cost,
7916 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
7917 break;
7918 default:
7919 break;
7920 }
7921
7922 if (or->type == OSPF_DESTINATION_NETWORK)
1eb8ef25 7923 for (ALL_LIST_ELEMENTS (or->paths, pnode, pnnode, path))
96735eea 7924 {
7e2b7603 7925 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
96735eea 7926 {
7927 if (path->nexthop.s_addr == 0)
7928 vty_out (vty, "%24s directly attached to %s%s",
baaea325 7929 "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
96735eea 7930 else
7931 vty_out (vty, "%24s via %s, %s%s", "",
a8ba847f 7932 inet_ntoa (path->nexthop),
baaea325 7933 ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
96735eea 7934 }
7935 }
718e3744 7936 }
7937 vty_out (vty, "%s", VTY_NEWLINE);
7938}
7939
4dadc291 7940static void
718e3744 7941show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs)
7942{
7943 struct route_node *rn;
7944 struct ospf_route *or;
1eb8ef25 7945 struct listnode *pnode;
7946 struct listnode *node;
718e3744 7947 struct ospf_path *path;
7948
7949 vty_out (vty, "============ OSPF router routing table =============%s",
7950 VTY_NEWLINE);
7951 for (rn = route_top (rtrs); rn; rn = route_next (rn))
7952 if (rn->info)
7953 {
7954 int flag = 0;
7955
7956 vty_out (vty, "R %-15s ", inet_ntoa (rn->p.u.prefix4));
7957
1eb8ef25 7958 for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, or))
7959 {
7960 if (flag++)
7961 vty_out (vty, "%24s", "");
7962
7963 /* Show path. */
7964 vty_out (vty, "%s [%d] area: %s",
7965 (or->path_type == OSPF_PATH_INTER_AREA ? "IA" : " "),
7966 or->cost, inet_ntoa (or->u.std.area_id));
7967 /* Show flags. */
7968 vty_out (vty, "%s%s%s",
7969 (or->u.std.flags & ROUTER_LSA_BORDER ? ", ABR" : ""),
7970 (or->u.std.flags & ROUTER_LSA_EXTERNAL ? ", ASBR" : ""),
7971 VTY_NEWLINE);
7972
7973 for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path))
7974 {
7e2b7603 7975 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
54bedb55 7976 {
7977 if (path->nexthop.s_addr == 0)
7978 vty_out (vty, "%24s directly attached to %s%s",
baaea325 7979 "", ifindex2ifname (path->ifindex, VRF_DEFAULT),
a8ba847f 7980 VTY_NEWLINE);
54bedb55 7981 else
7982 vty_out (vty, "%24s via %s, %s%s", "",
7983 inet_ntoa (path->nexthop),
baaea325 7984 ifindex2ifname (path->ifindex, VRF_DEFAULT),
a8ba847f 7985 VTY_NEWLINE);
54bedb55 7986 }
1eb8ef25 7987 }
7988 }
718e3744 7989 }
7990 vty_out (vty, "%s", VTY_NEWLINE);
7991}
7992
4dadc291 7993static void
718e3744 7994show_ip_ospf_route_external (struct vty *vty, struct route_table *rt)
7995{
7996 struct route_node *rn;
7997 struct ospf_route *er;
1eb8ef25 7998 struct listnode *pnode, *pnnode;
718e3744 7999 struct ospf_path *path;
8000
8001 vty_out (vty, "============ OSPF external routing table ===========%s",
8002 VTY_NEWLINE);
8003 for (rn = route_top (rt); rn; rn = route_next (rn))
8004 if ((er = rn->info) != NULL)
8005 {
8006 char buf1[19];
8007 snprintf (buf1, 19, "%s/%d",
8008 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
8009
8010 switch (er->path_type)
8011 {
8012 case OSPF_PATH_TYPE1_EXTERNAL:
dc9ffce8 8013 vty_out (vty, "N E1 %-18s [%d] tag: %"ROUTE_TAG_PRI"%s", buf1,
718e3744 8014 er->cost, er->u.ext.tag, VTY_NEWLINE);
8015 break;
8016 case OSPF_PATH_TYPE2_EXTERNAL:
dc9ffce8 8017 vty_out (vty, "N E2 %-18s [%d/%d] tag: %"ROUTE_TAG_PRI"%s", buf1, er->cost,
718e3744 8018 er->u.ext.type2_cost, er->u.ext.tag, VTY_NEWLINE);
8019 break;
8020 }
8021
1eb8ef25 8022 for (ALL_LIST_ELEMENTS (er->paths, pnode, pnnode, path))
718e3744 8023 {
7e2b7603 8024 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
718e3744 8025 {
8026 if (path->nexthop.s_addr == 0)
96735eea 8027 vty_out (vty, "%24s directly attached to %s%s",
baaea325 8028 "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
96735eea 8029 else
8030 vty_out (vty, "%24s via %s, %s%s", "",
a8ba847f 8031 inet_ntoa (path->nexthop),
baaea325 8032 ifindex2ifname (path->ifindex, VRF_DEFAULT),
96735eea 8033 VTY_NEWLINE);
718e3744 8034 }
8035 }
8036 }
8037 vty_out (vty, "%s", VTY_NEWLINE);
8038}
8039
7c8ff89e
DS
8040static int
8041show_ip_ospf_border_routers_common (struct vty *vty, struct ospf *ospf)
718e3744 8042{
7c8ff89e
DS
8043 if (ospf->instance)
8044 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
8045 VTY_NEWLINE, VTY_NEWLINE);
718e3744 8046
68980084 8047 if (ospf->new_table == NULL)
718e3744 8048 {
8049 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
8050 return CMD_SUCCESS;
8051 }
8052
8053 /* Show Network routes.
020709f9 8054 show_ip_ospf_route_network (vty, ospf->new_table); */
718e3744 8055
8056 /* Show Router routes. */
68980084 8057 show_ip_ospf_route_router (vty, ospf->new_rtrs);
718e3744 8058
7c8ff89e
DS
8059 vty_out (vty, "%s", VTY_NEWLINE);
8060
718e3744 8061 return CMD_SUCCESS;
8062}
718e3744 8063
7c8ff89e
DS
8064DEFUN (show_ip_ospf_border_routers,
8065 show_ip_ospf_border_routers_cmd,
8066 "show ip ospf border-routers",
718e3744 8067 SHOW_STR
8068 IP_STR
8069 "OSPF information\n"
7c8ff89e 8070 "Show all the ABR's and ASBR's\n")
718e3744 8071{
020709f9 8072 struct ospf *ospf;
68980084 8073
0bad4851 8074 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
7c8ff89e
DS
8075 return CMD_SUCCESS;
8076
8077 return show_ip_ospf_border_routers_common(vty, ospf);
8078}
8079
8080DEFUN (show_ip_ospf_instance_border_routers,
8081 show_ip_ospf_instance_border_routers_cmd,
6147e2c6 8082 "show ip ospf (1-65535) border-routers",
7c8ff89e
DS
8083 SHOW_STR
8084 IP_STR
8085 "OSPF information\n"
8086 "Instance ID\n"
8087 "Show all the ABR's and ASBR's\n")
8088{
8d769265 8089 int idx_number = 3;
7c8ff89e
DS
8090 struct ospf *ospf;
8091 u_short instance = 0;
8092
8d769265 8093 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 8094 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
8095 return CMD_SUCCESS;
8096
8097 return show_ip_ospf_border_routers_common(vty, ospf);
8098}
8099
8100static int
8101show_ip_ospf_route_common (struct vty *vty, struct ospf *ospf)
8102{
8103 if (ospf->instance)
8104 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
8105 VTY_NEWLINE, VTY_NEWLINE);
718e3744 8106
68980084 8107 if (ospf->new_table == NULL)
718e3744 8108 {
8109 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
8110 return CMD_SUCCESS;
8111 }
8112
8113 /* Show Network routes. */
68980084 8114 show_ip_ospf_route_network (vty, ospf->new_table);
718e3744 8115
8116 /* Show Router routes. */
68980084 8117 show_ip_ospf_route_router (vty, ospf->new_rtrs);
718e3744 8118
8119 /* Show AS External routes. */
68980084 8120 show_ip_ospf_route_external (vty, ospf->old_external_route);
718e3744 8121
7c8ff89e
DS
8122 vty_out (vty, "%s", VTY_NEWLINE);
8123
718e3744 8124 return CMD_SUCCESS;
8125}
8126
7c8ff89e
DS
8127DEFUN (show_ip_ospf_route,
8128 show_ip_ospf_route_cmd,
8129 "show ip ospf route",
8130 SHOW_STR
8131 IP_STR
8132 "OSPF information\n"
8133 "OSPF routing table\n")
8134{
8135 struct ospf *ospf;
8136
0bad4851 8137 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
7c8ff89e
DS
8138 return CMD_SUCCESS;
8139
8140 return show_ip_ospf_route_common(vty, ospf);
8141}
8142
8143DEFUN (show_ip_ospf_instance_route,
8144 show_ip_ospf_instance_route_cmd,
6147e2c6 8145 "show ip ospf (1-65535) route",
7c8ff89e
DS
8146 SHOW_STR
8147 IP_STR
8148 "OSPF information\n"
8149 "Instance ID\n"
8150 "OSPF routing table\n")
8151{
8d769265 8152 int idx_number = 3;
7c8ff89e
DS
8153 struct ospf *ospf;
8154 u_short instance = 0;
8155
8d769265 8156 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
0bad4851 8157 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
7c8ff89e
DS
8158 return CMD_SUCCESS;
8159
8160 return show_ip_ospf_route_common(vty, ospf);
8161}
6b0655a2 8162
eb1ce605 8163const char *ospf_abr_type_str[] =
718e3744 8164{
8165 "unknown",
8166 "standard",
8167 "ibm",
8168 "cisco",
8169 "shortcut"
8170};
8171
eb1ce605 8172const char *ospf_shortcut_mode_str[] =
718e3744 8173{
8174 "default",
8175 "enable",
8176 "disable"
8177};
8178
8179
4dadc291 8180static void
718e3744 8181area_id2str (char *buf, int length, struct ospf_area *area)
8182{
8183 memset (buf, 0, length);
8184
8185 if (area->format == OSPF_AREA_ID_FORMAT_ADDRESS)
8186 strncpy (buf, inet_ntoa (area->area_id), length);
8187 else
8188 sprintf (buf, "%lu", (unsigned long) ntohl (area->area_id.s_addr));
8189}
8190
6b0655a2 8191
eb1ce605 8192const char *ospf_int_type_str[] =
718e3744 8193{
8194 "unknown", /* should never be used. */
8195 "point-to-point",
8196 "broadcast",
8197 "non-broadcast",
8198 "point-to-multipoint",
8199 "virtual-link", /* should never be used. */
8200 "loopback"
8201};
8202
8203/* Configuration write function for ospfd. */
4dadc291 8204static int
718e3744 8205config_write_interface (struct vty *vty)
8206{
52dc7ee6 8207 struct listnode *n1, *n2;
718e3744 8208 struct interface *ifp;
8209 struct crypt_key *ck;
8210 int write = 0;
8211 struct route_node *rn = NULL;
8212 struct ospf_if_params *params;
7c8ff89e 8213 struct ospf *ospf = ospf_lookup();
718e3744 8214
b2d7c082 8215 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), n1, ifp))
718e3744 8216 {
718e3744 8217 if (memcmp (ifp->name, "VLINK", 5) == 0)
8218 continue;
8219
84361d61
DS
8220 if (ifp->ifindex == IFINDEX_DELETED)
8221 continue;
8222
718e3744 8223 vty_out (vty, "!%s", VTY_NEWLINE);
8224 vty_out (vty, "interface %s%s", ifp->name,
8225 VTY_NEWLINE);
8226 if (ifp->desc)
8227 vty_out (vty, " description %s%s", ifp->desc,
8228 VTY_NEWLINE);
8229
8230 write++;
8231
8232 params = IF_DEF_PARAMS (ifp);
8233
8234 do {
8235 /* Interface Network print. */
8236 if (OSPF_IF_PARAM_CONFIGURED (params, type) &&
718e3744 8237 params->type != OSPF_IFTYPE_LOOPBACK)
8238 {
bc18d616 8239 if (params->type != ospf_default_iftype(ifp))
7b90143f 8240 {
8241 vty_out (vty, " ip ospf network %s",
8242 ospf_int_type_str[params->type]);
8243 if (params != IF_DEF_PARAMS (ifp))
8244 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8245 vty_out (vty, "%s", VTY_NEWLINE);
8246 }
718e3744 8247 }
8248
8249 /* OSPF interface authentication print */
8250 if (OSPF_IF_PARAM_CONFIGURED (params, auth_type) &&
8251 params->auth_type != OSPF_AUTH_NOTSET)
8252 {
eb1ce605 8253 const char *auth_str;
718e3744 8254
8255 /* Translation tables are not that much help here due to syntax
8256 of the simple option */
8257 switch (params->auth_type)
8258 {
8259
8260 case OSPF_AUTH_NULL:
8261 auth_str = " null";
8262 break;
8263
8264 case OSPF_AUTH_SIMPLE:
8265 auth_str = "";
8266 break;
8267
8268 case OSPF_AUTH_CRYPTOGRAPHIC:
8269 auth_str = " message-digest";
8270 break;
8271
8272 default:
8273 auth_str = "";
8274 break;
8275 }
8276
8277 vty_out (vty, " ip ospf authentication%s", auth_str);
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 /* Simple Authentication Password print. */
8284 if (OSPF_IF_PARAM_CONFIGURED (params, auth_simple) &&
8285 params->auth_simple[0] != '\0')
8286 {
8287 vty_out (vty, " ip ospf authentication-key %s",
8288 params->auth_simple);
8289 if (params != IF_DEF_PARAMS (ifp))
8290 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8291 vty_out (vty, "%s", VTY_NEWLINE);
8292 }
8293
8294 /* Cryptographic Authentication Key print. */
1eb8ef25 8295 for (ALL_LIST_ELEMENTS_RO (params->auth_crypt, n2, ck))
718e3744 8296 {
718e3744 8297 vty_out (vty, " ip ospf message-digest-key %d md5 %s",
7c8ff89e 8298 ck->key_id, ck->auth_key);
718e3744 8299 if (params != IF_DEF_PARAMS (ifp))
8300 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8301 vty_out (vty, "%s", VTY_NEWLINE);
8302 }
8303
8304 /* Interface Output Cost print. */
8305 if (OSPF_IF_PARAM_CONFIGURED (params, output_cost_cmd))
8306 {
8307 vty_out (vty, " ip ospf cost %u", params->output_cost_cmd);
8308 if (params != IF_DEF_PARAMS (ifp))
8309 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8310 vty_out (vty, "%s", VTY_NEWLINE);
8311 }
8312
8313 /* Hello Interval print. */
8314 if (OSPF_IF_PARAM_CONFIGURED (params, v_hello) &&
8315 params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT)
8316 {
8317 vty_out (vty, " ip ospf hello-interval %u", params->v_hello);
8318 if (params != IF_DEF_PARAMS (ifp))
8319 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8320 vty_out (vty, "%s", VTY_NEWLINE);
8321 }
8322
8323
8324 /* Router Dead Interval print. */
8325 if (OSPF_IF_PARAM_CONFIGURED (params, v_wait) &&
8326 params->v_wait != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT)
8327 {
f9ad937f 8328 vty_out (vty, " ip ospf dead-interval ");
8329
8330 /* fast hello ? */
8331 if (OSPF_IF_PARAM_CONFIGURED (params, fast_hello))
8332 vty_out (vty, "minimal hello-multiplier %d",
8333 params->fast_hello);
8334 else
8335 vty_out (vty, "%u", params->v_wait);
8336
718e3744 8337 if (params != IF_DEF_PARAMS (ifp))
8338 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8339 vty_out (vty, "%s", VTY_NEWLINE);
8340 }
8341
8342 /* Router Priority print. */
8343 if (OSPF_IF_PARAM_CONFIGURED (params, priority) &&
8344 params->priority != OSPF_ROUTER_PRIORITY_DEFAULT)
8345 {
8346 vty_out (vty, " ip ospf priority %u", params->priority);
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 /* Retransmit Interval print. */
8353 if (OSPF_IF_PARAM_CONFIGURED (params, retransmit_interval) &&
8354 params->retransmit_interval != OSPF_RETRANSMIT_INTERVAL_DEFAULT)
8355 {
8356 vty_out (vty, " ip ospf retransmit-interval %u",
8357 params->retransmit_interval);
8358 if (params != IF_DEF_PARAMS (ifp))
8359 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8360 vty_out (vty, "%s", VTY_NEWLINE);
8361 }
8362
8363 /* Transmit Delay print. */
8364 if (OSPF_IF_PARAM_CONFIGURED (params, transmit_delay) &&
8365 params->transmit_delay != OSPF_TRANSMIT_DELAY_DEFAULT)
8366 {
8367 vty_out (vty, " ip ospf transmit-delay %u", params->transmit_delay);
8368 if (params != IF_DEF_PARAMS (ifp))
8369 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8370 vty_out (vty, "%s", VTY_NEWLINE);
8371 }
8372
953cde65
JT
8373 /* Area print. */
8374 if (OSPF_IF_PARAM_CONFIGURED (params, if_area))
8375 {
8376 if (ospf->instance)
8377 vty_out (vty, " ip ospf %d area %s%s", ospf->instance,
8378 inet_ntoa (params->if_area), VTY_NEWLINE);
8379 else
8380 vty_out (vty, " ip ospf area %s%s",
8381 inet_ntoa (params->if_area), VTY_NEWLINE);
8382
8383 }
8384
d5a5c8f0 8385 /* bfd print. */
7f342629 8386 ospf_bfd_write_config(vty, params);
d5a5c8f0 8387
ba682537 8388 /* MTU ignore print. */
8389 if (OSPF_IF_PARAM_CONFIGURED (params, mtu_ignore) &&
8390 params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8391 {
8392 if (params->mtu_ignore == 0)
8393 vty_out (vty, " no ip ospf mtu-ignore");
8394 else
8395 vty_out (vty, " ip ospf mtu-ignore");
8396 if (params != IF_DEF_PARAMS (ifp))
8397 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8398 vty_out (vty, "%s", VTY_NEWLINE);
8399 }
8400
8401
718e3744 8402 while (1)
8403 {
8404 if (rn == NULL)
8405 rn = route_top (IF_OIFS_PARAMS (ifp));
8406 else
8407 rn = route_next (rn);
8408
8409 if (rn == NULL)
8410 break;
8411 params = rn->info;
8412 if (params != NULL)
8413 break;
8414 }
8415 } while (rn);
8416
718e3744 8417 ospf_opaque_config_write_if (vty, ifp);
718e3744 8418 }
8419
8420 return write;
8421}
8422
4dadc291 8423static int
68980084 8424config_write_network_area (struct vty *vty, struct ospf *ospf)
718e3744 8425{
8426 struct route_node *rn;
8427 u_char buf[INET_ADDRSTRLEN];
8428
8429 /* `network area' print. */
68980084 8430 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
718e3744 8431 if (rn->info)
8432 {
8433 struct ospf_network *n = rn->info;
8434
8435 memset (buf, 0, INET_ADDRSTRLEN);
8436
8437 /* Create Area ID string by specified Area ID format. */
8438 if (n->format == OSPF_AREA_ID_FORMAT_ADDRESS)
c9e52be3 8439 strncpy ((char *) buf, inet_ntoa (n->area_id), INET_ADDRSTRLEN);
718e3744 8440 else
c9e52be3 8441 sprintf ((char *) buf, "%lu",
718e3744 8442 (unsigned long int) ntohl (n->area_id.s_addr));
8443
8444 /* Network print. */
8445 vty_out (vty, " network %s/%d area %s%s",
8446 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8447 buf, VTY_NEWLINE);
8448 }
8449
8450 return 0;
8451}
8452
4dadc291 8453static int
68980084 8454config_write_ospf_area (struct vty *vty, struct ospf *ospf)
718e3744 8455{
52dc7ee6 8456 struct listnode *node;
1eb8ef25 8457 struct ospf_area *area;
718e3744 8458 u_char buf[INET_ADDRSTRLEN];
8459
8460 /* Area configuration print. */
1eb8ef25 8461 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
718e3744 8462 {
718e3744 8463 struct route_node *rn1;
8464
c9e52be3 8465 area_id2str ((char *) buf, INET_ADDRSTRLEN, area);
718e3744 8466
8467 if (area->auth_type != OSPF_AUTH_NULL)
8468 {
8469 if (area->auth_type == OSPF_AUTH_SIMPLE)
8470 vty_out (vty, " area %s authentication%s", buf, VTY_NEWLINE);
8471 else
8472 vty_out (vty, " area %s authentication message-digest%s",
8473 buf, VTY_NEWLINE);
8474 }
8475
8476 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
8477 vty_out (vty, " area %s shortcut %s%s", buf,
8478 ospf_shortcut_mode_str[area->shortcut_configured],
8479 VTY_NEWLINE);
8480
8481 if ((area->external_routing == OSPF_AREA_STUB)
718e3744 8482 || (area->external_routing == OSPF_AREA_NSSA)
718e3744 8483 )
8484 {
b0a053be 8485 if (area->external_routing == OSPF_AREA_STUB)
8486 vty_out (vty, " area %s stub", buf);
b0a053be 8487 else if (area->external_routing == OSPF_AREA_NSSA)
8488 {
8489 vty_out (vty, " area %s nssa", buf);
8490 switch (area->NSSATranslatorRole)
8491 {
8492 case OSPF_NSSA_ROLE_NEVER:
8493 vty_out (vty, " translate-never");
8494 break;
8495 case OSPF_NSSA_ROLE_ALWAYS:
8496 vty_out (vty, " translate-always");
8497 break;
8498 case OSPF_NSSA_ROLE_CANDIDATE:
8499 default:
8500 vty_out (vty, " translate-candidate");
8501 }
8502 }
718e3744 8503
8504 if (area->no_summary)
8505 vty_out (vty, " no-summary");
8506
8507 vty_out (vty, "%s", VTY_NEWLINE);
8508
8509 if (area->default_cost != 1)
8510 vty_out (vty, " area %s default-cost %d%s", buf,
8511 area->default_cost, VTY_NEWLINE);
8512 }
8513
8514 for (rn1 = route_top (area->ranges); rn1; rn1 = route_next (rn1))
8515 if (rn1->info)
8516 {
8517 struct ospf_area_range *range = rn1->info;
8518
8519 vty_out (vty, " area %s range %s/%d", buf,
8520 inet_ntoa (rn1->p.u.prefix4), rn1->p.prefixlen);
8521
6c835671 8522 if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
718e3744 8523 vty_out (vty, " cost %d", range->cost_config);
8524
8525 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
8526 vty_out (vty, " not-advertise");
8527
8528 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
8529 vty_out (vty, " substitute %s/%d",
8530 inet_ntoa (range->subst_addr), range->subst_masklen);
8531
8532 vty_out (vty, "%s", VTY_NEWLINE);
8533 }
8534
8535 if (EXPORT_NAME (area))
8536 vty_out (vty, " area %s export-list %s%s", buf,
8537 EXPORT_NAME (area), VTY_NEWLINE);
8538
8539 if (IMPORT_NAME (area))
8540 vty_out (vty, " area %s import-list %s%s", buf,
8541 IMPORT_NAME (area), VTY_NEWLINE);
8542
8543 if (PREFIX_NAME_IN (area))
8544 vty_out (vty, " area %s filter-list prefix %s in%s", buf,
8545 PREFIX_NAME_IN (area), VTY_NEWLINE);
8546
8547 if (PREFIX_NAME_OUT (area))
8548 vty_out (vty, " area %s filter-list prefix %s out%s", buf,
8549 PREFIX_NAME_OUT (area), VTY_NEWLINE);
8550 }
8551
8552 return 0;
8553}
8554
4dadc291 8555static int
68980084 8556config_write_ospf_nbr_nbma (struct vty *vty, struct ospf *ospf)
718e3744 8557{
8558 struct ospf_nbr_nbma *nbr_nbma;
8559 struct route_node *rn;
8560
8561 /* Static Neighbor configuration print. */
68980084 8562 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
718e3744 8563 if ((nbr_nbma = rn->info))
8564 {
8565 vty_out (vty, " neighbor %s", inet_ntoa (nbr_nbma->addr));
8566
8567 if (nbr_nbma->priority != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
8568 vty_out (vty, " priority %d", nbr_nbma->priority);
8569
8570 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
8571 vty_out (vty, " poll-interval %d", nbr_nbma->v_poll);
8572
8573 vty_out (vty, "%s", VTY_NEWLINE);
8574 }
8575
8576 return 0;
8577}
8578
4dadc291 8579static int
68980084 8580config_write_virtual_link (struct vty *vty, struct ospf *ospf)
718e3744 8581{
52dc7ee6 8582 struct listnode *node;
1eb8ef25 8583 struct ospf_vl_data *vl_data;
718e3744 8584 u_char buf[INET_ADDRSTRLEN];
8585
8586 /* Virtual-Link print */
1eb8ef25 8587 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
718e3744 8588 {
52dc7ee6 8589 struct listnode *n2;
718e3744 8590 struct crypt_key *ck;
718e3744 8591 struct ospf_interface *oi;
8592
8593 if (vl_data != NULL)
8594 {
8595 memset (buf, 0, INET_ADDRSTRLEN);
8596
8597 if (vl_data->format == OSPF_AREA_ID_FORMAT_ADDRESS)
c9e52be3 8598 strncpy ((char *) buf, inet_ntoa (vl_data->vl_area_id), INET_ADDRSTRLEN);
718e3744 8599 else
c9e52be3 8600 sprintf ((char *) buf, "%lu",
718e3744 8601 (unsigned long int) ntohl (vl_data->vl_area_id.s_addr));
8602 oi = vl_data->vl_oi;
8603
8604 /* timers */
8605 if (OSPF_IF_PARAM (oi, v_hello) != OSPF_HELLO_INTERVAL_DEFAULT ||
8606 OSPF_IF_PARAM (oi, v_wait) != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT ||
8607 OSPF_IF_PARAM (oi, retransmit_interval) != OSPF_RETRANSMIT_INTERVAL_DEFAULT ||
8608 OSPF_IF_PARAM (oi, transmit_delay) != OSPF_TRANSMIT_DELAY_DEFAULT)
8609 vty_out (vty, " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d%s",
8610 buf,
8611 inet_ntoa (vl_data->vl_peer),
8612 OSPF_IF_PARAM (oi, v_hello),
8613 OSPF_IF_PARAM (oi, retransmit_interval),
8614 OSPF_IF_PARAM (oi, transmit_delay),
8615 OSPF_IF_PARAM (oi, v_wait),
8616 VTY_NEWLINE);
8617 else
8618 vty_out (vty, " area %s virtual-link %s%s", buf,
8619 inet_ntoa (vl_data->vl_peer), VTY_NEWLINE);
8620 /* Auth key */
8621 if (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple[0] != '\0')
8622 vty_out (vty, " area %s virtual-link %s authentication-key %s%s",
8623 buf,
8624 inet_ntoa (vl_data->vl_peer),
8625 IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple,
8626 VTY_NEWLINE);
8627 /* md5 keys */
1eb8ef25 8628 for (ALL_LIST_ELEMENTS_RO (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_crypt,
8629 n2, ck))
8630 vty_out (vty, " area %s virtual-link %s"
8631 " message-digest-key %d md5 %s%s",
8632 buf,
8633 inet_ntoa (vl_data->vl_peer),
8634 ck->key_id, ck->auth_key, VTY_NEWLINE);
718e3744 8635
8636 }
8637 }
8638
8639 return 0;
8640}
8641
6b0655a2 8642
4dadc291 8643static int
68980084 8644config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
718e3744 8645{
8646 int type;
8647
8648 /* redistribute print. */
8649 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
7c8ff89e
DS
8650 {
8651 struct list *red_list;
8652 struct listnode *node;
8653 struct ospf_redist *red;
718e3744 8654
7c8ff89e
DS
8655 red_list = ospf->redist[type];
8656 if (!red_list)
8657 continue;
8658
8659 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
8660 {
8661 vty_out (vty, " redistribute %s", zebra_route_string(type));
8662 if (red->instance)
8663 vty_out (vty, " %d", red->instance);
8664
8665 if (red->dmetric.value >= 0)
8666 vty_out (vty, " metric %d", red->dmetric.value);
8667
8668 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8669 vty_out (vty, " metric-type 1");
8670
8671 if (ROUTEMAP_NAME (red))
8672 vty_out (vty, " route-map %s", ROUTEMAP_NAME (red));
8673
8674 vty_out (vty, "%s", VTY_NEWLINE);
8675 }
8676 }
718e3744 8677
8678 return 0;
8679}
8680
4dadc291 8681static int
68980084 8682config_write_ospf_default_metric (struct vty *vty, struct ospf *ospf)
718e3744 8683{
68980084 8684 if (ospf->default_metric != -1)
8685 vty_out (vty, " default-metric %d%s", ospf->default_metric,
718e3744 8686 VTY_NEWLINE);
8687 return 0;
8688}
8689
4dadc291 8690static int
68980084 8691config_write_ospf_distribute (struct vty *vty, struct ospf *ospf)
718e3744 8692{
8693 int type;
7c8ff89e 8694 struct ospf_redist *red;
718e3744 8695
68980084 8696 if (ospf)
718e3744 8697 {
8698 /* distribute-list print. */
8699 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
171c9a99 8700 if (DISTRIBUTE_NAME (ospf, type))
718e3744 8701 vty_out (vty, " distribute-list %s out %s%s",
171c9a99 8702 DISTRIBUTE_NAME (ospf, type),
f52d13cb 8703 zebra_route_string(type), VTY_NEWLINE);
718e3744 8704
8705 /* default-information print. */
68980084 8706 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE)
718e3744 8707 {
c42c177d 8708 vty_out (vty, " default-information originate");
8709 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
8710 vty_out (vty, " always");
718e3744 8711
7c8ff89e
DS
8712 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
8713 if (red)
8714 {
8715 if (red->dmetric.value >= 0)
8716 vty_out (vty, " metric %d",
8717 red->dmetric.value);
8718 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8719 vty_out (vty, " metric-type 1");
8720
8721 if (ROUTEMAP_NAME (red))
8722 vty_out (vty, " route-map %s",
8723 ROUTEMAP_NAME (red));
8724 }
718e3744 8725
8726 vty_out (vty, "%s", VTY_NEWLINE);
8727 }
8728
8729 }
8730
8731 return 0;
8732}
8733
4dadc291 8734static int
68980084 8735config_write_ospf_distance (struct vty *vty, struct ospf *ospf)
718e3744 8736{
8737 struct route_node *rn;
8738 struct ospf_distance *odistance;
8739
68980084 8740 if (ospf->distance_all)
8741 vty_out (vty, " distance %d%s", ospf->distance_all, VTY_NEWLINE);
718e3744 8742
68980084 8743 if (ospf->distance_intra
8744 || ospf->distance_inter
8745 || ospf->distance_external)
718e3744 8746 {
8747 vty_out (vty, " distance ospf");
8748
68980084 8749 if (ospf->distance_intra)
8750 vty_out (vty, " intra-area %d", ospf->distance_intra);
8751 if (ospf->distance_inter)
8752 vty_out (vty, " inter-area %d", ospf->distance_inter);
8753 if (ospf->distance_external)
8754 vty_out (vty, " external %d", ospf->distance_external);
718e3744 8755
8756 vty_out (vty, "%s", VTY_NEWLINE);
8757 }
8758
68980084 8759 for (rn = route_top (ospf->distance_table); rn; rn = route_next (rn))
718e3744 8760 if ((odistance = rn->info) != NULL)
8761 {
8762 vty_out (vty, " distance %d %s/%d %s%s", odistance->distance,
8763 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8764 odistance->access_list ? odistance->access_list : "",
8765 VTY_NEWLINE);
8766 }
8767 return 0;
8768}
8769
8770/* OSPF configuration write function. */
4dadc291 8771static int
718e3744 8772ospf_config_write (struct vty *vty)
8773{
020709f9 8774 struct ospf *ospf;
1eb8ef25 8775 struct interface *ifp;
8776 struct ospf_interface *oi;
52dc7ee6 8777 struct listnode *node;
718e3744 8778 int write = 0;
8779
020709f9 8780 ospf = ospf_lookup ();
0bad4851 8781 if (ospf != NULL && ospf->oi_running)
718e3744 8782 {
8783 /* `router ospf' print. */
7c8ff89e
DS
8784 if (ospf->instance)
8785 vty_out (vty, "router ospf %d%s", ospf->instance, VTY_NEWLINE);
8786 else
8787 vty_out (vty, "router ospf%s", VTY_NEWLINE);
718e3744 8788
8789 write++;
8790
68980084 8791 if (!ospf->networks)
718e3744 8792 return write;
8793
8794 /* Router ID print. */
68980084 8795 if (ospf->router_id_static.s_addr != 0)
718e3744 8796 vty_out (vty, " ospf router-id %s%s",
68980084 8797 inet_ntoa (ospf->router_id_static), VTY_NEWLINE);
718e3744 8798
8799 /* ABR type print. */
d57834f6 8800 if (ospf->abr_type != OSPF_ABR_DEFAULT)
718e3744 8801 vty_out (vty, " ospf abr-type %s%s",
68980084 8802 ospf_abr_type_str[ospf->abr_type], VTY_NEWLINE);
718e3744 8803
d7e60dd7
AS
8804 /* log-adjacency-changes flag print. */
8805 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES))
8806 {
d7e60dd7 8807 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
692c7954 8808 vty_out(vty, " log-adjacency-changes detail%s", VTY_NEWLINE);
d7e60dd7 8809 }
692c7954
DW
8810 else
8811 {
8812 vty_out(vty, " no log-adjacency-changes%s", VTY_NEWLINE);
8813 }
d7e60dd7 8814
718e3744 8815 /* RFC1583 compatibility flag print -- Compatible with CISCO 12.1. */
68980084 8816 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
718e3744 8817 vty_out (vty, " compatible rfc1583%s", VTY_NEWLINE);
8818
8819 /* auto-cost reference-bandwidth configuration. */
68980084 8820 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH)
f9ad937f 8821 {
8822 vty_out (vty, "! Important: ensure reference bandwidth "
8823 "is consistent across all routers%s", VTY_NEWLINE);
8824 vty_out (vty, " auto-cost reference-bandwidth %d%s",
70bd3c43 8825 ospf->ref_bandwidth, VTY_NEWLINE);
f9ad937f 8826 }
718e3744 8827
8828 /* SPF timers print. */
68980084 8829 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT ||
ea4ffc90 8830 ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT ||
8831 ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
8832 vty_out (vty, " timers throttle spf %d %d %d%s",
88d6cf37 8833 ospf->spf_delay, ospf->spf_holdtime,
ea4ffc90 8834 ospf->spf_max_holdtime, VTY_NEWLINE);
b6927875
DS
8835
8836 /* LSA timers print. */
ac7424f9
MR
8837 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
8838 vty_out (vty, " timers throttle lsa all %d%s",
8839 ospf->min_ls_interval, VTY_NEWLINE);
8840 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
b6927875 8841 vty_out (vty, " timers lsa min-arrival %d%s",
ac7424f9 8842 ospf->min_ls_arrival, VTY_NEWLINE);
b6927875 8843
2f8f370e 8844 /* Write multiplier print. */
e8f45e82 8845 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
2f8f370e 8846 vty_out (vty, " ospf write-multiplier %d%s",
e8f45e82 8847 ospf->write_oi_count, VTY_NEWLINE);
2f8f370e 8848
88d6cf37 8849 /* Max-metric router-lsa print */
8850 config_write_stub_router (vty, ospf);
8851
718e3744 8852 /* SPF refresh parameters print. */
68980084 8853 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
718e3744 8854 vty_out (vty, " refresh timer %d%s",
68980084 8855 ospf->lsa_refresh_interval, VTY_NEWLINE);
718e3744 8856
8857 /* Redistribute information print. */
68980084 8858 config_write_ospf_redistribute (vty, ospf);
718e3744 8859
8860 /* passive-interface print. */
7ffa8fa2
PJ
8861 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
8862 vty_out (vty, " passive-interface default%s", VTY_NEWLINE);
8863
1eb8ef25 8864 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
7ffa8fa2
PJ
8865 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), passive_interface)
8866 && IF_DEF_PARAMS (ifp)->passive_interface !=
8867 ospf->passive_interface_default)
8868 {
8869 vty_out (vty, " %spassive-interface %s%s",
8870 IF_DEF_PARAMS (ifp)->passive_interface ? "" : "no ",
8871 ifp->name, VTY_NEWLINE);
8872 }
1eb8ef25 8873 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
7ffa8fa2
PJ
8874 {
8875 if (!OSPF_IF_PARAM_CONFIGURED (oi->params, passive_interface))
8876 continue;
8877 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp),
8878 passive_interface))
8879 {
8880 if (oi->params->passive_interface == IF_DEF_PARAMS (oi->ifp)->passive_interface)
8881 continue;
8882 }
8883 else if (oi->params->passive_interface == ospf->passive_interface_default)
8884 continue;
8885
8886 vty_out (vty, " %spassive-interface %s %s%s",
8887 oi->params->passive_interface ? "" : "no ",
1eb8ef25 8888 oi->ifp->name,
8889 inet_ntoa (oi->address->u.prefix4), VTY_NEWLINE);
7ffa8fa2 8890 }
718e3744 8891
8892 /* Network area print. */
68980084 8893 config_write_network_area (vty, ospf);
718e3744 8894
8895 /* Area config print. */
68980084 8896 config_write_ospf_area (vty, ospf);
718e3744 8897
8898 /* static neighbor print. */
68980084 8899 config_write_ospf_nbr_nbma (vty, ospf);
718e3744 8900
8901 /* Virtual-Link print. */
68980084 8902 config_write_virtual_link (vty, ospf);
718e3744 8903
8904 /* Default metric configuration. */
68980084 8905 config_write_ospf_default_metric (vty, ospf);
718e3744 8906
8907 /* Distribute-list and default-information print. */
68980084 8908 config_write_ospf_distribute (vty, ospf);
718e3744 8909
8910 /* Distance configuration. */
68980084 8911 config_write_ospf_distance (vty, ospf);
718e3744 8912
68980084 8913 ospf_opaque_config_write_router (vty, ospf);
718e3744 8914 }
8915
8916 return write;
8917}
8918
8919void
4dadc291 8920ospf_vty_show_init (void)
718e3744 8921{
8922 /* "show ip ospf" commands. */
8923 install_element (VIEW_NODE, &show_ip_ospf_cmd);
718e3744 8924
7c8ff89e 8925 install_element (VIEW_NODE, &show_ip_ospf_instance_cmd);
7c8ff89e 8926
718e3744 8927 /* "show ip ospf database" commands. */
718e3744 8928 install_element (VIEW_NODE, &show_ip_ospf_database_type_adv_router_cmd);
7a7be519 8929 install_element (VIEW_NODE, &show_ip_ospf_database_max_cmd);
718e3744 8930
7c8ff89e 8931 install_element (VIEW_NODE, &show_ip_ospf_instance_database_type_adv_router_cmd);
7c8ff89e 8932 install_element (VIEW_NODE, &show_ip_ospf_instance_database_cmd);
7a7be519 8933 install_element (VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
7c8ff89e 8934
718e3744 8935 /* "show ip ospf interface" commands. */
8936 install_element (VIEW_NODE, &show_ip_ospf_interface_cmd);
718e3744 8937
7c8ff89e 8938 install_element (VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
7c8ff89e 8939
718e3744 8940 /* "show ip ospf neighbor" commands. */
8941 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
8942 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
8943 install_element (VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
8944 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
8945 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
8946 install_element (VIEW_NODE, &show_ip_ospf_neighbor_cmd);
8947 install_element (VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
718e3744 8948
7c8ff89e
DS
8949 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_detail_cmd);
8950 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
8951 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
8952 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_all_cmd);
8953 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
8954 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
8955 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
7c8ff89e 8956
718e3744 8957 /* "show ip ospf route" commands. */
8958 install_element (VIEW_NODE, &show_ip_ospf_route_cmd);
718e3744 8959 install_element (VIEW_NODE, &show_ip_ospf_border_routers_cmd);
7c8ff89e
DS
8960
8961 install_element (VIEW_NODE, &show_ip_ospf_instance_route_cmd);
7c8ff89e 8962 install_element (VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
718e3744 8963}
8964
6b0655a2 8965
718e3744 8966/* ospfd's interface node. */
7fc626de 8967static struct cmd_node interface_node =
718e3744 8968{
8969 INTERFACE_NODE,
8970 "%s(config-if)# ",
8971 1
8972};
8973
8974/* Initialization of OSPF interface. */
4dadc291 8975static void
8976ospf_vty_if_init (void)
718e3744 8977{
8978 /* Install interface node. */
8979 install_node (&interface_node, config_write_interface);
0b84f294 8980 if_cmd_init ();
718e3744 8981
8982 /* "ip ospf authentication" commands. */
8983 install_element (INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
718e3744 8984 install_element (INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
b4a039bf 8985 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_args_addr_cmd);
718e3744 8986 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
718e3744 8987 install_element (INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
813d4307 8988 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_key_authkey_addr_cmd);
7a7be519 8989 install_element (INTERFACE_NODE, &no_ospf_authentication_key_authkey_addr_cmd);
718e3744 8990
8991 /* "ip ospf message-digest-key" commands. */
537eae3f
QY
8992 install_element (INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
8993 install_element (INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
718e3744 8994
8995 /* "ip ospf cost" commands. */
5c2fc921
QY
8996 install_element (INTERFACE_NODE, &ip_ospf_cost_cmd);
8997 install_element (INTERFACE_NODE, &no_ip_ospf_cost_cmd);
718e3744 8998
ba682537 8999 /* "ip ospf mtu-ignore" commands. */
9000 install_element (INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
ba682537 9001 install_element (INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
ba682537 9002
718e3744 9003 /* "ip ospf dead-interval" commands. */
0d829fa7 9004 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
f9ad937f 9005 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_minimal_addr_cmd);
0d829fa7 9006 install_element (INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
f9ad937f 9007
718e3744 9008 /* "ip ospf hello-interval" commands. */
0d829fa7
QY
9009 install_element (INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
9010 install_element (INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
718e3744 9011
9012 /* "ip ospf network" commands. */
9013 install_element (INTERFACE_NODE, &ip_ospf_network_cmd);
9014 install_element (INTERFACE_NODE, &no_ip_ospf_network_cmd);
9015
9016 /* "ip ospf priority" commands. */
537eae3f
QY
9017 install_element (INTERFACE_NODE, &ip_ospf_priority_cmd);
9018 install_element (INTERFACE_NODE, &no_ip_ospf_priority_cmd);
718e3744 9019
9020 /* "ip ospf retransmit-interval" commands. */
9021 install_element (INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
718e3744 9022 install_element (INTERFACE_NODE, &no_ip_ospf_retransmit_interval_addr_cmd);
718e3744 9023
9024 /* "ip ospf transmit-delay" commands. */
9025 install_element (INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
718e3744 9026 install_element (INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
718e3744 9027
953cde65
JT
9028 /* "ip ospf area" commands. */
9029 install_element (INTERFACE_NODE, &ip_ospf_area_cmd);
9030 install_element (INTERFACE_NODE, &no_ip_ospf_area_cmd);
953cde65 9031
718e3744 9032 /* These commands are compatibitliy for previous version. */
9033 install_element (INTERFACE_NODE, &ospf_authentication_key_cmd);
718e3744 9034 install_element (INTERFACE_NODE, &ospf_message_digest_key_cmd);
537eae3f 9035 install_element (INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
718e3744 9036 install_element (INTERFACE_NODE, &ospf_dead_interval_cmd);
537eae3f 9037 install_element (INTERFACE_NODE, &no_ospf_dead_interval_cmd);
718e3744 9038 install_element (INTERFACE_NODE, &ospf_hello_interval_cmd);
537eae3f
QY
9039 install_element (INTERFACE_NODE, &no_ospf_hello_interval_cmd);
9040 install_element (INTERFACE_NODE, &ospf_cost_cmd);
9041 install_element (INTERFACE_NODE, &no_ospf_cost_cmd);
718e3744 9042 install_element (INTERFACE_NODE, &ospf_network_cmd);
537eae3f 9043 install_element (INTERFACE_NODE, &no_ospf_network_cmd);
718e3744 9044 install_element (INTERFACE_NODE, &ospf_priority_cmd);
537eae3f 9045 install_element (INTERFACE_NODE, &no_ospf_priority_cmd);
718e3744 9046 install_element (INTERFACE_NODE, &ospf_retransmit_interval_cmd);
537eae3f 9047 install_element (INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
718e3744 9048 install_element (INTERFACE_NODE, &ospf_transmit_delay_cmd);
537eae3f 9049 install_element (INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
718e3744 9050}
9051
4dadc291 9052static void
9053ospf_vty_zebra_init (void)
718e3744 9054{
718e3744 9055 install_element (OSPF_NODE, &ospf_redistribute_source_cmd);
718e3744 9056 install_element (OSPF_NODE, &no_ospf_redistribute_source_cmd);
7c8ff89e
DS
9057 install_element (OSPF_NODE, &ospf_redistribute_instance_source_cmd);
9058 install_element (OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
718e3744 9059
9060 install_element (OSPF_NODE, &ospf_distribute_list_out_cmd);
9061 install_element (OSPF_NODE, &no_ospf_distribute_list_out_cmd);
9062
718e3744 9063 install_element (OSPF_NODE, &ospf_default_information_originate_cmd);
718e3744 9064 install_element (OSPF_NODE, &no_ospf_default_information_originate_cmd);
9065
9066 install_element (OSPF_NODE, &ospf_default_metric_cmd);
9067 install_element (OSPF_NODE, &no_ospf_default_metric_cmd);
718e3744 9068
9069 install_element (OSPF_NODE, &ospf_distance_cmd);
9070 install_element (OSPF_NODE, &no_ospf_distance_cmd);
9071 install_element (OSPF_NODE, &no_ospf_distance_ospf_cmd);
6f2a6703 9072 install_element (OSPF_NODE, &ospf_distance_ospf_cmd);
718e3744 9073#if 0
9074 install_element (OSPF_NODE, &ospf_distance_source_cmd);
9075 install_element (OSPF_NODE, &no_ospf_distance_source_cmd);
9076 install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd);
9077 install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd);
9078#endif /* 0 */
9079}
9080
7fc626de 9081static struct cmd_node ospf_node =
718e3744 9082{
9083 OSPF_NODE,
9084 "%s(config-router)# ",
9085 1
9086};
9087
09f35f8c
DS
9088static void
9089ospf_interface_clear (struct interface *ifp)
9090{
9091 if (!if_is_operative (ifp)) return;
9092
9093 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
4525281a 9094 zlog_debug("ISM[%s]: clear by reset", ifp->name);
09f35f8c
DS
9095
9096 ospf_if_reset(ifp);
9097}
9098
9099DEFUN (clear_ip_ospf_interface,
9100 clear_ip_ospf_interface_cmd,
9101 "clear ip ospf interface [IFNAME]",
9102 CLEAR_STR
9103 IP_STR
9104 "OSPF information\n"
9105 "Interface information\n"
9106 "Interface name\n")
9107{
8d769265 9108 int idx_ifname = 4;
09f35f8c
DS
9109 struct interface *ifp;
9110 struct listnode *node;
9111
7a7be519 9112 if (argc == 4) /* Clear all the ospfv2 interfaces. */
09f35f8c 9113 {
b2d7c082 9114 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
09f35f8c
DS
9115 ospf_interface_clear(ifp);
9116 }
9117 else /* Interface name is specified. */
9118 {
1306c09a 9119 if ((ifp = if_lookup_by_name (argv[idx_ifname]->text, VRF_DEFAULT)) == NULL)
09f35f8c
DS
9120 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
9121 else
9122 ospf_interface_clear(ifp);
9123 }
9124
9125 return CMD_SUCCESS;
9126}
9127
9128void
9129ospf_vty_clear_init (void)
9130{
9131 install_element (ENABLE_NODE, &clear_ip_ospf_interface_cmd);
9132}
9133
6b0655a2 9134
718e3744 9135/* Install OSPF related vty commands. */
9136void
4dadc291 9137ospf_vty_init (void)
718e3744 9138{
9139 /* Install ospf top node. */
9140 install_node (&ospf_node, ospf_config_write);
9141
9142 /* "router ospf" commands. */
9143 install_element (CONFIG_NODE, &router_ospf_cmd);
9144 install_element (CONFIG_NODE, &no_router_ospf_cmd);
9145
7c8ff89e 9146
718e3744 9147 install_default (OSPF_NODE);
9148
9149 /* "ospf router-id" commands. */
9150 install_element (OSPF_NODE, &ospf_router_id_cmd);
747e489c 9151 install_element (OSPF_NODE, &ospf_router_id_old_cmd);
718e3744 9152 install_element (OSPF_NODE, &no_ospf_router_id_cmd);
718e3744 9153
9154 /* "passive-interface" commands. */
a2c62831 9155 install_element (OSPF_NODE, &ospf_passive_interface_addr_cmd);
a2c62831 9156 install_element (OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
718e3744 9157
9158 /* "ospf abr-type" commands. */
9159 install_element (OSPF_NODE, &ospf_abr_type_cmd);
9160 install_element (OSPF_NODE, &no_ospf_abr_type_cmd);
9161
d7e60dd7
AS
9162 /* "ospf log-adjacency-changes" commands. */
9163 install_element (OSPF_NODE, &ospf_log_adjacency_changes_cmd);
9164 install_element (OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
9165 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
9166 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
9167
718e3744 9168 /* "ospf rfc1583-compatible" commands. */
718e3744 9169 install_element (OSPF_NODE, &ospf_compatible_rfc1583_cmd);
9170 install_element (OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
7a7be519 9171 install_element (OSPF_NODE, &ospf_rfc1583_flag_cmd);
9172 install_element (OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
718e3744 9173
9174 /* "network area" commands. */
a2c62831 9175 install_element (OSPF_NODE, &ospf_network_area_cmd);
9176 install_element (OSPF_NODE, &no_ospf_network_area_cmd);
718e3744 9177
9178 /* "area authentication" commands. */
a2c62831 9179 install_element (OSPF_NODE, &ospf_area_authentication_message_digest_cmd);
9180 install_element (OSPF_NODE, &ospf_area_authentication_cmd);
9181 install_element (OSPF_NODE, &no_ospf_area_authentication_cmd);
718e3744 9182
9183 /* "area range" commands. */
a2c62831 9184 install_element (OSPF_NODE, &ospf_area_range_cmd);
7a7be519 9185 install_element (OSPF_NODE, &ospf_area_range_cost_cmd);
a2c62831 9186 install_element (OSPF_NODE, &ospf_area_range_not_advertise_cmd);
9187 install_element (OSPF_NODE, &no_ospf_area_range_cmd);
a2c62831 9188 install_element (OSPF_NODE, &ospf_area_range_substitute_cmd);
9189 install_element (OSPF_NODE, &no_ospf_area_range_substitute_cmd);
718e3744 9190
9191 /* "area virtual-link" commands. */
a2c62831 9192 install_element (OSPF_NODE, &ospf_area_vlink_cmd);
7a7be519 9193 install_element (OSPF_NODE, &ospf_area_vlink_intervals_cmd);
a2c62831 9194 install_element (OSPF_NODE, &no_ospf_area_vlink_cmd);
7a7be519 9195 install_element (OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
718e3744 9196
718e3744 9197
718e3744 9198
718e3744 9199
718e3744 9200
718e3744 9201
718e3744 9202
718e3744 9203
718e3744 9204
718e3744 9205
9206 /* "area stub" commands. */
a2c62831 9207 install_element (OSPF_NODE, &ospf_area_stub_no_summary_cmd);
9208 install_element (OSPF_NODE, &ospf_area_stub_cmd);
9209 install_element (OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
9210 install_element (OSPF_NODE, &no_ospf_area_stub_cmd);
718e3744 9211
718e3744 9212 /* "area nssa" commands. */
a2c62831 9213 install_element (OSPF_NODE, &ospf_area_nssa_cmd);
9214 install_element (OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd);
9215 install_element (OSPF_NODE, &ospf_area_nssa_translate_cmd);
9216 install_element (OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
9217 install_element (OSPF_NODE, &no_ospf_area_nssa_cmd);
718e3744 9218
a2c62831 9219 install_element (OSPF_NODE, &ospf_area_default_cost_cmd);
9220 install_element (OSPF_NODE, &no_ospf_area_default_cost_cmd);
718e3744 9221
a2c62831 9222 install_element (OSPF_NODE, &ospf_area_shortcut_cmd);
9223 install_element (OSPF_NODE, &no_ospf_area_shortcut_cmd);
718e3744 9224
a2c62831 9225 install_element (OSPF_NODE, &ospf_area_export_list_cmd);
9226 install_element (OSPF_NODE, &no_ospf_area_export_list_cmd);
718e3744 9227
a2c62831 9228 install_element (OSPF_NODE, &ospf_area_filter_list_cmd);
9229 install_element (OSPF_NODE, &no_ospf_area_filter_list_cmd);
718e3744 9230
a2c62831 9231 install_element (OSPF_NODE, &ospf_area_import_list_cmd);
9232 install_element (OSPF_NODE, &no_ospf_area_import_list_cmd);
88d6cf37 9233
9234 /* SPF timer commands */
d24f6e2a 9235 install_element (OSPF_NODE, &ospf_timers_throttle_spf_cmd);
9236 install_element (OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
9237
b6927875 9238 /* LSA timers commands */
ac7424f9
MR
9239 install_element (OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
9240 install_element (OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
9241 install_element (OSPF_NODE, &ospf_timers_min_ls_arrival_cmd);
9242 install_element (OSPF_NODE, &no_ospf_timers_min_ls_arrival_cmd);
b6927875
DS
9243 install_element (OSPF_NODE, &ospf_timers_lsa_cmd);
9244 install_element (OSPF_NODE, &no_ospf_timers_lsa_cmd);
b6927875 9245
88d6cf37 9246 /* refresh timer commands */
a2c62831 9247 install_element (OSPF_NODE, &ospf_refresh_timer_cmd);
9248 install_element (OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
718e3744 9249
88d6cf37 9250 /* max-metric commands */
9251 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
9252 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
9253 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
9254 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
9255 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
9256 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
9257
9258 /* reference bandwidth commands */
a2c62831 9259 install_element (OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
9260 install_element (OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
718e3744 9261
9262 /* "neighbor" commands. */
a2c62831 9263 install_element (OSPF_NODE, &ospf_neighbor_cmd);
a2c62831 9264 install_element (OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
a2c62831 9265 install_element (OSPF_NODE, &no_ospf_neighbor_cmd);
7a7be519 9266 install_element (OSPF_NODE, &no_ospf_neighbor_poll_cmd);
718e3744 9267
2f8f370e
DS
9268 /* write multiplier commands */
9269 install_element (OSPF_NODE, &ospf_write_multiplier_cmd);
7a7be519 9270 install_element (OSPF_NODE, &write_multiplier_cmd);
2f8f370e 9271 install_element (OSPF_NODE, &no_ospf_write_multiplier_cmd);
7a7be519 9272 install_element (OSPF_NODE, &no_write_multiplier_cmd);
2f8f370e 9273
718e3744 9274 /* Init interface related vty commands. */
9275 ospf_vty_if_init ();
9276
9277 /* Init zebra related vty commands. */
9278 ospf_vty_zebra_init ();
9279}