blob: 1d09769773a49d5b4473fb9c80ac06b405fda827 [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 */
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070060const struct message bgp_status_msg[] =
paul718e3742002-12-13 20:15:29 +000061{
paul718e3742002-12-13 20:15:29 +000062 { Idle, "Idle" },
63 { Connect, "Connect" },
64 { Active, "Active" },
65 { OpenSent, "OpenSent" },
66 { OpenConfirm, "OpenConfirm" },
67 { Established, "Established" },
Paul Jakmaca058a32006-09-14 02:58:49 +000068 { Clearing, "Clearing" },
69 { Deleted, "Deleted" },
paul718e3742002-12-13 20:15:29 +000070};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070071const int bgp_status_msg_max = BGP_STATUS_MAX;
paul718e3742002-12-13 20:15:29 +000072
73/* BGP message type string. */
paulfd79ac92004-10-13 05:06:08 +000074const char *bgp_type_str[] =
paul718e3742002-12-13 20:15:29 +000075{
76 NULL,
77 "OPEN",
78 "UPDATE",
79 "NOTIFICATION",
80 "KEEPALIVE",
81 "ROUTE-REFRESH",
82 "CAPABILITY"
83};
84
85/* message for BGP-4 Notify */
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070086static const struct message bgp_notify_msg[] =
paul718e3742002-12-13 20:15:29 +000087{
paul718e3742002-12-13 20:15:29 +000088 { BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
89 { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
90 { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
91 { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
92 { BGP_NOTIFY_FSM_ERR, "Finite State Machine Error"},
93 { BGP_NOTIFY_CEASE, "Cease"},
94 { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
95};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070096static const int bgp_notify_msg_max = BGP_NOTIFY_MAX;
paul718e3742002-12-13 20:15:29 +000097
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070098static const struct message bgp_notify_head_msg[] =
paul718e3742002-12-13 20:15:29 +000099{
hasso3950fda2004-05-20 10:22:49 +0000100 { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
101 { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
102 { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}
paul718e3742002-12-13 20:15:29 +0000103};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700104static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
paul718e3742002-12-13 20:15:29 +0000105
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700106static const struct message bgp_notify_open_msg[] =
paul718e3742002-12-13 20:15:29 +0000107{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400108 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000109 { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number" },
110 { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
111 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
112 { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
113 { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
114 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
115 { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
paul718e3742002-12-13 20:15:29 +0000116};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700117static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
paul718e3742002-12-13 20:15:29 +0000118
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700119static const struct message bgp_notify_update_msg[] =
paul718e3742002-12-13 20:15:29 +0000120{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400121 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000122 { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
123 { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
124 { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
125 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
126 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
127 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
128 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
129 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
130 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
131 { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
132 { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
paul718e3742002-12-13 20:15:29 +0000133};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700134static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
paul718e3742002-12-13 20:15:29 +0000135
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700136static const struct message bgp_notify_cease_msg[] =
paul718e3742002-12-13 20:15:29 +0000137{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400138 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000139 { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
140 { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
141 { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
142 { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
143 { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
144 { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
145 { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
146 { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
paul718e3742002-12-13 20:15:29 +0000147};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700148static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
paul718e3742002-12-13 20:15:29 +0000149
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700150static const struct message bgp_notify_capability_msg[] =
paul718e3742002-12-13 20:15:29 +0000151{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400152 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000153 { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
154 { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
155 { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
paul718e3742002-12-13 20:15:29 +0000156};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700157static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
paul718e3742002-12-13 20:15:29 +0000158
159/* Origin strings. */
paulfd79ac92004-10-13 05:06:08 +0000160const char *bgp_origin_str[] = {"i","e","?"};
161const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
paul718e3742002-12-13 20:15:29 +0000162
163/* Dump attribute. */
paule01f9cb2004-07-09 17:48:53 +0000164int
paul718e3742002-12-13 20:15:29 +0000165bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
166{
paul718e3742002-12-13 20:15:29 +0000167 if (! attr)
paule01f9cb2004-07-09 17:48:53 +0000168 return 0;
paul718e3742002-12-13 20:15:29 +0000169
paule01f9cb2004-07-09 17:48:53 +0000170 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
171 snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
172
173 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
174 snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
175 bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +0000176
177#ifdef HAVE_IPV6
Paul Jakmafb982c22007-05-04 20:15:47 +0000178 if (attr->extra)
179 {
180 char addrbuf[BUFSIZ];
paul718e3742002-12-13 20:15:29 +0000181
Paul Jakmafb982c22007-05-04 20:15:47 +0000182 /* Add MP case. */
183 if (attr->extra->mp_nexthop_len == 16
184 || attr->extra->mp_nexthop_len == 32)
185 snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
186 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
187 addrbuf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +0000188
Paul Jakmafb982c22007-05-04 20:15:47 +0000189 if (attr->extra->mp_nexthop_len == 32)
190 snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
191 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
192 addrbuf, BUFSIZ));
193 }
paul718e3742002-12-13 20:15:29 +0000194#endif /* HAVE_IPV6 */
195
paule01f9cb2004-07-09 17:48:53 +0000196 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200197 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u",
paul718e3742002-12-13 20:15:29 +0000198 attr->local_pref);
199
paule01f9cb2004-07-09 17:48:53 +0000200 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200201 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %u",
paul718e3742002-12-13 20:15:29 +0000202 attr->med);
203
paule01f9cb2004-07-09 17:48:53 +0000204 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)))
paul718e3742002-12-13 20:15:29 +0000205 snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
206 community_str (attr->community));
207
paule01f9cb2004-07-09 17:48:53 +0000208 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
paul718e3742002-12-13 20:15:29 +0000209 snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
210
paule01f9cb2004-07-09 17:48:53 +0000211 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400212 snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000213 attr->extra->aggregator_as,
214 inet_ntoa (attr->extra->aggregator_addr));
paul718e3742002-12-13 20:15:29 +0000215
paule01f9cb2004-07-09 17:48:53 +0000216 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
paul718e3742002-12-13 20:15:29 +0000217 snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000218 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +0000219
paule01f9cb2004-07-09 17:48:53 +0000220 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
paul718e3742002-12-13 20:15:29 +0000221 {
222 int i;
223
paule01f9cb2004-07-09 17:48:53 +0000224 snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
Paul Jakmafb982c22007-05-04 20:15:47 +0000225 for (i = 0; i < attr->extra->cluster->length / 4; i++)
paule01f9cb2004-07-09 17:48:53 +0000226 snprintf (buf + strlen (buf), size - strlen (buf), " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000227 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +0000228 }
229
paule01f9cb2004-07-09 17:48:53 +0000230 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
paul718e3742002-12-13 20:15:29 +0000231 snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
232 aspath_print (attr->aspath));
paule01f9cb2004-07-09 17:48:53 +0000233
234 if (strlen (buf) > 1)
235 return 1;
236 else
237 return 0;
paul718e3742002-12-13 20:15:29 +0000238}
239
240/* dump notify packet */
241void
paulfd79ac92004-10-13 05:06:08 +0000242bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
243 const char *direct)
paul718e3742002-12-13 20:15:29 +0000244{
paulfd79ac92004-10-13 05:06:08 +0000245 const char *subcode_str;
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000246 const char *code_str;
paul718e3742002-12-13 20:15:29 +0000247
248 subcode_str = "";
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000249 code_str = LOOKUP_DEF (bgp_notify_msg, bgp_notify->code,
250 "Unrecognized Error Code");
paul718e3742002-12-13 20:15:29 +0000251
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000252 switch (bgp_notify->code)
paul718e3742002-12-13 20:15:29 +0000253 {
254 case BGP_NOTIFY_HEADER_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000255 subcode_str = LOOKUP_DEF (bgp_notify_head_msg, bgp_notify->subcode,
256 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000257 break;
258 case BGP_NOTIFY_OPEN_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000259 subcode_str = LOOKUP_DEF (bgp_notify_open_msg, bgp_notify->subcode,
260 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000261 break;
262 case BGP_NOTIFY_UPDATE_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000263 subcode_str = LOOKUP_DEF (bgp_notify_update_msg, bgp_notify->subcode,
264 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000265 break;
266 case BGP_NOTIFY_HOLD_ERR:
paul718e3742002-12-13 20:15:29 +0000267 break;
268 case BGP_NOTIFY_FSM_ERR:
paul718e3742002-12-13 20:15:29 +0000269 break;
270 case BGP_NOTIFY_CEASE:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000271 subcode_str = LOOKUP_DEF (bgp_notify_cease_msg, bgp_notify->subcode,
272 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000273 break;
274 case BGP_NOTIFY_CAPABILITY_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000275 subcode_str = LOOKUP_DEF (bgp_notify_capability_msg, bgp_notify->subcode,
276 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000277 break;
278 }
hasso3950fda2004-05-20 10:22:49 +0000279
280 if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
281 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
282 strcmp (direct, "received") == 0 ? "received from" : "sent to",
283 peer->host, bgp_notify->code, bgp_notify->subcode,
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000284 code_str, subcode_str, bgp_notify->length,
hasso3950fda2004-05-20 10:22:49 +0000285 bgp_notify->data ? bgp_notify->data : "");
286 else if (BGP_DEBUG (normal, NORMAL))
ajs557865c2004-12-08 19:59:11 +0000287 plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
paul718e3742002-12-13 20:15:29 +0000288 peer ? peer->host : "",
289 direct, bgp_notify->code, bgp_notify->subcode,
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000290 code_str, subcode_str, bgp_notify->length,
paul718e3742002-12-13 20:15:29 +0000291 bgp_notify->data ? bgp_notify->data : "");
292}
David Lamparter6b0655a2014-06-04 06:53:35 +0200293
paul718e3742002-12-13 20:15:29 +0000294/* Debug option setting interface. */
295unsigned long bgp_debug_option = 0;
296
297int
298debug (unsigned int option)
299{
300 return bgp_debug_option & option;
301}
302
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000303DEFUN (debug_bgp_as4,
304 debug_bgp_as4_cmd,
305 "debug bgp as4",
306 DEBUG_STR
307 BGP_STR
308 "BGP AS4 actions\n")
309{
310 if (vty->node == CONFIG_NODE)
311 DEBUG_ON (as4, AS4);
312 else
313 {
314 TERM_DEBUG_ON (as4, AS4);
315 vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
316 }
317 return CMD_SUCCESS;
318}
319
320DEFUN (no_debug_bgp_as4,
321 no_debug_bgp_as4_cmd,
322 "no debug bgp as4",
323 NO_STR
324 DEBUG_STR
325 BGP_STR
326 "BGP AS4 actions\n")
327{
328 if (vty->node == CONFIG_NODE)
329 DEBUG_OFF (as4, AS4);
330 else
331 {
332 TERM_DEBUG_OFF (as4, AS4);
333 vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
334 }
335 return CMD_SUCCESS;
336}
337
338ALIAS (no_debug_bgp_as4,
339 undebug_bgp_as4_cmd,
340 "undebug bgp as4",
341 UNDEBUG_STR
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000342 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
David Ward6e22b902011-01-17 10:58:52 +0300350 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000351 "BGP AS4 aspath segment handling\n")
352{
353 if (vty->node == CONFIG_NODE)
354 DEBUG_ON (as4, AS4_SEGMENT);
355 else
356 {
357 TERM_DEBUG_ON (as4, AS4_SEGMENT);
358 vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
359 }
360 return CMD_SUCCESS;
361}
362
363DEFUN (no_debug_bgp_as4_segment,
364 no_debug_bgp_as4_segment_cmd,
365 "no debug bgp as4 segment",
366 NO_STR
367 DEBUG_STR
368 BGP_STR
David Ward6e22b902011-01-17 10:58:52 +0300369 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000370 "BGP AS4 aspath segment handling\n")
371{
372 if (vty->node == CONFIG_NODE)
373 DEBUG_OFF (as4, AS4_SEGMENT);
374 else
375 {
376 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
377 vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
378 }
379 return CMD_SUCCESS;
380}
381
382ALIAS (no_debug_bgp_as4_segment,
383 undebug_bgp_as4_segment_cmd,
384 "undebug bgp as4 segment",
385 UNDEBUG_STR
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000386 BGP_STR
David Ward6e22b902011-01-17 10:58:52 +0300387 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000388 "BGP AS4 aspath segment handling\n")
389
paul718e3742002-12-13 20:15:29 +0000390DEFUN (debug_bgp_fsm,
391 debug_bgp_fsm_cmd,
392 "debug bgp fsm",
393 DEBUG_STR
394 BGP_STR
395 "BGP Finite State Machine\n")
396{
397 if (vty->node == CONFIG_NODE)
398 DEBUG_ON (fsm, FSM);
399 else
400 {
401 TERM_DEBUG_ON (fsm, FSM);
402 vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
403 }
404 return CMD_SUCCESS;
405}
406
407DEFUN (no_debug_bgp_fsm,
408 no_debug_bgp_fsm_cmd,
409 "no debug bgp fsm",
410 NO_STR
411 DEBUG_STR
412 BGP_STR
413 "Finite State Machine\n")
414{
415 if (vty->node == CONFIG_NODE)
416 DEBUG_OFF (fsm, FSM);
417 else
418 {
419 TERM_DEBUG_OFF (fsm, FSM);
420 vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
421 }
422 return CMD_SUCCESS;
423}
424
425ALIAS (no_debug_bgp_fsm,
426 undebug_bgp_fsm_cmd,
427 "undebug bgp fsm",
428 UNDEBUG_STR
paul718e3742002-12-13 20:15:29 +0000429 BGP_STR
430 "Finite State Machine\n")
431
432DEFUN (debug_bgp_events,
433 debug_bgp_events_cmd,
434 "debug bgp events",
435 DEBUG_STR
436 BGP_STR
437 "BGP events\n")
438{
439 if (vty->node == CONFIG_NODE)
440 DEBUG_ON (events, EVENTS);
441 else
442 {
443 TERM_DEBUG_ON (events, EVENTS);
444 vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
445 }
446 return CMD_SUCCESS;
447}
448
449DEFUN (no_debug_bgp_events,
450 no_debug_bgp_events_cmd,
451 "no debug bgp events",
452 NO_STR
453 DEBUG_STR
454 BGP_STR
455 "BGP events\n")
456{
457 if (vty->node == CONFIG_NODE)
458 DEBUG_OFF (events, EVENTS);
459 else
460 {
461 TERM_DEBUG_OFF (events, EVENTS);
462 vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
463 }
464 return CMD_SUCCESS;
465}
466
467ALIAS (no_debug_bgp_events,
468 undebug_bgp_events_cmd,
469 "undebug bgp events",
470 UNDEBUG_STR
471 BGP_STR
472 "BGP events\n")
473
474DEFUN (debug_bgp_filter,
475 debug_bgp_filter_cmd,
476 "debug bgp filters",
477 DEBUG_STR
478 BGP_STR
479 "BGP filters\n")
480{
481 if (vty->node == CONFIG_NODE)
482 DEBUG_ON (filter, FILTER);
483 else
484 {
485 TERM_DEBUG_ON (filter, FILTER);
486 vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
487 }
488 return CMD_SUCCESS;
489}
490
491DEFUN (no_debug_bgp_filter,
492 no_debug_bgp_filter_cmd,
493 "no debug bgp filters",
494 NO_STR
495 DEBUG_STR
496 BGP_STR
497 "BGP filters\n")
498{
499 if (vty->node == CONFIG_NODE)
500 DEBUG_OFF (filter, FILTER);
501 else
502 {
503 TERM_DEBUG_OFF (filter, FILTER);
504 vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
505 }
506 return CMD_SUCCESS;
507}
508
509ALIAS (no_debug_bgp_filter,
510 undebug_bgp_filter_cmd,
511 "undebug bgp filters",
512 UNDEBUG_STR
513 BGP_STR
514 "BGP filters\n")
515
516DEFUN (debug_bgp_keepalive,
517 debug_bgp_keepalive_cmd,
518 "debug bgp keepalives",
519 DEBUG_STR
520 BGP_STR
521 "BGP keepalives\n")
522{
523 if (vty->node == CONFIG_NODE)
524 DEBUG_ON (keepalive, KEEPALIVE);
525 else
526 {
527 TERM_DEBUG_ON (keepalive, KEEPALIVE);
528 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
529 }
530 return CMD_SUCCESS;
531}
532
533DEFUN (no_debug_bgp_keepalive,
534 no_debug_bgp_keepalive_cmd,
535 "no debug bgp keepalives",
536 NO_STR
537 DEBUG_STR
538 BGP_STR
539 "BGP keepalives\n")
540{
541 if (vty->node == CONFIG_NODE)
542 DEBUG_OFF (keepalive, KEEPALIVE);
543 else
544 {
545 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
546 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
547 }
548 return CMD_SUCCESS;
549}
550
551ALIAS (no_debug_bgp_keepalive,
552 undebug_bgp_keepalive_cmd,
553 "undebug bgp keepalives",
554 UNDEBUG_STR
555 BGP_STR
556 "BGP keepalives\n")
557
558DEFUN (debug_bgp_update,
559 debug_bgp_update_cmd,
560 "debug bgp updates",
561 DEBUG_STR
562 BGP_STR
563 "BGP updates\n")
564{
565 if (vty->node == CONFIG_NODE)
566 {
567 DEBUG_ON (update, UPDATE_IN);
568 DEBUG_ON (update, UPDATE_OUT);
569 }
570 else
571 {
572 TERM_DEBUG_ON (update, UPDATE_IN);
573 TERM_DEBUG_ON (update, UPDATE_OUT);
574 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
575 }
576 return CMD_SUCCESS;
577}
578
579DEFUN (debug_bgp_update_direct,
580 debug_bgp_update_direct_cmd,
581 "debug bgp updates (in|out)",
582 DEBUG_STR
583 BGP_STR
584 "BGP updates\n"
585 "Inbound updates\n"
586 "Outbound updates\n")
587{
588 if (vty->node == CONFIG_NODE)
589 {
590 if (strncmp ("i", argv[0], 1) == 0)
591 {
592 DEBUG_OFF (update, UPDATE_OUT);
593 DEBUG_ON (update, UPDATE_IN);
594 }
595 else
596 {
597 DEBUG_OFF (update, UPDATE_IN);
598 DEBUG_ON (update, UPDATE_OUT);
599 }
600 }
601 else
602 {
603 if (strncmp ("i", argv[0], 1) == 0)
604 {
605 TERM_DEBUG_OFF (update, UPDATE_OUT);
606 TERM_DEBUG_ON (update, UPDATE_IN);
607 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
608 }
609 else
610 {
611 TERM_DEBUG_OFF (update, UPDATE_IN);
612 TERM_DEBUG_ON (update, UPDATE_OUT);
613 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
614 }
615 }
616 return CMD_SUCCESS;
617}
618
619DEFUN (no_debug_bgp_update,
620 no_debug_bgp_update_cmd,
621 "no debug bgp updates",
622 NO_STR
623 DEBUG_STR
624 BGP_STR
625 "BGP updates\n")
626{
627 if (vty->node == CONFIG_NODE)
628 {
629 DEBUG_OFF (update, UPDATE_IN);
630 DEBUG_OFF (update, UPDATE_OUT);
631 }
632 else
633 {
634 TERM_DEBUG_OFF (update, UPDATE_IN);
635 TERM_DEBUG_OFF (update, UPDATE_OUT);
636 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
637 }
638 return CMD_SUCCESS;
639}
640
641ALIAS (no_debug_bgp_update,
642 undebug_bgp_update_cmd,
643 "undebug bgp updates",
644 UNDEBUG_STR
645 BGP_STR
646 "BGP updates\n")
647
648DEFUN (debug_bgp_normal,
649 debug_bgp_normal_cmd,
650 "debug bgp",
651 DEBUG_STR
652 BGP_STR)
653{
654 if (vty->node == CONFIG_NODE)
655 DEBUG_ON (normal, NORMAL);
656 else
657 {
658 TERM_DEBUG_ON (normal, NORMAL);
659 vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
660 }
661 return CMD_SUCCESS;
662}
663
664DEFUN (no_debug_bgp_normal,
665 no_debug_bgp_normal_cmd,
666 "no debug bgp",
667 NO_STR
668 DEBUG_STR
669 BGP_STR)
670{
671 if (vty->node == CONFIG_NODE)
672 DEBUG_OFF (normal, NORMAL);
673 else
674 {
675 TERM_DEBUG_OFF (normal, NORMAL);
676 vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
677 }
678 return CMD_SUCCESS;
679}
680
681ALIAS (no_debug_bgp_normal,
682 undebug_bgp_normal_cmd,
683 "undebug bgp",
684 UNDEBUG_STR
685 BGP_STR)
686
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000687DEFUN (debug_bgp_zebra,
688 debug_bgp_zebra_cmd,
689 "debug bgp zebra",
690 DEBUG_STR
691 BGP_STR
692 "BGP Zebra messages\n")
693{
694 if (vty->node == CONFIG_NODE)
695 DEBUG_ON (zebra, ZEBRA);
696 else
697 {
698 TERM_DEBUG_ON (zebra, ZEBRA);
699 vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
700 }
701 return CMD_SUCCESS;
702}
703
704DEFUN (no_debug_bgp_zebra,
705 no_debug_bgp_zebra_cmd,
706 "no debug bgp zebra",
707 NO_STR
708 DEBUG_STR
709 BGP_STR
710 "BGP Zebra messages\n")
711{
712 if (vty->node == CONFIG_NODE)
713 DEBUG_OFF (zebra, ZEBRA);
714 else
715 {
716 TERM_DEBUG_OFF (zebra, ZEBRA);
717 vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
718 }
719 return CMD_SUCCESS;
720}
721
722ALIAS (no_debug_bgp_zebra,
723 undebug_bgp_zebra_cmd,
724 "undebug bgp zebra",
725 UNDEBUG_STR
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000726 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
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800866static struct cmd_node debug_node =
paul718e3742002-12-13 20:15:29 +0000867{
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}