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