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