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