]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_dump.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[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
6b333611 504/* Expects header to be in host order */
d62a17ae 505void ospf_ip_header_dump(struct ip *iph)
718e3744 506{
d62a17ae 507 /* IP Header dump. */
508 zlog_debug("ip_v %d", iph->ip_v);
509 zlog_debug("ip_hl %d", iph->ip_hl);
510 zlog_debug("ip_tos %d", iph->ip_tos);
511 zlog_debug("ip_len %d", iph->ip_len);
d7c0a89a
QY
512 zlog_debug("ip_id %u", (uint32_t)iph->ip_id);
513 zlog_debug("ip_off %u", (uint32_t)iph->ip_off);
d62a17ae 514 zlog_debug("ip_ttl %d", iph->ip_ttl);
515 zlog_debug("ip_p %d", iph->ip_p);
d7c0a89a 516 zlog_debug("ip_sum 0x%x", (uint32_t)iph->ip_sum);
d62a17ae 517 zlog_debug("ip_src %s", inet_ntoa(iph->ip_src));
518 zlog_debug("ip_dst %s", inet_ntoa(iph->ip_dst));
718e3744 519}
520
d62a17ae 521static void ospf_header_dump(struct ospf_header *ospfh)
718e3744 522{
d62a17ae 523 char buf[9];
d7c0a89a 524 uint16_t auth_type = ntohs(ospfh->auth_type);
d62a17ae 525
526 zlog_debug("Header");
527 zlog_debug(" Version %d", ospfh->version);
528 zlog_debug(" Type %d (%s)", ospfh->type,
529 lookup_msg(ospf_packet_type_str, ospfh->type, NULL));
530 zlog_debug(" Packet Len %d", ntohs(ospfh->length));
531 zlog_debug(" Router ID %s", inet_ntoa(ospfh->router_id));
532 zlog_debug(" Area ID %s", inet_ntoa(ospfh->area_id));
533 zlog_debug(" Checksum 0x%x", ntohs(ospfh->checksum));
534 zlog_debug(" AuType %s",
535 lookup_msg(ospf_auth_type_str, auth_type, NULL));
536
537 switch (auth_type) {
538 case OSPF_AUTH_NULL:
539 break;
540 case OSPF_AUTH_SIMPLE:
541 memset(buf, 0, 9);
542 strncpy(buf, (char *)ospfh->u.auth_data, 8);
543 zlog_debug(" Simple Password %s", buf);
544 break;
545 case OSPF_AUTH_CRYPTOGRAPHIC:
546 zlog_debug(" Cryptographic Authentication");
547 zlog_debug(" Key ID %d", ospfh->u.crypt.key_id);
548 zlog_debug(" Auth Data Len %d", ospfh->u.crypt.auth_data_len);
549 zlog_debug(" Sequence number %ld",
d7c0a89a 550 (unsigned long)ntohl(ospfh->u.crypt.crypt_seqnum));
d62a17ae 551 break;
552 default:
553 zlog_debug("* This is not supported authentication type");
554 break;
555 }
718e3744 556}
557
d62a17ae 558void ospf_packet_dump(struct stream *s)
718e3744 559{
d62a17ae 560 struct ospf_header *ospfh;
561 unsigned long gp;
562
563 /* Preserve pointer. */
564 gp = stream_get_getp(s);
565
566 /* OSPF Header dump. */
2d34fb80 567 ospfh = (struct ospf_header *)stream_pnt(s);
d62a17ae 568
569 /* Until detail flag is set, return. */
570 if (!(term_debug_ospf_packet[ospfh->type - 1] & OSPF_DEBUG_DETAIL))
571 return;
572
573 /* Show OSPF header detail. */
574 ospf_header_dump(ospfh);
575 stream_forward_getp(s, OSPF_HEADER_SIZE);
576
577 switch (ospfh->type) {
578 case OSPF_MSG_HELLO:
579 ospf_packet_hello_dump(s, ntohs(ospfh->length));
580 break;
581 case OSPF_MSG_DB_DESC:
582 ospf_packet_db_desc_dump(s, ntohs(ospfh->length));
583 break;
584 case OSPF_MSG_LS_REQ:
585 ospf_packet_ls_req_dump(s, ntohs(ospfh->length));
586 break;
587 case OSPF_MSG_LS_UPD:
588 ospf_packet_ls_upd_dump(s, ntohs(ospfh->length));
589 break;
590 case OSPF_MSG_LS_ACK:
591 ospf_packet_ls_ack_dump(s, ntohs(ospfh->length));
592 break;
593 default:
594 break;
595 }
596
597 stream_set_getp(s, gp);
718e3744 598}
599
692b4c65
QY
600DEFUN (debug_ospf_packet,
601 debug_ospf_packet_cmd,
602 "debug ospf [(1-65535)] packet <hello|dd|ls-request|ls-update|ls-ack|all> [<send [detail]|recv [detail]|detail>]",
603 DEBUG_STR
604 OSPF_STR
605 "Instance ID\n"
606 "OSPF packets\n"
607 "OSPF Hello\n"
608 "OSPF Database Description\n"
609 "OSPF Link State Request\n"
610 "OSPF Link State Update\n"
611 "OSPF Link State Acknowledgment\n"
612 "OSPF all packets\n"
613 "Packet sent\n"
614 "Detail Information\n"
615 "Packet received\n"
616 "Detail Information\n"
617 "Detail Information\n")
618{
d62a17ae 619 int inst = (argv[2]->type == RANGE_TKN) ? 1 : 0;
620 int detail = strmatch(argv[argc - 1]->text, "detail");
621 int send = strmatch(argv[argc - (1 + detail)]->text, "send");
622 int recv = strmatch(argv[argc - (1 + detail)]->text, "recv");
623 char *packet = argv[3 + inst]->text;
718e3744 624
d62a17ae 625 if (inst) // user passed instance ID
626 {
627 if (!ospf_lookup_instance(strtoul(argv[2]->arg, NULL, 10)))
ac28e4ec 628 return CMD_NOT_MY_INSTANCE;
d62a17ae 629 }
630
631 int type = 0;
632 int flag = 0;
633 int i;
634
635 /* Check packet type. */
636 if (strmatch(packet, "hello"))
637 type = OSPF_DEBUG_HELLO;
638 else if (strmatch(packet, "dd"))
639 type = OSPF_DEBUG_DB_DESC;
640 else if (strmatch(packet, "ls-request"))
641 type = OSPF_DEBUG_LS_REQ;
642 else if (strmatch(packet, "ls-update"))
643 type = OSPF_DEBUG_LS_UPD;
644 else if (strmatch(packet, "ls-ack"))
645 type = OSPF_DEBUG_LS_ACK;
646 else if (strmatch(packet, "all"))
647 type = OSPF_DEBUG_ALL;
648
649 /* Cases:
650 * (none) = send + recv
651 * detail = send + recv + detail
652 * recv = recv
653 * send = send
654 * recv detail = recv + detail
655 * send detail = send + detail
656 */
657 if (!send && !recv)
658 send = recv = 1;
659
660 flag |= (send) ? OSPF_DEBUG_SEND : 0;
661 flag |= (recv) ? OSPF_DEBUG_RECV : 0;
662 flag |= (detail) ? OSPF_DEBUG_DETAIL : 0;
663
664 for (i = 0; i < 5; i++)
665 if (type & (0x01 << i)) {
666 if (vty->node == CONFIG_NODE)
667 DEBUG_PACKET_ON(i, flag);
668 else
669 TERM_DEBUG_PACKET_ON(i, flag);
670 }
671
672 return CMD_SUCCESS;
718e3744 673}
674
692b4c65
QY
675DEFUN (no_debug_ospf_packet,
676 no_debug_ospf_packet_cmd,
677 "no debug ospf [(1-65535)] packet <hello|dd|ls-request|ls-update|ls-ack|all> [<send [detail]|recv [detail]|detail>]",
678 NO_STR
718e3744 679 DEBUG_STR
680 OSPF_STR
7c8ff89e 681 "Instance ID\n"
718e3744 682 "OSPF packets\n"
683 "OSPF Hello\n"
684 "OSPF Database Description\n"
685 "OSPF Link State Request\n"
686 "OSPF Link State Update\n"
687 "OSPF Link State Acknowledgment\n"
692b4c65
QY
688 "OSPF all packets\n"
689 "Packet sent\n"
690 "Detail Information\n"
691 "Packet received\n"
692 "Detail Information\n"
693 "Detail Information\n")
694{
d62a17ae 695 int inst = (argv[3]->type == RANGE_TKN) ? 1 : 0;
696 int detail = strmatch(argv[argc - 1]->text, "detail");
697 int send = strmatch(argv[argc - (1 + detail)]->text, "send");
698 int recv = strmatch(argv[argc - (1 + detail)]->text, "recv");
699 char *packet = argv[4 + inst]->text;
700
701 if (inst) // user passed instance ID
702 {
703 if (!ospf_lookup_instance(strtoul(argv[3]->arg, NULL, 10)))
ac28e4ec 704 return CMD_NOT_MY_INSTANCE;
d62a17ae 705 }
706
707 int type = 0;
708 int flag = 0;
709 int i;
710
711 /* Check packet type. */
712 if (strmatch(packet, "hello"))
713 type = OSPF_DEBUG_HELLO;
714 else if (strmatch(packet, "dd"))
715 type = OSPF_DEBUG_DB_DESC;
716 else if (strmatch(packet, "ls-request"))
717 type = OSPF_DEBUG_LS_REQ;
718 else if (strmatch(packet, "ls-update"))
719 type = OSPF_DEBUG_LS_UPD;
720 else if (strmatch(packet, "ls-ack"))
721 type = OSPF_DEBUG_LS_ACK;
722 else if (strmatch(packet, "all"))
723 type = OSPF_DEBUG_ALL;
724
725 /* Cases:
726 * (none) = send + recv
727 * detail = send + recv + detail
728 * recv = recv
729 * send = send
730 * recv detail = recv + detail
731 * send detail = send + detail
732 */
733 if (!send && !recv)
734 send = recv = 1;
735
736 flag |= (send) ? OSPF_DEBUG_SEND : 0;
737 flag |= (recv) ? OSPF_DEBUG_RECV : 0;
738 flag |= (detail) ? OSPF_DEBUG_DETAIL : 0;
739
740 for (i = 0; i < 5; i++)
741 if (type & (0x01 << i)) {
742 if (vty->node == CONFIG_NODE)
743 DEBUG_PACKET_OFF(i, flag);
744 else
745 TERM_DEBUG_PACKET_OFF(i, flag);
746 }
718e3744 747
748#ifdef DEBUG
d62a17ae 749/*
750for (i = 0; i < 5; i++)
751 zlog_debug ("flag[%d] = %d", i, ospf_debug_packet[i]);
752*/
718e3744 753#endif /* DEBUG */
754
d62a17ae 755 return CMD_SUCCESS;
718e3744 756}
757
692b4c65
QY
758DEFUN (debug_ospf_ism,
759 debug_ospf_ism_cmd,
760 "debug ospf [(1-65535)] ism [<status|events|timers>]",
718e3744 761 DEBUG_STR
762 OSPF_STR
7c8ff89e 763 "Instance ID\n"
692b4c65
QY
764 "OSPF Interface State Machine\n"
765 "ISM Status Information\n"
766 "ISM Event Information\n"
767 "ISM TImer Information\n")
7c8ff89e 768{
d62a17ae 769 int inst = (argv[2]->type == RANGE_TKN);
770 char *dbgparam = (argc == 4 + inst) ? argv[argc - 1]->text : NULL;
771
772 if (inst) // user passed instance ID
718e3744 773 {
d62a17ae 774 if (!ospf_lookup_instance(strtoul(argv[2]->arg, NULL, 10)))
ac28e4ec 775 return CMD_NOT_MY_INSTANCE;
718e3744 776 }
777
d62a17ae 778 if (vty->node == CONFIG_NODE) {
779 if (!dbgparam)
780 DEBUG_ON(ism, ISM);
781 else {
782 if (strmatch(dbgparam, "status"))
783 DEBUG_ON(ism, ISM_STATUS);
784 else if (strmatch(dbgparam, "events"))
785 DEBUG_ON(ism, ISM_EVENTS);
786 else if (strmatch(dbgparam, "timers"))
787 DEBUG_ON(ism, ISM_TIMERS);
788 }
789
790 return CMD_SUCCESS;
791 }
792
793 /* ENABLE_NODE. */
794 if (!dbgparam)
795 TERM_DEBUG_ON(ism, ISM);
796 else {
797 if (strmatch(dbgparam, "status"))
798 TERM_DEBUG_ON(ism, ISM_STATUS);
799 else if (strmatch(dbgparam, "events"))
800 TERM_DEBUG_ON(ism, ISM_EVENTS);
801 else if (strmatch(dbgparam, "timers"))
802 TERM_DEBUG_ON(ism, ISM_TIMERS);
803 }
804
805 return CMD_SUCCESS;
718e3744 806}
807
692b4c65
QY
808DEFUN (no_debug_ospf_ism,
809 no_debug_ospf_ism_cmd,
810 "no debug ospf [(1-65535)] ism [<status|events|timers>]",
16cedbb0 811 NO_STR
718e3744 812 DEBUG_STR
813 OSPF_STR
7c8ff89e 814 "Instance ID\n"
692b4c65
QY
815 "OSPF Interface State Machine\n"
816 "ISM Status Information\n"
817 "ISM Event Information\n"
818 "ISM TImer Information\n")
7c8ff89e 819{
d62a17ae 820 int inst = (argv[3]->type == RANGE_TKN);
821 char *dbgparam = (argc == 5 + inst) ? argv[argc - 1]->text : NULL;
822
823 if (inst) // user passed instance ID
718e3744 824 {
d62a17ae 825 if (!ospf_lookup_instance(strtoul(argv[3]->arg, NULL, 10)))
ac28e4ec 826 return CMD_NOT_MY_INSTANCE;
d62a17ae 827 }
828
829 if (vty->node == CONFIG_NODE) {
830 if (!dbgparam)
831 DEBUG_OFF(ism, ISM);
832 else {
833 if (strmatch(dbgparam, "status"))
834 DEBUG_OFF(ism, ISM_STATUS);
835 else if (strmatch(dbgparam, "events"))
836 DEBUG_OFF(ism, ISM_EVENTS);
837 else if (strmatch(dbgparam, "timers"))
838 DEBUG_OFF(ism, ISM_TIMERS);
839 }
840
841 return CMD_SUCCESS;
842 }
843
844 /* ENABLE_NODE. */
845 if (!dbgparam)
846 TERM_DEBUG_OFF(ism, ISM);
847 else {
848 if (strmatch(dbgparam, "status"))
849 TERM_DEBUG_OFF(ism, ISM_STATUS);
850 else if (strmatch(dbgparam, "events"))
851 TERM_DEBUG_OFF(ism, ISM_EVENTS);
852 else if (strmatch(dbgparam, "timers"))
853 TERM_DEBUG_OFF(ism, ISM_TIMERS);
718e3744 854 }
692b4c65 855
d62a17ae 856 return CMD_SUCCESS;
718e3744 857}
858
d62a17ae 859static int debug_ospf_nsm_common(struct vty *vty, int arg_base, int argc,
860 struct cmd_token **argv)
718e3744 861{
d62a17ae 862 if (vty->node == CONFIG_NODE) {
863 if (argc == arg_base + 0)
864 DEBUG_ON(nsm, NSM);
865 else if (argc == arg_base + 1) {
866 if (strmatch(argv[arg_base]->text, "status"))
867 DEBUG_ON(nsm, NSM_STATUS);
868 else if (strmatch(argv[arg_base]->text, "events"))
869 DEBUG_ON(nsm, NSM_EVENTS);
870 else if (strmatch(argv[arg_base]->text, "timers"))
871 DEBUG_ON(nsm, NSM_TIMERS);
872 }
873
874 return CMD_SUCCESS;
875 }
876
877 /* ENABLE_NODE. */
878 if (argc == arg_base + 0)
879 TERM_DEBUG_ON(nsm, NSM);
880 else if (argc == arg_base + 1) {
881 if (strmatch(argv[arg_base]->text, "status"))
882 TERM_DEBUG_ON(nsm, NSM_STATUS);
883 else if (strmatch(argv[arg_base]->text, "events"))
884 TERM_DEBUG_ON(nsm, NSM_EVENTS);
885 else if (strmatch(argv[arg_base]->text, "timers"))
886 TERM_DEBUG_ON(nsm, NSM_TIMERS);
718e3744 887 }
888
d62a17ae 889 return CMD_SUCCESS;
718e3744 890}
891
7c8ff89e
DS
892DEFUN (debug_ospf_nsm,
893 debug_ospf_nsm_cmd,
6de69f83 894 "debug ospf nsm [<status|events|timers>]",
7c8ff89e
DS
895 DEBUG_STR
896 OSPF_STR
1d68dbfe
DW
897 "OSPF Neighbor State Machine\n"
898 "NSM Status Information\n"
899 "NSM Event Information\n"
900 "NSM Timer Information\n")
7c8ff89e 901{
d62a17ae 902 return debug_ospf_nsm_common(vty, 3, argc, argv);
7c8ff89e
DS
903}
904
7c8ff89e
DS
905DEFUN (debug_ospf_instance_nsm,
906 debug_ospf_instance_nsm_cmd,
6de69f83 907 "debug ospf (1-65535) nsm [<status|events|timers>]",
718e3744 908 DEBUG_STR
909 OSPF_STR
7c8ff89e 910 "Instance ID\n"
1d68dbfe
DW
911 "OSPF Neighbor State Machine\n"
912 "NSM Status Information\n"
913 "NSM Event Information\n"
914 "NSM Timer Information\n")
7c8ff89e 915{
d62a17ae 916 int idx_number = 2;
d7c0a89a 917 unsigned short instance = 0;
7c8ff89e 918
d62a17ae 919 instance = strtoul(argv[idx_number]->arg, NULL, 10);
920 if (!ospf_lookup_instance(instance))
921 return CMD_SUCCESS;
7c8ff89e 922
d62a17ae 923 return debug_ospf_nsm_common(vty, 4, argc, argv);
7c8ff89e
DS
924}
925
7c8ff89e 926
d62a17ae 927static int no_debug_ospf_nsm_common(struct vty *vty, int arg_base, int argc,
928 struct cmd_token **argv)
718e3744 929{
d62a17ae 930 /* XXX qlyoung */
931 if (vty->node == CONFIG_NODE) {
932 if (argc == arg_base + 0)
933 DEBUG_OFF(nsm, NSM);
934 else if (argc == arg_base + 1) {
935 if (strmatch(argv[arg_base]->text, "status"))
936 DEBUG_OFF(nsm, NSM_STATUS);
937 else if (strmatch(argv[arg_base]->text, "events"))
938 DEBUG_OFF(nsm, NSM_EVENTS);
939 else if (strmatch(argv[arg_base]->text, "timers"))
940 DEBUG_OFF(nsm, NSM_TIMERS);
941 }
942
943 return CMD_SUCCESS;
944 }
945
946 /* ENABLE_NODE. */
947 if (argc == arg_base + 0)
948 TERM_DEBUG_OFF(nsm, NSM);
949 else if (argc == arg_base + 1) {
950 if (strmatch(argv[arg_base]->text, "status"))
951 TERM_DEBUG_OFF(nsm, NSM_STATUS);
952 else if (strmatch(argv[arg_base]->text, "events"))
953 TERM_DEBUG_OFF(nsm, NSM_EVENTS);
954 else if (strmatch(argv[arg_base]->text, "timers"))
955 TERM_DEBUG_OFF(nsm, NSM_TIMERS);
718e3744 956 }
957
d62a17ae 958 return CMD_SUCCESS;
718e3744 959}
960
7c8ff89e
DS
961DEFUN (no_debug_ospf_nsm,
962 no_debug_ospf_nsm_cmd,
6de69f83 963 "no debug ospf nsm [<status|events|timers>]",
7c8ff89e
DS
964 NO_STR
965 DEBUG_STR
966 OSPF_STR
16cedbb0 967 "OSPF Neighbor State Machine\n"
1d68dbfe
DW
968 "NSM Status Information\n"
969 "NSM Event Information\n"
970 "NSM Timer Information\n")
7c8ff89e 971{
d62a17ae 972 return no_debug_ospf_nsm_common(vty, 4, argc, argv);
7c8ff89e
DS
973}
974
718e3744 975
7c8ff89e
DS
976DEFUN (no_debug_ospf_instance_nsm,
977 no_debug_ospf_instance_nsm_cmd,
6de69f83 978 "no debug ospf (1-65535) nsm [<status|events|timers>]",
7c8ff89e 979 NO_STR
718e3744 980 DEBUG_STR
981 OSPF_STR
7c8ff89e 982 "Instance ID\n"
16cedbb0 983 "OSPF Neighbor State Machine\n"
1d68dbfe
DW
984 "NSM Status Information\n"
985 "NSM Event Information\n"
986 "NSM Timer Information\n")
7c8ff89e 987{
d62a17ae 988 int idx_number = 3;
d7c0a89a 989 unsigned short instance = 0;
7c8ff89e 990
d62a17ae 991 instance = strtoul(argv[idx_number]->arg, NULL, 10);
992 if (!ospf_lookup_instance(instance))
ac28e4ec 993 return CMD_NOT_MY_INSTANCE;
7c8ff89e 994
d62a17ae 995 return no_debug_ospf_nsm_common(vty, 5, argc, argv);
7c8ff89e
DS
996}
997
7c8ff89e 998
d62a17ae 999static int debug_ospf_lsa_common(struct vty *vty, int arg_base, int argc,
1000 struct cmd_token **argv)
718e3744 1001{
d62a17ae 1002 if (vty->node == CONFIG_NODE) {
1003 if (argc == arg_base + 0)
1004 DEBUG_ON(lsa, LSA);
1005 else if (argc == arg_base + 1) {
1006 if (strmatch(argv[arg_base]->text, "generate"))
1007 DEBUG_ON(lsa, LSA_GENERATE);
1008 else if (strmatch(argv[arg_base]->text, "flooding"))
1009 DEBUG_ON(lsa, LSA_FLOODING);
1010 else if (strmatch(argv[arg_base]->text, "install"))
1011 DEBUG_ON(lsa, LSA_INSTALL);
1012 else if (strmatch(argv[arg_base]->text, "refresh"))
1013 DEBUG_ON(lsa, LSA_REFRESH);
1014 }
1015
1016 return CMD_SUCCESS;
718e3744 1017 }
1018
d62a17ae 1019 /* ENABLE_NODE. */
1020 if (argc == arg_base + 0)
1021 TERM_DEBUG_ON(lsa, LSA);
1022 else if (argc == arg_base + 1) {
1023 if (strmatch(argv[arg_base]->text, "generate"))
1024 TERM_DEBUG_ON(lsa, LSA_GENERATE);
1025 else if (strmatch(argv[arg_base]->text, "flooding"))
1026 TERM_DEBUG_ON(lsa, LSA_FLOODING);
1027 else if (strmatch(argv[arg_base]->text, "install"))
1028 TERM_DEBUG_ON(lsa, LSA_INSTALL);
1029 else if (strmatch(argv[arg_base]->text, "refresh"))
1030 TERM_DEBUG_ON(lsa, LSA_REFRESH);
1031 }
1032
1033 return CMD_SUCCESS;
718e3744 1034}
1035
7c8ff89e
DS
1036DEFUN (debug_ospf_lsa,
1037 debug_ospf_lsa_cmd,
6de69f83 1038 "debug ospf lsa [<generate|flooding|install|refresh>]",
7c8ff89e
DS
1039 DEBUG_STR
1040 OSPF_STR
1d68dbfe
DW
1041 "OSPF Link State Advertisement\n"
1042 "LSA Generation\n"
1043 "LSA Flooding\n"
1044 "LSA Install/Delete\n"
1045 "LSA Refresh\n")
7c8ff89e 1046{
d62a17ae 1047 return debug_ospf_lsa_common(vty, 3, argc, argv);
7c8ff89e
DS
1048}
1049
7c8ff89e
DS
1050DEFUN (debug_ospf_instance_lsa,
1051 debug_ospf_instance_lsa_cmd,
6de69f83 1052 "debug ospf (1-65535) lsa [<generate|flooding|install|refresh>]",
718e3744 1053 DEBUG_STR
1054 OSPF_STR
7c8ff89e 1055 "Instance ID\n"
1d68dbfe
DW
1056 "OSPF Link State Advertisement\n"
1057 "LSA Generation\n"
1058 "LSA Flooding\n"
1059 "LSA Install/Delete\n"
1060 "LSA Refresh\n")
7c8ff89e 1061{
d62a17ae 1062 int idx_number = 2;
d7c0a89a 1063 unsigned short instance = 0;
7c8ff89e 1064
d62a17ae 1065 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1066 if (!ospf_lookup_instance(instance))
ac28e4ec 1067 return CMD_NOT_MY_INSTANCE;
7c8ff89e 1068
d62a17ae 1069 return debug_ospf_lsa_common(vty, 4, argc, argv);
7c8ff89e
DS
1070}
1071
7c8ff89e 1072
d62a17ae 1073static int no_debug_ospf_lsa_common(struct vty *vty, int arg_base, int argc,
1074 struct cmd_token **argv)
718e3744 1075{
d62a17ae 1076 if (vty->node == CONFIG_NODE) {
1077 if (argc == arg_base + 0)
1078 DEBUG_OFF(lsa, LSA);
1079 else if (argc == arg_base + 1) {
1080 if (strmatch(argv[arg_base]->text, "generate"))
1081 DEBUG_OFF(lsa, LSA_GENERATE);
1082 else if (strmatch(argv[arg_base]->text, "flooding"))
1083 DEBUG_OFF(lsa, LSA_FLOODING);
1084 else if (strmatch(argv[arg_base]->text, "install"))
1085 DEBUG_OFF(lsa, LSA_INSTALL);
1086 else if (strmatch(argv[arg_base]->text, "refresh"))
1087 DEBUG_OFF(lsa, LSA_REFRESH);
1088 }
1089
1090 return CMD_SUCCESS;
1091 }
1092
1093 /* ENABLE_NODE. */
1094 if (argc == arg_base + 0)
1095 TERM_DEBUG_OFF(lsa, LSA);
1096 else if (argc == arg_base + 1) {
1097 if (strmatch(argv[arg_base]->text, "generate"))
1098 TERM_DEBUG_OFF(lsa, LSA_GENERATE);
1099 else if (strmatch(argv[arg_base]->text, "flooding"))
1100 TERM_DEBUG_OFF(lsa, LSA_FLOODING);
1101 else if (strmatch(argv[arg_base]->text, "install"))
1102 TERM_DEBUG_OFF(lsa, LSA_INSTALL);
1103 else if (strmatch(argv[arg_base]->text, "refresh"))
1104 TERM_DEBUG_OFF(lsa, LSA_REFRESH);
718e3744 1105 }
1106
d62a17ae 1107 return CMD_SUCCESS;
718e3744 1108}
1109
7c8ff89e
DS
1110DEFUN (no_debug_ospf_lsa,
1111 no_debug_ospf_lsa_cmd,
6de69f83 1112 "no debug ospf lsa [<generate|flooding|install|refresh>]",
7c8ff89e
DS
1113 NO_STR
1114 DEBUG_STR
1115 OSPF_STR
1d68dbfe
DW
1116 "OSPF Link State Advertisement\n"
1117 "LSA Generation\n"
1118 "LSA Flooding\n"
1119 "LSA Install/Delete\n"
1120 "LSA Refres\n")
7c8ff89e 1121{
d62a17ae 1122 return no_debug_ospf_lsa_common(vty, 4, argc, argv);
7c8ff89e
DS
1123}
1124
7c8ff89e
DS
1125DEFUN (no_debug_ospf_instance_lsa,
1126 no_debug_ospf_instance_lsa_cmd,
6de69f83 1127 "no debug ospf (1-65535) lsa [<generate|flooding|install|refresh>]",
7c8ff89e
DS
1128 NO_STR
1129 DEBUG_STR
1130 OSPF_STR
1131 "Instance ID\n"
1d68dbfe
DW
1132 "OSPF Link State Advertisement\n"
1133 "LSA Generation\n"
1134 "LSA Flooding\n"
1135 "LSA Install/Delete\n"
1136 "LSA Refres\n")
7c8ff89e 1137{
d62a17ae 1138 int idx_number = 3;
d7c0a89a 1139 unsigned short instance = 0;
7c8ff89e 1140
d62a17ae 1141 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1142 if (!ospf_lookup_instance(instance))
ac28e4ec 1143 return CMD_NOT_MY_INSTANCE;
6b0655a2 1144
d62a17ae 1145 return no_debug_ospf_lsa_common(vty, 5, argc, argv);
7c8ff89e
DS
1146}
1147
7c8ff89e 1148
d62a17ae 1149static int debug_ospf_zebra_common(struct vty *vty, int arg_base, int argc,
1150 struct cmd_token **argv)
718e3744 1151{
d62a17ae 1152 if (vty->node == CONFIG_NODE) {
1153 if (argc == arg_base + 0)
1154 DEBUG_ON(zebra, ZEBRA);
1155 else if (argc == arg_base + 1) {
1156 if (strmatch(argv[arg_base]->text, "interface"))
1157 DEBUG_ON(zebra, ZEBRA_INTERFACE);
1158 else if (strmatch(argv[arg_base]->text, "redistribute"))
1159 DEBUG_ON(zebra, ZEBRA_REDISTRIBUTE);
1160 }
1161
1162 return CMD_SUCCESS;
1163 }
1164
1165 /* ENABLE_NODE. */
1166 if (argc == arg_base + 0)
1167 TERM_DEBUG_ON(zebra, ZEBRA);
1168 else if (argc == arg_base + 1) {
1169 if (strmatch(argv[arg_base]->text, "interface"))
1170 TERM_DEBUG_ON(zebra, ZEBRA_INTERFACE);
1171 else if (strmatch(argv[arg_base]->text, "redistribute"))
1172 TERM_DEBUG_ON(zebra, ZEBRA_REDISTRIBUTE);
718e3744 1173 }
1174
d62a17ae 1175 return CMD_SUCCESS;
718e3744 1176}
1177
7c8ff89e
DS
1178DEFUN (debug_ospf_zebra,
1179 debug_ospf_zebra_cmd,
6de69f83 1180 "debug ospf zebra [<interface|redistribute>]",
7c8ff89e
DS
1181 DEBUG_STR
1182 OSPF_STR
41e7fb80 1183 ZEBRA_STR
1d68dbfe
DW
1184 "Zebra interface\n"
1185 "Zebra redistribute\n")
7c8ff89e 1186{
d62a17ae 1187 return debug_ospf_zebra_common(vty, 3, argc, argv);
7c8ff89e
DS
1188}
1189
7c8ff89e
DS
1190DEFUN (debug_ospf_instance_zebra,
1191 debug_ospf_instance_zebra_cmd,
6de69f83 1192 "debug ospf (1-65535) zebra [<interface|redistribute>]",
718e3744 1193 DEBUG_STR
1194 OSPF_STR
7c8ff89e 1195 "Instance ID\n"
41e7fb80 1196 ZEBRA_STR
1d68dbfe
DW
1197 "Zebra interface\n"
1198 "Zebra redistribute\n")
7c8ff89e 1199{
d62a17ae 1200 int idx_number = 2;
d7c0a89a 1201 unsigned short instance = 0;
7c8ff89e 1202
d62a17ae 1203 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1204 if (!ospf_lookup_instance(instance))
ac28e4ec 1205 return CMD_NOT_MY_INSTANCE;
7c8ff89e 1206
d62a17ae 1207 return debug_ospf_zebra_common(vty, 4, argc, argv);
7c8ff89e
DS
1208}
1209
7c8ff89e 1210
d62a17ae 1211static int no_debug_ospf_zebra_common(struct vty *vty, int arg_base, int argc,
1212 struct cmd_token **argv)
718e3744 1213{
d62a17ae 1214 if (vty->node == CONFIG_NODE) {
1215 if (argc == arg_base + 0)
1216 DEBUG_OFF(zebra, ZEBRA);
1217 else if (argc == arg_base + 1) {
1218 if (strmatch(argv[arg_base]->text, "interface"))
1219 DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1220 else if (strmatch(argv[arg_base]->text, "redistribute"))
1221 DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
1222 }
1223
1224 return CMD_SUCCESS;
1225 }
1226
1227 /* ENABLE_NODE. */
1228 if (argc == arg_base + 0)
1229 TERM_DEBUG_OFF(zebra, ZEBRA);
1230 else if (argc == arg_base + 1) {
1231 if (strmatch(argv[arg_base]->text, "interface"))
1232 TERM_DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1233 else if (strmatch(argv[arg_base]->text, "redistribute"))
1234 TERM_DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
718e3744 1235 }
1236
d62a17ae 1237 return CMD_SUCCESS;
718e3744 1238}
1239
7c8ff89e
DS
1240DEFUN (no_debug_ospf_zebra,
1241 no_debug_ospf_zebra_cmd,
6de69f83 1242 "no debug ospf zebra [<interface|redistribute>]",
7c8ff89e
DS
1243 NO_STR
1244 DEBUG_STR
1245 OSPF_STR
41e7fb80 1246 ZEBRA_STR
1d68dbfe
DW
1247 "Zebra interface\n"
1248 "Zebra redistribute\n")
7c8ff89e 1249{
d62a17ae 1250 return no_debug_ospf_zebra_common(vty, 4, argc, argv);
7c8ff89e
DS
1251}
1252
7c8ff89e
DS
1253DEFUN (no_debug_ospf_instance_zebra,
1254 no_debug_ospf_instance_zebra_cmd,
6de69f83 1255 "no debug ospf (1-65535) zebra [<interface|redistribute>]",
7c8ff89e
DS
1256 NO_STR
1257 DEBUG_STR
1258 OSPF_STR
1259 "Instance ID\n"
41e7fb80 1260 ZEBRA_STR
1d68dbfe
DW
1261 "Zebra interface\n"
1262 "Zebra redistribute\n")
7c8ff89e 1263{
d62a17ae 1264 int idx_number = 3;
d7c0a89a 1265 unsigned short instance = 0;
7c8ff89e 1266
d62a17ae 1267 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1268 if (!ospf_lookup_instance(instance))
1269 return CMD_SUCCESS;
7c8ff89e 1270
d62a17ae 1271 return no_debug_ospf_zebra_common(vty, 5, argc, argv);
7c8ff89e
DS
1272}
1273
7c8ff89e 1274
718e3744 1275DEFUN (debug_ospf_event,
1276 debug_ospf_event_cmd,
1277 "debug ospf event",
1278 DEBUG_STR
1279 OSPF_STR
1280 "OSPF event information\n")
1281{
d62a17ae 1282 if (vty->node == CONFIG_NODE)
1283 CONF_DEBUG_ON(event, EVENT);
1284 TERM_DEBUG_ON(event, EVENT);
1285 return CMD_SUCCESS;
718e3744 1286}
1287
1288DEFUN (no_debug_ospf_event,
1289 no_debug_ospf_event_cmd,
1290 "no debug ospf event",
1291 NO_STR
1292 DEBUG_STR
1293 OSPF_STR
1294 "OSPF event information\n")
1295{
d62a17ae 1296 if (vty->node == CONFIG_NODE)
1297 CONF_DEBUG_OFF(event, EVENT);
1298 TERM_DEBUG_OFF(event, EVENT);
1299 return CMD_SUCCESS;
718e3744 1300}
1301
7c8ff89e
DS
1302DEFUN (debug_ospf_instance_event,
1303 debug_ospf_instance_event_cmd,
6147e2c6 1304 "debug ospf (1-65535) event",
7c8ff89e
DS
1305 DEBUG_STR
1306 OSPF_STR
1307 "Instance ID\n"
1308 "OSPF event information\n")
1309{
d62a17ae 1310 int idx_number = 2;
d7c0a89a 1311 unsigned short instance = 0;
7c8ff89e 1312
d62a17ae 1313 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1314 if (!ospf_lookup_instance(instance))
1315 return CMD_SUCCESS;
7c8ff89e 1316
d62a17ae 1317 if (vty->node == CONFIG_NODE)
1318 CONF_DEBUG_ON(event, EVENT);
1319 TERM_DEBUG_ON(event, EVENT);
1320 return CMD_SUCCESS;
7c8ff89e
DS
1321}
1322
1323DEFUN (no_debug_ospf_instance_event,
1324 no_debug_ospf_instance_event_cmd,
6147e2c6 1325 "no debug ospf (1-65535) event",
7c8ff89e
DS
1326 NO_STR
1327 DEBUG_STR
1328 OSPF_STR
1329 "Instance ID\n"
1330 "OSPF event information\n")
1331{
d62a17ae 1332 int idx_number = 3;
d7c0a89a 1333 unsigned short instance = 0;
7c8ff89e 1334
d62a17ae 1335 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1336 if (!ospf_lookup_instance(instance))
1337 return CMD_SUCCESS;
7c8ff89e 1338
d62a17ae 1339 if (vty->node == CONFIG_NODE)
1340 CONF_DEBUG_OFF(event, EVENT);
1341 TERM_DEBUG_OFF(event, EVENT);
1342 return CMD_SUCCESS;
7c8ff89e
DS
1343}
1344
718e3744 1345DEFUN (debug_ospf_nssa,
1346 debug_ospf_nssa_cmd,
1347 "debug ospf nssa",
1348 DEBUG_STR
1349 OSPF_STR
1350 "OSPF nssa information\n")
1351{
d62a17ae 1352 if (vty->node == CONFIG_NODE)
1353 CONF_DEBUG_ON(nssa, NSSA);
1354 TERM_DEBUG_ON(nssa, NSSA);
1355 return CMD_SUCCESS;
718e3744 1356}
1357
1358DEFUN (no_debug_ospf_nssa,
1359 no_debug_ospf_nssa_cmd,
1360 "no debug ospf nssa",
1361 NO_STR
1362 DEBUG_STR
1363 OSPF_STR
1364 "OSPF nssa information\n")
1365{
d62a17ae 1366 if (vty->node == CONFIG_NODE)
1367 CONF_DEBUG_OFF(nssa, NSSA);
1368 TERM_DEBUG_OFF(nssa, NSSA);
1369 return CMD_SUCCESS;
718e3744 1370}
1371
7c8ff89e
DS
1372DEFUN (debug_ospf_instance_nssa,
1373 debug_ospf_instance_nssa_cmd,
6147e2c6 1374 "debug ospf (1-65535) nssa",
7c8ff89e
DS
1375 DEBUG_STR
1376 OSPF_STR
1377 "Instance ID\n"
1378 "OSPF nssa information\n")
1379{
d62a17ae 1380 int idx_number = 2;
d7c0a89a 1381 unsigned short instance = 0;
7c8ff89e 1382
d62a17ae 1383 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1384 if (!ospf_lookup_instance(instance))
1385 return CMD_SUCCESS;
6b0655a2 1386
d62a17ae 1387 if (vty->node == CONFIG_NODE)
1388 CONF_DEBUG_ON(nssa, NSSA);
1389 TERM_DEBUG_ON(nssa, NSSA);
1390 return CMD_SUCCESS;
7c8ff89e
DS
1391}
1392
1393DEFUN (no_debug_ospf_instance_nssa,
1394 no_debug_ospf_instance_nssa_cmd,
6147e2c6 1395 "no debug ospf (1-65535) nssa",
7c8ff89e 1396 NO_STR
718e3744 1397 DEBUG_STR
7c8ff89e
DS
1398 OSPF_STR
1399 "Instance ID\n"
1400 "OSPF nssa information\n")
1401{
d62a17ae 1402 int idx_number = 3;
d7c0a89a 1403 unsigned short instance = 0;
7c8ff89e 1404
d62a17ae 1405 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1406 if (!ospf_lookup_instance(instance))
1407 return CMD_SUCCESS;
7c8ff89e 1408
d62a17ae 1409 if (vty->node == CONFIG_NODE)
1410 CONF_DEBUG_OFF(nssa, NSSA);
1411 TERM_DEBUG_OFF(nssa, NSSA);
1412 return CMD_SUCCESS;
7c8ff89e
DS
1413}
1414
16f1b9ee
OD
1415DEFUN (debug_ospf_te,
1416 debug_ospf_te_cmd,
1417 "debug ospf te",
1418 DEBUG_STR
1419 OSPF_STR
1420 "OSPF-TE information\n")
1421{
d62a17ae 1422 if (vty->node == CONFIG_NODE)
1423 CONF_DEBUG_ON(te, TE);
1424 TERM_DEBUG_ON(te, TE);
1425 return CMD_SUCCESS;
16f1b9ee
OD
1426}
1427
1428DEFUN (no_debug_ospf_te,
1429 no_debug_ospf_te_cmd,
1430 "no debug ospf te",
1431 NO_STR
1432 DEBUG_STR
1433 OSPF_STR
1434 "OSPF-TE information\n")
1435{
d62a17ae 1436 if (vty->node == CONFIG_NODE)
1437 CONF_DEBUG_OFF(te, TE);
1438 TERM_DEBUG_OFF(te, TE);
1439 return CMD_SUCCESS;
16f1b9ee
OD
1440}
1441
cf9b9f77
OD
1442DEFUN (debug_ospf_sr,
1443 debug_ospf_sr_cmd,
1444 "debug ospf sr",
1445 DEBUG_STR
1446 OSPF_STR
1447 "OSPF-SR information\n")
1448{
1449 if (vty->node == CONFIG_NODE)
1450 CONF_DEBUG_ON(sr, SR);
1451 TERM_DEBUG_ON(sr, SR);
1452 return CMD_SUCCESS;
1453}
1454
1455DEFUN (no_debug_ospf_sr,
1456 no_debug_ospf_sr_cmd,
1457 "no debug ospf sr",
1458 NO_STR
1459 DEBUG_STR
1460 OSPF_STR
1461 "OSPF-SR information\n")
1462{
1463 if (vty->node == CONFIG_NODE)
1464 CONF_DEBUG_OFF(sr, SR);
1465 TERM_DEBUG_OFF(sr, SR);
1466 return CMD_SUCCESS;
1467}
1468
4dfd8aff
DW
1469DEFUN (no_debug_ospf,
1470 no_debug_ospf_cmd,
1471 "no debug ospf",
1472 NO_STR
1473 DEBUG_STR
1474 OSPF_STR)
1475{
d62a17ae 1476 int flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
1477 int i;
1478
1479 if (vty->node == CONFIG_NODE) {
1480 CONF_DEBUG_OFF(event, EVENT);
1481 CONF_DEBUG_OFF(nssa, NSSA);
1482 DEBUG_OFF(ism, ISM_EVENTS);
1483 DEBUG_OFF(ism, ISM_STATUS);
1484 DEBUG_OFF(ism, ISM_TIMERS);
1485 DEBUG_OFF(lsa, LSA);
1486 DEBUG_OFF(lsa, LSA_FLOODING);
1487 DEBUG_OFF(lsa, LSA_GENERATE);
1488 DEBUG_OFF(lsa, LSA_INSTALL);
1489 DEBUG_OFF(lsa, LSA_REFRESH);
1490 DEBUG_OFF(nsm, NSM);
1491 DEBUG_OFF(nsm, NSM_EVENTS);
1492 DEBUG_OFF(nsm, NSM_STATUS);
1493 DEBUG_OFF(nsm, NSM_TIMERS);
1494 DEBUG_OFF(zebra, ZEBRA);
1495 DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1496 DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
1497
1498 for (i = 0; i < 5; i++)
1499 DEBUG_PACKET_OFF(i, flag);
1500 }
1501
1502 for (i = 0; i < 5; i++)
1503 TERM_DEBUG_PACKET_OFF(i, flag);
1504
1505 TERM_DEBUG_OFF(event, EVENT);
1506 TERM_DEBUG_OFF(ism, ISM);
1507 TERM_DEBUG_OFF(ism, ISM_EVENTS);
1508 TERM_DEBUG_OFF(ism, ISM_STATUS);
1509 TERM_DEBUG_OFF(ism, ISM_TIMERS);
1510 TERM_DEBUG_OFF(lsa, LSA);
1511 TERM_DEBUG_OFF(lsa, LSA_FLOODING);
1512 TERM_DEBUG_OFF(lsa, LSA_GENERATE);
1513 TERM_DEBUG_OFF(lsa, LSA_INSTALL);
1514 TERM_DEBUG_OFF(lsa, LSA_REFRESH);
1515 TERM_DEBUG_OFF(nsm, NSM);
1516 TERM_DEBUG_OFF(nsm, NSM_EVENTS);
1517 TERM_DEBUG_OFF(nsm, NSM_STATUS);
1518 TERM_DEBUG_OFF(nsm, NSM_TIMERS);
1519 TERM_DEBUG_OFF(nssa, NSSA);
1520 TERM_DEBUG_OFF(zebra, ZEBRA);
1521 TERM_DEBUG_OFF(zebra, ZEBRA_INTERFACE);
1522 TERM_DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
1523
1524 return CMD_SUCCESS;
4dfd8aff 1525}
7c8ff89e 1526
d62a17ae 1527static int show_debugging_ospf_common(struct vty *vty, struct ospf *ospf)
718e3744 1528{
d62a17ae 1529 int i;
1530
1531 if (ospf->instance)
1532 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
1533
1534 vty_out(vty, "OSPF debugging status:\n");
1535
1536 /* Show debug status for events. */
1537 if (IS_DEBUG_OSPF(event, EVENT))
1538 vty_out(vty, " OSPF event debugging is on\n");
1539
1540 /* Show debug status for ISM. */
1541 if (IS_DEBUG_OSPF(ism, ISM) == OSPF_DEBUG_ISM)
1542 vty_out(vty, " OSPF ISM debugging is on\n");
1543 else {
1544 if (IS_DEBUG_OSPF(ism, ISM_STATUS))
1545 vty_out(vty, " OSPF ISM status debugging is on\n");
1546 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
1547 vty_out(vty, " OSPF ISM event debugging is on\n");
1548 if (IS_DEBUG_OSPF(ism, ISM_TIMERS))
1549 vty_out(vty, " OSPF ISM timer debugging is on\n");
1550 }
1551
1552 /* Show debug status for NSM. */
1553 if (IS_DEBUG_OSPF(nsm, NSM) == OSPF_DEBUG_NSM)
1554 vty_out(vty, " OSPF NSM debugging is on\n");
1555 else {
1556 if (IS_DEBUG_OSPF(nsm, NSM_STATUS))
1557 vty_out(vty, " OSPF NSM status debugging is on\n");
1558 if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
1559 vty_out(vty, " OSPF NSM event debugging is on\n");
1560 if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
1561 vty_out(vty, " OSPF NSM timer debugging is on\n");
1562 }
1563
1564 /* Show debug status for OSPF Packets. */
1565 for (i = 0; i < 5; i++)
1566 if (IS_DEBUG_OSPF_PACKET(i, SEND)
1567 && IS_DEBUG_OSPF_PACKET(i, RECV)) {
1568 vty_out(vty, " OSPF packet %s%s debugging is on\n",
1569 lookup_msg(ospf_packet_type_str, i + 1, NULL),
1570 IS_DEBUG_OSPF_PACKET(i, DETAIL) ? " detail"
1571 : "");
1572 } else {
1573 if (IS_DEBUG_OSPF_PACKET(i, SEND))
1574 vty_out(vty,
1575 " OSPF packet %s send%s debugging is on\n",
1576 lookup_msg(ospf_packet_type_str, i + 1,
1577 NULL),
1578 IS_DEBUG_OSPF_PACKET(i, DETAIL)
1579 ? " detail"
1580 : "");
1581 if (IS_DEBUG_OSPF_PACKET(i, RECV))
1582 vty_out(vty,
1583 " OSPF packet %s receive%s debugging is on\n",
1584 lookup_msg(ospf_packet_type_str, i + 1,
1585 NULL),
1586 IS_DEBUG_OSPF_PACKET(i, DETAIL)
1587 ? " detail"
1588 : "");
1589 }
1590
1591 /* Show debug status for OSPF LSAs. */
1592 if (IS_DEBUG_OSPF(lsa, LSA) == OSPF_DEBUG_LSA)
1593 vty_out(vty, " OSPF LSA debugging is on\n");
1594 else {
1595 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1596 vty_out(vty, " OSPF LSA generation debugging is on\n");
1597 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
1598 vty_out(vty, " OSPF LSA flooding debugging is on\n");
1599 if (IS_DEBUG_OSPF(lsa, LSA_INSTALL))
1600 vty_out(vty, " OSPF LSA install debugging is on\n");
1601 if (IS_DEBUG_OSPF(lsa, LSA_REFRESH))
1602 vty_out(vty, " OSPF LSA refresh debugging is on\n");
1603 }
1604
1605 /* Show debug status for Zebra. */
1606 if (IS_DEBUG_OSPF(zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1607 vty_out(vty, " OSPF Zebra debugging is on\n");
1608 else {
1609 if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
1610 vty_out(vty,
1611 " OSPF Zebra interface debugging is on\n");
1612 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
1613 vty_out(vty,
1614 " OSPF Zebra redistribute debugging is on\n");
1615 }
1616
1617 /* Show debug status for NSSA. */
1618 if (IS_DEBUG_OSPF(nssa, NSSA) == OSPF_DEBUG_NSSA)
1619 vty_out(vty, " OSPF NSSA debugging is on\n");
1620
1621 vty_out(vty, "\n");
1622
1623 return CMD_SUCCESS;
718e3744 1624}
1625
87f6dc50
DS
1626DEFUN_NOSH (show_debugging_ospf,
1627 show_debugging_ospf_cmd,
1628 "show debugging [ospf]",
1629 SHOW_STR
1630 DEBUG_STR
1631 OSPF_STR)
7c8ff89e 1632{
b5a8894d 1633 struct ospf *ospf = NULL;
7c8ff89e 1634
b5a8894d
CS
1635 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1636 if (ospf == NULL)
d62a17ae 1637 return CMD_SUCCESS;
7c8ff89e 1638
d62a17ae 1639 return show_debugging_ospf_common(vty, ospf);
7c8ff89e
DS
1640}
1641
87f6dc50
DS
1642DEFUN_NOSH (show_debugging_ospf_instance,
1643 show_debugging_ospf_instance_cmd,
1644 "show debugging ospf (1-65535)",
1645 SHOW_STR
1646 DEBUG_STR
1647 OSPF_STR
1648 "Instance ID\n")
7c8ff89e 1649{
d62a17ae 1650 int idx_number = 3;
1651 struct ospf *ospf;
d7c0a89a 1652 unsigned short instance = 0;
7c8ff89e 1653
d62a17ae 1654 instance = strtoul(argv[idx_number]->arg, NULL, 10);
1655 if ((ospf = ospf_lookup_instance(instance)) == NULL)
1656 return CMD_SUCCESS;
7c8ff89e 1657
d62a17ae 1658 return show_debugging_ospf_common(vty, ospf);
7c8ff89e
DS
1659}
1660
718e3744 1661/* Debug node. */
d62a17ae 1662static struct cmd_node debug_node = {
1663 DEBUG_NODE, "", 1 /* VTYSH */
718e3744 1664};
1665
d62a17ae 1666static int config_write_debug(struct vty *vty)
718e3744 1667{
d62a17ae 1668 int write = 0;
1669 int i, r;
1670
1671 const char *type_str[] = {"hello", "dd", "ls-request", "ls-update",
1672 "ls-ack"};
1673 const char *detail_str[] = {
1674 "", " send", " recv", "",
1675 " detail", " send detail", " recv detail", " detail"};
1676
1677 struct ospf *ospf;
1678 char str[16];
1679 memset(str, 0, 16);
1680
b5a8894d
CS
1681 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1682 if (ospf == NULL)
d62a17ae 1683 return CMD_SUCCESS;
1684
1685 if (ospf->instance)
2ec42b85 1686 sprintf(str, " %u", ospf->instance);
d62a17ae 1687
1688 /* debug ospf ism (status|events|timers). */
1689 if (IS_CONF_DEBUG_OSPF(ism, ISM) == OSPF_DEBUG_ISM)
1690 vty_out(vty, "debug ospf%s ism\n", str);
1691 else {
1692 if (IS_CONF_DEBUG_OSPF(ism, ISM_STATUS))
1693 vty_out(vty, "debug ospf%s ism status\n", str);
1694 if (IS_CONF_DEBUG_OSPF(ism, ISM_EVENTS))
1695 vty_out(vty, "debug ospf%s ism event\n", str);
1696 if (IS_CONF_DEBUG_OSPF(ism, ISM_TIMERS))
1697 vty_out(vty, "debug ospf%s ism timer\n", str);
1698 }
1699
1700 /* debug ospf nsm (status|events|timers). */
1701 if (IS_CONF_DEBUG_OSPF(nsm, NSM) == OSPF_DEBUG_NSM)
1702 vty_out(vty, "debug ospf%s nsm\n", str);
1703 else {
1704 if (IS_CONF_DEBUG_OSPF(nsm, NSM_STATUS))
1705 vty_out(vty, "debug ospf%s nsm status\n", str);
1706 if (IS_CONF_DEBUG_OSPF(nsm, NSM_EVENTS))
1707 vty_out(vty, "debug ospf%s nsm event\n", str);
1708 if (IS_CONF_DEBUG_OSPF(nsm, NSM_TIMERS))
1709 vty_out(vty, "debug ospf%s nsm timer\n", str);
1710 }
1711
1712 /* debug ospf lsa (generate|flooding|install|refresh). */
1713 if (IS_CONF_DEBUG_OSPF(lsa, LSA) == OSPF_DEBUG_LSA)
1714 vty_out(vty, "debug ospf%s lsa\n", str);
1715 else {
1716 if (IS_CONF_DEBUG_OSPF(lsa, LSA_GENERATE))
1717 vty_out(vty, "debug ospf%s lsa generate\n", str);
1718 if (IS_CONF_DEBUG_OSPF(lsa, LSA_FLOODING))
1719 vty_out(vty, "debug ospf%s lsa flooding\n", str);
1720 if (IS_CONF_DEBUG_OSPF(lsa, LSA_INSTALL))
1721 vty_out(vty, "debug ospf%s lsa install\n", str);
1722 if (IS_CONF_DEBUG_OSPF(lsa, LSA_REFRESH))
1723 vty_out(vty, "debug ospf%s lsa refresh\n", str);
1724
1725 write = 1;
1726 }
1727
1728 /* debug ospf zebra (interface|redistribute). */
1729 if (IS_CONF_DEBUG_OSPF(zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
1730 vty_out(vty, "debug ospf%s zebra\n", str);
1731 else {
1732 if (IS_CONF_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
1733 vty_out(vty, "debug ospf%s zebra interface\n", str);
1734 if (IS_CONF_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
1735 vty_out(vty, "debug ospf%s zebra redistribute\n", str);
1736
1737 write = 1;
1738 }
1739
1740 /* debug ospf event. */
1741 if (IS_CONF_DEBUG_OSPF(event, EVENT) == OSPF_DEBUG_EVENT) {
1742 vty_out(vty, "debug ospf%s event\n", str);
1743 write = 1;
1744 }
1745
1746 /* debug ospf nssa. */
1747 if (IS_CONF_DEBUG_OSPF(nssa, NSSA) == OSPF_DEBUG_NSSA) {
1748 vty_out(vty, "debug ospf%s nssa\n", str);
1749 write = 1;
1750 }
1751
1752 /* debug ospf packet all detail. */
1753 r = OSPF_DEBUG_SEND_RECV | OSPF_DEBUG_DETAIL;
1754 for (i = 0; i < 5; i++)
1755 r &= conf_debug_ospf_packet[i]
1756 & (OSPF_DEBUG_SEND_RECV | OSPF_DEBUG_DETAIL);
1757 if (r == (OSPF_DEBUG_SEND_RECV | OSPF_DEBUG_DETAIL)) {
1758 vty_out(vty, "debug ospf%s packet all detail\n", str);
1759 return 1;
1760 }
1761
1762 /* debug ospf packet all. */
1763 r = OSPF_DEBUG_SEND_RECV;
1764 for (i = 0; i < 5; i++)
1765 r &= conf_debug_ospf_packet[i] & OSPF_DEBUG_SEND_RECV;
1766 if (r == OSPF_DEBUG_SEND_RECV) {
1767 vty_out(vty, "debug ospf%s packet all\n", str);
1768 for (i = 0; i < 5; i++)
1769 if (conf_debug_ospf_packet[i] & OSPF_DEBUG_DETAIL)
1770 vty_out(vty, "debug ospf%s packet %s detail\n",
1771 str, type_str[i]);
1772 return 1;
1773 }
1774
1775 /* debug ospf packet (hello|dd|ls-request|ls-update|ls-ack)
1776 (send|recv) (detail). */
1777 for (i = 0; i < 5; i++) {
1778 if (conf_debug_ospf_packet[i] == 0)
1779 continue;
1780
1781 vty_out(vty, "debug ospf%s packet %s%s\n", str, type_str[i],
1782 detail_str[conf_debug_ospf_packet[i]]);
1783 write = 1;
1784 }
1785
7743f2f8
OD
1786 /* debug ospf te */
1787 if (IS_CONF_DEBUG_OSPF(te, TE) == OSPF_DEBUG_TE) {
1788 vty_out(vty, "debug ospf%s te\n", str);
1789 write = 1;
1790 }
1791
1792 /* debug ospf sr */
1793 if (IS_CONF_DEBUG_OSPF(sr, SR) == OSPF_DEBUG_SR) {
1794 vty_out(vty, "debug ospf%s sr\n", str);
1795 write = 1;
1796 }
1797
d62a17ae 1798 return write;
718e3744 1799}
1800
1801/* Initialize debug commands. */
6243a7b5 1802void ospf_debug_init(void)
718e3744 1803{
d62a17ae 1804 install_node(&debug_node, config_write_debug);
1805
1806 install_element(ENABLE_NODE, &show_debugging_ospf_cmd);
1807 install_element(ENABLE_NODE, &debug_ospf_ism_cmd);
1808 install_element(ENABLE_NODE, &debug_ospf_nsm_cmd);
1809 install_element(ENABLE_NODE, &debug_ospf_lsa_cmd);
1810 install_element(ENABLE_NODE, &debug_ospf_zebra_cmd);
1811 install_element(ENABLE_NODE, &debug_ospf_event_cmd);
1812 install_element(ENABLE_NODE, &debug_ospf_nssa_cmd);
1813 install_element(ENABLE_NODE, &debug_ospf_te_cmd);
cf9b9f77 1814 install_element(ENABLE_NODE, &debug_ospf_sr_cmd);
d62a17ae 1815 install_element(ENABLE_NODE, &no_debug_ospf_ism_cmd);
1816 install_element(ENABLE_NODE, &no_debug_ospf_nsm_cmd);
1817 install_element(ENABLE_NODE, &no_debug_ospf_lsa_cmd);
1818 install_element(ENABLE_NODE, &no_debug_ospf_zebra_cmd);
1819 install_element(ENABLE_NODE, &no_debug_ospf_event_cmd);
1820 install_element(ENABLE_NODE, &no_debug_ospf_nssa_cmd);
1821 install_element(ENABLE_NODE, &no_debug_ospf_te_cmd);
cf9b9f77 1822 install_element(ENABLE_NODE, &no_debug_ospf_sr_cmd);
d62a17ae 1823
1824 install_element(ENABLE_NODE, &show_debugging_ospf_instance_cmd);
1825 install_element(ENABLE_NODE, &debug_ospf_packet_cmd);
1826 install_element(ENABLE_NODE, &no_debug_ospf_packet_cmd);
1827
1828 install_element(ENABLE_NODE, &debug_ospf_instance_nsm_cmd);
1829 install_element(ENABLE_NODE, &debug_ospf_instance_lsa_cmd);
1830 install_element(ENABLE_NODE, &debug_ospf_instance_zebra_cmd);
1831 install_element(ENABLE_NODE, &debug_ospf_instance_event_cmd);
1832 install_element(ENABLE_NODE, &debug_ospf_instance_nssa_cmd);
1833 install_element(ENABLE_NODE, &no_debug_ospf_instance_nsm_cmd);
1834 install_element(ENABLE_NODE, &no_debug_ospf_instance_lsa_cmd);
1835 install_element(ENABLE_NODE, &no_debug_ospf_instance_zebra_cmd);
1836 install_element(ENABLE_NODE, &no_debug_ospf_instance_event_cmd);
1837 install_element(ENABLE_NODE, &no_debug_ospf_instance_nssa_cmd);
1838 install_element(ENABLE_NODE, &no_debug_ospf_cmd);
1839
1840 install_element(CONFIG_NODE, &debug_ospf_packet_cmd);
1841 install_element(CONFIG_NODE, &no_debug_ospf_packet_cmd);
1842 install_element(CONFIG_NODE, &debug_ospf_ism_cmd);
1843 install_element(CONFIG_NODE, &no_debug_ospf_ism_cmd);
1844
1845 install_element(CONFIG_NODE, &debug_ospf_nsm_cmd);
1846 install_element(CONFIG_NODE, &debug_ospf_lsa_cmd);
1847 install_element(CONFIG_NODE, &debug_ospf_zebra_cmd);
1848 install_element(CONFIG_NODE, &debug_ospf_event_cmd);
1849 install_element(CONFIG_NODE, &debug_ospf_nssa_cmd);
1850 install_element(CONFIG_NODE, &debug_ospf_te_cmd);
cf9b9f77 1851 install_element(CONFIG_NODE, &debug_ospf_sr_cmd);
d62a17ae 1852 install_element(CONFIG_NODE, &no_debug_ospf_nsm_cmd);
1853 install_element(CONFIG_NODE, &no_debug_ospf_lsa_cmd);
1854 install_element(CONFIG_NODE, &no_debug_ospf_zebra_cmd);
1855 install_element(CONFIG_NODE, &no_debug_ospf_event_cmd);
1856 install_element(CONFIG_NODE, &no_debug_ospf_nssa_cmd);
1857 install_element(CONFIG_NODE, &no_debug_ospf_te_cmd);
cf9b9f77 1858 install_element(CONFIG_NODE, &no_debug_ospf_sr_cmd);
d62a17ae 1859
1860 install_element(CONFIG_NODE, &debug_ospf_instance_nsm_cmd);
1861 install_element(CONFIG_NODE, &debug_ospf_instance_lsa_cmd);
1862 install_element(CONFIG_NODE, &debug_ospf_instance_zebra_cmd);
1863 install_element(CONFIG_NODE, &debug_ospf_instance_event_cmd);
1864 install_element(CONFIG_NODE, &debug_ospf_instance_nssa_cmd);
1865 install_element(CONFIG_NODE, &no_debug_ospf_instance_nsm_cmd);
1866 install_element(CONFIG_NODE, &no_debug_ospf_instance_lsa_cmd);
1867 install_element(CONFIG_NODE, &no_debug_ospf_instance_zebra_cmd);
1868 install_element(CONFIG_NODE, &no_debug_ospf_instance_event_cmd);
1869 install_element(CONFIG_NODE, &no_debug_ospf_instance_nssa_cmd);
1870 install_element(CONFIG_NODE, &no_debug_ospf_cmd);
718e3744 1871}