blob: 8e16186458f25b3318ebfe2006768f3929d58960 [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 Tejblumc3478462011-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 Tejblumc3478462011-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 Tejblumc3478462011-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 Tejblumc3478462011-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)))
paul718e3742002-12-13 20:15:29 +0000197 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d",
198 attr->local_pref);
199
paule01f9cb2004-07-09 17:48:53 +0000200 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
paul718e3742002-12-13 20:15:29 +0000201 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %d",
202 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;
paul718e3742002-12-13 20:15:29 +0000246
247 subcode_str = "";
248
249 switch (bgp_notify->code)
250 {
251 case BGP_NOTIFY_HEADER_ERR:
252 subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode);
253 break;
254 case BGP_NOTIFY_OPEN_ERR:
255 subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode);
256 break;
257 case BGP_NOTIFY_UPDATE_ERR:
258 subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode);
259 break;
260 case BGP_NOTIFY_HOLD_ERR:
261 subcode_str = "";
262 break;
263 case BGP_NOTIFY_FSM_ERR:
264 subcode_str = "";
265 break;
266 case BGP_NOTIFY_CEASE:
267 subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode);
268 break;
269 case BGP_NOTIFY_CAPABILITY_ERR:
270 subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode);
271 break;
272 }
hasso3950fda2004-05-20 10:22:49 +0000273
274 if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
275 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
276 strcmp (direct, "received") == 0 ? "received from" : "sent to",
277 peer->host, bgp_notify->code, bgp_notify->subcode,
278 LOOKUP (bgp_notify_msg, bgp_notify->code),
279 subcode_str, bgp_notify->length,
280 bgp_notify->data ? bgp_notify->data : "");
281 else if (BGP_DEBUG (normal, NORMAL))
ajs557865c2004-12-08 19:59:11 +0000282 plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
paul718e3742002-12-13 20:15:29 +0000283 peer ? peer->host : "",
284 direct, bgp_notify->code, bgp_notify->subcode,
285 LOOKUP (bgp_notify_msg, bgp_notify->code),
286 subcode_str, bgp_notify->length,
287 bgp_notify->data ? bgp_notify->data : "");
288}
289
290/* Debug option setting interface. */
291unsigned long bgp_debug_option = 0;
292
293int
294debug (unsigned int option)
295{
296 return bgp_debug_option & option;
297}
298
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000299DEFUN (debug_bgp_as4,
300 debug_bgp_as4_cmd,
301 "debug bgp as4",
302 DEBUG_STR
303 BGP_STR
304 "BGP AS4 actions\n")
305{
306 if (vty->node == CONFIG_NODE)
307 DEBUG_ON (as4, AS4);
308 else
309 {
310 TERM_DEBUG_ON (as4, AS4);
311 vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
312 }
313 return CMD_SUCCESS;
314}
315
316DEFUN (no_debug_bgp_as4,
317 no_debug_bgp_as4_cmd,
318 "no debug bgp as4",
319 NO_STR
320 DEBUG_STR
321 BGP_STR
322 "BGP AS4 actions\n")
323{
324 if (vty->node == CONFIG_NODE)
325 DEBUG_OFF (as4, AS4);
326 else
327 {
328 TERM_DEBUG_OFF (as4, AS4);
329 vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
330 }
331 return CMD_SUCCESS;
332}
333
334ALIAS (no_debug_bgp_as4,
335 undebug_bgp_as4_cmd,
336 "undebug bgp as4",
337 UNDEBUG_STR
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000338 BGP_STR
339 "BGP AS4 actions\n")
340
341DEFUN (debug_bgp_as4_segment,
342 debug_bgp_as4_segment_cmd,
343 "debug bgp as4 segment",
344 DEBUG_STR
345 BGP_STR
David Ward16ac5972011-01-17 10:58:52 +0300346 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000347 "BGP AS4 aspath segment handling\n")
348{
349 if (vty->node == CONFIG_NODE)
350 DEBUG_ON (as4, AS4_SEGMENT);
351 else
352 {
353 TERM_DEBUG_ON (as4, AS4_SEGMENT);
354 vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
355 }
356 return CMD_SUCCESS;
357}
358
359DEFUN (no_debug_bgp_as4_segment,
360 no_debug_bgp_as4_segment_cmd,
361 "no debug bgp as4 segment",
362 NO_STR
363 DEBUG_STR
364 BGP_STR
David Ward16ac5972011-01-17 10:58:52 +0300365 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000366 "BGP AS4 aspath segment handling\n")
367{
368 if (vty->node == CONFIG_NODE)
369 DEBUG_OFF (as4, AS4_SEGMENT);
370 else
371 {
372 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
373 vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
374 }
375 return CMD_SUCCESS;
376}
377
378ALIAS (no_debug_bgp_as4_segment,
379 undebug_bgp_as4_segment_cmd,
380 "undebug bgp as4 segment",
381 UNDEBUG_STR
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000382 BGP_STR
David Ward16ac5972011-01-17 10:58:52 +0300383 "BGP AS4 actions\n"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000384 "BGP AS4 aspath segment handling\n")
385
paul718e3742002-12-13 20:15:29 +0000386DEFUN (debug_bgp_fsm,
387 debug_bgp_fsm_cmd,
388 "debug bgp fsm",
389 DEBUG_STR
390 BGP_STR
391 "BGP Finite State Machine\n")
392{
393 if (vty->node == CONFIG_NODE)
394 DEBUG_ON (fsm, FSM);
395 else
396 {
397 TERM_DEBUG_ON (fsm, FSM);
398 vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
399 }
400 return CMD_SUCCESS;
401}
402
403DEFUN (no_debug_bgp_fsm,
404 no_debug_bgp_fsm_cmd,
405 "no debug bgp fsm",
406 NO_STR
407 DEBUG_STR
408 BGP_STR
409 "Finite State Machine\n")
410{
411 if (vty->node == CONFIG_NODE)
412 DEBUG_OFF (fsm, FSM);
413 else
414 {
415 TERM_DEBUG_OFF (fsm, FSM);
416 vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
417 }
418 return CMD_SUCCESS;
419}
420
421ALIAS (no_debug_bgp_fsm,
422 undebug_bgp_fsm_cmd,
423 "undebug bgp fsm",
424 UNDEBUG_STR
paul718e3742002-12-13 20:15:29 +0000425 BGP_STR
426 "Finite State Machine\n")
427
428DEFUN (debug_bgp_events,
429 debug_bgp_events_cmd,
430 "debug bgp events",
431 DEBUG_STR
432 BGP_STR
433 "BGP events\n")
434{
435 if (vty->node == CONFIG_NODE)
436 DEBUG_ON (events, EVENTS);
437 else
438 {
439 TERM_DEBUG_ON (events, EVENTS);
440 vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
441 }
442 return CMD_SUCCESS;
443}
444
445DEFUN (no_debug_bgp_events,
446 no_debug_bgp_events_cmd,
447 "no debug bgp events",
448 NO_STR
449 DEBUG_STR
450 BGP_STR
451 "BGP events\n")
452{
453 if (vty->node == CONFIG_NODE)
454 DEBUG_OFF (events, EVENTS);
455 else
456 {
457 TERM_DEBUG_OFF (events, EVENTS);
458 vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
459 }
460 return CMD_SUCCESS;
461}
462
463ALIAS (no_debug_bgp_events,
464 undebug_bgp_events_cmd,
465 "undebug bgp events",
466 UNDEBUG_STR
467 BGP_STR
468 "BGP events\n")
469
470DEFUN (debug_bgp_filter,
471 debug_bgp_filter_cmd,
472 "debug bgp filters",
473 DEBUG_STR
474 BGP_STR
475 "BGP filters\n")
476{
477 if (vty->node == CONFIG_NODE)
478 DEBUG_ON (filter, FILTER);
479 else
480 {
481 TERM_DEBUG_ON (filter, FILTER);
482 vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
483 }
484 return CMD_SUCCESS;
485}
486
487DEFUN (no_debug_bgp_filter,
488 no_debug_bgp_filter_cmd,
489 "no debug bgp filters",
490 NO_STR
491 DEBUG_STR
492 BGP_STR
493 "BGP filters\n")
494{
495 if (vty->node == CONFIG_NODE)
496 DEBUG_OFF (filter, FILTER);
497 else
498 {
499 TERM_DEBUG_OFF (filter, FILTER);
500 vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
501 }
502 return CMD_SUCCESS;
503}
504
505ALIAS (no_debug_bgp_filter,
506 undebug_bgp_filter_cmd,
507 "undebug bgp filters",
508 UNDEBUG_STR
509 BGP_STR
510 "BGP filters\n")
511
512DEFUN (debug_bgp_keepalive,
513 debug_bgp_keepalive_cmd,
514 "debug bgp keepalives",
515 DEBUG_STR
516 BGP_STR
517 "BGP keepalives\n")
518{
519 if (vty->node == CONFIG_NODE)
520 DEBUG_ON (keepalive, KEEPALIVE);
521 else
522 {
523 TERM_DEBUG_ON (keepalive, KEEPALIVE);
524 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
525 }
526 return CMD_SUCCESS;
527}
528
529DEFUN (no_debug_bgp_keepalive,
530 no_debug_bgp_keepalive_cmd,
531 "no debug bgp keepalives",
532 NO_STR
533 DEBUG_STR
534 BGP_STR
535 "BGP keepalives\n")
536{
537 if (vty->node == CONFIG_NODE)
538 DEBUG_OFF (keepalive, KEEPALIVE);
539 else
540 {
541 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
542 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
543 }
544 return CMD_SUCCESS;
545}
546
547ALIAS (no_debug_bgp_keepalive,
548 undebug_bgp_keepalive_cmd,
549 "undebug bgp keepalives",
550 UNDEBUG_STR
551 BGP_STR
552 "BGP keepalives\n")
553
554DEFUN (debug_bgp_update,
555 debug_bgp_update_cmd,
556 "debug bgp updates",
557 DEBUG_STR
558 BGP_STR
559 "BGP updates\n")
560{
561 if (vty->node == CONFIG_NODE)
562 {
563 DEBUG_ON (update, UPDATE_IN);
564 DEBUG_ON (update, UPDATE_OUT);
565 }
566 else
567 {
568 TERM_DEBUG_ON (update, UPDATE_IN);
569 TERM_DEBUG_ON (update, UPDATE_OUT);
570 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
571 }
572 return CMD_SUCCESS;
573}
574
575DEFUN (debug_bgp_update_direct,
576 debug_bgp_update_direct_cmd,
577 "debug bgp updates (in|out)",
578 DEBUG_STR
579 BGP_STR
580 "BGP updates\n"
581 "Inbound updates\n"
582 "Outbound updates\n")
583{
584 if (vty->node == CONFIG_NODE)
585 {
586 if (strncmp ("i", argv[0], 1) == 0)
587 {
588 DEBUG_OFF (update, UPDATE_OUT);
589 DEBUG_ON (update, UPDATE_IN);
590 }
591 else
592 {
593 DEBUG_OFF (update, UPDATE_IN);
594 DEBUG_ON (update, UPDATE_OUT);
595 }
596 }
597 else
598 {
599 if (strncmp ("i", argv[0], 1) == 0)
600 {
601 TERM_DEBUG_OFF (update, UPDATE_OUT);
602 TERM_DEBUG_ON (update, UPDATE_IN);
603 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
604 }
605 else
606 {
607 TERM_DEBUG_OFF (update, UPDATE_IN);
608 TERM_DEBUG_ON (update, UPDATE_OUT);
609 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
610 }
611 }
612 return CMD_SUCCESS;
613}
614
615DEFUN (no_debug_bgp_update,
616 no_debug_bgp_update_cmd,
617 "no debug bgp updates",
618 NO_STR
619 DEBUG_STR
620 BGP_STR
621 "BGP updates\n")
622{
623 if (vty->node == CONFIG_NODE)
624 {
625 DEBUG_OFF (update, UPDATE_IN);
626 DEBUG_OFF (update, UPDATE_OUT);
627 }
628 else
629 {
630 TERM_DEBUG_OFF (update, UPDATE_IN);
631 TERM_DEBUG_OFF (update, UPDATE_OUT);
632 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
633 }
634 return CMD_SUCCESS;
635}
636
637ALIAS (no_debug_bgp_update,
638 undebug_bgp_update_cmd,
639 "undebug bgp updates",
640 UNDEBUG_STR
641 BGP_STR
642 "BGP updates\n")
643
644DEFUN (debug_bgp_normal,
645 debug_bgp_normal_cmd,
646 "debug bgp",
647 DEBUG_STR
648 BGP_STR)
649{
650 if (vty->node == CONFIG_NODE)
651 DEBUG_ON (normal, NORMAL);
652 else
653 {
654 TERM_DEBUG_ON (normal, NORMAL);
655 vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
656 }
657 return CMD_SUCCESS;
658}
659
660DEFUN (no_debug_bgp_normal,
661 no_debug_bgp_normal_cmd,
662 "no debug bgp",
663 NO_STR
664 DEBUG_STR
665 BGP_STR)
666{
667 if (vty->node == CONFIG_NODE)
668 DEBUG_OFF (normal, NORMAL);
669 else
670 {
671 TERM_DEBUG_OFF (normal, NORMAL);
672 vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
673 }
674 return CMD_SUCCESS;
675}
676
677ALIAS (no_debug_bgp_normal,
678 undebug_bgp_normal_cmd,
679 "undebug bgp",
680 UNDEBUG_STR
681 BGP_STR)
682
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000683DEFUN (debug_bgp_zebra,
684 debug_bgp_zebra_cmd,
685 "debug bgp zebra",
686 DEBUG_STR
687 BGP_STR
688 "BGP Zebra messages\n")
689{
690 if (vty->node == CONFIG_NODE)
691 DEBUG_ON (zebra, ZEBRA);
692 else
693 {
694 TERM_DEBUG_ON (zebra, ZEBRA);
695 vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
696 }
697 return CMD_SUCCESS;
698}
699
700DEFUN (no_debug_bgp_zebra,
701 no_debug_bgp_zebra_cmd,
702 "no debug bgp zebra",
703 NO_STR
704 DEBUG_STR
705 BGP_STR
706 "BGP Zebra messages\n")
707{
708 if (vty->node == CONFIG_NODE)
709 DEBUG_OFF (zebra, ZEBRA);
710 else
711 {
712 TERM_DEBUG_OFF (zebra, ZEBRA);
713 vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
714 }
715 return CMD_SUCCESS;
716}
717
718ALIAS (no_debug_bgp_zebra,
719 undebug_bgp_zebra_cmd,
720 "undebug bgp zebra",
721 UNDEBUG_STR
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000722 BGP_STR
723 "BGP Zebra messages\n")
724
paul718e3742002-12-13 20:15:29 +0000725DEFUN (no_debug_bgp_all,
726 no_debug_bgp_all_cmd,
727 "no debug all bgp",
728 NO_STR
729 DEBUG_STR
730 "Enable all debugging\n"
731 BGP_STR)
732{
733 TERM_DEBUG_OFF (normal, NORMAL);
734 TERM_DEBUG_OFF (events, EVENTS);
735 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
736 TERM_DEBUG_OFF (update, UPDATE_IN);
737 TERM_DEBUG_OFF (update, UPDATE_OUT);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000738 TERM_DEBUG_OFF (as4, AS4);
739 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
paul718e3742002-12-13 20:15:29 +0000740 TERM_DEBUG_OFF (fsm, FSM);
741 TERM_DEBUG_OFF (filter, FILTER);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000742 TERM_DEBUG_OFF (zebra, ZEBRA);
paul718e3742002-12-13 20:15:29 +0000743 vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
744
745 return CMD_SUCCESS;
746}
747
748ALIAS (no_debug_bgp_all,
749 undebug_bgp_all_cmd,
750 "undebug all bgp",
751 UNDEBUG_STR
752 "Enable all debugging\n"
753 BGP_STR)
754
755DEFUN (show_debugging_bgp,
756 show_debugging_bgp_cmd,
757 "show debugging bgp",
758 SHOW_STR
759 DEBUG_STR
760 BGP_STR)
761{
762 vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
763
764 if (BGP_DEBUG (normal, NORMAL))
765 vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE);
766 if (BGP_DEBUG (events, EVENTS))
767 vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE);
768 if (BGP_DEBUG (keepalive, KEEPALIVE))
769 vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE);
770 if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
771 vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE);
772 else if (BGP_DEBUG (update, UPDATE_IN))
773 vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
774 else if (BGP_DEBUG (update, UPDATE_OUT))
775 vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
776 if (BGP_DEBUG (fsm, FSM))
777 vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE);
778 if (BGP_DEBUG (filter, FILTER))
779 vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000780 if (BGP_DEBUG (zebra, ZEBRA))
781 vty_out (vty, " BGP zebra debugging is on%s", VTY_NEWLINE);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000782 if (BGP_DEBUG (as4, AS4))
783 vty_out (vty, " BGP as4 debugging is on%s", VTY_NEWLINE);
784 if (BGP_DEBUG (as4, AS4_SEGMENT))
785 vty_out (vty, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000786 vty_out (vty, "%s", VTY_NEWLINE);
787 return CMD_SUCCESS;
788}
789
paul94f2b392005-06-28 12:44:16 +0000790static int
paul718e3742002-12-13 20:15:29 +0000791bgp_config_write_debug (struct vty *vty)
792{
793 int write = 0;
794
795 if (CONF_BGP_DEBUG (normal, NORMAL))
796 {
797 vty_out (vty, "debug bgp%s", VTY_NEWLINE);
798 write++;
799 }
800
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000801 if (CONF_BGP_DEBUG (as4, AS4))
802 {
803 vty_out (vty, "debug bgp as4%s", VTY_NEWLINE);
804 write++;
805 }
806
807 if (CONF_BGP_DEBUG (as4, AS4_SEGMENT))
808 {
809 vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE);
810 write++;
811 }
812
paul718e3742002-12-13 20:15:29 +0000813 if (CONF_BGP_DEBUG (events, EVENTS))
814 {
815 vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
816 write++;
817 }
818
819 if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
820 {
821 vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
822 write++;
823 }
824
825 if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
826 {
827 vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
828 write++;
829 }
830 else if (CONF_BGP_DEBUG (update, UPDATE_IN))
831 {
832 vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
833 write++;
834 }
835 else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
836 {
837 vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
838 write++;
839 }
840
841 if (CONF_BGP_DEBUG (fsm, FSM))
842 {
843 vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
844 write++;
845 }
846
847 if (CONF_BGP_DEBUG (filter, FILTER))
848 {
849 vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
850 write++;
851 }
852
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000853 if (CONF_BGP_DEBUG (zebra, ZEBRA))
854 {
855 vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
856 write++;
857 }
858
paul718e3742002-12-13 20:15:29 +0000859 return write;
860}
861
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800862static struct cmd_node debug_node =
paul718e3742002-12-13 20:15:29 +0000863{
864 DEBUG_NODE,
865 "",
866 1
867};
868
869void
paul94f2b392005-06-28 12:44:16 +0000870bgp_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000871{
872 install_node (&debug_node, bgp_config_write_debug);
873
874 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
875
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000876 install_element (ENABLE_NODE, &debug_bgp_as4_cmd);
877 install_element (CONFIG_NODE, &debug_bgp_as4_cmd);
878 install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd);
879 install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd);
880
paul718e3742002-12-13 20:15:29 +0000881 install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
882 install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
883 install_element (ENABLE_NODE, &debug_bgp_events_cmd);
884 install_element (CONFIG_NODE, &debug_bgp_events_cmd);
885 install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
886 install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
887 install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
888 install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
889 install_element (ENABLE_NODE, &debug_bgp_update_cmd);
890 install_element (CONFIG_NODE, &debug_bgp_update_cmd);
891 install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
892 install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
893 install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
894 install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000895 install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
896 install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
paul718e3742002-12-13 20:15:29 +0000897
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000898 install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd);
899 install_element (ENABLE_NODE, &undebug_bgp_as4_cmd);
900 install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd);
901 install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
902 install_element (ENABLE_NODE, &undebug_bgp_as4_segment_cmd);
903 install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
904
paul718e3742002-12-13 20:15:29 +0000905 install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
906 install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
907 install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
908 install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
909 install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
910 install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
911 install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
912 install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
913 install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
914 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
915 install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
916 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
917 install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
918 install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
919 install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
920 install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
921 install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
922 install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
Andrew J. Schorra39275d2006-11-30 16:36:57 +0000923 install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
924 install_element (ENABLE_NODE, &undebug_bgp_zebra_cmd);
925 install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
paul718e3742002-12-13 20:15:29 +0000926 install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
927 install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
928}