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