]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_debug.c
bgpd: bgpd-update-delay.patch
[mirror_frr.git] / bgpd / bgp_debug.c
CommitLineData
718e3744 1/* 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
5e4fa164 23#include <lib/version.h>
718e3744 24#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
0b2aa3a0 39unsigned long conf_bgp_debug_as4;
718e3744 40unsigned 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;
a39275d7 47unsigned long conf_bgp_debug_zebra;
718e3744 48
0b2aa3a0 49unsigned long term_bgp_debug_as4;
718e3744 50unsigned 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;
a39275d7 57unsigned long term_bgp_debug_zebra;
718e3744 58
59/* messages for BGP-4 status */
b2d933f8 60const struct message bgp_status_msg[] =
718e3744 61{
718e3744 62 { Idle, "Idle" },
63 { Connect, "Connect" },
64 { Active, "Active" },
65 { OpenSent, "OpenSent" },
66 { OpenConfirm, "OpenConfirm" },
67 { Established, "Established" },
ca058a30
PJ
68 { Clearing, "Clearing" },
69 { Deleted, "Deleted" },
718e3744 70};
b2d933f8 71const int bgp_status_msg_max = BGP_STATUS_MAX;
718e3744 72
73/* BGP message type string. */
fd79ac91 74const char *bgp_type_str[] =
718e3744 75{
76 NULL,
77 "OPEN",
78 "UPDATE",
79 "NOTIFICATION",
80 "KEEPALIVE",
81 "ROUTE-REFRESH",
82 "CAPABILITY"
83};
84
85/* message for BGP-4 Notify */
b2d933f8 86static const struct message bgp_notify_msg[] =
718e3744 87{
718e3744 88 { 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};
b2d933f8 96static const int bgp_notify_msg_max = BGP_NOTIFY_MAX;
718e3744 97
b2d933f8 98static const struct message bgp_notify_head_msg[] =
718e3744 99{
3950fda5 100 { 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"}
718e3744 103};
b2d933f8 104static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
718e3744 105
b2d933f8 106static const struct message bgp_notify_open_msg[] =
718e3744 107{
4b4e07d2 108 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 109 { 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"},
718e3744 116};
b2d933f8 117static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
718e3744 118
b2d933f8 119static const struct message bgp_notify_update_msg[] =
718e3744 120{
4b4e07d2 121 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 122 { 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"},
718e3744 133};
b2d933f8 134static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
718e3744 135
b2d933f8 136static const struct message bgp_notify_cease_msg[] =
718e3744 137{
4b4e07d2 138 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 139 { 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"},
718e3744 147};
b2d933f8 148static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
718e3744 149
b2d933f8 150static const struct message bgp_notify_capability_msg[] =
718e3744 151{
4b4e07d2 152 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 153 { 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"},
718e3744 156};
b2d933f8 157static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
718e3744 158
159/* Origin strings. */
fd79ac91 160const char *bgp_origin_str[] = {"i","e","?"};
161const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
718e3744 162
163/* Dump attribute. */
e01f9cbb 164int
718e3744 165bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
166{
718e3744 167 if (! attr)
e01f9cbb 168 return 0;
718e3744 169
e01f9cbb 170 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]);
718e3744 176
177#ifdef HAVE_IPV6
fb982c25
PJ
178 if (attr->extra)
179 {
180 char addrbuf[BUFSIZ];
181
182 /* 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));
188
189 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 }
718e3744 194#endif /* HAVE_IPV6 */
195
e01f9cbb 196 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
ddc943de 197 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u",
718e3744 198 attr->local_pref);
199
e01f9cbb 200 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
ddc943de 201 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %u",
718e3744 202 attr->med);
203
e01f9cbb 204 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)))
718e3744 205 snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
206 community_str (attr->community));
207
e01f9cbb 208 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
718e3744 209 snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
210
e01f9cbb 211 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
aea339f7 212 snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s",
fb982c25
PJ
213 attr->extra->aggregator_as,
214 inet_ntoa (attr->extra->aggregator_addr));
718e3744 215
e01f9cbb 216 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
718e3744 217 snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
fb982c25 218 inet_ntoa (attr->extra->originator_id));
718e3744 219
e01f9cbb 220 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
718e3744 221 {
222 int i;
223
e01f9cbb 224 snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
fb982c25 225 for (i = 0; i < attr->extra->cluster->length / 4; i++)
e01f9cbb 226 snprintf (buf + strlen (buf), size - strlen (buf), " %s",
fb982c25 227 inet_ntoa (attr->extra->cluster->list[i]));
718e3744 228 }
229
e01f9cbb 230 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
718e3744 231 snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
232 aspath_print (attr->aspath));
e01f9cbb 233
234 if (strlen (buf) > 1)
235 return 1;
236 else
237 return 0;
718e3744 238}
239
240/* dump notify packet */
241void
fd79ac91 242bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
243 const char *direct)
718e3744 244{
fd79ac91 245 const char *subcode_str;
1e0ce7ca 246 const char *code_str;
718e3744 247
248 subcode_str = "";
1e0ce7ca
LR
249 code_str = LOOKUP_DEF (bgp_notify_msg, bgp_notify->code,
250 "Unrecognized Error Code");
718e3744 251
1e0ce7ca 252 switch (bgp_notify->code)
718e3744 253 {
254 case BGP_NOTIFY_HEADER_ERR:
1e0ce7ca
LR
255 subcode_str = LOOKUP_DEF (bgp_notify_head_msg, bgp_notify->subcode,
256 "Unrecognized Error Subcode");
718e3744 257 break;
258 case BGP_NOTIFY_OPEN_ERR:
1e0ce7ca
LR
259 subcode_str = LOOKUP_DEF (bgp_notify_open_msg, bgp_notify->subcode,
260 "Unrecognized Error Subcode");
718e3744 261 break;
262 case BGP_NOTIFY_UPDATE_ERR:
1e0ce7ca
LR
263 subcode_str = LOOKUP_DEF (bgp_notify_update_msg, bgp_notify->subcode,
264 "Unrecognized Error Subcode");
718e3744 265 break;
266 case BGP_NOTIFY_HOLD_ERR:
718e3744 267 break;
268 case BGP_NOTIFY_FSM_ERR:
718e3744 269 break;
270 case BGP_NOTIFY_CEASE:
1e0ce7ca
LR
271 subcode_str = LOOKUP_DEF (bgp_notify_cease_msg, bgp_notify->subcode,
272 "Unrecognized Error Subcode");
718e3744 273 break;
274 case BGP_NOTIFY_CAPABILITY_ERR:
1e0ce7ca
LR
275 subcode_str = LOOKUP_DEF (bgp_notify_capability_msg, bgp_notify->subcode,
276 "Unrecognized Error Subcode");
718e3744 277 break;
278 }
3950fda5 279
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,
1e0ce7ca 284 code_str, subcode_str, bgp_notify->length,
3950fda5 285 bgp_notify->data ? bgp_notify->data : "");
286 else if (BGP_DEBUG (normal, NORMAL))
557865c2 287 plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
718e3744 288 peer ? peer->host : "",
289 direct, bgp_notify->code, bgp_notify->subcode,
1e0ce7ca 290 code_str, subcode_str, bgp_notify->length,
718e3744 291 bgp_notify->data ? bgp_notify->data : "");
292}
6b0655a2 293
718e3744 294/* 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
0b2aa3a0
PJ
303DEFUN (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
0b2aa3a0
PJ
342 BGP_STR
343 "BGP AS4 actions\n")
344
345DEFUN (debug_bgp_as4_segment,
346 debug_bgp_as4_segment_cmd,
347 "debug bgp as4 segment",
348 DEBUG_STR
349 BGP_STR
6e22b901 350 "BGP AS4 actions\n"
0b2aa3a0
PJ
351 "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
6e22b901 369 "BGP AS4 actions\n"
0b2aa3a0
PJ
370 "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
0b2aa3a0 386 BGP_STR
6e22b901 387 "BGP AS4 actions\n"
0b2aa3a0
PJ
388 "BGP AS4 aspath segment handling\n")
389
718e3744 390DEFUN (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
718e3744 429 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
a39275d7
AS
687DEFUN (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
a39275d7
AS
726 BGP_STR
727 "BGP Zebra messages\n")
728
718e3744 729DEFUN (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);
0b2aa3a0
PJ
742 TERM_DEBUG_OFF (as4, AS4);
743 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
718e3744 744 TERM_DEBUG_OFF (fsm, FSM);
745 TERM_DEBUG_OFF (filter, FILTER);
a39275d7 746 TERM_DEBUG_OFF (zebra, ZEBRA);
718e3744 747 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);
a39275d7
AS
784 if (BGP_DEBUG (zebra, ZEBRA))
785 vty_out (vty, " BGP zebra debugging is on%s", VTY_NEWLINE);
0b2aa3a0
PJ
786 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);
718e3744 790 vty_out (vty, "%s", VTY_NEWLINE);
791 return CMD_SUCCESS;
792}
793
94f2b392 794static int
718e3744 795bgp_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
0b2aa3a0
PJ
805 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
718e3744 817 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
a39275d7
AS
857 if (CONF_BGP_DEBUG (zebra, ZEBRA))
858 {
859 vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
860 write++;
861 }
862
718e3744 863 return write;
864}
865
7fc626de 866static struct cmd_node debug_node =
718e3744 867{
868 DEBUG_NODE,
869 "",
870 1
871};
872
873void
94f2b392 874bgp_debug_init (void)
718e3744 875{
876 install_node (&debug_node, bgp_config_write_debug);
877
878 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
879
0b2aa3a0
PJ
880 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
718e3744 885 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);
a39275d7
AS
899 install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
900 install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
718e3744 901
0b2aa3a0
PJ
902 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
718e3744 909 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);
a39275d7
AS
927 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);
718e3744 930 install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
931 install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
932}