Tomato 1.28
[tomato.git] / release / src / router / zebra / bgpd / bgp_debug.c
blob5bf58d1e0b83357d940b7a8266df8f23d20f135c
1 /* BGP-4, BGP-4+ packet debug routine
2 * Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
22 #include <zebra.h>
24 #include "version.h"
25 #include "prefix.h"
26 #include "linklist.h"
27 #include "stream.h"
28 #include "command.h"
29 #include "str.h"
30 #include "log.h"
31 #include "sockunion.h"
33 #include "bgpd/bgpd.h"
34 #include "bgpd/bgp_aspath.h"
35 #include "bgpd/bgp_route.h"
36 #include "bgpd/bgp_attr.h"
37 #include "bgpd/bgp_debug.h"
38 #include "bgpd/bgp_community.h"
40 unsigned long conf_bgp_debug_fsm;
41 unsigned long conf_bgp_debug_events;
42 unsigned long conf_bgp_debug_packet;
43 unsigned long conf_bgp_debug_filter;
44 unsigned long conf_bgp_debug_keepalive;
45 unsigned long conf_bgp_debug_update;
46 unsigned long conf_bgp_debug_normal;
48 unsigned long term_bgp_debug_fsm;
49 unsigned long term_bgp_debug_events;
50 unsigned long term_bgp_debug_packet;
51 unsigned long term_bgp_debug_filter;
52 unsigned long term_bgp_debug_keepalive;
53 unsigned long term_bgp_debug_update;
54 unsigned long term_bgp_debug_normal;
56 /* messages for BGP-4 status */
57 struct message bgp_status_msg[] =
59 { 0, "null" },
60 { Idle, "Idle" },
61 { Connect, "Connect" },
62 { Active, "Active" },
63 { OpenSent, "OpenSent" },
64 { OpenConfirm, "OpenConfirm" },
65 { Established, "Established" },
67 int bgp_status_msg_max = BGP_STATUS_MAX;
69 /* BGP message type string. */
70 char *bgp_type_str[] =
72 NULL,
73 "OPEN",
74 "UPDATE",
75 "NOTIFICATION",
76 "KEEPALIVE",
77 "ROUTE-REFRESH"
80 /* message for BGP-4 Notify */
81 struct message bgp_notify_msg[] =
83 { 0, "null" },
84 { BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
85 { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
86 { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
87 { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
88 { BGP_NOTIFY_FSM_ERR, "Finite State Machine Error"},
89 { BGP_NOTIFY_CEASE, "Cease"},
91 int bgp_notify_msg_max = BGP_NOTIFY_MAX;
93 struct message bgp_notify_head_msg[] =
95 { 0, "null"},
96 { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized."},
97 { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length."},
98 { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type."}
100 int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
102 struct message bgp_notify_open_msg[] =
104 { 0, "null" },
105 { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number." },
106 { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS."},
107 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier."},
108 { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter."},
109 { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure."},
110 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time."},
111 { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability."},
113 int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
115 struct message bgp_notify_update_msg[] =
117 { 0, "null"},
118 { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List."},
119 { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute."},
120 { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute."},
121 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error."},
122 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error."},
123 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute."},
124 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop."},
125 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute."},
126 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error."},
127 { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field."},
128 { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH."},
130 int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
132 /* Origin strings. */
133 char *bgp_origin_str[] = {"i","e","?"};
134 char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
136 #if 0
137 /* Dump bgp header information. */
138 void
139 bgp_dump_header (struct bgp_header *bgp_header)
141 int flag = 0;
143 switch (bgp_header->type)
145 case BGP_MSG_OPEN:
146 if (IS_SET(dump_open, DUMP_DETAIL))
147 flag = 1;
148 break;
149 case BGP_MSG_UPDATE:
150 if (IS_SET(dump_open, DUMP_DETAIL))
151 flag = 1;
152 break;
153 case BGP_MSG_KEEPALIVE:
154 if (IS_SET(dump_keepalive, DUMP_DETAIL))
155 flag = 1;
156 break;
157 default:
158 break;
161 if (flag)
162 zlog (NULL, LOG_INFO, "Head: %s(%d) length(%d)",
163 bgp_type_str[bgp_header->type],
164 bgp_header->type, bgp_header->length);
166 #endif
168 /* Dump attribute. */
169 void
170 bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
172 if (attr == NULL)
173 return;
175 snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
176 snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
177 bgp_origin_str[attr->origin]);
179 #ifdef HAVE_IPV6
181 char addrbuf[BUFSIZ];
183 /* Add MP case. */
184 if (attr->mp_nexthop_len == 16 || attr->mp_nexthop_len == 32)
185 snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
186 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
187 addrbuf, BUFSIZ));
189 if (attr->mp_nexthop_len == 32)
190 snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
191 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
192 addrbuf, BUFSIZ));
194 #endif /* HAVE_IPV6 */
196 if (peer_sort (peer) == BGP_PEER_IBGP)
198 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d",
199 attr->local_pref);
202 if (attr->med)
204 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %d",
205 attr->med);
208 if (attr->community)
210 snprintf (buf + strlen (buf), size - strlen (buf), ", community%s",
211 community_print (attr->community));
214 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
215 snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
217 if (attr->aggregator_as)
219 snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %d %s",
220 attr->aggregator_as, inet_ntoa (attr->aggregator_addr));
223 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
225 snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
226 inet_ntoa (attr->originator_id));
229 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST))
231 int i;
233 snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist ");
234 for (i = 0; i < attr->cluster->length / 4; i++)
235 snprintf (buf + strlen (buf), size - strlen (buf), "%s",
236 inet_ntoa (attr->cluster->list[i]));
239 if (attr->aspath)
241 snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
242 aspath_print (attr->aspath));
246 /* dump notify packet */
247 void
248 bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, char *direct)
250 char *subcode_str;
252 subcode_str = "";
254 switch (bgp_notify->code)
256 case BGP_NOTIFY_HEADER_ERR:
257 subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode);
258 break;
259 case BGP_NOTIFY_OPEN_ERR:
260 subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode);
261 break;
262 case BGP_NOTIFY_UPDATE_ERR:
263 subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode);
264 break;
265 case BGP_NOTIFY_HOLD_ERR:
266 subcode_str = "";
267 break;
268 case BGP_NOTIFY_FSM_ERR:
269 subcode_str = "";
270 break;
271 case BGP_NOTIFY_CEASE:
272 subcode_str = "";
273 break;
275 if (BGP_DEBUG (normal, NORMAL))
276 plog_info (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
277 peer ? peer->host : "",
278 direct, bgp_notify->code, bgp_notify->subcode,
279 LOOKUP (bgp_notify_msg, bgp_notify->code),
280 subcode_str, bgp_notify->length,
281 bgp_notify->data ? bgp_notify->data : "");
284 #if 0
285 /* Open packet dump */
286 void
287 bgp_open_dump (struct bgp_open *bgp_open, struct peer *peer, int direct)
289 /* decide whether dump or not */
290 if (direct == PACKET_RECV &&
291 IS_SET(dump_open, DUMP_SEND)) {
293 if (IS_SET(dump_open, DUMP_DETAIL)) {
294 /* detail */
295 zlog (peer->log, LOG_INFO, "Open: peer(%s) version(%d) AS(%d) holdtime(%d)"
296 " ident(%lu) optlen(%d)",
297 peer->host,
298 bgp_open->version, bgp_open->asno, bgp_open->holdtime,
299 bgp_open->ident, bgp_open->optlen);
300 } else {
301 /* normal */
302 zlog (peer->log, LOG_INFO, "Open: peer(%s)", peer->host);
306 #endif
308 /* Dump BGP open packet. */
309 void
310 bgp_packet_open_dump (struct stream *s)
312 printf ("BGP open ");
313 printf ("version: %d ", stream_getc (s));
314 printf ("as: %d ", stream_getw (s));
315 printf ("holdtime: %d ", stream_getw (s));
316 printf ("ident: %d\n", stream_getl (s));
318 /* Open message option. */
319 printf ("opt parm len: %d\n", stream_getc (s));
322 void
323 bgp_packet_notify_dump (struct stream *s)
325 struct bgp_notify bgp_notify;
327 bgp_notify.code = stream_getc (s);
328 bgp_notify.subcode = stream_getc (s);
329 bgp_notify_print (NULL, &bgp_notify, "received");
332 /* Dump bgp update packet. */
333 void
334 bgp_update_dump (struct stream *s)
336 u_char *endp;
337 bgp_size_t unfeasible_len;
338 bgp_size_t attr_total_len;
340 unfeasible_len = stream_getw (s);
341 printf ("Unfeasible length: %d\n", unfeasible_len);
343 stream_forward (s, unfeasible_len);
345 attr_total_len = stream_getw (s);
346 printf ("Attribute length: %d\n", attr_total_len);
348 endp = STREAM_PNT (s) + attr_total_len;
350 while (STREAM_PNT (s) < endp)
352 u_char flag;
353 u_char type;
354 bgp_size_t length;
356 flag = stream_getc (s);
357 type = stream_getc (s);
359 printf ("flag: %d\n", flag);
360 printf ("type: %d\n", type);
362 if (flag & BGP_ATTR_FLAG_EXTLEN)
363 length = stream_getw (s);
364 else
365 length = stream_getc (s);
366 #if 0
367 printf ("length %d\n", length);
369 stream_forward (s, length);
370 #else
372 int p1;
373 printf ("length %d // ", length);
374 for(p1=length; p1 ; p1--) {
375 printf("0x%02x ",(unsigned char) stream_getc (s) );
377 printf("\n");
379 #endif
382 /* Debug dump of bgp packet. */
383 void
384 bgp_packet_dump (struct stream *s)
386 int i;
387 u_char type;
388 u_int16_t size;
389 unsigned long sp;
391 /* Preserve pointer. */
392 sp = stream_get_getp (s);
393 stream_set_getp (s, 0);
395 /* Marker dump. */
396 printf ("BGP packet marker : ");
397 for (i = 0; i < BGP_MARKER_SIZE; i++)
398 printf ("%x ", stream_getc (s));
399 printf ("\n");
401 /* BGP packet size. */
402 size = stream_getw (s);
403 printf ("BGP packet size : %d\n", size);
405 /* BGP packet type. */
406 type = stream_getc (s);
407 printf ("BGP packet type : %s (%d)\n", bgp_type_str[type], type);
409 switch (type)
411 case BGP_MSG_OPEN:
412 bgp_packet_open_dump (s);
413 break;
414 case BGP_MSG_KEEPALIVE:
415 assert (size == BGP_HEADER_SIZE);
416 return;
417 break;
418 case BGP_MSG_UPDATE:
419 bgp_update_dump (s);
420 break;
421 case BGP_MSG_NOTIFY:
422 bgp_packet_notify_dump (s);
423 break;
425 stream_set_getp (s, sp);
428 /* Debug option setting interface. */
429 unsigned long bgp_debug_option = 0;
431 int
432 debug (unsigned int option)
434 return bgp_debug_option & option;
437 DEFUN (debug_bgp_fsm,
438 debug_bgp_fsm_cmd,
439 "debug bgp fsm",
440 DEBUG_STR
441 BGP_STR
442 "BGP Finite State Machine\n")
444 if (vty->node == CONFIG_NODE)
445 DEBUG_ON (fsm, FSM);
446 else
448 TERM_DEBUG_ON (fsm, FSM);
449 vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
451 return CMD_SUCCESS;
454 DEFUN (no_debug_bgp_fsm,
455 no_debug_bgp_fsm_cmd,
456 "no debug bgp fsm",
457 NO_STR
458 DEBUG_STR
459 BGP_STR
460 "Finite State Machine\n")
462 if (vty->node == CONFIG_NODE)
463 DEBUG_OFF (fsm, FSM);
464 else
466 TERM_DEBUG_OFF (fsm, FSM);
467 vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
469 return CMD_SUCCESS;
472 ALIAS (no_debug_bgp_fsm,
473 undebug_bgp_fsm_cmd,
474 "undebug bgp fsm",
475 UNDEBUG_STR
476 DEBUG_STR
477 BGP_STR
478 "Finite State Machine\n")
480 DEFUN (debug_bgp_events,
481 debug_bgp_events_cmd,
482 "debug bgp events",
483 DEBUG_STR
484 BGP_STR
485 "BGP events\n")
487 if (vty->node == CONFIG_NODE)
488 DEBUG_ON (events, EVENTS);
489 else
491 TERM_DEBUG_ON (events, EVENTS);
492 vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
494 return CMD_SUCCESS;
497 DEFUN (no_debug_bgp_events,
498 no_debug_bgp_events_cmd,
499 "no debug bgp events",
500 NO_STR
501 DEBUG_STR
502 BGP_STR
503 "BGP events\n")
505 if (vty->node == CONFIG_NODE)
506 DEBUG_OFF (events, EVENTS);
507 else
509 TERM_DEBUG_OFF (events, EVENTS);
510 vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
512 return CMD_SUCCESS;
515 ALIAS (no_debug_bgp_events,
516 undebug_bgp_events_cmd,
517 "undebug bgp events",
518 UNDEBUG_STR
519 BGP_STR
520 "BGP events\n")
522 DEFUN (debug_bgp_filter,
523 debug_bgp_filter_cmd,
524 "debug bgp filters",
525 DEBUG_STR
526 BGP_STR
527 "BGP filters\n")
529 if (vty->node == CONFIG_NODE)
530 DEBUG_ON (filter, FILTER);
531 else
533 TERM_DEBUG_ON (filter, FILTER);
534 vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
536 return CMD_SUCCESS;
539 DEFUN (no_debug_bgp_filter,
540 no_debug_bgp_filter_cmd,
541 "no debug bgp filters",
542 NO_STR
543 DEBUG_STR
544 BGP_STR
545 "BGP filters\n")
547 if (vty->node == CONFIG_NODE)
548 DEBUG_OFF (filter, FILTER);
549 else
551 TERM_DEBUG_OFF (filter, FILTER);
552 vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
554 return CMD_SUCCESS;
557 ALIAS (no_debug_bgp_filter,
558 undebug_bgp_filter_cmd,
559 "undebug bgp filters",
560 UNDEBUG_STR
561 BGP_STR
562 "BGP filters\n")
564 DEFUN (debug_bgp_keepalive,
565 debug_bgp_keepalive_cmd,
566 "debug bgp keepalives",
567 DEBUG_STR
568 BGP_STR
569 "BGP keepalives\n")
571 if (vty->node == CONFIG_NODE)
572 DEBUG_ON (keepalive, KEEPALIVE);
573 else
575 TERM_DEBUG_ON (keepalive, KEEPALIVE);
576 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
578 return CMD_SUCCESS;
581 DEFUN (no_debug_bgp_keepalive,
582 no_debug_bgp_keepalive_cmd,
583 "no debug bgp keepalives",
584 NO_STR
585 DEBUG_STR
586 BGP_STR
587 "BGP keepalives\n")
589 if (vty->node == CONFIG_NODE)
590 DEBUG_OFF (keepalive, KEEPALIVE);
591 else
593 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
594 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
596 return CMD_SUCCESS;
599 ALIAS (no_debug_bgp_keepalive,
600 undebug_bgp_keepalive_cmd,
601 "undebug bgp keepalives",
602 UNDEBUG_STR
603 BGP_STR
604 "BGP keepalives\n")
606 DEFUN (debug_bgp_update,
607 debug_bgp_update_cmd,
608 "debug bgp updates",
609 DEBUG_STR
610 BGP_STR
611 "BGP updates\n")
613 if (vty->node == CONFIG_NODE)
615 DEBUG_ON (update, UPDATE_IN);
616 DEBUG_ON (update, UPDATE_OUT);
618 else
620 TERM_DEBUG_ON (update, UPDATE_IN);
621 TERM_DEBUG_ON (update, UPDATE_OUT);
622 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
624 return CMD_SUCCESS;
627 DEFUN (debug_bgp_update_direct,
628 debug_bgp_update_direct_cmd,
629 "debug bgp updates (in|out)",
630 DEBUG_STR
631 BGP_STR
632 "BGP updates\n"
633 "Inbound updates\n"
634 "Outbound updates\n")
636 if (vty->node == CONFIG_NODE)
638 if (strncmp ("i", argv[0], 1) == 0)
640 DEBUG_OFF (update, UPDATE_OUT);
641 DEBUG_ON (update, UPDATE_IN);
643 else
645 DEBUG_OFF (update, UPDATE_IN);
646 DEBUG_ON (update, UPDATE_OUT);
649 else
651 if (strncmp ("i", argv[0], 1) == 0)
653 TERM_DEBUG_OFF (update, UPDATE_OUT);
654 TERM_DEBUG_ON (update, UPDATE_IN);
655 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
657 else
659 TERM_DEBUG_OFF (update, UPDATE_IN);
660 TERM_DEBUG_ON (update, UPDATE_OUT);
661 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
664 return CMD_SUCCESS;
667 DEFUN (no_debug_bgp_update,
668 no_debug_bgp_update_cmd,
669 "no debug bgp updates",
670 NO_STR
671 DEBUG_STR
672 BGP_STR
673 "BGP updates\n")
675 if (vty->node == CONFIG_NODE)
677 DEBUG_OFF (update, UPDATE_IN);
678 DEBUG_OFF (update, UPDATE_OUT);
680 else
682 TERM_DEBUG_OFF (update, UPDATE_IN);
683 TERM_DEBUG_OFF (update, UPDATE_OUT);
684 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
686 return CMD_SUCCESS;
689 ALIAS (no_debug_bgp_update,
690 undebug_bgp_update_cmd,
691 "undebug bgp updates",
692 UNDEBUG_STR
693 BGP_STR
694 "BGP updates\n")
696 DEFUN (debug_bgp_normal,
697 debug_bgp_normal_cmd,
698 "debug bgp",
699 DEBUG_STR
700 BGP_STR)
702 if (vty->node == CONFIG_NODE)
703 DEBUG_ON (normal, NORMAL);
704 else
706 TERM_DEBUG_ON (normal, NORMAL);
707 vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
709 return CMD_SUCCESS;
712 DEFUN (no_debug_bgp_normal,
713 no_debug_bgp_normal_cmd,
714 "no debug bgp",
715 NO_STR
716 DEBUG_STR
717 BGP_STR)
719 if (vty->node == CONFIG_NODE)
720 DEBUG_OFF (normal, NORMAL);
721 else
723 TERM_DEBUG_OFF (normal, NORMAL);
724 vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
726 return CMD_SUCCESS;
729 ALIAS (no_debug_bgp_normal,
730 undebug_bgp_normal_cmd,
731 "undebug bgp",
732 UNDEBUG_STR
733 BGP_STR)
735 DEFUN (no_debug_bgp_all,
736 no_debug_bgp_all_cmd,
737 "no debug all bgp",
738 NO_STR
739 DEBUG_STR
740 "Enable all debugging\n"
741 BGP_STR)
743 TERM_DEBUG_OFF (normal, NORMAL);
744 TERM_DEBUG_OFF (events, EVENTS);
745 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
746 TERM_DEBUG_OFF (update, UPDATE_IN);
747 TERM_DEBUG_OFF (update, UPDATE_OUT);
748 TERM_DEBUG_OFF (fsm, FSM);
749 TERM_DEBUG_OFF (filter, FILTER);
750 vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
752 return CMD_SUCCESS;
755 ALIAS (no_debug_bgp_all,
756 undebug_bgp_all_cmd,
757 "undebug all bgp",
758 UNDEBUG_STR
759 "Enable all debugging\n"
760 BGP_STR)
762 DEFUN (show_debugging_bgp,
763 show_debugging_bgp_cmd,
764 "show debugging bgp",
765 SHOW_STR
766 DEBUG_STR
767 BGP_STR)
769 vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
771 if (BGP_DEBUG (normal, NORMAL))
772 vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE);
773 if (BGP_DEBUG (events, EVENTS))
774 vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE);
775 if (BGP_DEBUG (keepalive, KEEPALIVE))
776 vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE);
777 if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
778 vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE);
779 else if (BGP_DEBUG (update, UPDATE_IN))
780 vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
781 else if (BGP_DEBUG (update, UPDATE_OUT))
782 vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
783 if (BGP_DEBUG (fsm, FSM))
784 vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE);
785 if (BGP_DEBUG (filter, FILTER))
786 vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE);
787 vty_out (vty, "%s", VTY_NEWLINE);
788 return CMD_SUCCESS;
792 config_write_debug (struct vty *vty)
794 int write = 0;
796 if (CONF_BGP_DEBUG (normal, NORMAL))
798 vty_out (vty, "debug bgp%s", VTY_NEWLINE);
799 write++;
802 if (CONF_BGP_DEBUG (events, EVENTS))
804 vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
805 write++;
808 if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
810 vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
811 write++;
814 if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
816 vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
817 write++;
819 else if (CONF_BGP_DEBUG (update, UPDATE_IN))
821 vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
822 write++;
824 else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
826 vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
827 write++;
830 if (CONF_BGP_DEBUG (fsm, FSM))
832 vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
833 write++;
836 if (CONF_BGP_DEBUG (filter, FILTER))
838 vty_out (vty, "debug bgp filter%s", VTY_NEWLINE);
839 write++;
842 return write;
845 struct cmd_node debug_node =
847 DEBUG_NODE,
852 void
853 bgp_debug_init ()
855 install_node (&debug_node, config_write_debug);
857 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
859 install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
860 install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
861 install_element (ENABLE_NODE, &debug_bgp_events_cmd);
862 install_element (CONFIG_NODE, &debug_bgp_events_cmd);
863 install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
864 install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
865 install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
866 install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
867 install_element (ENABLE_NODE, &debug_bgp_update_cmd);
868 install_element (CONFIG_NODE, &debug_bgp_update_cmd);
869 install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
870 install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
871 install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
872 install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
874 install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
875 install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
876 install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
877 install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
878 install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
879 install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
880 install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
881 install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
882 install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
883 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
884 install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
885 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
886 install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
887 install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
888 install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
889 install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
890 install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
891 install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
892 install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
893 install_element (ENABLE_NODE, &undebug_bgp_all_cmd);