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