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