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