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