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