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