]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_dump.c
Revert "lib: Macroize CLI matcher tracing"
[mirror_frr.git] / ospfd / ospf_dump.c
CommitLineData
718e3744 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"
aa20c6f1 31#include "sockopt.h"
718e3744 32
33#include "ospfd/ospfd.h"
34#include "ospfd/ospf_interface.h"
35#include "ospfd/ospf_ism.h"
36#include "ospfd/ospf_asbr.h"
37#include "ospfd/ospf_lsa.h"
38#include "ospfd/ospf_lsdb.h"
39#include "ospfd/ospf_neighbor.h"
40#include "ospfd/ospf_nsm.h"
41#include "ospfd/ospf_dump.h"
42#include "ospfd/ospf_packet.h"
43#include "ospfd/ospf_network.h"
44
7ba82f70 45const struct message ospf_ism_state_msg[] =
718e3744 46{
47 { ISM_DependUpon, "DependUpon" },
48 { ISM_Down, "Down" },
49 { ISM_Loopback, "Loopback" },
50 { ISM_Waiting, "Waiting" },
51 { ISM_PointToPoint, "Point-To-Point" },
52 { ISM_DROther, "DROther" },
53 { ISM_Backup, "Backup" },
54 { ISM_DR, "DR" },
55};
7ba82f70 56const int ospf_ism_state_msg_max = OSPF_ISM_STATE_MAX;
718e3744 57
7ba82f70 58const struct message ospf_nsm_state_msg[] =
718e3744 59{
60 { NSM_DependUpon, "DependUpon" },
1f2c2743 61 { NSM_Deleted, "Deleted" },
718e3744 62 { NSM_Down, "Down" },
63 { NSM_Attempt, "Attempt" },
64 { NSM_Init, "Init" },
65 { NSM_TwoWay, "2-Way" },
66 { NSM_ExStart, "ExStart" },
67 { NSM_Exchange, "Exchange" },
68 { NSM_Loading, "Loading" },
69 { NSM_Full, "Full" },
70};
7ba82f70 71const int ospf_nsm_state_msg_max = OSPF_NSM_STATE_MAX;
718e3744 72
7ba82f70 73const struct message ospf_lsa_type_msg[] =
718e3744 74{
75 { OSPF_UNKNOWN_LSA, "unknown" },
76 { OSPF_ROUTER_LSA, "router-LSA" },
77 { OSPF_NETWORK_LSA, "network-LSA" },
78 { OSPF_SUMMARY_LSA, "summary-LSA" },
79 { OSPF_ASBR_SUMMARY_LSA, "summary-LSA" },
80 { OSPF_AS_EXTERNAL_LSA, "AS-external-LSA" },
81 { OSPF_GROUP_MEMBER_LSA, "GROUP MEMBER LSA" },
82 { OSPF_AS_NSSA_LSA, "NSSA-LSA" },
83 { 8, "Type-8 LSA" },
84 { OSPF_OPAQUE_LINK_LSA, "Link-Local Opaque-LSA" },
85 { OSPF_OPAQUE_AREA_LSA, "Area-Local Opaque-LSA" },
86 { OSPF_OPAQUE_AS_LSA, "AS-external Opaque-LSA" },
87};
7ba82f70 88const int ospf_lsa_type_msg_max = OSPF_MAX_LSA;
718e3744 89
7ba82f70 90const struct message ospf_link_state_id_type_msg[] =
718e3744 91{
92 { OSPF_UNKNOWN_LSA, "(unknown)" },
93 { OSPF_ROUTER_LSA, "" },
94 { OSPF_NETWORK_LSA, "(address of Designated Router)" },
95 { OSPF_SUMMARY_LSA, "(summary Network Number)" },
96 { OSPF_ASBR_SUMMARY_LSA, "(AS Boundary Router address)" },
97 { OSPF_AS_EXTERNAL_LSA, "(External Network Number)" },
98 { OSPF_GROUP_MEMBER_LSA, "(Group membership information)" },
99 { OSPF_AS_NSSA_LSA, "(External Network Number for NSSA)" },
100 { 8, "(Type-8 LSID)" },
101 { OSPF_OPAQUE_LINK_LSA, "(Link-Local Opaque-Type/ID)" },
102 { OSPF_OPAQUE_AREA_LSA, "(Area-Local Opaque-Type/ID)" },
103 { OSPF_OPAQUE_AS_LSA, "(AS-external Opaque-Type/ID)" },
104};
7ba82f70 105const int ospf_link_state_id_type_msg_max = OSPF_MAX_LSA;
718e3744 106
7ba82f70 107const struct message ospf_network_type_msg[] =
718e3744 108{
109 { OSPF_IFTYPE_NONE, "NONE" },
110 { OSPF_IFTYPE_POINTOPOINT, "Point-to-Point" },
111 { OSPF_IFTYPE_BROADCAST, "Broadcast" },
112 { OSPF_IFTYPE_NBMA, "NBMA" },
113 { OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint" },
114 { OSPF_IFTYPE_VIRTUALLINK, "Virtual-Link" },
115};
7ba82f70 116const int ospf_network_type_msg_max = OSPF_IFTYPE_MAX;
718e3744 117
ef1b78cb
DO
118/* AuType */
119const struct message ospf_auth_type_str[] =
120{
121 { OSPF_AUTH_NULL, "Null" },
122 { OSPF_AUTH_SIMPLE, "Simple" },
123 { OSPF_AUTH_CRYPTOGRAPHIC, "Cryptographic" },
124};
125const size_t ospf_auth_type_str_max = sizeof (ospf_auth_type_str) /
126 sizeof (ospf_auth_type_str[0]);
127
718e3744 128/* Configuration debug option variables. */
129unsigned long conf_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
130unsigned long conf_debug_ospf_event = 0;
131unsigned long conf_debug_ospf_ism = 0;
132unsigned long conf_debug_ospf_nsm = 0;
133unsigned long conf_debug_ospf_lsa = 0;
134unsigned long conf_debug_ospf_zebra = 0;
135unsigned long conf_debug_ospf_nssa = 0;
16f1b9ee 136unsigned long conf_debug_ospf_te = 0;
718e3744 137
138/* Enable debug option variables -- valid only session. */
139unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
140unsigned long term_debug_ospf_event = 0;
141unsigned long term_debug_ospf_ism = 0;
142unsigned long term_debug_ospf_nsm = 0;
143unsigned long term_debug_ospf_lsa = 0;
144unsigned long term_debug_ospf_zebra = 0;
145unsigned long term_debug_ospf_nssa = 0;
16f1b9ee 146unsigned long term_debug_ospf_te = 0;
6b0655a2 147
f52d13cb 148
149const char *
150ospf_redist_string(u_int route_type)
151{
152 return (route_type == ZEBRA_ROUTE_MAX) ?
153 "Default" : zebra_route_string(route_type);
154}
155
718e3744 156#define OSPF_AREA_STRING_MAXLEN 16
eb1ce605 157const char *
718e3744 158ospf_area_name_string (struct ospf_area *area)
159{
160 static char buf[OSPF_AREA_STRING_MAXLEN] = "";
161 u_int32_t area_id;
162
163 if (!area)
164 return "-";
165
166 area_id = ntohl (area->area_id.s_addr);
167 snprintf (buf, OSPF_AREA_STRING_MAXLEN, "%d.%d.%d.%d",
168 (area_id >> 24) & 0xff, (area_id >> 16) & 0xff,
169 (area_id >> 8) & 0xff, area_id & 0xff);
170 return buf;
171}
172
173#define OSPF_AREA_DESC_STRING_MAXLEN 23
eb1ce605 174const char *
718e3744 175ospf_area_desc_string (struct ospf_area *area)
176{
177 static char buf[OSPF_AREA_DESC_STRING_MAXLEN] = "";
178 u_char type;
179
180 if (!area)
181 return "(incomplete)";
182
183 type = area->external_routing;
184 switch (type)
185 {
186 case OSPF_AREA_NSSA:
187 snprintf (buf, OSPF_AREA_DESC_STRING_MAXLEN, "%s [NSSA]",
188 ospf_area_name_string (area));
189 break;
190 case OSPF_AREA_STUB:
191 snprintf (buf, OSPF_AREA_DESC_STRING_MAXLEN, "%s [Stub]",
192 ospf_area_name_string (area));
193 break;
194 default:
195 return ospf_area_name_string (area);
718e3744 196 }
197
198 return buf;
199}
200
201#define OSPF_IF_STRING_MAXLEN 40
eb1ce605 202const char *
718e3744 203ospf_if_name_string (struct ospf_interface *oi)
204{
205 static char buf[OSPF_IF_STRING_MAXLEN] = "";
206 u_int32_t ifaddr;
207
64e34726 208 if (!oi || !oi->address)
718e3744 209 return "inactive";
210
211 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
212 return oi->ifp->name;
213
214 ifaddr = ntohl (oi->address->u.prefix4.s_addr);
215 snprintf (buf, OSPF_IF_STRING_MAXLEN,
216 "%s:%d.%d.%d.%d", oi->ifp->name,
217 (ifaddr >> 24) & 0xff, (ifaddr >> 16) & 0xff,
218 (ifaddr >> 8) & 0xff, ifaddr & 0xff);
219 return buf;
220}
221
6b0655a2 222
718e3744 223void
224ospf_nbr_state_message (struct ospf_neighbor *nbr, char *buf, size_t size)
225{
226 int state;
227 struct ospf_interface *oi = nbr->oi;
228
229 if (IPV4_ADDR_SAME (&DR (oi), &nbr->address.u.prefix4))
230 state = ISM_DR;
231 else if (IPV4_ADDR_SAME (&BDR (oi), &nbr->address.u.prefix4))
232 state = ISM_Backup;
233 else
234 state = ISM_DROther;
235
236 memset (buf, 0, size);
237
238 snprintf (buf, size, "%s/%s",
239 LOOKUP (ospf_nsm_state_msg, nbr->state),
240 LOOKUP (ospf_ism_state_msg, state));
241}
242
eb1ce605 243const char *
d24f6e2a 244ospf_timeval_dump (struct timeval *t, char *buf, size_t size)
718e3744 245{
d24f6e2a 246 /* Making formatted timer strings. */
247#define MINUTE_IN_SECONDS 60
248#define HOUR_IN_SECONDS (60*MINUTE_IN_SECONDS)
249#define DAY_IN_SECONDS (24*HOUR_IN_SECONDS)
250#define WEEK_IN_SECONDS (7*DAY_IN_SECONDS)
cf744958 251 unsigned long w, d, h, m, s, ms, us;
d24f6e2a 252
718e3744 253 if (!t)
254 return "inactive";
f9ad937f 255
cf744958 256 w = d = h = m = s = ms = us = 0;
d24f6e2a 257 memset (buf, 0, size);
cf744958
DS
258
259 us = t->tv_usec;
260 if (us >= 1000)
261 {
262 ms = us / 1000;
263 us %= 1000;
264 }
265
f9ad937f 266 if (ms >= 1000)
267 {
ea4ffc90 268 t->tv_sec += ms / 1000;
269 ms %= 1000;
f9ad937f 270 }
d24f6e2a 271
272 if (t->tv_sec > WEEK_IN_SECONDS)
718e3744 273 {
d24f6e2a 274 w = t->tv_sec / WEEK_IN_SECONDS;
275 t->tv_sec -= w * WEEK_IN_SECONDS;
718e3744 276 }
d24f6e2a 277
278 if (t->tv_sec > DAY_IN_SECONDS)
718e3744 279 {
d24f6e2a 280 d = t->tv_sec / DAY_IN_SECONDS;
281 t->tv_sec -= d * DAY_IN_SECONDS;
718e3744 282 }
d24f6e2a 283
284 if (t->tv_sec >= HOUR_IN_SECONDS)
285 {
286 h = t->tv_sec / HOUR_IN_SECONDS;
287 t->tv_sec -= h * HOUR_IN_SECONDS;
288 }
289
290 if (t->tv_sec >= MINUTE_IN_SECONDS)
291 {
292 m = t->tv_sec / MINUTE_IN_SECONDS;
293 t->tv_sec -= m * MINUTE_IN_SECONDS;
294 }
295
296 if (w > 99)
297 snprintf (buf, size, "%ldw%1ldd", w, d);
298 else if (w)
299 snprintf (buf, size, "%ldw%1ldd%02ldh", w, d, h);
300 else if (d)
301 snprintf (buf, size, "%1ldd%02ldh%02ldm", d, h, m);
302 else if (h)
8f2c16aa 303 snprintf (buf, size, "%ldh%02ldm%02lds", h, m, (long)t->tv_sec);
d24f6e2a 304 else if (m)
8f2c16aa 305 snprintf (buf, size, "%ldm%02lds", m, (long)t->tv_sec);
cf744958 306 else if (ms)
8f2c16aa 307 snprintf (buf, size, "%ld.%03lds", (long)t->tv_sec, ms);
cf744958 308 else
8f2c16aa 309 snprintf (buf, size, "%ld usecs", (long)t->tv_usec);
cf744958 310
718e3744 311 return buf;
312}
313
d24f6e2a 314const char *
315ospf_timer_dump (struct thread *t, char *buf, size_t size)
316{
317 struct timeval result;
d24f6e2a 318 if (!t)
319 return "inactive";
320
2518efd1 321 result = tv_sub (t->u.sands, recent_relative_time());
d24f6e2a 322 return ospf_timeval_dump (&result, buf, size);
323}
324
718e3744 325#define OSPF_OPTION_STR_MAXLEN 24
326
327char *
328ospf_options_dump (u_char options)
329{
330 static char buf[OSPF_OPTION_STR_MAXLEN];
331
16f1b9ee 332 snprintf (buf, OSPF_OPTION_STR_MAXLEN, "*|%s|%s|%s|%s|%s|%s|%s",
718e3744 333 (options & OSPF_OPTION_O) ? "O" : "-",
334 (options & OSPF_OPTION_DC) ? "DC" : "-",
335 (options & OSPF_OPTION_EA) ? "EA" : "-",
336 (options & OSPF_OPTION_NP) ? "N/P" : "-",
337 (options & OSPF_OPTION_MC) ? "MC" : "-",
16f1b9ee
OD
338 (options & OSPF_OPTION_E) ? "E" : "-",
339 (options & OSPF_OPTION_MT) ? "M/T" : "-");
718e3744 340
341 return buf;
342}
343
4dadc291 344static void
718e3744 345ospf_packet_hello_dump (struct stream *s, u_int16_t length)
346{
347 struct ospf_hello *hello;
348 int i;
349
350 hello = (struct ospf_hello *) STREAM_PNT (s);
351
60925303 352 zlog_debug ("Hello");
353 zlog_debug (" NetworkMask %s", inet_ntoa (hello->network_mask));
354 zlog_debug (" HelloInterval %d", ntohs (hello->hello_interval));
355 zlog_debug (" Options %d (%s)", hello->options,
718e3744 356 ospf_options_dump (hello->options));
60925303 357 zlog_debug (" RtrPriority %d", hello->priority);
358 zlog_debug (" RtrDeadInterval %ld", (u_long)ntohl (hello->dead_interval));
359 zlog_debug (" DRouter %s", inet_ntoa (hello->d_router));
360 zlog_debug (" BDRouter %s", inet_ntoa (hello->bd_router));
718e3744 361
362 length -= OSPF_HEADER_SIZE + OSPF_HELLO_MIN_SIZE;
60925303 363 zlog_debug (" # Neighbors %d", length / 4);
718e3744 364 for (i = 0; length > 0; i++, length -= sizeof (struct in_addr))
60925303 365 zlog_debug (" Neighbor %s", inet_ntoa (hello->neighbors[i]));
718e3744 366}
367
4dadc291 368static char *
718e3744 369ospf_dd_flags_dump (u_char flags, char *buf, size_t size)
370{
371 memset (buf, 0, size);
372
373 snprintf (buf, size, "%s|%s|%s",
374 (flags & OSPF_DD_FLAG_I) ? "I" : "-",
375 (flags & OSPF_DD_FLAG_M) ? "M" : "-",
376 (flags & OSPF_DD_FLAG_MS) ? "MS" : "-");
377
378 return buf;
379}
380
381void
382ospf_lsa_header_dump (struct lsa_header *lsah)
383{
eb1ce605 384 const char *lsah_type = LOOKUP (ospf_lsa_type_msg, lsah->type);
0c2be26c 385
60925303 386 zlog_debug (" LSA Header");
387 zlog_debug (" LS age %d", ntohs (lsah->ls_age));
388 zlog_debug (" Options %d (%s)", lsah->options,
718e3744 389 ospf_options_dump (lsah->options));
60925303 390 zlog_debug (" LS type %d (%s)", lsah->type,
553ff113 391 (lsah->type ? lsah_type : "unknown type"));
60925303 392 zlog_debug (" Link State ID %s", inet_ntoa (lsah->id));
393 zlog_debug (" Advertising Router %s", inet_ntoa (lsah->adv_router));
394 zlog_debug (" LS sequence number 0x%lx", (u_long)ntohl (lsah->ls_seqnum));
395 zlog_debug (" LS checksum 0x%x", ntohs (lsah->checksum));
396 zlog_debug (" length %d", ntohs (lsah->length));
718e3744 397}
398
4dadc291 399static char *
718e3744 400ospf_router_lsa_flags_dump (u_char flags, char *buf, size_t size)
401{
402 memset (buf, 0, size);
403
404 snprintf (buf, size, "%s|%s|%s",
405 (flags & ROUTER_LSA_VIRTUAL) ? "V" : "-",
406 (flags & ROUTER_LSA_EXTERNAL) ? "E" : "-",
407 (flags & ROUTER_LSA_BORDER) ? "B" : "-");
408
409 return buf;
410}
411
4dadc291 412static void
718e3744 413ospf_router_lsa_dump (struct stream *s, u_int16_t length)
414{
415 char buf[BUFSIZ];
416 struct router_lsa *rl;
417 int i, len;
418
419 rl = (struct router_lsa *) STREAM_PNT (s);
420
60925303 421 zlog_debug (" Router-LSA");
422 zlog_debug (" flags %s",
718e3744 423 ospf_router_lsa_flags_dump (rl->flags, buf, BUFSIZ));
60925303 424 zlog_debug (" # links %d", ntohs (rl->links));
718e3744 425
426 len = ntohs (rl->header.length) - OSPF_LSA_HEADER_SIZE - 4;
427 for (i = 0; len > 0; i++)
428 {
60925303 429 zlog_debug (" Link ID %s", inet_ntoa (rl->link[i].link_id));
430 zlog_debug (" Link Data %s", inet_ntoa (rl->link[i].link_data));
431 zlog_debug (" Type %d", (u_char) rl->link[i].type);
432 zlog_debug (" TOS %d", (u_char) rl->link[i].tos);
433 zlog_debug (" metric %d", ntohs (rl->link[i].metric));
718e3744 434
435 len -= 12;
436 }
437}
438
4dadc291 439static void
718e3744 440ospf_network_lsa_dump (struct stream *s, u_int16_t length)
441{
442 struct network_lsa *nl;
443 int i, cnt;
444
445 nl = (struct network_lsa *) STREAM_PNT (s);
446 cnt = (ntohs (nl->header.length) - (OSPF_LSA_HEADER_SIZE + 4)) / 4;
447
60925303 448 zlog_debug (" Network-LSA");
718e3744 449 /*
60925303 450 zlog_debug ("LSA total size %d", ntohs (nl->header.length));
451 zlog_debug ("Network-LSA size %d",
718e3744 452 ntohs (nl->header.length) - OSPF_LSA_HEADER_SIZE);
453 */
60925303 454 zlog_debug (" Network Mask %s", inet_ntoa (nl->mask));
455 zlog_debug (" # Attached Routers %d", cnt);
718e3744 456 for (i = 0; i < cnt; i++)
60925303 457 zlog_debug (" Attached Router %s", inet_ntoa (nl->routers[i]));
718e3744 458}
459
4dadc291 460static void
718e3744 461ospf_summary_lsa_dump (struct stream *s, u_int16_t length)
462{
463 struct summary_lsa *sl;
464 int size;
465 int i;
466
467 sl = (struct summary_lsa *) STREAM_PNT (s);
468
60925303 469 zlog_debug (" Summary-LSA");
470 zlog_debug (" Network Mask %s", inet_ntoa (sl->mask));
718e3744 471
472 size = ntohs (sl->header.length) - OSPF_LSA_HEADER_SIZE - 4;
473 for (i = 0; size > 0; size -= 4, i++)
60925303 474 zlog_debug (" TOS=%d metric %d", sl->tos,
718e3744 475 GET_METRIC (sl->metric));
476}
477
4dadc291 478static void
718e3744 479ospf_as_external_lsa_dump (struct stream *s, u_int16_t length)
480{
481 struct as_external_lsa *al;
482 int size;
483 int i;
484
485 al = (struct as_external_lsa *) STREAM_PNT (s);
60925303 486 zlog_debug (" %s", ospf_lsa_type_msg[al->header.type].str);
487 zlog_debug (" Network Mask %s", inet_ntoa (al->mask));
718e3744 488
489 size = ntohs (al->header.length) - OSPF_LSA_HEADER_SIZE -4;
490 for (i = 0; size > 0; size -= 12, i++)
491 {
60925303 492 zlog_debug (" bit %s TOS=%d metric %d",
718e3744 493 IS_EXTERNAL_METRIC (al->e[i].tos) ? "E" : "-",
494 al->e[i].tos & 0x7f, GET_METRIC (al->e[i].metric));
60925303 495 zlog_debug (" Forwarding address %s", inet_ntoa (al->e[i].fwd_addr));
dc9ffce8 496 zlog_debug (" External Route Tag %"ROUTE_TAG_PRI, al->e[i].route_tag);
718e3744 497 }
498}
499
4dadc291 500static void
718e3744 501ospf_lsa_header_list_dump (struct stream *s, u_int16_t length)
502{
503 struct lsa_header *lsa;
504
60925303 505 zlog_debug (" # LSA Headers %d", length / OSPF_LSA_HEADER_SIZE);
718e3744 506
507 /* LSA Headers. */
508 while (length > 0)
509 {
510 lsa = (struct lsa_header *) STREAM_PNT (s);
511 ospf_lsa_header_dump (lsa);
512
9985f83c 513 stream_forward_getp (s, OSPF_LSA_HEADER_SIZE);
718e3744 514 length -= OSPF_LSA_HEADER_SIZE;
515 }
516}
517
4dadc291 518static void
718e3744 519ospf_packet_db_desc_dump (struct stream *s, u_int16_t length)
520{
521 struct ospf_db_desc *dd;
522 char dd_flags[8];
523
524 u_int32_t gp;
525
526 gp = stream_get_getp (s);
527 dd = (struct ospf_db_desc *) STREAM_PNT (s);
528
60925303 529 zlog_debug ("Database Description");
530 zlog_debug (" Interface MTU %d", ntohs (dd->mtu));
531 zlog_debug (" Options %d (%s)", dd->options,
718e3744 532 ospf_options_dump (dd->options));
60925303 533 zlog_debug (" Flags %d (%s)", dd->flags,
718e3744 534 ospf_dd_flags_dump (dd->flags, dd_flags, sizeof dd_flags));
60925303 535 zlog_debug (" Sequence Number 0x%08lx", (u_long)ntohl (dd->dd_seqnum));
718e3744 536
537 length -= OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE;
538
9985f83c 539 stream_forward_getp (s, OSPF_DB_DESC_MIN_SIZE);
718e3744 540
541 ospf_lsa_header_list_dump (s, length);
542
543 stream_set_getp (s, gp);
544}
545
4dadc291 546static void
718e3744 547ospf_packet_ls_req_dump (struct stream *s, u_int16_t length)
548{
549 u_int32_t sp;
550 u_int32_t ls_type;
551 struct in_addr ls_id;
552 struct in_addr adv_router;
553
554 sp = stream_get_getp (s);
555
556 length -= OSPF_HEADER_SIZE;
557
60925303 558 zlog_debug ("Link State Request");
559 zlog_debug (" # Requests %d", length / 12);
718e3744 560
561 for (; length > 0; length -= 12)
562 {
563 ls_type = stream_getl (s);
564 ls_id.s_addr = stream_get_ipv4 (s);
565 adv_router.s_addr = stream_get_ipv4 (s);
566
60925303 567 zlog_debug (" LS type %d", ls_type);
568 zlog_debug (" Link State ID %s", inet_ntoa (ls_id));
569 zlog_debug (" Advertising Router %s",
718e3744 570 inet_ntoa (adv_router));
571 }
572
573 stream_set_getp (s, sp);
574}
575
4dadc291 576static void
718e3744 577ospf_packet_ls_upd_dump (struct stream *s, u_int16_t length)
578{
579 u_int32_t sp;
580 struct lsa_header *lsa;
581 int lsa_len;
582 u_int32_t count;
583
584 length -= OSPF_HEADER_SIZE;
585
586 sp = stream_get_getp (s);
587
588 count = stream_getl (s);
589 length -= 4;
590
60925303 591 zlog_debug ("Link State Update");
592 zlog_debug (" # LSAs %d", count);
718e3744 593
594 while (length > 0 && count > 0)
595 {
596 if (length < OSPF_HEADER_SIZE || length % 4 != 0)
597 {
60925303 598 zlog_debug (" Remaining %d bytes; Incorrect length.", length);
718e3744 599 break;
600 }
601
602 lsa = (struct lsa_header *) STREAM_PNT (s);
603 lsa_len = ntohs (lsa->length);
604 ospf_lsa_header_dump (lsa);
605
606 switch (lsa->type)
607 {
608 case OSPF_ROUTER_LSA:
609 ospf_router_lsa_dump (s, length);
610 break;
611 case OSPF_NETWORK_LSA:
612 ospf_network_lsa_dump (s, length);
613 break;
614 case OSPF_SUMMARY_LSA:
615 case OSPF_ASBR_SUMMARY_LSA:
616 ospf_summary_lsa_dump (s, length);
617 break;
618 case OSPF_AS_EXTERNAL_LSA:
619 ospf_as_external_lsa_dump (s, length);
620 break;
718e3744 621 case OSPF_AS_NSSA_LSA:
d4a53d58 622 ospf_as_external_lsa_dump (s, length);
718e3744 623 break;
718e3744 624 case OSPF_OPAQUE_LINK_LSA:
625 case OSPF_OPAQUE_AREA_LSA:
626 case OSPF_OPAQUE_AS_LSA:
627 ospf_opaque_lsa_dump (s, length);
628 break;
718e3744 629 default:
630 break;
631 }
632
9985f83c 633 stream_forward_getp (s, lsa_len);
718e3744 634 length -= lsa_len;
635 count--;
636 }
637
638 stream_set_getp (s, sp);
639}
640
4dadc291 641static void
718e3744 642ospf_packet_ls_ack_dump (struct stream *s, u_int16_t length)
643{
644 u_int32_t sp;
645
646 length -= OSPF_HEADER_SIZE;
647 sp = stream_get_getp (s);
648
60925303 649 zlog_debug ("Link State Acknowledgment");
718e3744 650 ospf_lsa_header_list_dump (s, length);
651
652 stream_set_getp (s, sp);
653}
654
6b333611 655/* Expects header to be in host order */
718e3744 656void
6b333611 657ospf_ip_header_dump (struct ip *iph)
718e3744 658{
718e3744 659 /* IP Header dump. */
60925303 660 zlog_debug ("ip_v %d", iph->ip_v);
661 zlog_debug ("ip_hl %d", iph->ip_hl);
662 zlog_debug ("ip_tos %d", iph->ip_tos);
663 zlog_debug ("ip_len %d", iph->ip_len);
664 zlog_debug ("ip_id %u", (u_int32_t) iph->ip_id);
665 zlog_debug ("ip_off %u", (u_int32_t) iph->ip_off);
666 zlog_debug ("ip_ttl %d", iph->ip_ttl);
667 zlog_debug ("ip_p %d", iph->ip_p);
668 zlog_debug ("ip_sum 0x%x", (u_int32_t) iph->ip_sum);
669 zlog_debug ("ip_src %s", inet_ntoa (iph->ip_src));
670 zlog_debug ("ip_dst %s", inet_ntoa (iph->ip_dst));
718e3744 671}
672
4dadc291 673static void
718e3744 674ospf_header_dump (struct ospf_header *ospfh)
675{
676 char buf[9];
ef1b78cb 677 u_int16_t auth_type = ntohs (ospfh->auth_type);
718e3744 678
60925303 679 zlog_debug ("Header");
680 zlog_debug (" Version %d", ospfh->version);
681 zlog_debug (" Type %d (%s)", ospfh->type,
272ca1e3 682 LOOKUP (ospf_packet_type_str, ospfh->type));
60925303 683 zlog_debug (" Packet Len %d", ntohs (ospfh->length));
684 zlog_debug (" Router ID %s", inet_ntoa (ospfh->router_id));
685 zlog_debug (" Area ID %s", inet_ntoa (ospfh->area_id));
686 zlog_debug (" Checksum 0x%x", ntohs (ospfh->checksum));
ef1b78cb 687 zlog_debug (" AuType %s", LOOKUP (ospf_auth_type_str, auth_type));
718e3744 688
ef1b78cb 689 switch (auth_type)
718e3744 690 {
691 case OSPF_AUTH_NULL:
692 break;
693 case OSPF_AUTH_SIMPLE:
694 memset (buf, 0, 9);
c9e52be3 695 strncpy (buf, (char *) ospfh->u.auth_data, 8);
60925303 696 zlog_debug (" Simple Password %s", buf);
718e3744 697 break;
698 case OSPF_AUTH_CRYPTOGRAPHIC:
60925303 699 zlog_debug (" Cryptographic Authentication");
700 zlog_debug (" Key ID %d", ospfh->u.crypt.key_id);
701 zlog_debug (" Auth Data Len %d", ospfh->u.crypt.auth_data_len);
702 zlog_debug (" Sequence number %ld",
718e3744 703 (u_long)ntohl (ospfh->u.crypt.crypt_seqnum));
704 break;
705 default:
60925303 706 zlog_debug ("* This is not supported authentication type");
718e3744 707 break;
708 }
709
710}
711
712void
713ospf_packet_dump (struct stream *s)
714{
715 struct ospf_header *ospfh;
716 unsigned long gp;
717
718 /* Preserve pointer. */
719 gp = stream_get_getp (s);
720
721 /* OSPF Header dump. */
722 ospfh = (struct ospf_header *) STREAM_PNT (s);
723
724 /* Until detail flag is set, return. */
725 if (!(term_debug_ospf_packet[ospfh->type - 1] & OSPF_DEBUG_DETAIL))
726 return;
727
728 /* Show OSPF header detail. */
729 ospf_header_dump (ospfh);
9985f83c 730 stream_forward_getp (s, OSPF_HEADER_SIZE);
718e3744 731
732 switch (ospfh->type)
733 {
734 case OSPF_MSG_HELLO:
735 ospf_packet_hello_dump (s, ntohs (ospfh->length));
736 break;
737 case OSPF_MSG_DB_DESC:
738 ospf_packet_db_desc_dump (s, ntohs (ospfh->length));
739 break;
740 case OSPF_MSG_LS_REQ:
741 ospf_packet_ls_req_dump (s, ntohs (ospfh->length));
742 break;
743 case OSPF_MSG_LS_UPD:
744 ospf_packet_ls_upd_dump (s, ntohs (ospfh->length));
745 break;
746 case OSPF_MSG_LS_ACK:
747 ospf_packet_ls_ack_dump (s, ntohs (ospfh->length));
748 break;
749 default:
750 break;
751 }
752
753 stream_set_getp (s, gp);
754}
755
692b4c65
QY
756DEFUN (debug_ospf_packet,
757 debug_ospf_packet_cmd,
758 "debug ospf [(1-65535)] packet <hello|dd|ls-request|ls-update|ls-ack|all> [<send [detail]|recv [detail]|detail>]",
759 DEBUG_STR
760 OSPF_STR
761 "Instance ID\n"
762 "OSPF packets\n"
763 "OSPF Hello\n"
764 "OSPF Database Description\n"
765 "OSPF Link State Request\n"
766 "OSPF Link State Update\n"
767 "OSPF Link State Acknowledgment\n"
768 "OSPF all packets\n"
769 "Packet sent\n"
770 "Detail Information\n"
771 "Packet received\n"
772 "Detail Information\n"
773 "Detail Information\n")
774{
775 int inst = (argv[2]->type == RANGE_TKN) ? 1 : 0;
776 int detail = strmatch (argv[argc - 1]->text, "detail");
777 int send = strmatch (argv[argc - (1+detail)]->text, "send");
778 int recv = strmatch (argv[argc - (1+detail)]->text, "recv");
779 char *packet = argv[3 + inst]->text;
780
781 if (inst) // user passed instance ID
782 {
783 if (!ospf_lookup_instance (strtoul (argv[2]->arg, NULL, 10)))
784 return CMD_SUCCESS;
785 }
6b0655a2 786
718e3744 787 int type = 0;
788 int flag = 0;
789 int i;
790
718e3744 791 /* Check packet type. */
692b4c65 792 if (strmatch (packet, "hello"))
718e3744 793 type = OSPF_DEBUG_HELLO;
692b4c65 794 else if (strmatch (packet, "dd"))
718e3744 795 type = OSPF_DEBUG_DB_DESC;
692b4c65 796 else if (strmatch (packet, "ls-request"))
718e3744 797 type = OSPF_DEBUG_LS_REQ;
692b4c65 798 else if (strmatch (packet, "ls-update"))
718e3744 799 type = OSPF_DEBUG_LS_UPD;
692b4c65 800 else if (strmatch (packet, "ls-ack"))
718e3744 801 type = OSPF_DEBUG_LS_ACK;
692b4c65 802 else if (strmatch (packet, "all"))
718e3744 803 type = OSPF_DEBUG_ALL;
804
692b4c65
QY
805 /* Cases:
806 * (none) = send + recv
807 * detail = send + recv + detail
808 * recv = recv
809 * send = send
810 * recv detail = recv + detail
811 * send detail = send + detail
812 */
813 if (!send && !recv)
814 send = recv = 1;
815
816 flag |= (send) ? OSPF_DEBUG_SEND : 0;
817 flag |= (recv) ? OSPF_DEBUG_RECV : 0;
818 flag |= (detail) ? OSPF_DEBUG_DETAIL : 0;
718e3744 819
820 for (i = 0; i < 5; i++)
821 if (type & (0x01 << i))
822 {
823 if (vty->node == CONFIG_NODE)
824 DEBUG_PACKET_ON (i, flag);
825 else
826 TERM_DEBUG_PACKET_ON (i, flag);
827 }
828
829 return CMD_SUCCESS;
830}
831
692b4c65
QY
832DEFUN (no_debug_ospf_packet,
833 no_debug_ospf_packet_cmd,
834 "no debug ospf [(1-65535)] packet <hello|dd|ls-request|ls-update|ls-ack|all> [<send [detail]|recv [detail]|detail>]",
835 NO_STR
718e3744 836 DEBUG_STR
837 OSPF_STR
7c8ff89e 838 "Instance ID\n"
718e3744 839 "OSPF packets\n"
840 "OSPF Hello\n"
841 "OSPF Database Description\n"
842 "OSPF Link State Request\n"
843 "OSPF Link State Update\n"
844 "OSPF Link State Acknowledgment\n"
692b4c65
QY
845 "OSPF all packets\n"
846 "Packet sent\n"
847 "Detail Information\n"
848 "Packet received\n"
849 "Detail Information\n"
850 "Detail Information\n")
851{
852 int inst = (argv[3]->type == RANGE_TKN) ? 1 : 0;
853 int detail = strmatch (argv[argc - 1]->text, "detail");
854 int send = strmatch (argv[argc - (1+detail)]->text, "send");
855 int recv = strmatch (argv[argc - (1+detail)]->text, "recv");
856 char *packet = argv[4 + inst]->text;
857
858 if (inst) // user passed instance ID
859 {
860 if (!ospf_lookup_instance (strtoul (argv[3]->arg, NULL, 10)))
861 return CMD_SUCCESS;
862 }
7c8ff89e 863
718e3744 864 int type = 0;
865 int flag = 0;
866 int i;
867
718e3744 868 /* Check packet type. */
692b4c65 869 if (strmatch (packet, "hello"))
718e3744 870 type = OSPF_DEBUG_HELLO;
692b4c65 871 else if (strmatch (packet, "dd"))
718e3744 872 type = OSPF_DEBUG_DB_DESC;
692b4c65 873 else if (strmatch (packet, "ls-request"))
718e3744 874 type = OSPF_DEBUG_LS_REQ;
692b4c65 875 else if (strmatch (packet, "ls-update"))
718e3744 876 type = OSPF_DEBUG_LS_UPD;
692b4c65 877 else if (strmatch (packet, "ls-ack"))
718e3744 878 type = OSPF_DEBUG_LS_ACK;
692b4c65 879 else if (strmatch (packet, "all"))
718e3744 880 type = OSPF_DEBUG_ALL;
881
692b4c65
QY
882 /* Cases:
883 * (none) = send + recv
884 * detail = send + recv + detail
885 * recv = recv
886 * send = send
887 * recv detail = recv + detail
888 * send detail = send + detail
889 */
890 if (!send && !recv)
891 send = recv = 1;
892
893 flag |= (send) ? OSPF_DEBUG_SEND : 0;
894 flag |= (recv) ? OSPF_DEBUG_RECV : 0;
895 flag |= (detail) ? OSPF_DEBUG_DETAIL : 0;
718e3744 896
897 for (i = 0; i < 5; i++)
898 if (type & (0x01 << i))
899 {
900 if (vty->node == CONFIG_NODE)
901 DEBUG_PACKET_OFF (i, flag);
902 else
903 TERM_DEBUG_PACKET_OFF (i, flag);
904 }
905
906#ifdef DEBUG
6638c1ab 907 /*
718e3744 908 for (i = 0; i < 5; i++)
60925303 909 zlog_debug ("flag[%d] = %d", i, ospf_debug_packet[i]);
6638c1ab 910 */
718e3744 911#endif /* DEBUG */
912
913 return CMD_SUCCESS;
914}
915
692b4c65
QY
916DEFUN (debug_ospf_ism,
917 debug_ospf_ism_cmd,
918 "debug ospf [(1-65535)] ism [<status|events|timers>]",
718e3744 919 DEBUG_STR
920 OSPF_STR
7c8ff89e 921 "Instance ID\n"
692b4c65
QY
922 "OSPF Interface State Machine\n"
923 "ISM Status Information\n"
924 "ISM Event Information\n"
925 "ISM TImer Information\n")
7c8ff89e 926{
692b4c65
QY
927 int inst = (argv[2]->type == RANGE_TKN);
928 char *dbgparam = (argc == 4 + inst) ? argv[argc - 1]->text : NULL;
7c8ff89e 929
692b4c65
QY
930 if (inst) // user passed instance ID
931 {
932 if (!ospf_lookup_instance (strtoul (argv[2]->arg, NULL, 10)))
933 return CMD_SUCCESS;
934 }
7c8ff89e 935
718e3744 936 if (vty->node == CONFIG_NODE)
937 {
692b4c65 938 if (!dbgparam)
718e3744 939 DEBUG_ON (ism, ISM);
692b4c65 940 else
718e3744 941 {
692b4c65 942 if (strmatch (dbgparam, "status"))
718e3744 943 DEBUG_ON (ism, ISM_STATUS);
692b4c65 944 else if (strmatch (dbgparam, "events"))
718e3744 945 DEBUG_ON (ism, ISM_EVENTS);
692b4c65 946 else if (strmatch (dbgparam, "timers"))
718e3744 947 DEBUG_ON (ism, ISM_TIMERS);
948 }
949
950 return CMD_SUCCESS;
951 }
952
953 /* ENABLE_NODE. */
692b4c65 954 if (!dbgparam)
718e3744 955 TERM_DEBUG_ON (ism, ISM);
692b4c65 956 else
718e3744 957 {
692b4c65
QY
958 if (strmatch (dbgparam, "status"))
959 TERM_DEBUG_ON (ism, ISM_STATUS);
960 else if (strmatch (dbgparam, "events"))
961 TERM_DEBUG_ON (ism, ISM_EVENTS);
962 else if (strmatch (dbgparam, "timers"))
963 TERM_DEBUG_ON (ism, ISM_TIMERS);
718e3744 964 }
ff788d08
DW
965
966 return CMD_SUCCESS;
718e3744 967}
968
692b4c65
QY
969DEFUN (no_debug_ospf_ism,
970 no_debug_ospf_ism_cmd,
971 "no debug ospf [(1-65535)] ism [<status|events|timers>]",
16cedbb0 972 NO_STR
718e3744 973 DEBUG_STR
974 OSPF_STR
7c8ff89e 975 "Instance ID\n"
692b4c65
QY
976 "OSPF Interface State Machine\n"
977 "ISM Status Information\n"
978 "ISM Event Information\n"
979 "ISM TImer Information\n")
7c8ff89e 980{
692b4c65
QY
981 int inst = (argv[3]->type == RANGE_TKN);
982 char *dbgparam = (argc == 5 + inst) ? argv[argc - 1]->text : NULL;
7c8ff89e 983
692b4c65
QY
984 if (inst) // user passed instance ID
985 {
22b27e95 986 if (!ospf_lookup_instance (strtoul (argv[3]->arg, NULL, 10)))
692b4c65
QY
987 return CMD_SUCCESS;
988 }
7c8ff89e 989
718e3744 990 if (vty->node == CONFIG_NODE)
991 {
692b4c65 992 if (!dbgparam)
718e3744 993 DEBUG_OFF (ism, ISM);
692b4c65 994 else
718e3744 995 {
692b4c65 996 if (strmatch (dbgparam, "status"))
718e3744 997 DEBUG_OFF (ism, ISM_STATUS);
692b4c65 998 else if (strmatch (dbgparam, "events"))
718e3744 999 DEBUG_OFF (ism, ISM_EVENTS);
692b4c65 1000 else if (strmatch (dbgparam, "timers"))
718e3744 1001 DEBUG_OFF (ism, ISM_TIMERS);
1002 }
692b4c65 1003
718e3744 1004 return CMD_SUCCESS;
1005 }
1006
1007 /* ENABLE_NODE. */
692b4c65 1008 if (!dbgparam)
718e3744 1009 TERM_DEBUG_OFF (ism, ISM);
692b4c65 1010 else
718e3744 1011 {
692b4c65
QY
1012 if (strmatch (dbgparam, "status"))
1013 TERM_DEBUG_OFF (ism, ISM_STATUS);
1014 else if (strmatch (dbgparam, "events"))
1015 TERM_DEBUG_OFF (ism, ISM_EVENTS);
1016 else if (strmatch (dbgparam, "timers"))
1017 TERM_DEBUG_OFF (ism, ISM_TIMERS);
718e3744 1018 }
ff788d08
DW
1019
1020 return CMD_SUCCESS;
718e3744 1021}
1022
7c8ff89e 1023static int
bf2bfafd 1024debug_ospf_nsm_common (struct vty *vty, int arg_base, int argc, struct cmd_token **argv)
718e3744 1025{
1026 if (vty->node == CONFIG_NODE)
1027 {
7c8ff89e 1028 if (argc == arg_base + 0)
718e3744 1029 DEBUG_ON (nsm, NSM);
7c8ff89e 1030 else if (argc == arg_base + 1)
718e3744 1031 {
1d68dbfe 1032 if (strmatch(argv[arg_base]->text, "status"))
718e3744 1033 DEBUG_ON (nsm, NSM_STATUS);
1d68dbfe 1034 else if (strmatch(argv[arg_base]->text, "events"))
718e3744 1035 DEBUG_ON (nsm, NSM_EVENTS);
1d68dbfe 1036 else if (strmatch(argv[arg_base]->text, "timers"))
718e3744 1037 DEBUG_ON (nsm, NSM_TIMERS);
1038 }
1039
1040 return CMD_SUCCESS;
1041 }
1042
1043 /* ENABLE_NODE. */
7c8ff89e 1044 if (argc == arg_base + 0)
718e3744 1045 TERM_DEBUG_ON (nsm, NSM);
7c8ff89e 1046 else if (argc == arg_base + 1)
718e3744 1047 {
1d68dbfe 1048 if (strmatch(argv[arg_base]->text, "status"))
718e3744 1049 TERM_DEBUG_ON (nsm, NSM_STATUS);
1d68dbfe 1050 else if (strmatch(argv[arg_base]->text, "events"))
718e3744 1051 TERM_DEBUG_ON (nsm, NSM_EVENTS);
1d68dbfe 1052 else if (strmatch(argv[arg_base]->text, "timers"))
718e3744 1053 TERM_DEBUG_ON (nsm, NSM_TIMERS);
1054 }
1055
1056 return CMD_SUCCESS;
1057}
1058
7c8ff89e
DS
1059DEFUN (debug_ospf_nsm,
1060 debug_ospf_nsm_cmd,
6de69f83 1061 "debug ospf nsm [<status|events|timers>]",
7c8ff89e
DS
1062 DEBUG_STR
1063 OSPF_STR
1d68dbfe
DW
1064 "OSPF Neighbor State Machine\n"
1065 "NSM Status Information\n"
1066 "NSM Event Information\n"
1067 "NSM Timer Information\n")
7c8ff89e 1068{
1d68dbfe 1069 return debug_ospf_nsm_common (vty, 3, argc, argv);
7c8ff89e
DS
1070}
1071
7c8ff89e
DS
1072DEFUN (debug_ospf_instance_nsm,
1073 debug_ospf_instance_nsm_cmd,
6de69f83 1074 "debug ospf (1-65535) nsm [<status|events|timers>]",
718e3744 1075 DEBUG_STR
1076 OSPF_STR
7c8ff89e 1077 "Instance ID\n"
1d68dbfe
DW
1078 "OSPF Neighbor State Machine\n"
1079 "NSM Status Information\n"
1080 "NSM Event Information\n"
1081 "NSM Timer Information\n")
7c8ff89e 1082{
8d769265 1083 int idx_number = 2;
7c8ff89e
DS
1084 u_short instance = 0;
1085
8d769265 1086 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1087 if (!ospf_lookup_instance (instance))
1088 return CMD_SUCCESS;
1089
1d68dbfe 1090 return debug_ospf_nsm_common (vty, 4, argc, argv);
7c8ff89e
DS
1091}
1092
7c8ff89e
DS
1093
1094static int
bf2bfafd 1095no_debug_ospf_nsm_common (struct vty *vty, int arg_base, int argc, struct cmd_token **argv)
718e3744 1096{
16cedbb0 1097 /* XXX qlyoung */
718e3744 1098 if (vty->node == CONFIG_NODE)
1099 {
7c8ff89e 1100 if (argc == arg_base + 0)
718e3744 1101 DEBUG_OFF (nsm, NSM);
7c8ff89e 1102 else if (argc == arg_base + 1)
718e3744 1103 {
1d68dbfe 1104 if (strmatch(argv[arg_base]->text, "status"))
718e3744 1105 DEBUG_OFF (nsm, NSM_STATUS);
1d68dbfe 1106 else if (strmatch(argv[arg_base]->text, "events"))
718e3744 1107 DEBUG_OFF (nsm, NSM_EVENTS);
1d68dbfe 1108 else if (strmatch(argv[arg_base]->text, "timers"))
718e3744 1109 DEBUG_OFF (nsm, NSM_TIMERS);
1110 }
1111
1112 return CMD_SUCCESS;
1113 }
1114
1115 /* ENABLE_NODE. */
7c8ff89e 1116 if (argc == arg_base + 0)
718e3744 1117 TERM_DEBUG_OFF (nsm, NSM);
7c8ff89e 1118 else if (argc == arg_base + 1)
718e3744 1119 {
1d68dbfe 1120 if (strmatch(argv[arg_base]->text, "status"))
718e3744 1121 TERM_DEBUG_OFF (nsm, NSM_STATUS);
1d68dbfe 1122 else if (strmatch(argv[arg_base]->text, "events"))
718e3744 1123 TERM_DEBUG_OFF (nsm, NSM_EVENTS);
1d68dbfe 1124 else if (strmatch(argv[arg_base]->text, "timers"))
718e3744 1125 TERM_DEBUG_OFF (nsm, NSM_TIMERS);
1126 }
1127
1128 return CMD_SUCCESS;
1129}
1130
7c8ff89e
DS
1131DEFUN (no_debug_ospf_nsm,
1132 no_debug_ospf_nsm_cmd,
6de69f83 1133 "no debug ospf nsm [<status|events|timers>]",
7c8ff89e
DS
1134 NO_STR
1135 DEBUG_STR
1136 OSPF_STR
16cedbb0 1137 "OSPF Neighbor State Machine\n"
1d68dbfe
DW
1138 "NSM Status Information\n"
1139 "NSM Event Information\n"
1140 "NSM Timer Information\n")
7c8ff89e 1141{
1d68dbfe 1142 return no_debug_ospf_nsm_common(vty, 4, argc, argv);
7c8ff89e
DS
1143}
1144
718e3744 1145
7c8ff89e
DS
1146DEFUN (no_debug_ospf_instance_nsm,
1147 no_debug_ospf_instance_nsm_cmd,
6de69f83 1148 "no debug ospf (1-65535) nsm [<status|events|timers>]",
7c8ff89e 1149 NO_STR
718e3744 1150 DEBUG_STR
1151 OSPF_STR
7c8ff89e 1152 "Instance ID\n"
16cedbb0 1153 "OSPF Neighbor State Machine\n"
1d68dbfe
DW
1154 "NSM Status Information\n"
1155 "NSM Event Information\n"
1156 "NSM Timer Information\n")
7c8ff89e 1157{
8d769265 1158 int idx_number = 3;
7c8ff89e
DS
1159 u_short instance = 0;
1160
8d769265 1161 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1162 if (!ospf_lookup_instance (instance))
1163 return CMD_SUCCESS;
1164
1d68dbfe 1165 return no_debug_ospf_nsm_common(vty, 5, argc, argv);
7c8ff89e
DS
1166}
1167
7c8ff89e 1168
7c8ff89e 1169static int
bf2bfafd 1170debug_ospf_lsa_common (struct vty *vty, int arg_base, int argc, struct cmd_token **argv)
718e3744 1171{
1172 if (vty->node == CONFIG_NODE)
1173 {
7c8ff89e 1174 if (argc == arg_base + 0)
718e3744 1175 DEBUG_ON (lsa, LSA);
7c8ff89e 1176 else if (argc == arg_base + 1)
718e3744 1177 {
1d68dbfe 1178 if (strmatch(argv[arg_base]->text, "generate"))
718e3744 1179 DEBUG_ON (lsa, LSA_GENERATE);
1d68dbfe 1180 else if (strmatch(argv[arg_base]->text, "flooding"))
718e3744 1181 DEBUG_ON (lsa, LSA_FLOODING);
1d68dbfe 1182 else if (strmatch(argv[arg_base]->text, "install"))
718e3744 1183 DEBUG_ON (lsa, LSA_INSTALL);
1d68dbfe 1184 else if (strmatch(argv[arg_base]->text, "refresh"))
718e3744 1185 DEBUG_ON (lsa, LSA_REFRESH);
1186 }
1187
1188 return CMD_SUCCESS;
1189 }
1190
1191 /* ENABLE_NODE. */
7c8ff89e 1192 if (argc == arg_base + 0)
718e3744 1193 TERM_DEBUG_ON (lsa, LSA);
7c8ff89e 1194 else if (argc == arg_base + 1)
718e3744 1195 {
1d68dbfe 1196 if (strmatch(argv[arg_base]->text, "generate"))
718e3744 1197 TERM_DEBUG_ON (lsa, LSA_GENERATE);
1d68dbfe 1198 else if (strmatch(argv[arg_base]->text, "flooding"))
718e3744 1199 TERM_DEBUG_ON (lsa, LSA_FLOODING);
1d68dbfe 1200 else if (strmatch(argv[arg_base]->text, "install"))
718e3744 1201 TERM_DEBUG_ON (lsa, LSA_INSTALL);
1d68dbfe 1202 else if (strmatch(argv[arg_base]->text, "refresh"))
718e3744 1203 TERM_DEBUG_ON (lsa, LSA_REFRESH);
1204 }
1205
1206 return CMD_SUCCESS;
1207}
1208
7c8ff89e
DS
1209DEFUN (debug_ospf_lsa,
1210 debug_ospf_lsa_cmd,
6de69f83 1211 "debug ospf lsa [<generate|flooding|install|refresh>]",
7c8ff89e
DS
1212 DEBUG_STR
1213 OSPF_STR
1d68dbfe
DW
1214 "OSPF Link State Advertisement\n"
1215 "LSA Generation\n"
1216 "LSA Flooding\n"
1217 "LSA Install/Delete\n"
1218 "LSA Refresh\n")
7c8ff89e 1219{
1d68dbfe 1220 return debug_ospf_lsa_common(vty, 3, argc, argv);
7c8ff89e
DS
1221}
1222
7c8ff89e
DS
1223DEFUN (debug_ospf_instance_lsa,
1224 debug_ospf_instance_lsa_cmd,
6de69f83 1225 "debug ospf (1-65535) lsa [<generate|flooding|install|refresh>]",
718e3744 1226 DEBUG_STR
1227 OSPF_STR
7c8ff89e 1228 "Instance ID\n"
1d68dbfe
DW
1229 "OSPF Link State Advertisement\n"
1230 "LSA Generation\n"
1231 "LSA Flooding\n"
1232 "LSA Install/Delete\n"
1233 "LSA Refresh\n")
7c8ff89e 1234{
8d769265 1235 int idx_number = 2;
7c8ff89e
DS
1236 u_short instance = 0;
1237
8d769265 1238 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1239 if (!ospf_lookup_instance (instance))
1240 return CMD_SUCCESS;
1241
1d68dbfe 1242 return debug_ospf_lsa_common(vty, 4, argc, argv);
7c8ff89e
DS
1243}
1244
7c8ff89e
DS
1245
1246static int
bf2bfafd 1247no_debug_ospf_lsa_common (struct vty *vty, int arg_base, int argc, struct cmd_token **argv)
718e3744 1248{
1249 if (vty->node == CONFIG_NODE)
1250 {
7c8ff89e 1251 if (argc == arg_base + 0)
718e3744 1252 DEBUG_OFF (lsa, LSA);
7c8ff89e 1253 else if (argc == arg_base + 1)
718e3744 1254 {
1d68dbfe 1255 if (strmatch(argv[arg_base]->text, "generate"))
718e3744 1256 DEBUG_OFF (lsa, LSA_GENERATE);
1d68dbfe 1257 else if (strmatch(argv[arg_base]->text, "flooding"))
718e3744 1258 DEBUG_OFF (lsa, LSA_FLOODING);
1d68dbfe 1259 else if (strmatch(argv[arg_base]->text, "install"))
718e3744 1260 DEBUG_OFF (lsa, LSA_INSTALL);
1d68dbfe 1261 else if (strmatch(argv[arg_base]->text, "refresh"))
718e3744 1262 DEBUG_OFF (lsa, LSA_REFRESH);
1263 }
1264
1265 return CMD_SUCCESS;
1266 }
1267
1268 /* ENABLE_NODE. */
7c8ff89e 1269 if (argc == arg_base + 0)
718e3744 1270 TERM_DEBUG_OFF (lsa, LSA);
7c8ff89e 1271 else if (argc == arg_base + 1)
718e3744 1272 {
1d68dbfe 1273 if (strmatch(argv[arg_base]->text, "generate"))
718e3744 1274 TERM_DEBUG_OFF (lsa, LSA_GENERATE);
1d68dbfe 1275 else if (strmatch(argv[arg_base]->text, "flooding"))
718e3744 1276 TERM_DEBUG_OFF (lsa, LSA_FLOODING);
1d68dbfe 1277 else if (strmatch(argv[arg_base]->text, "install"))
718e3744 1278 TERM_DEBUG_OFF (lsa, LSA_INSTALL);
1d68dbfe 1279 else if (strmatch(argv[arg_base]->text, "refresh"))
718e3744 1280 TERM_DEBUG_OFF (lsa, LSA_REFRESH);
1281 }
1282
1283 return CMD_SUCCESS;
1284}
1285
7c8ff89e
DS
1286DEFUN (no_debug_ospf_lsa,
1287 no_debug_ospf_lsa_cmd,
6de69f83 1288 "no debug ospf lsa [<generate|flooding|install|refresh>]",
7c8ff89e
DS
1289 NO_STR
1290 DEBUG_STR
1291 OSPF_STR
1d68dbfe
DW
1292 "OSPF Link State Advertisement\n"
1293 "LSA Generation\n"
1294 "LSA Flooding\n"
1295 "LSA Install/Delete\n"
1296 "LSA Refres\n")
7c8ff89e 1297{
1d68dbfe 1298 return no_debug_ospf_lsa_common (vty, 4, argc, argv);
7c8ff89e
DS
1299}
1300
7c8ff89e
DS
1301DEFUN (no_debug_ospf_instance_lsa,
1302 no_debug_ospf_instance_lsa_cmd,
6de69f83 1303 "no debug ospf (1-65535) lsa [<generate|flooding|install|refresh>]",
7c8ff89e
DS
1304 NO_STR
1305 DEBUG_STR
1306 OSPF_STR
1307 "Instance ID\n"
1d68dbfe
DW
1308 "OSPF Link State Advertisement\n"
1309 "LSA Generation\n"
1310 "LSA Flooding\n"
1311 "LSA Install/Delete\n"
1312 "LSA Refres\n")
7c8ff89e 1313{
8d769265 1314 int idx_number = 3;
7c8ff89e
DS
1315 u_short instance = 0;
1316
8d769265 1317 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1318 if (!ospf_lookup_instance (instance))
1319 return CMD_SUCCESS;
6b0655a2 1320
1d68dbfe 1321 return no_debug_ospf_lsa_common (vty, 5, argc, argv);
7c8ff89e
DS
1322}
1323
7c8ff89e 1324
7c8ff89e 1325static int
bf2bfafd 1326debug_ospf_zebra_common (struct vty *vty, int arg_base, int argc, struct cmd_token **argv)
718e3744 1327{
1328 if (vty->node == CONFIG_NODE)
1329 {
7c8ff89e 1330 if (argc == arg_base + 0)
718e3744 1331 DEBUG_ON (zebra, ZEBRA);
7c8ff89e 1332 else if (argc == arg_base + 1)
718e3744 1333 {
1d68dbfe 1334 if (strmatch(argv[arg_base]->text, "interface"))
718e3744 1335 DEBUG_ON (zebra, ZEBRA_INTERFACE);
1d68dbfe 1336 else if (strmatch(argv[arg_base]->text, "redistribute"))
718e3744 1337 DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
1338 }
1339
1340 return CMD_SUCCESS;
1341 }
1342
1343 /* ENABLE_NODE. */
7c8ff89e 1344 if (argc == arg_base + 0)
718e3744 1345 TERM_DEBUG_ON (zebra, ZEBRA);
7c8ff89e 1346 else if (argc == arg_base + 1)
718e3744 1347 {
1d68dbfe 1348 if (strmatch(argv[arg_base]->text, "interface"))
718e3744 1349 TERM_DEBUG_ON (zebra, ZEBRA_INTERFACE);
1d68dbfe 1350 else if (strmatch(argv[arg_base]->text, "redistribute"))
718e3744 1351 TERM_DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
1352 }
1353
1354 return CMD_SUCCESS;
1355}
1356
7c8ff89e
DS
1357DEFUN (debug_ospf_zebra,
1358 debug_ospf_zebra_cmd,
6de69f83 1359 "debug ospf zebra [<interface|redistribute>]",
7c8ff89e
DS
1360 DEBUG_STR
1361 OSPF_STR
1d68dbfe
DW
1362 "OSPF Zebra information\n"
1363 "Zebra interface\n"
1364 "Zebra redistribute\n")
7c8ff89e 1365{
1d68dbfe 1366 return debug_ospf_zebra_common(vty, 3, argc, argv);
7c8ff89e
DS
1367}
1368
7c8ff89e
DS
1369DEFUN (debug_ospf_instance_zebra,
1370 debug_ospf_instance_zebra_cmd,
6de69f83 1371 "debug ospf (1-65535) zebra [<interface|redistribute>]",
718e3744 1372 DEBUG_STR
1373 OSPF_STR
7c8ff89e 1374 "Instance ID\n"
1d68dbfe
DW
1375 "OSPF Zebra information\n"
1376 "Zebra interface\n"
1377 "Zebra redistribute\n")
7c8ff89e 1378{
8d769265 1379 int idx_number = 2;
7c8ff89e
DS
1380 u_short instance = 0;
1381
8d769265 1382 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1383 if (!ospf_lookup_instance (instance))
1384 return CMD_SUCCESS;
1385
1d68dbfe 1386 return debug_ospf_zebra_common(vty, 4, argc, argv);
7c8ff89e
DS
1387}
1388
7c8ff89e
DS
1389
1390static int
1391no_debug_ospf_zebra_common(struct vty *vty, int arg_base, int argc,
bf2bfafd 1392 struct cmd_token **argv)
718e3744 1393{
1394 if (vty->node == CONFIG_NODE)
1395 {
7c8ff89e 1396 if (argc == arg_base + 0)
718e3744 1397 DEBUG_OFF (zebra, ZEBRA);
7c8ff89e 1398 else if (argc == arg_base + 1)
718e3744 1399 {
1d68dbfe 1400 if (strmatch(argv[arg_base]->text, "interface"))
718e3744 1401 DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1d68dbfe 1402 else if (strmatch(argv[arg_base]->text, "redistribute"))
718e3744 1403 DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1404 }
1405
1406 return CMD_SUCCESS;
1407 }
1408
1409 /* ENABLE_NODE. */
7c8ff89e 1410 if (argc == arg_base + 0)
718e3744 1411 TERM_DEBUG_OFF (zebra, ZEBRA);
7c8ff89e 1412 else if (argc == arg_base + 1)
718e3744 1413 {
1d68dbfe 1414 if (strmatch(argv[arg_base]->text, "interface"))
718e3744 1415 TERM_DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1d68dbfe 1416 else if (strmatch(argv[arg_base]->text, "redistribute"))
718e3744 1417 TERM_DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1418 }
1419
1420 return CMD_SUCCESS;
1421}
1422
7c8ff89e
DS
1423DEFUN (no_debug_ospf_zebra,
1424 no_debug_ospf_zebra_cmd,
6de69f83 1425 "no debug ospf zebra [<interface|redistribute>]",
7c8ff89e
DS
1426 NO_STR
1427 DEBUG_STR
1428 OSPF_STR
1d68dbfe
DW
1429 "OSPF Zebra information\n"
1430 "Zebra interface\n"
1431 "Zebra redistribute\n")
7c8ff89e 1432{
1d68dbfe 1433 return no_debug_ospf_zebra_common(vty, 4, argc, argv);
7c8ff89e
DS
1434}
1435
7c8ff89e
DS
1436DEFUN (no_debug_ospf_instance_zebra,
1437 no_debug_ospf_instance_zebra_cmd,
6de69f83 1438 "no debug ospf (1-65535) zebra [<interface|redistribute>]",
7c8ff89e
DS
1439 NO_STR
1440 DEBUG_STR
1441 OSPF_STR
1442 "Instance ID\n"
1d68dbfe
DW
1443 "OSPF Zebra information\n"
1444 "Zebra interface\n"
1445 "Zebra redistribute\n")
7c8ff89e 1446{
8d769265 1447 int idx_number = 3;
7c8ff89e
DS
1448 u_short instance = 0;
1449
8d769265 1450 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1451 if (!ospf_lookup_instance (instance))
1452 return CMD_SUCCESS;
1453
1d68dbfe 1454 return no_debug_ospf_zebra_common(vty, 5, argc, argv);
7c8ff89e
DS
1455}
1456
7c8ff89e
DS
1457
1458
718e3744 1459DEFUN (debug_ospf_event,
1460 debug_ospf_event_cmd,
1461 "debug ospf event",
1462 DEBUG_STR
1463 OSPF_STR
1464 "OSPF event information\n")
1465{
1466 if (vty->node == CONFIG_NODE)
1467 CONF_DEBUG_ON (event, EVENT);
1468 TERM_DEBUG_ON (event, EVENT);
1469 return CMD_SUCCESS;
1470}
1471
1472DEFUN (no_debug_ospf_event,
1473 no_debug_ospf_event_cmd,
1474 "no debug ospf event",
1475 NO_STR
1476 DEBUG_STR
1477 OSPF_STR
1478 "OSPF event information\n")
1479{
1480 if (vty->node == CONFIG_NODE)
1481 CONF_DEBUG_OFF (event, EVENT);
1482 TERM_DEBUG_OFF (event, EVENT);
1483 return CMD_SUCCESS;
1484}
1485
7c8ff89e
DS
1486DEFUN (debug_ospf_instance_event,
1487 debug_ospf_instance_event_cmd,
6147e2c6 1488 "debug ospf (1-65535) event",
7c8ff89e
DS
1489 DEBUG_STR
1490 OSPF_STR
1491 "Instance ID\n"
1492 "OSPF event information\n")
1493{
8d769265 1494 int idx_number = 2;
7c8ff89e
DS
1495 u_short instance = 0;
1496
8d769265 1497 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1498 if (!ospf_lookup_instance (instance))
1499 return CMD_SUCCESS;
1500
1501 if (vty->node == CONFIG_NODE)
1502 CONF_DEBUG_ON (event, EVENT);
1503 TERM_DEBUG_ON (event, EVENT);
1504 return CMD_SUCCESS;
1505}
1506
1507DEFUN (no_debug_ospf_instance_event,
1508 no_debug_ospf_instance_event_cmd,
6147e2c6 1509 "no debug ospf (1-65535) event",
7c8ff89e
DS
1510 NO_STR
1511 DEBUG_STR
1512 OSPF_STR
1513 "Instance ID\n"
1514 "OSPF event information\n")
1515{
8d769265 1516 int idx_number = 3;
7c8ff89e
DS
1517 u_short instance = 0;
1518
8d769265 1519 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1520 if (!ospf_lookup_instance (instance))
1521 return CMD_SUCCESS;
1522
1523 if (vty->node == CONFIG_NODE)
1524 CONF_DEBUG_OFF (event, EVENT);
1525 TERM_DEBUG_OFF (event, EVENT);
1526 return CMD_SUCCESS;
1527}
1528
718e3744 1529DEFUN (debug_ospf_nssa,
1530 debug_ospf_nssa_cmd,
1531 "debug ospf nssa",
1532 DEBUG_STR
1533 OSPF_STR
1534 "OSPF nssa information\n")
1535{
1536 if (vty->node == CONFIG_NODE)
1537 CONF_DEBUG_ON (nssa, NSSA);
1538 TERM_DEBUG_ON (nssa, NSSA);
1539 return CMD_SUCCESS;
1540}
1541
1542DEFUN (no_debug_ospf_nssa,
1543 no_debug_ospf_nssa_cmd,
1544 "no debug ospf nssa",
1545 NO_STR
1546 DEBUG_STR
1547 OSPF_STR
1548 "OSPF nssa information\n")
1549{
1550 if (vty->node == CONFIG_NODE)
1551 CONF_DEBUG_OFF (nssa, NSSA);
1552 TERM_DEBUG_OFF (nssa, NSSA);
1553 return CMD_SUCCESS;
1554}
1555
7c8ff89e
DS
1556DEFUN (debug_ospf_instance_nssa,
1557 debug_ospf_instance_nssa_cmd,
6147e2c6 1558 "debug ospf (1-65535) nssa",
7c8ff89e
DS
1559 DEBUG_STR
1560 OSPF_STR
1561 "Instance ID\n"
1562 "OSPF nssa information\n")
1563{
8d769265 1564 int idx_number = 2;
7c8ff89e
DS
1565 u_short instance = 0;
1566
8d769265 1567 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1568 if (!ospf_lookup_instance (instance))
1569 return CMD_SUCCESS;
6b0655a2 1570
7c8ff89e
DS
1571 if (vty->node == CONFIG_NODE)
1572 CONF_DEBUG_ON (nssa, NSSA);
1573 TERM_DEBUG_ON (nssa, NSSA);
1574 return CMD_SUCCESS;
1575}
1576
1577DEFUN (no_debug_ospf_instance_nssa,
1578 no_debug_ospf_instance_nssa_cmd,
6147e2c6 1579 "no debug ospf (1-65535) nssa",
7c8ff89e 1580 NO_STR
718e3744 1581 DEBUG_STR
7c8ff89e
DS
1582 OSPF_STR
1583 "Instance ID\n"
1584 "OSPF nssa information\n")
1585{
8d769265 1586 int idx_number = 3;
7c8ff89e
DS
1587 u_short instance = 0;
1588
8d769265 1589 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1590 if (!ospf_lookup_instance (instance))
1591 return CMD_SUCCESS;
1592
1593 if (vty->node == CONFIG_NODE)
1594 CONF_DEBUG_OFF (nssa, NSSA);
1595 TERM_DEBUG_OFF (nssa, NSSA);
1596 return CMD_SUCCESS;
1597}
1598
16f1b9ee
OD
1599DEFUN (debug_ospf_te,
1600 debug_ospf_te_cmd,
1601 "debug ospf te",
1602 DEBUG_STR
1603 OSPF_STR
1604 "OSPF-TE information\n")
1605{
1606 if (vty->node == CONFIG_NODE)
1607 CONF_DEBUG_ON (te, TE);
1608 TERM_DEBUG_ON (te, TE);
1609 return CMD_SUCCESS;
1610}
1611
1612DEFUN (no_debug_ospf_te,
1613 no_debug_ospf_te_cmd,
1614 "no debug ospf te",
1615 NO_STR
1616 DEBUG_STR
1617 OSPF_STR
1618 "OSPF-TE information\n")
1619{
1620 if (vty->node == CONFIG_NODE)
1621 CONF_DEBUG_OFF (te, TE);
1622 TERM_DEBUG_OFF (te, TE);
1623 return CMD_SUCCESS;
1624}
1625
4dfd8aff
DW
1626DEFUN (no_debug_ospf,
1627 no_debug_ospf_cmd,
1628 "no debug ospf",
1629 NO_STR
1630 DEBUG_STR
1631 OSPF_STR)
1632{
1633 int flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
1634 int i;
1635
1636 if (vty->node == CONFIG_NODE)
1637 {
1638 CONF_DEBUG_OFF (event, EVENT);
1639 CONF_DEBUG_OFF (nssa, NSSA);
1640 DEBUG_OFF (ism, ISM_EVENTS);
1641 DEBUG_OFF (ism, ISM_STATUS);
1642 DEBUG_OFF (ism, ISM_TIMERS);
1643 DEBUG_OFF (lsa, LSA);
1644 DEBUG_OFF (lsa, LSA_FLOODING);
1645 DEBUG_OFF (lsa, LSA_GENERATE);
1646 DEBUG_OFF (lsa, LSA_INSTALL);
1647 DEBUG_OFF (lsa, LSA_REFRESH);
1648 DEBUG_OFF (nsm, NSM);
1649 DEBUG_OFF (nsm, NSM_EVENTS);
1650 DEBUG_OFF (nsm, NSM_STATUS);
1651 DEBUG_OFF (nsm, NSM_TIMERS);
1652 DEBUG_OFF (zebra, ZEBRA);
1653 DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1654 DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1655
1656 for (i = 0; i < 5; i++)
1657 DEBUG_PACKET_OFF (i, flag);
1658 }
1659
1660 for (i = 0; i < 5; i++)
1661 TERM_DEBUG_PACKET_OFF (i, flag);
1662
1663 TERM_DEBUG_OFF (event, EVENT);
1664 TERM_DEBUG_OFF (ism, ISM);
1665 TERM_DEBUG_OFF (ism, ISM_EVENTS);
1666 TERM_DEBUG_OFF (ism, ISM_STATUS);
1667 TERM_DEBUG_OFF (ism, ISM_TIMERS);
1668 TERM_DEBUG_OFF (lsa, LSA);
1669 TERM_DEBUG_OFF (lsa, LSA_FLOODING);
1670 TERM_DEBUG_OFF (lsa, LSA_GENERATE);
1671 TERM_DEBUG_OFF (lsa, LSA_INSTALL);
1672 TERM_DEBUG_OFF (lsa, LSA_REFRESH);
1673 TERM_DEBUG_OFF (nsm, NSM);
1674 TERM_DEBUG_OFF (nsm, NSM_EVENTS);
1675 TERM_DEBUG_OFF (nsm, NSM_STATUS);
1676 TERM_DEBUG_OFF (nsm, NSM_TIMERS);
1677 TERM_DEBUG_OFF (nssa, NSSA);
1678 TERM_DEBUG_OFF (zebra, ZEBRA);
1679 TERM_DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1680 TERM_DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1681
1682 return CMD_SUCCESS;
1683}
7c8ff89e
DS
1684
1685static int
1686show_debugging_ospf_common (struct vty *vty, struct ospf *ospf)
718e3744 1687{
1688 int i;
1689
7c8ff89e
DS
1690 if (ospf->instance)
1691 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
1692 VTY_NEWLINE, VTY_NEWLINE);
1693
df43a137 1694 vty_out (vty, "OSPF debugging status:%s", VTY_NEWLINE);
718e3744 1695
aca72fda 1696 /* Show debug status for events. */
1697 if (IS_DEBUG_OSPF(event,EVENT))
1698 vty_out (vty, " OSPF event debugging is on%s", VTY_NEWLINE);
1699
718e3744 1700 /* Show debug status for ISM. */
1701 if (IS_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
1702 vty_out (vty, " OSPF ISM debugging is on%s", VTY_NEWLINE);
1703 else
1704 {
1705 if (IS_DEBUG_OSPF (ism, ISM_STATUS))
1706 vty_out (vty, " OSPF ISM status debugging is on%s", VTY_NEWLINE);
1707 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
1708 vty_out (vty, " OSPF ISM event debugging is on%s", VTY_NEWLINE);
1709 if (IS_DEBUG_OSPF (ism, ISM_TIMERS))
1710 vty_out (vty, " OSPF ISM timer debugging is on%s", VTY_NEWLINE);
1711 }
1712
1713 /* Show debug status for NSM. */
1714 if (IS_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
1715 vty_out (vty, " OSPF NSM debugging is on%s", VTY_NEWLINE);
1716 else
1717 {
1718 if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
1719 vty_out (vty, " OSPF NSM status debugging is on%s", VTY_NEWLINE);
1720 if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
1721 vty_out (vty, " OSPF NSM event debugging is on%s", VTY_NEWLINE);
1722 if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
1723 vty_out (vty, " OSPF NSM timer debugging is on%s", VTY_NEWLINE);
1724 }
1725
1726 /* Show debug status for OSPF Packets. */
1727 for (i = 0; i < 5; i++)
1728 if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV))
1729 {
1730 vty_out (vty, " OSPF packet %s%s debugging is on%s",
272ca1e3 1731 LOOKUP (ospf_packet_type_str, i + 1),
718e3744 1732 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1733 VTY_NEWLINE);
1734 }
1735 else
1736 {
1737 if (IS_DEBUG_OSPF_PACKET (i, SEND))
1738 vty_out (vty, " OSPF packet %s send%s debugging is on%s",
272ca1e3 1739 LOOKUP (ospf_packet_type_str, i + 1),
718e3744 1740 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1741 VTY_NEWLINE);
1742 if (IS_DEBUG_OSPF_PACKET (i, RECV))
1743 vty_out (vty, " OSPF packet %s receive%s debugging is on%s",
272ca1e3 1744 LOOKUP (ospf_packet_type_str, i + 1),
718e3744 1745 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1746 VTY_NEWLINE);
1747 }
1748
1749 /* Show debug status for OSPF LSAs. */
1750 if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
1751 vty_out (vty, " OSPF LSA debugging is on%s", VTY_NEWLINE);
1752 else
1753 {
1754 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1755 vty_out (vty, " OSPF LSA generation debugging is on%s", VTY_NEWLINE);
1756 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
1757 vty_out (vty, " OSPF LSA flooding debugging is on%s", VTY_NEWLINE);
1758 if (IS_DEBUG_OSPF (lsa, LSA_INSTALL))
1759 vty_out (vty, " OSPF LSA install debugging is on%s", VTY_NEWLINE);
1760 if (IS_DEBUG_OSPF (lsa, LSA_REFRESH))
1761 vty_out (vty, " OSPF LSA refresh debugging is on%s", VTY_NEWLINE);
1762 }
1763
1764 /* Show debug status for Zebra. */
1765 if (IS_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1766 vty_out (vty, " OSPF Zebra debugging is on%s", VTY_NEWLINE);
1767 else
1768 {
1769 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
1770 vty_out (vty, " OSPF Zebra interface debugging is on%s", VTY_NEWLINE);
1771 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
1772 vty_out (vty, " OSPF Zebra redistribute debugging is on%s", VTY_NEWLINE);
1773 }
aca72fda 1774
1775 /* Show debug status for NSSA. */
ead687e1 1776 if (IS_DEBUG_OSPF (nssa, NSSA) == OSPF_DEBUG_NSSA)
1777 vty_out (vty, " OSPF NSSA debugging is on%s", VTY_NEWLINE);
718e3744 1778
7c8ff89e
DS
1779 vty_out (vty, "%s", VTY_NEWLINE);
1780
718e3744 1781 return CMD_SUCCESS;
1782}
1783
7c8ff89e
DS
1784DEFUN (show_debugging_ospf,
1785 show_debugging_ospf_cmd,
1786 "show debugging ospf",
1787 SHOW_STR
1788 DEBUG_STR
1789 OSPF_STR)
1790{
1791 struct ospf *ospf;
1792
1793 if ((ospf = ospf_lookup()) == NULL)
1794 return CMD_SUCCESS;
1795
1796 return show_debugging_ospf_common(vty, ospf);
1797}
1798
1799DEFUN (show_debugging_ospf_instance,
1800 show_debugging_ospf_instance_cmd,
6147e2c6 1801 "show debugging ospf (1-65535)",
7c8ff89e
DS
1802 SHOW_STR
1803 DEBUG_STR
1804 OSPF_STR
1805 "Instance ID\n")
1806{
8d769265 1807 int idx_number = 3;
7c8ff89e
DS
1808 struct ospf *ospf;
1809 u_short instance = 0;
1810
8d769265 1811 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
7c8ff89e
DS
1812 if ((ospf = ospf_lookup_instance (instance)) == NULL )
1813 return CMD_SUCCESS;
1814
1815 return show_debugging_ospf_common(vty, ospf);
1816}
1817
718e3744 1818/* Debug node. */
7fc626de 1819static struct cmd_node debug_node =
718e3744 1820{
1821 DEBUG_NODE,
1d806288 1822 "",
1823 1 /* VTYSH */
718e3744 1824};
1825
4dadc291 1826static int
718e3744 1827config_write_debug (struct vty *vty)
1828{
1829 int write = 0;
1830 int i, r;
1831
eb1ce605 1832 const char *type_str[] = {"hello", "dd", "ls-request", "ls-update", "ls-ack"};
1833 const char *detail_str[] = {"", " send", " recv", "", " detail",
718e3744 1834 " send detail", " recv detail", " detail"};
1835
7c8ff89e
DS
1836 struct ospf *ospf;
1837 char str[16];
7fe9687b 1838 memset (str, 0, 16);
7c8ff89e
DS
1839
1840 if ((ospf = ospf_lookup()) == NULL)
1841 return CMD_SUCCESS;
1842
1843 if (ospf->instance)
1844 sprintf(str, " %d", ospf->instance);
7c8ff89e 1845
718e3744 1846 /* debug ospf ism (status|events|timers). */
1847 if (IS_CONF_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
7c8ff89e 1848 vty_out (vty, "debug ospf%s ism%s", str, VTY_NEWLINE);
718e3744 1849 else
1850 {
1851 if (IS_CONF_DEBUG_OSPF (ism, ISM_STATUS))
7c8ff89e 1852 vty_out (vty, "debug ospf%s ism status%s", str, VTY_NEWLINE);
718e3744 1853 if (IS_CONF_DEBUG_OSPF (ism, ISM_EVENTS))
7c8ff89e 1854 vty_out (vty, "debug ospf%s ism event%s", str, VTY_NEWLINE);
718e3744 1855 if (IS_CONF_DEBUG_OSPF (ism, ISM_TIMERS))
7c8ff89e 1856 vty_out (vty, "debug ospf%s ism timer%s", str, VTY_NEWLINE);
718e3744 1857 }
1858
1859 /* debug ospf nsm (status|events|timers). */
1860 if (IS_CONF_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
7c8ff89e 1861 vty_out (vty, "debug ospf%s nsm%s", str, VTY_NEWLINE);
718e3744 1862 else
1863 {
1864 if (IS_CONF_DEBUG_OSPF (nsm, NSM_STATUS))
7c8ff89e 1865 vty_out (vty, "debug ospf%s nsm status%s", str, VTY_NEWLINE);
718e3744 1866 if (IS_CONF_DEBUG_OSPF (nsm, NSM_EVENTS))
7c8ff89e 1867 vty_out (vty, "debug ospf%s nsm event%s", str, VTY_NEWLINE);
718e3744 1868 if (IS_CONF_DEBUG_OSPF (nsm, NSM_TIMERS))
7c8ff89e 1869 vty_out (vty, "debug ospf%s nsm timer%s", str, VTY_NEWLINE);
718e3744 1870 }
1871
1872 /* debug ospf lsa (generate|flooding|install|refresh). */
1873 if (IS_CONF_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
7c8ff89e 1874 vty_out (vty, "debug ospf%s lsa%s", str, VTY_NEWLINE);
718e3744 1875 else
1876 {
1877 if (IS_CONF_DEBUG_OSPF (lsa, LSA_GENERATE))
7c8ff89e 1878 vty_out (vty, "debug ospf%s lsa generate%s", str, VTY_NEWLINE);
718e3744 1879 if (IS_CONF_DEBUG_OSPF (lsa, LSA_FLOODING))
7c8ff89e 1880 vty_out (vty, "debug ospf%s lsa flooding%s", str, VTY_NEWLINE);
718e3744 1881 if (IS_CONF_DEBUG_OSPF (lsa, LSA_INSTALL))
7c8ff89e 1882 vty_out (vty, "debug ospf%s lsa install%s", str, VTY_NEWLINE);
718e3744 1883 if (IS_CONF_DEBUG_OSPF (lsa, LSA_REFRESH))
7c8ff89e 1884 vty_out (vty, "debug ospf%s lsa refresh%s", str, VTY_NEWLINE);
718e3744 1885
1886 write = 1;
1887 }
1888
1889 /* debug ospf zebra (interface|redistribute). */
1890 if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
7c8ff89e 1891 vty_out (vty, "debug ospf%s zebra%s", str, VTY_NEWLINE);
718e3744 1892 else
1893 {
1894 if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
7c8ff89e 1895 vty_out (vty, "debug ospf%s zebra interface%s", str, VTY_NEWLINE);
718e3744 1896 if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
7c8ff89e 1897 vty_out (vty, "debug ospf%s zebra redistribute%s", str, VTY_NEWLINE);
718e3744 1898
1899 write = 1;
1900 }
1901
1902 /* debug ospf event. */
1903 if (IS_CONF_DEBUG_OSPF (event, EVENT) == OSPF_DEBUG_EVENT)
1904 {
7c8ff89e 1905 vty_out (vty, "debug ospf%s event%s", str, VTY_NEWLINE);
718e3744 1906 write = 1;
1907 }
1908
1909 /* debug ospf nssa. */
1910 if (IS_CONF_DEBUG_OSPF (nssa, NSSA) == OSPF_DEBUG_NSSA)
1911 {
7c8ff89e 1912 vty_out (vty, "debug ospf%s nssa%s", str, VTY_NEWLINE);
718e3744 1913 write = 1;
1914 }
1915
1916 /* debug ospf packet all detail. */
1917 r = OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL;
1918 for (i = 0; i < 5; i++)
1919 r &= conf_debug_ospf_packet[i] & (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL);
1920 if (r == (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL))
1921 {
7c8ff89e 1922 vty_out (vty, "debug ospf%s packet all detail%s", str, VTY_NEWLINE);
718e3744 1923 return 1;
1924 }
1925
1926 /* debug ospf packet all. */
1927 r = OSPF_DEBUG_SEND_RECV;
1928 for (i = 0; i < 5; i++)
1929 r &= conf_debug_ospf_packet[i] & OSPF_DEBUG_SEND_RECV;
1930 if (r == OSPF_DEBUG_SEND_RECV)
1931 {
7c8ff89e 1932 vty_out (vty, "debug ospf%s packet all%s", str, VTY_NEWLINE);
718e3744 1933 for (i = 0; i < 5; i++)
1934 if (conf_debug_ospf_packet[i] & OSPF_DEBUG_DETAIL)
7c8ff89e 1935 vty_out (vty, "debug ospf%s packet %s detail%s", str,
718e3744 1936 type_str[i],
1937 VTY_NEWLINE);
1938 return 1;
1939 }
1940
1941 /* debug ospf packet (hello|dd|ls-request|ls-update|ls-ack)
1942 (send|recv) (detail). */
1943 for (i = 0; i < 5; i++)
1944 {
1945 if (conf_debug_ospf_packet[i] == 0)
1946 continue;
1947
7c8ff89e 1948 vty_out (vty, "debug ospf%s packet %s%s%s", str,
718e3744 1949 type_str[i], detail_str[conf_debug_ospf_packet[i]],
1950 VTY_NEWLINE);
1951 write = 1;
1952 }
1953
1954 return write;
1955}
1956
1957/* Initialize debug commands. */
1958void
1959debug_init ()
1960{
1961 install_node (&debug_node, config_write_debug);
1962
1963 install_element (ENABLE_NODE, &show_debugging_ospf_cmd);
718e3744 1964 install_element (ENABLE_NODE, &debug_ospf_ism_cmd);
718e3744 1965 install_element (ENABLE_NODE, &debug_ospf_nsm_cmd);
718e3744 1966 install_element (ENABLE_NODE, &debug_ospf_lsa_cmd);
718e3744 1967 install_element (ENABLE_NODE, &debug_ospf_zebra_cmd);
1968 install_element (ENABLE_NODE, &debug_ospf_event_cmd);
718e3744 1969 install_element (ENABLE_NODE, &debug_ospf_nssa_cmd);
16f1b9ee 1970 install_element (ENABLE_NODE, &debug_ospf_te_cmd);
718e3744 1971 install_element (ENABLE_NODE, &no_debug_ospf_ism_cmd);
718e3744 1972 install_element (ENABLE_NODE, &no_debug_ospf_nsm_cmd);
718e3744 1973 install_element (ENABLE_NODE, &no_debug_ospf_lsa_cmd);
718e3744 1974 install_element (ENABLE_NODE, &no_debug_ospf_zebra_cmd);
1975 install_element (ENABLE_NODE, &no_debug_ospf_event_cmd);
718e3744 1976 install_element (ENABLE_NODE, &no_debug_ospf_nssa_cmd);
16f1b9ee 1977 install_element (ENABLE_NODE, &no_debug_ospf_te_cmd);
718e3744 1978
7c8ff89e 1979 install_element (ENABLE_NODE, &show_debugging_ospf_instance_cmd);
692b4c65
QY
1980 install_element (ENABLE_NODE, &debug_ospf_packet_cmd);
1981 install_element (ENABLE_NODE, &no_debug_ospf_packet_cmd);
1982 install_element (ENABLE_NODE, &debug_ospf_ism_cmd);
1983 install_element (ENABLE_NODE, &no_debug_ospf_ism_cmd);
1984
7c8ff89e 1985 install_element (ENABLE_NODE, &debug_ospf_instance_nsm_cmd);
7c8ff89e 1986 install_element (ENABLE_NODE, &debug_ospf_instance_lsa_cmd);
7c8ff89e
DS
1987 install_element (ENABLE_NODE, &debug_ospf_instance_zebra_cmd);
1988 install_element (ENABLE_NODE, &debug_ospf_instance_event_cmd);
1989 install_element (ENABLE_NODE, &debug_ospf_instance_nssa_cmd);
7c8ff89e 1990 install_element (ENABLE_NODE, &no_debug_ospf_instance_nsm_cmd);
7c8ff89e 1991 install_element (ENABLE_NODE, &no_debug_ospf_instance_lsa_cmd);
7c8ff89e
DS
1992 install_element (ENABLE_NODE, &no_debug_ospf_instance_zebra_cmd);
1993 install_element (ENABLE_NODE, &no_debug_ospf_instance_event_cmd);
1994 install_element (ENABLE_NODE, &no_debug_ospf_instance_nssa_cmd);
4dfd8aff 1995 install_element (ENABLE_NODE, &no_debug_ospf_cmd);
7c8ff89e 1996
692b4c65
QY
1997
1998
1999 install_element (CONFIG_NODE, &debug_ospf_packet_cmd);
2000 install_element (CONFIG_NODE, &no_debug_ospf_packet_cmd);
718e3744 2001 install_element (CONFIG_NODE, &debug_ospf_ism_cmd);
692b4c65
QY
2002 install_element (CONFIG_NODE, &no_debug_ospf_ism_cmd);
2003
718e3744 2004 install_element (CONFIG_NODE, &debug_ospf_nsm_cmd);
718e3744 2005 install_element (CONFIG_NODE, &debug_ospf_lsa_cmd);
718e3744 2006 install_element (CONFIG_NODE, &debug_ospf_zebra_cmd);
2007 install_element (CONFIG_NODE, &debug_ospf_event_cmd);
718e3744 2008 install_element (CONFIG_NODE, &debug_ospf_nssa_cmd);
16f1b9ee 2009 install_element (CONFIG_NODE, &debug_ospf_te_cmd);
718e3744 2010 install_element (CONFIG_NODE, &no_debug_ospf_ism_cmd);
718e3744 2011 install_element (CONFIG_NODE, &no_debug_ospf_nsm_cmd);
718e3744 2012 install_element (CONFIG_NODE, &no_debug_ospf_lsa_cmd);
718e3744 2013 install_element (CONFIG_NODE, &no_debug_ospf_zebra_cmd);
2014 install_element (CONFIG_NODE, &no_debug_ospf_event_cmd);
718e3744 2015 install_element (CONFIG_NODE, &no_debug_ospf_nssa_cmd);
16f1b9ee 2016 install_element (CONFIG_NODE, &no_debug_ospf_te_cmd);
7c8ff89e 2017
7c8ff89e 2018 install_element (CONFIG_NODE, &debug_ospf_instance_nsm_cmd);
7c8ff89e 2019 install_element (CONFIG_NODE, &debug_ospf_instance_lsa_cmd);
7c8ff89e
DS
2020 install_element (CONFIG_NODE, &debug_ospf_instance_zebra_cmd);
2021 install_element (CONFIG_NODE, &debug_ospf_instance_event_cmd);
2022 install_element (CONFIG_NODE, &debug_ospf_instance_nssa_cmd);
7c8ff89e 2023 install_element (CONFIG_NODE, &no_debug_ospf_instance_nsm_cmd);
7c8ff89e 2024 install_element (CONFIG_NODE, &no_debug_ospf_instance_lsa_cmd);
7c8ff89e
DS
2025 install_element (CONFIG_NODE, &no_debug_ospf_instance_zebra_cmd);
2026 install_element (CONFIG_NODE, &no_debug_ospf_instance_event_cmd);
2027 install_element (CONFIG_NODE, &no_debug_ospf_instance_nssa_cmd);
4dfd8aff 2028 install_element (CONFIG_NODE, &no_debug_ospf_cmd);
718e3744 2029}