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