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