1 /* BGP-4, BGP-4+ packet debug routine
2 * Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <lib/version.h>
29 #include "sockunion.h"
34 #include "bgpd/bgpd.h"
35 #include "bgpd/bgp_aspath.h"
36 #include "bgpd/bgp_route.h"
37 #include "bgpd/bgp_attr.h"
38 #include "bgpd/bgp_debug.h"
39 #include "bgpd/bgp_community.h"
40 #include "bgpd/bgp_updgrp.h"
41 #include "bgpd/bgp_mplsvpn.h"
43 #define BGP_ADDPATH_STR 20
45 unsigned long conf_bgp_debug_as4
;
46 unsigned long conf_bgp_debug_neighbor_events
;
47 unsigned long conf_bgp_debug_events
;
48 unsigned long conf_bgp_debug_packet
;
49 unsigned long conf_bgp_debug_filter
;
50 unsigned long conf_bgp_debug_keepalive
;
51 unsigned long conf_bgp_debug_update
;
52 unsigned long conf_bgp_debug_bestpath
;
53 unsigned long conf_bgp_debug_zebra
;
54 unsigned long conf_bgp_debug_allow_martians
;
55 unsigned long conf_bgp_debug_nht
;
56 unsigned long conf_bgp_debug_update_groups
;
58 unsigned long term_bgp_debug_as4
;
59 unsigned long term_bgp_debug_neighbor_events
;
60 unsigned long term_bgp_debug_events
;
61 unsigned long term_bgp_debug_packet
;
62 unsigned long term_bgp_debug_filter
;
63 unsigned long term_bgp_debug_keepalive
;
64 unsigned long term_bgp_debug_update
;
65 unsigned long term_bgp_debug_bestpath
;
66 unsigned long term_bgp_debug_zebra
;
67 unsigned long term_bgp_debug_allow_martians
;
68 unsigned long term_bgp_debug_nht
;
69 unsigned long term_bgp_debug_update_groups
;
71 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
72 struct list
*bgp_debug_keepalive_peers
= NULL
;
73 struct list
*bgp_debug_update_out_peers
= NULL
;
74 struct list
*bgp_debug_update_in_peers
= NULL
;
75 struct list
*bgp_debug_update_prefixes
= NULL
;
76 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
77 struct list
*bgp_debug_zebra_prefixes
= NULL
;
79 /* messages for BGP-4 status */
80 const struct message bgp_status_msg
[] =
83 { Connect
, "Connect" },
85 { OpenSent
, "OpenSent" },
86 { OpenConfirm
, "OpenConfirm" },
87 { Established
, "Established" },
88 { Clearing
, "Clearing" },
89 { Deleted
, "Deleted" },
91 const int bgp_status_msg_max
= BGP_STATUS_MAX
;
93 /* BGP message type string. */
94 const char *bgp_type_str
[] =
105 /* message for BGP-4 Notify */
106 static const struct message bgp_notify_msg
[] =
108 { BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
109 { BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
110 { BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
111 { BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
112 { BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
113 { BGP_NOTIFY_CEASE
, "Cease"},
114 { BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
116 static const int bgp_notify_msg_max
= BGP_NOTIFY_MAX
;
118 static const struct message bgp_notify_head_msg
[] =
120 { BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
121 { BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
122 { BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"}
124 static const int bgp_notify_head_msg_max
= BGP_NOTIFY_HEADER_MAX
;
126 static const struct message bgp_notify_open_msg
[] =
128 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
129 { BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number" },
130 { BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
131 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
132 { BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
133 { BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
134 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
135 { BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
137 static const int bgp_notify_open_msg_max
= BGP_NOTIFY_OPEN_MAX
;
139 static const struct message bgp_notify_update_msg
[] =
141 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
142 { BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
143 { BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
144 { BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
145 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
146 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
147 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
148 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
149 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
150 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
151 { BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
152 { BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
154 static const int bgp_notify_update_msg_max
= BGP_NOTIFY_UPDATE_MAX
;
156 static const struct message bgp_notify_cease_msg
[] =
158 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
159 { BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
160 { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
161 { BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
162 { BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
163 { BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
164 { BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
165 { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
, "/Connection collision resolution"},
166 { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
168 static const int bgp_notify_cease_msg_max
= BGP_NOTIFY_CEASE_MAX
;
170 static const struct message bgp_notify_capability_msg
[] =
172 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
173 { BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value" },
174 { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
175 { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
177 static const int bgp_notify_capability_msg_max
= BGP_NOTIFY_CAPABILITY_MAX
;
179 /* Origin strings. */
180 const char *bgp_origin_str
[] = {"i","e","?"};
181 const char *bgp_origin_long_str
[] = {"IGP","EGP","incomplete"};
184 /* Given a string return a pointer the corresponding peer structure */
186 bgp_find_peer (struct vty
*vty
, const char *peer_str
)
188 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
196 ret
= str2sockunion (peer_str
, &su
);
201 peer
= peer_lookup_by_conf_if (bgp
, peer_str
);
204 peer
= peer_lookup_by_hostname (bgp
, peer_str
);
209 return peer_lookup (bgp
, &su
);
213 bgp_debug_list_free(struct list
*list
)
215 struct bgp_debug_filter
*filter
;
216 struct listnode
*node
, *nnode
;
219 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
221 listnode_delete (list
, filter
);
224 prefix_free(filter
->p
);
227 XFREE (MTYPE_BGP_DEBUG_STR
, filter
->host
);
229 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
233 /* Print the desc along with a list of peers/prefixes this debug is
236 bgp_debug_list_print (struct vty
*vty
, const char *desc
, struct list
*list
)
238 struct bgp_debug_filter
*filter
;
239 struct listnode
*node
, *nnode
;
240 char buf
[INET6_ADDRSTRLEN
];
242 vty_out (vty
, "%s", desc
);
244 if (list
&& !list_isempty(list
))
246 vty_out (vty
, " for");
247 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
250 vty_out (vty
, " %s", filter
->host
);
253 vty_out (vty
, " %s/%d",
254 inet_ntop (filter
->p
->family
, &filter
->p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
255 filter
->p
->prefixlen
);
259 vty_out (vty
, "%s", VTY_NEWLINE
);
262 /* Print the command to enable the debug for each peer/prefix this debug is
266 bgp_debug_list_conf_print (struct vty
*vty
, const char *desc
, struct list
*list
)
268 struct bgp_debug_filter
*filter
;
269 struct listnode
*node
, *nnode
;
270 char buf
[INET6_ADDRSTRLEN
];
273 if (list
&& !list_isempty(list
))
275 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
279 vty_out (vty
, "%s %s%s", desc
, filter
->host
, VTY_NEWLINE
);
286 vty_out (vty
, "%s %s/%d%s", desc
,
287 inet_ntop (filter
->p
->family
, &filter
->p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
288 filter
->p
->prefixlen
, VTY_NEWLINE
);
296 vty_out (vty
, "%s%s", desc
, VTY_NEWLINE
);
304 bgp_debug_list_add_entry(struct list
*list
, const char *host
, struct prefix
*p
)
306 struct bgp_debug_filter
*filter
;
308 filter
= XCALLOC (MTYPE_BGP_DEBUG_FILTER
, sizeof (struct bgp_debug_filter
));
312 filter
->host
= XSTRDUP (MTYPE_BGP_DEBUG_STR
, host
);
321 listnode_add(list
, filter
);
325 bgp_debug_list_remove_entry(struct list
*list
, const char *host
, struct prefix
*p
)
327 struct bgp_debug_filter
*filter
;
328 struct listnode
*node
, *nnode
;
330 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
332 if (host
&& strcmp (filter
->host
, host
) == 0)
334 listnode_delete (list
, filter
);
335 XFREE (MTYPE_BGP_DEBUG_STR
, filter
->host
);
336 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
339 else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
341 listnode_delete (list
, filter
);
342 prefix_free (filter
->p
);
343 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
352 bgp_debug_list_has_entry(struct list
*list
, const char *host
, struct prefix
*p
)
354 struct bgp_debug_filter
*filter
;
355 struct listnode
*node
, *nnode
;
357 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
361 if (strcmp (filter
->host
, host
) == 0)
368 if (filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
379 bgp_debug_peer_updout_enabled(char *host
)
381 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
, NULL
));
384 /* Dump attribute. */
386 bgp_dump_attr (struct attr
*attr
, char *buf
, size_t size
)
391 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
)))
392 snprintf (buf
, size
, "nexthop %s", inet_ntoa (attr
->nexthop
));
394 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN
)))
395 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", origin %s",
396 bgp_origin_str
[attr
->origin
]);
400 char addrbuf
[BUFSIZ
];
403 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
404 || attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
405 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", mp_nexthop %s",
406 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
409 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
410 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), "(%s)",
411 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_local
,
415 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
)))
416 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", localpref %u",
419 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
)))
420 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", metric %u",
423 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
)))
424 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", community %s",
425 community_str (attr
->community
));
427 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
)))
428 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", atomic-aggregate");
430 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
)))
431 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", aggregated by %u %s",
432 attr
->extra
->aggregator_as
,
433 inet_ntoa (attr
->extra
->aggregator_addr
));
435 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
)))
436 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", originator %s",
437 inet_ntoa (attr
->extra
->originator_id
));
439 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST
)))
443 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", clusterlist");
444 for (i
= 0; i
< attr
->extra
->cluster
->length
/ 4; i
++)
445 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), " %s",
446 inet_ntoa (attr
->extra
->cluster
->list
[i
]));
449 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH
)))
450 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", path %s",
451 aspath_print (attr
->aspath
));
453 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID
)))
455 if (attr
->extra
->label_index
!= BGP_INVALID_LABEL_INDEX
)
456 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", label-index %u",
457 attr
->extra
->label_index
);
460 if (strlen (buf
) > 1)
467 bgp_notify_code_str (char code
)
469 return LOOKUP_DEF (bgp_notify_msg
, code
, "Unrecognized Error Code");
473 bgp_notify_subcode_str (char code
, char subcode
)
478 case BGP_NOTIFY_HEADER_ERR
:
479 return LOOKUP_DEF (bgp_notify_head_msg
, subcode
,
480 "Unrecognized Error Subcode");
481 case BGP_NOTIFY_OPEN_ERR
:
482 return LOOKUP_DEF (bgp_notify_open_msg
, subcode
,
483 "Unrecognized Error Subcode");
484 case BGP_NOTIFY_UPDATE_ERR
:
485 return LOOKUP_DEF (bgp_notify_update_msg
, subcode
,
486 "Unrecognized Error Subcode");
487 case BGP_NOTIFY_HOLD_ERR
:
489 case BGP_NOTIFY_FSM_ERR
:
491 case BGP_NOTIFY_CEASE
:
492 return LOOKUP_DEF (bgp_notify_cease_msg
, subcode
,
493 "Unrecognized Error Subcode");
494 case BGP_NOTIFY_CAPABILITY_ERR
:
495 return LOOKUP_DEF (bgp_notify_capability_msg
, subcode
,
496 "Unrecognized Error Subcode");
501 /* extract notify admin reason if correctly present */
503 bgp_notify_admin_message(char *buf
, size_t bufsz
, u_char
*data
, size_t datalen
)
505 if (!data
|| datalen
< 1)
508 u_char len
= data
[0];
510 || len
> datalen
- 1)
513 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
516 /* dump notify packet */
518 bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
521 const char *subcode_str
;
522 const char *code_str
;
523 const char *msg_str
= NULL
;
526 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
) || bgp_flag_check (peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
))
528 code_str
= bgp_notify_code_str(bgp_notify
->code
);
529 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
, bgp_notify
->subcode
);
531 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
532 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
533 || bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_RESET
))
535 msg_str
= bgp_notify_admin_message(msg_buf
, sizeof(msg_buf
),
536 bgp_notify
->raw_data
, bgp_notify
->length
);
541 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
542 strcmp (direct
, "received") == 0 ? "received from" : "sent to",
543 peer
->host
, bgp_notify
->code
, bgp_notify
->subcode
,
544 code_str
, subcode_str
, msg_str
);
548 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
549 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
550 strcmp (direct
, "received") == 0 ? "received from" : "sent to",
551 peer
->host
, bgp_notify
->code
, bgp_notify
->subcode
,
552 code_str
, subcode_str
, bgp_notify
->length
, msg_str
);
558 bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
561 bgp
= bgp_get_default();
562 update_group_walk (bgp
, update_group_clear_update_dbg
, NULL
);
566 /* Debug option setting interface. */
567 unsigned long bgp_debug_option
= 0;
570 debug (unsigned int option
)
572 return bgp_debug_option
& option
;
575 DEFUN (debug_bgp_as4
,
582 if (vty
->node
== CONFIG_NODE
)
586 TERM_DEBUG_ON (as4
, AS4
);
587 vty_out (vty
, "BGP as4 debugging is on%s", VTY_NEWLINE
);
592 DEFUN (no_debug_bgp_as4
,
593 no_debug_bgp_as4_cmd
,
600 if (vty
->node
== CONFIG_NODE
)
601 DEBUG_OFF (as4
, AS4
);
604 TERM_DEBUG_OFF (as4
, AS4
);
605 vty_out (vty
, "BGP as4 debugging is off%s", VTY_NEWLINE
);
610 DEFUN (debug_bgp_as4_segment
,
611 debug_bgp_as4_segment_cmd
,
612 "debug bgp as4 segment",
616 "BGP AS4 aspath segment handling\n")
618 if (vty
->node
== CONFIG_NODE
)
619 DEBUG_ON (as4
, AS4_SEGMENT
);
622 TERM_DEBUG_ON (as4
, AS4_SEGMENT
);
623 vty_out (vty
, "BGP as4 segment debugging is on%s", VTY_NEWLINE
);
628 DEFUN (no_debug_bgp_as4_segment
,
629 no_debug_bgp_as4_segment_cmd
,
630 "no debug bgp as4 segment",
635 "BGP AS4 aspath segment handling\n")
637 if (vty
->node
== CONFIG_NODE
)
638 DEBUG_OFF (as4
, AS4_SEGMENT
);
641 TERM_DEBUG_OFF (as4
, AS4_SEGMENT
);
642 vty_out (vty
, "BGP as4 segment debugging is off%s", VTY_NEWLINE
);
647 /* debug bgp neighbor_events */
648 DEFUN (debug_bgp_neighbor_events
,
649 debug_bgp_neighbor_events_cmd
,
650 "debug bgp neighbor-events",
653 "BGP Neighbor Events\n")
655 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
657 if (vty
->node
== CONFIG_NODE
)
658 DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
661 TERM_DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
662 vty_out (vty
, "BGP neighbor-events debugging is on%s", VTY_NEWLINE
);
667 DEFUN (debug_bgp_neighbor_events_peer
,
668 debug_bgp_neighbor_events_peer_cmd
,
669 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
672 "BGP Neighbor Events\n"
673 "BGP neighbor IP address to debug\n"
674 "BGP IPv6 neighbor to debug\n"
675 "BGP neighbor on interface to debug\n")
678 const char *host
= argv
[idx_peer
]->arg
;
680 if (!bgp_debug_neighbor_events_peers
)
681 bgp_debug_neighbor_events_peers
= list_new ();
683 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
, NULL
))
685 vty_out (vty
, "BGP neighbor-events debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
689 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
691 if (vty
->node
== CONFIG_NODE
)
692 DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
695 TERM_DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
696 vty_out (vty
, "BGP neighbor-events debugging is on for %s%s", host
, VTY_NEWLINE
);
701 DEFUN (no_debug_bgp_neighbor_events
,
702 no_debug_bgp_neighbor_events_cmd
,
703 "no debug bgp neighbor-events",
709 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
711 if (vty
->node
== CONFIG_NODE
)
712 DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
715 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
716 vty_out (vty
, "BGP neighbor-events debugging is off%s", VTY_NEWLINE
);
721 DEFUN (no_debug_bgp_neighbor_events_peer
,
722 no_debug_bgp_neighbor_events_peer_cmd
,
723 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
728 "BGP neighbor IP address to debug\n"
729 "BGP IPv6 neighbor to debug\n"
730 "BGP neighbor on interface to debug\n")
734 const char *host
= argv
[idx_peer
]->arg
;
736 if (bgp_debug_neighbor_events_peers
&& !list_isempty(bgp_debug_neighbor_events_peers
))
738 found_peer
= bgp_debug_list_remove_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
740 if (list_isempty(bgp_debug_neighbor_events_peers
))
742 if (vty
->node
== CONFIG_NODE
)
743 DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
745 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
750 vty_out (vty
, "BGP neighbor-events debugging is off for %s%s", host
, VTY_NEWLINE
);
752 vty_out (vty
, "BGP neighbor-events debugging was not enabled for %s%s", host
, VTY_NEWLINE
);
758 DEFUN (debug_bgp_nht
,
763 "BGP nexthop tracking events\n")
765 if (vty
->node
== CONFIG_NODE
)
769 TERM_DEBUG_ON (nht
, NHT
);
770 vty_out (vty
, "BGP nexthop tracking debugging is on%s", VTY_NEWLINE
);
775 DEFUN (no_debug_bgp_nht
,
776 no_debug_bgp_nht_cmd
,
781 "BGP nexthop tracking events\n")
783 if (vty
->node
== CONFIG_NODE
)
784 DEBUG_OFF (nht
, NHT
);
787 TERM_DEBUG_OFF (nht
, NHT
);
788 vty_out (vty
, "BGP nexthop tracking debugging is off%s", VTY_NEWLINE
);
793 /* debug bgp keepalives */
794 DEFUN (debug_bgp_keepalive
,
795 debug_bgp_keepalive_cmd
,
796 "debug bgp keepalives",
801 bgp_debug_list_free(bgp_debug_keepalive_peers
);
803 if (vty
->node
== CONFIG_NODE
)
804 DEBUG_ON (keepalive
, KEEPALIVE
);
807 TERM_DEBUG_ON (keepalive
, KEEPALIVE
);
808 vty_out (vty
, "BGP keepalives debugging is on%s", VTY_NEWLINE
);
813 DEFUN (debug_bgp_keepalive_peer
,
814 debug_bgp_keepalive_peer_cmd
,
815 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
818 "BGP Neighbor Events\n"
819 "BGP neighbor IP address to debug\n"
820 "BGP IPv6 neighbor to debug\n"
821 "BGP neighbor on interface to debug\n")
824 const char *host
= argv
[idx_peer
]->arg
;
826 if (!bgp_debug_keepalive_peers
)
827 bgp_debug_keepalive_peers
= list_new ();
829 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
))
831 vty_out (vty
, "BGP keepalive debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
835 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
837 if (vty
->node
== CONFIG_NODE
)
838 DEBUG_ON (keepalive
, KEEPALIVE
);
841 TERM_DEBUG_ON (keepalive
, KEEPALIVE
);
842 vty_out (vty
, "BGP keepalives debugging is on for %s%s", host
, VTY_NEWLINE
);
847 DEFUN (no_debug_bgp_keepalive
,
848 no_debug_bgp_keepalive_cmd
,
849 "no debug bgp keepalives",
855 bgp_debug_list_free(bgp_debug_keepalive_peers
);
857 if (vty
->node
== CONFIG_NODE
)
858 DEBUG_OFF (keepalive
, KEEPALIVE
);
861 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
862 vty_out (vty
, "BGP keepalives debugging is off%s", VTY_NEWLINE
);
867 DEFUN (no_debug_bgp_keepalive_peer
,
868 no_debug_bgp_keepalive_peer_cmd
,
869 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
874 "BGP neighbor IP address to debug\n"
875 "BGP IPv6 neighbor to debug\n"
876 "BGP neighbor on interface to debug\n")
880 const char *host
= argv
[idx_peer
]->arg
;
882 if (bgp_debug_keepalive_peers
&& !list_isempty(bgp_debug_keepalive_peers
))
884 found_peer
= bgp_debug_list_remove_entry(bgp_debug_keepalive_peers
, host
, NULL
);
886 if (list_isempty(bgp_debug_keepalive_peers
))
888 if (vty
->node
== CONFIG_NODE
)
889 DEBUG_OFF (keepalive
, KEEPALIVE
);
891 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
896 vty_out (vty
, "BGP keepalives debugging is off for %s%s", host
, VTY_NEWLINE
);
898 vty_out (vty
, "BGP keepalives debugging was not enabled for %s%s", host
, VTY_NEWLINE
);
903 /* debug bgp bestpath */
904 DEFUN (debug_bgp_bestpath_prefix
,
905 debug_bgp_bestpath_prefix_cmd
,
906 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
914 int idx_ipv4_ipv6_prefixlen
= 3;
915 struct prefix
*argv_p
;
918 argv_p
= prefix_new();
919 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
923 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
928 if (!bgp_debug_bestpath_prefixes
)
929 bgp_debug_bestpath_prefixes
= list_new ();
931 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
))
933 vty_out (vty
, "BGP bestptah debugging is already enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
937 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
939 if (vty
->node
== CONFIG_NODE
)
941 DEBUG_ON (bestpath
, BESTPATH
);
945 TERM_DEBUG_ON (bestpath
, BESTPATH
);
946 vty_out (vty
, "BGP bestpath debugging is on for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
952 DEFUN (no_debug_bgp_bestpath_prefix
,
953 no_debug_bgp_bestpath_prefix_cmd
,
954 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
963 int idx_ipv4_ipv6_prefixlen
= 4;
964 struct prefix
*argv_p
;
965 int found_prefix
= 0;
968 argv_p
= prefix_new();
969 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
973 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
977 if (bgp_debug_bestpath_prefixes
&& !list_isempty(bgp_debug_bestpath_prefixes
))
979 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
981 if (list_isempty(bgp_debug_bestpath_prefixes
))
983 if (vty
->node
== CONFIG_NODE
)
985 DEBUG_OFF (bestpath
, BESTPATH
);
989 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
990 vty_out (vty
, "BGP bestpath debugging (per prefix) is off%s", VTY_NEWLINE
);
996 vty_out (vty
, "BGP bestpath debugging is off for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
998 vty_out (vty
, "BGP bestpath debugging was not enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1003 DEFUN (no_debug_bgp_bestpath
,
1004 no_debug_bgp_bestpath_cmd
,
1005 "no debug bgp bestpath",
1011 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1013 if (vty
->node
== CONFIG_NODE
)
1014 DEBUG_OFF (bestpath
, BESTPATH
);
1017 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
1018 vty_out (vty
, "BGP bestpath debugging is off%s", VTY_NEWLINE
);
1023 /* debug bgp updates */
1024 DEFUN (debug_bgp_update
,
1025 debug_bgp_update_cmd
,
1026 "debug bgp updates",
1031 bgp_debug_list_free(bgp_debug_update_in_peers
);
1032 bgp_debug_list_free(bgp_debug_update_out_peers
);
1033 bgp_debug_list_free(bgp_debug_update_prefixes
);
1035 if (vty
->node
== CONFIG_NODE
)
1037 DEBUG_ON (update
, UPDATE_IN
);
1038 DEBUG_ON (update
, UPDATE_OUT
);
1042 TERM_DEBUG_ON (update
, UPDATE_IN
);
1043 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1044 vty_out (vty
, "BGP updates debugging is on%s", VTY_NEWLINE
);
1049 DEFUN (debug_bgp_update_direct
,
1050 debug_bgp_update_direct_cmd
,
1051 "debug bgp updates <in|out>",
1056 "Outbound updates\n")
1060 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1061 bgp_debug_list_free(bgp_debug_update_in_peers
);
1063 bgp_debug_list_free(bgp_debug_update_out_peers
);
1065 if (vty
->node
== CONFIG_NODE
)
1067 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1068 DEBUG_ON (update
, UPDATE_IN
);
1070 DEBUG_ON (update
, UPDATE_OUT
);
1074 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1076 TERM_DEBUG_ON (update
, UPDATE_IN
);
1077 vty_out (vty
, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE
);
1081 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1082 vty_out (vty
, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE
);
1088 DEFUN (debug_bgp_update_direct_peer
,
1089 debug_bgp_update_direct_peer_cmd
,
1090 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1095 "Outbound updates\n"
1096 "BGP neighbor IP address to debug\n"
1097 "BGP IPv6 neighbor to debug\n"
1098 "BGP neighbor on interface to debug\n")
1102 const char *host
= argv
[idx_peer
]->arg
;
1105 if (!bgp_debug_update_in_peers
)
1106 bgp_debug_update_in_peers
= list_new ();
1108 if (!bgp_debug_update_out_peers
)
1109 bgp_debug_update_out_peers
= list_new ();
1111 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1118 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
, NULL
))
1120 vty_out (vty
, "BGP inbound update debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
1127 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
, NULL
))
1129 vty_out (vty
, "BGP outbound update debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
1135 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1139 struct peer_af
*paf
;
1142 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
, NULL
);
1143 peer
= bgp_find_peer (vty
, host
);
1147 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
; afidx
++)
1149 paf
= peer
->peer_af_array
[afidx
];
1152 if (PAF_SUBGRP (paf
))
1154 UPDGRP_PEER_DBG_EN(PAF_SUBGRP(paf
)->update_group
);
1161 if (vty
->node
== CONFIG_NODE
)
1164 DEBUG_ON (update
, UPDATE_IN
);
1166 DEBUG_ON (update
, UPDATE_OUT
);
1172 TERM_DEBUG_ON (update
, UPDATE_IN
);
1173 vty_out (vty
, "BGP updates debugging is on (inbound) for %s%s", argv
[idx_peer
]->arg
, VTY_NEWLINE
);
1177 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1178 vty_out (vty
, "BGP updates debugging is on (outbound) for %s%s", argv
[idx_peer
]->arg
, VTY_NEWLINE
);
1184 DEFUN (no_debug_bgp_update_direct
,
1185 no_debug_bgp_update_direct_cmd
,
1186 "no debug bgp updates <in|out>",
1192 "Outbound updates\n")
1195 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1197 bgp_debug_list_free(bgp_debug_update_in_peers
);
1199 if (vty
->node
== CONFIG_NODE
)
1201 DEBUG_OFF (update
, UPDATE_IN
);
1205 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1206 vty_out (vty
, "BGP updates debugging is off (inbound)%s", VTY_NEWLINE
);
1211 bgp_debug_list_free(bgp_debug_update_out_peers
);
1213 if (vty
->node
== CONFIG_NODE
)
1215 DEBUG_OFF (update
, UPDATE_OUT
);
1219 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1220 vty_out (vty
, "BGP updates debugging is off (outbound)%s", VTY_NEWLINE
);
1227 DEFUN (no_debug_bgp_update_direct_peer
,
1228 no_debug_bgp_update_direct_peer_cmd
,
1229 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1235 "Outbound updates\n"
1236 "BGP neighbor IP address to debug\n"
1237 "BGP IPv6 neighbor to debug\n"
1238 "BGP neighbor on interface to debug\n")
1244 const char *host
= argv
[idx_peer
]->arg
;
1246 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1251 if (inbound
&& bgp_debug_update_in_peers
&&
1252 !list_isempty(bgp_debug_update_in_peers
))
1254 found_peer
= bgp_debug_list_remove_entry(bgp_debug_update_in_peers
, host
, NULL
);
1256 if (list_isempty(bgp_debug_update_in_peers
))
1258 if (vty
->node
== CONFIG_NODE
)
1259 DEBUG_OFF (update
, UPDATE_IN
);
1262 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1263 vty_out (vty
, "BGP updates debugging (inbound) is off%s", VTY_NEWLINE
);
1268 if (!inbound
&& bgp_debug_update_out_peers
&&
1269 !list_isempty(bgp_debug_update_out_peers
))
1271 found_peer
= bgp_debug_list_remove_entry(bgp_debug_update_out_peers
, host
, NULL
);
1273 if (list_isempty(bgp_debug_update_out_peers
))
1275 if (vty
->node
== CONFIG_NODE
)
1276 DEBUG_OFF (update
, UPDATE_OUT
);
1279 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1280 vty_out (vty
, "BGP updates debugging (outbound) is off%s", VTY_NEWLINE
);
1285 struct peer_af
*paf
;
1287 peer
= bgp_find_peer (vty
, host
);
1291 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
; afidx
++)
1293 paf
= peer
->peer_af_array
[afidx
];
1296 if (PAF_SUBGRP (paf
))
1298 UPDGRP_PEER_DBG_DIS(PAF_SUBGRP(paf
)->update_group
);
1307 vty_out (vty
, "BGP updates debugging (inbound) is off for %s%s", host
, VTY_NEWLINE
);
1309 vty_out (vty
, "BGP updates debugging (outbound) is off for %s%s", host
, VTY_NEWLINE
);
1312 vty_out (vty
, "BGP updates debugging (inbound) was not enabled for %s%s", host
, VTY_NEWLINE
);
1314 vty_out (vty
, "BGP updates debugging (outbound) was not enabled for %s%s", host
, VTY_NEWLINE
);
1319 DEFUN (debug_bgp_update_prefix
,
1320 debug_bgp_update_prefix_cmd
,
1321 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1325 "Specify a prefix to debug\n"
1330 int idx_ipv4_ipv6_prefixlen
= 4;
1331 struct prefix
*argv_p
;
1334 argv_p
= prefix_new();
1335 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1338 prefix_free(argv_p
);
1339 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1344 if (!bgp_debug_update_prefixes
)
1345 bgp_debug_update_prefixes
= list_new ();
1347 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
))
1349 vty_out (vty
, "BGP updates debugging is already enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1353 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1355 if (vty
->node
== CONFIG_NODE
)
1357 DEBUG_ON (update
, UPDATE_PREFIX
);
1361 TERM_DEBUG_ON (update
, UPDATE_PREFIX
);
1362 vty_out (vty
, "BGP updates debugging is on for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1368 DEFUN (no_debug_bgp_update_prefix
,
1369 no_debug_bgp_update_prefix_cmd
,
1370 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1375 "Specify a prefix to debug\n"
1380 int idx_ipv4_ipv6_prefixlen
= 5;
1381 struct prefix
*argv_p
;
1382 int found_prefix
= 0;
1385 argv_p
= prefix_new();
1386 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1389 prefix_free(argv_p
);
1390 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1394 if (bgp_debug_update_prefixes
&& !list_isempty(bgp_debug_update_prefixes
))
1396 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1398 if (list_isempty(bgp_debug_update_prefixes
))
1400 if (vty
->node
== CONFIG_NODE
)
1402 DEBUG_OFF (update
, UPDATE_PREFIX
);
1406 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1407 vty_out (vty
, "BGP updates debugging (per prefix) is off%s", VTY_NEWLINE
);
1413 vty_out (vty
, "BGP updates debugging is off for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1415 vty_out (vty
, "BGP updates debugging was not enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1420 DEFUN (no_debug_bgp_update
,
1421 no_debug_bgp_update_cmd
,
1422 "no debug bgp updates",
1428 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1429 bgp_debug_list_free(bgp_debug_update_in_peers
);
1430 bgp_debug_list_free(bgp_debug_update_out_peers
);
1431 bgp_debug_list_free(bgp_debug_update_prefixes
);
1433 bgp_debug_clear_updgrp_update_dbg(bgp
);
1435 if (vty
->node
== CONFIG_NODE
)
1437 DEBUG_OFF (update
, UPDATE_IN
);
1438 DEBUG_OFF (update
, UPDATE_OUT
);
1439 DEBUG_OFF (update
, UPDATE_PREFIX
);
1443 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1444 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1445 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1446 vty_out (vty
, "BGP updates debugging is off%s", VTY_NEWLINE
);
1451 /* debug bgp zebra */
1452 DEFUN (debug_bgp_zebra
,
1453 debug_bgp_zebra_cmd
,
1457 "BGP Zebra messages\n")
1459 if (vty
->node
== CONFIG_NODE
)
1460 DEBUG_ON (zebra
, ZEBRA
);
1463 TERM_DEBUG_ON (zebra
, ZEBRA
);
1464 vty_out (vty
, "BGP zebra debugging is on%s", VTY_NEWLINE
);
1469 DEFUN (debug_bgp_zebra_prefix
,
1470 debug_bgp_zebra_prefix_cmd
,
1471 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1474 "BGP Zebra messages\n"
1475 "Specify a prefix to debug\n"
1480 int idx_ipv4_ipv6_prefixlen
= 4;
1481 struct prefix
*argv_p
;
1484 argv_p
= prefix_new();
1485 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1488 prefix_free(argv_p
);
1489 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1493 if (!bgp_debug_zebra_prefixes
)
1494 bgp_debug_zebra_prefixes
= list_new();
1496 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
))
1498 vty_out (vty
, "BGP zebra debugging is already enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1502 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1504 if (vty
->node
== CONFIG_NODE
)
1505 DEBUG_ON (zebra
, ZEBRA
);
1508 TERM_DEBUG_ON (zebra
, ZEBRA
);
1509 vty_out (vty
, "BGP zebra debugging is on for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1515 DEFUN (no_debug_bgp_zebra
,
1516 no_debug_bgp_zebra_cmd
,
1517 "no debug bgp zebra",
1521 "BGP Zebra messages\n")
1523 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1525 if (vty
->node
== CONFIG_NODE
)
1526 DEBUG_OFF (zebra
, ZEBRA
);
1529 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1530 vty_out (vty
, "BGP zebra debugging is off%s", VTY_NEWLINE
);
1535 DEFUN (no_debug_bgp_zebra_prefix
,
1536 no_debug_bgp_zebra_prefix_cmd
,
1537 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1541 "BGP Zebra messages\n"
1542 "Specify a prefix to debug\n"
1547 int idx_ipv4_ipv6_prefixlen
= 5;
1548 struct prefix
*argv_p
;
1549 int found_prefix
= 0;
1552 argv_p
= prefix_new();
1553 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1556 prefix_free(argv_p
);
1557 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1561 if (bgp_debug_zebra_prefixes
&& !list_isempty(bgp_debug_zebra_prefixes
))
1563 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1565 if (list_isempty(bgp_debug_zebra_prefixes
))
1567 if (vty
->node
== CONFIG_NODE
)
1568 DEBUG_OFF (zebra
, ZEBRA
);
1571 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1572 vty_out (vty
, "BGP zebra debugging is off%s", VTY_NEWLINE
);
1578 vty_out (vty
, "BGP zebra debugging is off for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1580 vty_out (vty
, "BGP zebra debugging was not enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1585 DEFUN (debug_bgp_allow_martians
,
1586 debug_bgp_allow_martians_cmd
,
1587 "debug bgp allow-martians",
1590 "BGP allow martian next hops\n")
1592 if (vty
->node
== CONFIG_NODE
)
1593 DEBUG_ON (allow_martians
, ALLOW_MARTIANS
);
1596 TERM_DEBUG_ON (allow_martians
, ALLOW_MARTIANS
);
1597 vty_out (vty
, "BGP allow_martian next hop debugging is on%s", VTY_NEWLINE
);
1602 DEFUN (no_debug_bgp_allow_martians
,
1603 no_debug_bgp_allow_martians_cmd
,
1604 "no debug bgp allow-martians",
1608 "BGP allow martian next hops\n")
1610 if (vty
->node
== CONFIG_NODE
)
1611 DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1614 TERM_DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1615 vty_out (vty
, "BGP allow martian next hop debugging is off%s", VTY_NEWLINE
);
1621 /* debug bgp update-groups */
1622 DEFUN (debug_bgp_update_groups
,
1623 debug_bgp_update_groups_cmd
,
1624 "debug bgp update-groups",
1627 "BGP update-groups\n")
1629 if (vty
->node
== CONFIG_NODE
)
1630 DEBUG_ON (update_groups
, UPDATE_GROUPS
);
1633 TERM_DEBUG_ON (update_groups
, UPDATE_GROUPS
);
1634 vty_out (vty
, "BGP update-groups debugging is on%s", VTY_NEWLINE
);
1639 DEFUN (no_debug_bgp_update_groups
,
1640 no_debug_bgp_update_groups_cmd
,
1641 "no debug bgp update-groups",
1645 "BGP update-groups\n")
1647 if (vty
->node
== CONFIG_NODE
)
1648 DEBUG_OFF (update_groups
, UPDATE_GROUPS
);
1651 TERM_DEBUG_OFF (update_groups
, UPDATE_GROUPS
);
1652 vty_out (vty
, "BGP update-groups debugging is off%s", VTY_NEWLINE
);
1657 DEFUN (no_debug_bgp
,
1664 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1665 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
1666 bgp_debug_list_free(bgp_debug_keepalive_peers
);
1667 bgp_debug_list_free(bgp_debug_update_in_peers
);
1668 bgp_debug_list_free(bgp_debug_update_out_peers
);
1669 bgp_debug_list_free(bgp_debug_update_prefixes
);
1670 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1671 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1673 bgp_debug_clear_updgrp_update_dbg(bgp
);
1675 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
1676 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1677 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1678 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1679 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
1680 TERM_DEBUG_OFF (as4
, AS4
);
1681 TERM_DEBUG_OFF (as4
, AS4_SEGMENT
);
1682 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
1683 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1684 TERM_DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1685 vty_out (vty
, "All possible debugging has been turned off%s", VTY_NEWLINE
);
1690 DEFUN (show_debugging_bgp
,
1691 show_debugging_bgp_cmd
,
1692 "show debugging bgp",
1697 vty_out (vty
, "BGP debugging status:%s", VTY_NEWLINE
);
1699 if (BGP_DEBUG (as4
, AS4
))
1700 vty_out (vty
, " BGP as4 debugging is on%s", VTY_NEWLINE
);
1702 if (BGP_DEBUG (as4
, AS4_SEGMENT
))
1703 vty_out (vty
, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE
);
1705 if (BGP_DEBUG (bestpath
, BESTPATH
))
1706 bgp_debug_list_print (vty
, " BGP bestpath debugging is on",
1707 bgp_debug_bestpath_prefixes
);
1709 if (BGP_DEBUG (keepalive
, KEEPALIVE
))
1710 bgp_debug_list_print (vty
, " BGP keepalives debugging is on",
1711 bgp_debug_keepalive_peers
);
1713 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1714 bgp_debug_list_print (vty
, " BGP neighbor-events debugging is on",
1715 bgp_debug_neighbor_events_peers
);
1717 if (BGP_DEBUG (nht
, NHT
))
1718 vty_out (vty
, " BGP next-hop tracking debugging is on%s", VTY_NEWLINE
);
1720 if (BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1721 vty_out (vty
, " BGP update-groups debugging is on%s", VTY_NEWLINE
);
1723 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
1724 bgp_debug_list_print (vty
, " BGP updates debugging is on",
1725 bgp_debug_update_prefixes
);
1727 if (BGP_DEBUG (update
, UPDATE_IN
))
1728 bgp_debug_list_print (vty
, " BGP updates debugging is on (inbound)",
1729 bgp_debug_update_in_peers
);
1731 if (BGP_DEBUG (update
, UPDATE_OUT
))
1732 bgp_debug_list_print (vty
, " BGP updates debugging is on (outbound)",
1733 bgp_debug_update_out_peers
);
1735 if (BGP_DEBUG (zebra
, ZEBRA
))
1736 bgp_debug_list_print (vty
, " BGP zebra debugging is on",
1737 bgp_debug_zebra_prefixes
);
1739 if (BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1740 vty_out (vty
, " BGP allow martian next hop debugging is on%s", VTY_NEWLINE
);
1741 vty_out (vty
, "%s", VTY_NEWLINE
);
1745 /* return count of number of debug flags set */
1747 bgp_debug_count(void)
1750 if (BGP_DEBUG (as4
, AS4
))
1753 if (BGP_DEBUG (as4
, AS4_SEGMENT
))
1756 if (BGP_DEBUG (bestpath
, BESTPATH
))
1759 if (BGP_DEBUG (keepalive
, KEEPALIVE
))
1762 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1765 if (BGP_DEBUG (nht
, NHT
))
1768 if (BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1771 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
1774 if (BGP_DEBUG (update
, UPDATE_IN
))
1777 if (BGP_DEBUG (update
, UPDATE_OUT
))
1780 if (BGP_DEBUG (zebra
, ZEBRA
))
1783 if (BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1790 bgp_config_write_debug (struct vty
*vty
)
1794 if (CONF_BGP_DEBUG (as4
, AS4
))
1796 vty_out (vty
, "debug bgp as4%s", VTY_NEWLINE
);
1800 if (CONF_BGP_DEBUG (as4
, AS4_SEGMENT
))
1802 vty_out (vty
, "debug bgp as4 segment%s", VTY_NEWLINE
);
1806 if (CONF_BGP_DEBUG (bestpath
, BESTPATH
))
1808 write
+= bgp_debug_list_conf_print (vty
, "debug bgp bestpath",
1809 bgp_debug_bestpath_prefixes
);
1812 if (CONF_BGP_DEBUG (keepalive
, KEEPALIVE
))
1814 write
+= bgp_debug_list_conf_print (vty
, "debug bgp keepalives",
1815 bgp_debug_keepalive_peers
);
1818 if (CONF_BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1820 write
+= bgp_debug_list_conf_print (vty
, "debug bgp neighbor-events",
1821 bgp_debug_neighbor_events_peers
);
1824 if (CONF_BGP_DEBUG (nht
, NHT
))
1826 vty_out (vty
, "debug bgp nht%s", VTY_NEWLINE
);
1830 if (CONF_BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1832 vty_out (vty
, "debug bgp update-groups%s", VTY_NEWLINE
);
1836 if (CONF_BGP_DEBUG (update
, UPDATE_PREFIX
))
1838 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates prefix",
1839 bgp_debug_update_prefixes
);
1842 if (CONF_BGP_DEBUG (update
, UPDATE_IN
))
1844 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates in",
1845 bgp_debug_update_in_peers
);
1848 if (CONF_BGP_DEBUG (update
, UPDATE_OUT
))
1850 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates out",
1851 bgp_debug_update_out_peers
);
1854 if (CONF_BGP_DEBUG (zebra
, ZEBRA
))
1856 if (!bgp_debug_zebra_prefixes
|| list_isempty(bgp_debug_zebra_prefixes
))
1858 vty_out (vty
, "debug bgp zebra%s", VTY_NEWLINE
);
1863 write
+= bgp_debug_list_conf_print (vty
, "debug bgp zebra prefix",
1864 bgp_debug_zebra_prefixes
);
1868 if (CONF_BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1870 vty_out (vty
, "debug bgp allow-martians%s", VTY_NEWLINE
);
1877 static struct cmd_node debug_node
=
1885 bgp_debug_init (void)
1887 install_node (&debug_node
, bgp_config_write_debug
);
1889 install_element (ENABLE_NODE
, &show_debugging_bgp_cmd
);
1891 install_element (ENABLE_NODE
, &debug_bgp_as4_cmd
);
1892 install_element (CONFIG_NODE
, &debug_bgp_as4_cmd
);
1893 install_element (ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
1894 install_element (CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
1896 install_element (ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
1897 install_element (CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
1898 install_element (ENABLE_NODE
, &debug_bgp_nht_cmd
);
1899 install_element (CONFIG_NODE
, &debug_bgp_nht_cmd
);
1900 install_element (ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
1901 install_element (CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
1902 install_element (ENABLE_NODE
, &debug_bgp_update_cmd
);
1903 install_element (CONFIG_NODE
, &debug_bgp_update_cmd
);
1904 install_element (ENABLE_NODE
, &debug_bgp_zebra_cmd
);
1905 install_element (CONFIG_NODE
, &debug_bgp_zebra_cmd
);
1906 install_element (ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
1907 install_element (CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
1908 install_element (ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
1909 install_element (CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
1910 install_element (ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1911 install_element (CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1913 /* debug bgp updates (in|out) */
1914 install_element (ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
1915 install_element (CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
1916 install_element (ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
1917 install_element (CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
1919 /* debug bgp updates (in|out) A.B.C.D */
1920 install_element (ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
1921 install_element (CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
1922 install_element (ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1923 install_element (CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1925 /* debug bgp updates prefix A.B.C.D/M */
1926 install_element (ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
1927 install_element (CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
1928 install_element (ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
1929 install_element (CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
1931 /* debug bgp zebra prefix A.B.C.D/M */
1932 install_element (ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
1933 install_element (CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
1934 install_element (ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1935 install_element (CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1937 install_element (ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
1938 install_element (CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
1939 install_element (ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
1940 install_element (CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
1942 /* debug bgp neighbor-events A.B.C.D */
1943 install_element (ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1944 install_element (CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1945 install_element (ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1946 install_element (CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1948 /* debug bgp keepalive A.B.C.D */
1949 install_element (ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
1950 install_element (CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
1951 install_element (ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1952 install_element (CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1954 install_element (ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1955 install_element (CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1956 install_element (ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
1957 install_element (CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
1958 install_element (ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
1959 install_element (CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
1960 install_element (ENABLE_NODE
, &no_debug_bgp_update_cmd
);
1961 install_element (CONFIG_NODE
, &no_debug_bgp_update_cmd
);
1962 install_element (ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
1963 install_element (CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
1964 install_element (ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
1965 install_element (CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
1966 install_element (ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
1967 install_element (CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
1968 install_element (ENABLE_NODE
, &no_debug_bgp_cmd
);
1969 install_element (ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
1970 install_element (CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
1971 install_element (ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1972 install_element (CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1975 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
1976 * for BGP_DEBUG_TYPE
1979 bgp_debug_per_prefix (struct prefix
*p
, unsigned long term_bgp_debug_type
,
1980 unsigned int BGP_DEBUG_TYPE
, struct list
*per_prefix_list
)
1982 struct bgp_debug_filter
*filter
;
1983 struct listnode
*node
, *nnode
;
1985 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
)
1987 /* We are debugging all prefixes so return true */
1988 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
1996 for (ALL_LIST_ELEMENTS (per_prefix_list
, node
, nnode
, filter
))
1997 if (filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
2007 /* Return true if this peer is on the per_peer_list of peers to debug
2008 * for BGP_DEBUG_TYPE
2011 bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2012 unsigned int BGP_DEBUG_TYPE
, struct list
*per_peer_list
)
2014 struct bgp_debug_filter
*filter
;
2015 struct listnode
*node
, *nnode
;
2017 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
)
2019 /* We are debugging all peers so return true */
2020 if (!per_peer_list
|| list_isempty(per_peer_list
))
2028 for (ALL_LIST_ELEMENTS (per_peer_list
, node
, nnode
, filter
))
2029 if (strcmp (filter
->host
, host
) == 0)
2040 bgp_debug_neighbor_events (struct peer
*peer
)
2047 return bgp_debug_per_peer (host
,
2048 term_bgp_debug_neighbor_events
,
2049 BGP_DEBUG_NEIGHBOR_EVENTS
,
2050 bgp_debug_neighbor_events_peers
);
2054 bgp_debug_keepalive (struct peer
*peer
)
2061 return bgp_debug_per_peer (host
,
2062 term_bgp_debug_keepalive
,
2063 BGP_DEBUG_KEEPALIVE
,
2064 bgp_debug_keepalive_peers
);
2068 bgp_debug_update (struct peer
*peer
, struct prefix
*p
,
2069 struct update_group
*updgrp
, unsigned int inbound
)
2078 if (bgp_debug_per_peer (host
, term_bgp_debug_update
, BGP_DEBUG_UPDATE_IN
,
2079 bgp_debug_update_in_peers
))
2086 if (bgp_debug_per_peer (host
, term_bgp_debug_update
,
2087 BGP_DEBUG_UPDATE_OUT
,
2088 bgp_debug_update_out_peers
))
2091 /* Check if update debugging implicitly enabled for the group. */
2092 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2097 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
2099 if (bgp_debug_per_prefix (p
, term_bgp_debug_update
,
2100 BGP_DEBUG_UPDATE_PREFIX
,
2101 bgp_debug_update_prefixes
))
2109 bgp_debug_bestpath (struct prefix
*p
)
2111 if (BGP_DEBUG (bestpath
, BESTPATH
))
2113 if (bgp_debug_per_prefix (p
, term_bgp_debug_bestpath
,
2115 bgp_debug_bestpath_prefixes
))
2123 bgp_debug_zebra (struct prefix
*p
)
2125 if (BGP_DEBUG (zebra
, ZEBRA
))
2127 if (bgp_debug_per_prefix (p
, term_bgp_debug_zebra
, BGP_DEBUG_ZEBRA
,
2128 bgp_debug_zebra_prefixes
))
2136 bgp_debug_rdpfxpath2str (struct prefix_rd
*prd
, union prefixconstptr pu
,
2137 int addpath_valid
, u_int32_t addpath_id
,
2138 char *str
, int size
)
2140 char rd_buf
[RD_ADDRSTRLEN
];
2141 char pfx_buf
[PREFIX_STRLEN
];
2142 char pathid_buf
[BGP_ADDPATH_STR
];
2144 if (size
< BGP_PRD_PATH_STRLEN
)
2147 /* Note: Path-id is created by default, but only included in update sometimes. */
2148 pathid_buf
[0] = '\0';
2150 sprintf(pathid_buf
, " with addpath ID %d", addpath_id
);
2153 snprintf (str
, size
, "RD %s %s%s",
2154 prefix_rd2str(prd
, rd_buf
, sizeof (rd_buf
)),
2155 prefix2str (pu
, pfx_buf
, sizeof (pfx_buf
)), pathid_buf
);
2157 snprintf (str
, size
, "%s%s",
2158 prefix2str (pu
, pfx_buf
, sizeof (pfx_buf
)), pathid_buf
);