]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_dump.c
2004-10-07 Greg Troxel <gdt@sunpal7.mit.edu>
[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"
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\f
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\f
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{
0c2be26c 328 char *lsah_type = LOOKUP (ospf_lsa_type_msg, lsah->type);
329
718e3744 330 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,
553ff113 335 (lsah->type ? lsah_type : "unknown type"));
718e3744 336 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);
d4a53d58 430 zlog_info (" %s", ospf_lsa_type_msg[al->header.type].str);
718e3744 431 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;
718e3744 565 case OSPF_AS_NSSA_LSA:
d4a53d58 566 ospf_as_external_lsa_dump (s, length);
718e3744 567 break;
718e3744 568#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;
6a99f831 605 u_int16_t offset;
718e3744 606 struct ip *iph;
607
608 iph = (struct ip *) STREAM_PNT (s);
609
18b12c38 610 sockopt_iphdrincl_swab_systoh (iph);
611
718e3744 612 /* IP Header dump. */
613 zlog_info ("ip_v %d", iph->ip_v);
614 zlog_info ("ip_hl %d", iph->ip_hl);
615 zlog_info ("ip_tos %d", iph->ip_tos);
616 zlog_info ("ip_len %d", length);
617 zlog_info ("ip_id %u", (u_int32_t) iph->ip_id);
6a99f831 618 zlog_info ("ip_off %u", (u_int32_t) offset);
718e3744 619 zlog_info ("ip_ttl %d", iph->ip_ttl);
620 zlog_info ("ip_p %d", iph->ip_p);
6a99f831 621 zlog_info ("ip_sum 0x%x", (u_int32_t) ntohs (iph->ip_sum));
718e3744 622 zlog_info ("ip_src %s", inet_ntoa (iph->ip_src));
623 zlog_info ("ip_dst %s", inet_ntoa (iph->ip_dst));
624}
625
626void
627ospf_header_dump (struct ospf_header *ospfh)
628{
629 char buf[9];
630
631 zlog_info ("Header");
632 zlog_info (" Version %d", ospfh->version);
633 zlog_info (" Type %d (%s)", ospfh->type,
634 ospf_packet_type_str[ospfh->type]);
635 zlog_info (" Packet Len %d", ntohs (ospfh->length));
636 zlog_info (" Router ID %s", inet_ntoa (ospfh->router_id));
637 zlog_info (" Area ID %s", inet_ntoa (ospfh->area_id));
638 zlog_info (" Checksum 0x%x", ntohs (ospfh->checksum));
639 zlog_info (" AuType %d", ntohs (ospfh->auth_type));
640
641 switch (ntohs (ospfh->auth_type))
642 {
643 case OSPF_AUTH_NULL:
644 break;
645 case OSPF_AUTH_SIMPLE:
646 memset (buf, 0, 9);
c9e52be3 647 strncpy (buf, (char *) ospfh->u.auth_data, 8);
718e3744 648 zlog_info (" Simple Password %s", buf);
649 break;
650 case OSPF_AUTH_CRYPTOGRAPHIC:
651 zlog_info (" Cryptographic Authentication");
652 zlog_info (" Key ID %d", ospfh->u.crypt.key_id);
653 zlog_info (" Auth Data Len %d", ospfh->u.crypt.auth_data_len);
654 zlog_info (" Sequence number %ld",
655 (u_long)ntohl (ospfh->u.crypt.crypt_seqnum));
656 break;
657 default:
658 zlog_info ("* This is not supported authentication type");
659 break;
660 }
661
662}
663
664void
665ospf_packet_dump (struct stream *s)
666{
667 struct ospf_header *ospfh;
668 unsigned long gp;
669
670 /* Preserve pointer. */
671 gp = stream_get_getp (s);
672
673 /* OSPF Header dump. */
674 ospfh = (struct ospf_header *) STREAM_PNT (s);
675
676 /* Until detail flag is set, return. */
677 if (!(term_debug_ospf_packet[ospfh->type - 1] & OSPF_DEBUG_DETAIL))
678 return;
679
680 /* Show OSPF header detail. */
681 ospf_header_dump (ospfh);
682 stream_forward (s, OSPF_HEADER_SIZE);
683
684 switch (ospfh->type)
685 {
686 case OSPF_MSG_HELLO:
687 ospf_packet_hello_dump (s, ntohs (ospfh->length));
688 break;
689 case OSPF_MSG_DB_DESC:
690 ospf_packet_db_desc_dump (s, ntohs (ospfh->length));
691 break;
692 case OSPF_MSG_LS_REQ:
693 ospf_packet_ls_req_dump (s, ntohs (ospfh->length));
694 break;
695 case OSPF_MSG_LS_UPD:
696 ospf_packet_ls_upd_dump (s, ntohs (ospfh->length));
697 break;
698 case OSPF_MSG_LS_ACK:
699 ospf_packet_ls_ack_dump (s, ntohs (ospfh->length));
700 break;
701 default:
702 break;
703 }
704
705 stream_set_getp (s, gp);
706}
707
708\f
709/*
710 [no] debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)
711 [send|recv [detail]]
712*/
713DEFUN (debug_ospf_packet,
714 debug_ospf_packet_all_cmd,
715 "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)",
716 DEBUG_STR
717 OSPF_STR
718 "OSPF packets\n"
719 "OSPF Hello\n"
720 "OSPF Database Description\n"
721 "OSPF Link State Request\n"
722 "OSPF Link State Update\n"
723 "OSPF Link State Acknowledgment\n"
724 "OSPF all packets\n")
725{
726 int type = 0;
727 int flag = 0;
728 int i;
729
730 assert (argc > 0);
731
732 /* Check packet type. */
733 if (strncmp (argv[0], "h", 1) == 0)
734 type = OSPF_DEBUG_HELLO;
735 else if (strncmp (argv[0], "d", 1) == 0)
736 type = OSPF_DEBUG_DB_DESC;
737 else if (strncmp (argv[0], "ls-r", 4) == 0)
738 type = OSPF_DEBUG_LS_REQ;
739 else if (strncmp (argv[0], "ls-u", 4) == 0)
740 type = OSPF_DEBUG_LS_UPD;
741 else if (strncmp (argv[0], "ls-a", 4) == 0)
742 type = OSPF_DEBUG_LS_ACK;
743 else if (strncmp (argv[0], "a", 1) == 0)
744 type = OSPF_DEBUG_ALL;
745
746 /* Default, both send and recv. */
747 if (argc == 1)
748 flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV;
749
750 /* send or recv. */
751 if (argc >= 2)
752 {
753 if (strncmp (argv[1], "s", 1) == 0)
754 flag = OSPF_DEBUG_SEND;
755 else if (strncmp (argv[1], "r", 1) == 0)
756 flag = OSPF_DEBUG_RECV;
757 else if (strncmp (argv[1], "d", 1) == 0)
758 flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
759 }
760
761 /* detail. */
762 if (argc == 3)
763 if (strncmp (argv[2], "d", 1) == 0)
764 flag |= OSPF_DEBUG_DETAIL;
765
766 for (i = 0; i < 5; i++)
767 if (type & (0x01 << i))
768 {
769 if (vty->node == CONFIG_NODE)
770 DEBUG_PACKET_ON (i, flag);
771 else
772 TERM_DEBUG_PACKET_ON (i, flag);
773 }
774
775 return CMD_SUCCESS;
776}
777
778ALIAS (debug_ospf_packet,
779 debug_ospf_packet_send_recv_cmd,
780 "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv|detail)",
781 "Debugging functions\n"
782 "OSPF information\n"
783 "OSPF packets\n"
784 "OSPF Hello\n"
785 "OSPF Database Description\n"
786 "OSPF Link State Request\n"
787 "OSPF Link State Update\n"
788 "OSPF Link State Acknowledgment\n"
789 "OSPF all packets\n"
790 "Packet sent\n"
791 "Packet received\n"
792 "Detail information\n")
793
794ALIAS (debug_ospf_packet,
795 debug_ospf_packet_send_recv_detail_cmd,
796 "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) (detail|)",
797 "Debugging functions\n"
798 "OSPF information\n"
799 "OSPF packets\n"
800 "OSPF Hello\n"
801 "OSPF Database Description\n"
802 "OSPF Link State Request\n"
803 "OSPF Link State Update\n"
804 "OSPF Link State Acknowledgment\n"
805 "OSPF all packets\n"
806 "Packet sent\n"
807 "Packet received\n"
808 "Detail Information\n")
809
810
811DEFUN (no_debug_ospf_packet,
812 no_debug_ospf_packet_all_cmd,
813 "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)",
814 NO_STR
815 DEBUG_STR
816 OSPF_STR
817 "OSPF packets\n"
818 "OSPF Hello\n"
819 "OSPF Database Description\n"
820 "OSPF Link State Request\n"
821 "OSPF Link State Update\n"
822 "OSPF Link State Acknowledgment\n"
823 "OSPF all packets\n")
824{
825 int type = 0;
826 int flag = 0;
827 int i;
828
829 assert (argc > 0);
830
831 /* Check packet type. */
832 if (strncmp (argv[0], "h", 1) == 0)
833 type = OSPF_DEBUG_HELLO;
834 else if (strncmp (argv[0], "d", 1) == 0)
835 type = OSPF_DEBUG_DB_DESC;
836 else if (strncmp (argv[0], "ls-r", 4) == 0)
837 type = OSPF_DEBUG_LS_REQ;
838 else if (strncmp (argv[0], "ls-u", 4) == 0)
839 type = OSPF_DEBUG_LS_UPD;
840 else if (strncmp (argv[0], "ls-a", 4) == 0)
841 type = OSPF_DEBUG_LS_ACK;
842 else if (strncmp (argv[0], "a", 1) == 0)
843 type = OSPF_DEBUG_ALL;
844
845 /* Default, both send and recv. */
846 if (argc == 1)
847 flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL ;
848
849 /* send or recv. */
850 if (argc == 2)
851 {
852 if (strncmp (argv[1], "s", 1) == 0)
853 flag = OSPF_DEBUG_SEND | OSPF_DEBUG_DETAIL;
854 else if (strncmp (argv[1], "r", 1) == 0)
855 flag = OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
856 else if (strncmp (argv[1], "d", 1) == 0)
857 flag = OSPF_DEBUG_DETAIL;
858 }
859
860 /* detail. */
861 if (argc == 3)
862 if (strncmp (argv[2], "d", 1) == 0)
863 flag = OSPF_DEBUG_DETAIL;
864
865 for (i = 0; i < 5; i++)
866 if (type & (0x01 << i))
867 {
868 if (vty->node == CONFIG_NODE)
869 DEBUG_PACKET_OFF (i, flag);
870 else
871 TERM_DEBUG_PACKET_OFF (i, flag);
872 }
873
874#ifdef DEBUG
875 for (i = 0; i < 5; i++)
876 zlog_info ("flag[%d] = %d", i, ospf_debug_packet[i]);
877#endif /* DEBUG */
878
879 return CMD_SUCCESS;
880}
881
882ALIAS (no_debug_ospf_packet,
883 no_debug_ospf_packet_send_recv_cmd,
884 "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv|detail)",
885 NO_STR
886 "Debugging functions\n"
887 "OSPF information\n"
888 "OSPF packets\n"
889 "OSPF Hello\n"
890 "OSPF Database Description\n"
891 "OSPF Link State Request\n"
892 "OSPF Link State Update\n"
893 "OSPF Link State Acknowledgment\n"
894 "OSPF all packets\n"
895 "Packet sent\n"
896 "Packet received\n"
897 "Detail Information\n")
898
899ALIAS (no_debug_ospf_packet,
900 no_debug_ospf_packet_send_recv_detail_cmd,
901 "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) (detail|)",
902 NO_STR
903 "Debugging functions\n"
904 "OSPF information\n"
905 "OSPF packets\n"
906 "OSPF Hello\n"
907 "OSPF Database Description\n"
908 "OSPF Link State Request\n"
909 "OSPF Link State Update\n"
910 "OSPF Link State Acknowledgment\n"
911 "OSPF all packets\n"
912 "Packet sent\n"
913 "Packet received\n"
914 "Detail Information\n")
915
916\f
917DEFUN (debug_ospf_ism,
918 debug_ospf_ism_cmd,
919 "debug ospf ism",
920 DEBUG_STR
921 OSPF_STR
922 "OSPF Interface State Machine\n")
923{
924 if (vty->node == CONFIG_NODE)
925 {
926 if (argc == 0)
927 DEBUG_ON (ism, ISM);
928 else if (argc == 1)
929 {
930 if (strncmp (argv[0], "s", 1) == 0)
931 DEBUG_ON (ism, ISM_STATUS);
932 else if (strncmp (argv[0], "e", 1) == 0)
933 DEBUG_ON (ism, ISM_EVENTS);
934 else if (strncmp (argv[0], "t", 1) == 0)
935 DEBUG_ON (ism, ISM_TIMERS);
936 }
937
938 return CMD_SUCCESS;
939 }
940
941 /* ENABLE_NODE. */
942 if (argc == 0)
943 TERM_DEBUG_ON (ism, ISM);
944 else if (argc == 1)
945 {
946 if (strncmp (argv[0], "s", 1) == 0)
947 TERM_DEBUG_ON (ism, ISM_STATUS);
948 else if (strncmp (argv[0], "e", 1) == 0)
949 TERM_DEBUG_ON (ism, ISM_EVENTS);
950 else if (strncmp (argv[0], "t", 1) == 0)
951 TERM_DEBUG_ON (ism, ISM_TIMERS);
952 }
953
954 return CMD_SUCCESS;
955}
956
957ALIAS (debug_ospf_ism,
958 debug_ospf_ism_sub_cmd,
959 "debug ospf ism (status|events|timers)",
960 DEBUG_STR
961 OSPF_STR
962 "OSPF Interface State Machine\n"
963 "ISM Status Information\n"
964 "ISM Event Information\n"
965 "ISM TImer Information\n")
966
967DEFUN (no_debug_ospf_ism,
968 no_debug_ospf_ism_cmd,
969 "no debug ospf ism",
970 NO_STR
971 DEBUG_STR
972 OSPF_STR
973 "OSPF Interface State Machine")
974{
975 if (vty->node == CONFIG_NODE)
976 {
977 if (argc == 0)
978 DEBUG_OFF (ism, ISM);
979 else if (argc == 1)
980 {
981 if (strncmp (argv[0], "s", 1) == 0)
982 DEBUG_OFF (ism, ISM_STATUS);
983 else if (strncmp (argv[0], "e", 1) == 0)
984 DEBUG_OFF (ism, ISM_EVENTS);
985 else if (strncmp (argv[0], "t", 1) == 0)
986 DEBUG_OFF (ism, ISM_TIMERS);
987 }
988 return CMD_SUCCESS;
989 }
990
991 /* ENABLE_NODE. */
992 if (argc == 0)
993 TERM_DEBUG_OFF (ism, ISM);
994 else if (argc == 1)
995 {
996 if (strncmp (argv[0], "s", 1) == 0)
997 TERM_DEBUG_OFF (ism, ISM_STATUS);
998 else if (strncmp (argv[0], "e", 1) == 0)
999 TERM_DEBUG_OFF (ism, ISM_EVENTS);
1000 else if (strncmp (argv[0], "t", 1) == 0)
1001 TERM_DEBUG_OFF (ism, ISM_TIMERS);
1002 }
1003
1004 return CMD_SUCCESS;
1005}
1006
1007ALIAS (no_debug_ospf_ism,
1008 no_debug_ospf_ism_sub_cmd,
1009 "no debug ospf ism (status|events|timers)",
1010 NO_STR
1011 "Debugging functions\n"
1012 "OSPF information\n"
1013 "OSPF Interface State Machine\n"
1014 "ISM Status Information\n"
1015 "ISM Event Information\n"
1016 "ISM Timer Information\n")
1017
1018\f
1019DEFUN (debug_ospf_nsm,
1020 debug_ospf_nsm_cmd,
1021 "debug ospf nsm",
1022 DEBUG_STR
1023 OSPF_STR
1024 "OSPF Neighbor State Machine\n")
1025{
1026 if (vty->node == CONFIG_NODE)
1027 {
1028 if (argc == 0)
1029 DEBUG_ON (nsm, NSM);
1030 else if (argc == 1)
1031 {
1032 if (strncmp (argv[0], "s", 1) == 0)
1033 DEBUG_ON (nsm, NSM_STATUS);
1034 else if (strncmp (argv[0], "e", 1) == 0)
1035 DEBUG_ON (nsm, NSM_EVENTS);
1036 else if (strncmp (argv[0], "t", 1) == 0)
1037 DEBUG_ON (nsm, NSM_TIMERS);
1038 }
1039
1040 return CMD_SUCCESS;
1041 }
1042
1043 /* ENABLE_NODE. */
1044 if (argc == 0)
1045 TERM_DEBUG_ON (nsm, NSM);
1046 else if (argc == 1)
1047 {
1048 if (strncmp (argv[0], "s", 1) == 0)
1049 TERM_DEBUG_ON (nsm, NSM_STATUS);
1050 else if (strncmp (argv[0], "e", 1) == 0)
1051 TERM_DEBUG_ON (nsm, NSM_EVENTS);
1052 else if (strncmp (argv[0], "t", 1) == 0)
1053 TERM_DEBUG_ON (nsm, NSM_TIMERS);
1054 }
1055
1056 return CMD_SUCCESS;
1057}
1058
1059ALIAS (debug_ospf_nsm,
1060 debug_ospf_nsm_sub_cmd,
1061 "debug ospf nsm (status|events|timers)",
1062 DEBUG_STR
1063 OSPF_STR
1064 "OSPF Neighbor State Machine\n"
1065 "NSM Status Information\n"
1066 "NSM Event Information\n"
1067 "NSM Timer Information\n")
1068
1069DEFUN (no_debug_ospf_nsm,
1070 no_debug_ospf_nsm_cmd,
1071 "no debug ospf nsm",
1072 NO_STR
1073 DEBUG_STR
1074 OSPF_STR
1075 "OSPF Neighbor State Machine")
1076{
1077 if (vty->node == CONFIG_NODE)
1078 {
1079 if (argc == 0)
1080 DEBUG_OFF (nsm, NSM);
1081 else if (argc == 1)
1082 {
1083 if (strncmp (argv[0], "s", 1) == 0)
1084 DEBUG_OFF (nsm, NSM_STATUS);
1085 else if (strncmp (argv[0], "e", 1) == 0)
1086 DEBUG_OFF (nsm, NSM_EVENTS);
1087 else if (strncmp (argv[0], "t", 1) == 0)
1088 DEBUG_OFF (nsm, NSM_TIMERS);
1089 }
1090
1091 return CMD_SUCCESS;
1092 }
1093
1094 /* ENABLE_NODE. */
1095 if (argc == 0)
1096 TERM_DEBUG_OFF (nsm, NSM);
1097 else if (argc == 1)
1098 {
1099 if (strncmp (argv[0], "s", 1) == 0)
1100 TERM_DEBUG_OFF (nsm, NSM_STATUS);
1101 else if (strncmp (argv[0], "e", 1) == 0)
1102 TERM_DEBUG_OFF (nsm, NSM_EVENTS);
1103 else if (strncmp (argv[0], "t", 1) == 0)
1104 TERM_DEBUG_OFF (nsm, NSM_TIMERS);
1105 }
1106
1107 return CMD_SUCCESS;
1108}
1109
1110ALIAS (no_debug_ospf_nsm,
1111 no_debug_ospf_nsm_sub_cmd,
1112 "no debug ospf nsm (status|events|timers)",
1113 NO_STR
1114 "Debugging functions\n"
1115 "OSPF information\n"
1116 "OSPF Interface State Machine\n"
1117 "NSM Status Information\n"
1118 "NSM Event Information\n"
1119 "NSM Timer Information\n")
1120
1121\f
1122DEFUN (debug_ospf_lsa,
1123 debug_ospf_lsa_cmd,
1124 "debug ospf lsa",
1125 DEBUG_STR
1126 OSPF_STR
1127 "OSPF Link State Advertisement\n")
1128{
1129 if (vty->node == CONFIG_NODE)
1130 {
1131 if (argc == 0)
1132 DEBUG_ON (lsa, LSA);
1133 else if (argc == 1)
1134 {
1135 if (strncmp (argv[0], "g", 1) == 0)
1136 DEBUG_ON (lsa, LSA_GENERATE);
1137 else if (strncmp (argv[0], "f", 1) == 0)
1138 DEBUG_ON (lsa, LSA_FLOODING);
1139 else if (strncmp (argv[0], "i", 1) == 0)
1140 DEBUG_ON (lsa, LSA_INSTALL);
1141 else if (strncmp (argv[0], "r", 1) == 0)
1142 DEBUG_ON (lsa, LSA_REFRESH);
1143 }
1144
1145 return CMD_SUCCESS;
1146 }
1147
1148 /* ENABLE_NODE. */
1149 if (argc == 0)
1150 TERM_DEBUG_ON (lsa, LSA);
1151 else if (argc == 1)
1152 {
1153 if (strncmp (argv[0], "g", 1) == 0)
1154 TERM_DEBUG_ON (lsa, LSA_GENERATE);
1155 else if (strncmp (argv[0], "f", 1) == 0)
1156 TERM_DEBUG_ON (lsa, LSA_FLOODING);
1157 else if (strncmp (argv[0], "i", 1) == 0)
1158 TERM_DEBUG_ON (lsa, LSA_INSTALL);
1159 else if (strncmp (argv[0], "r", 1) == 0)
1160 TERM_DEBUG_ON (lsa, LSA_REFRESH);
1161 }
1162
1163 return CMD_SUCCESS;
1164}
1165
1166ALIAS (debug_ospf_lsa,
1167 debug_ospf_lsa_sub_cmd,
1168 "debug ospf lsa (generate|flooding|install|refresh)",
1169 DEBUG_STR
1170 OSPF_STR
1171 "OSPF Link State Advertisement\n"
1172 "LSA Generation\n"
1173 "LSA Flooding\n"
1174 "LSA Install/Delete\n"
1175 "LSA Refresh\n")
1176
1177DEFUN (no_debug_ospf_lsa,
1178 no_debug_ospf_lsa_cmd,
1179 "no debug ospf lsa",
1180 NO_STR
1181 DEBUG_STR
1182 OSPF_STR
1183 "OSPF Link State Advertisement\n")
1184{
1185 if (vty->node == CONFIG_NODE)
1186 {
1187 if (argc == 0)
1188 DEBUG_OFF (lsa, LSA);
1189 else if (argc == 1)
1190 {
1191 if (strncmp (argv[0], "g", 1) == 0)
1192 DEBUG_OFF (lsa, LSA_GENERATE);
1193 else if (strncmp (argv[0], "f", 1) == 0)
1194 DEBUG_OFF (lsa, LSA_FLOODING);
1195 else if (strncmp (argv[0], "i", 1) == 0)
1196 DEBUG_OFF (lsa, LSA_INSTALL);
1197 else if (strncmp (argv[0], "r", 1) == 0)
1198 DEBUG_OFF (lsa, LSA_REFRESH);
1199 }
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 /* ENABLE_NODE. */
1205 if (argc == 0)
1206 TERM_DEBUG_OFF (lsa, LSA);
1207 else if (argc == 1)
1208 {
1209 if (strncmp (argv[0], "g", 1) == 0)
1210 TERM_DEBUG_OFF (lsa, LSA_GENERATE);
1211 else if (strncmp (argv[0], "f", 1) == 0)
1212 TERM_DEBUG_OFF (lsa, LSA_FLOODING);
1213 else if (strncmp (argv[0], "i", 1) == 0)
1214 TERM_DEBUG_OFF (lsa, LSA_INSTALL);
1215 else if (strncmp (argv[0], "r", 1) == 0)
1216 TERM_DEBUG_OFF (lsa, LSA_REFRESH);
1217 }
1218
1219 return CMD_SUCCESS;
1220}
1221
1222ALIAS (no_debug_ospf_lsa,
1223 no_debug_ospf_lsa_sub_cmd,
1224 "no debug ospf lsa (generate|flooding|install|refresh)",
1225 NO_STR
1226 DEBUG_STR
1227 OSPF_STR
1228 "OSPF Link State Advertisement\n"
1229 "LSA Generation\n"
1230 "LSA Flooding\n"
1231 "LSA Install/Delete\n"
1232 "LSA Refres\n")
1233
1234\f
1235DEFUN (debug_ospf_zebra,
1236 debug_ospf_zebra_cmd,
1237 "debug ospf zebra",
1238 DEBUG_STR
1239 OSPF_STR
1240 "OSPF Zebra information\n")
1241{
1242 if (vty->node == CONFIG_NODE)
1243 {
1244 if (argc == 0)
1245 DEBUG_ON (zebra, ZEBRA);
1246 else if (argc == 1)
1247 {
1248 if (strncmp (argv[0], "i", 1) == 0)
1249 DEBUG_ON (zebra, ZEBRA_INTERFACE);
1250 else if (strncmp (argv[0], "r", 1) == 0)
1251 DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
1252 }
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 /* ENABLE_NODE. */
1258 if (argc == 0)
1259 TERM_DEBUG_ON (zebra, ZEBRA);
1260 else if (argc == 1)
1261 {
1262 if (strncmp (argv[0], "i", 1) == 0)
1263 TERM_DEBUG_ON (zebra, ZEBRA_INTERFACE);
1264 else if (strncmp (argv[0], "r", 1) == 0)
1265 TERM_DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
1266 }
1267
1268 return CMD_SUCCESS;
1269}
1270
1271ALIAS (debug_ospf_zebra,
1272 debug_ospf_zebra_sub_cmd,
1273 "debug ospf zebra (interface|redistribute)",
1274 DEBUG_STR
1275 OSPF_STR
1276 "OSPF Zebra information\n"
1277 "Zebra interface\n"
1278 "Zebra redistribute\n")
1279
1280DEFUN (no_debug_ospf_zebra,
1281 no_debug_ospf_zebra_cmd,
1282 "no debug ospf zebra",
1283 NO_STR
1284 DEBUG_STR
1285 OSPF_STR
1286 "OSPF Zebra information\n")
1287{
1288 if (vty->node == CONFIG_NODE)
1289 {
1290 if (argc == 0)
1291 DEBUG_OFF (zebra, ZEBRA);
1292 else if (argc == 1)
1293 {
1294 if (strncmp (argv[0], "i", 1) == 0)
1295 DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1296 else if (strncmp (argv[0], "r", 1) == 0)
1297 DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1298 }
1299
1300 return CMD_SUCCESS;
1301 }
1302
1303 /* ENABLE_NODE. */
1304 if (argc == 0)
1305 TERM_DEBUG_OFF (zebra, ZEBRA);
1306 else if (argc == 1)
1307 {
1308 if (strncmp (argv[0], "i", 1) == 0)
1309 TERM_DEBUG_OFF (zebra, ZEBRA_INTERFACE);
1310 else if (strncmp (argv[0], "r", 1) == 0)
1311 TERM_DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
1312 }
1313
1314 return CMD_SUCCESS;
1315}
1316
1317ALIAS (no_debug_ospf_zebra,
1318 no_debug_ospf_zebra_sub_cmd,
1319 "no debug ospf zebra (interface|redistribute)",
1320 NO_STR
1321 DEBUG_STR
1322 OSPF_STR
1323 "OSPF Zebra information\n"
1324 "Zebra interface\n"
1325 "Zebra redistribute\n")
1326\f
1327DEFUN (debug_ospf_event,
1328 debug_ospf_event_cmd,
1329 "debug ospf event",
1330 DEBUG_STR
1331 OSPF_STR
1332 "OSPF event information\n")
1333{
1334 if (vty->node == CONFIG_NODE)
1335 CONF_DEBUG_ON (event, EVENT);
1336 TERM_DEBUG_ON (event, EVENT);
1337 return CMD_SUCCESS;
1338}
1339
1340DEFUN (no_debug_ospf_event,
1341 no_debug_ospf_event_cmd,
1342 "no debug ospf event",
1343 NO_STR
1344 DEBUG_STR
1345 OSPF_STR
1346 "OSPF event information\n")
1347{
1348 if (vty->node == CONFIG_NODE)
1349 CONF_DEBUG_OFF (event, EVENT);
1350 TERM_DEBUG_OFF (event, EVENT);
1351 return CMD_SUCCESS;
1352}
1353
1354DEFUN (debug_ospf_nssa,
1355 debug_ospf_nssa_cmd,
1356 "debug ospf nssa",
1357 DEBUG_STR
1358 OSPF_STR
1359 "OSPF nssa information\n")
1360{
1361 if (vty->node == CONFIG_NODE)
1362 CONF_DEBUG_ON (nssa, NSSA);
1363 TERM_DEBUG_ON (nssa, NSSA);
1364 return CMD_SUCCESS;
1365}
1366
1367DEFUN (no_debug_ospf_nssa,
1368 no_debug_ospf_nssa_cmd,
1369 "no debug ospf nssa",
1370 NO_STR
1371 DEBUG_STR
1372 OSPF_STR
1373 "OSPF nssa information\n")
1374{
1375 if (vty->node == CONFIG_NODE)
1376 CONF_DEBUG_OFF (nssa, NSSA);
1377 TERM_DEBUG_OFF (nssa, NSSA);
1378 return CMD_SUCCESS;
1379}
1380
1381\f
1382DEFUN (show_debugging_ospf,
1383 show_debugging_ospf_cmd,
1384 "show debugging ospf",
1385 SHOW_STR
1386 DEBUG_STR
1387 OSPF_STR)
1388{
1389 int i;
1390
df43a137 1391 vty_out (vty, "OSPF debugging status:%s", VTY_NEWLINE);
718e3744 1392
1393 /* Show debug status for ISM. */
1394 if (IS_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
1395 vty_out (vty, " OSPF ISM debugging is on%s", VTY_NEWLINE);
1396 else
1397 {
1398 if (IS_DEBUG_OSPF (ism, ISM_STATUS))
1399 vty_out (vty, " OSPF ISM status debugging is on%s", VTY_NEWLINE);
1400 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
1401 vty_out (vty, " OSPF ISM event debugging is on%s", VTY_NEWLINE);
1402 if (IS_DEBUG_OSPF (ism, ISM_TIMERS))
1403 vty_out (vty, " OSPF ISM timer debugging is on%s", VTY_NEWLINE);
1404 }
1405
1406 /* Show debug status for NSM. */
1407 if (IS_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
1408 vty_out (vty, " OSPF NSM debugging is on%s", VTY_NEWLINE);
1409 else
1410 {
1411 if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
1412 vty_out (vty, " OSPF NSM status debugging is on%s", VTY_NEWLINE);
1413 if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
1414 vty_out (vty, " OSPF NSM event debugging is on%s", VTY_NEWLINE);
1415 if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
1416 vty_out (vty, " OSPF NSM timer debugging is on%s", VTY_NEWLINE);
1417 }
1418
1419 /* Show debug status for OSPF Packets. */
1420 for (i = 0; i < 5; i++)
1421 if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV))
1422 {
1423 vty_out (vty, " OSPF packet %s%s debugging is on%s",
1424 ospf_packet_type_str[i + 1],
1425 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1426 VTY_NEWLINE);
1427 }
1428 else
1429 {
1430 if (IS_DEBUG_OSPF_PACKET (i, SEND))
1431 vty_out (vty, " OSPF packet %s send%s debugging is on%s",
1432 ospf_packet_type_str[i + 1],
1433 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1434 VTY_NEWLINE);
1435 if (IS_DEBUG_OSPF_PACKET (i, RECV))
1436 vty_out (vty, " OSPF packet %s receive%s debugging is on%s",
1437 ospf_packet_type_str[i + 1],
1438 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
1439 VTY_NEWLINE);
1440 }
1441
1442 /* Show debug status for OSPF LSAs. */
1443 if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
1444 vty_out (vty, " OSPF LSA debugging is on%s", VTY_NEWLINE);
1445 else
1446 {
1447 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1448 vty_out (vty, " OSPF LSA generation debugging is on%s", VTY_NEWLINE);
1449 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
1450 vty_out (vty, " OSPF LSA flooding debugging is on%s", VTY_NEWLINE);
1451 if (IS_DEBUG_OSPF (lsa, LSA_INSTALL))
1452 vty_out (vty, " OSPF LSA install debugging is on%s", VTY_NEWLINE);
1453 if (IS_DEBUG_OSPF (lsa, LSA_REFRESH))
1454 vty_out (vty, " OSPF LSA refresh debugging is on%s", VTY_NEWLINE);
1455 }
1456
1457 /* Show debug status for Zebra. */
1458 if (IS_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1459 vty_out (vty, " OSPF Zebra debugging is on%s", VTY_NEWLINE);
1460 else
1461 {
1462 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
1463 vty_out (vty, " OSPF Zebra interface debugging is on%s", VTY_NEWLINE);
1464 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
1465 vty_out (vty, " OSPF Zebra redistribute debugging is on%s", VTY_NEWLINE);
1466 }
ead687e1 1467 if (IS_DEBUG_OSPF (nssa, NSSA) == OSPF_DEBUG_NSSA)
1468 vty_out (vty, " OSPF NSSA debugging is on%s", VTY_NEWLINE);
718e3744 1469
1470 return CMD_SUCCESS;
1471}
1472
1473/* Debug node. */
1474struct cmd_node debug_node =
1475{
1476 DEBUG_NODE,
1477 ""
1478};
1479
1480int
1481config_write_debug (struct vty *vty)
1482{
1483 int write = 0;
1484 int i, r;
1485
1486 char *type_str[] = {"hello", "dd", "ls-request", "ls-update", "ls-ack"};
1487 char *detail_str[] = {"", " send", " recv", "", " detail",
1488 " send detail", " recv detail", " detail"};
1489
1490 /* debug ospf ism (status|events|timers). */
1491 if (IS_CONF_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
1492 vty_out (vty, "debug ospf ism%s", VTY_NEWLINE);
1493 else
1494 {
1495 if (IS_CONF_DEBUG_OSPF (ism, ISM_STATUS))
1496 vty_out (vty, "debug ospf ism status%s", VTY_NEWLINE);
1497 if (IS_CONF_DEBUG_OSPF (ism, ISM_EVENTS))
1498 vty_out (vty, "debug ospf ism event%s", VTY_NEWLINE);
1499 if (IS_CONF_DEBUG_OSPF (ism, ISM_TIMERS))
1500 vty_out (vty, "debug ospf ism timer%s", VTY_NEWLINE);
1501 }
1502
1503 /* debug ospf nsm (status|events|timers). */
1504 if (IS_CONF_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
1505 vty_out (vty, "debug ospf nsm%s", VTY_NEWLINE);
1506 else
1507 {
1508 if (IS_CONF_DEBUG_OSPF (nsm, NSM_STATUS))
1509 vty_out (vty, "debug ospf ism status%s", VTY_NEWLINE);
1510 if (IS_CONF_DEBUG_OSPF (nsm, NSM_EVENTS))
1511 vty_out (vty, "debug ospf nsm event%s", VTY_NEWLINE);
1512 if (IS_CONF_DEBUG_OSPF (nsm, NSM_TIMERS))
1513 vty_out (vty, "debug ospf nsm timer%s", VTY_NEWLINE);
1514 }
1515
1516 /* debug ospf lsa (generate|flooding|install|refresh). */
1517 if (IS_CONF_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
1518 vty_out (vty, "debug ospf lsa%s", VTY_NEWLINE);
1519 else
1520 {
1521 if (IS_CONF_DEBUG_OSPF (lsa, LSA_GENERATE))
1522 vty_out (vty, "debug ospf lsa generate%s", VTY_NEWLINE);
1523 if (IS_CONF_DEBUG_OSPF (lsa, LSA_FLOODING))
1524 vty_out (vty, "debug ospf lsa flooding%s", VTY_NEWLINE);
1525 if (IS_CONF_DEBUG_OSPF (lsa, LSA_INSTALL))
1526 vty_out (vty, "debug ospf lsa install%s", VTY_NEWLINE);
1527 if (IS_CONF_DEBUG_OSPF (lsa, LSA_REFRESH))
1528 vty_out (vty, "debug ospf lsa refresh%s", VTY_NEWLINE);
1529
1530 write = 1;
1531 }
1532
1533 /* debug ospf zebra (interface|redistribute). */
1534 if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1535 vty_out (vty, "debug ospf zebra%s", VTY_NEWLINE);
1536 else
1537 {
1538 if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
1539 vty_out (vty, "debug ospf zebra interface%s", VTY_NEWLINE);
1540 if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
1541 vty_out (vty, "debug ospf zebra redistribute%s", VTY_NEWLINE);
1542
1543 write = 1;
1544 }
1545
1546 /* debug ospf event. */
1547 if (IS_CONF_DEBUG_OSPF (event, EVENT) == OSPF_DEBUG_EVENT)
1548 {
1549 vty_out (vty, "debug ospf event%s", VTY_NEWLINE);
1550 write = 1;
1551 }
1552
1553 /* debug ospf nssa. */
1554 if (IS_CONF_DEBUG_OSPF (nssa, NSSA) == OSPF_DEBUG_NSSA)
1555 {
1556 vty_out (vty, "debug ospf nssa%s", VTY_NEWLINE);
1557 write = 1;
1558 }
1559
1560 /* debug ospf packet all detail. */
1561 r = OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL;
1562 for (i = 0; i < 5; i++)
1563 r &= conf_debug_ospf_packet[i] & (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL);
1564 if (r == (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL))
1565 {
1566 vty_out (vty, "debug ospf packet all detail%s", VTY_NEWLINE);
1567 return 1;
1568 }
1569
1570 /* debug ospf packet all. */
1571 r = OSPF_DEBUG_SEND_RECV;
1572 for (i = 0; i < 5; i++)
1573 r &= conf_debug_ospf_packet[i] & OSPF_DEBUG_SEND_RECV;
1574 if (r == OSPF_DEBUG_SEND_RECV)
1575 {
1576 vty_out (vty, "debug ospf packet all%s", VTY_NEWLINE);
1577 for (i = 0; i < 5; i++)
1578 if (conf_debug_ospf_packet[i] & OSPF_DEBUG_DETAIL)
1579 vty_out (vty, "debug ospf packet %s detail%s",
1580 type_str[i],
1581 VTY_NEWLINE);
1582 return 1;
1583 }
1584
1585 /* debug ospf packet (hello|dd|ls-request|ls-update|ls-ack)
1586 (send|recv) (detail). */
1587 for (i = 0; i < 5; i++)
1588 {
1589 if (conf_debug_ospf_packet[i] == 0)
1590 continue;
1591
1592 vty_out (vty, "debug ospf packet %s%s%s",
1593 type_str[i], detail_str[conf_debug_ospf_packet[i]],
1594 VTY_NEWLINE);
1595 write = 1;
1596 }
1597
1598 return write;
1599}
1600
1601/* Initialize debug commands. */
1602void
1603debug_init ()
1604{
1605 install_node (&debug_node, config_write_debug);
1606
1607 install_element (ENABLE_NODE, &show_debugging_ospf_cmd);
1608 install_element (ENABLE_NODE, &debug_ospf_packet_send_recv_detail_cmd);
1609 install_element (ENABLE_NODE, &debug_ospf_packet_send_recv_cmd);
1610 install_element (ENABLE_NODE, &debug_ospf_packet_all_cmd);
1611 install_element (ENABLE_NODE, &debug_ospf_ism_sub_cmd);
1612 install_element (ENABLE_NODE, &debug_ospf_ism_cmd);
1613 install_element (ENABLE_NODE, &debug_ospf_nsm_sub_cmd);
1614 install_element (ENABLE_NODE, &debug_ospf_nsm_cmd);
1615 install_element (ENABLE_NODE, &debug_ospf_lsa_sub_cmd);
1616 install_element (ENABLE_NODE, &debug_ospf_lsa_cmd);
1617 install_element (ENABLE_NODE, &debug_ospf_zebra_sub_cmd);
1618 install_element (ENABLE_NODE, &debug_ospf_zebra_cmd);
1619 install_element (ENABLE_NODE, &debug_ospf_event_cmd);
718e3744 1620 install_element (ENABLE_NODE, &debug_ospf_nssa_cmd);
718e3744 1621 install_element (ENABLE_NODE, &no_debug_ospf_packet_send_recv_detail_cmd);
1622 install_element (ENABLE_NODE, &no_debug_ospf_packet_send_recv_cmd);
1623 install_element (ENABLE_NODE, &no_debug_ospf_packet_all_cmd);
1624 install_element (ENABLE_NODE, &no_debug_ospf_ism_sub_cmd);
1625 install_element (ENABLE_NODE, &no_debug_ospf_ism_cmd);
1626 install_element (ENABLE_NODE, &no_debug_ospf_nsm_sub_cmd);
1627 install_element (ENABLE_NODE, &no_debug_ospf_nsm_cmd);
1628 install_element (ENABLE_NODE, &no_debug_ospf_lsa_sub_cmd);
1629 install_element (ENABLE_NODE, &no_debug_ospf_lsa_cmd);
1630 install_element (ENABLE_NODE, &no_debug_ospf_zebra_sub_cmd);
1631 install_element (ENABLE_NODE, &no_debug_ospf_zebra_cmd);
1632 install_element (ENABLE_NODE, &no_debug_ospf_event_cmd);
718e3744 1633 install_element (ENABLE_NODE, &no_debug_ospf_nssa_cmd);
718e3744 1634
1635 install_element (CONFIG_NODE, &debug_ospf_packet_send_recv_detail_cmd);
1636 install_element (CONFIG_NODE, &debug_ospf_packet_send_recv_cmd);
1637 install_element (CONFIG_NODE, &debug_ospf_packet_all_cmd);
1638 install_element (CONFIG_NODE, &debug_ospf_ism_sub_cmd);
1639 install_element (CONFIG_NODE, &debug_ospf_ism_cmd);
1640 install_element (CONFIG_NODE, &debug_ospf_nsm_sub_cmd);
1641 install_element (CONFIG_NODE, &debug_ospf_nsm_cmd);
1642 install_element (CONFIG_NODE, &debug_ospf_lsa_sub_cmd);
1643 install_element (CONFIG_NODE, &debug_ospf_lsa_cmd);
1644 install_element (CONFIG_NODE, &debug_ospf_zebra_sub_cmd);
1645 install_element (CONFIG_NODE, &debug_ospf_zebra_cmd);
1646 install_element (CONFIG_NODE, &debug_ospf_event_cmd);
718e3744 1647 install_element (CONFIG_NODE, &debug_ospf_nssa_cmd);
718e3744 1648 install_element (CONFIG_NODE, &no_debug_ospf_packet_send_recv_detail_cmd);
1649 install_element (CONFIG_NODE, &no_debug_ospf_packet_send_recv_cmd);
1650 install_element (CONFIG_NODE, &no_debug_ospf_packet_all_cmd);
1651 install_element (CONFIG_NODE, &no_debug_ospf_ism_sub_cmd);
1652 install_element (CONFIG_NODE, &no_debug_ospf_ism_cmd);
1653 install_element (CONFIG_NODE, &no_debug_ospf_nsm_sub_cmd);
1654 install_element (CONFIG_NODE, &no_debug_ospf_nsm_cmd);
1655 install_element (CONFIG_NODE, &no_debug_ospf_lsa_sub_cmd);
1656 install_element (CONFIG_NODE, &no_debug_ospf_lsa_cmd);
1657 install_element (CONFIG_NODE, &no_debug_ospf_zebra_sub_cmd);
1658 install_element (CONFIG_NODE, &no_debug_ospf_zebra_cmd);
1659 install_element (CONFIG_NODE, &no_debug_ospf_event_cmd);
718e3744 1660 install_element (CONFIG_NODE, &no_debug_ospf_nssa_cmd);
718e3744 1661}