]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_dump.c
build, vtysh: extract vtysh commands from .xref
[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 unsigned long conf_debug_ospf_orr;
65
66 /* Enable debug option variables -- valid only session. */
67 unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
68 unsigned long term_debug_ospf_event;
69 unsigned long term_debug_ospf_ism = 0;
70 unsigned long term_debug_ospf_nsm = 0;
71 unsigned long term_debug_ospf_lsa = 0;
72 unsigned long term_debug_ospf_zebra = 0;
73 unsigned long term_debug_ospf_nssa = 0;
74 unsigned long term_debug_ospf_te;
75 unsigned long term_debug_ospf_ext = 0;
76 unsigned long term_debug_ospf_sr;
77 unsigned long term_debug_ospf_ti_lfa;
78 unsigned long term_debug_ospf_defaultinfo;
79 unsigned long term_debug_ospf_ldp_sync;
80 unsigned long term_debug_ospf_gr;
81 unsigned long term_debug_ospf_bfd;
82 unsigned long term_debug_ospf_client_api;
83 unsigned long term_debug_ospf_orr;
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 DEFPY (debug_ospf_packet,
632 debug_ospf_packet_cmd,
633 "[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>]",
634 NO_STR
635 DEBUG_STR
636 OSPF_STR
637 "Instance ID\n"
638 "OSPF packets\n"
639 "OSPF Hello\n"
640 "OSPF Database Description\n"
641 "OSPF Link State Request\n"
642 "OSPF Link State Update\n"
643 "OSPF Link State Acknowledgment\n"
644 "OSPF all packets\n"
645 "Packet sent\n"
646 "Detail Information\n"
647 "Packet received\n"
648 "Detail Information\n"
649 "Detail Information\n")
650 {
651 int type = 0;
652 int flag = 0;
653 int i;
654
655 if (inst && inst != ospf_instance)
656 return CMD_NOT_MY_INSTANCE;
657
658 /* Check packet type. */
659 if (strmatch(packet, "hello"))
660 type = OSPF_DEBUG_HELLO;
661 else if (strmatch(packet, "dd"))
662 type = OSPF_DEBUG_DB_DESC;
663 else if (strmatch(packet, "ls-request"))
664 type = OSPF_DEBUG_LS_REQ;
665 else if (strmatch(packet, "ls-update"))
666 type = OSPF_DEBUG_LS_UPD;
667 else if (strmatch(packet, "ls-ack"))
668 type = OSPF_DEBUG_LS_ACK;
669 else if (strmatch(packet, "all"))
670 type = OSPF_DEBUG_ALL;
671
672 /* Cases:
673 * (none) = send + recv
674 * detail = send + recv + detail
675 * recv = recv
676 * send = send
677 * recv detail = recv + detail
678 * send detail = send + detail
679 */
680 if (!send && !recv) {
681 flag |= OSPF_DEBUG_SEND;
682 flag |= OSPF_DEBUG_RECV;
683 }
684
685 flag |= (send) ? OSPF_DEBUG_SEND : 0;
686 flag |= (recv) ? OSPF_DEBUG_RECV : 0;
687 flag |= (detail) ? OSPF_DEBUG_DETAIL : 0;
688
689 for (i = 0; i < 5; i++)
690 if (type & (0x01 << i)) {
691 if (vty->node == CONFIG_NODE) {
692 if (no)
693 DEBUG_PACKET_OFF(i, flag);
694 else
695 DEBUG_PACKET_ON(i, flag);
696 } else {
697 if (no)
698 TERM_DEBUG_PACKET_OFF(i, flag);
699 else
700 TERM_DEBUG_PACKET_ON(i, flag);
701 }
702 }
703
704 #ifdef DEBUG
705 /*
706 for (i = 0; i < 5; i++)
707 zlog_debug ("flag[%d] = %d", i, ospf_debug_packet[i]);
708 */
709 #endif /* DEBUG */
710
711 return CMD_SUCCESS;
712 }
713
714 DEFUN (debug_ospf_ism,
715 debug_ospf_ism_cmd,
716 "debug ospf [(1-65535)] ism [<status|events|timers>]",
717 DEBUG_STR
718 OSPF_STR
719 "Instance ID\n"
720 "OSPF Interface State Machine\n"
721 "ISM Status Information\n"
722 "ISM Event Information\n"
723 "ISM TImer Information\n")
724 {
725 int inst = (argv[2]->type == RANGE_TKN);
726 char *dbgparam = (argc == 4 + inst) ? argv[argc - 1]->text : NULL;
727
728 if (inst) // user passed instance ID
729 {
730 if (inst != ospf_instance)
731 return CMD_NOT_MY_INSTANCE;
732 }
733
734 if (vty->node == CONFIG_NODE) {
735 if (!dbgparam)
736 DEBUG_ON(ism, ISM);
737 else {
738 if (strmatch(dbgparam, "status"))
739 DEBUG_ON(ism, ISM_STATUS);
740 else if (strmatch(dbgparam, "events"))
741 DEBUG_ON(ism, ISM_EVENTS);
742 else if (strmatch(dbgparam, "timers"))
743 DEBUG_ON(ism, ISM_TIMERS);
744 }
745
746 return CMD_SUCCESS;
747 }
748
749 /* ENABLE_NODE. */
750 if (!dbgparam)
751 TERM_DEBUG_ON(ism, ISM);
752 else {
753 if (strmatch(dbgparam, "status"))
754 TERM_DEBUG_ON(ism, ISM_STATUS);
755 else if (strmatch(dbgparam, "events"))
756 TERM_DEBUG_ON(ism, ISM_EVENTS);
757 else if (strmatch(dbgparam, "timers"))
758 TERM_DEBUG_ON(ism, ISM_TIMERS);
759 }
760
761 return CMD_SUCCESS;
762 }
763
764 DEFUN (no_debug_ospf_ism,
765 no_debug_ospf_ism_cmd,
766 "no debug ospf [(1-65535)] ism [<status|events|timers>]",
767 NO_STR
768 DEBUG_STR
769 OSPF_STR
770 "Instance ID\n"
771 "OSPF Interface State Machine\n"
772 "ISM Status Information\n"
773 "ISM Event Information\n"
774 "ISM TImer Information\n")
775 {
776 int inst = (argv[3]->type == RANGE_TKN);
777 char *dbgparam = (argc == 5 + inst) ? argv[argc - 1]->text : NULL;
778
779 if (inst) // user passed instance ID
780 {
781 if (inst != ospf_instance)
782 return CMD_NOT_MY_INSTANCE;
783 }
784
785 if (vty->node == CONFIG_NODE) {
786 if (!dbgparam)
787 DEBUG_OFF(ism, ISM);
788 else {
789 if (strmatch(dbgparam, "status"))
790 DEBUG_OFF(ism, ISM_STATUS);
791 else if (strmatch(dbgparam, "events"))
792 DEBUG_OFF(ism, ISM_EVENTS);
793 else if (strmatch(dbgparam, "timers"))
794 DEBUG_OFF(ism, ISM_TIMERS);
795 }
796
797 return CMD_SUCCESS;
798 }
799
800 /* ENABLE_NODE. */
801 if (!dbgparam)
802 TERM_DEBUG_OFF(ism, ISM);
803 else {
804 if (strmatch(dbgparam, "status"))
805 TERM_DEBUG_OFF(ism, ISM_STATUS);
806 else if (strmatch(dbgparam, "events"))
807 TERM_DEBUG_OFF(ism, ISM_EVENTS);
808 else if (strmatch(dbgparam, "timers"))
809 TERM_DEBUG_OFF(ism, ISM_TIMERS);
810 }
811
812 return CMD_SUCCESS;
813 }
814
815 static int debug_ospf_nsm_common(struct vty *vty, int arg_base, int argc,
816 struct cmd_token **argv)
817 {
818 if (vty->node == CONFIG_NODE) {
819 if (argc == arg_base + 0)
820 DEBUG_ON(nsm, NSM);
821 else if (argc == arg_base + 1) {
822 if (strmatch(argv[arg_base]->text, "status"))
823 DEBUG_ON(nsm, NSM_STATUS);
824 else if (strmatch(argv[arg_base]->text, "events"))
825 DEBUG_ON(nsm, NSM_EVENTS);
826 else if (strmatch(argv[arg_base]->text, "timers"))
827 DEBUG_ON(nsm, NSM_TIMERS);
828 }
829
830 return CMD_SUCCESS;
831 }
832
833 /* ENABLE_NODE. */
834 if (argc == arg_base + 0)
835 TERM_DEBUG_ON(nsm, NSM);
836 else if (argc == arg_base + 1) {
837 if (strmatch(argv[arg_base]->text, "status"))
838 TERM_DEBUG_ON(nsm, NSM_STATUS);
839 else if (strmatch(argv[arg_base]->text, "events"))
840 TERM_DEBUG_ON(nsm, NSM_EVENTS);
841 else if (strmatch(argv[arg_base]->text, "timers"))
842 TERM_DEBUG_ON(nsm, NSM_TIMERS);
843 }
844
845 return CMD_SUCCESS;
846 }
847
848 DEFUN (debug_ospf_nsm,
849 debug_ospf_nsm_cmd,
850 "debug ospf nsm [<status|events|timers>]",
851 DEBUG_STR
852 OSPF_STR
853 "OSPF Neighbor State Machine\n"
854 "NSM Status Information\n"
855 "NSM Event Information\n"
856 "NSM Timer Information\n")
857 {
858 return debug_ospf_nsm_common(vty, 3, argc, argv);
859 }
860
861 DEFUN (debug_ospf_instance_nsm,
862 debug_ospf_instance_nsm_cmd,
863 "debug ospf (1-65535) nsm [<status|events|timers>]",
864 DEBUG_STR
865 OSPF_STR
866 "Instance ID\n"
867 "OSPF Neighbor State Machine\n"
868 "NSM Status Information\n"
869 "NSM Event Information\n"
870 "NSM Timer Information\n")
871 {
872 int idx_number = 2;
873 unsigned short instance = 0;
874
875 instance = strtoul(argv[idx_number]->arg, NULL, 10);
876 if (instance != ospf_instance)
877 return CMD_NOT_MY_INSTANCE;
878
879 return debug_ospf_nsm_common(vty, 4, argc, argv);
880 }
881
882
883 static int no_debug_ospf_nsm_common(struct vty *vty, int arg_base, int argc,
884 struct cmd_token **argv)
885 {
886 /* XXX qlyoung */
887 if (vty->node == CONFIG_NODE) {
888 if (argc == arg_base + 0)
889 DEBUG_OFF(nsm, NSM);
890 else if (argc == arg_base + 1) {
891 if (strmatch(argv[arg_base]->text, "status"))
892 DEBUG_OFF(nsm, NSM_STATUS);
893 else if (strmatch(argv[arg_base]->text, "events"))
894 DEBUG_OFF(nsm, NSM_EVENTS);
895 else if (strmatch(argv[arg_base]->text, "timers"))
896 DEBUG_OFF(nsm, NSM_TIMERS);
897 }
898
899 return CMD_SUCCESS;
900 }
901
902 /* ENABLE_NODE. */
903 if (argc == arg_base + 0)
904 TERM_DEBUG_OFF(nsm, NSM);
905 else if (argc == arg_base + 1) {
906 if (strmatch(argv[arg_base]->text, "status"))
907 TERM_DEBUG_OFF(nsm, NSM_STATUS);
908 else if (strmatch(argv[arg_base]->text, "events"))
909 TERM_DEBUG_OFF(nsm, NSM_EVENTS);
910 else if (strmatch(argv[arg_base]->text, "timers"))
911 TERM_DEBUG_OFF(nsm, NSM_TIMERS);
912 }
913
914 return CMD_SUCCESS;
915 }
916
917 DEFUN (no_debug_ospf_nsm,
918 no_debug_ospf_nsm_cmd,
919 "no debug ospf nsm [<status|events|timers>]",
920 NO_STR
921 DEBUG_STR
922 OSPF_STR
923 "OSPF Neighbor State Machine\n"
924 "NSM Status Information\n"
925 "NSM Event Information\n"
926 "NSM Timer Information\n")
927 {
928 return no_debug_ospf_nsm_common(vty, 4, argc, argv);
929 }
930
931
932 DEFUN (no_debug_ospf_instance_nsm,
933 no_debug_ospf_instance_nsm_cmd,
934 "no debug ospf (1-65535) nsm [<status|events|timers>]",
935 NO_STR
936 DEBUG_STR
937 OSPF_STR
938 "Instance ID\n"
939 "OSPF Neighbor State Machine\n"
940 "NSM Status Information\n"
941 "NSM Event Information\n"
942 "NSM Timer Information\n")
943 {
944 int idx_number = 3;
945 unsigned short instance = 0;
946
947 instance = strtoul(argv[idx_number]->arg, NULL, 10);
948 if (instance != ospf_instance)
949 return CMD_NOT_MY_INSTANCE;
950
951 return no_debug_ospf_nsm_common(vty, 5, argc, argv);
952 }
953
954
955 static int debug_ospf_lsa_common(struct vty *vty, int arg_base, int argc,
956 struct cmd_token **argv)
957 {
958 if (vty->node == CONFIG_NODE) {
959 if (argc == arg_base + 0)
960 DEBUG_ON(lsa, LSA);
961 else if (argc == arg_base + 1) {
962 if (strmatch(argv[arg_base]->text, "generate"))
963 DEBUG_ON(lsa, LSA_GENERATE);
964 else if (strmatch(argv[arg_base]->text, "flooding"))
965 DEBUG_ON(lsa, LSA_FLOODING);
966 else if (strmatch(argv[arg_base]->text, "install"))
967 DEBUG_ON(lsa, LSA_INSTALL);
968 else if (strmatch(argv[arg_base]->text, "refresh"))
969 DEBUG_ON(lsa, LSA_REFRESH);
970 else if (strmatch(argv[arg_base]->text, "aggregate"))
971 DEBUG_ON(lsa, EXTNL_LSA_AGGR);
972 }
973
974 return CMD_SUCCESS;
975 }
976
977 /* ENABLE_NODE. */
978 if (argc == arg_base + 0)
979 TERM_DEBUG_ON(lsa, LSA);
980 else if (argc == arg_base + 1) {
981 if (strmatch(argv[arg_base]->text, "generate"))
982 TERM_DEBUG_ON(lsa, LSA_GENERATE);
983 else if (strmatch(argv[arg_base]->text, "flooding"))
984 TERM_DEBUG_ON(lsa, LSA_FLOODING);
985 else if (strmatch(argv[arg_base]->text, "install"))
986 TERM_DEBUG_ON(lsa, LSA_INSTALL);
987 else if (strmatch(argv[arg_base]->text, "refresh"))
988 TERM_DEBUG_ON(lsa, LSA_REFRESH);
989 else if (strmatch(argv[arg_base]->text, "aggregate"))
990 TERM_DEBUG_ON(lsa, EXTNL_LSA_AGGR);
991 }
992
993 return CMD_SUCCESS;
994 }
995
996 DEFUN (debug_ospf_lsa,
997 debug_ospf_lsa_cmd,
998 "debug ospf lsa [<generate|flooding|install|refresh|aggregate>]",
999 DEBUG_STR
1000 OSPF_STR
1001 "OSPF Link State Advertisement\n"
1002 "LSA Generation\n"
1003 "LSA Flooding\n"
1004 "LSA Install/Delete\n"
1005 "LSA Refresh\n"
1006 "External LSA Aggregation\n")
1007 {
1008 return debug_ospf_lsa_common(vty, 3, argc, argv);
1009 }
1010
1011 DEFUN (debug_ospf_instance_lsa,
1012 debug_ospf_instance_lsa_cmd,
1013 "debug ospf (1-65535) lsa "
1014 "[<generate|flooding|install|refresh|aggregate>]",
1015 DEBUG_STR
1016 OSPF_STR
1017 "Instance ID\n"
1018 "OSPF Link State Advertisement\n"
1019 "LSA Generation\n"
1020 "LSA Flooding\n"
1021 "LSA Install/Delete\n"
1022 "LSA Refresh\n"
1023 "External LSA Aggregation\n")
1024 {
1025 int idx_number = 2;
1026 unsigned short instance = 0;
1027
1028 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1029 if (instance != ospf_instance)
1030 return CMD_NOT_MY_INSTANCE;
1031
1032 return debug_ospf_lsa_common(vty, 4, argc, argv);
1033 }
1034
1035
1036 static int no_debug_ospf_lsa_common(struct vty *vty, int arg_base, int argc,
1037 struct cmd_token **argv)
1038 {
1039 if (vty->node == CONFIG_NODE) {
1040 if (argc == arg_base + 0)
1041 DEBUG_OFF(lsa, LSA);
1042 else if (argc == arg_base + 1) {
1043 if (strmatch(argv[arg_base]->text, "generate"))
1044 DEBUG_OFF(lsa, LSA_GENERATE);
1045 else if (strmatch(argv[arg_base]->text, "flooding"))
1046 DEBUG_OFF(lsa, LSA_FLOODING);
1047 else if (strmatch(argv[arg_base]->text, "install"))
1048 DEBUG_OFF(lsa, LSA_INSTALL);
1049 else if (strmatch(argv[arg_base]->text, "refresh"))
1050 DEBUG_OFF(lsa, LSA_REFRESH);
1051 else if (strmatch(argv[arg_base]->text, "aggregate"))
1052 DEBUG_OFF(lsa, EXTNL_LSA_AGGR);
1053 }
1054
1055 return CMD_SUCCESS;
1056 }
1057
1058 /* ENABLE_NODE. */
1059 if (argc == arg_base + 0)
1060 TERM_DEBUG_OFF(lsa, LSA);
1061 else if (argc == arg_base + 1) {
1062 if (strmatch(argv[arg_base]->text, "generate"))
1063 TERM_DEBUG_OFF(lsa, LSA_GENERATE);
1064 else if (strmatch(argv[arg_base]->text, "flooding"))
1065 TERM_DEBUG_OFF(lsa, LSA_FLOODING);
1066 else if (strmatch(argv[arg_base]->text, "install"))
1067 TERM_DEBUG_OFF(lsa, LSA_INSTALL);
1068 else if (strmatch(argv[arg_base]->text, "refresh"))
1069 TERM_DEBUG_OFF(lsa, LSA_REFRESH);
1070 else if (strmatch(argv[arg_base]->text, "aggregate"))
1071 TERM_DEBUG_OFF(lsa, EXTNL_LSA_AGGR);
1072 }
1073
1074 return CMD_SUCCESS;
1075 }
1076
1077 DEFUN (no_debug_ospf_lsa,
1078 no_debug_ospf_lsa_cmd,
1079 "no debug ospf lsa [<generate|flooding|install|refresh|aggregate>]",
1080 NO_STR
1081 DEBUG_STR
1082 OSPF_STR
1083 "OSPF Link State Advertisement\n"
1084 "LSA Generation\n"
1085 "LSA Flooding\n"
1086 "LSA Install/Delete\n"
1087 "LSA Refres\n"
1088 "External LSA Aggregation\n")
1089 {
1090 return no_debug_ospf_lsa_common(vty, 4, argc, argv);
1091 }
1092
1093 DEFUN (no_debug_ospf_instance_lsa,
1094 no_debug_ospf_instance_lsa_cmd,
1095 "no debug ospf (1-65535) lsa "
1096 "[<generate|flooding|install|refresh|aggregate>]",
1097 NO_STR
1098 DEBUG_STR
1099 OSPF_STR
1100 "Instance ID\n"
1101 "OSPF Link State Advertisement\n"
1102 "LSA Generation\n"
1103 "LSA Flooding\n"
1104 "LSA Install/Delete\n"
1105 "LSA Refres\n"
1106 "External LSA Aggregation\n")
1107 {
1108 int idx_number = 3;
1109 unsigned short instance = 0;
1110
1111 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1112 if (instance != ospf_instance)
1113 return CMD_NOT_MY_INSTANCE;
1114
1115 return no_debug_ospf_lsa_common(vty, 5, argc, argv);
1116 }
1117
1118
1119 static int debug_ospf_zebra_common(struct vty *vty, int arg_base, int argc,
1120 struct cmd_token **argv)
1121 {
1122 if (vty->node == CONFIG_NODE) {
1123 if (argc == arg_base + 0)
1124 DEBUG_ON(zebra, ZEBRA);
1125 else if (argc == arg_base + 1) {
1126 if (strmatch(argv[arg_base]->text, "interface"))
1127 DEBUG_ON(zebra, ZEBRA_INTERFACE);
1128 else if (strmatch(argv[arg_base]->text, "redistribute"))
1129 DEBUG_ON(zebra, ZEBRA_REDISTRIBUTE);
1130 }
1131
1132 return CMD_SUCCESS;
1133 }
1134
1135 /* ENABLE_NODE. */
1136 if (argc == arg_base + 0)
1137 TERM_DEBUG_ON(zebra, ZEBRA);
1138 else if (argc == arg_base + 1) {
1139 if (strmatch(argv[arg_base]->text, "interface"))
1140 TERM_DEBUG_ON(zebra, ZEBRA_INTERFACE);
1141 else if (strmatch(argv[arg_base]->text, "redistribute"))
1142 TERM_DEBUG_ON(zebra, ZEBRA_REDISTRIBUTE);
1143 }
1144
1145 return CMD_SUCCESS;
1146 }
1147
1148 DEFUN (debug_ospf_zebra,
1149 debug_ospf_zebra_cmd,
1150 "debug ospf zebra [<interface|redistribute>]",
1151 DEBUG_STR
1152 OSPF_STR
1153 ZEBRA_STR
1154 "Zebra interface\n"
1155 "Zebra redistribute\n")
1156 {
1157 return debug_ospf_zebra_common(vty, 3, argc, argv);
1158 }
1159
1160 DEFUN (debug_ospf_instance_zebra,
1161 debug_ospf_instance_zebra_cmd,
1162 "debug ospf (1-65535) zebra [<interface|redistribute>]",
1163 DEBUG_STR
1164 OSPF_STR
1165 "Instance ID\n"
1166 ZEBRA_STR
1167 "Zebra interface\n"
1168 "Zebra redistribute\n")
1169 {
1170 int idx_number = 2;
1171 unsigned short instance = 0;
1172
1173 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1174 if (instance != ospf_instance)
1175 return CMD_NOT_MY_INSTANCE;
1176
1177 return debug_ospf_zebra_common(vty, 4, argc, argv);
1178 }
1179
1180
1181 static int no_debug_ospf_zebra_common(struct vty *vty, int arg_base, int argc,
1182 struct cmd_token **argv)
1183 {
1184 if (vty->node == CONFIG_NODE) {
1185 if (argc == arg_base + 0)
1186 DEBUG_OFF(zebra, ZEBRA);
1187 else if (argc == arg_base + 1) {
1188 if (strmatch(argv[arg_base]->text, "interface"))
1189 DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1190 else if (strmatch(argv[arg_base]->text, "redistribute"))
1191 DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
1192 }
1193
1194 return CMD_SUCCESS;
1195 }
1196
1197 /* ENABLE_NODE. */
1198 if (argc == arg_base + 0)
1199 TERM_DEBUG_OFF(zebra, ZEBRA);
1200 else if (argc == arg_base + 1) {
1201 if (strmatch(argv[arg_base]->text, "interface"))
1202 TERM_DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1203 else if (strmatch(argv[arg_base]->text, "redistribute"))
1204 TERM_DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
1205 }
1206
1207 return CMD_SUCCESS;
1208 }
1209
1210 DEFUN (no_debug_ospf_zebra,
1211 no_debug_ospf_zebra_cmd,
1212 "no debug ospf zebra [<interface|redistribute>]",
1213 NO_STR
1214 DEBUG_STR
1215 OSPF_STR
1216 ZEBRA_STR
1217 "Zebra interface\n"
1218 "Zebra redistribute\n")
1219 {
1220 return no_debug_ospf_zebra_common(vty, 4, argc, argv);
1221 }
1222
1223 DEFUN (no_debug_ospf_instance_zebra,
1224 no_debug_ospf_instance_zebra_cmd,
1225 "no debug ospf (1-65535) zebra [<interface|redistribute>]",
1226 NO_STR
1227 DEBUG_STR
1228 OSPF_STR
1229 "Instance ID\n"
1230 ZEBRA_STR
1231 "Zebra interface\n"
1232 "Zebra redistribute\n")
1233 {
1234 int idx_number = 3;
1235 unsigned short instance = 0;
1236
1237 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1238 if (instance != ospf_instance)
1239 return CMD_NOT_MY_INSTANCE;
1240
1241 return no_debug_ospf_zebra_common(vty, 5, argc, argv);
1242 }
1243
1244
1245 DEFUN (debug_ospf_event,
1246 debug_ospf_event_cmd,
1247 "debug ospf event",
1248 DEBUG_STR
1249 OSPF_STR
1250 "OSPF event information\n")
1251 {
1252 if (vty->node == CONFIG_NODE)
1253 CONF_DEBUG_ON(event, EVENT);
1254 TERM_DEBUG_ON(event, EVENT);
1255 return CMD_SUCCESS;
1256 }
1257
1258 DEFUN (no_debug_ospf_event,
1259 no_debug_ospf_event_cmd,
1260 "no debug ospf event",
1261 NO_STR
1262 DEBUG_STR
1263 OSPF_STR
1264 "OSPF event information\n")
1265 {
1266 if (vty->node == CONFIG_NODE)
1267 CONF_DEBUG_OFF(event, EVENT);
1268 TERM_DEBUG_OFF(event, EVENT);
1269 return CMD_SUCCESS;
1270 }
1271
1272 DEFUN (debug_ospf_instance_event,
1273 debug_ospf_instance_event_cmd,
1274 "debug ospf (1-65535) event",
1275 DEBUG_STR
1276 OSPF_STR
1277 "Instance ID\n"
1278 "OSPF event information\n")
1279 {
1280 int idx_number = 2;
1281 unsigned short instance = 0;
1282
1283 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1284 if (instance != ospf_instance)
1285 return CMD_NOT_MY_INSTANCE;
1286
1287 if (vty->node == CONFIG_NODE)
1288 CONF_DEBUG_ON(event, EVENT);
1289 TERM_DEBUG_ON(event, EVENT);
1290 return CMD_SUCCESS;
1291 }
1292
1293 DEFUN (no_debug_ospf_instance_event,
1294 no_debug_ospf_instance_event_cmd,
1295 "no debug ospf (1-65535) event",
1296 NO_STR
1297 DEBUG_STR
1298 OSPF_STR
1299 "Instance ID\n"
1300 "OSPF event information\n")
1301 {
1302 int idx_number = 3;
1303 unsigned short instance = 0;
1304
1305 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1306 if (instance != ospf_instance)
1307 return CMD_NOT_MY_INSTANCE;
1308
1309 if (vty->node == CONFIG_NODE)
1310 CONF_DEBUG_OFF(event, EVENT);
1311 TERM_DEBUG_OFF(event, EVENT);
1312 return CMD_SUCCESS;
1313 }
1314
1315 DEFUN (debug_ospf_nssa,
1316 debug_ospf_nssa_cmd,
1317 "debug ospf nssa",
1318 DEBUG_STR
1319 OSPF_STR
1320 "OSPF nssa information\n")
1321 {
1322 if (vty->node == CONFIG_NODE)
1323 CONF_DEBUG_ON(nssa, NSSA);
1324 TERM_DEBUG_ON(nssa, NSSA);
1325 return CMD_SUCCESS;
1326 }
1327
1328 DEFUN (no_debug_ospf_nssa,
1329 no_debug_ospf_nssa_cmd,
1330 "no debug ospf nssa",
1331 NO_STR
1332 DEBUG_STR
1333 OSPF_STR
1334 "OSPF nssa information\n")
1335 {
1336 if (vty->node == CONFIG_NODE)
1337 CONF_DEBUG_OFF(nssa, NSSA);
1338 TERM_DEBUG_OFF(nssa, NSSA);
1339 return CMD_SUCCESS;
1340 }
1341
1342 DEFUN (debug_ospf_instance_nssa,
1343 debug_ospf_instance_nssa_cmd,
1344 "debug ospf (1-65535) nssa",
1345 DEBUG_STR
1346 OSPF_STR
1347 "Instance ID\n"
1348 "OSPF nssa information\n")
1349 {
1350 int idx_number = 2;
1351 unsigned short instance = 0;
1352
1353 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1354 if (instance != ospf_instance)
1355 return CMD_NOT_MY_INSTANCE;
1356
1357 if (vty->node == CONFIG_NODE)
1358 CONF_DEBUG_ON(nssa, NSSA);
1359 TERM_DEBUG_ON(nssa, NSSA);
1360 return CMD_SUCCESS;
1361 }
1362
1363 DEFUN (no_debug_ospf_instance_nssa,
1364 no_debug_ospf_instance_nssa_cmd,
1365 "no debug ospf (1-65535) nssa",
1366 NO_STR
1367 DEBUG_STR
1368 OSPF_STR
1369 "Instance ID\n"
1370 "OSPF nssa information\n")
1371 {
1372 int idx_number = 3;
1373 unsigned short instance = 0;
1374
1375 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1376 if (instance != ospf_instance)
1377 return CMD_NOT_MY_INSTANCE;
1378
1379 if (vty->node == CONFIG_NODE)
1380 CONF_DEBUG_OFF(nssa, NSSA);
1381 TERM_DEBUG_OFF(nssa, NSSA);
1382 return CMD_SUCCESS;
1383 }
1384
1385 DEFPY (debug_ospf_te,
1386 debug_ospf_te_cmd,
1387 "[no$no] debug ospf [(1-65535)$instance] te",
1388 NO_STR
1389 DEBUG_STR
1390 OSPF_STR
1391 "Instance ID\n"
1392 "OSPF-TE information\n")
1393 {
1394 if (instance && instance != ospf_instance)
1395 return CMD_NOT_MY_INSTANCE;
1396
1397 if (vty->node == CONFIG_NODE) {
1398 if (no)
1399 DEBUG_OFF(te, TE);
1400 else
1401 DEBUG_ON(te, TE);
1402 } else {
1403 if (no)
1404 TERM_DEBUG_OFF(te, TE);
1405 else
1406 TERM_DEBUG_ON(te, TE);
1407 }
1408
1409 return CMD_SUCCESS;
1410 }
1411
1412 DEFPY (debug_ospf_sr,
1413 debug_ospf_sr_cmd,
1414 "[no$no] debug ospf [(1-65535)$instance] sr",
1415 NO_STR
1416 DEBUG_STR
1417 OSPF_STR
1418 "Instance ID\n"
1419 "OSPF-SR information\n")
1420 {
1421 if (instance && instance != ospf_instance)
1422 return CMD_NOT_MY_INSTANCE;
1423
1424 if (vty->node == CONFIG_NODE) {
1425 if (no)
1426 DEBUG_OFF(sr, SR);
1427 else
1428 DEBUG_ON(sr, SR);
1429 } else {
1430 if (no)
1431 TERM_DEBUG_OFF(sr, SR);
1432 else
1433 TERM_DEBUG_ON(sr, SR);
1434 }
1435
1436 return CMD_SUCCESS;
1437 }
1438
1439 DEFPY (debug_ospf_ti_lfa,
1440 debug_ospf_ti_lfa_cmd,
1441 "[no$no] debug ospf [(1-65535)$instance] ti-lfa",
1442 NO_STR
1443 DEBUG_STR
1444 OSPF_STR
1445 "Instance ID\n"
1446 "OSPF-SR TI-LFA information\n")
1447 {
1448 if (instance && instance != ospf_instance)
1449 return CMD_NOT_MY_INSTANCE;
1450
1451 if (vty->node == CONFIG_NODE) {
1452 if (no)
1453 DEBUG_OFF(ti_lfa, TI_LFA);
1454 else
1455 DEBUG_ON(ti_lfa, TI_LFA);
1456 } else {
1457 if (no)
1458 TERM_DEBUG_OFF(ti_lfa, TI_LFA);
1459 else
1460 TERM_DEBUG_ON(ti_lfa, TI_LFA);
1461 }
1462
1463 return CMD_SUCCESS;
1464 }
1465
1466 DEFPY (debug_ospf_default_info,
1467 debug_ospf_default_info_cmd,
1468 "[no$no] debug ospf [(1-65535)$instance] default-information",
1469 NO_STR
1470 DEBUG_STR
1471 OSPF_STR
1472 "Instance ID\n"
1473 "OSPF default information\n")
1474 {
1475 if (instance && instance != ospf_instance)
1476 return CMD_NOT_MY_INSTANCE;
1477
1478 if (vty->node == CONFIG_NODE) {
1479 if (no)
1480 DEBUG_OFF(defaultinfo, DEFAULTINFO);
1481 else
1482 DEBUG_ON(defaultinfo, DEFAULTINFO);
1483 } else {
1484 if (no)
1485 TERM_DEBUG_OFF(defaultinfo, DEFAULTINFO);
1486 else
1487 TERM_DEBUG_ON(defaultinfo, DEFAULTINFO);
1488 }
1489
1490 return CMD_SUCCESS;
1491 }
1492
1493 DEFPY (debug_ospf_ldp_sync,
1494 debug_ospf_ldp_sync_cmd,
1495 "[no$no] debug ospf [(1-65535)$instance] ldp-sync",
1496 NO_STR
1497 DEBUG_STR
1498 OSPF_STR
1499 "Instance ID\n"
1500 "OSPF LDP-Sync information\n")
1501 {
1502 if (instance && instance != ospf_instance)
1503 return CMD_NOT_MY_INSTANCE;
1504
1505 if (vty->node == CONFIG_NODE) {
1506 if (no)
1507 DEBUG_OFF(ldp_sync, LDP_SYNC);
1508 else
1509 DEBUG_ON(ldp_sync, LDP_SYNC);
1510 } else {
1511 if (no)
1512 TERM_DEBUG_OFF(ldp_sync, LDP_SYNC);
1513 else
1514 TERM_DEBUG_ON(ldp_sync, LDP_SYNC);
1515 }
1516
1517 return CMD_SUCCESS;
1518 }
1519
1520 DEFPY (debug_ospf_gr,
1521 debug_ospf_gr_cmd,
1522 "[no$no] debug ospf [(1-65535)$instance] graceful-restart",
1523 NO_STR
1524 DEBUG_STR
1525 OSPF_STR
1526 "Instance ID\n"
1527 "OSPF Graceful Restart\n")
1528 {
1529 if (instance && instance != ospf_instance)
1530 return CMD_NOT_MY_INSTANCE;
1531
1532 if (vty->node == CONFIG_NODE) {
1533 if (no)
1534 CONF_DEBUG_OFF(gr, GR);
1535 else
1536 CONF_DEBUG_ON(gr, GR);
1537 }
1538
1539 if (no)
1540 TERM_DEBUG_OFF(gr, GR);
1541 else
1542 TERM_DEBUG_ON(gr, GR);
1543
1544 return CMD_SUCCESS;
1545 }
1546
1547 DEFPY (debug_ospf_bfd,
1548 debug_ospf_bfd_cmd,
1549 "[no] debug ospf [(1-65535)$instance] bfd",
1550 NO_STR
1551 DEBUG_STR
1552 OSPF_STR
1553 "Instance ID\n"
1554 "Bidirection Forwarding Detection\n")
1555 {
1556 if (instance && instance != ospf_instance)
1557 return CMD_NOT_MY_INSTANCE;
1558
1559 if (vty->node == CONFIG_NODE) {
1560 if (no) {
1561 bfd_protocol_integration_set_debug(false);
1562 DEBUG_OFF(bfd, BFD_LIB);
1563 } else {
1564 bfd_protocol_integration_set_debug(true);
1565 DEBUG_ON(bfd, BFD_LIB);
1566 }
1567 } else {
1568 if (no)
1569 TERM_DEBUG_OFF(bfd, BFD_LIB);
1570 else
1571 TERM_DEBUG_ON(bfd, BFD_LIB);
1572 }
1573
1574 return CMD_SUCCESS;
1575 }
1576
1577 DEFPY (debug_ospf_client_api,
1578 debug_ospf_client_api_cmd,
1579 "[no$no] debug ospf [(1-65535)$instance] client-api",
1580 NO_STR
1581 DEBUG_STR
1582 OSPF_STR
1583 "Instance ID\n"
1584 "OSPF client API information\n")
1585 {
1586 if (instance && instance != ospf_instance)
1587 return CMD_NOT_MY_INSTANCE;
1588
1589 if (vty->node == CONFIG_NODE) {
1590 if (no)
1591 DEBUG_OFF(client_api, CLIENT_API);
1592 else
1593 DEBUG_ON(client_api, CLIENT_API);
1594 } else {
1595 if (no)
1596 TERM_DEBUG_OFF(client_api, CLIENT_API);
1597 else
1598 TERM_DEBUG_ON(client_api, CLIENT_API);
1599 }
1600
1601 return CMD_SUCCESS;
1602 }
1603
1604 DEFPY (debug_ospf_orr,
1605 debug_ospf_orr_cmd,
1606 "[no$no] debug ospf [(1-65535)$instance] orr",
1607 NO_STR
1608 DEBUG_STR
1609 OSPF_STR
1610 "Instance ID\n"
1611 "OSPF ORR information\n")
1612 {
1613 if (instance && instance != ospf_instance)
1614 return CMD_NOT_MY_INSTANCE;
1615
1616 if (vty->node == CONFIG_NODE) {
1617 if (no)
1618 DEBUG_OFF(orr, ORR);
1619 else
1620 DEBUG_ON(orr, ORR);
1621 } else {
1622 if (no)
1623 TERM_DEBUG_OFF(orr, ORR);
1624 else
1625 TERM_DEBUG_ON(orr, ORR);
1626 }
1627
1628 return CMD_SUCCESS;
1629 }
1630
1631 DEFUN (no_debug_ospf,
1632 no_debug_ospf_cmd,
1633 "no debug ospf",
1634 NO_STR
1635 DEBUG_STR
1636 OSPF_STR)
1637 {
1638 int flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
1639 int i;
1640
1641 if (vty->node == CONFIG_NODE) {
1642 CONF_DEBUG_OFF(event, EVENT);
1643 CONF_DEBUG_OFF(nssa, NSSA);
1644 DEBUG_OFF(ism, ISM_EVENTS);
1645 DEBUG_OFF(ism, ISM_STATUS);
1646 DEBUG_OFF(ism, ISM_TIMERS);
1647 DEBUG_OFF(lsa, LSA);
1648 DEBUG_OFF(lsa, LSA_FLOODING);
1649 DEBUG_OFF(lsa, LSA_GENERATE);
1650 DEBUG_OFF(lsa, LSA_INSTALL);
1651 DEBUG_OFF(lsa, LSA_REFRESH);
1652 DEBUG_OFF(nsm, NSM);
1653 DEBUG_OFF(nsm, NSM_EVENTS);
1654 DEBUG_OFF(nsm, NSM_STATUS);
1655 DEBUG_OFF(nsm, NSM_TIMERS);
1656 DEBUG_OFF(event, EVENT);
1657 DEBUG_OFF(zebra, ZEBRA);
1658 DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1659 DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
1660 DEBUG_OFF(defaultinfo, DEFAULTINFO);
1661 DEBUG_OFF(ldp_sync, LDP_SYNC);
1662 DEBUG_OFF(te, TE);
1663 DEBUG_OFF(sr, SR);
1664 DEBUG_OFF(ti_lfa, TI_LFA);
1665 DEBUG_OFF(client_api, CLIENT_API);
1666
1667 /* BFD debugging is two parts: OSPF and library. */
1668 DEBUG_OFF(bfd, BFD_LIB);
1669 bfd_protocol_integration_set_debug(false);
1670
1671 for (i = 0; i < 5; i++)
1672 DEBUG_PACKET_OFF(i, flag);
1673
1674 DEBUG_OFF(orr, ORR);
1675 }
1676
1677 for (i = 0; i < 5; i++)
1678 TERM_DEBUG_PACKET_OFF(i, flag);
1679
1680 TERM_DEBUG_OFF(event, EVENT);
1681 TERM_DEBUG_OFF(ism, ISM);
1682 TERM_DEBUG_OFF(ism, ISM_EVENTS);
1683 TERM_DEBUG_OFF(ism, ISM_STATUS);
1684 TERM_DEBUG_OFF(ism, ISM_TIMERS);
1685 TERM_DEBUG_OFF(lsa, LSA);
1686 TERM_DEBUG_OFF(lsa, LSA_FLOODING);
1687 TERM_DEBUG_OFF(lsa, LSA_GENERATE);
1688 TERM_DEBUG_OFF(lsa, LSA_INSTALL);
1689 TERM_DEBUG_OFF(lsa, LSA_REFRESH);
1690 TERM_DEBUG_OFF(nsm, NSM);
1691 TERM_DEBUG_OFF(nsm, NSM_EVENTS);
1692 TERM_DEBUG_OFF(nsm, NSM_STATUS);
1693 TERM_DEBUG_OFF(nsm, NSM_TIMERS);
1694 TERM_DEBUG_OFF(nssa, NSSA);
1695 TERM_DEBUG_OFF(zebra, ZEBRA);
1696 TERM_DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1697 TERM_DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
1698 TERM_DEBUG_OFF(defaultinfo, DEFAULTINFO);
1699 TERM_DEBUG_OFF(ldp_sync, LDP_SYNC);
1700 TERM_DEBUG_OFF(te, TE);
1701 TERM_DEBUG_OFF(sr, SR);
1702 TERM_DEBUG_OFF(ti_lfa, TI_LFA);
1703 TERM_DEBUG_OFF(bfd, BFD_LIB);
1704 TERM_DEBUG_OFF(client_api, CLIENT_API);
1705 TERM_DEBUG_OFF(orr, ORR);
1706
1707 return CMD_SUCCESS;
1708 }
1709
1710 static int show_debugging_ospf_common(struct vty *vty)
1711 {
1712 int i;
1713
1714 if (ospf_instance)
1715 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf_instance);
1716
1717 vty_out(vty, "OSPF debugging status:\n");
1718
1719 /* Show debug status for events. */
1720 if (IS_DEBUG_OSPF(event, EVENT))
1721 vty_out(vty, " OSPF event debugging is on\n");
1722
1723 /* Show debug status for ISM. */
1724 if (IS_DEBUG_OSPF(ism, ISM) == OSPF_DEBUG_ISM)
1725 vty_out(vty, " OSPF ISM debugging is on\n");
1726 else {
1727 if (IS_DEBUG_OSPF(ism, ISM_STATUS))
1728 vty_out(vty, " OSPF ISM status debugging is on\n");
1729 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
1730 vty_out(vty, " OSPF ISM event debugging is on\n");
1731 if (IS_DEBUG_OSPF(ism, ISM_TIMERS))
1732 vty_out(vty, " OSPF ISM timer debugging is on\n");
1733 }
1734
1735 /* Show debug status for NSM. */
1736 if (IS_DEBUG_OSPF(nsm, NSM) == OSPF_DEBUG_NSM)
1737 vty_out(vty, " OSPF NSM debugging is on\n");
1738 else {
1739 if (IS_DEBUG_OSPF(nsm, NSM_STATUS))
1740 vty_out(vty, " OSPF NSM status debugging is on\n");
1741 if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
1742 vty_out(vty, " OSPF NSM event debugging is on\n");
1743 if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
1744 vty_out(vty, " OSPF NSM timer debugging is on\n");
1745 }
1746
1747 /* Show debug status for OSPF Packets. */
1748 for (i = 0; i < 5; i++)
1749 if (IS_DEBUG_OSPF_PACKET(i, SEND)
1750 && IS_DEBUG_OSPF_PACKET(i, RECV)) {
1751 vty_out(vty, " OSPF packet %s%s debugging is on\n",
1752 lookup_msg(ospf_packet_type_str, i + 1, NULL),
1753 IS_DEBUG_OSPF_PACKET(i, DETAIL) ? " detail"
1754 : "");
1755 } else {
1756 if (IS_DEBUG_OSPF_PACKET(i, SEND))
1757 vty_out(vty,
1758 " OSPF packet %s send%s debugging is on\n",
1759 lookup_msg(ospf_packet_type_str, i + 1,
1760 NULL),
1761 IS_DEBUG_OSPF_PACKET(i, DETAIL)
1762 ? " detail"
1763 : "");
1764 if (IS_DEBUG_OSPF_PACKET(i, RECV))
1765 vty_out(vty,
1766 " OSPF packet %s receive%s debugging is on\n",
1767 lookup_msg(ospf_packet_type_str, i + 1,
1768 NULL),
1769 IS_DEBUG_OSPF_PACKET(i, DETAIL)
1770 ? " detail"
1771 : "");
1772 }
1773
1774 /* Show debug status for OSPF LSAs. */
1775 if (IS_DEBUG_OSPF(lsa, LSA) == OSPF_DEBUG_LSA)
1776 vty_out(vty, " OSPF LSA debugging is on\n");
1777 else {
1778 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1779 vty_out(vty, " OSPF LSA generation debugging is on\n");
1780 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
1781 vty_out(vty, " OSPF LSA flooding debugging is on\n");
1782 if (IS_DEBUG_OSPF(lsa, LSA_INSTALL))
1783 vty_out(vty, " OSPF LSA install debugging is on\n");
1784 if (IS_DEBUG_OSPF(lsa, LSA_REFRESH))
1785 vty_out(vty, " OSPF LSA refresh debugging is on\n");
1786 }
1787
1788 /* Show debug status for Zebra. */
1789 if (IS_DEBUG_OSPF(zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1790 vty_out(vty, " OSPF Zebra debugging is on\n");
1791 else {
1792 if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
1793 vty_out(vty,
1794 " OSPF Zebra interface debugging is on\n");
1795 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
1796 vty_out(vty,
1797 " OSPF Zebra redistribute debugging is on\n");
1798 }
1799
1800 if (IS_DEBUG_OSPF(defaultinfo, DEFAULTINFO) == OSPF_DEBUG_DEFAULTINFO)
1801 vty_out(vty, " OSPF default information is on\n");
1802
1803 /* Show debug status for NSSA. */
1804 if (IS_DEBUG_OSPF(nssa, NSSA) == OSPF_DEBUG_NSSA)
1805 vty_out(vty, " OSPF NSSA debugging is on\n");
1806
1807 /* Show debug status for LDP-SYNC. */
1808 if (IS_DEBUG_OSPF(ldp_sync, LDP_SYNC) == OSPF_DEBUG_LDP_SYNC)
1809 vty_out(vty, " OSPF ldp-sync debugging is on\n");
1810
1811 /* Show debug status for GR. */
1812 if (IS_DEBUG_OSPF(gr, GR) == OSPF_DEBUG_GR)
1813 vty_out(vty, " OSPF Graceful Restart debugging is on\n");
1814
1815 /* Show debug status for TE */
1816 if (IS_DEBUG_OSPF(te, TE) == OSPF_DEBUG_TE)
1817 vty_out(vty, " OSPF TE debugging is on\n");
1818
1819 /* Show debug status for SR */
1820 if (IS_DEBUG_OSPF(sr, SR) == OSPF_DEBUG_SR)
1821 vty_out(vty, " OSPF SR debugging is on\n");
1822
1823 /* Show debug status for TI-LFA */
1824 if (IS_DEBUG_OSPF(ti_lfa, TI_LFA) == OSPF_DEBUG_TI_LFA)
1825 vty_out(vty, " OSPF TI-LFA debugging is on\n");
1826
1827 if (IS_DEBUG_OSPF(bfd, BFD_LIB) == OSPF_DEBUG_BFD_LIB)
1828 vty_out(vty,
1829 " OSPF BFD integration library debugging is on\n");
1830
1831 /* Show debug status for LDP-SYNC. */
1832 if (IS_DEBUG_OSPF(client_api, CLIENT_API) == OSPF_DEBUG_CLIENT_API)
1833 vty_out(vty, " OSPF client-api debugging is on\n");
1834
1835 /* Show debug status for ORR. */
1836 if (IS_DEBUG_OSPF(orr, ORR) == OSPF_DEBUG_ORR)
1837 vty_out(vty, " OSPF ORR debugging is on\n");
1838
1839 vty_out(vty, "\n");
1840
1841 return CMD_SUCCESS;
1842 }
1843
1844 DEFUN_NOSH (show_debugging_ospf,
1845 show_debugging_ospf_cmd,
1846 "show debugging [ospf]",
1847 SHOW_STR
1848 DEBUG_STR
1849 OSPF_STR)
1850 {
1851 show_debugging_ospf_common(vty);
1852
1853 cmd_show_lib_debugs(vty);
1854
1855 return CMD_SUCCESS;
1856 }
1857
1858 DEFUN_NOSH (show_debugging_ospf_instance,
1859 show_debugging_ospf_instance_cmd,
1860 "show debugging ospf (1-65535)",
1861 SHOW_STR
1862 DEBUG_STR
1863 OSPF_STR
1864 "Instance ID\n")
1865 {
1866 int idx_number = 3;
1867 unsigned short instance = 0;
1868
1869 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1870 if (instance != ospf_instance)
1871 return CMD_NOT_MY_INSTANCE;
1872
1873 show_debugging_ospf_common(vty);
1874
1875 cmd_show_lib_debugs(vty);
1876
1877 return CMD_SUCCESS;
1878 }
1879
1880 static int config_write_debug(struct vty *vty);
1881 /* Debug node. */
1882 static struct cmd_node debug_node = {
1883 .name = "debug",
1884 .node = DEBUG_NODE,
1885 .prompt = "",
1886 .config_write = config_write_debug,
1887 };
1888
1889 static int config_write_debug(struct vty *vty)
1890 {
1891 int write = 0;
1892 int i, r;
1893
1894 const char *type_str[] = {"hello", "dd", "ls-request", "ls-update",
1895 "ls-ack"};
1896 const char *detail_str[] = {
1897 "", " send", " recv", "",
1898 " detail", " send detail", " recv detail", " detail"};
1899
1900 char str[16];
1901 memset(str, 0, 16);
1902
1903 if (ospf_instance)
1904 snprintf(str, sizeof(str), " %u", ospf_instance);
1905
1906 /* debug ospf ism (status|events|timers). */
1907 if (IS_CONF_DEBUG_OSPF(ism, ISM) == OSPF_DEBUG_ISM)
1908 vty_out(vty, "debug ospf%s ism\n", str);
1909 else {
1910 if (IS_CONF_DEBUG_OSPF(ism, ISM_STATUS))
1911 vty_out(vty, "debug ospf%s ism status\n", str);
1912 if (IS_CONF_DEBUG_OSPF(ism, ISM_EVENTS))
1913 vty_out(vty, "debug ospf%s ism event\n", str);
1914 if (IS_CONF_DEBUG_OSPF(ism, ISM_TIMERS))
1915 vty_out(vty, "debug ospf%s ism timer\n", str);
1916 }
1917
1918 /* debug ospf nsm (status|events|timers). */
1919 if (IS_CONF_DEBUG_OSPF(nsm, NSM) == OSPF_DEBUG_NSM)
1920 vty_out(vty, "debug ospf%s nsm\n", str);
1921 else {
1922 if (IS_CONF_DEBUG_OSPF(nsm, NSM_STATUS))
1923 vty_out(vty, "debug ospf%s nsm status\n", str);
1924 if (IS_CONF_DEBUG_OSPF(nsm, NSM_EVENTS))
1925 vty_out(vty, "debug ospf%s nsm event\n", str);
1926 if (IS_CONF_DEBUG_OSPF(nsm, NSM_TIMERS))
1927 vty_out(vty, "debug ospf%s nsm timer\n", str);
1928 }
1929
1930 /* debug ospf lsa (generate|flooding|install|refresh). */
1931 if (IS_CONF_DEBUG_OSPF(lsa, LSA) == OSPF_DEBUG_LSA)
1932 vty_out(vty, "debug ospf%s lsa\n", str);
1933 else {
1934 if (IS_CONF_DEBUG_OSPF(lsa, LSA_GENERATE))
1935 vty_out(vty, "debug ospf%s lsa generate\n", str);
1936 if (IS_CONF_DEBUG_OSPF(lsa, LSA_FLOODING))
1937 vty_out(vty, "debug ospf%s lsa flooding\n", str);
1938 if (IS_CONF_DEBUG_OSPF(lsa, LSA_INSTALL))
1939 vty_out(vty, "debug ospf%s lsa install\n", str);
1940 if (IS_CONF_DEBUG_OSPF(lsa, LSA_REFRESH))
1941 vty_out(vty, "debug ospf%s lsa refresh\n", str);
1942
1943 write = 1;
1944 }
1945
1946 /* debug ospf zebra (interface|redistribute). */
1947 if (IS_CONF_DEBUG_OSPF(zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1948 vty_out(vty, "debug ospf%s zebra\n", str);
1949 else {
1950 if (IS_CONF_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
1951 vty_out(vty, "debug ospf%s zebra interface\n", str);
1952 if (IS_CONF_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
1953 vty_out(vty, "debug ospf%s zebra redistribute\n", str);
1954
1955 write = 1;
1956 }
1957
1958 /* debug ospf event. */
1959 if (IS_CONF_DEBUG_OSPF(event, EVENT) == OSPF_DEBUG_EVENT) {
1960 vty_out(vty, "debug ospf%s event\n", str);
1961 write = 1;
1962 }
1963
1964 /* debug ospf nssa. */
1965 if (IS_CONF_DEBUG_OSPF(nssa, NSSA) == OSPF_DEBUG_NSSA) {
1966 vty_out(vty, "debug ospf%s nssa\n", str);
1967 write = 1;
1968 }
1969
1970 /* debug ospf packet all detail. */
1971 r = OSPF_DEBUG_SEND_RECV | OSPF_DEBUG_DETAIL;
1972 for (i = 0; i < 5; i++)
1973 r &= conf_debug_ospf_packet[i]
1974 & (OSPF_DEBUG_SEND_RECV | OSPF_DEBUG_DETAIL);
1975 if (r == (OSPF_DEBUG_SEND_RECV | OSPF_DEBUG_DETAIL)) {
1976 vty_out(vty, "debug ospf%s packet all detail\n", str);
1977 write = 1;
1978 }
1979
1980 /* debug ospf packet all. */
1981 r = OSPF_DEBUG_SEND_RECV;
1982 for (i = 0; i < 5; i++)
1983 r &= conf_debug_ospf_packet[i] & OSPF_DEBUG_SEND_RECV;
1984 if (r == OSPF_DEBUG_SEND_RECV) {
1985 vty_out(vty, "debug ospf%s packet all\n", str);
1986 for (i = 0; i < 5; i++)
1987 if (conf_debug_ospf_packet[i] & OSPF_DEBUG_DETAIL)
1988 vty_out(vty, "debug ospf%s packet %s detail\n",
1989 str, type_str[i]);
1990 write = 1;
1991 }
1992
1993 /* debug ospf packet (hello|dd|ls-request|ls-update|ls-ack)
1994 (send|recv) (detail). */
1995 for (i = 0; i < 5; i++) {
1996 if (conf_debug_ospf_packet[i] == 0)
1997 continue;
1998
1999 vty_out(vty, "debug ospf%s packet %s%s\n", str, type_str[i],
2000 detail_str[conf_debug_ospf_packet[i]]);
2001 write = 1;
2002 }
2003
2004 /* debug ospf te */
2005 if (IS_CONF_DEBUG_OSPF(te, TE) == OSPF_DEBUG_TE) {
2006 vty_out(vty, "debug ospf%s te\n", str);
2007 write = 1;
2008 }
2009
2010 /* debug ospf sr */
2011 if (IS_CONF_DEBUG_OSPF(sr, SR) == OSPF_DEBUG_SR) {
2012 vty_out(vty, "debug ospf%s sr\n", str);
2013 write = 1;
2014 }
2015
2016 /* debug ospf sr ti-lfa */
2017 if (IS_CONF_DEBUG_OSPF(ti_lfa, TI_LFA) == OSPF_DEBUG_TI_LFA) {
2018 vty_out(vty, "debug ospf%s ti-lfa\n", str);
2019 write = 1;
2020 }
2021
2022 /* debug ospf ldp-sync */
2023 if (IS_CONF_DEBUG_OSPF(ldp_sync, LDP_SYNC) == OSPF_DEBUG_LDP_SYNC) {
2024 vty_out(vty, "debug ospf%s ldp-sync\n", str);
2025 write = 1;
2026 }
2027
2028 /* debug ospf gr */
2029 if (IS_CONF_DEBUG_OSPF(gr, GR) == OSPF_DEBUG_GR) {
2030 vty_out(vty, "debug ospf%s graceful-restart\n", str);
2031 write = 1;
2032 }
2033
2034 if (IS_CONF_DEBUG_OSPF(bfd, BFD_LIB) == OSPF_DEBUG_BFD_LIB) {
2035 vty_out(vty, "debug ospf%s bfd\n", str);
2036 write = 1;
2037 }
2038
2039 /* debug ospf client-api */
2040 if (IS_CONF_DEBUG_OSPF(client_api, CLIENT_API) ==
2041 OSPF_DEBUG_CLIENT_API) {
2042 vty_out(vty, "debug ospf%s client-api\n", str);
2043 write = 1;
2044 }
2045
2046 /* debug ospf default-information */
2047 if (IS_CONF_DEBUG_OSPF(defaultinfo, DEFAULTINFO) ==
2048 OSPF_DEBUG_DEFAULTINFO) {
2049 vty_out(vty, "debug ospf%s default-information\n", str);
2050 write = 1;
2051 }
2052
2053 /* debug ospf orr */
2054 if (IS_CONF_DEBUG_OSPF(orr, ORR) == OSPF_DEBUG_ORR) {
2055 vty_out(vty, "debug ospf%s orr\n", str);
2056 write = 1;
2057 }
2058
2059 return write;
2060 }
2061
2062 /* Initialize debug commands. */
2063 void ospf_debug_init(void)
2064 {
2065 install_node(&debug_node);
2066
2067 install_element(ENABLE_NODE, &show_debugging_ospf_cmd);
2068 install_element(ENABLE_NODE, &debug_ospf_ism_cmd);
2069 install_element(ENABLE_NODE, &debug_ospf_nsm_cmd);
2070 install_element(ENABLE_NODE, &debug_ospf_lsa_cmd);
2071 install_element(ENABLE_NODE, &debug_ospf_zebra_cmd);
2072 install_element(ENABLE_NODE, &debug_ospf_event_cmd);
2073 install_element(ENABLE_NODE, &debug_ospf_nssa_cmd);
2074 install_element(ENABLE_NODE, &debug_ospf_te_cmd);
2075 install_element(ENABLE_NODE, &debug_ospf_sr_cmd);
2076 install_element(ENABLE_NODE, &debug_ospf_ti_lfa_cmd);
2077 install_element(ENABLE_NODE, &debug_ospf_default_info_cmd);
2078 install_element(ENABLE_NODE, &debug_ospf_ldp_sync_cmd);
2079 install_element(ENABLE_NODE, &debug_ospf_client_api_cmd);
2080 install_element(ENABLE_NODE, &debug_ospf_orr_cmd);
2081 install_element(ENABLE_NODE, &no_debug_ospf_ism_cmd);
2082 install_element(ENABLE_NODE, &no_debug_ospf_nsm_cmd);
2083 install_element(ENABLE_NODE, &no_debug_ospf_lsa_cmd);
2084 install_element(ENABLE_NODE, &no_debug_ospf_zebra_cmd);
2085 install_element(ENABLE_NODE, &no_debug_ospf_event_cmd);
2086 install_element(ENABLE_NODE, &no_debug_ospf_nssa_cmd);
2087 install_element(ENABLE_NODE, &debug_ospf_gr_cmd);
2088 install_element(ENABLE_NODE, &debug_ospf_bfd_cmd);
2089
2090 install_element(ENABLE_NODE, &show_debugging_ospf_instance_cmd);
2091 install_element(ENABLE_NODE, &debug_ospf_packet_cmd);
2092
2093 install_element(ENABLE_NODE, &debug_ospf_instance_nsm_cmd);
2094 install_element(ENABLE_NODE, &debug_ospf_instance_lsa_cmd);
2095 install_element(ENABLE_NODE, &debug_ospf_instance_zebra_cmd);
2096 install_element(ENABLE_NODE, &debug_ospf_instance_event_cmd);
2097 install_element(ENABLE_NODE, &debug_ospf_instance_nssa_cmd);
2098 install_element(ENABLE_NODE, &no_debug_ospf_instance_nsm_cmd);
2099 install_element(ENABLE_NODE, &no_debug_ospf_instance_lsa_cmd);
2100 install_element(ENABLE_NODE, &no_debug_ospf_instance_zebra_cmd);
2101 install_element(ENABLE_NODE, &no_debug_ospf_instance_event_cmd);
2102 install_element(ENABLE_NODE, &no_debug_ospf_instance_nssa_cmd);
2103 install_element(ENABLE_NODE, &no_debug_ospf_cmd);
2104
2105 install_element(CONFIG_NODE, &debug_ospf_packet_cmd);
2106 install_element(CONFIG_NODE, &debug_ospf_ism_cmd);
2107 install_element(CONFIG_NODE, &no_debug_ospf_ism_cmd);
2108
2109 install_element(CONFIG_NODE, &debug_ospf_nsm_cmd);
2110 install_element(CONFIG_NODE, &debug_ospf_lsa_cmd);
2111 install_element(CONFIG_NODE, &debug_ospf_zebra_cmd);
2112 install_element(CONFIG_NODE, &debug_ospf_event_cmd);
2113 install_element(CONFIG_NODE, &debug_ospf_nssa_cmd);
2114 install_element(CONFIG_NODE, &debug_ospf_te_cmd);
2115 install_element(CONFIG_NODE, &debug_ospf_sr_cmd);
2116 install_element(CONFIG_NODE, &debug_ospf_ti_lfa_cmd);
2117 install_element(CONFIG_NODE, &debug_ospf_default_info_cmd);
2118 install_element(CONFIG_NODE, &debug_ospf_ldp_sync_cmd);
2119 install_element(CONFIG_NODE, &debug_ospf_client_api_cmd);
2120 install_element(CONFIG_NODE, &debug_ospf_orr_cmd);
2121 install_element(CONFIG_NODE, &no_debug_ospf_nsm_cmd);
2122 install_element(CONFIG_NODE, &no_debug_ospf_lsa_cmd);
2123 install_element(CONFIG_NODE, &no_debug_ospf_zebra_cmd);
2124 install_element(CONFIG_NODE, &no_debug_ospf_event_cmd);
2125 install_element(CONFIG_NODE, &no_debug_ospf_nssa_cmd);
2126 install_element(CONFIG_NODE, &debug_ospf_gr_cmd);
2127 install_element(CONFIG_NODE, &debug_ospf_bfd_cmd);
2128
2129 install_element(CONFIG_NODE, &debug_ospf_instance_nsm_cmd);
2130 install_element(CONFIG_NODE, &debug_ospf_instance_lsa_cmd);
2131 install_element(CONFIG_NODE, &debug_ospf_instance_zebra_cmd);
2132 install_element(CONFIG_NODE, &debug_ospf_instance_event_cmd);
2133 install_element(CONFIG_NODE, &debug_ospf_instance_nssa_cmd);
2134 install_element(CONFIG_NODE, &no_debug_ospf_instance_nsm_cmd);
2135 install_element(CONFIG_NODE, &no_debug_ospf_instance_lsa_cmd);
2136 install_element(CONFIG_NODE, &no_debug_ospf_instance_zebra_cmd);
2137 install_element(CONFIG_NODE, &no_debug_ospf_instance_event_cmd);
2138 install_element(CONFIG_NODE, &no_debug_ospf_instance_nssa_cmd);
2139 install_element(CONFIG_NODE, &no_debug_ospf_cmd);
2140 }