blob: acb1de7facd54e744f88fd2024d3a2d63d976d1a [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
Paul Jakma0b2aa3a2007-10-14 22:32:21 +000039unsigned long conf_bgp_debug_as4;
paul718e3742002-12-13 20:15:29 +000040unsigned long conf_bgp_debug_fsm;
41unsigned long conf_bgp_debug_events;
42unsigned long conf_bgp_debug_packet;
43unsigned long conf_bgp_debug_filter;
44unsigned long conf_bgp_debug_keepalive;
45unsigned long conf_bgp_debug_update;
46unsigned long conf_bgp_debug_normal;
Andrew J. Schorra39275d2006-11-30 16:36:57 +000047unsigned long conf_bgp_debug_zebra;
paul718e3742002-12-13 20:15:29 +000048
Paul Jakma0b2aa3a2007-10-14 22:32:21 +000049unsigned long term_bgp_debug_as4;
paul718e3742002-12-13 20:15:29 +000050unsigned long term_bgp_debug_fsm;
51unsigned long term_bgp_debug_events;
52unsigned long term_bgp_debug_packet;
53unsigned long term_bgp_debug_filter;
54unsigned long term_bgp_debug_keepalive;
55unsigned long term_bgp_debug_update;
56unsigned long term_bgp_debug_normal;
Andrew J. Schorra39275d2006-11-30 16:36:57 +000057unsigned long term_bgp_debug_zebra;
paul718e3742002-12-13 20:15:29 +000058
59/* messages for BGP-4 status */
60struct message bgp_status_msg[] =
61{
62 { 0, "null" },
63 { Idle, "Idle" },
64 { Connect, "Connect" },
65 { Active, "Active" },
66 { OpenSent, "OpenSent" },
67 { OpenConfirm, "OpenConfirm" },
68 { Established, "Established" },
Paul Jakmaca058a32006-09-14 02:58:49 +000069 { Clearing, "Clearing" },
70 { Deleted, "Deleted" },
paul718e3742002-12-13 20:15:29 +000071};
72int bgp_status_msg_max = BGP_STATUS_MAX;
73
74/* BGP message type string. */
paulfd79ac92004-10-13 05:06:08 +000075const char *bgp_type_str[] =
paul718e3742002-12-13 20:15:29 +000076{
77 NULL,
78 "OPEN",
79 "UPDATE",
80 "NOTIFICATION",
81 "KEEPALIVE",
82 "ROUTE-REFRESH",
83 "CAPABILITY"
84};
85
86/* message for BGP-4 Notify */
87struct message bgp_notify_msg[] =
88{
89 { 0, "" },
90 { BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
91 { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
92 { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
93 { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
94 { BGP_NOTIFY_FSM_ERR, "Finite State Machine Error"},
95 { BGP_NOTIFY_CEASE, "Cease"},
96 { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
97};
98int bgp_notify_msg_max = BGP_NOTIFY_MAX;
99
100struct message bgp_notify_head_msg[] =
101{
102 { 0, "null"},
hasso3950fda2004-05-20 10:22:49 +0000103 { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
104 { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
105 { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}
paul718e3742002-12-13 20:15:29 +0000106};
107int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
108
109struct message bgp_notify_open_msg[] =
110{
111 { 0, "null" },
hasso3950fda2004-05-20 10:22:49 +0000112 { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number" },
113 { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
114 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
115 { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
116 { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
117 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
118 { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
paul718e3742002-12-13 20:15:29 +0000119};
120int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
121
122struct message bgp_notify_update_msg[] =
123{
124 { 0, "null"},
hasso3950fda2004-05-20 10:22:49 +0000125 { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
126 { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
127 { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
128 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
129 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
130 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
131 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
132 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
133 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
134 { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
135 { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
paul718e3742002-12-13 20:15:29 +0000136};
137int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
138
139struct message bgp_notify_cease_msg[] =
140{
141 { 0, ""},
hasso3950fda2004-05-20 10:22:49 +0000142 { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
143 { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
144 { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
145 { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
146 { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
147 { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
148 { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
149 { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
paul718e3742002-12-13 20:15:29 +0000150};
151int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
152
153struct message bgp_notify_capability_msg[] =
154{
155 { 0, "null" },
hasso3950fda2004-05-20 10:22:49 +0000156 { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
157 { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
158 { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
paul718e3742002-12-13 20:15:29 +0000159};
160int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
161
162/* Origin strings. */
paulfd79ac92004-10-13 05:06:08 +0000163const char *bgp_origin_str[] = {"i","e","?"};
164const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
paul718e3742002-12-13 20:15:29 +0000165
166/* Dump attribute. */
paule01f9cb2004-07-09 17:48:53 +0000167int
paul718e3742002-12-13 20:15:29 +0000168bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
169{
paul718e3742002-12-13 20:15:29 +0000170 if (! attr)
paule01f9cb2004-07-09 17:48:53 +0000171 return 0;
paul718e3742002-12-13 20:15:29 +0000172
paule01f9cb2004-07-09 17:48:53 +0000173 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
174 snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
175
176 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
177 snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
178 bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +0000179
180#ifdef HAVE_IPV6
Paul Jakmafb982c22007-05-04 20:15:47 +0000181 if (attr->extra)
182 {
183 char addrbuf[BUFSIZ];
paul718e3742002-12-13 20:15:29 +0000184
Paul Jakmafb982c22007-05-04 20:15:47 +0000185 /* Add MP case. */
186 if (attr->extra->mp_nexthop_len == 16
187 || attr->extra->mp_nexthop_len == 32)
188 snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
189 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
190 addrbuf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +0000191
Paul Jakmafb982c22007-05-04 20:15:47 +0000192 if (attr->extra->mp_nexthop_len == 32)
193 snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
194 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
195 addrbuf, BUFSIZ));
196 }
paul718e3742002-12-13 20:15:29 +0000197#endif /* HAVE_IPV6 */
198
paule01f9cb2004-07-09 17:48:53 +0000199 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
paul718e3742002-12-13 20:15:29 +0000200 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d",
201 attr->local_pref);
202
paule01f9cb2004-07-09 17:48:53 +0000203 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
paul718e3742002-12-13 20:15:29 +0000204 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %d",
205 attr->med);
206
paule01f9cb2004-07-09 17:48:53 +0000207 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)))
paul718e3742002-12-13 20:15:29 +0000208 snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
209 community_str (attr->community));
210
paule01f9cb2004-07-09 17:48:53 +0000211 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
paul718e3742002-12-13 20:15:29 +0000212 snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
213
paule01f9cb2004-07-09 17:48:53 +0000214 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
paul718e3742002-12-13 20:15:29 +0000215 snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %d %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000216 attr->extra->aggregator_as,
217 inet_ntoa (attr->extra->aggregator_addr));
paul718e3742002-12-13 20:15:29 +0000218
paule01f9cb2004-07-09 17:48:53 +0000219 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
paul718e3742002-12-13 20:15:29 +0000220 snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000221 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +0000222
paule01f9cb2004-07-09 17:48:53 +0000223 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
paul718e3742002-12-13 20:15:29 +0000224 {
225 int i;
226
paule01f9cb2004-07-09 17:48:53 +0000227 snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
Paul Jakmafb982c22007-05-04 20:15:47 +0000228 for (i = 0; i < attr->extra->cluster->length / 4; i++)
paule01f9cb2004-07-09 17:48:53 +0000229 snprintf (buf + strlen (buf), size - strlen (buf), " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000230 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +0000231 }
232
paule01f9cb2004-07-09 17:48:53 +0000233 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
paul718e3742002-12-13 20:15:29 +0000234 snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
235 aspath_print (attr->aspath));
paule01f9cb2004-07-09 17:48:53 +0000236
237 if (strlen (buf) > 1)
238 return 1;
239 else
240 return 0;
paul718e3742002-12-13 20:15:29 +0000241}
242
243/* dump notify packet */
244void
paulfd79ac92004-10-13 05:06:08 +0000245bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
246 const char *direct)
paul718e3742002-12-13 20:15:29 +0000247{
paulfd79ac92004-10-13 05:06:08 +0000248 const char *subcode_str;
paul718e3742002-12-13 20:15:29 +0000249
250 subcode_str = "";
251
252 switch (bgp_notify->code)
253 {
254 case BGP_NOTIFY_HEADER_ERR:
255 subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode);
256 break;
257 case BGP_NOTIFY_OPEN_ERR:
258 subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode);
259 break;
260 case BGP_NOTIFY_UPDATE_ERR:
261 subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode);
262 break;
263 case BGP_NOTIFY_HOLD_ERR:
264 subcode_str = "";
265 break;
266 case BGP_NOTIFY_FSM_ERR:
267 subcode_str = "";
268 break;
269 case BGP_NOTIFY_CEASE:
270 subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode);
271 break;
272 case BGP_NOTIFY_CAPABILITY_ERR:
273 subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode);
274 break;
275 }
hasso3950fda2004-05-20 10:22:49 +0000276
277 if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
278 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
279 strcmp (direct, "received") == 0 ? "received from" : "sent to",
280 peer->host, bgp_notify->code, bgp_notify->subcode,
281 LOOKUP (bgp_notify_msg, bgp_notify->code),
282 subcode_str, bgp_notify->length,
283 bgp_notify->data ? bgp_notify->data : "");
284 else if (BGP_DEBUG (normal, NORMAL))
ajs557865c2004-12-08 19:59:11 +0000285 plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
paul718e3742002-12-13 20:15:29 +0000286 peer ? peer->host : "",
287 direct, bgp_notify->code, bgp_notify->subcode,
288 LOOKUP (bgp_notify_msg, bgp_notify->code),
289 subcode_str, bgp_notify->length,
290 bgp_notify->data ? bgp_notify->data : "");
291}
292
293/* Debug option setting interface. */
294unsigned long bgp_debug_option = 0;
295
296int
297debug (unsigned int option)
298{
299 return bgp_debug_option & option;
300}
301
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000302DEFUN (debug_bgp_as4,
303 debug_bgp_as4_cmd,
304 "debug bgp as4",
305 DEBUG_STR
306 BGP_STR
307 "BGP AS4 actions\n")
308{
309 if (vty->node == CONFIG_NODE)
310 DEBUG_ON (as4, AS4);
311 else
312 {
313 TERM_DEBUG_ON (as4, AS4);
314 vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
315 }
316 return CMD_SUCCESS;
317}
318
319DEFUN (no_debug_bgp_as4,
320 no_debug_bgp_as4_cmd,
321 "no debug bgp as4",
322 NO_STR
323 DEBUG_STR
324 BGP_STR
325 "BGP AS4 actions\n")
326{
327 if (vty->node == CONFIG_NODE)
328 DEBUG_OFF (as4, AS4);
329 else
330 {
331 TERM_DEBUG_OFF (as4, AS4);
332 vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
333 }
334 return CMD_SUCCESS;
335}
336
337ALIAS (no_debug_bgp_as4,
338 undebug_bgp_as4_cmd,
339 "undebug bgp as4",
340 UNDEBUG_STR
341 DEBUG_STR
342 BGP_STR
343 "BGP AS4 actions\n")
344
345DEFUN (debug_bgp_as4_segment,
346 debug_bgp_as4_segment_cmd,
347 "debug bgp as4 segment",
348 DEBUG_STR
349 BGP_STR
350 "BGP AS4 aspath segment handling\n")
351{
352 if (vty->node == CONFIG_NODE)
353 DEBUG_ON (as4, AS4_SEGMENT);
354 else
355 {
356 TERM_DEBUG_ON (as4, AS4_SEGMENT);
357 vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
358 }
359 return CMD_SUCCESS;
360}
361
362DEFUN (no_debug_bgp_as4_segment,
363 no_debug_bgp_as4_segment_cmd,
364 "no debug bgp as4 segment",
365 NO_STR
366 DEBUG_STR
367 BGP_STR
368 "BGP AS4 aspath segment handling\n")
369{
370 if (vty->node == CONFIG_NODE)
371 DEBUG_OFF (as4, AS4_SEGMENT);
372 else
373 {
374 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
375 vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
376 }
377 return CMD_SUCCESS;
378}
379
380ALIAS (no_debug_bgp_as4_segment,
381 undebug_bgp_as4_segment_cmd,
382 "undebug bgp as4 segment",
383 UNDEBUG_STR
384 DEBUG_STR
385 BGP_STR
386 "BGP AS4 aspath segment handling\n")
387
paul718e3742002-12-13 20:15:29 +0000388DEFUN (debug_bgp_fsm,
389 debug_bgp_fsm_cmd,
390 "debug bgp fsm",
391 DEBUG_STR
392 BGP_STR
393 "BGP Finite State Machine\n")
394{
395 if (vty->node == CONFIG_NODE)
396 DEBUG_ON (fsm, FSM);
397 else
398 {
399 TERM_DEBUG_ON (fsm, FSM);
400 vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
401 }
402 return CMD_SUCCESS;
403}
404
405DEFUN (no_debug_bgp_fsm,
406 no_debug_bgp_fsm_cmd,
407 "no debug bgp fsm",
408 NO_STR
409 DEBUG_STR
410 BGP_STR
411 "Finite State Machine\n")
412{
413 if (vty->node == CONFIG_NODE)
414 DEBUG_OFF (fsm, FSM);
415 else
416 {
417 TERM_DEBUG_OFF (fsm, FSM);
418 vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
419 }
420 return CMD_SUCCESS;
421}
422
423ALIAS (no_debug_bgp_fsm,
424 undebug_bgp_fsm_cmd,
425 "undebug bgp fsm",
426 UNDEBUG_STR
427 DEBUG_STR
428 BGP_STR
429 "Finite State Machine\n")
430
431DEFUN (debug_bgp_events,
432 debug_bgp_events_cmd,
433 "debug bgp events",
434 DEBUG_STR
435 BGP_STR
436 "BGP events\n")
437{
438 if (vty->node == CONFIG_NODE)
439 DEBUG_ON (events, EVENTS);
440 else
441 {
442 TERM_DEBUG_ON (events, EVENTS);
443 vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
444 }
445 return CMD_SUCCESS;
446}
447
448DEFUN (no_debug_bgp_events,
449 no_debug_bgp_events_cmd,
450 "no debug bgp events",
451 NO_STR
452 DEBUG_STR
453 BGP_STR
454 "BGP events\n")
455{
456 if (vty->node == CONFIG_NODE)
457 DEBUG_OFF (events, EVENTS);
458 else
459 {
460 TERM_DEBUG_OFF (events, EVENTS);
461 vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
462 }
463 return CMD_SUCCESS;
464}
465
466ALIAS (no_debug_bgp_events,
467 undebug_bgp_events_cmd,
468 "undebug bgp events",
469 UNDEBUG_STR
470 BGP_STR
471 "BGP events\n")
472
473DEFUN (debug_bgp_filter,
474 debug_bgp_filter_cmd,
475 "debug bgp filters",
476 DEBUG_STR
477 BGP_STR
478 "BGP filters\n")
479{
480 if (vty->node == CONFIG_NODE)
481 DEBUG_ON (filter, FILTER);
482 else
483 {
484 TERM_DEBUG_ON (filter, FILTER);
485 vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
486 }
487 return CMD_SUCCESS;
488}
489
490DEFUN (no_debug_bgp_filter,
491 no_debug_bgp_filter_cmd,
492 "no debug bgp filters",
493 NO_STR
494 DEBUG_STR
495 BGP_STR
496 "BGP filters\n")
497{
498 if (vty->node == CONFIG_NODE)
499 DEBUG_OFF (filter, FILTER);
500 else
501 {
502 TERM_DEBUG_OFF (filter, FILTER);
503 vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
504 }
505 return CMD_SUCCESS;
506}
507
508ALIAS (no_debug_bgp_filter,
509 undebug_bgp_filter_cmd,
510 "undebug bgp filters",
511 UNDEBUG_STR
512 BGP_STR
513 "BGP filters\n")
514
515DEFUN (debug_bgp_keepalive,
516 debug_bgp_keepalive_cmd,
517 "debug bgp keepalives",
518 DEBUG_STR
519 BGP_STR
520 "BGP keepalives\n")
521{
522 if (vty->node == CONFIG_NODE)
523 DEBUG_ON (keepalive, KEEPALIVE);
524 else
525 {
526 TERM_DEBUG_ON (keepalive, KEEPALIVE);
527 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
528 }
529 return CMD_SUCCESS;
530}
531
532DEFUN (no_debug_bgp_keepalive,
533 no_debug_bgp_keepalive_cmd,
534 "no debug bgp keepalives",
535 NO_STR
536 DEBUG_STR
537 BGP_STR
538 "BGP keepalives\n")
539{
540 if (vty->node == CONFIG_NODE)
541 DEBUG_OFF (keepalive, KEEPALIVE);
542 else
543 {
544 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
545 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
546 }
547 return CMD_SUCCESS;
548}
549
550ALIAS (no_debug_bgp_keepalive,
551 undebug_bgp_keepalive_cmd,
552 "undebug bgp keepalives",
553 UNDEBUG_STR
554 BGP_STR
555 "BGP keepalives\n")
556
557DEFUN (debug_bgp_update,
558 debug_bgp_update_cmd,
559 "debug bgp updates",
560 DEBUG_STR
561 BGP_STR
562 "BGP updates\n")
563{
564 if (vty->node == CONFIG_NODE)
565 {
566 DEBUG_ON (update, UPDATE_IN);
567 DEBUG_ON (update, UPDATE_OUT);
568 }
569 else
570 {
571 TERM_DEBUG_ON (update, UPDATE_IN);
572 TERM_DEBUG_ON (update, UPDATE_OUT);
573 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
574 }
575 return CMD_SUCCESS;
576}
577
578DEFUN (debug_bgp_update_direct,
579 debug_bgp_update_direct_cmd,
580 "debug bgp updates (in|out)",
581 DEBUG_STR
582 BGP_STR
583 "BGP updates\n"
584 "Inbound updates\n"
585 "Outbound updates\n")
586{
587 if (vty->node == CONFIG_NODE)
588 {
589 if (strncmp ("i", argv[0], 1) == 0)
590 {
591 DEBUG_OFF (update, UPDATE_OUT);
592 DEBUG_ON (update, UPDATE_IN);
593 }
594 else
595 {
596 DEBUG_OFF (update, UPDATE_IN);
597 DEBUG_ON (update, UPDATE_OUT);
598 }
599 }
600 else
601 {
602 if (strncmp ("i", argv[0], 1) == 0)
603 {
604 TERM_DEBUG_OFF (update, UPDATE_OUT);
605 TERM_DEBUG_ON (update, UPDATE_IN);
606 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
607 }
608 else
609 {
610 TERM_DEBUG_OFF (update, UPDATE_IN);
611 TERM_DEBUG_ON (update, UPDATE_OUT);
612 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
613 }
614 }
615 return CMD_SUCCESS;
616}
617
618DEFUN (no_debug_bgp_update,
619 no_debug_bgp_update_cmd,
620 "no debug bgp updates",
621 NO_STR
622 DEBUG_STR
623 BGP_STR
624 "BGP updates\n")
625{
626 if (vty->node == CONFIG_NODE)
627 {
628 DEBUG_OFF (update, UPDATE_IN);
629 DEBUG_OFF (update, UPDATE_OUT);
630 }
631 else
632 {
633 TERM_DEBUG_OFF (update, UPDATE_IN);
634 TERM_DEBUG_OFF (update, UPDATE_OUT);
635 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
636 }
637 return CMD_SUCCESS;
638}
639
640ALIAS (no_debug_bgp_update,
641 undebug_bgp_update_cmd,
642 "undebug bgp updates",
643 UNDEBUG_STR
644 BGP_STR
645 "BGP updates\n")
646
647DEFUN (debug_bgp_normal,
648 debug_bgp_normal_cmd,
649 "debug bgp",
650 DEBUG_STR
651 BGP_STR)
652{
653 if (vty->node == CONFIG_NODE)
654 DEBUG_ON (normal, NORMAL);
655 else
656 {
657 TERM_DEBUG_ON (normal, NORMAL);
658 vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
659 }
660 return CMD_SUCCESS;
661}
662
663DEFUN (no_debug_bgp_normal,
664 no_debug_bgp_normal_cmd,
665 "no debug bgp",
666 NO_STR
667 DEBUG_STR
668 BGP_STR)
669{
670 if (vty->node == CONFIG_NODE)
671 DEBUG_OFF (normal, NORMAL);
672 else
673 {
674 TERM_DEBUG_OFF (normal, NORMAL);
675 vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
676 }
677 return CMD_SUCCESS;
678}
679
680ALIAS (no_debug_bgp_normal,
681 undebug_bgp_normal_cmd,
682 "undebug bgp",
683 UNDEBUG_STR
684 BGP_STR)
685
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000686DEFUN (debug_bgp_zebra,
687 debug_bgp_zebra_cmd,
688 "debug bgp zebra",
689 DEBUG_STR
690 BGP_STR
691 "BGP Zebra messages\n")
692{
693 if (vty->node == CONFIG_NODE)
694 DEBUG_ON (zebra, ZEBRA);
695 else
696 {
697 TERM_DEBUG_ON (zebra, ZEBRA);
698 vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
699 }
700 return CMD_SUCCESS;
701}
702
703DEFUN (no_debug_bgp_zebra,
704 no_debug_bgp_zebra_cmd,
705 "no debug bgp zebra",
706 NO_STR
707 DEBUG_STR
708 BGP_STR
709 "BGP Zebra messages\n")
710{
711 if (vty->node == CONFIG_NODE)
712 DEBUG_OFF (zebra, ZEBRA);
713 else
714 {
715 TERM_DEBUG_OFF (zebra, ZEBRA);
716 vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
717 }
718 return CMD_SUCCESS;
719}
720
721ALIAS (no_debug_bgp_zebra,
722 undebug_bgp_zebra_cmd,
723 "undebug bgp zebra",
724 UNDEBUG_STR
725 DEBUG_STR
726 BGP_STR
727 "BGP Zebra messages\n")
728
paul718e3742002-12-13 20:15:29 +0000729DEFUN (no_debug_bgp_all,
730 no_debug_bgp_all_cmd,
731 "no debug all bgp",
732 NO_STR
733 DEBUG_STR
734 "Enable all debugging\n"
735 BGP_STR)
736{
737 TERM_DEBUG_OFF (normal, NORMAL);
738 TERM_DEBUG_OFF (events, EVENTS);
739 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
740 TERM_DEBUG_OFF (update, UPDATE_IN);
741 TERM_DEBUG_OFF (update, UPDATE_OUT);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000742 TERM_DEBUG_OFF (as4, AS4);
743 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
paul718e3742002-12-13 20:15:29 +0000744 TERM_DEBUG_OFF (fsm, FSM);
745 TERM_DEBUG_OFF (filter, FILTER);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000746 TERM_DEBUG_OFF (zebra, ZEBRA);
paul718e3742002-12-13 20:15:29 +0000747 vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
748
749 return CMD_SUCCESS;
750}
751
752ALIAS (no_debug_bgp_all,
753 undebug_bgp_all_cmd,
754 "undebug all bgp",
755 UNDEBUG_STR
756 "Enable all debugging\n"
757 BGP_STR)
758
759DEFUN (show_debugging_bgp,
760 show_debugging_bgp_cmd,
761 "show debugging bgp",
762 SHOW_STR
763 DEBUG_STR
764 BGP_STR)
765{
766 vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
767
768 if (BGP_DEBUG (normal, NORMAL))
769 vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE);
770 if (BGP_DEBUG (events, EVENTS))
771 vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE);
772 if (BGP_DEBUG (keepalive, KEEPALIVE))
773 vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE);
774 if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
775 vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE);
776 else if (BGP_DEBUG (update, UPDATE_IN))
777 vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
778 else if (BGP_DEBUG (update, UPDATE_OUT))
779 vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
780 if (BGP_DEBUG (fsm, FSM))
781 vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE);
782 if (BGP_DEBUG (filter, FILTER))
783 vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000784 if (BGP_DEBUG (zebra, ZEBRA))
785 vty_out (vty, " BGP zebra debugging is on%s", VTY_NEWLINE);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000786 if (BGP_DEBUG (as4, AS4))
787 vty_out (vty, " BGP as4 debugging is on%s", VTY_NEWLINE);
788 if (BGP_DEBUG (as4, AS4_SEGMENT))
789 vty_out (vty, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000790 vty_out (vty, "%s", VTY_NEWLINE);
791 return CMD_SUCCESS;
792}
793
paul94f2b392005-06-28 12:44:16 +0000794static int
paul718e3742002-12-13 20:15:29 +0000795bgp_config_write_debug (struct vty *vty)
796{
797 int write = 0;
798
799 if (CONF_BGP_DEBUG (normal, NORMAL))
800 {
801 vty_out (vty, "debug bgp%s", VTY_NEWLINE);
802 write++;
803 }
804
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000805 if (CONF_BGP_DEBUG (as4, AS4))
806 {
807 vty_out (vty, "debug bgp as4%s", VTY_NEWLINE);
808 write++;
809 }
810
811 if (CONF_BGP_DEBUG (as4, AS4_SEGMENT))
812 {
813 vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE);
814 write++;
815 }
816
paul718e3742002-12-13 20:15:29 +0000817 if (CONF_BGP_DEBUG (events, EVENTS))
818 {
819 vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
820 write++;
821 }
822
823 if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
824 {
825 vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
826 write++;
827 }
828
829 if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
830 {
831 vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
832 write++;
833 }
834 else if (CONF_BGP_DEBUG (update, UPDATE_IN))
835 {
836 vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
837 write++;
838 }
839 else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
840 {
841 vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
842 write++;
843 }
844
845 if (CONF_BGP_DEBUG (fsm, FSM))
846 {
847 vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
848 write++;
849 }
850
851 if (CONF_BGP_DEBUG (filter, FILTER))
852 {
853 vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
854 write++;
855 }
856
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000857 if (CONF_BGP_DEBUG (zebra, ZEBRA))
858 {
859 vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
860 write++;
861 }
862
paul718e3742002-12-13 20:15:29 +0000863 return write;
864}
865
866struct cmd_node debug_node =
867{
868 DEBUG_NODE,
869 "",
870 1
871};
872
873void
paul94f2b392005-06-28 12:44:16 +0000874bgp_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000875{
876 install_node (&debug_node, bgp_config_write_debug);
877
878 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
879
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000880 install_element (ENABLE_NODE, &debug_bgp_as4_cmd);
881 install_element (CONFIG_NODE, &debug_bgp_as4_cmd);
882 install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd);
883 install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd);
884
paul718e3742002-12-13 20:15:29 +0000885 install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
886 install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
887 install_element (ENABLE_NODE, &debug_bgp_events_cmd);
888 install_element (CONFIG_NODE, &debug_bgp_events_cmd);
889 install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
890 install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
891 install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
892 install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
893 install_element (ENABLE_NODE, &debug_bgp_update_cmd);
894 install_element (CONFIG_NODE, &debug_bgp_update_cmd);
895 install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
896 install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
897 install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
898 install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000899 install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
900 install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
paul718e3742002-12-13 20:15:29 +0000901
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000902 install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd);
903 install_element (ENABLE_NODE, &undebug_bgp_as4_cmd);
904 install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd);
905 install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
906 install_element (ENABLE_NODE, &undebug_bgp_as4_segment_cmd);
907 install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
908
paul718e3742002-12-13 20:15:29 +0000909 install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
910 install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
911 install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
912 install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
913 install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
914 install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
915 install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
916 install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
917 install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
918 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
919 install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
920 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
921 install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
922 install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
923 install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
924 install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
925 install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
926 install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000927 install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
928 install_element (ENABLE_NODE, &undebug_bgp_zebra_cmd);
929 install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
paul718e3742002-12-13 20:15:29 +0000930 install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
931 install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
932}