blob: 9c5208dacc4c9b42aec1af20307d11d32b8ab2c4 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP-4, BGP-4+ packet debug routine
2 Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
gdt5e4fa162004-03-16 14:38:36 +000023#include <lib/version.h>
paul718e3742002-12-13 20:15:29 +000024#include "prefix.h"
25#include "linklist.h"
26#include "stream.h"
27#include "command.h"
28#include "str.h"
29#include "log.h"
30#include "sockunion.h"
31
32#include "bgpd/bgpd.h"
33#include "bgpd/bgp_aspath.h"
34#include "bgpd/bgp_route.h"
35#include "bgpd/bgp_attr.h"
36#include "bgpd/bgp_debug.h"
37#include "bgpd/bgp_community.h"
38
39unsigned long conf_bgp_debug_fsm;
40unsigned long conf_bgp_debug_events;
41unsigned long conf_bgp_debug_packet;
42unsigned long conf_bgp_debug_filter;
43unsigned long conf_bgp_debug_keepalive;
44unsigned long conf_bgp_debug_update;
45unsigned long conf_bgp_debug_normal;
46
47unsigned long term_bgp_debug_fsm;
48unsigned long term_bgp_debug_events;
49unsigned long term_bgp_debug_packet;
50unsigned long term_bgp_debug_filter;
51unsigned long term_bgp_debug_keepalive;
52unsigned long term_bgp_debug_update;
53unsigned long term_bgp_debug_normal;
54
55/* messages for BGP-4 status */
56struct message bgp_status_msg[] =
57{
58 { 0, "null" },
59 { Idle, "Idle" },
60 { Connect, "Connect" },
61 { Active, "Active" },
62 { OpenSent, "OpenSent" },
63 { OpenConfirm, "OpenConfirm" },
64 { Established, "Established" },
65};
66int bgp_status_msg_max = BGP_STATUS_MAX;
67
68/* BGP message type string. */
69char *bgp_type_str[] =
70{
71 NULL,
72 "OPEN",
73 "UPDATE",
74 "NOTIFICATION",
75 "KEEPALIVE",
76 "ROUTE-REFRESH",
77 "CAPABILITY"
78};
79
80/* message for BGP-4 Notify */
81struct message bgp_notify_msg[] =
82{
83 { 0, "" },
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"},
90 { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
91};
92int bgp_notify_msg_max = BGP_NOTIFY_MAX;
93
94struct message bgp_notify_head_msg[] =
95{
96 { 0, "null"},
hasso3950fda2004-05-20 10:22:49 +000097 { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
98 { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
99 { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}
paul718e3742002-12-13 20:15:29 +0000100};
101int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
102
103struct message bgp_notify_open_msg[] =
104{
105 { 0, "null" },
hasso3950fda2004-05-20 10:22:49 +0000106 { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number" },
107 { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
108 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
109 { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
110 { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
111 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
112 { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
paul718e3742002-12-13 20:15:29 +0000113};
114int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
115
116struct message bgp_notify_update_msg[] =
117{
118 { 0, "null"},
hasso3950fda2004-05-20 10:22:49 +0000119 { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
120 { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
121 { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
122 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
123 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
124 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
125 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
126 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
127 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
128 { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
129 { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
paul718e3742002-12-13 20:15:29 +0000130};
131int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
132
133struct message bgp_notify_cease_msg[] =
134{
135 { 0, ""},
hasso3950fda2004-05-20 10:22:49 +0000136 { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
137 { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
138 { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
139 { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
140 { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
141 { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
142 { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
143 { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
paul718e3742002-12-13 20:15:29 +0000144};
145int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
146
147struct message bgp_notify_capability_msg[] =
148{
149 { 0, "null" },
hasso3950fda2004-05-20 10:22:49 +0000150 { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
151 { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
152 { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
paul718e3742002-12-13 20:15:29 +0000153};
154int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
155
156/* Origin strings. */
157char *bgp_origin_str[] = {"i","e","?"};
158char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
159
160/* Dump attribute. */
paule01f9cb2004-07-09 17:48:53 +0000161int
paul718e3742002-12-13 20:15:29 +0000162bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
163{
paul718e3742002-12-13 20:15:29 +0000164 if (! attr)
paule01f9cb2004-07-09 17:48:53 +0000165 return 0;
paul718e3742002-12-13 20:15:29 +0000166
paule01f9cb2004-07-09 17:48:53 +0000167 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
168 snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
169
170 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
171 snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
172 bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +0000173
174#ifdef HAVE_IPV6
175 {
176 char addrbuf[BUFSIZ];
177
178 /* Add MP case. */
179 if (attr->mp_nexthop_len == 16 || attr->mp_nexthop_len == 32)
180 snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
181 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
182 addrbuf, BUFSIZ));
183
184 if (attr->mp_nexthop_len == 32)
185 snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
186 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
187 addrbuf, BUFSIZ));
188 }
189#endif /* HAVE_IPV6 */
190
paule01f9cb2004-07-09 17:48:53 +0000191 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
paul718e3742002-12-13 20:15:29 +0000192 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d",
193 attr->local_pref);
194
paule01f9cb2004-07-09 17:48:53 +0000195 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
paul718e3742002-12-13 20:15:29 +0000196 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %d",
197 attr->med);
198
paule01f9cb2004-07-09 17:48:53 +0000199 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)))
paul718e3742002-12-13 20:15:29 +0000200 snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
201 community_str (attr->community));
202
paule01f9cb2004-07-09 17:48:53 +0000203 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
paul718e3742002-12-13 20:15:29 +0000204 snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
205
paule01f9cb2004-07-09 17:48:53 +0000206 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
paul718e3742002-12-13 20:15:29 +0000207 snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %d %s",
208 attr->aggregator_as, inet_ntoa (attr->aggregator_addr));
209
paule01f9cb2004-07-09 17:48:53 +0000210 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
paul718e3742002-12-13 20:15:29 +0000211 snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
212 inet_ntoa (attr->originator_id));
213
paule01f9cb2004-07-09 17:48:53 +0000214 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
paul718e3742002-12-13 20:15:29 +0000215 {
216 int i;
217
paule01f9cb2004-07-09 17:48:53 +0000218 snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
paul718e3742002-12-13 20:15:29 +0000219 for (i = 0; i < attr->cluster->length / 4; i++)
paule01f9cb2004-07-09 17:48:53 +0000220 snprintf (buf + strlen (buf), size - strlen (buf), " %s",
paul718e3742002-12-13 20:15:29 +0000221 inet_ntoa (attr->cluster->list[i]));
222 }
223
paule01f9cb2004-07-09 17:48:53 +0000224 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
paul718e3742002-12-13 20:15:29 +0000225 snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
226 aspath_print (attr->aspath));
paule01f9cb2004-07-09 17:48:53 +0000227
228 if (strlen (buf) > 1)
229 return 1;
230 else
231 return 0;
paul718e3742002-12-13 20:15:29 +0000232}
233
234/* dump notify packet */
235void
236bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, char *direct)
237{
238 char *subcode_str;
239
240 subcode_str = "";
241
242 switch (bgp_notify->code)
243 {
244 case BGP_NOTIFY_HEADER_ERR:
245 subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode);
246 break;
247 case BGP_NOTIFY_OPEN_ERR:
248 subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode);
249 break;
250 case BGP_NOTIFY_UPDATE_ERR:
251 subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode);
252 break;
253 case BGP_NOTIFY_HOLD_ERR:
254 subcode_str = "";
255 break;
256 case BGP_NOTIFY_FSM_ERR:
257 subcode_str = "";
258 break;
259 case BGP_NOTIFY_CEASE:
260 subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode);
261 break;
262 case BGP_NOTIFY_CAPABILITY_ERR:
263 subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode);
264 break;
265 }
hasso3950fda2004-05-20 10:22:49 +0000266
267 if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
268 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
269 strcmp (direct, "received") == 0 ? "received from" : "sent to",
270 peer->host, bgp_notify->code, bgp_notify->subcode,
271 LOOKUP (bgp_notify_msg, bgp_notify->code),
272 subcode_str, bgp_notify->length,
273 bgp_notify->data ? bgp_notify->data : "");
274 else if (BGP_DEBUG (normal, NORMAL))
paul718e3742002-12-13 20:15:29 +0000275 plog_info (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
276 peer ? peer->host : "",
277 direct, bgp_notify->code, bgp_notify->subcode,
278 LOOKUP (bgp_notify_msg, bgp_notify->code),
279 subcode_str, bgp_notify->length,
280 bgp_notify->data ? bgp_notify->data : "");
281}
282
283/* Debug option setting interface. */
284unsigned long bgp_debug_option = 0;
285
286int
287debug (unsigned int option)
288{
289 return bgp_debug_option & option;
290}
291
292DEFUN (debug_bgp_fsm,
293 debug_bgp_fsm_cmd,
294 "debug bgp fsm",
295 DEBUG_STR
296 BGP_STR
297 "BGP Finite State Machine\n")
298{
299 if (vty->node == CONFIG_NODE)
300 DEBUG_ON (fsm, FSM);
301 else
302 {
303 TERM_DEBUG_ON (fsm, FSM);
304 vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
305 }
306 return CMD_SUCCESS;
307}
308
309DEFUN (no_debug_bgp_fsm,
310 no_debug_bgp_fsm_cmd,
311 "no debug bgp fsm",
312 NO_STR
313 DEBUG_STR
314 BGP_STR
315 "Finite State Machine\n")
316{
317 if (vty->node == CONFIG_NODE)
318 DEBUG_OFF (fsm, FSM);
319 else
320 {
321 TERM_DEBUG_OFF (fsm, FSM);
322 vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
323 }
324 return CMD_SUCCESS;
325}
326
327ALIAS (no_debug_bgp_fsm,
328 undebug_bgp_fsm_cmd,
329 "undebug bgp fsm",
330 UNDEBUG_STR
331 DEBUG_STR
332 BGP_STR
333 "Finite State Machine\n")
334
335DEFUN (debug_bgp_events,
336 debug_bgp_events_cmd,
337 "debug bgp events",
338 DEBUG_STR
339 BGP_STR
340 "BGP events\n")
341{
342 if (vty->node == CONFIG_NODE)
343 DEBUG_ON (events, EVENTS);
344 else
345 {
346 TERM_DEBUG_ON (events, EVENTS);
347 vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
348 }
349 return CMD_SUCCESS;
350}
351
352DEFUN (no_debug_bgp_events,
353 no_debug_bgp_events_cmd,
354 "no debug bgp events",
355 NO_STR
356 DEBUG_STR
357 BGP_STR
358 "BGP events\n")
359{
360 if (vty->node == CONFIG_NODE)
361 DEBUG_OFF (events, EVENTS);
362 else
363 {
364 TERM_DEBUG_OFF (events, EVENTS);
365 vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
366 }
367 return CMD_SUCCESS;
368}
369
370ALIAS (no_debug_bgp_events,
371 undebug_bgp_events_cmd,
372 "undebug bgp events",
373 UNDEBUG_STR
374 BGP_STR
375 "BGP events\n")
376
377DEFUN (debug_bgp_filter,
378 debug_bgp_filter_cmd,
379 "debug bgp filters",
380 DEBUG_STR
381 BGP_STR
382 "BGP filters\n")
383{
384 if (vty->node == CONFIG_NODE)
385 DEBUG_ON (filter, FILTER);
386 else
387 {
388 TERM_DEBUG_ON (filter, FILTER);
389 vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
390 }
391 return CMD_SUCCESS;
392}
393
394DEFUN (no_debug_bgp_filter,
395 no_debug_bgp_filter_cmd,
396 "no debug bgp filters",
397 NO_STR
398 DEBUG_STR
399 BGP_STR
400 "BGP filters\n")
401{
402 if (vty->node == CONFIG_NODE)
403 DEBUG_OFF (filter, FILTER);
404 else
405 {
406 TERM_DEBUG_OFF (filter, FILTER);
407 vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
408 }
409 return CMD_SUCCESS;
410}
411
412ALIAS (no_debug_bgp_filter,
413 undebug_bgp_filter_cmd,
414 "undebug bgp filters",
415 UNDEBUG_STR
416 BGP_STR
417 "BGP filters\n")
418
419DEFUN (debug_bgp_keepalive,
420 debug_bgp_keepalive_cmd,
421 "debug bgp keepalives",
422 DEBUG_STR
423 BGP_STR
424 "BGP keepalives\n")
425{
426 if (vty->node == CONFIG_NODE)
427 DEBUG_ON (keepalive, KEEPALIVE);
428 else
429 {
430 TERM_DEBUG_ON (keepalive, KEEPALIVE);
431 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
432 }
433 return CMD_SUCCESS;
434}
435
436DEFUN (no_debug_bgp_keepalive,
437 no_debug_bgp_keepalive_cmd,
438 "no debug bgp keepalives",
439 NO_STR
440 DEBUG_STR
441 BGP_STR
442 "BGP keepalives\n")
443{
444 if (vty->node == CONFIG_NODE)
445 DEBUG_OFF (keepalive, KEEPALIVE);
446 else
447 {
448 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
449 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
450 }
451 return CMD_SUCCESS;
452}
453
454ALIAS (no_debug_bgp_keepalive,
455 undebug_bgp_keepalive_cmd,
456 "undebug bgp keepalives",
457 UNDEBUG_STR
458 BGP_STR
459 "BGP keepalives\n")
460
461DEFUN (debug_bgp_update,
462 debug_bgp_update_cmd,
463 "debug bgp updates",
464 DEBUG_STR
465 BGP_STR
466 "BGP updates\n")
467{
468 if (vty->node == CONFIG_NODE)
469 {
470 DEBUG_ON (update, UPDATE_IN);
471 DEBUG_ON (update, UPDATE_OUT);
472 }
473 else
474 {
475 TERM_DEBUG_ON (update, UPDATE_IN);
476 TERM_DEBUG_ON (update, UPDATE_OUT);
477 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
478 }
479 return CMD_SUCCESS;
480}
481
482DEFUN (debug_bgp_update_direct,
483 debug_bgp_update_direct_cmd,
484 "debug bgp updates (in|out)",
485 DEBUG_STR
486 BGP_STR
487 "BGP updates\n"
488 "Inbound updates\n"
489 "Outbound updates\n")
490{
491 if (vty->node == CONFIG_NODE)
492 {
493 if (strncmp ("i", argv[0], 1) == 0)
494 {
495 DEBUG_OFF (update, UPDATE_OUT);
496 DEBUG_ON (update, UPDATE_IN);
497 }
498 else
499 {
500 DEBUG_OFF (update, UPDATE_IN);
501 DEBUG_ON (update, UPDATE_OUT);
502 }
503 }
504 else
505 {
506 if (strncmp ("i", argv[0], 1) == 0)
507 {
508 TERM_DEBUG_OFF (update, UPDATE_OUT);
509 TERM_DEBUG_ON (update, UPDATE_IN);
510 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
511 }
512 else
513 {
514 TERM_DEBUG_OFF (update, UPDATE_IN);
515 TERM_DEBUG_ON (update, UPDATE_OUT);
516 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
517 }
518 }
519 return CMD_SUCCESS;
520}
521
522DEFUN (no_debug_bgp_update,
523 no_debug_bgp_update_cmd,
524 "no debug bgp updates",
525 NO_STR
526 DEBUG_STR
527 BGP_STR
528 "BGP updates\n")
529{
530 if (vty->node == CONFIG_NODE)
531 {
532 DEBUG_OFF (update, UPDATE_IN);
533 DEBUG_OFF (update, UPDATE_OUT);
534 }
535 else
536 {
537 TERM_DEBUG_OFF (update, UPDATE_IN);
538 TERM_DEBUG_OFF (update, UPDATE_OUT);
539 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
540 }
541 return CMD_SUCCESS;
542}
543
544ALIAS (no_debug_bgp_update,
545 undebug_bgp_update_cmd,
546 "undebug bgp updates",
547 UNDEBUG_STR
548 BGP_STR
549 "BGP updates\n")
550
551DEFUN (debug_bgp_normal,
552 debug_bgp_normal_cmd,
553 "debug bgp",
554 DEBUG_STR
555 BGP_STR)
556{
557 if (vty->node == CONFIG_NODE)
558 DEBUG_ON (normal, NORMAL);
559 else
560 {
561 TERM_DEBUG_ON (normal, NORMAL);
562 vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
563 }
564 return CMD_SUCCESS;
565}
566
567DEFUN (no_debug_bgp_normal,
568 no_debug_bgp_normal_cmd,
569 "no debug bgp",
570 NO_STR
571 DEBUG_STR
572 BGP_STR)
573{
574 if (vty->node == CONFIG_NODE)
575 DEBUG_OFF (normal, NORMAL);
576 else
577 {
578 TERM_DEBUG_OFF (normal, NORMAL);
579 vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
580 }
581 return CMD_SUCCESS;
582}
583
584ALIAS (no_debug_bgp_normal,
585 undebug_bgp_normal_cmd,
586 "undebug bgp",
587 UNDEBUG_STR
588 BGP_STR)
589
590DEFUN (no_debug_bgp_all,
591 no_debug_bgp_all_cmd,
592 "no debug all bgp",
593 NO_STR
594 DEBUG_STR
595 "Enable all debugging\n"
596 BGP_STR)
597{
598 TERM_DEBUG_OFF (normal, NORMAL);
599 TERM_DEBUG_OFF (events, EVENTS);
600 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
601 TERM_DEBUG_OFF (update, UPDATE_IN);
602 TERM_DEBUG_OFF (update, UPDATE_OUT);
603 TERM_DEBUG_OFF (fsm, FSM);
604 TERM_DEBUG_OFF (filter, FILTER);
605 vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
606
607 return CMD_SUCCESS;
608}
609
610ALIAS (no_debug_bgp_all,
611 undebug_bgp_all_cmd,
612 "undebug all bgp",
613 UNDEBUG_STR
614 "Enable all debugging\n"
615 BGP_STR)
616
617DEFUN (show_debugging_bgp,
618 show_debugging_bgp_cmd,
619 "show debugging bgp",
620 SHOW_STR
621 DEBUG_STR
622 BGP_STR)
623{
624 vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
625
626 if (BGP_DEBUG (normal, NORMAL))
627 vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE);
628 if (BGP_DEBUG (events, EVENTS))
629 vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE);
630 if (BGP_DEBUG (keepalive, KEEPALIVE))
631 vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE);
632 if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
633 vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE);
634 else if (BGP_DEBUG (update, UPDATE_IN))
635 vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
636 else if (BGP_DEBUG (update, UPDATE_OUT))
637 vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
638 if (BGP_DEBUG (fsm, FSM))
639 vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE);
640 if (BGP_DEBUG (filter, FILTER))
641 vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE);
642 vty_out (vty, "%s", VTY_NEWLINE);
643 return CMD_SUCCESS;
644}
645
646int
647bgp_config_write_debug (struct vty *vty)
648{
649 int write = 0;
650
651 if (CONF_BGP_DEBUG (normal, NORMAL))
652 {
653 vty_out (vty, "debug bgp%s", VTY_NEWLINE);
654 write++;
655 }
656
657 if (CONF_BGP_DEBUG (events, EVENTS))
658 {
659 vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
660 write++;
661 }
662
663 if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
664 {
665 vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
666 write++;
667 }
668
669 if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
670 {
671 vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
672 write++;
673 }
674 else if (CONF_BGP_DEBUG (update, UPDATE_IN))
675 {
676 vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
677 write++;
678 }
679 else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
680 {
681 vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
682 write++;
683 }
684
685 if (CONF_BGP_DEBUG (fsm, FSM))
686 {
687 vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
688 write++;
689 }
690
691 if (CONF_BGP_DEBUG (filter, FILTER))
692 {
693 vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
694 write++;
695 }
696
697 return write;
698}
699
700struct cmd_node debug_node =
701{
702 DEBUG_NODE,
703 "",
704 1
705};
706
707void
708bgp_debug_init ()
709{
710 install_node (&debug_node, bgp_config_write_debug);
711
712 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
713
714 install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
715 install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
716 install_element (ENABLE_NODE, &debug_bgp_events_cmd);
717 install_element (CONFIG_NODE, &debug_bgp_events_cmd);
718 install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
719 install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
720 install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
721 install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
722 install_element (ENABLE_NODE, &debug_bgp_update_cmd);
723 install_element (CONFIG_NODE, &debug_bgp_update_cmd);
724 install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
725 install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
726 install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
727 install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
728
729 install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
730 install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
731 install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
732 install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
733 install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
734 install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
735 install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
736 install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
737 install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
738 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
739 install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
740 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
741 install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
742 install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
743 install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
744 install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
745 install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
746 install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
747 install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
748 install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
749}