blob: e3e5ca46a8d32fef9d992da90b959d0a64067c82 [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"
Donald Sharp04907292016-01-07 10:03:01 -050031#include "filter.h"
paul718e3742002-12-13 20:15:29 +000032
33#include "bgpd/bgpd.h"
34#include "bgpd/bgp_aspath.h"
35#include "bgpd/bgp_route.h"
36#include "bgpd/bgp_attr.h"
37#include "bgpd/bgp_debug.h"
38#include "bgpd/bgp_community.h"
39
Paul Jakma0b2aa3a2007-10-14 22:32:21 +000040unsigned long conf_bgp_debug_as4;
paul718e3742002-12-13 20:15:29 +000041unsigned long conf_bgp_debug_fsm;
42unsigned long conf_bgp_debug_events;
43unsigned long conf_bgp_debug_packet;
44unsigned long conf_bgp_debug_filter;
45unsigned long conf_bgp_debug_keepalive;
46unsigned long conf_bgp_debug_update;
47unsigned long conf_bgp_debug_normal;
Andrew J. Schorra39275d2006-11-30 16:36:57 +000048unsigned long conf_bgp_debug_zebra;
paul718e3742002-12-13 20:15:29 +000049
Paul Jakma0b2aa3a2007-10-14 22:32:21 +000050unsigned long term_bgp_debug_as4;
paul718e3742002-12-13 20:15:29 +000051unsigned long term_bgp_debug_fsm;
52unsigned long term_bgp_debug_events;
53unsigned long term_bgp_debug_packet;
54unsigned long term_bgp_debug_filter;
55unsigned long term_bgp_debug_keepalive;
56unsigned long term_bgp_debug_update;
57unsigned long term_bgp_debug_normal;
Andrew J. Schorra39275d2006-11-30 16:36:57 +000058unsigned long term_bgp_debug_zebra;
paul718e3742002-12-13 20:15:29 +000059
60/* messages for BGP-4 status */
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070061const struct message bgp_status_msg[] =
paul718e3742002-12-13 20:15:29 +000062{
paul718e3742002-12-13 20:15:29 +000063 { 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};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070072const int bgp_status_msg_max = BGP_STATUS_MAX;
paul718e3742002-12-13 20:15:29 +000073
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 */
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070087static const struct message bgp_notify_msg[] =
paul718e3742002-12-13 20:15:29 +000088{
paul718e3742002-12-13 20:15:29 +000089 { BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
90 { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
91 { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
92 { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
93 { BGP_NOTIFY_FSM_ERR, "Finite State Machine Error"},
94 { BGP_NOTIFY_CEASE, "Cease"},
95 { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
96};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070097static const int bgp_notify_msg_max = BGP_NOTIFY_MAX;
paul718e3742002-12-13 20:15:29 +000098
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -070099static const struct message bgp_notify_head_msg[] =
paul718e3742002-12-13 20:15:29 +0000100{
hasso3950fda2004-05-20 10:22:49 +0000101 { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
102 { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
103 { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}
paul718e3742002-12-13 20:15:29 +0000104};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700105static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
paul718e3742002-12-13 20:15:29 +0000106
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700107static const struct message bgp_notify_open_msg[] =
paul718e3742002-12-13 20:15:29 +0000108{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400109 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000110 { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number" },
111 { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
112 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
113 { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
114 { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
115 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
116 { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
paul718e3742002-12-13 20:15:29 +0000117};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700118static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
paul718e3742002-12-13 20:15:29 +0000119
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700120static const struct message bgp_notify_update_msg[] =
paul718e3742002-12-13 20:15:29 +0000121{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400122 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000123 { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
124 { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
125 { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
126 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
127 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
128 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
129 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
130 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
131 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
132 { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
133 { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
paul718e3742002-12-13 20:15:29 +0000134};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700135static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
paul718e3742002-12-13 20:15:29 +0000136
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700137static const struct message bgp_notify_cease_msg[] =
paul718e3742002-12-13 20:15:29 +0000138{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400139 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000140 { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
141 { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
142 { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
143 { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
144 { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
145 { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
146 { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
147 { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
paul718e3742002-12-13 20:15:29 +0000148};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700149static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
paul718e3742002-12-13 20:15:29 +0000150
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700151static const struct message bgp_notify_capability_msg[] =
paul718e3742002-12-13 20:15:29 +0000152{
Dmitrij Tejblum4b4e07d2011-09-21 23:13:22 +0400153 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
hasso3950fda2004-05-20 10:22:49 +0000154 { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
155 { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
156 { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
paul718e3742002-12-13 20:15:29 +0000157};
Stephen Hemmingerb2d933f2009-05-15 10:48:03 -0700158static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
paul718e3742002-12-13 20:15:29 +0000159
160/* Origin strings. */
paulfd79ac92004-10-13 05:06:08 +0000161const char *bgp_origin_str[] = {"i","e","?"};
162const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
paul718e3742002-12-13 20:15:29 +0000163
164/* Dump attribute. */
paule01f9cb2004-07-09 17:48:53 +0000165int
paul718e3742002-12-13 20:15:29 +0000166bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
167{
paul718e3742002-12-13 20:15:29 +0000168 if (! attr)
paule01f9cb2004-07-09 17:48:53 +0000169 return 0;
paul718e3742002-12-13 20:15:29 +0000170
paule01f9cb2004-07-09 17:48:53 +0000171 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
172 snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
173
174 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
175 snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
176 bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +0000177
178#ifdef HAVE_IPV6
Paul Jakmafb982c22007-05-04 20:15:47 +0000179 if (attr->extra)
180 {
181 char addrbuf[BUFSIZ];
paul718e3742002-12-13 20:15:29 +0000182
Paul Jakmafb982c22007-05-04 20:15:47 +0000183 /* Add MP case. */
184 if (attr->extra->mp_nexthop_len == 16
185 || attr->extra->mp_nexthop_len == 32)
186 snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
187 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
188 addrbuf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +0000189
Paul Jakmafb982c22007-05-04 20:15:47 +0000190 if (attr->extra->mp_nexthop_len == 32)
191 snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
192 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
193 addrbuf, BUFSIZ));
194 }
paul718e3742002-12-13 20:15:29 +0000195#endif /* HAVE_IPV6 */
196
paule01f9cb2004-07-09 17:48:53 +0000197 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200198 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u",
paul718e3742002-12-13 20:15:29 +0000199 attr->local_pref);
200
paule01f9cb2004-07-09 17:48:53 +0000201 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200202 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %u",
paul718e3742002-12-13 20:15:29 +0000203 attr->med);
204
paule01f9cb2004-07-09 17:48:53 +0000205 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)))
paul718e3742002-12-13 20:15:29 +0000206 snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
207 community_str (attr->community));
208
paule01f9cb2004-07-09 17:48:53 +0000209 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
paul718e3742002-12-13 20:15:29 +0000210 snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
211
paule01f9cb2004-07-09 17:48:53 +0000212 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400213 snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000214 attr->extra->aggregator_as,
215 inet_ntoa (attr->extra->aggregator_addr));
paul718e3742002-12-13 20:15:29 +0000216
paule01f9cb2004-07-09 17:48:53 +0000217 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
paul718e3742002-12-13 20:15:29 +0000218 snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000219 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +0000220
paule01f9cb2004-07-09 17:48:53 +0000221 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
paul718e3742002-12-13 20:15:29 +0000222 {
223 int i;
224
paule01f9cb2004-07-09 17:48:53 +0000225 snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
Paul Jakmafb982c22007-05-04 20:15:47 +0000226 for (i = 0; i < attr->extra->cluster->length / 4; i++)
paule01f9cb2004-07-09 17:48:53 +0000227 snprintf (buf + strlen (buf), size - strlen (buf), " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +0000228 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +0000229 }
230
paule01f9cb2004-07-09 17:48:53 +0000231 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
paul718e3742002-12-13 20:15:29 +0000232 snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
233 aspath_print (attr->aspath));
paule01f9cb2004-07-09 17:48:53 +0000234
235 if (strlen (buf) > 1)
236 return 1;
237 else
238 return 0;
paul718e3742002-12-13 20:15:29 +0000239}
240
241/* dump notify packet */
242void
paulfd79ac92004-10-13 05:06:08 +0000243bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
244 const char *direct)
paul718e3742002-12-13 20:15:29 +0000245{
paulfd79ac92004-10-13 05:06:08 +0000246 const char *subcode_str;
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000247 const char *code_str;
paul718e3742002-12-13 20:15:29 +0000248
249 subcode_str = "";
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000250 code_str = LOOKUP_DEF (bgp_notify_msg, bgp_notify->code,
251 "Unrecognized Error Code");
paul718e3742002-12-13 20:15:29 +0000252
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000253 switch (bgp_notify->code)
paul718e3742002-12-13 20:15:29 +0000254 {
255 case BGP_NOTIFY_HEADER_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000256 subcode_str = LOOKUP_DEF (bgp_notify_head_msg, bgp_notify->subcode,
257 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000258 break;
259 case BGP_NOTIFY_OPEN_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000260 subcode_str = LOOKUP_DEF (bgp_notify_open_msg, bgp_notify->subcode,
261 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000262 break;
263 case BGP_NOTIFY_UPDATE_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000264 subcode_str = LOOKUP_DEF (bgp_notify_update_msg, bgp_notify->subcode,
265 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000266 break;
267 case BGP_NOTIFY_HOLD_ERR:
paul718e3742002-12-13 20:15:29 +0000268 break;
269 case BGP_NOTIFY_FSM_ERR:
paul718e3742002-12-13 20:15:29 +0000270 break;
271 case BGP_NOTIFY_CEASE:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000272 subcode_str = LOOKUP_DEF (bgp_notify_cease_msg, bgp_notify->subcode,
273 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000274 break;
275 case BGP_NOTIFY_CAPABILITY_ERR:
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000276 subcode_str = LOOKUP_DEF (bgp_notify_capability_msg, bgp_notify->subcode,
277 "Unrecognized Error Subcode");
paul718e3742002-12-13 20:15:29 +0000278 break;
279 }
hasso3950fda2004-05-20 10:22:49 +0000280
281 if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
282 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
283 strcmp (direct, "received") == 0 ? "received from" : "sent to",
284 peer->host, bgp_notify->code, bgp_notify->subcode,
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000285 code_str, subcode_str, bgp_notify->length,
hasso3950fda2004-05-20 10:22:49 +0000286 bgp_notify->data ? bgp_notify->data : "");
287 else if (BGP_DEBUG (normal, NORMAL))
ajs557865c2004-12-08 19:59:11 +0000288 plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
paul718e3742002-12-13 20:15:29 +0000289 peer ? peer->host : "",
290 direct, bgp_notify->code, bgp_notify->subcode,
Leonid Rosenboim1e0ce7c2012-12-07 21:31:07 +0000291 code_str, subcode_str, bgp_notify->length,
paul718e3742002-12-13 20:15:29 +0000292 bgp_notify->data ? bgp_notify->data : "");
293}
David Lamparter6b0655a2014-06-04 06:53:35 +0200294
paul718e3742002-12-13 20:15:29 +0000295/* Debug option setting interface. */
296unsigned long bgp_debug_option = 0;
297
298int
299debug (unsigned int option)
300{
301 return bgp_debug_option & option;
302}
303
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000304DEFUN (debug_bgp_as4,
305 debug_bgp_as4_cmd,
306 "debug bgp as4",
307 DEBUG_STR
308 BGP_STR
309 "BGP AS4 actions\n")
310{
311 if (vty->node == CONFIG_NODE)
312 DEBUG_ON (as4, AS4);
313 else
314 {
315 TERM_DEBUG_ON (as4, AS4);
316 vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
317 }
318 return CMD_SUCCESS;
319}
320
321DEFUN (no_debug_bgp_as4,
322 no_debug_bgp_as4_cmd,
323 "no debug bgp as4",
324 NO_STR
325 DEBUG_STR
326 BGP_STR
327 "BGP AS4 actions\n")
328{
329 if (vty->node == CONFIG_NODE)
330 DEBUG_OFF (as4, AS4);
331 else
332 {
333 TERM_DEBUG_OFF (as4, AS4);
334 vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
335 }
336 return CMD_SUCCESS;
337}
338
339ALIAS (no_debug_bgp_as4,
340 undebug_bgp_as4_cmd,
341 "undebug bgp as4",
342 UNDEBUG_STR
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000343 BGP_STR
344 "BGP AS4 actions\n")
345
346DEFUN (debug_bgp_as4_segment,
347 debug_bgp_as4_segment_cmd,
348 "debug bgp as4 segment",
349 DEBUG_STR
350 BGP_STR
David Ward6e22b902011-01-17 10:58:52 +0300351 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000352 "BGP AS4 aspath segment handling\n")
353{
354 if (vty->node == CONFIG_NODE)
355 DEBUG_ON (as4, AS4_SEGMENT);
356 else
357 {
358 TERM_DEBUG_ON (as4, AS4_SEGMENT);
359 vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
360 }
361 return CMD_SUCCESS;
362}
363
364DEFUN (no_debug_bgp_as4_segment,
365 no_debug_bgp_as4_segment_cmd,
366 "no debug bgp as4 segment",
367 NO_STR
368 DEBUG_STR
369 BGP_STR
David Ward6e22b902011-01-17 10:58:52 +0300370 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000371 "BGP AS4 aspath segment handling\n")
372{
373 if (vty->node == CONFIG_NODE)
374 DEBUG_OFF (as4, AS4_SEGMENT);
375 else
376 {
377 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
378 vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
379 }
380 return CMD_SUCCESS;
381}
382
383ALIAS (no_debug_bgp_as4_segment,
384 undebug_bgp_as4_segment_cmd,
385 "undebug bgp as4 segment",
386 UNDEBUG_STR
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000387 BGP_STR
David Ward6e22b902011-01-17 10:58:52 +0300388 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000389 "BGP AS4 aspath segment handling\n")
390
paul718e3742002-12-13 20:15:29 +0000391DEFUN (debug_bgp_fsm,
392 debug_bgp_fsm_cmd,
393 "debug bgp fsm",
394 DEBUG_STR
395 BGP_STR
396 "BGP Finite State Machine\n")
397{
398 if (vty->node == CONFIG_NODE)
399 DEBUG_ON (fsm, FSM);
400 else
401 {
402 TERM_DEBUG_ON (fsm, FSM);
403 vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
404 }
405 return CMD_SUCCESS;
406}
407
408DEFUN (no_debug_bgp_fsm,
409 no_debug_bgp_fsm_cmd,
410 "no debug bgp fsm",
411 NO_STR
412 DEBUG_STR
413 BGP_STR
414 "Finite State Machine\n")
415{
416 if (vty->node == CONFIG_NODE)
417 DEBUG_OFF (fsm, FSM);
418 else
419 {
420 TERM_DEBUG_OFF (fsm, FSM);
421 vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
422 }
423 return CMD_SUCCESS;
424}
425
426ALIAS (no_debug_bgp_fsm,
427 undebug_bgp_fsm_cmd,
428 "undebug bgp fsm",
429 UNDEBUG_STR
paul718e3742002-12-13 20:15:29 +0000430 BGP_STR
431 "Finite State Machine\n")
432
433DEFUN (debug_bgp_events,
434 debug_bgp_events_cmd,
435 "debug bgp events",
436 DEBUG_STR
437 BGP_STR
438 "BGP events\n")
439{
440 if (vty->node == CONFIG_NODE)
441 DEBUG_ON (events, EVENTS);
442 else
443 {
444 TERM_DEBUG_ON (events, EVENTS);
445 vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
446 }
447 return CMD_SUCCESS;
448}
449
450DEFUN (no_debug_bgp_events,
451 no_debug_bgp_events_cmd,
452 "no debug bgp events",
453 NO_STR
454 DEBUG_STR
455 BGP_STR
456 "BGP events\n")
457{
458 if (vty->node == CONFIG_NODE)
459 DEBUG_OFF (events, EVENTS);
460 else
461 {
462 TERM_DEBUG_OFF (events, EVENTS);
463 vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
464 }
465 return CMD_SUCCESS;
466}
467
468ALIAS (no_debug_bgp_events,
469 undebug_bgp_events_cmd,
470 "undebug bgp events",
471 UNDEBUG_STR
472 BGP_STR
473 "BGP events\n")
474
475DEFUN (debug_bgp_filter,
476 debug_bgp_filter_cmd,
477 "debug bgp filters",
478 DEBUG_STR
479 BGP_STR
480 "BGP filters\n")
481{
482 if (vty->node == CONFIG_NODE)
483 DEBUG_ON (filter, FILTER);
484 else
485 {
486 TERM_DEBUG_ON (filter, FILTER);
487 vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
488 }
489 return CMD_SUCCESS;
490}
491
492DEFUN (no_debug_bgp_filter,
493 no_debug_bgp_filter_cmd,
494 "no debug bgp filters",
495 NO_STR
496 DEBUG_STR
497 BGP_STR
498 "BGP filters\n")
499{
500 if (vty->node == CONFIG_NODE)
501 DEBUG_OFF (filter, FILTER);
502 else
503 {
504 TERM_DEBUG_OFF (filter, FILTER);
505 vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
506 }
507 return CMD_SUCCESS;
508}
509
510ALIAS (no_debug_bgp_filter,
511 undebug_bgp_filter_cmd,
512 "undebug bgp filters",
513 UNDEBUG_STR
514 BGP_STR
515 "BGP filters\n")
516
517DEFUN (debug_bgp_keepalive,
518 debug_bgp_keepalive_cmd,
519 "debug bgp keepalives",
520 DEBUG_STR
521 BGP_STR
522 "BGP keepalives\n")
523{
524 if (vty->node == CONFIG_NODE)
525 DEBUG_ON (keepalive, KEEPALIVE);
526 else
527 {
528 TERM_DEBUG_ON (keepalive, KEEPALIVE);
529 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
530 }
531 return CMD_SUCCESS;
532}
533
534DEFUN (no_debug_bgp_keepalive,
535 no_debug_bgp_keepalive_cmd,
536 "no debug bgp keepalives",
537 NO_STR
538 DEBUG_STR
539 BGP_STR
540 "BGP keepalives\n")
541{
542 if (vty->node == CONFIG_NODE)
543 DEBUG_OFF (keepalive, KEEPALIVE);
544 else
545 {
546 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
547 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
548 }
549 return CMD_SUCCESS;
550}
551
552ALIAS (no_debug_bgp_keepalive,
553 undebug_bgp_keepalive_cmd,
554 "undebug bgp keepalives",
555 UNDEBUG_STR
556 BGP_STR
557 "BGP keepalives\n")
558
559DEFUN (debug_bgp_update,
560 debug_bgp_update_cmd,
561 "debug bgp updates",
562 DEBUG_STR
563 BGP_STR
564 "BGP updates\n")
565{
566 if (vty->node == CONFIG_NODE)
567 {
568 DEBUG_ON (update, UPDATE_IN);
569 DEBUG_ON (update, UPDATE_OUT);
570 }
571 else
572 {
573 TERM_DEBUG_ON (update, UPDATE_IN);
574 TERM_DEBUG_ON (update, UPDATE_OUT);
575 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
576 }
577 return CMD_SUCCESS;
578}
579
580DEFUN (debug_bgp_update_direct,
581 debug_bgp_update_direct_cmd,
582 "debug bgp updates (in|out)",
583 DEBUG_STR
584 BGP_STR
585 "BGP updates\n"
586 "Inbound updates\n"
587 "Outbound updates\n")
588{
589 if (vty->node == CONFIG_NODE)
590 {
591 if (strncmp ("i", argv[0], 1) == 0)
592 {
593 DEBUG_OFF (update, UPDATE_OUT);
594 DEBUG_ON (update, UPDATE_IN);
595 }
596 else
597 {
598 DEBUG_OFF (update, UPDATE_IN);
599 DEBUG_ON (update, UPDATE_OUT);
600 }
601 }
602 else
603 {
604 if (strncmp ("i", argv[0], 1) == 0)
605 {
606 TERM_DEBUG_OFF (update, UPDATE_OUT);
607 TERM_DEBUG_ON (update, UPDATE_IN);
608 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
609 }
610 else
611 {
612 TERM_DEBUG_OFF (update, UPDATE_IN);
613 TERM_DEBUG_ON (update, UPDATE_OUT);
614 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
615 }
616 }
617 return CMD_SUCCESS;
618}
619
620DEFUN (no_debug_bgp_update,
621 no_debug_bgp_update_cmd,
622 "no debug bgp updates",
623 NO_STR
624 DEBUG_STR
625 BGP_STR
626 "BGP updates\n")
627{
628 if (vty->node == CONFIG_NODE)
629 {
630 DEBUG_OFF (update, UPDATE_IN);
631 DEBUG_OFF (update, UPDATE_OUT);
632 }
633 else
634 {
635 TERM_DEBUG_OFF (update, UPDATE_IN);
636 TERM_DEBUG_OFF (update, UPDATE_OUT);
637 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
638 }
639 return CMD_SUCCESS;
640}
641
642ALIAS (no_debug_bgp_update,
643 undebug_bgp_update_cmd,
644 "undebug bgp updates",
645 UNDEBUG_STR
646 BGP_STR
647 "BGP updates\n")
648
649DEFUN (debug_bgp_normal,
650 debug_bgp_normal_cmd,
651 "debug bgp",
652 DEBUG_STR
653 BGP_STR)
654{
655 if (vty->node == CONFIG_NODE)
656 DEBUG_ON (normal, NORMAL);
657 else
658 {
659 TERM_DEBUG_ON (normal, NORMAL);
660 vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
661 }
662 return CMD_SUCCESS;
663}
664
665DEFUN (no_debug_bgp_normal,
666 no_debug_bgp_normal_cmd,
667 "no debug bgp",
668 NO_STR
669 DEBUG_STR
670 BGP_STR)
671{
672 if (vty->node == CONFIG_NODE)
673 DEBUG_OFF (normal, NORMAL);
674 else
675 {
676 TERM_DEBUG_OFF (normal, NORMAL);
677 vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
678 }
679 return CMD_SUCCESS;
680}
681
682ALIAS (no_debug_bgp_normal,
683 undebug_bgp_normal_cmd,
684 "undebug bgp",
685 UNDEBUG_STR
686 BGP_STR)
687
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000688DEFUN (debug_bgp_zebra,
689 debug_bgp_zebra_cmd,
690 "debug bgp zebra",
691 DEBUG_STR
692 BGP_STR
693 "BGP Zebra messages\n")
694{
695 if (vty->node == CONFIG_NODE)
696 DEBUG_ON (zebra, ZEBRA);
697 else
698 {
699 TERM_DEBUG_ON (zebra, ZEBRA);
700 vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
701 }
702 return CMD_SUCCESS;
703}
704
705DEFUN (no_debug_bgp_zebra,
706 no_debug_bgp_zebra_cmd,
707 "no debug bgp zebra",
708 NO_STR
709 DEBUG_STR
710 BGP_STR
711 "BGP Zebra messages\n")
712{
713 if (vty->node == CONFIG_NODE)
714 DEBUG_OFF (zebra, ZEBRA);
715 else
716 {
717 TERM_DEBUG_OFF (zebra, ZEBRA);
718 vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
719 }
720 return CMD_SUCCESS;
721}
722
723ALIAS (no_debug_bgp_zebra,
724 undebug_bgp_zebra_cmd,
725 "undebug bgp zebra",
726 UNDEBUG_STR
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000727 BGP_STR
728 "BGP Zebra messages\n")
729
paul718e3742002-12-13 20:15:29 +0000730DEFUN (no_debug_bgp_all,
731 no_debug_bgp_all_cmd,
732 "no debug all bgp",
733 NO_STR
734 DEBUG_STR
735 "Enable all debugging\n"
736 BGP_STR)
737{
738 TERM_DEBUG_OFF (normal, NORMAL);
739 TERM_DEBUG_OFF (events, EVENTS);
740 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
741 TERM_DEBUG_OFF (update, UPDATE_IN);
742 TERM_DEBUG_OFF (update, UPDATE_OUT);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000743 TERM_DEBUG_OFF (as4, AS4);
744 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
paul718e3742002-12-13 20:15:29 +0000745 TERM_DEBUG_OFF (fsm, FSM);
746 TERM_DEBUG_OFF (filter, FILTER);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000747 TERM_DEBUG_OFF (zebra, ZEBRA);
paul718e3742002-12-13 20:15:29 +0000748 vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
749
750 return CMD_SUCCESS;
751}
752
753ALIAS (no_debug_bgp_all,
754 undebug_bgp_all_cmd,
755 "undebug all bgp",
756 UNDEBUG_STR
757 "Enable all debugging\n"
758 BGP_STR)
759
760DEFUN (show_debugging_bgp,
761 show_debugging_bgp_cmd,
762 "show debugging bgp",
763 SHOW_STR
764 DEBUG_STR
765 BGP_STR)
766{
767 vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
768
769 if (BGP_DEBUG (normal, NORMAL))
770 vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE);
771 if (BGP_DEBUG (events, EVENTS))
772 vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE);
773 if (BGP_DEBUG (keepalive, KEEPALIVE))
774 vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE);
775 if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
776 vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE);
777 else if (BGP_DEBUG (update, UPDATE_IN))
778 vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
779 else if (BGP_DEBUG (update, UPDATE_OUT))
780 vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
781 if (BGP_DEBUG (fsm, FSM))
782 vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE);
783 if (BGP_DEBUG (filter, FILTER))
784 vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000785 if (BGP_DEBUG (zebra, ZEBRA))
786 vty_out (vty, " BGP zebra debugging is on%s", VTY_NEWLINE);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000787 if (BGP_DEBUG (as4, AS4))
788 vty_out (vty, " BGP as4 debugging is on%s", VTY_NEWLINE);
789 if (BGP_DEBUG (as4, AS4_SEGMENT))
790 vty_out (vty, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000791 vty_out (vty, "%s", VTY_NEWLINE);
792 return CMD_SUCCESS;
793}
794
paul94f2b392005-06-28 12:44:16 +0000795static int
paul718e3742002-12-13 20:15:29 +0000796bgp_config_write_debug (struct vty *vty)
797{
798 int write = 0;
799
800 if (CONF_BGP_DEBUG (normal, NORMAL))
801 {
802 vty_out (vty, "debug bgp%s", VTY_NEWLINE);
803 write++;
804 }
805
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000806 if (CONF_BGP_DEBUG (as4, AS4))
807 {
808 vty_out (vty, "debug bgp as4%s", VTY_NEWLINE);
809 write++;
810 }
811
812 if (CONF_BGP_DEBUG (as4, AS4_SEGMENT))
813 {
814 vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE);
815 write++;
816 }
817
paul718e3742002-12-13 20:15:29 +0000818 if (CONF_BGP_DEBUG (events, EVENTS))
819 {
820 vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
821 write++;
822 }
823
824 if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
825 {
826 vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
827 write++;
828 }
829
830 if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
831 {
832 vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
833 write++;
834 }
835 else if (CONF_BGP_DEBUG (update, UPDATE_IN))
836 {
837 vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
838 write++;
839 }
840 else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
841 {
842 vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
843 write++;
844 }
845
846 if (CONF_BGP_DEBUG (fsm, FSM))
847 {
848 vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
849 write++;
850 }
851
852 if (CONF_BGP_DEBUG (filter, FILTER))
853 {
854 vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
855 write++;
856 }
857
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000858 if (CONF_BGP_DEBUG (zebra, ZEBRA))
859 {
860 vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
861 write++;
862 }
863
paul718e3742002-12-13 20:15:29 +0000864 return write;
865}
866
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800867static struct cmd_node debug_node =
paul718e3742002-12-13 20:15:29 +0000868{
869 DEBUG_NODE,
870 "",
871 1
872};
873
874void
paul94f2b392005-06-28 12:44:16 +0000875bgp_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000876{
877 install_node (&debug_node, bgp_config_write_debug);
878
879 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
880
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000881 install_element (ENABLE_NODE, &debug_bgp_as4_cmd);
882 install_element (CONFIG_NODE, &debug_bgp_as4_cmd);
883 install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd);
884 install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd);
885
paul718e3742002-12-13 20:15:29 +0000886 install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
887 install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
888 install_element (ENABLE_NODE, &debug_bgp_events_cmd);
889 install_element (CONFIG_NODE, &debug_bgp_events_cmd);
890 install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
891 install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
892 install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
893 install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
894 install_element (ENABLE_NODE, &debug_bgp_update_cmd);
895 install_element (CONFIG_NODE, &debug_bgp_update_cmd);
896 install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
897 install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
898 install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
899 install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000900 install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
901 install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
paul718e3742002-12-13 20:15:29 +0000902
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000903 install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd);
904 install_element (ENABLE_NODE, &undebug_bgp_as4_cmd);
905 install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd);
906 install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
907 install_element (ENABLE_NODE, &undebug_bgp_as4_segment_cmd);
908 install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
909
paul718e3742002-12-13 20:15:29 +0000910 install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
911 install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
912 install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
913 install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
914 install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
915 install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
916 install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
917 install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
918 install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
919 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
920 install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
921 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
922 install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
923 install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
924 install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
925 install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
926 install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
927 install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000928 install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
929 install_element (ENABLE_NODE, &undebug_bgp_zebra_cmd);
930 install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
paul718e3742002-12-13 20:15:29 +0000931 install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
932 install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
933}