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