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