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