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