1/*
2 * OSPFd dump routine.
3 * Copyright (C) 1999, 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
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "linklist.h"
26#include "thread.h"
27#include "prefix.h"
28#include "command.h"
29#include "stream.h"
30#include "log.h"
31
32#include "ospfd/ospfd.h"
33#include "ospfd/ospf_interface.h"
34#include "ospfd/ospf_ism.h"
35#include "ospfd/ospf_asbr.h"
36#include "ospfd/ospf_lsa.h"
37#include "ospfd/ospf_lsdb.h"
38#include "ospfd/ospf_neighbor.h"
39#include "ospfd/ospf_nsm.h"
40#include "ospfd/ospf_dump.h"
41#include "ospfd/ospf_packet.h"
42#include "ospfd/ospf_network.h"
43
44struct message ospf_ism_state_msg[] =
45{
46  { ISM_DependUpon,   "DependUpon" },
47  { ISM_Down,         "Down" },
48  { ISM_Loopback,     "Loopback" },
49  { ISM_Waiting,      "Waiting" },
50  { ISM_PointToPoint, "Point-To-Point" },
51  { ISM_DROther,      "DROther" },
52  { ISM_Backup,       "Backup" },
53  { ISM_DR,           "DR" },
54};
55int ospf_ism_state_msg_max = OSPF_ISM_STATE_MAX;
56
57struct message ospf_nsm_state_msg[] =
58{
59  { NSM_DependUpon, "DependUpon" },
60  { NSM_Down,       "Down" },
61  { NSM_Attempt,    "Attempt" },
62  { NSM_Init,       "Init" },
63  { NSM_TwoWay,     "2-Way" },
64  { NSM_ExStart,    "ExStart" },
65  { NSM_Exchange,   "Exchange" },
66  { NSM_Loading,    "Loading" },
67  { NSM_Full,       "Full" },
68};
69int ospf_nsm_state_msg_max = OSPF_NSM_STATE_MAX;
70
71struct message ospf_lsa_type_msg[] =
72{
73  { OSPF_UNKNOWN_LSA,      "unknown" },
74  { OSPF_ROUTER_LSA,       "router-LSA" },
75  { OSPF_NETWORK_LSA,      "network-LSA" },
76  { OSPF_SUMMARY_LSA,      "summary-LSA" },
77  { OSPF_ASBR_SUMMARY_LSA, "summary-LSA" },
78  { OSPF_AS_EXTERNAL_LSA,  "AS-external-LSA" },
79  { OSPF_GROUP_MEMBER_LSA, "GROUP MEMBER LSA" },
80  { OSPF_AS_NSSA_LSA,      "NSSA-LSA" },
81  { 8,                     "Type-8 LSA" },
82  { OSPF_OPAQUE_LINK_LSA,  "Link-Local Opaque-LSA" },
83  { OSPF_OPAQUE_AREA_LSA,  "Area-Local Opaque-LSA" },
84  { OSPF_OPAQUE_AS_LSA,    "AS-external Opaque-LSA" },
85};
86int ospf_lsa_type_msg_max = OSPF_MAX_LSA;
87
88struct message ospf_link_state_id_type_msg[] =
89{
90  { OSPF_UNKNOWN_LSA,      "(unknown)" },
91  { OSPF_ROUTER_LSA,       "" },
92  { OSPF_NETWORK_LSA,      "(address of Designated Router)" },
93  { OSPF_SUMMARY_LSA,      "(summary Network Number)" },
94  { OSPF_ASBR_SUMMARY_LSA, "(AS Boundary Router address)" },
95  { OSPF_AS_EXTERNAL_LSA,  "(External Network Number)" },
96  { OSPF_GROUP_MEMBER_LSA, "(Group membership information)" },
97  { OSPF_AS_NSSA_LSA,      "(External Network Number for NSSA)" },
98  { 8,                     "(Type-8 LSID)" },
99  { OSPF_OPAQUE_LINK_LSA,  "(Link-Local Opaque-Type/ID)" },
100  { OSPF_OPAQUE_AREA_LSA,  "(Area-Local Opaque-Type/ID)" },
101  { OSPF_OPAQUE_AS_LSA,    "(AS-external Opaque-Type/ID)" },
102};
103int ospf_link_state_id_type_msg_max = OSPF_MAX_LSA;
104
105struct message ospf_redistributed_proto[] =
106{
107  { ZEBRA_ROUTE_SYSTEM,   "System" },
108  { ZEBRA_ROUTE_KERNEL,   "Kernel" },
109  { ZEBRA_ROUTE_CONNECT,  "Connected" },
110  { ZEBRA_ROUTE_STATIC,   "Static" },
111  { ZEBRA_ROUTE_RIP,      "RIP" },
112  { ZEBRA_ROUTE_RIPNG,    "RIPng" },
113  { ZEBRA_ROUTE_OSPF,     "OSPF" },
114  { ZEBRA_ROUTE_OSPF6,    "OSPFv3" },
115  { ZEBRA_ROUTE_BGP,      "BGP" },
116  { ZEBRA_ROUTE_MAX,	  "Default" },
117};
118int ospf_redistributed_proto_max = ZEBRA_ROUTE_MAX + 1;
119
120struct message ospf_network_type_msg[] =
121{
122  { OSPF_IFTYPE_NONE,		  "NONE" },
123  { OSPF_IFTYPE_POINTOPOINT,      "Point-to-Point" },
124  { OSPF_IFTYPE_BROADCAST,        "Broadcast" },
125  { OSPF_IFTYPE_NBMA,             "NBMA" },
126  { OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint" },
127  { OSPF_IFTYPE_VIRTUALLINK,      "Virtual-Link" },
128};
129int ospf_network_type_msg_max = OSPF_IFTYPE_MAX;
130
131/* Configuration debug option variables. */
132unsigned long conf_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
133unsigned long conf_debug_ospf_event = 0;
134unsigned long conf_debug_ospf_ism = 0;
135unsigned long conf_debug_ospf_nsm = 0;
136unsigned long conf_debug_ospf_lsa = 0;
137unsigned long conf_debug_ospf_zebra = 0;
138unsigned long conf_debug_ospf_nssa = 0;
139
140/* Enable debug option variables -- valid only session. */
141unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
142unsigned long term_debug_ospf_event = 0;
143unsigned long term_debug_ospf_ism = 0;
144unsigned long term_debug_ospf_nsm = 0;
145unsigned long term_debug_ospf_lsa = 0;
146unsigned long term_debug_ospf_zebra = 0;
147unsigned long term_debug_ospf_nssa = 0;
148
149
150#define OSPF_AREA_STRING_MAXLEN  16
151char *
152ospf_area_name_string (struct ospf_area *area)
153{
154  static char buf[OSPF_AREA_STRING_MAXLEN] = "";
155  u_int32_t area_id;
156
157  if (!area)
158    return "-";
159
160  area_id = ntohl (area->area_id.s_addr);
161  snprintf (buf, OSPF_AREA_STRING_MAXLEN, "%d.%d.%d.%d",
162            (area_id >> 24) & 0xff, (area_id >> 16) & 0xff,
163            (area_id >> 8) & 0xff, area_id & 0xff);
164  return buf;
165}
166
167#define OSPF_AREA_DESC_STRING_MAXLEN  23
168char *
169ospf_area_desc_string (struct ospf_area *area)
170{
171  static char buf[OSPF_AREA_DESC_STRING_MAXLEN] = "";
172  u_char type;
173
174  if (!area)
175    return "(incomplete)";
176
177  type = area->external_routing;
178  switch (type)
179    {
180    case OSPF_AREA_NSSA:
181      snprintf (buf, OSPF_AREA_DESC_STRING_MAXLEN, "%s [NSSA]",
182                ospf_area_name_string (area));
183      break;
184    case OSPF_AREA_STUB:
185      snprintf (buf, OSPF_AREA_DESC_STRING_MAXLEN, "%s [Stub]",
186                ospf_area_name_string (area));
187      break;
188    default:
189      return ospf_area_name_string (area);
190      break;
191    }
192
193  return buf;
194}
195
196#define OSPF_IF_STRING_MAXLEN  40
197char *
198ospf_if_name_string (struct ospf_interface *oi)
199{
200  static char buf[OSPF_IF_STRING_MAXLEN] = "";
201  u_int32_t ifaddr;
202
203  if (!oi)
204    return "inactive";
205
206  if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
207    return oi->ifp->name;
208
209  ifaddr = ntohl (oi->address->u.prefix4.s_addr);
210  snprintf (buf, OSPF_IF_STRING_MAXLEN,
211            "%s:%d.%d.%d.%d", oi->ifp->name,
212            (ifaddr >> 24) & 0xff, (ifaddr >> 16) & 0xff,
213            (ifaddr >> 8) & 0xff, ifaddr & 0xff);
214  return buf;
215}
216
217
218void
219ospf_nbr_state_message (struct ospf_neighbor *nbr, char *buf, size_t size)
220{
221  int state;
222  struct ospf_interface *oi = nbr->oi;
223
224  if (IPV4_ADDR_SAME (&DR (oi), &nbr->address.u.prefix4))
225    state = ISM_DR;
226  else if (IPV4_ADDR_SAME (&BDR (oi), &nbr->address.u.prefix4))
227    state = ISM_Backup;
228  else
229    state = ISM_DROther;
230
231  memset (buf, 0, size);
232
233  snprintf (buf, size, "%s/%s",
234	    LOOKUP (ospf_nsm_state_msg, nbr->state),
235	    LOOKUP (ospf_ism_state_msg, state));
236}
237
238char *
239ospf_timer_dump (struct thread *t, char *buf, size_t size)
240{
241  struct timeval now;
242  unsigned long h, m, s;
243
244  if (!t)
245    return "inactive";
246
247  h = m = s = 0;
248  memset (buf, 0, size);
249
250  gettimeofday (&now, NULL);
251
252  s = t->u.sands.tv_sec - now.tv_sec;
253  if (s >= 3600)
254    {
255      h = s / 3600;
256      s -= h * 3600;
257    }
258
259  if (s >= 60)
260    {
261      m = s / 60;
262      s -= m * 60;
263    }
264
265  snprintf (buf, size, "%02ld:%02ld:%02ld", h, m, s);
266
267  return buf;
268}
269
270#define OSPF_OPTION_STR_MAXLEN		24
271
272char *
273ospf_options_dump (u_char options)
274{
275  static char buf[OSPF_OPTION_STR_MAXLEN];
276
277  snprintf (buf, OSPF_OPTION_STR_MAXLEN, "*|%s|%s|%s|%s|%s|%s|*",
278	    (options & OSPF_OPTION_O) ? "O" : "-",
279	    (options & OSPF_OPTION_DC) ? "DC" : "-",
280	    (options & OSPF_OPTION_EA) ? "EA" : "-",
281	    (options & OSPF_OPTION_NP) ? "N/P" : "-",
282	    (options & OSPF_OPTION_MC) ? "MC" : "-",
283	    (options & OSPF_OPTION_E) ? "E" : "-");
284
285  return buf;
286}
287
288void
289ospf_packet_hello_dump (struct stream *s, u_int16_t length)
290{
291  struct ospf_hello *hello;
292  int i;
293
294  hello = (struct ospf_hello *) STREAM_PNT (s);
295
296  zlog_info ("Hello");
297  zlog_info ("  NetworkMask %s", inet_ntoa (hello->network_mask));
298  zlog_info ("  HelloInterval %d", ntohs (hello->hello_interval));
299  zlog_info ("  Options %d (%s)", hello->options,
300	     ospf_options_dump (hello->options));
301  zlog_info ("  RtrPriority %d", hello->priority);
302  zlog_info ("  RtrDeadInterval %ld", (u_long)ntohl (hello->dead_interval));
303  zlog_info ("  DRouter %s", inet_ntoa (hello->d_router));
304  zlog_info ("  BDRouter %s", inet_ntoa (hello->bd_router));
305
306  length -= OSPF_HEADER_SIZE + OSPF_HELLO_MIN_SIZE;
307  zlog_info ("  # Neighbors %d", length / 4);
308  for (i = 0; length > 0; i++, length -= sizeof (struct in_addr))
309    zlog_info ("    Neighbor %s", inet_ntoa (hello->neighbors[i]));
310}
311
312char *
313ospf_dd_flags_dump (u_char flags, char *buf, size_t size)
314{
315  memset (buf, 0, size);
316
317  snprintf (buf, size, "%s|%s|%s",
318	    (flags & OSPF_DD_FLAG_I) ? "I" : "-",
319	    (flags & OSPF_DD_FLAG_M) ? "M" : "-",
320	    (flags & OSPF_DD_FLAG_MS) ? "MS" : "-");
321
322  return buf;
323}
324
325void
326ospf_lsa_header_dump (struct lsa_header *lsah)
327{
328  zlog_info ("  LSA Header");
329  zlog_info ("    LS age %d", ntohs (lsah->ls_age));
330  zlog_info ("    Options %d (%s)", lsah->options,
331	     ospf_options_dump (lsah->options));
332  zlog_info ("    LS type %d (%s)", lsah->type,
333	     LOOKUP (ospf_lsa_type_msg, lsah->type));
334  zlog_info ("    Link State ID %s", inet_ntoa (lsah->id));
335  zlog_info ("    Advertising Router %s", inet_ntoa (lsah->adv_router));
336  zlog_info ("    LS sequence number 0x%lx", (u_long)ntohl (lsah->ls_seqnum));
337  zlog_info ("    LS checksum 0x%x", ntohs (lsah->checksum));
338  zlog_info ("    length %d", ntohs (lsah->length));
339}
340
341char *
342ospf_router_lsa_flags_dump (u_char flags, char *buf, size_t size)
343{
344  memset (buf, 0, size);
345
346  snprintf (buf, size, "%s|%s|%s",
347	    (flags & ROUTER_LSA_VIRTUAL) ? "V" : "-",
348	    (flags & ROUTER_LSA_EXTERNAL) ? "E" : "-",
349	    (flags & ROUTER_LSA_BORDER) ? "B" : "-");
350
351  return buf;
352}
353
354void
355ospf_router_lsa_dump (struct stream *s, u_int16_t length)
356{
357  char buf[BUFSIZ];
358  struct router_lsa *rl;
359  int i, len;
360
361  rl = (struct router_lsa *) STREAM_PNT (s);
362
363  zlog_info ("  Router-LSA");
364  zlog_info ("    flags %s",
365	     ospf_router_lsa_flags_dump (rl->flags, buf, BUFSIZ));
366  zlog_info ("    # links %d", ntohs (rl->links));
367
368  len = ntohs (rl->header.length) - OSPF_LSA_HEADER_SIZE - 4;
369  for (i = 0; len > 0; i++)
370    {
371      zlog_info ("    Link ID %s", inet_ntoa (rl->link[i].link_id));
372      zlog_info ("    Link Data %s", inet_ntoa (rl->link[i].link_data));
373      zlog_info ("    Type %d", (u_char) rl->link[i].type);
374      zlog_info ("    TOS %d", (u_char) rl->link[i].tos);
375      zlog_info ("    metric %d", ntohs (rl->link[i].metric));
376
377      len -= 12;
378    }
379}
380
381void
382ospf_network_lsa_dump (struct stream *s, u_int16_t length)
383{
384  struct network_lsa *nl;
385  int i, cnt;
386
387  nl = (struct network_lsa *) STREAM_PNT (s);
388  cnt = (ntohs (nl->header.length) - (OSPF_LSA_HEADER_SIZE + 4)) / 4;
389
390  zlog_info ("  Network-LSA");
391  /*
392  zlog_info ("LSA total size %d", ntohs (nl->header.length));
393  zlog_info ("Network-LSA size %d",
394  ntohs (nl->header.length) - OSPF_LSA_HEADER_SIZE);
395  */
396  zlog_info ("    Network Mask %s", inet_ntoa (nl->mask));
397  zlog_info ("    # Attached Routers %d", cnt);
398  for (i = 0; i < cnt; i++)
399    zlog_info ("      Attached Router %s", inet_ntoa (nl->routers[i]));
400}
401
402void
403ospf_summary_lsa_dump (struct stream *s, u_int16_t length)
404{
405  struct summary_lsa *sl;
406  int size;
407  int i;
408
409  sl = (struct summary_lsa *) STREAM_PNT (s);
410
411  zlog_info ("  Summary-LSA");
412  zlog_info ("    Network Mask %s", inet_ntoa (sl->mask));
413
414  size = ntohs (sl->header.length) - OSPF_LSA_HEADER_SIZE - 4;
415  for (i = 0; size > 0; size -= 4, i++)
416    zlog_info ("    TOS=%d metric %d", sl->tos,
417	       GET_METRIC (sl->metric));
418}
419
420void
421ospf_as_external_lsa_dump (struct stream *s, u_int16_t length)
422{
423  struct as_external_lsa *al;
424  int size;
425  int i;
426
427  al = (struct as_external_lsa *) STREAM_PNT (s);
428
429  zlog_info ("  AS-external-LSA");
430  zlog_info ("    Network Mask %s", inet_ntoa (al->mask));
431
432  size = ntohs (al->header.length) - OSPF_LSA_HEADER_SIZE -4;
433  for (i = 0; size > 0; size -= 12, i++)
434    {
435      zlog_info ("    bit %s TOS=%d metric %d",
436		 IS_EXTERNAL_METRIC (al->e[i].tos) ? "E" : "-",
437		 al->e[i].tos & 0x7f, GET_METRIC (al->e[i].metric));
438      zlog_info ("    Forwarding address %s", inet_ntoa (al->e[i].fwd_addr));
439      zlog_info ("    External Route Tag %d", al->e[i].route_tag);
440    }
441}
442
443void
444ospf_lsa_header_list_dump (struct stream *s, u_int16_t length)
445{
446  struct lsa_header *lsa;
447
448  zlog_info ("  # LSA Headers %d", length / OSPF_LSA_HEADER_SIZE);
449
450  /* LSA Headers. */
451  while (length > 0)
452    {
453      lsa = (struct lsa_header *) STREAM_PNT (s);
454      ospf_lsa_header_dump (lsa);
455
456      stream_forward (s, OSPF_LSA_HEADER_SIZE);
457      length -= OSPF_LSA_HEADER_SIZE;
458    }
459}
460
461void
462ospf_packet_db_desc_dump (struct stream *s, u_int16_t length)
463{
464  struct ospf_db_desc *dd;
465  char dd_flags[8];
466
467  u_int32_t gp;
468
469  gp = stream_get_getp (s);
470  dd = (struct ospf_db_desc *) STREAM_PNT (s);
471
472  zlog_info ("Database Description");
473  zlog_info ("  Interface MTU %d", ntohs (dd->mtu));
474  zlog_info ("  Options %d (%s)", dd->options,
475	     ospf_options_dump (dd->options));
476  zlog_info ("  Flags %d (%s)", dd->flags,
477	     ospf_dd_flags_dump (dd->flags, dd_flags, sizeof dd_flags));
478  zlog_info ("  Sequence Number 0x%08lx", (u_long)ntohl (dd->dd_seqnum));
479
480  length -= OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE;
481
482  stream_forward (s, OSPF_DB_DESC_MIN_SIZE);
483
484  ospf_lsa_header_list_dump (s, length);
485
486  stream_set_getp (s, gp);
487}
488
489void
490ospf_packet_ls_req_dump (struct stream *s, u_int16_t length)
491{
492  u_int32_t sp;
493  u_int32_t ls_type;
494  struct in_addr ls_id;
495  struct in_addr adv_router;
496
497  sp = stream_get_getp (s);
498
499  length -= OSPF_HEADER_SIZE;
500
501  zlog_info ("Link State Request");
502  zlog_info ("  # Requests %d", length / 12);
503
504  for (; length > 0; length -= 12)
505    {
506      ls_type = stream_getl (s);
507      ls_id.s_addr = stream_get_ipv4 (s);
508      adv_router.s_addr = stream_get_ipv4 (s);
509
510      zlog_info ("  LS type %d", ls_type);
511      zlog_info ("  Link State ID %s", inet_ntoa (ls_id));
512      zlog_info ("  Advertising Router %s",
513		 inet_ntoa (adv_router));
514    }
515
516  stream_set_getp (s, sp);
517}
518
519void
520ospf_packet_ls_upd_dump (struct stream *s, u_int16_t length)
521{
522  u_int32_t sp;
523  struct lsa_header *lsa;
524  int lsa_len;
525  u_int32_t count;
526
527  length -= OSPF_HEADER_SIZE;
528
529  sp = stream_get_getp (s);
530
531  count = stream_getl (s);
532  length -= 4;
533
534  zlog_info ("Link State Update");
535  zlog_info ("  # LSAs %d", count);
536
537  while (length > 0 && count > 0)
538    {
539      if (length < OSPF_HEADER_SIZE || length % 4 != 0)
540	{
541          zlog_info ("  Remaining %d bytes; Incorrect length.", length);
542	  break;
543	}
544
545      lsa = (struct lsa_header *) STREAM_PNT (s);
546      lsa_len = ntohs (lsa->length);
547      ospf_lsa_header_dump (lsa);
548
549      switch (lsa->type)
550	{
551	case OSPF_ROUTER_LSA:
552	  ospf_router_lsa_dump (s, length);
553	  break;
554	case OSPF_NETWORK_LSA:
555	  ospf_network_lsa_dump (s, length);
556	  break;
557	case OSPF_SUMMARY_LSA:
558	case OSPF_ASBR_SUMMARY_LSA:
559	  ospf_summary_lsa_dump (s, length);
560	  break;
561	case OSPF_AS_EXTERNAL_LSA:
562	  ospf_as_external_lsa_dump (s, length);
563	  break;
564#ifdef HAVE_NSSA
565	case OSPF_AS_NSSA_LSA:
566	  /* XXX */
567	  break;
568#endif /* HAVE_NSSA */
569#ifdef HAVE_OPAQUE_LSA
570	case OSPF_OPAQUE_LINK_LSA:
571	case OSPF_OPAQUE_AREA_LSA:
572	case OSPF_OPAQUE_AS_LSA:
573	  ospf_opaque_lsa_dump (s, length);
574	  break;
575#endif /* HAVE_OPAQUE_LSA */
576	default:
577	  break;
578	}
579
580      stream_forward (s, lsa_len);
581      length -= lsa_len;
582      count--;
583    }
584
585  stream_set_getp (s, sp);
586}
587
588void
589ospf_packet_ls_ack_dump (struct stream *s, u_int16_t length)
590{
591  u_int32_t sp;
592
593  length -= OSPF_HEADER_SIZE;
594  sp = stream_get_getp (s);
595
596  zlog_info ("Link State Acknowledgment");
597  ospf_lsa_header_list_dump (s, length);
598
599  stream_set_getp (s, sp);
600}
601
602void
603ospf_ip_header_dump (struct stream *s)
604{
605  u_int16_t length;
606  struct ip *iph;
607
608  iph = (struct ip *) STREAM_PNT (s);
609
610#ifdef GNU_LINUX
611  length = ntohs (iph->ip_len);
612#else /* GNU_LINUX */
613  length = iph->ip_len;
614#endif /* GNU_LINUX */
615
616  /* IP Header dump. */
617  zlog_info ("ip_v %d", iph->ip_v);
618  zlog_info ("ip_hl %d", iph->ip_hl);
619  zlog_info ("ip_tos %d", iph->ip_tos);
620  zlog_info ("ip_len %d", length);
621  zlog_info ("ip_id %u", (u_int32_t) iph->ip_id);
622  zlog_info ("ip_off %u", (u_int32_t) iph->ip_off);
623  zlog_info ("ip_ttl %d", iph->ip_ttl);
624  zlog_info ("ip_p %d", iph->ip_p);
625  /* There is a report that Linux 2.0.37 does not have ip_sum.  But
626     I'm not sure.  Temporary commented out by kunihiro. */
627  /* zlog_info ("ip_sum 0x%x", (u_int32_t) ntohs (iph->ip_sum)); */
628  zlog_info ("ip_src %s",  inet_ntoa (iph->ip_src));
629  zlog_info ("ip_dst %s", inet_ntoa (iph->ip_dst));
630}
631
632void
633ospf_header_dump (struct ospf_header *ospfh)
634{
635  char buf[9];
636
637  zlog_info ("Header");
638  zlog_info ("  Version %d", ospfh->version);
639  zlog_info ("  Type %d (%s)", ospfh->type,
640	     ospf_packet_type_str[ospfh->type]);
641  zlog_info ("  Packet Len %d", ntohs (ospfh->length));
642  zlog_info ("  Router ID %s", inet_ntoa (ospfh->router_id));
643  zlog_info ("  Area ID %s", inet_ntoa (ospfh->area_id));
644  zlog_info ("  Checksum 0x%x", ntohs (ospfh->checksum));
645  zlog_info ("  AuType %d", ntohs (ospfh->auth_type));
646
647  switch (ntohs (ospfh->auth_type))
648    {
649    case OSPF_AUTH_NULL:
650      break;
651    case OSPF_AUTH_SIMPLE:
652      memset (buf, 0, 9);
653      strncpy (buf, ospfh->u.auth_data, 8);
654      zlog_info ("  Simple Password %s", buf);
655      break;
656    case OSPF_AUTH_CRYPTOGRAPHIC:
657      zlog_info ("  Cryptographic Authentication");
658      zlog_info ("  Key ID %d", ospfh->u.crypt.key_id);
659      zlog_info ("  Auth Data Len %d", ospfh->u.crypt.auth_data_len);
660      zlog_info ("  Sequence number %ld",
661		 (u_long)ntohl (ospfh->u.crypt.crypt_seqnum));
662      break;
663    default:
664      zlog_info ("* This is not supported authentication type");
665      break;
666    }
667
668}
669
670void
671ospf_packet_dump (struct stream *s)
672{
673  struct ospf_header *ospfh;
674  unsigned long gp;
675
676  /* Preserve pointer. */
677  gp = stream_get_getp (s);
678
679  /* OSPF Header dump. */
680  ospfh = (struct ospf_header *) STREAM_PNT (s);
681
682  /* Until detail flag is set, return. */
683  if (!(term_debug_ospf_packet[ospfh->type - 1] & OSPF_DEBUG_DETAIL))
684    return;
685
686  /* Show OSPF header detail. */
687  ospf_header_dump (ospfh);
688  stream_forward (s, OSPF_HEADER_SIZE);
689
690  switch (ospfh->type)
691    {
692    case OSPF_MSG_HELLO:
693      ospf_packet_hello_dump (s, ntohs (ospfh->length));
694      break;
695    case OSPF_MSG_DB_DESC:
696      ospf_packet_db_desc_dump (s, ntohs (ospfh->length));
697      break;
698    case OSPF_MSG_LS_REQ:
699      ospf_packet_ls_req_dump (s, ntohs (ospfh->length));
700      break;
701    case OSPF_MSG_LS_UPD:
702      ospf_packet_ls_upd_dump (s, ntohs (ospfh->length));
703      break;
704    case OSPF_MSG_LS_ACK:
705      ospf_packet_ls_ack_dump (s, ntohs (ospfh->length));
706      break;
707    default:
708      break;
709    }
710
711  stream_set_getp (s, gp);
712}
713
714
715/*
716   [no] debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)
717                          [send|recv [detail]]
718*/
719DEFUN (debug_ospf_packet,
720       debug_ospf_packet_all_cmd,
721       "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)",
722       DEBUG_STR
723       OSPF_STR
724       "OSPF packets\n"
725       "OSPF Hello\n"
726       "OSPF Database Description\n"
727       "OSPF Link State Request\n"
728       "OSPF Link State Update\n"
729       "OSPF Link State Acknowledgment\n"
730       "OSPF all packets\n")
731{
732  int type = 0;
733  int flag = 0;
734  int i;
735
736  assert (argc > 0);
737
738  /* Check packet type. */
739  if (strncmp (argv[0], "h", 1) == 0)
740    type = OSPF_DEBUG_HELLO;
741  else if (strncmp (argv[0], "d", 1) == 0)
742    type = OSPF_DEBUG_DB_DESC;
743  else if (strncmp (argv[0], "ls-r", 4) == 0)
744    type = OSPF_DEBUG_LS_REQ;
745  else if (strncmp (argv[0], "ls-u", 4) == 0)
746    type = OSPF_DEBUG_LS_UPD;
747  else if (strncmp (argv[0], "ls-a", 4) == 0)
748    type = OSPF_DEBUG_LS_ACK;
749  else if (strncmp (argv[0], "a", 1) == 0)
750    type = OSPF_DEBUG_ALL;
751
752  /* Default, both send and recv. */
753  if (argc == 1)
754    flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV;
755
756  /* send or recv. */
757  if (argc >= 2)
758    {
759      if (strncmp (argv[1], "s", 1) == 0)
760	flag = OSPF_DEBUG_SEND;
761      else if (strncmp (argv[1], "r", 1) == 0)
762	flag = OSPF_DEBUG_RECV;
763      else if (strncmp (argv[1], "d", 1) == 0)
764	flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
765    }
766
767  /* detail. */
768  if (argc == 3)
769    if (strncmp (argv[2], "d", 1) == 0)
770      flag |= OSPF_DEBUG_DETAIL;
771
772  for (i = 0; i < 5; i++)
773    if (type & (0x01 << i))
774      {
775	if (vty->node == CONFIG_NODE)
776	  DEBUG_PACKET_ON (i, flag);
777	else
778	  TERM_DEBUG_PACKET_ON (i, flag);
779      }
780
781  return CMD_SUCCESS;
782}
783
784ALIAS (debug_ospf_packet,
785       debug_ospf_packet_send_recv_cmd,
786       "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv|detail)",
787       "Debugging functions\n"
788       "OSPF information\n"
789       "OSPF packets\n"
790       "OSPF Hello\n"
791       "OSPF Database Description\n"
792       "OSPF Link State Request\n"
793       "OSPF Link State Update\n"
794       "OSPF Link State Acknowledgment\n"
795       "OSPF all packets\n"
796       "Packet sent\n"
797       "Packet received\n"
798       "Detail information\n")
799
800ALIAS (debug_ospf_packet,
801       debug_ospf_packet_send_recv_detail_cmd,
802       "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) (detail|)",
803       "Debugging functions\n"
804       "OSPF information\n"
805       "OSPF packets\n"
806       "OSPF Hello\n"
807       "OSPF Database Description\n"
808       "OSPF Link State Request\n"
809       "OSPF Link State Update\n"
810       "OSPF Link State Acknowledgment\n"
811       "OSPF all packets\n"
812       "Packet sent\n"
813       "Packet received\n"
814       "Detail Information\n")
815
816
817DEFUN (no_debug_ospf_packet,
818       no_debug_ospf_packet_all_cmd,
819       "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)",
820       NO_STR
821       DEBUG_STR
822       OSPF_STR
823       "OSPF packets\n"
824       "OSPF Hello\n"
825       "OSPF Database Description\n"
826       "OSPF Link State Request\n"
827       "OSPF Link State Update\n"
828       "OSPF Link State Acknowledgment\n"
829       "OSPF all packets\n")
830{
831  int type = 0;
832  int flag = 0;
833  int i;
834
835  assert (argc > 0);
836
837  /* Check packet type. */
838  if (strncmp (argv[0], "h", 1) == 0)
839    type = OSPF_DEBUG_HELLO;
840  else if (strncmp (argv[0], "d", 1) == 0)
841    type = OSPF_DEBUG_DB_DESC;
842  else if (strncmp (argv[0], "ls-r", 4) == 0)
843    type = OSPF_DEBUG_LS_REQ;
844  else if (strncmp (argv[0], "ls-u", 4) == 0)
845    type = OSPF_DEBUG_LS_UPD;
846  else if (strncmp (argv[0], "ls-a", 4) == 0)
847    type = OSPF_DEBUG_LS_ACK;
848  else if (strncmp (argv[0], "a", 1) == 0)
849    type = OSPF_DEBUG_ALL;
850
851  /* Default, both send and recv. */
852  if (argc == 1)
853    flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL ;
854
855  /* send or recv. */
856  if (argc == 2)
857    {
858      if (strncmp (argv[1], "s", 1) == 0)
859	flag = OSPF_DEBUG_SEND | OSPF_DEBUG_DETAIL;
860      else if (strncmp (argv[1], "r", 1) == 0)
861	flag = OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
862      else if (strncmp (argv[1], "d", 1) == 0)
863	flag = OSPF_DEBUG_DETAIL;
864    }
865
866  /* detail. */
867  if (argc == 3)
868    if (strncmp (argv[2], "d", 1) == 0)
869      flag = OSPF_DEBUG_DETAIL;
870
871  for (i = 0; i < 5; i++)
872    if (type & (0x01 << i))
873      {
874	if (vty->node == CONFIG_NODE)
875	  DEBUG_PACKET_OFF (i, flag);
876	else
877	  TERM_DEBUG_PACKET_OFF (i, flag);
878      }
879
880#ifdef DEBUG
881  for (i = 0; i < 5; i++)
882    zlog_info ("flag[%d] = %d", i, ospf_debug_packet[i]);
883#endif /* DEBUG */
884
885  return CMD_SUCCESS;
886}
887
888ALIAS (no_debug_ospf_packet,
889       no_debug_ospf_packet_send_recv_cmd,
890       "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv|detail)",
891       NO_STR
892       "Debugging functions\n"
893       "OSPF information\n"
894       "OSPF packets\n"
895       "OSPF Hello\n"
896       "OSPF Database Description\n"
897       "OSPF Link State Request\n"
898       "OSPF Link State Update\n"
899       "OSPF Link State Acknowledgment\n"
900       "OSPF all packets\n"
901       "Packet sent\n"
902       "Packet received\n"
903       "Detail Information\n")
904
905ALIAS (no_debug_ospf_packet,
906       no_debug_ospf_packet_send_recv_detail_cmd,
907       "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) (detail|)",
908       NO_STR
909       "Debugging functions\n"
910       "OSPF information\n"
911       "OSPF packets\n"
912       "OSPF Hello\n"
913       "OSPF Database Description\n"
914       "OSPF Link State Request\n"
915       "OSPF Link State Update\n"
916       "OSPF Link State Acknowledgment\n"
917       "OSPF all packets\n"
918       "Packet sent\n"
919       "Packet received\n"
920       "Detail Information\n")
921
922
923DEFUN (debug_ospf_ism,
924       debug_ospf_ism_cmd,
925       "debug ospf ism",
926       DEBUG_STR
927       OSPF_STR
928       "OSPF Interface State Machine\n")
929{
930  if (vty->node == CONFIG_NODE)
931    {
932      if (argc == 0)
933	DEBUG_ON (ism, ISM);
934      else if (argc == 1)
935	{
936	  if (strncmp (argv[0], "s", 1) == 0)
937	    DEBUG_ON (ism, ISM_STATUS);
938	  else if (strncmp (argv[0], "e", 1) == 0)
939	    DEBUG_ON (ism, ISM_EVENTS);
940	  else if (strncmp (argv[0], "t", 1) == 0)
941	    DEBUG_ON (ism, ISM_TIMERS);
942	}
943
944      return CMD_SUCCESS;
945    }
946
947  /* ENABLE_NODE. */
948  if (argc == 0)
949    TERM_DEBUG_ON (ism, ISM);
950  else if (argc == 1)
951    {
952      if (strncmp (argv[0], "s", 1) == 0)
953	TERM_DEBUG_ON (ism, ISM_STATUS);
954      else if (strncmp (argv[0], "e", 1) == 0)
955	TERM_DEBUG_ON (ism, ISM_EVENTS);
956      else if (strncmp (argv[0], "t", 1) == 0)
957	TERM_DEBUG_ON (ism, ISM_TIMERS);
958    }
959
960  return CMD_SUCCESS;
961}
962
963ALIAS (debug_ospf_ism,
964       debug_ospf_ism_sub_cmd,
965       "debug ospf ism (status|events|timers)",
966       DEBUG_STR
967       OSPF_STR
968       "OSPF Interface State Machine\n"
969       "ISM Status Information\n"
970       "ISM Event Information\n"
971       "ISM TImer Information\n")
972
973DEFUN (no_debug_ospf_ism,
974       no_debug_ospf_ism_cmd,
975       "no debug ospf ism",
976       NO_STR
977       DEBUG_STR
978       OSPF_STR
979       "OSPF Interface State Machine")
980{
981  if (vty->node == CONFIG_NODE)
982    {
983      if (argc == 0)
984	DEBUG_OFF (ism, ISM);
985      else if (argc == 1)
986	{
987	  if (strncmp (argv[0], "s", 1) == 0)
988	    DEBUG_OFF (ism, ISM_STATUS);
989	  else if (strncmp (argv[0], "e", 1) == 0)
990	    DEBUG_OFF (ism, ISM_EVENTS);
991	  else if (strncmp (argv[0], "t", 1) == 0)
992	    DEBUG_OFF (ism, ISM_TIMERS);
993	}
994      return CMD_SUCCESS;
995    }
996
997  /* ENABLE_NODE. */
998  if (argc == 0)
999    TERM_DEBUG_OFF (ism, ISM);
1000  else if (argc == 1)
1001    {
1002      if (strncmp (argv[0], "s", 1) == 0)
1003	TERM_DEBUG_OFF (ism, ISM_STATUS);
1004      else if (strncmp (argv[0], "e", 1) == 0)
1005	TERM_DEBUG_OFF (ism, ISM_EVENTS);
1006      else if (strncmp (argv[0], "t", 1) == 0)
1007	TERM_DEBUG_OFF (ism, ISM_TIMERS);
1008    }
1009
1010  return CMD_SUCCESS;
1011}
1012
1013ALIAS (no_debug_ospf_ism,
1014       no_debug_ospf_ism_sub_cmd,
1015       "no debug ospf ism (status|events|timers)",
1016       NO_STR
1017       "Debugging functions\n"
1018       "OSPF information\n"
1019       "OSPF Interface State Machine\n"
1020       "ISM Status Information\n"
1021       "ISM Event Information\n"
1022       "ISM Timer Information\n")
1023
1024
1025DEFUN (debug_ospf_nsm,
1026       debug_ospf_nsm_cmd,
1027       "debug ospf nsm",
1028       DEBUG_STR
1029       OSPF_STR
1030       "OSPF Neighbor State Machine\n")
1031{
1032  if (vty->node == CONFIG_NODE)
1033    {
1034      if (argc == 0)
1035	DEBUG_ON (nsm, NSM);
1036      else if (argc == 1)
1037	{
1038	  if (strncmp (argv[0], "s", 1) == 0)
1039	    DEBUG_ON (nsm, NSM_STATUS);
1040	  else if (strncmp (argv[0], "e", 1) == 0)
1041	    DEBUG_ON (nsm, NSM_EVENTS);
1042	  else if (strncmp (argv[0], "t", 1) == 0)
1043	    DEBUG_ON (nsm, NSM_TIMERS);
1044	}
1045
1046      return CMD_SUCCESS;
1047    }
1048
1049  /* ENABLE_NODE. */
1050  if (argc == 0)
1051    TERM_DEBUG_ON (nsm, NSM);
1052  else if (argc == 1)
1053    {
1054      if (strncmp (argv[0], "s", 1) == 0)
1055	TERM_DEBUG_ON (nsm, NSM_STATUS);
1056      else if (strncmp (argv[0], "e", 1) == 0)
1057	TERM_DEBUG_ON (nsm, NSM_EVENTS);
1058      else if (strncmp (argv[0], "t", 1) == 0)
1059	TERM_DEBUG_ON (nsm, NSM_TIMERS);
1060    }
1061
1062  return CMD_SUCCESS;
1063}
1064
1065ALIAS (debug_ospf_nsm,
1066       debug_ospf_nsm_sub_cmd,
1067       "debug ospf nsm (status|events|timers)",
1068       DEBUG_STR
1069       OSPF_STR
1070       "OSPF Neighbor State Machine\n"
1071       "NSM Status Information\n"
1072       "NSM Event Information\n"
1073       "NSM Timer Information\n")
1074
1075DEFUN (no_debug_ospf_nsm,
1076       no_debug_ospf_nsm_cmd,
1077       "no debug ospf nsm",
1078       NO_STR
1079       DEBUG_STR
1080       OSPF_STR
1081       "OSPF Neighbor State Machine")
1082{
1083  if (vty->node == CONFIG_NODE)
1084    {
1085      if (argc == 0)
1086	DEBUG_OFF (nsm, NSM);
1087      else if (argc == 1)
1088	{
1089	  if (strncmp (argv[0], "s", 1) == 0)
1090	    DEBUG_OFF (nsm, NSM_STATUS);
1091	  else if (strncmp (argv[0], "e", 1) == 0)
1092	    DEBUG_OFF (nsm, NSM_EVENTS);
1093	  else if (strncmp (argv[0], "t", 1) == 0)
1094	    DEBUG_OFF (nsm, NSM_TIMERS);
1095	}
1096
1097      return CMD_SUCCESS;
1098    }
1099
1100  /* ENABLE_NODE. */
1101  if (argc == 0)
1102    TERM_DEBUG_OFF (nsm, NSM);
1103  else if (argc == 1)
1104    {
1105      if (strncmp (argv[0], "s", 1) == 0)
1106	TERM_DEBUG_OFF (nsm, NSM_STATUS);
1107      else if (strncmp (argv[0], "e", 1) == 0)
1108	TERM_DEBUG_OFF (nsm, NSM_EVENTS);
1109      else if (strncmp (argv[0], "t", 1) == 0)
1110	TERM_DEBUG_OFF (nsm, NSM_TIMERS);
1111    }
1112
1113  return CMD_SUCCESS;
1114}
1115
1116ALIAS (no_debug_ospf_nsm,
1117       no_debug_ospf_nsm_sub_cmd,
1118       "no debug ospf nsm (status|events|timers)",
1119       NO_STR
1120       "Debugging functions\n"
1121       "OSPF information\n"
1122       "OSPF Interface State Machine\n"
1123       "NSM Status Information\n"
1124       "NSM Event Information\n"
1125       "NSM Timer Information\n")
1126
1127
1128DEFUN (debug_ospf_lsa,
1129       debug_ospf_lsa_cmd,
1130       "debug ospf lsa",
1131       DEBUG_STR
1132       OSPF_STR
1133       "OSPF Link State Advertisement\n")
1134{
1135  if (vty->node == CONFIG_NODE)
1136    {
1137      if (argc == 0)
1138	DEBUG_ON (lsa, LSA);
1139      else if (argc == 1)
1140	{
1141	  if (strncmp (argv[0], "g", 1) == 0)
1142	    DEBUG_ON (lsa, LSA_GENERATE);
1143	  else if (strncmp (argv[0], "f", 1) == 0)
1144	    DEBUG_ON (lsa, LSA_FLOODING);
1145	  else if (strncmp (argv[0], "i", 1) == 0)
1146	    DEBUG_ON (lsa, LSA_INSTALL);
1147	  else if (strncmp (argv[0], "r", 1) == 0)
1148	    DEBUG_ON (lsa, LSA_REFRESH);
1149	}
1150
1151      return CMD_SUCCESS;
1152    }
1153
1154  /* ENABLE_NODE. */
1155  if (argc == 0)
1156    TERM_DEBUG_ON (lsa, LSA);
1157  else if (argc == 1)
1158    {
1159      if (strncmp (argv[0], "g", 1) == 0)
1160	TERM_DEBUG_ON (lsa, LSA_GENERATE);
1161      else if (strncmp (argv[0], "f", 1) == 0)
1162	TERM_DEBUG_ON (lsa, LSA_FLOODING);
1163      else if (strncmp (argv[0], "i", 1) == 0)
1164	TERM_DEBUG_ON (lsa, LSA_INSTALL);
1165      else if (strncmp (argv[0], "r", 1) == 0)
1166	TERM_DEBUG_ON (lsa, LSA_REFRESH);
1167    }
1168
1169  return CMD_SUCCESS;
1170}
1171
1172ALIAS (debug_ospf_lsa,
1173       debug_ospf_lsa_sub_cmd,
1174       "debug ospf lsa (generate|flooding|install|refresh)",
1175       DEBUG_STR
1176       OSPF_STR
1177       "OSPF Link State Advertisement\n"
1178       "LSA Generation\n"
1179       "LSA Flooding\n"
1180       "LSA Install/Delete\n"
1181       "LSA Refresh\n")
1182
1183DEFUN (no_debug_ospf_lsa,
1184       no_debug_ospf_lsa_cmd,
1185       "no debug ospf lsa",
1186       NO_STR
1187       DEBUG_STR
1188       OSPF_STR
1189       "OSPF Link State Advertisement\n")
1190{
1191  if (vty->node == CONFIG_NODE)
1192    {
1193      if (argc == 0)
1194	DEBUG_OFF (lsa, LSA);
1195      else if (argc == 1)
1196	{
1197	  if (strncmp (argv[0], "g", 1) == 0)
1198	    DEBUG_OFF (lsa, LSA_GENERATE);
1199	  else if (strncmp (argv[0], "f", 1) == 0)
1200	    DEBUG_OFF (lsa, LSA_FLOODING);
1201	  else if (strncmp (argv[0], "i", 1) == 0)
1202	    DEBUG_OFF (lsa, LSA_INSTALL);
1203	  else if (strncmp (argv[0], "r", 1) == 0)
1204	    DEBUG_OFF (lsa, LSA_REFRESH);
1205	}
1206
1207      return CMD_SUCCESS;
1208    }
1209
1210  /* ENABLE_NODE. */
1211  if (argc == 0)
1212    TERM_DEBUG_OFF (lsa, LSA);
1213  else if (argc == 1)
1214    {
1215      if (strncmp (argv[0], "g", 1) == 0)
1216	TERM_DEBUG_OFF (lsa, LSA_GENERATE);
1217      else if (strncmp (argv[0], "f", 1) == 0)
1218	TERM_DEBUG_OFF (lsa, LSA_FLOODING);
1219      else if (strncmp (argv[0], "i", 1) == 0)
1220	TERM_DEBUG_OFF (lsa, LSA_INSTALL);
1221      else if (strncmp (argv[0], "r", 1) == 0)
1222	TERM_DEBUG_OFF (lsa, LSA_REFRESH);
1223    }
1224
1225  return CMD_SUCCESS;
1226}
1227
1228ALIAS (no_debug_ospf_lsa,
1229       no_debug_ospf_lsa_sub_cmd,
1230       "no debug ospf lsa (generate|flooding|install|refresh)",
1231       NO_STR
1232       DEBUG_STR
1233       OSPF_STR
1234       "OSPF Link State Advertisement\n"
1235       "LSA Generation\n"
1236       "LSA Flooding\n"
1237       "LSA Install/Delete\n"
1238       "LSA Refres\n")
1239
1240
1241DEFUN (debug_ospf_zebra,
1242       debug_ospf_zebra_cmd,
1243       "debug ospf zebra",
1244       DEBUG_STR
1245       OSPF_STR
1246       "OSPF Zebra information\n")
1247{
1248  if (vty->node == CONFIG_NODE)
1249    {
1250      if (argc == 0)
1251	DEBUG_ON (zebra, ZEBRA);
1252      else if (argc == 1)
1253	{
1254	  if (strncmp (argv[0], "i", 1) == 0)
1255	    DEBUG_ON (zebra, ZEBRA_INTERFACE);
1256	  else if (strncmp (argv[0], "r", 1) == 0)
1257	    DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
1258	}
1259
1260      return CMD_SUCCESS;
1261    }
1262
1263  /* ENABLE_NODE. */
1264  if (argc == 0)
1265    TERM_DEBUG_ON (zebra, ZEBRA);
1266  else if (argc == 1)
1267    {
1268      if (strncmp (argv[0], "i", 1) == 0)
1269	TERM_DEBUG_ON (zebra, ZEBRA_INTERFACE);
1270      else if (strncmp (argv[0], "r", 1) == 0)
1271	TERM_DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
1272    }
1273
1274  return CMD_SUCCESS;
1275}
1276
1277ALIAS (debug_ospf_zebra,
1278       debug_ospf_zebra_sub_cmd,
1279       "debug ospf zebra (interface|redistribute)",
1280       DEBUG_STR
1281       OSPF_STR
1282       "OSPF Zebra information\n"
1283       "Zebra interface\n"
1284       "Zebra redistribute\n")
1285
1286DEFUN (no_debug_ospf_zebra,
1287       no_debug_ospf_zebra_cmd,
1288       "no debug ospf zebra",
1289       NO_STR
1290       DEBUG_STR
1291       OSPF_STR
1292       "OSPF Zebra information\n")
1293{
1294  if (vty->node == CONFIG_NODE)
1295    {
1296      if (argc == 0)
1297	DEBUG_OFF (zebra, ZEBRA);
1298      else if (argc == 1)
1299	{
1300	  if (strncmp (argv[0], "i", 1) == 0)
1301	    DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1302	  else if (strncmp (argv[0], "r", 1) == 0)
1303	    DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1304	}
1305
1306      return CMD_SUCCESS;
1307    }
1308
1309  /* ENABLE_NODE. */
1310  if (argc == 0)
1311    TERM_DEBUG_OFF (zebra, ZEBRA);
1312  else if (argc == 1)
1313    {
1314      if (strncmp (argv[0], "i", 1) == 0)
1315	TERM_DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1316      else if (strncmp (argv[0], "r", 1) == 0)
1317	TERM_DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1318    }
1319
1320  return CMD_SUCCESS;
1321}
1322
1323ALIAS (no_debug_ospf_zebra,
1324       no_debug_ospf_zebra_sub_cmd,
1325       "no debug ospf zebra (interface|redistribute)",
1326       NO_STR
1327       DEBUG_STR
1328       OSPF_STR
1329       "OSPF Zebra information\n"
1330       "Zebra interface\n"
1331       "Zebra redistribute\n")
1332
1333DEFUN (debug_ospf_event,
1334       debug_ospf_event_cmd,
1335       "debug ospf event",
1336       DEBUG_STR
1337       OSPF_STR
1338       "OSPF event information\n")
1339{
1340  if (vty->node == CONFIG_NODE)
1341    CONF_DEBUG_ON (event, EVENT);
1342  TERM_DEBUG_ON (event, EVENT);
1343  return CMD_SUCCESS;
1344}
1345
1346DEFUN (no_debug_ospf_event,
1347       no_debug_ospf_event_cmd,
1348       "no debug ospf event",
1349       NO_STR
1350       DEBUG_STR
1351       OSPF_STR
1352       "OSPF event information\n")
1353{
1354  if (vty->node == CONFIG_NODE)
1355    CONF_DEBUG_OFF (event, EVENT);
1356  TERM_DEBUG_OFF (event, EVENT);
1357  return CMD_SUCCESS;
1358}
1359
1360DEFUN (debug_ospf_nssa,
1361       debug_ospf_nssa_cmd,
1362       "debug ospf nssa",
1363       DEBUG_STR
1364       OSPF_STR
1365       "OSPF nssa information\n")
1366{
1367  if (vty->node == CONFIG_NODE)
1368    CONF_DEBUG_ON (nssa, NSSA);
1369  TERM_DEBUG_ON (nssa, NSSA);
1370  return CMD_SUCCESS;
1371}
1372
1373DEFUN (no_debug_ospf_nssa,
1374       no_debug_ospf_nssa_cmd,
1375       "no debug ospf nssa",
1376       NO_STR
1377       DEBUG_STR
1378       OSPF_STR
1379       "OSPF nssa information\n")
1380{
1381  if (vty->node == CONFIG_NODE)
1382    CONF_DEBUG_OFF (nssa, NSSA);
1383  TERM_DEBUG_OFF (nssa, NSSA);
1384  return CMD_SUCCESS;
1385}
1386
1387
1388DEFUN (show_debugging_ospf,
1389       show_debugging_ospf_cmd,
1390       "show debugging ospf",
1391       SHOW_STR
1392       DEBUG_STR
1393       OSPF_STR)
1394{
1395  int i;
1396
1397  vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE);
1398
1399  /* Show debug status for ISM. */
1400  if (IS_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
1401    vty_out (vty, "  OSPF ISM debugging is on%s", VTY_NEWLINE);
1402  else
1403    {
1404      if (IS_DEBUG_OSPF (ism, ISM_STATUS))
1405	vty_out (vty, "  OSPF ISM status debugging is on%s", VTY_NEWLINE);
1406      if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
1407	vty_out (vty, "  OSPF ISM event debugging is on%s", VTY_NEWLINE);
1408      if (IS_DEBUG_OSPF (ism, ISM_TIMERS))
1409	vty_out (vty, "  OSPF ISM timer debugging is on%s", VTY_NEWLINE);
1410    }
1411
1412  /* Show debug status for NSM. */
1413  if (IS_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
1414    vty_out (vty, "  OSPF NSM debugging is on%s", VTY_NEWLINE);
1415  else
1416    {
1417      if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
1418	vty_out (vty, "  OSPF NSM status debugging is on%s", VTY_NEWLINE);
1419      if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
1420	vty_out (vty, "  OSPF NSM event debugging is on%s", VTY_NEWLINE);
1421      if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
1422	vty_out (vty, "  OSPF NSM timer debugging is on%s", VTY_NEWLINE);
1423    }
1424
1425  /* Show debug status for OSPF Packets. */
1426  for (i = 0; i < 5; i++)
1427    if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV))
1428      {
1429	vty_out (vty, "  OSPF packet %s%s debugging is on%s",
1430		 ospf_packet_type_str[i + 1],
1431		 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1432		 VTY_NEWLINE);
1433      }
1434    else
1435      {
1436	if (IS_DEBUG_OSPF_PACKET (i, SEND))
1437	  vty_out (vty, "  OSPF packet %s send%s debugging is on%s",
1438		   ospf_packet_type_str[i + 1],
1439		   IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1440		   VTY_NEWLINE);
1441	if (IS_DEBUG_OSPF_PACKET (i, RECV))
1442	  vty_out (vty, "  OSPF packet %s receive%s debugging is on%s",
1443		   ospf_packet_type_str[i + 1],
1444		   IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1445		   VTY_NEWLINE);
1446      }
1447
1448  /* Show debug status for OSPF LSAs. */
1449  if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
1450    vty_out (vty, "  OSPF LSA debugging is on%s", VTY_NEWLINE);
1451  else
1452    {
1453      if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1454	vty_out (vty, "  OSPF LSA generation debugging is on%s", VTY_NEWLINE);
1455      if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
1456	vty_out (vty, "  OSPF LSA flooding debugging is on%s", VTY_NEWLINE);
1457      if (IS_DEBUG_OSPF (lsa, LSA_INSTALL))
1458	vty_out (vty, "  OSPF LSA install debugging is on%s", VTY_NEWLINE);
1459      if (IS_DEBUG_OSPF (lsa, LSA_REFRESH))
1460	vty_out (vty, "  OSPF LSA refresh debugging is on%s", VTY_NEWLINE);
1461    }
1462
1463  /* Show debug status for Zebra. */
1464  if (IS_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1465    vty_out (vty, "  OSPF Zebra debugging is on%s", VTY_NEWLINE);
1466  else
1467    {
1468      if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
1469	vty_out (vty, "  OSPF Zebra interface debugging is on%s", VTY_NEWLINE);
1470      if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
1471	vty_out (vty, "  OSPF Zebra redistribute debugging is on%s", VTY_NEWLINE);
1472    }
1473
1474  return CMD_SUCCESS;
1475}
1476
1477/* Debug node. */
1478struct cmd_node debug_node =
1479{
1480  DEBUG_NODE,
1481  ""
1482};
1483
1484int
1485config_write_debug (struct vty *vty)
1486{
1487  int write = 0;
1488  int i, r;
1489
1490  char *type_str[] = {"hello", "dd", "ls-request", "ls-update", "ls-ack"};
1491  char *detail_str[] = {"", " send", " recv", "", " detail",
1492			" send detail", " recv detail", " detail"};
1493
1494  /* debug ospf ism (status|events|timers). */
1495  if (IS_CONF_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
1496    vty_out (vty, "debug ospf ism%s", VTY_NEWLINE);
1497  else
1498    {
1499      if (IS_CONF_DEBUG_OSPF (ism, ISM_STATUS))
1500	vty_out (vty, "debug ospf ism status%s", VTY_NEWLINE);
1501      if (IS_CONF_DEBUG_OSPF (ism, ISM_EVENTS))
1502	vty_out (vty, "debug ospf ism event%s", VTY_NEWLINE);
1503      if (IS_CONF_DEBUG_OSPF (ism, ISM_TIMERS))
1504	vty_out (vty, "debug ospf ism timer%s", VTY_NEWLINE);
1505    }
1506
1507  /* debug ospf nsm (status|events|timers). */
1508  if (IS_CONF_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
1509    vty_out (vty, "debug ospf nsm%s", VTY_NEWLINE);
1510  else
1511    {
1512      if (IS_CONF_DEBUG_OSPF (nsm, NSM_STATUS))
1513	vty_out (vty, "debug ospf ism status%s", VTY_NEWLINE);
1514      if (IS_CONF_DEBUG_OSPF (nsm, NSM_EVENTS))
1515	vty_out (vty, "debug ospf nsm event%s", VTY_NEWLINE);
1516      if (IS_CONF_DEBUG_OSPF (nsm, NSM_TIMERS))
1517	vty_out (vty, "debug ospf nsm timer%s", VTY_NEWLINE);
1518    }
1519
1520  /* debug ospf lsa (generate|flooding|install|refresh). */
1521  if (IS_CONF_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
1522    vty_out (vty, "debug ospf lsa%s", VTY_NEWLINE);
1523  else
1524    {
1525      if (IS_CONF_DEBUG_OSPF (lsa, LSA_GENERATE))
1526	vty_out (vty, "debug ospf lsa generate%s", VTY_NEWLINE);
1527      if (IS_CONF_DEBUG_OSPF (lsa, LSA_FLOODING))
1528	vty_out (vty, "debug ospf lsa flooding%s", VTY_NEWLINE);
1529      if (IS_CONF_DEBUG_OSPF (lsa, LSA_INSTALL))
1530	vty_out (vty, "debug ospf lsa install%s", VTY_NEWLINE);
1531      if (IS_CONF_DEBUG_OSPF (lsa, LSA_REFRESH))
1532	vty_out (vty, "debug ospf lsa refresh%s", VTY_NEWLINE);
1533
1534      write = 1;
1535    }
1536
1537  /* debug ospf zebra (interface|redistribute). */
1538  if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1539    vty_out (vty, "debug ospf zebra%s", VTY_NEWLINE);
1540  else
1541    {
1542      if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
1543	vty_out (vty, "debug ospf zebra interface%s", VTY_NEWLINE);
1544      if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
1545	vty_out (vty, "debug ospf zebra redistribute%s", VTY_NEWLINE);
1546
1547      write = 1;
1548    }
1549
1550  /* debug ospf event. */
1551  if (IS_CONF_DEBUG_OSPF (event, EVENT) == OSPF_DEBUG_EVENT)
1552    {
1553      vty_out (vty, "debug ospf event%s", VTY_NEWLINE);
1554      write = 1;
1555    }
1556
1557  /* debug ospf nssa. */
1558  if (IS_CONF_DEBUG_OSPF (nssa, NSSA) == OSPF_DEBUG_NSSA)
1559    {
1560      vty_out (vty, "debug ospf nssa%s", VTY_NEWLINE);
1561      write = 1;
1562    }
1563
1564  /* debug ospf packet all detail. */
1565  r = OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL;
1566  for (i = 0; i < 5; i++)
1567    r &= conf_debug_ospf_packet[i] & (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL);
1568  if (r == (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL))
1569    {
1570      vty_out (vty, "debug ospf packet all detail%s", VTY_NEWLINE);
1571      return 1;
1572    }
1573
1574  /* debug ospf packet all. */
1575  r = OSPF_DEBUG_SEND_RECV;
1576  for (i = 0; i < 5; i++)
1577    r &= conf_debug_ospf_packet[i] & OSPF_DEBUG_SEND_RECV;
1578  if (r == OSPF_DEBUG_SEND_RECV)
1579    {
1580      vty_out (vty, "debug ospf packet all%s", VTY_NEWLINE);
1581      for (i = 0; i < 5; i++)
1582	if (conf_debug_ospf_packet[i] & OSPF_DEBUG_DETAIL)
1583	  vty_out (vty, "debug ospf packet %s detail%s",
1584		   type_str[i],
1585		   VTY_NEWLINE);
1586      return 1;
1587    }
1588
1589  /* debug ospf packet (hello|dd|ls-request|ls-update|ls-ack)
1590     (send|recv) (detail). */
1591  for (i = 0; i < 5; i++)
1592    {
1593      if (conf_debug_ospf_packet[i] == 0)
1594	continue;
1595
1596      vty_out (vty, "debug ospf packet %s%s%s",
1597	       type_str[i], detail_str[conf_debug_ospf_packet[i]],
1598	       VTY_NEWLINE);
1599      write = 1;
1600    }
1601
1602  return write;
1603}
1604
1605/* Initialize debug commands. */
1606void
1607debug_init ()
1608{
1609  install_node (&debug_node, config_write_debug);
1610
1611  install_element (ENABLE_NODE, &show_debugging_ospf_cmd);
1612  install_element (ENABLE_NODE, &debug_ospf_packet_send_recv_detail_cmd);
1613  install_element (ENABLE_NODE, &debug_ospf_packet_send_recv_cmd);
1614  install_element (ENABLE_NODE, &debug_ospf_packet_all_cmd);
1615  install_element (ENABLE_NODE, &debug_ospf_ism_sub_cmd);
1616  install_element (ENABLE_NODE, &debug_ospf_ism_cmd);
1617  install_element (ENABLE_NODE, &debug_ospf_nsm_sub_cmd);
1618  install_element (ENABLE_NODE, &debug_ospf_nsm_cmd);
1619  install_element (ENABLE_NODE, &debug_ospf_lsa_sub_cmd);
1620  install_element (ENABLE_NODE, &debug_ospf_lsa_cmd);
1621  install_element (ENABLE_NODE, &debug_ospf_zebra_sub_cmd);
1622  install_element (ENABLE_NODE, &debug_ospf_zebra_cmd);
1623  install_element (ENABLE_NODE, &debug_ospf_event_cmd);
1624#ifdef HAVE_NSSA
1625  install_element (ENABLE_NODE, &debug_ospf_nssa_cmd);
1626#endif /* HAVE_NSSA */
1627  install_element (ENABLE_NODE, &no_debug_ospf_packet_send_recv_detail_cmd);
1628  install_element (ENABLE_NODE, &no_debug_ospf_packet_send_recv_cmd);
1629  install_element (ENABLE_NODE, &no_debug_ospf_packet_all_cmd);
1630  install_element (ENABLE_NODE, &no_debug_ospf_ism_sub_cmd);
1631  install_element (ENABLE_NODE, &no_debug_ospf_ism_cmd);
1632  install_element (ENABLE_NODE, &no_debug_ospf_nsm_sub_cmd);
1633  install_element (ENABLE_NODE, &no_debug_ospf_nsm_cmd);
1634  install_element (ENABLE_NODE, &no_debug_ospf_lsa_sub_cmd);
1635  install_element (ENABLE_NODE, &no_debug_ospf_lsa_cmd);
1636  install_element (ENABLE_NODE, &no_debug_ospf_zebra_sub_cmd);
1637  install_element (ENABLE_NODE, &no_debug_ospf_zebra_cmd);
1638  install_element (ENABLE_NODE, &no_debug_ospf_event_cmd);
1639#ifdef HAVE_NSSA
1640  install_element (ENABLE_NODE, &no_debug_ospf_nssa_cmd);
1641#endif /* HAVE_NSSA */
1642
1643  install_element (CONFIG_NODE, &debug_ospf_packet_send_recv_detail_cmd);
1644  install_element (CONFIG_NODE, &debug_ospf_packet_send_recv_cmd);
1645  install_element (CONFIG_NODE, &debug_ospf_packet_all_cmd);
1646  install_element (CONFIG_NODE, &debug_ospf_ism_sub_cmd);
1647  install_element (CONFIG_NODE, &debug_ospf_ism_cmd);
1648  install_element (CONFIG_NODE, &debug_ospf_nsm_sub_cmd);
1649  install_element (CONFIG_NODE, &debug_ospf_nsm_cmd);
1650  install_element (CONFIG_NODE, &debug_ospf_lsa_sub_cmd);
1651  install_element (CONFIG_NODE, &debug_ospf_lsa_cmd);
1652  install_element (CONFIG_NODE, &debug_ospf_zebra_sub_cmd);
1653  install_element (CONFIG_NODE, &debug_ospf_zebra_cmd);
1654  install_element (CONFIG_NODE, &debug_ospf_event_cmd);
1655#ifdef HAVE_NSSA
1656  install_element (CONFIG_NODE, &debug_ospf_nssa_cmd);
1657#endif /* HAVE_NSSA */
1658  install_element (CONFIG_NODE, &no_debug_ospf_packet_send_recv_detail_cmd);
1659  install_element (CONFIG_NODE, &no_debug_ospf_packet_send_recv_cmd);
1660  install_element (CONFIG_NODE, &no_debug_ospf_packet_all_cmd);
1661  install_element (CONFIG_NODE, &no_debug_ospf_ism_sub_cmd);
1662  install_element (CONFIG_NODE, &no_debug_ospf_ism_cmd);
1663  install_element (CONFIG_NODE, &no_debug_ospf_nsm_sub_cmd);
1664  install_element (CONFIG_NODE, &no_debug_ospf_nsm_cmd);
1665  install_element (CONFIG_NODE, &no_debug_ospf_lsa_sub_cmd);
1666  install_element (CONFIG_NODE, &no_debug_ospf_lsa_cmd);
1667  install_element (CONFIG_NODE, &no_debug_ospf_zebra_sub_cmd);
1668  install_element (CONFIG_NODE, &no_debug_ospf_zebra_cmd);
1669  install_element (CONFIG_NODE, &no_debug_ospf_event_cmd);
1670#ifdef HAVE_NSSA
1671  install_element (CONFIG_NODE, &no_debug_ospf_nssa_cmd);
1672#endif /* HAVE_NSSA */
1673}
1674