blob: 1b398ee8b1b681334809827701c99cb2d18169dd [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. */
paulfd79ac92004-10-13 05:06:08 +000069const char *bgp_type_str[] =
paul718e3742002-12-13 20:15:29 +000070{
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. */
paulfd79ac92004-10-13 05:06:08 +0000157const char *bgp_origin_str[] = {"i","e","?"};
158const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
paul718e3742002-12-13 20:15:29 +0000159
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
paulfd79ac92004-10-13 05:06:08 +0000236bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
237 const char *direct)
paul718e3742002-12-13 20:15:29 +0000238{
paulfd79ac92004-10-13 05:06:08 +0000239 const char *subcode_str;
paul718e3742002-12-13 20:15:29 +0000240
241 subcode_str = "";
242
243 switch (bgp_notify->code)
244 {
245 case BGP_NOTIFY_HEADER_ERR:
246 subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode);
247 break;
248 case BGP_NOTIFY_OPEN_ERR:
249 subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode);
250 break;
251 case BGP_NOTIFY_UPDATE_ERR:
252 subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode);
253 break;
254 case BGP_NOTIFY_HOLD_ERR:
255 subcode_str = "";
256 break;
257 case BGP_NOTIFY_FSM_ERR:
258 subcode_str = "";
259 break;
260 case BGP_NOTIFY_CEASE:
261 subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode);
262 break;
263 case BGP_NOTIFY_CAPABILITY_ERR:
264 subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode);
265 break;
266 }
hasso3950fda2004-05-20 10:22:49 +0000267
268 if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
269 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
270 strcmp (direct, "received") == 0 ? "received from" : "sent to",
271 peer->host, bgp_notify->code, bgp_notify->subcode,
272 LOOKUP (bgp_notify_msg, bgp_notify->code),
273 subcode_str, bgp_notify->length,
274 bgp_notify->data ? bgp_notify->data : "");
275 else if (BGP_DEBUG (normal, NORMAL))
ajs557865c2004-12-08 19:59:11 +0000276 plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
paul718e3742002-12-13 20:15:29 +0000277 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 : "");
282}
283
284/* Debug option setting interface. */
285unsigned long bgp_debug_option = 0;
286
287int
288debug (unsigned int option)
289{
290 return bgp_debug_option & option;
291}
292
293DEFUN (debug_bgp_fsm,
294 debug_bgp_fsm_cmd,
295 "debug bgp fsm",
296 DEBUG_STR
297 BGP_STR
298 "BGP Finite State Machine\n")
299{
300 if (vty->node == CONFIG_NODE)
301 DEBUG_ON (fsm, FSM);
302 else
303 {
304 TERM_DEBUG_ON (fsm, FSM);
305 vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
306 }
307 return CMD_SUCCESS;
308}
309
310DEFUN (no_debug_bgp_fsm,
311 no_debug_bgp_fsm_cmd,
312 "no debug bgp fsm",
313 NO_STR
314 DEBUG_STR
315 BGP_STR
316 "Finite State Machine\n")
317{
318 if (vty->node == CONFIG_NODE)
319 DEBUG_OFF (fsm, FSM);
320 else
321 {
322 TERM_DEBUG_OFF (fsm, FSM);
323 vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
324 }
325 return CMD_SUCCESS;
326}
327
328ALIAS (no_debug_bgp_fsm,
329 undebug_bgp_fsm_cmd,
330 "undebug bgp fsm",
331 UNDEBUG_STR
332 DEBUG_STR
333 BGP_STR
334 "Finite State Machine\n")
335
336DEFUN (debug_bgp_events,
337 debug_bgp_events_cmd,
338 "debug bgp events",
339 DEBUG_STR
340 BGP_STR
341 "BGP events\n")
342{
343 if (vty->node == CONFIG_NODE)
344 DEBUG_ON (events, EVENTS);
345 else
346 {
347 TERM_DEBUG_ON (events, EVENTS);
348 vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
349 }
350 return CMD_SUCCESS;
351}
352
353DEFUN (no_debug_bgp_events,
354 no_debug_bgp_events_cmd,
355 "no debug bgp events",
356 NO_STR
357 DEBUG_STR
358 BGP_STR
359 "BGP events\n")
360{
361 if (vty->node == CONFIG_NODE)
362 DEBUG_OFF (events, EVENTS);
363 else
364 {
365 TERM_DEBUG_OFF (events, EVENTS);
366 vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
367 }
368 return CMD_SUCCESS;
369}
370
371ALIAS (no_debug_bgp_events,
372 undebug_bgp_events_cmd,
373 "undebug bgp events",
374 UNDEBUG_STR
375 BGP_STR
376 "BGP events\n")
377
378DEFUN (debug_bgp_filter,
379 debug_bgp_filter_cmd,
380 "debug bgp filters",
381 DEBUG_STR
382 BGP_STR
383 "BGP filters\n")
384{
385 if (vty->node == CONFIG_NODE)
386 DEBUG_ON (filter, FILTER);
387 else
388 {
389 TERM_DEBUG_ON (filter, FILTER);
390 vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
391 }
392 return CMD_SUCCESS;
393}
394
395DEFUN (no_debug_bgp_filter,
396 no_debug_bgp_filter_cmd,
397 "no debug bgp filters",
398 NO_STR
399 DEBUG_STR
400 BGP_STR
401 "BGP filters\n")
402{
403 if (vty->node == CONFIG_NODE)
404 DEBUG_OFF (filter, FILTER);
405 else
406 {
407 TERM_DEBUG_OFF (filter, FILTER);
408 vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
409 }
410 return CMD_SUCCESS;
411}
412
413ALIAS (no_debug_bgp_filter,
414 undebug_bgp_filter_cmd,
415 "undebug bgp filters",
416 UNDEBUG_STR
417 BGP_STR
418 "BGP filters\n")
419
420DEFUN (debug_bgp_keepalive,
421 debug_bgp_keepalive_cmd,
422 "debug bgp keepalives",
423 DEBUG_STR
424 BGP_STR
425 "BGP keepalives\n")
426{
427 if (vty->node == CONFIG_NODE)
428 DEBUG_ON (keepalive, KEEPALIVE);
429 else
430 {
431 TERM_DEBUG_ON (keepalive, KEEPALIVE);
432 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
433 }
434 return CMD_SUCCESS;
435}
436
437DEFUN (no_debug_bgp_keepalive,
438 no_debug_bgp_keepalive_cmd,
439 "no debug bgp keepalives",
440 NO_STR
441 DEBUG_STR
442 BGP_STR
443 "BGP keepalives\n")
444{
445 if (vty->node == CONFIG_NODE)
446 DEBUG_OFF (keepalive, KEEPALIVE);
447 else
448 {
449 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
450 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
451 }
452 return CMD_SUCCESS;
453}
454
455ALIAS (no_debug_bgp_keepalive,
456 undebug_bgp_keepalive_cmd,
457 "undebug bgp keepalives",
458 UNDEBUG_STR
459 BGP_STR
460 "BGP keepalives\n")
461
462DEFUN (debug_bgp_update,
463 debug_bgp_update_cmd,
464 "debug bgp updates",
465 DEBUG_STR
466 BGP_STR
467 "BGP updates\n")
468{
469 if (vty->node == CONFIG_NODE)
470 {
471 DEBUG_ON (update, UPDATE_IN);
472 DEBUG_ON (update, UPDATE_OUT);
473 }
474 else
475 {
476 TERM_DEBUG_ON (update, UPDATE_IN);
477 TERM_DEBUG_ON (update, UPDATE_OUT);
478 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
479 }
480 return CMD_SUCCESS;
481}
482
483DEFUN (debug_bgp_update_direct,
484 debug_bgp_update_direct_cmd,
485 "debug bgp updates (in|out)",
486 DEBUG_STR
487 BGP_STR
488 "BGP updates\n"
489 "Inbound updates\n"
490 "Outbound updates\n")
491{
492 if (vty->node == CONFIG_NODE)
493 {
494 if (strncmp ("i", argv[0], 1) == 0)
495 {
496 DEBUG_OFF (update, UPDATE_OUT);
497 DEBUG_ON (update, UPDATE_IN);
498 }
499 else
500 {
501 DEBUG_OFF (update, UPDATE_IN);
502 DEBUG_ON (update, UPDATE_OUT);
503 }
504 }
505 else
506 {
507 if (strncmp ("i", argv[0], 1) == 0)
508 {
509 TERM_DEBUG_OFF (update, UPDATE_OUT);
510 TERM_DEBUG_ON (update, UPDATE_IN);
511 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
512 }
513 else
514 {
515 TERM_DEBUG_OFF (update, UPDATE_IN);
516 TERM_DEBUG_ON (update, UPDATE_OUT);
517 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
518 }
519 }
520 return CMD_SUCCESS;
521}
522
523DEFUN (no_debug_bgp_update,
524 no_debug_bgp_update_cmd,
525 "no debug bgp updates",
526 NO_STR
527 DEBUG_STR
528 BGP_STR
529 "BGP updates\n")
530{
531 if (vty->node == CONFIG_NODE)
532 {
533 DEBUG_OFF (update, UPDATE_IN);
534 DEBUG_OFF (update, UPDATE_OUT);
535 }
536 else
537 {
538 TERM_DEBUG_OFF (update, UPDATE_IN);
539 TERM_DEBUG_OFF (update, UPDATE_OUT);
540 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
541 }
542 return CMD_SUCCESS;
543}
544
545ALIAS (no_debug_bgp_update,
546 undebug_bgp_update_cmd,
547 "undebug bgp updates",
548 UNDEBUG_STR
549 BGP_STR
550 "BGP updates\n")
551
552DEFUN (debug_bgp_normal,
553 debug_bgp_normal_cmd,
554 "debug bgp",
555 DEBUG_STR
556 BGP_STR)
557{
558 if (vty->node == CONFIG_NODE)
559 DEBUG_ON (normal, NORMAL);
560 else
561 {
562 TERM_DEBUG_ON (normal, NORMAL);
563 vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
564 }
565 return CMD_SUCCESS;
566}
567
568DEFUN (no_debug_bgp_normal,
569 no_debug_bgp_normal_cmd,
570 "no debug bgp",
571 NO_STR
572 DEBUG_STR
573 BGP_STR)
574{
575 if (vty->node == CONFIG_NODE)
576 DEBUG_OFF (normal, NORMAL);
577 else
578 {
579 TERM_DEBUG_OFF (normal, NORMAL);
580 vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
581 }
582 return CMD_SUCCESS;
583}
584
585ALIAS (no_debug_bgp_normal,
586 undebug_bgp_normal_cmd,
587 "undebug bgp",
588 UNDEBUG_STR
589 BGP_STR)
590
591DEFUN (no_debug_bgp_all,
592 no_debug_bgp_all_cmd,
593 "no debug all bgp",
594 NO_STR
595 DEBUG_STR
596 "Enable all debugging\n"
597 BGP_STR)
598{
599 TERM_DEBUG_OFF (normal, NORMAL);
600 TERM_DEBUG_OFF (events, EVENTS);
601 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
602 TERM_DEBUG_OFF (update, UPDATE_IN);
603 TERM_DEBUG_OFF (update, UPDATE_OUT);
604 TERM_DEBUG_OFF (fsm, FSM);
605 TERM_DEBUG_OFF (filter, FILTER);
606 vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
607
608 return CMD_SUCCESS;
609}
610
611ALIAS (no_debug_bgp_all,
612 undebug_bgp_all_cmd,
613 "undebug all bgp",
614 UNDEBUG_STR
615 "Enable all debugging\n"
616 BGP_STR)
617
618DEFUN (show_debugging_bgp,
619 show_debugging_bgp_cmd,
620 "show debugging bgp",
621 SHOW_STR
622 DEBUG_STR
623 BGP_STR)
624{
625 vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
626
627 if (BGP_DEBUG (normal, NORMAL))
628 vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE);
629 if (BGP_DEBUG (events, EVENTS))
630 vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE);
631 if (BGP_DEBUG (keepalive, KEEPALIVE))
632 vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE);
633 if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
634 vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE);
635 else if (BGP_DEBUG (update, UPDATE_IN))
636 vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
637 else if (BGP_DEBUG (update, UPDATE_OUT))
638 vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
639 if (BGP_DEBUG (fsm, FSM))
640 vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE);
641 if (BGP_DEBUG (filter, FILTER))
642 vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE);
643 vty_out (vty, "%s", VTY_NEWLINE);
644 return CMD_SUCCESS;
645}
646
paul94f2b392005-06-28 12:44:16 +0000647static int
paul718e3742002-12-13 20:15:29 +0000648bgp_config_write_debug (struct vty *vty)
649{
650 int write = 0;
651
652 if (CONF_BGP_DEBUG (normal, NORMAL))
653 {
654 vty_out (vty, "debug bgp%s", VTY_NEWLINE);
655 write++;
656 }
657
658 if (CONF_BGP_DEBUG (events, EVENTS))
659 {
660 vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
661 write++;
662 }
663
664 if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
665 {
666 vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
667 write++;
668 }
669
670 if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
671 {
672 vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
673 write++;
674 }
675 else if (CONF_BGP_DEBUG (update, UPDATE_IN))
676 {
677 vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
678 write++;
679 }
680 else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
681 {
682 vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
683 write++;
684 }
685
686 if (CONF_BGP_DEBUG (fsm, FSM))
687 {
688 vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
689 write++;
690 }
691
692 if (CONF_BGP_DEBUG (filter, FILTER))
693 {
694 vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
695 write++;
696 }
697
698 return write;
699}
700
701struct cmd_node debug_node =
702{
703 DEBUG_NODE,
704 "",
705 1
706};
707
708void
paul94f2b392005-06-28 12:44:16 +0000709bgp_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000710{
711 install_node (&debug_node, bgp_config_write_debug);
712
713 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
714
715 install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
716 install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
717 install_element (ENABLE_NODE, &debug_bgp_events_cmd);
718 install_element (CONFIG_NODE, &debug_bgp_events_cmd);
719 install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
720 install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
721 install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
722 install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
723 install_element (ENABLE_NODE, &debug_bgp_update_cmd);
724 install_element (CONFIG_NODE, &debug_bgp_update_cmd);
725 install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
726 install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
727 install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
728 install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
729
730 install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
731 install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
732 install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
733 install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
734 install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
735 install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
736 install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
737 install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
738 install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
739 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
740 install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
741 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
742 install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
743 install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
744 install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
745 install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
746 install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
747 install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
748 install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
749 install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
750}