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