3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
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
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.
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
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"
45 /* Configuration debug option variables. */
46 unsigned long conf_debug_ospf_packet
[5] = {0, 0, 0, 0, 0};
47 unsigned long conf_debug_ospf_event
= 0;
48 unsigned long conf_debug_ospf_ism
= 0;
49 unsigned long conf_debug_ospf_nsm
= 0;
50 unsigned long conf_debug_ospf_lsa
= 0;
51 unsigned long conf_debug_ospf_zebra
= 0;
52 unsigned long conf_debug_ospf_nssa
= 0;
53 unsigned long conf_debug_ospf_te
= 0;
55 /* Enable debug option variables -- valid only session. */
56 unsigned long term_debug_ospf_packet
[5] = {0, 0, 0, 0, 0};
57 unsigned long term_debug_ospf_event
= 0;
58 unsigned long term_debug_ospf_ism
= 0;
59 unsigned long term_debug_ospf_nsm
= 0;
60 unsigned long term_debug_ospf_lsa
= 0;
61 unsigned long term_debug_ospf_zebra
= 0;
62 unsigned long term_debug_ospf_nssa
= 0;
63 unsigned long term_debug_ospf_te
= 0;
66 const char *ospf_redist_string(u_int route_type
)
68 return (route_type
== ZEBRA_ROUTE_MAX
) ? "Default"
69 : zebra_route_string(route_type
);
72 #define OSPF_AREA_STRING_MAXLEN 16
73 const char *ospf_area_name_string(struct ospf_area
*area
)
75 static char buf
[OSPF_AREA_STRING_MAXLEN
] = "";
81 area_id
= ntohl(area
->area_id
.s_addr
);
82 snprintf(buf
, OSPF_AREA_STRING_MAXLEN
, "%d.%d.%d.%d",
83 (area_id
>> 24) & 0xff, (area_id
>> 16) & 0xff,
84 (area_id
>> 8) & 0xff, area_id
& 0xff);
88 #define OSPF_AREA_DESC_STRING_MAXLEN 23
89 const char *ospf_area_desc_string(struct ospf_area
*area
)
91 static char buf
[OSPF_AREA_DESC_STRING_MAXLEN
] = "";
95 return "(incomplete)";
97 type
= area
->external_routing
;
100 snprintf(buf
, OSPF_AREA_DESC_STRING_MAXLEN
, "%s [NSSA]",
101 ospf_area_name_string(area
));
104 snprintf(buf
, OSPF_AREA_DESC_STRING_MAXLEN
, "%s [Stub]",
105 ospf_area_name_string(area
));
108 return ospf_area_name_string(area
);
114 #define OSPF_IF_STRING_MAXLEN 40
115 const char *ospf_if_name_string(struct ospf_interface
*oi
)
117 static char buf
[OSPF_IF_STRING_MAXLEN
] = "";
120 if (!oi
|| !oi
->address
)
123 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
124 return oi
->ifp
->name
;
126 ifaddr
= ntohl(oi
->address
->u
.prefix4
.s_addr
);
127 snprintf(buf
, OSPF_IF_STRING_MAXLEN
, "%s:%d.%d.%d.%d", oi
->ifp
->name
,
128 (ifaddr
>> 24) & 0xff, (ifaddr
>> 16) & 0xff,
129 (ifaddr
>> 8) & 0xff, ifaddr
& 0xff);
134 void ospf_nbr_state_message(struct ospf_neighbor
*nbr
, char *buf
, size_t size
)
137 struct ospf_interface
*oi
= nbr
->oi
;
139 if (IPV4_ADDR_SAME(&DR(oi
), &nbr
->address
.u
.prefix4
))
141 else if (IPV4_ADDR_SAME(&BDR(oi
), &nbr
->address
.u
.prefix4
))
146 memset(buf
, 0, size
);
148 snprintf(buf
, size
, "%s/%s",
149 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
),
150 lookup_msg(ospf_ism_state_msg
, state
, NULL
));
153 const char *ospf_timeval_dump(struct timeval
*t
, char *buf
, size_t size
)
155 /* Making formatted timer strings. */
156 #define MINUTE_IN_SECONDS 60
157 #define HOUR_IN_SECONDS (60*MINUTE_IN_SECONDS)
158 #define DAY_IN_SECONDS (24*HOUR_IN_SECONDS)
159 #define WEEK_IN_SECONDS (7*DAY_IN_SECONDS)
160 unsigned long w
, d
, h
, m
, s
, ms
, us
;
165 w
= d
= h
= m
= s
= ms
= us
= 0;
166 memset(buf
, 0, size
);
172 (void)us
; /* unused */
176 t
->tv_sec
+= ms
/ 1000;
180 if (t
->tv_sec
> WEEK_IN_SECONDS
) {
181 w
= t
->tv_sec
/ WEEK_IN_SECONDS
;
182 t
->tv_sec
-= w
* WEEK_IN_SECONDS
;
185 if (t
->tv_sec
> DAY_IN_SECONDS
) {
186 d
= t
->tv_sec
/ DAY_IN_SECONDS
;
187 t
->tv_sec
-= d
* DAY_IN_SECONDS
;
190 if (t
->tv_sec
>= HOUR_IN_SECONDS
) {
191 h
= t
->tv_sec
/ HOUR_IN_SECONDS
;
192 t
->tv_sec
-= h
* HOUR_IN_SECONDS
;
195 if (t
->tv_sec
>= MINUTE_IN_SECONDS
) {
196 m
= t
->tv_sec
/ MINUTE_IN_SECONDS
;
197 t
->tv_sec
-= m
* MINUTE_IN_SECONDS
;
201 snprintf(buf
, size
, "%ldw%1ldd", w
, d
);
203 snprintf(buf
, size
, "%ldw%1ldd%02ldh", w
, d
, h
);
205 snprintf(buf
, size
, "%1ldd%02ldh%02ldm", d
, h
, m
);
207 snprintf(buf
, size
, "%ldh%02ldm%02lds", h
, m
, (long)t
->tv_sec
);
209 snprintf(buf
, size
, "%ldm%02lds", m
, (long)t
->tv_sec
);
211 snprintf(buf
, size
, "%ld.%03lds", (long)t
->tv_sec
, ms
);
213 snprintf(buf
, size
, "%ld usecs", (long)t
->tv_usec
);
218 const char *ospf_timer_dump(struct thread
*t
, char *buf
, size_t size
)
220 struct timeval result
;
224 monotime_until(&t
->u
.sands
, &result
);
225 return ospf_timeval_dump(&result
, buf
, size
);
228 static void ospf_packet_hello_dump(struct stream
*s
, u_int16_t length
)
230 struct ospf_hello
*hello
;
233 hello
= (struct ospf_hello
*)stream_pnt(s
);
236 zlog_debug(" NetworkMask %s", inet_ntoa(hello
->network_mask
));
237 zlog_debug(" HelloInterval %d", ntohs(hello
->hello_interval
));
238 zlog_debug(" Options %d (%s)", hello
->options
,
239 ospf_options_dump(hello
->options
));
240 zlog_debug(" RtrPriority %d", hello
->priority
);
241 zlog_debug(" RtrDeadInterval %ld",
242 (u_long
)ntohl(hello
->dead_interval
));
243 zlog_debug(" DRouter %s", inet_ntoa(hello
->d_router
));
244 zlog_debug(" BDRouter %s", inet_ntoa(hello
->bd_router
));
246 length
-= OSPF_HEADER_SIZE
+ OSPF_HELLO_MIN_SIZE
;
247 zlog_debug(" # Neighbors %d", length
/ 4);
248 for (i
= 0; length
> 0; i
++, length
-= sizeof(struct in_addr
))
249 zlog_debug(" Neighbor %s", inet_ntoa(hello
->neighbors
[i
]));
252 static char *ospf_dd_flags_dump(u_char flags
, char *buf
, size_t size
)
254 memset(buf
, 0, size
);
256 snprintf(buf
, size
, "%s|%s|%s", (flags
& OSPF_DD_FLAG_I
) ? "I" : "-",
257 (flags
& OSPF_DD_FLAG_M
) ? "M" : "-",
258 (flags
& OSPF_DD_FLAG_MS
) ? "MS" : "-");
263 static char *ospf_router_lsa_flags_dump(u_char flags
, char *buf
, size_t size
)
265 memset(buf
, 0, size
);
267 snprintf(buf
, size
, "%s|%s|%s",
268 (flags
& ROUTER_LSA_VIRTUAL
) ? "V" : "-",
269 (flags
& ROUTER_LSA_EXTERNAL
) ? "E" : "-",
270 (flags
& ROUTER_LSA_BORDER
) ? "B" : "-");
275 static void ospf_router_lsa_dump(struct stream
*s
, u_int16_t length
)
278 struct router_lsa
*rl
;
281 rl
= (struct router_lsa
*)stream_pnt(s
);
283 zlog_debug(" Router-LSA");
284 zlog_debug(" flags %s",
285 ospf_router_lsa_flags_dump(rl
->flags
, buf
, BUFSIZ
));
286 zlog_debug(" # links %d", ntohs(rl
->links
));
288 len
= ntohs(rl
->header
.length
) - OSPF_LSA_HEADER_SIZE
- 4;
289 for (i
= 0; len
> 0; i
++) {
290 zlog_debug(" Link ID %s", inet_ntoa(rl
->link
[i
].link_id
));
291 zlog_debug(" Link Data %s",
292 inet_ntoa(rl
->link
[i
].link_data
));
293 zlog_debug(" Type %d", (u_char
)rl
->link
[i
].type
);
294 zlog_debug(" TOS %d", (u_char
)rl
->link
[i
].tos
);
295 zlog_debug(" metric %d", ntohs(rl
->link
[i
].metric
));
301 static void ospf_network_lsa_dump(struct stream
*s
, u_int16_t length
)
303 struct network_lsa
*nl
;
306 nl
= (struct network_lsa
*)stream_pnt(s
);
307 cnt
= (ntohs(nl
->header
.length
) - (OSPF_LSA_HEADER_SIZE
+ 4)) / 4;
309 zlog_debug(" Network-LSA");
311 zlog_debug ("LSA total size %d", ntohs (nl->header.length));
312 zlog_debug ("Network-LSA size %d",
313 ntohs (nl->header.length) - OSPF_LSA_HEADER_SIZE);
315 zlog_debug(" Network Mask %s", inet_ntoa(nl
->mask
));
316 zlog_debug(" # Attached Routers %d", cnt
);
317 for (i
= 0; i
< cnt
; i
++)
318 zlog_debug(" Attached Router %s",
319 inet_ntoa(nl
->routers
[i
]));
322 static void ospf_summary_lsa_dump(struct stream
*s
, u_int16_t length
)
324 struct summary_lsa
*sl
;
328 sl
= (struct summary_lsa
*)stream_pnt(s
);
330 zlog_debug(" Summary-LSA");
331 zlog_debug(" Network Mask %s", inet_ntoa(sl
->mask
));
333 size
= ntohs(sl
->header
.length
) - OSPF_LSA_HEADER_SIZE
- 4;
334 for (i
= 0; size
> 0; size
-= 4, i
++)
335 zlog_debug(" TOS=%d metric %d", sl
->tos
,
336 GET_METRIC(sl
->metric
));
339 static void ospf_as_external_lsa_dump(struct stream
*s
, u_int16_t length
)
341 struct as_external_lsa
*al
;
345 al
= (struct as_external_lsa
*)stream_pnt(s
);
346 zlog_debug(" %s", ospf_lsa_type_msg
[al
->header
.type
].str
);
347 zlog_debug(" Network Mask %s", inet_ntoa(al
->mask
));
349 size
= ntohs(al
->header
.length
) - OSPF_LSA_HEADER_SIZE
- 4;
350 for (i
= 0; size
> 0; size
-= 12, i
++) {
351 zlog_debug(" bit %s TOS=%d metric %d",
352 IS_EXTERNAL_METRIC(al
->e
[i
].tos
) ? "E" : "-",
353 al
->e
[i
].tos
& 0x7f, GET_METRIC(al
->e
[i
].metric
));
354 zlog_debug(" Forwarding address %s",
355 inet_ntoa(al
->e
[i
].fwd_addr
));
356 zlog_debug(" External Route Tag %" ROUTE_TAG_PRI
,
361 static void ospf_lsa_header_list_dump(struct stream
*s
, u_int16_t length
)
363 struct lsa_header
*lsa
;
365 zlog_debug(" # LSA Headers %d", length
/ OSPF_LSA_HEADER_SIZE
);
369 lsa
= (struct lsa_header
*)stream_pnt(s
);
370 ospf_lsa_header_dump(lsa
);
372 stream_forward_getp(s
, OSPF_LSA_HEADER_SIZE
);
373 length
-= OSPF_LSA_HEADER_SIZE
;
377 static void ospf_packet_db_desc_dump(struct stream
*s
, u_int16_t length
)
379 struct ospf_db_desc
*dd
;
384 gp
= stream_get_getp(s
);
385 dd
= (struct ospf_db_desc
*)stream_pnt(s
);
387 zlog_debug("Database Description");
388 zlog_debug(" Interface MTU %d", ntohs(dd
->mtu
));
389 zlog_debug(" Options %d (%s)", dd
->options
,
390 ospf_options_dump(dd
->options
));
391 zlog_debug(" Flags %d (%s)", dd
->flags
,
392 ospf_dd_flags_dump(dd
->flags
, dd_flags
, sizeof dd_flags
));
393 zlog_debug(" Sequence Number 0x%08lx", (u_long
)ntohl(dd
->dd_seqnum
));
395 length
-= OSPF_HEADER_SIZE
+ OSPF_DB_DESC_MIN_SIZE
;
397 stream_forward_getp(s
, OSPF_DB_DESC_MIN_SIZE
);
399 ospf_lsa_header_list_dump(s
, length
);
401 stream_set_getp(s
, gp
);
404 static void ospf_packet_ls_req_dump(struct stream
*s
, u_int16_t length
)
408 struct in_addr ls_id
;
409 struct in_addr adv_router
;
411 sp
= stream_get_getp(s
);
413 length
-= OSPF_HEADER_SIZE
;
415 zlog_debug("Link State Request");
416 zlog_debug(" # Requests %d", length
/ 12);
418 for (; length
> 0; length
-= 12) {
419 ls_type
= stream_getl(s
);
420 ls_id
.s_addr
= stream_get_ipv4(s
);
421 adv_router
.s_addr
= stream_get_ipv4(s
);
423 zlog_debug(" LS type %d", ls_type
);
424 zlog_debug(" Link State ID %s", inet_ntoa(ls_id
));
425 zlog_debug(" Advertising Router %s", inet_ntoa(adv_router
));
428 stream_set_getp(s
, sp
);
431 static void ospf_packet_ls_upd_dump(struct stream
*s
, u_int16_t length
)
434 struct lsa_header
*lsa
;
438 length
-= OSPF_HEADER_SIZE
;
440 sp
= stream_get_getp(s
);
442 count
= stream_getl(s
);
445 zlog_debug("Link State Update");
446 zlog_debug(" # LSAs %d", count
);
448 while (length
> 0 && count
> 0) {
449 if (length
< OSPF_HEADER_SIZE
|| length
% 4 != 0) {
450 zlog_debug(" Remaining %d bytes; Incorrect length.",
455 lsa
= (struct lsa_header
*)stream_pnt(s
);
456 lsa_len
= ntohs(lsa
->length
);
457 ospf_lsa_header_dump(lsa
);
460 case OSPF_ROUTER_LSA
:
461 ospf_router_lsa_dump(s
, length
);
463 case OSPF_NETWORK_LSA
:
464 ospf_network_lsa_dump(s
, length
);
466 case OSPF_SUMMARY_LSA
:
467 case OSPF_ASBR_SUMMARY_LSA
:
468 ospf_summary_lsa_dump(s
, length
);
470 case OSPF_AS_EXTERNAL_LSA
:
471 ospf_as_external_lsa_dump(s
, length
);
473 case OSPF_AS_NSSA_LSA
:
474 ospf_as_external_lsa_dump(s
, length
);
476 case OSPF_OPAQUE_LINK_LSA
:
477 case OSPF_OPAQUE_AREA_LSA
:
478 case OSPF_OPAQUE_AS_LSA
:
479 ospf_opaque_lsa_dump(s
, length
);
485 stream_forward_getp(s
, lsa_len
);
490 stream_set_getp(s
, sp
);
493 static void ospf_packet_ls_ack_dump(struct stream
*s
, u_int16_t length
)
497 length
-= OSPF_HEADER_SIZE
;
498 sp
= stream_get_getp(s
);
500 zlog_debug("Link State Acknowledgment");
501 ospf_lsa_header_list_dump(s
, length
);
503 stream_set_getp(s
, sp
);
506 /* Expects header to be in host order */
507 void ospf_ip_header_dump(struct ip
*iph
)
509 /* IP Header dump. */
510 zlog_debug("ip_v %d", iph
->ip_v
);
511 zlog_debug("ip_hl %d", iph
->ip_hl
);
512 zlog_debug("ip_tos %d", iph
->ip_tos
);
513 zlog_debug("ip_len %d", iph
->ip_len
);
514 zlog_debug("ip_id %u", (u_int32_t
)iph
->ip_id
);
515 zlog_debug("ip_off %u", (u_int32_t
)iph
->ip_off
);
516 zlog_debug("ip_ttl %d", iph
->ip_ttl
);
517 zlog_debug("ip_p %d", iph
->ip_p
);
518 zlog_debug("ip_sum 0x%x", (u_int32_t
)iph
->ip_sum
);
519 zlog_debug("ip_src %s", inet_ntoa(iph
->ip_src
));
520 zlog_debug("ip_dst %s", inet_ntoa(iph
->ip_dst
));
523 static void ospf_header_dump(struct ospf_header
*ospfh
)
526 u_int16_t auth_type
= ntohs(ospfh
->auth_type
);
528 zlog_debug("Header");
529 zlog_debug(" Version %d", ospfh
->version
);
530 zlog_debug(" Type %d (%s)", ospfh
->type
,
531 lookup_msg(ospf_packet_type_str
, ospfh
->type
, NULL
));
532 zlog_debug(" Packet Len %d", ntohs(ospfh
->length
));
533 zlog_debug(" Router ID %s", inet_ntoa(ospfh
->router_id
));
534 zlog_debug(" Area ID %s", inet_ntoa(ospfh
->area_id
));
535 zlog_debug(" Checksum 0x%x", ntohs(ospfh
->checksum
));
536 zlog_debug(" AuType %s",
537 lookup_msg(ospf_auth_type_str
, auth_type
, NULL
));
542 case OSPF_AUTH_SIMPLE
:
544 strncpy(buf
, (char *)ospfh
->u
.auth_data
, 8);
545 zlog_debug(" Simple Password %s", buf
);
547 case OSPF_AUTH_CRYPTOGRAPHIC
:
548 zlog_debug(" Cryptographic Authentication");
549 zlog_debug(" Key ID %d", ospfh
->u
.crypt
.key_id
);
550 zlog_debug(" Auth Data Len %d", ospfh
->u
.crypt
.auth_data_len
);
551 zlog_debug(" Sequence number %ld",
552 (u_long
)ntohl(ospfh
->u
.crypt
.crypt_seqnum
));
555 zlog_debug("* This is not supported authentication type");
560 void ospf_packet_dump(struct stream
*s
)
562 struct ospf_header
*ospfh
;
565 /* Preserve pointer. */
566 gp
= stream_get_getp(s
);
568 /* OSPF Header dump. */
569 ospfh
= (struct ospf_header
*)stream_pnt(s
);
571 /* Until detail flag is set, return. */
572 if (!(term_debug_ospf_packet
[ospfh
->type
- 1] & OSPF_DEBUG_DETAIL
))
575 /* Show OSPF header detail. */
576 ospf_header_dump(ospfh
);
577 stream_forward_getp(s
, OSPF_HEADER_SIZE
);
579 switch (ospfh
->type
) {
581 ospf_packet_hello_dump(s
, ntohs(ospfh
->length
));
583 case OSPF_MSG_DB_DESC
:
584 ospf_packet_db_desc_dump(s
, ntohs(ospfh
->length
));
586 case OSPF_MSG_LS_REQ
:
587 ospf_packet_ls_req_dump(s
, ntohs(ospfh
->length
));
589 case OSPF_MSG_LS_UPD
:
590 ospf_packet_ls_upd_dump(s
, ntohs(ospfh
->length
));
592 case OSPF_MSG_LS_ACK
:
593 ospf_packet_ls_ack_dump(s
, ntohs(ospfh
->length
));
599 stream_set_getp(s
, gp
);
602 DEFUN (debug_ospf_packet
,
603 debug_ospf_packet_cmd
,
604 "debug ospf [(1-65535)] packet <hello|dd|ls-request|ls-update|ls-ack|all> [<send [detail]|recv [detail]|detail>]",
610 "OSPF Database Description\n"
611 "OSPF Link State Request\n"
612 "OSPF Link State Update\n"
613 "OSPF Link State Acknowledgment\n"
616 "Detail Information\n"
618 "Detail Information\n"
619 "Detail Information\n")
621 int inst
= (argv
[2]->type
== RANGE_TKN
) ? 1 : 0;
622 int detail
= strmatch(argv
[argc
- 1]->text
, "detail");
623 int send
= strmatch(argv
[argc
- (1 + detail
)]->text
, "send");
624 int recv
= strmatch(argv
[argc
- (1 + detail
)]->text
, "recv");
625 char *packet
= argv
[3 + inst
]->text
;
627 if (inst
) // user passed instance ID
629 if (!ospf_lookup_instance(strtoul(argv
[2]->arg
, NULL
, 10)))
630 return CMD_NOT_MY_INSTANCE
;
637 /* Check packet type. */
638 if (strmatch(packet
, "hello"))
639 type
= OSPF_DEBUG_HELLO
;
640 else if (strmatch(packet
, "dd"))
641 type
= OSPF_DEBUG_DB_DESC
;
642 else if (strmatch(packet
, "ls-request"))
643 type
= OSPF_DEBUG_LS_REQ
;
644 else if (strmatch(packet
, "ls-update"))
645 type
= OSPF_DEBUG_LS_UPD
;
646 else if (strmatch(packet
, "ls-ack"))
647 type
= OSPF_DEBUG_LS_ACK
;
648 else if (strmatch(packet
, "all"))
649 type
= OSPF_DEBUG_ALL
;
652 * (none) = send + recv
653 * detail = send + recv + detail
656 * recv detail = recv + detail
657 * send detail = send + detail
662 flag
|= (send
) ? OSPF_DEBUG_SEND
: 0;
663 flag
|= (recv
) ? OSPF_DEBUG_RECV
: 0;
664 flag
|= (detail
) ? OSPF_DEBUG_DETAIL
: 0;
666 for (i
= 0; i
< 5; i
++)
667 if (type
& (0x01 << i
)) {
668 if (vty
->node
== CONFIG_NODE
)
669 DEBUG_PACKET_ON(i
, flag
);
671 TERM_DEBUG_PACKET_ON(i
, flag
);
677 DEFUN (no_debug_ospf_packet
,
678 no_debug_ospf_packet_cmd
,
679 "no debug ospf [(1-65535)] packet <hello|dd|ls-request|ls-update|ls-ack|all> [<send [detail]|recv [detail]|detail>]",
686 "OSPF Database Description\n"
687 "OSPF Link State Request\n"
688 "OSPF Link State Update\n"
689 "OSPF Link State Acknowledgment\n"
692 "Detail Information\n"
694 "Detail Information\n"
695 "Detail Information\n")
697 int inst
= (argv
[3]->type
== RANGE_TKN
) ? 1 : 0;
698 int detail
= strmatch(argv
[argc
- 1]->text
, "detail");
699 int send
= strmatch(argv
[argc
- (1 + detail
)]->text
, "send");
700 int recv
= strmatch(argv
[argc
- (1 + detail
)]->text
, "recv");
701 char *packet
= argv
[4 + inst
]->text
;
703 if (inst
) // user passed instance ID
705 if (!ospf_lookup_instance(strtoul(argv
[3]->arg
, NULL
, 10)))
706 return CMD_NOT_MY_INSTANCE
;
713 /* Check packet type. */
714 if (strmatch(packet
, "hello"))
715 type
= OSPF_DEBUG_HELLO
;
716 else if (strmatch(packet
, "dd"))
717 type
= OSPF_DEBUG_DB_DESC
;
718 else if (strmatch(packet
, "ls-request"))
719 type
= OSPF_DEBUG_LS_REQ
;
720 else if (strmatch(packet
, "ls-update"))
721 type
= OSPF_DEBUG_LS_UPD
;
722 else if (strmatch(packet
, "ls-ack"))
723 type
= OSPF_DEBUG_LS_ACK
;
724 else if (strmatch(packet
, "all"))
725 type
= OSPF_DEBUG_ALL
;
728 * (none) = send + recv
729 * detail = send + recv + detail
732 * recv detail = recv + detail
733 * send detail = send + detail
738 flag
|= (send
) ? OSPF_DEBUG_SEND
: 0;
739 flag
|= (recv
) ? OSPF_DEBUG_RECV
: 0;
740 flag
|= (detail
) ? OSPF_DEBUG_DETAIL
: 0;
742 for (i
= 0; i
< 5; i
++)
743 if (type
& (0x01 << i
)) {
744 if (vty
->node
== CONFIG_NODE
)
745 DEBUG_PACKET_OFF(i
, flag
);
747 TERM_DEBUG_PACKET_OFF(i
, flag
);
752 for (i = 0; i < 5; i++)
753 zlog_debug ("flag[%d] = %d", i, ospf_debug_packet[i]);
760 DEFUN (debug_ospf_ism
,
762 "debug ospf [(1-65535)] ism [<status|events|timers>]",
766 "OSPF Interface State Machine\n"
767 "ISM Status Information\n"
768 "ISM Event Information\n"
769 "ISM TImer Information\n")
771 int inst
= (argv
[2]->type
== RANGE_TKN
);
772 char *dbgparam
= (argc
== 4 + inst
) ? argv
[argc
- 1]->text
: NULL
;
774 if (inst
) // user passed instance ID
776 if (!ospf_lookup_instance(strtoul(argv
[2]->arg
, NULL
, 10)))
777 return CMD_NOT_MY_INSTANCE
;
780 if (vty
->node
== CONFIG_NODE
) {
784 if (strmatch(dbgparam
, "status"))
785 DEBUG_ON(ism
, ISM_STATUS
);
786 else if (strmatch(dbgparam
, "events"))
787 DEBUG_ON(ism
, ISM_EVENTS
);
788 else if (strmatch(dbgparam
, "timers"))
789 DEBUG_ON(ism
, ISM_TIMERS
);
797 TERM_DEBUG_ON(ism
, ISM
);
799 if (strmatch(dbgparam
, "status"))
800 TERM_DEBUG_ON(ism
, ISM_STATUS
);
801 else if (strmatch(dbgparam
, "events"))
802 TERM_DEBUG_ON(ism
, ISM_EVENTS
);
803 else if (strmatch(dbgparam
, "timers"))
804 TERM_DEBUG_ON(ism
, ISM_TIMERS
);
810 DEFUN (no_debug_ospf_ism
,
811 no_debug_ospf_ism_cmd
,
812 "no debug ospf [(1-65535)] ism [<status|events|timers>]",
817 "OSPF Interface State Machine\n"
818 "ISM Status Information\n"
819 "ISM Event Information\n"
820 "ISM TImer Information\n")
822 int inst
= (argv
[3]->type
== RANGE_TKN
);
823 char *dbgparam
= (argc
== 5 + inst
) ? argv
[argc
- 1]->text
: NULL
;
825 if (inst
) // user passed instance ID
827 if (!ospf_lookup_instance(strtoul(argv
[3]->arg
, NULL
, 10)))
828 return CMD_NOT_MY_INSTANCE
;
831 if (vty
->node
== CONFIG_NODE
) {
835 if (strmatch(dbgparam
, "status"))
836 DEBUG_OFF(ism
, ISM_STATUS
);
837 else if (strmatch(dbgparam
, "events"))
838 DEBUG_OFF(ism
, ISM_EVENTS
);
839 else if (strmatch(dbgparam
, "timers"))
840 DEBUG_OFF(ism
, ISM_TIMERS
);
848 TERM_DEBUG_OFF(ism
, ISM
);
850 if (strmatch(dbgparam
, "status"))
851 TERM_DEBUG_OFF(ism
, ISM_STATUS
);
852 else if (strmatch(dbgparam
, "events"))
853 TERM_DEBUG_OFF(ism
, ISM_EVENTS
);
854 else if (strmatch(dbgparam
, "timers"))
855 TERM_DEBUG_OFF(ism
, ISM_TIMERS
);
861 static int debug_ospf_nsm_common(struct vty
*vty
, int arg_base
, int argc
,
862 struct cmd_token
**argv
)
864 if (vty
->node
== CONFIG_NODE
) {
865 if (argc
== arg_base
+ 0)
867 else if (argc
== arg_base
+ 1) {
868 if (strmatch(argv
[arg_base
]->text
, "status"))
869 DEBUG_ON(nsm
, NSM_STATUS
);
870 else if (strmatch(argv
[arg_base
]->text
, "events"))
871 DEBUG_ON(nsm
, NSM_EVENTS
);
872 else if (strmatch(argv
[arg_base
]->text
, "timers"))
873 DEBUG_ON(nsm
, NSM_TIMERS
);
880 if (argc
== arg_base
+ 0)
881 TERM_DEBUG_ON(nsm
, NSM
);
882 else if (argc
== arg_base
+ 1) {
883 if (strmatch(argv
[arg_base
]->text
, "status"))
884 TERM_DEBUG_ON(nsm
, NSM_STATUS
);
885 else if (strmatch(argv
[arg_base
]->text
, "events"))
886 TERM_DEBUG_ON(nsm
, NSM_EVENTS
);
887 else if (strmatch(argv
[arg_base
]->text
, "timers"))
888 TERM_DEBUG_ON(nsm
, NSM_TIMERS
);
894 DEFUN (debug_ospf_nsm
,
896 "debug ospf nsm [<status|events|timers>]",
899 "OSPF Neighbor State Machine\n"
900 "NSM Status Information\n"
901 "NSM Event Information\n"
902 "NSM Timer Information\n")
904 return debug_ospf_nsm_common(vty
, 3, argc
, argv
);
907 DEFUN (debug_ospf_instance_nsm
,
908 debug_ospf_instance_nsm_cmd
,
909 "debug ospf (1-65535) nsm [<status|events|timers>]",
913 "OSPF Neighbor State Machine\n"
914 "NSM Status Information\n"
915 "NSM Event Information\n"
916 "NSM Timer Information\n")
919 u_short instance
= 0;
921 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
922 if (!ospf_lookup_instance(instance
))
925 return debug_ospf_nsm_common(vty
, 4, argc
, argv
);
929 static int no_debug_ospf_nsm_common(struct vty
*vty
, int arg_base
, int argc
,
930 struct cmd_token
**argv
)
933 if (vty
->node
== CONFIG_NODE
) {
934 if (argc
== arg_base
+ 0)
936 else if (argc
== arg_base
+ 1) {
937 if (strmatch(argv
[arg_base
]->text
, "status"))
938 DEBUG_OFF(nsm
, NSM_STATUS
);
939 else if (strmatch(argv
[arg_base
]->text
, "events"))
940 DEBUG_OFF(nsm
, NSM_EVENTS
);
941 else if (strmatch(argv
[arg_base
]->text
, "timers"))
942 DEBUG_OFF(nsm
, NSM_TIMERS
);
949 if (argc
== arg_base
+ 0)
950 TERM_DEBUG_OFF(nsm
, NSM
);
951 else if (argc
== arg_base
+ 1) {
952 if (strmatch(argv
[arg_base
]->text
, "status"))
953 TERM_DEBUG_OFF(nsm
, NSM_STATUS
);
954 else if (strmatch(argv
[arg_base
]->text
, "events"))
955 TERM_DEBUG_OFF(nsm
, NSM_EVENTS
);
956 else if (strmatch(argv
[arg_base
]->text
, "timers"))
957 TERM_DEBUG_OFF(nsm
, NSM_TIMERS
);
963 DEFUN (no_debug_ospf_nsm
,
964 no_debug_ospf_nsm_cmd
,
965 "no debug ospf nsm [<status|events|timers>]",
969 "OSPF Neighbor State Machine\n"
970 "NSM Status Information\n"
971 "NSM Event Information\n"
972 "NSM Timer Information\n")
974 return no_debug_ospf_nsm_common(vty
, 4, argc
, argv
);
978 DEFUN (no_debug_ospf_instance_nsm
,
979 no_debug_ospf_instance_nsm_cmd
,
980 "no debug ospf (1-65535) nsm [<status|events|timers>]",
985 "OSPF Neighbor State Machine\n"
986 "NSM Status Information\n"
987 "NSM Event Information\n"
988 "NSM Timer Information\n")
991 u_short instance
= 0;
993 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
994 if (!ospf_lookup_instance(instance
))
995 return CMD_NOT_MY_INSTANCE
;
997 return no_debug_ospf_nsm_common(vty
, 5, argc
, argv
);
1001 static int debug_ospf_lsa_common(struct vty
*vty
, int arg_base
, int argc
,
1002 struct cmd_token
**argv
)
1004 if (vty
->node
== CONFIG_NODE
) {
1005 if (argc
== arg_base
+ 0)
1007 else if (argc
== arg_base
+ 1) {
1008 if (strmatch(argv
[arg_base
]->text
, "generate"))
1009 DEBUG_ON(lsa
, LSA_GENERATE
);
1010 else if (strmatch(argv
[arg_base
]->text
, "flooding"))
1011 DEBUG_ON(lsa
, LSA_FLOODING
);
1012 else if (strmatch(argv
[arg_base
]->text
, "install"))
1013 DEBUG_ON(lsa
, LSA_INSTALL
);
1014 else if (strmatch(argv
[arg_base
]->text
, "refresh"))
1015 DEBUG_ON(lsa
, LSA_REFRESH
);
1022 if (argc
== arg_base
+ 0)
1023 TERM_DEBUG_ON(lsa
, LSA
);
1024 else if (argc
== arg_base
+ 1) {
1025 if (strmatch(argv
[arg_base
]->text
, "generate"))
1026 TERM_DEBUG_ON(lsa
, LSA_GENERATE
);
1027 else if (strmatch(argv
[arg_base
]->text
, "flooding"))
1028 TERM_DEBUG_ON(lsa
, LSA_FLOODING
);
1029 else if (strmatch(argv
[arg_base
]->text
, "install"))
1030 TERM_DEBUG_ON(lsa
, LSA_INSTALL
);
1031 else if (strmatch(argv
[arg_base
]->text
, "refresh"))
1032 TERM_DEBUG_ON(lsa
, LSA_REFRESH
);
1038 DEFUN (debug_ospf_lsa
,
1040 "debug ospf lsa [<generate|flooding|install|refresh>]",
1043 "OSPF Link State Advertisement\n"
1046 "LSA Install/Delete\n"
1049 return debug_ospf_lsa_common(vty
, 3, argc
, argv
);
1052 DEFUN (debug_ospf_instance_lsa
,
1053 debug_ospf_instance_lsa_cmd
,
1054 "debug ospf (1-65535) lsa [<generate|flooding|install|refresh>]",
1058 "OSPF Link State Advertisement\n"
1061 "LSA Install/Delete\n"
1065 u_short instance
= 0;
1067 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1068 if (!ospf_lookup_instance(instance
))
1069 return CMD_NOT_MY_INSTANCE
;
1071 return debug_ospf_lsa_common(vty
, 4, argc
, argv
);
1075 static int no_debug_ospf_lsa_common(struct vty
*vty
, int arg_base
, int argc
,
1076 struct cmd_token
**argv
)
1078 if (vty
->node
== CONFIG_NODE
) {
1079 if (argc
== arg_base
+ 0)
1080 DEBUG_OFF(lsa
, LSA
);
1081 else if (argc
== arg_base
+ 1) {
1082 if (strmatch(argv
[arg_base
]->text
, "generate"))
1083 DEBUG_OFF(lsa
, LSA_GENERATE
);
1084 else if (strmatch(argv
[arg_base
]->text
, "flooding"))
1085 DEBUG_OFF(lsa
, LSA_FLOODING
);
1086 else if (strmatch(argv
[arg_base
]->text
, "install"))
1087 DEBUG_OFF(lsa
, LSA_INSTALL
);
1088 else if (strmatch(argv
[arg_base
]->text
, "refresh"))
1089 DEBUG_OFF(lsa
, LSA_REFRESH
);
1096 if (argc
== arg_base
+ 0)
1097 TERM_DEBUG_OFF(lsa
, LSA
);
1098 else if (argc
== arg_base
+ 1) {
1099 if (strmatch(argv
[arg_base
]->text
, "generate"))
1100 TERM_DEBUG_OFF(lsa
, LSA_GENERATE
);
1101 else if (strmatch(argv
[arg_base
]->text
, "flooding"))
1102 TERM_DEBUG_OFF(lsa
, LSA_FLOODING
);
1103 else if (strmatch(argv
[arg_base
]->text
, "install"))
1104 TERM_DEBUG_OFF(lsa
, LSA_INSTALL
);
1105 else if (strmatch(argv
[arg_base
]->text
, "refresh"))
1106 TERM_DEBUG_OFF(lsa
, LSA_REFRESH
);
1112 DEFUN (no_debug_ospf_lsa
,
1113 no_debug_ospf_lsa_cmd
,
1114 "no debug ospf lsa [<generate|flooding|install|refresh>]",
1118 "OSPF Link State Advertisement\n"
1121 "LSA Install/Delete\n"
1124 return no_debug_ospf_lsa_common(vty
, 4, argc
, argv
);
1127 DEFUN (no_debug_ospf_instance_lsa
,
1128 no_debug_ospf_instance_lsa_cmd
,
1129 "no debug ospf (1-65535) lsa [<generate|flooding|install|refresh>]",
1134 "OSPF Link State Advertisement\n"
1137 "LSA Install/Delete\n"
1141 u_short instance
= 0;
1143 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1144 if (!ospf_lookup_instance(instance
))
1145 return CMD_NOT_MY_INSTANCE
;
1147 return no_debug_ospf_lsa_common(vty
, 5, argc
, argv
);
1151 static int debug_ospf_zebra_common(struct vty
*vty
, int arg_base
, int argc
,
1152 struct cmd_token
**argv
)
1154 if (vty
->node
== CONFIG_NODE
) {
1155 if (argc
== arg_base
+ 0)
1156 DEBUG_ON(zebra
, ZEBRA
);
1157 else if (argc
== arg_base
+ 1) {
1158 if (strmatch(argv
[arg_base
]->text
, "interface"))
1159 DEBUG_ON(zebra
, ZEBRA_INTERFACE
);
1160 else if (strmatch(argv
[arg_base
]->text
, "redistribute"))
1161 DEBUG_ON(zebra
, ZEBRA_REDISTRIBUTE
);
1168 if (argc
== arg_base
+ 0)
1169 TERM_DEBUG_ON(zebra
, ZEBRA
);
1170 else if (argc
== arg_base
+ 1) {
1171 if (strmatch(argv
[arg_base
]->text
, "interface"))
1172 TERM_DEBUG_ON(zebra
, ZEBRA_INTERFACE
);
1173 else if (strmatch(argv
[arg_base
]->text
, "redistribute"))
1174 TERM_DEBUG_ON(zebra
, ZEBRA_REDISTRIBUTE
);
1180 DEFUN (debug_ospf_zebra
,
1181 debug_ospf_zebra_cmd
,
1182 "debug ospf zebra [<interface|redistribute>]",
1187 "Zebra redistribute\n")
1189 return debug_ospf_zebra_common(vty
, 3, argc
, argv
);
1192 DEFUN (debug_ospf_instance_zebra
,
1193 debug_ospf_instance_zebra_cmd
,
1194 "debug ospf (1-65535) zebra [<interface|redistribute>]",
1200 "Zebra redistribute\n")
1203 u_short instance
= 0;
1205 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1206 if (!ospf_lookup_instance(instance
))
1207 return CMD_NOT_MY_INSTANCE
;
1209 return debug_ospf_zebra_common(vty
, 4, argc
, argv
);
1213 static int no_debug_ospf_zebra_common(struct vty
*vty
, int arg_base
, int argc
,
1214 struct cmd_token
**argv
)
1216 if (vty
->node
== CONFIG_NODE
) {
1217 if (argc
== arg_base
+ 0)
1218 DEBUG_OFF(zebra
, ZEBRA
);
1219 else if (argc
== arg_base
+ 1) {
1220 if (strmatch(argv
[arg_base
]->text
, "interface"))
1221 DEBUG_OFF(zebra
, ZEBRA_INTERFACE
);
1222 else if (strmatch(argv
[arg_base
]->text
, "redistribute"))
1223 DEBUG_OFF(zebra
, ZEBRA_REDISTRIBUTE
);
1230 if (argc
== arg_base
+ 0)
1231 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1232 else if (argc
== arg_base
+ 1) {
1233 if (strmatch(argv
[arg_base
]->text
, "interface"))
1234 TERM_DEBUG_OFF(zebra
, ZEBRA_INTERFACE
);
1235 else if (strmatch(argv
[arg_base
]->text
, "redistribute"))
1236 TERM_DEBUG_OFF(zebra
, ZEBRA_REDISTRIBUTE
);
1242 DEFUN (no_debug_ospf_zebra
,
1243 no_debug_ospf_zebra_cmd
,
1244 "no debug ospf zebra [<interface|redistribute>]",
1250 "Zebra redistribute\n")
1252 return no_debug_ospf_zebra_common(vty
, 4, argc
, argv
);
1255 DEFUN (no_debug_ospf_instance_zebra
,
1256 no_debug_ospf_instance_zebra_cmd
,
1257 "no debug ospf (1-65535) zebra [<interface|redistribute>]",
1264 "Zebra redistribute\n")
1267 u_short instance
= 0;
1269 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1270 if (!ospf_lookup_instance(instance
))
1273 return no_debug_ospf_zebra_common(vty
, 5, argc
, argv
);
1277 DEFUN (debug_ospf_event
,
1278 debug_ospf_event_cmd
,
1282 "OSPF event information\n")
1284 if (vty
->node
== CONFIG_NODE
)
1285 CONF_DEBUG_ON(event
, EVENT
);
1286 TERM_DEBUG_ON(event
, EVENT
);
1290 DEFUN (no_debug_ospf_event
,
1291 no_debug_ospf_event_cmd
,
1292 "no debug ospf event",
1296 "OSPF event information\n")
1298 if (vty
->node
== CONFIG_NODE
)
1299 CONF_DEBUG_OFF(event
, EVENT
);
1300 TERM_DEBUG_OFF(event
, EVENT
);
1304 DEFUN (debug_ospf_instance_event
,
1305 debug_ospf_instance_event_cmd
,
1306 "debug ospf (1-65535) event",
1310 "OSPF event information\n")
1313 u_short instance
= 0;
1315 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1316 if (!ospf_lookup_instance(instance
))
1319 if (vty
->node
== CONFIG_NODE
)
1320 CONF_DEBUG_ON(event
, EVENT
);
1321 TERM_DEBUG_ON(event
, EVENT
);
1325 DEFUN (no_debug_ospf_instance_event
,
1326 no_debug_ospf_instance_event_cmd
,
1327 "no debug ospf (1-65535) event",
1332 "OSPF event information\n")
1335 u_short instance
= 0;
1337 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1338 if (!ospf_lookup_instance(instance
))
1341 if (vty
->node
== CONFIG_NODE
)
1342 CONF_DEBUG_OFF(event
, EVENT
);
1343 TERM_DEBUG_OFF(event
, EVENT
);
1347 DEFUN (debug_ospf_nssa
,
1348 debug_ospf_nssa_cmd
,
1352 "OSPF nssa information\n")
1354 if (vty
->node
== CONFIG_NODE
)
1355 CONF_DEBUG_ON(nssa
, NSSA
);
1356 TERM_DEBUG_ON(nssa
, NSSA
);
1360 DEFUN (no_debug_ospf_nssa
,
1361 no_debug_ospf_nssa_cmd
,
1362 "no debug ospf nssa",
1366 "OSPF nssa information\n")
1368 if (vty
->node
== CONFIG_NODE
)
1369 CONF_DEBUG_OFF(nssa
, NSSA
);
1370 TERM_DEBUG_OFF(nssa
, NSSA
);
1374 DEFUN (debug_ospf_instance_nssa
,
1375 debug_ospf_instance_nssa_cmd
,
1376 "debug ospf (1-65535) nssa",
1380 "OSPF nssa information\n")
1383 u_short instance
= 0;
1385 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1386 if (!ospf_lookup_instance(instance
))
1389 if (vty
->node
== CONFIG_NODE
)
1390 CONF_DEBUG_ON(nssa
, NSSA
);
1391 TERM_DEBUG_ON(nssa
, NSSA
);
1395 DEFUN (no_debug_ospf_instance_nssa
,
1396 no_debug_ospf_instance_nssa_cmd
,
1397 "no debug ospf (1-65535) nssa",
1402 "OSPF nssa information\n")
1405 u_short instance
= 0;
1407 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1408 if (!ospf_lookup_instance(instance
))
1411 if (vty
->node
== CONFIG_NODE
)
1412 CONF_DEBUG_OFF(nssa
, NSSA
);
1413 TERM_DEBUG_OFF(nssa
, NSSA
);
1417 DEFUN (debug_ospf_te
,
1422 "OSPF-TE information\n")
1424 if (vty
->node
== CONFIG_NODE
)
1425 CONF_DEBUG_ON(te
, TE
);
1426 TERM_DEBUG_ON(te
, TE
);
1430 DEFUN (no_debug_ospf_te
,
1431 no_debug_ospf_te_cmd
,
1436 "OSPF-TE information\n")
1438 if (vty
->node
== CONFIG_NODE
)
1439 CONF_DEBUG_OFF(te
, TE
);
1440 TERM_DEBUG_OFF(te
, TE
);
1444 DEFUN (no_debug_ospf
,
1451 int flag
= OSPF_DEBUG_SEND
| OSPF_DEBUG_RECV
| OSPF_DEBUG_DETAIL
;
1454 if (vty
->node
== CONFIG_NODE
) {
1455 CONF_DEBUG_OFF(event
, EVENT
);
1456 CONF_DEBUG_OFF(nssa
, NSSA
);
1457 DEBUG_OFF(ism
, ISM_EVENTS
);
1458 DEBUG_OFF(ism
, ISM_STATUS
);
1459 DEBUG_OFF(ism
, ISM_TIMERS
);
1460 DEBUG_OFF(lsa
, LSA
);
1461 DEBUG_OFF(lsa
, LSA_FLOODING
);
1462 DEBUG_OFF(lsa
, LSA_GENERATE
);
1463 DEBUG_OFF(lsa
, LSA_INSTALL
);
1464 DEBUG_OFF(lsa
, LSA_REFRESH
);
1465 DEBUG_OFF(nsm
, NSM
);
1466 DEBUG_OFF(nsm
, NSM_EVENTS
);
1467 DEBUG_OFF(nsm
, NSM_STATUS
);
1468 DEBUG_OFF(nsm
, NSM_TIMERS
);
1469 DEBUG_OFF(zebra
, ZEBRA
);
1470 DEBUG_OFF(zebra
, ZEBRA_INTERFACE
);
1471 DEBUG_OFF(zebra
, ZEBRA_REDISTRIBUTE
);
1473 for (i
= 0; i
< 5; i
++)
1474 DEBUG_PACKET_OFF(i
, flag
);
1477 for (i
= 0; i
< 5; i
++)
1478 TERM_DEBUG_PACKET_OFF(i
, flag
);
1480 TERM_DEBUG_OFF(event
, EVENT
);
1481 TERM_DEBUG_OFF(ism
, ISM
);
1482 TERM_DEBUG_OFF(ism
, ISM_EVENTS
);
1483 TERM_DEBUG_OFF(ism
, ISM_STATUS
);
1484 TERM_DEBUG_OFF(ism
, ISM_TIMERS
);
1485 TERM_DEBUG_OFF(lsa
, LSA
);
1486 TERM_DEBUG_OFF(lsa
, LSA_FLOODING
);
1487 TERM_DEBUG_OFF(lsa
, LSA_GENERATE
);
1488 TERM_DEBUG_OFF(lsa
, LSA_INSTALL
);
1489 TERM_DEBUG_OFF(lsa
, LSA_REFRESH
);
1490 TERM_DEBUG_OFF(nsm
, NSM
);
1491 TERM_DEBUG_OFF(nsm
, NSM_EVENTS
);
1492 TERM_DEBUG_OFF(nsm
, NSM_STATUS
);
1493 TERM_DEBUG_OFF(nsm
, NSM_TIMERS
);
1494 TERM_DEBUG_OFF(nssa
, NSSA
);
1495 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1496 TERM_DEBUG_OFF(zebra
, ZEBRA_INTERFACE
);
1497 TERM_DEBUG_OFF(zebra
, ZEBRA_REDISTRIBUTE
);
1502 static int show_debugging_ospf_common(struct vty
*vty
, struct ospf
*ospf
)
1507 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
1509 vty_out(vty
, "OSPF debugging status:\n");
1511 /* Show debug status for events. */
1512 if (IS_DEBUG_OSPF(event
, EVENT
))
1513 vty_out(vty
, " OSPF event debugging is on\n");
1515 /* Show debug status for ISM. */
1516 if (IS_DEBUG_OSPF(ism
, ISM
) == OSPF_DEBUG_ISM
)
1517 vty_out(vty
, " OSPF ISM debugging is on\n");
1519 if (IS_DEBUG_OSPF(ism
, ISM_STATUS
))
1520 vty_out(vty
, " OSPF ISM status debugging is on\n");
1521 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
1522 vty_out(vty
, " OSPF ISM event debugging is on\n");
1523 if (IS_DEBUG_OSPF(ism
, ISM_TIMERS
))
1524 vty_out(vty
, " OSPF ISM timer debugging is on\n");
1527 /* Show debug status for NSM. */
1528 if (IS_DEBUG_OSPF(nsm
, NSM
) == OSPF_DEBUG_NSM
)
1529 vty_out(vty
, " OSPF NSM debugging is on\n");
1531 if (IS_DEBUG_OSPF(nsm
, NSM_STATUS
))
1532 vty_out(vty
, " OSPF NSM status debugging is on\n");
1533 if (IS_DEBUG_OSPF(nsm
, NSM_EVENTS
))
1534 vty_out(vty
, " OSPF NSM event debugging is on\n");
1535 if (IS_DEBUG_OSPF(nsm
, NSM_TIMERS
))
1536 vty_out(vty
, " OSPF NSM timer debugging is on\n");
1539 /* Show debug status for OSPF Packets. */
1540 for (i
= 0; i
< 5; i
++)
1541 if (IS_DEBUG_OSPF_PACKET(i
, SEND
)
1542 && IS_DEBUG_OSPF_PACKET(i
, RECV
)) {
1543 vty_out(vty
, " OSPF packet %s%s debugging is on\n",
1544 lookup_msg(ospf_packet_type_str
, i
+ 1, NULL
),
1545 IS_DEBUG_OSPF_PACKET(i
, DETAIL
) ? " detail"
1548 if (IS_DEBUG_OSPF_PACKET(i
, SEND
))
1550 " OSPF packet %s send%s debugging is on\n",
1551 lookup_msg(ospf_packet_type_str
, i
+ 1,
1553 IS_DEBUG_OSPF_PACKET(i
, DETAIL
)
1556 if (IS_DEBUG_OSPF_PACKET(i
, RECV
))
1558 " OSPF packet %s receive%s debugging is on\n",
1559 lookup_msg(ospf_packet_type_str
, i
+ 1,
1561 IS_DEBUG_OSPF_PACKET(i
, DETAIL
)
1566 /* Show debug status for OSPF LSAs. */
1567 if (IS_DEBUG_OSPF(lsa
, LSA
) == OSPF_DEBUG_LSA
)
1568 vty_out(vty
, " OSPF LSA debugging is on\n");
1570 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1571 vty_out(vty
, " OSPF LSA generation debugging is on\n");
1572 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
1573 vty_out(vty
, " OSPF LSA flooding debugging is on\n");
1574 if (IS_DEBUG_OSPF(lsa
, LSA_INSTALL
))
1575 vty_out(vty
, " OSPF LSA install debugging is on\n");
1576 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
1577 vty_out(vty
, " OSPF LSA refresh debugging is on\n");
1580 /* Show debug status for Zebra. */
1581 if (IS_DEBUG_OSPF(zebra
, ZEBRA
) == OSPF_DEBUG_ZEBRA
)
1582 vty_out(vty
, " OSPF Zebra debugging is on\n");
1584 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
1586 " OSPF Zebra interface debugging is on\n");
1587 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
1589 " OSPF Zebra redistribute debugging is on\n");
1592 /* Show debug status for NSSA. */
1593 if (IS_DEBUG_OSPF(nssa
, NSSA
) == OSPF_DEBUG_NSSA
)
1594 vty_out(vty
, " OSPF NSSA debugging is on\n");
1601 DEFUN_NOSH (show_debugging_ospf
,
1602 show_debugging_ospf_cmd
,
1603 "show debugging [ospf]",
1608 struct ospf
*ospf
= NULL
;
1610 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1614 return show_debugging_ospf_common(vty
, ospf
);
1617 DEFUN_NOSH (show_debugging_ospf_instance
,
1618 show_debugging_ospf_instance_cmd
,
1619 "show debugging ospf (1-65535)",
1627 u_short instance
= 0;
1629 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1630 if ((ospf
= ospf_lookup_instance(instance
)) == NULL
)
1633 return show_debugging_ospf_common(vty
, ospf
);
1637 static struct cmd_node debug_node
= {
1638 DEBUG_NODE
, "", 1 /* VTYSH */
1641 static int config_write_debug(struct vty
*vty
)
1646 const char *type_str
[] = {"hello", "dd", "ls-request", "ls-update",
1648 const char *detail_str
[] = {
1649 "", " send", " recv", "",
1650 " detail", " send detail", " recv detail", " detail"};
1656 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1661 sprintf(str
, " %d", ospf
->instance
);
1663 /* debug ospf ism (status|events|timers). */
1664 if (IS_CONF_DEBUG_OSPF(ism
, ISM
) == OSPF_DEBUG_ISM
)
1665 vty_out(vty
, "debug ospf%s ism\n", str
);
1667 if (IS_CONF_DEBUG_OSPF(ism
, ISM_STATUS
))
1668 vty_out(vty
, "debug ospf%s ism status\n", str
);
1669 if (IS_CONF_DEBUG_OSPF(ism
, ISM_EVENTS
))
1670 vty_out(vty
, "debug ospf%s ism event\n", str
);
1671 if (IS_CONF_DEBUG_OSPF(ism
, ISM_TIMERS
))
1672 vty_out(vty
, "debug ospf%s ism timer\n", str
);
1675 /* debug ospf nsm (status|events|timers). */
1676 if (IS_CONF_DEBUG_OSPF(nsm
, NSM
) == OSPF_DEBUG_NSM
)
1677 vty_out(vty
, "debug ospf%s nsm\n", str
);
1679 if (IS_CONF_DEBUG_OSPF(nsm
, NSM_STATUS
))
1680 vty_out(vty
, "debug ospf%s nsm status\n", str
);
1681 if (IS_CONF_DEBUG_OSPF(nsm
, NSM_EVENTS
))
1682 vty_out(vty
, "debug ospf%s nsm event\n", str
);
1683 if (IS_CONF_DEBUG_OSPF(nsm
, NSM_TIMERS
))
1684 vty_out(vty
, "debug ospf%s nsm timer\n", str
);
1687 /* debug ospf lsa (generate|flooding|install|refresh). */
1688 if (IS_CONF_DEBUG_OSPF(lsa
, LSA
) == OSPF_DEBUG_LSA
)
1689 vty_out(vty
, "debug ospf%s lsa\n", str
);
1691 if (IS_CONF_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1692 vty_out(vty
, "debug ospf%s lsa generate\n", str
);
1693 if (IS_CONF_DEBUG_OSPF(lsa
, LSA_FLOODING
))
1694 vty_out(vty
, "debug ospf%s lsa flooding\n", str
);
1695 if (IS_CONF_DEBUG_OSPF(lsa
, LSA_INSTALL
))
1696 vty_out(vty
, "debug ospf%s lsa install\n", str
);
1697 if (IS_CONF_DEBUG_OSPF(lsa
, LSA_REFRESH
))
1698 vty_out(vty
, "debug ospf%s lsa refresh\n", str
);
1703 /* debug ospf zebra (interface|redistribute). */
1704 if (IS_CONF_DEBUG_OSPF(zebra
, ZEBRA
) == OSPF_DEBUG_ZEBRA
)
1705 vty_out(vty
, "debug ospf%s zebra\n", str
);
1707 if (IS_CONF_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
1708 vty_out(vty
, "debug ospf%s zebra interface\n", str
);
1709 if (IS_CONF_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
1710 vty_out(vty
, "debug ospf%s zebra redistribute\n", str
);
1715 /* debug ospf event. */
1716 if (IS_CONF_DEBUG_OSPF(event
, EVENT
) == OSPF_DEBUG_EVENT
) {
1717 vty_out(vty
, "debug ospf%s event\n", str
);
1721 /* debug ospf nssa. */
1722 if (IS_CONF_DEBUG_OSPF(nssa
, NSSA
) == OSPF_DEBUG_NSSA
) {
1723 vty_out(vty
, "debug ospf%s nssa\n", str
);
1727 /* debug ospf packet all detail. */
1728 r
= OSPF_DEBUG_SEND_RECV
| OSPF_DEBUG_DETAIL
;
1729 for (i
= 0; i
< 5; i
++)
1730 r
&= conf_debug_ospf_packet
[i
]
1731 & (OSPF_DEBUG_SEND_RECV
| OSPF_DEBUG_DETAIL
);
1732 if (r
== (OSPF_DEBUG_SEND_RECV
| OSPF_DEBUG_DETAIL
)) {
1733 vty_out(vty
, "debug ospf%s packet all detail\n", str
);
1737 /* debug ospf packet all. */
1738 r
= OSPF_DEBUG_SEND_RECV
;
1739 for (i
= 0; i
< 5; i
++)
1740 r
&= conf_debug_ospf_packet
[i
] & OSPF_DEBUG_SEND_RECV
;
1741 if (r
== OSPF_DEBUG_SEND_RECV
) {
1742 vty_out(vty
, "debug ospf%s packet all\n", str
);
1743 for (i
= 0; i
< 5; i
++)
1744 if (conf_debug_ospf_packet
[i
] & OSPF_DEBUG_DETAIL
)
1745 vty_out(vty
, "debug ospf%s packet %s detail\n",
1750 /* debug ospf packet (hello|dd|ls-request|ls-update|ls-ack)
1751 (send|recv) (detail). */
1752 for (i
= 0; i
< 5; i
++) {
1753 if (conf_debug_ospf_packet
[i
] == 0)
1756 vty_out(vty
, "debug ospf%s packet %s%s\n", str
, type_str
[i
],
1757 detail_str
[conf_debug_ospf_packet
[i
]]);
1764 /* Initialize debug commands. */
1767 install_node(&debug_node
, config_write_debug
);
1769 install_element(ENABLE_NODE
, &show_debugging_ospf_cmd
);
1770 install_element(ENABLE_NODE
, &debug_ospf_ism_cmd
);
1771 install_element(ENABLE_NODE
, &debug_ospf_nsm_cmd
);
1772 install_element(ENABLE_NODE
, &debug_ospf_lsa_cmd
);
1773 install_element(ENABLE_NODE
, &debug_ospf_zebra_cmd
);
1774 install_element(ENABLE_NODE
, &debug_ospf_event_cmd
);
1775 install_element(ENABLE_NODE
, &debug_ospf_nssa_cmd
);
1776 install_element(ENABLE_NODE
, &debug_ospf_te_cmd
);
1777 install_element(ENABLE_NODE
, &no_debug_ospf_ism_cmd
);
1778 install_element(ENABLE_NODE
, &no_debug_ospf_nsm_cmd
);
1779 install_element(ENABLE_NODE
, &no_debug_ospf_lsa_cmd
);
1780 install_element(ENABLE_NODE
, &no_debug_ospf_zebra_cmd
);
1781 install_element(ENABLE_NODE
, &no_debug_ospf_event_cmd
);
1782 install_element(ENABLE_NODE
, &no_debug_ospf_nssa_cmd
);
1783 install_element(ENABLE_NODE
, &no_debug_ospf_te_cmd
);
1785 install_element(ENABLE_NODE
, &show_debugging_ospf_instance_cmd
);
1786 install_element(ENABLE_NODE
, &debug_ospf_packet_cmd
);
1787 install_element(ENABLE_NODE
, &no_debug_ospf_packet_cmd
);
1789 install_element(ENABLE_NODE
, &debug_ospf_instance_nsm_cmd
);
1790 install_element(ENABLE_NODE
, &debug_ospf_instance_lsa_cmd
);
1791 install_element(ENABLE_NODE
, &debug_ospf_instance_zebra_cmd
);
1792 install_element(ENABLE_NODE
, &debug_ospf_instance_event_cmd
);
1793 install_element(ENABLE_NODE
, &debug_ospf_instance_nssa_cmd
);
1794 install_element(ENABLE_NODE
, &no_debug_ospf_instance_nsm_cmd
);
1795 install_element(ENABLE_NODE
, &no_debug_ospf_instance_lsa_cmd
);
1796 install_element(ENABLE_NODE
, &no_debug_ospf_instance_zebra_cmd
);
1797 install_element(ENABLE_NODE
, &no_debug_ospf_instance_event_cmd
);
1798 install_element(ENABLE_NODE
, &no_debug_ospf_instance_nssa_cmd
);
1799 install_element(ENABLE_NODE
, &no_debug_ospf_cmd
);
1801 install_element(CONFIG_NODE
, &debug_ospf_packet_cmd
);
1802 install_element(CONFIG_NODE
, &no_debug_ospf_packet_cmd
);
1803 install_element(CONFIG_NODE
, &debug_ospf_ism_cmd
);
1804 install_element(CONFIG_NODE
, &no_debug_ospf_ism_cmd
);
1806 install_element(CONFIG_NODE
, &debug_ospf_nsm_cmd
);
1807 install_element(CONFIG_NODE
, &debug_ospf_lsa_cmd
);
1808 install_element(CONFIG_NODE
, &debug_ospf_zebra_cmd
);
1809 install_element(CONFIG_NODE
, &debug_ospf_event_cmd
);
1810 install_element(CONFIG_NODE
, &debug_ospf_nssa_cmd
);
1811 install_element(CONFIG_NODE
, &debug_ospf_te_cmd
);
1812 install_element(CONFIG_NODE
, &no_debug_ospf_nsm_cmd
);
1813 install_element(CONFIG_NODE
, &no_debug_ospf_lsa_cmd
);
1814 install_element(CONFIG_NODE
, &no_debug_ospf_zebra_cmd
);
1815 install_element(CONFIG_NODE
, &no_debug_ospf_event_cmd
);
1816 install_element(CONFIG_NODE
, &no_debug_ospf_nssa_cmd
);
1817 install_element(CONFIG_NODE
, &no_debug_ospf_te_cmd
);
1819 install_element(CONFIG_NODE
, &debug_ospf_instance_nsm_cmd
);
1820 install_element(CONFIG_NODE
, &debug_ospf_instance_lsa_cmd
);
1821 install_element(CONFIG_NODE
, &debug_ospf_instance_zebra_cmd
);
1822 install_element(CONFIG_NODE
, &debug_ospf_instance_event_cmd
);
1823 install_element(CONFIG_NODE
, &debug_ospf_instance_nssa_cmd
);
1824 install_element(CONFIG_NODE
, &no_debug_ospf_instance_nsm_cmd
);
1825 install_element(CONFIG_NODE
, &no_debug_ospf_instance_lsa_cmd
);
1826 install_element(CONFIG_NODE
, &no_debug_ospf_instance_zebra_cmd
);
1827 install_element(CONFIG_NODE
, &no_debug_ospf_instance_event_cmd
);
1828 install_element(CONFIG_NODE
, &no_debug_ospf_instance_nssa_cmd
);
1829 install_element(CONFIG_NODE
, &no_debug_ospf_cmd
);