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"
42 #include "bgpd/bgp_ecommunity.h"
43 #include "bgpd/bgp_label.h"
44 #include "bgpd/bgp_evpn.h"
46 unsigned long conf_bgp_debug_as4
;
47 unsigned long conf_bgp_debug_neighbor_events
;
48 unsigned long conf_bgp_debug_events
;
49 unsigned long conf_bgp_debug_packet
;
50 unsigned long conf_bgp_debug_filter
;
51 unsigned long conf_bgp_debug_keepalive
;
52 unsigned long conf_bgp_debug_update
;
53 unsigned long conf_bgp_debug_bestpath
;
54 unsigned long conf_bgp_debug_zebra
;
55 unsigned long conf_bgp_debug_allow_martians
;
56 unsigned long conf_bgp_debug_nht
;
57 unsigned long conf_bgp_debug_update_groups
;
59 unsigned long term_bgp_debug_as4
;
60 unsigned long term_bgp_debug_neighbor_events
;
61 unsigned long term_bgp_debug_events
;
62 unsigned long term_bgp_debug_packet
;
63 unsigned long term_bgp_debug_filter
;
64 unsigned long term_bgp_debug_keepalive
;
65 unsigned long term_bgp_debug_update
;
66 unsigned long term_bgp_debug_bestpath
;
67 unsigned long term_bgp_debug_zebra
;
68 unsigned long term_bgp_debug_allow_martians
;
69 unsigned long term_bgp_debug_nht
;
70 unsigned long term_bgp_debug_update_groups
;
72 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
73 struct list
*bgp_debug_keepalive_peers
= NULL
;
74 struct list
*bgp_debug_update_out_peers
= NULL
;
75 struct list
*bgp_debug_update_in_peers
= NULL
;
76 struct list
*bgp_debug_update_prefixes
= NULL
;
77 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
78 struct list
*bgp_debug_zebra_prefixes
= NULL
;
80 /* messages for BGP-4 status */
81 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
84 {OpenSent
, "OpenSent"},
85 {OpenConfirm
, "OpenConfirm"},
86 {Established
, "Established"},
87 {Clearing
, "Clearing"},
91 /* BGP message type string. */
92 const char *bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
93 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
96 /* message for BGP-4 Notify */
97 static const struct message bgp_notify_msg
[] = {
98 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
99 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
100 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
101 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
102 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
103 {BGP_NOTIFY_CEASE
, "Cease"},
104 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
107 static const struct message bgp_notify_head_msg
[] = {
108 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
109 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
110 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
113 static const struct message bgp_notify_open_msg
[] = {
114 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
115 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
116 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
117 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
118 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
119 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
120 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
121 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
124 static const struct message bgp_notify_update_msg
[] = {
125 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
126 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
127 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
128 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
129 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
130 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
131 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
132 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
133 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
134 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
135 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
136 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
139 static const struct message bgp_notify_cease_msg
[] = {
140 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
141 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
142 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
143 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
144 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
145 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
146 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
147 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
148 "/Connection collision resolution"},
149 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
152 static const struct message bgp_notify_capability_msg
[] = {
153 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
154 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
155 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
156 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
159 /* Origin strings. */
160 const char *bgp_origin_str
[] = {"i", "e", "?"};
161 const char *bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
164 /* Given a string return a pointer the corresponding peer structure */
165 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
167 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
175 ret
= str2sockunion(peer_str
, &su
);
179 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
182 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
186 return peer_lookup(bgp
, &su
);
189 static void bgp_debug_list_free(struct list
*list
)
191 struct bgp_debug_filter
*filter
;
192 struct listnode
*node
, *nnode
;
195 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
196 listnode_delete(list
, filter
);
199 prefix_free(filter
->p
);
202 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
204 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
208 /* Print the desc along with a list of peers/prefixes this debug is
210 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
213 struct bgp_debug_filter
*filter
;
214 struct listnode
*node
, *nnode
;
215 char buf
[INET6_ADDRSTRLEN
];
217 vty_out(vty
, "%s", desc
);
219 if (list
&& !list_isempty(list
)) {
220 vty_out(vty
, " for");
221 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
223 vty_out(vty
, " %s", filter
->host
);
226 vty_out(vty
, " %s/%d",
227 inet_ntop(filter
->p
->family
,
228 &filter
->p
->u
.prefix
, buf
,
230 filter
->p
->prefixlen
);
237 /* Print the command to enable the debug for each peer/prefix this debug is
240 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
243 struct bgp_debug_filter
*filter
;
244 struct listnode
*node
, *nnode
;
245 char buf
[INET6_ADDRSTRLEN
];
248 if (list
&& !list_isempty(list
)) {
249 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
251 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
257 vty_out(vty
, "%s %s/%d\n", desc
,
258 inet_ntop(filter
->p
->family
,
259 &filter
->p
->u
.prefix
, buf
,
261 filter
->p
->prefixlen
);
268 vty_out(vty
, "%s\n", desc
);
275 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
276 const struct prefix
*p
)
278 struct bgp_debug_filter
*filter
;
280 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
281 sizeof(struct bgp_debug_filter
));
284 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
288 filter
->p
= prefix_new();
289 prefix_copy(filter
->p
, p
);
292 listnode_add(list
, filter
);
295 static int bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
298 struct bgp_debug_filter
*filter
;
299 struct listnode
*node
, *nnode
;
301 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
302 if (host
&& strcmp(filter
->host
, host
) == 0) {
303 listnode_delete(list
, filter
);
304 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
305 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
307 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
308 && prefix_match(filter
->p
, p
)) {
309 listnode_delete(list
, filter
);
310 prefix_free(filter
->p
);
311 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
319 static int bgp_debug_list_has_entry(struct list
*list
, const char *host
,
320 const struct prefix
*p
)
322 struct bgp_debug_filter
*filter
;
323 struct listnode
*node
, *nnode
;
325 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
327 if (strcmp(filter
->host
, host
) == 0) {
331 if (filter
->p
->prefixlen
== p
->prefixlen
332 && prefix_match(filter
->p
, p
)) {
341 int bgp_debug_peer_updout_enabled(char *host
)
343 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
347 /* Dump attribute. */
348 int bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
350 char addrbuf
[BUFSIZ
];
355 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
356 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
358 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
359 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
360 bgp_origin_str
[attr
->origin
]);
363 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
364 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
365 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
367 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
370 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
371 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
372 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
375 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
376 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
378 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
379 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
380 ", localpref %u", attr
->local_pref
);
382 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
383 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
386 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
387 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
388 ", community %s", community_str(attr
->community
));
390 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
391 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
392 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
394 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
395 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
396 ", atomic-aggregate");
398 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
399 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
400 ", aggregated by %u %s", attr
->aggregator_as
,
401 inet_ntoa(attr
->aggregator_addr
));
403 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
404 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
405 ", originator %s", inet_ntoa(attr
->originator_id
));
407 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
410 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
412 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
413 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
414 inet_ntoa(attr
->cluster
->list
[i
]));
417 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
418 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
419 aspath_print(attr
->aspath
));
421 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
422 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
423 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
424 ", label-index %u", attr
->label_index
);
433 const char *bgp_notify_code_str(char code
)
435 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
438 const char *bgp_notify_subcode_str(char code
, char subcode
)
442 case BGP_NOTIFY_HEADER_ERR
:
443 return lookup_msg(bgp_notify_head_msg
, subcode
,
444 "Unrecognized Error Subcode");
445 case BGP_NOTIFY_OPEN_ERR
:
446 return lookup_msg(bgp_notify_open_msg
, subcode
,
447 "Unrecognized Error Subcode");
448 case BGP_NOTIFY_UPDATE_ERR
:
449 return lookup_msg(bgp_notify_update_msg
, subcode
,
450 "Unrecognized Error Subcode");
451 case BGP_NOTIFY_HOLD_ERR
:
453 case BGP_NOTIFY_FSM_ERR
:
455 case BGP_NOTIFY_CEASE
:
456 return lookup_msg(bgp_notify_cease_msg
, subcode
,
457 "Unrecognized Error Subcode");
458 case BGP_NOTIFY_CAPABILITY_ERR
:
459 return lookup_msg(bgp_notify_capability_msg
, subcode
,
460 "Unrecognized Error Subcode");
465 /* extract notify admin reason if correctly present */
466 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, u_char
*data
,
469 if (!data
|| datalen
< 1)
472 u_char len
= data
[0];
473 if (len
> 128 || len
> datalen
- 1)
476 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
479 /* dump notify packet */
480 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
483 const char *subcode_str
;
484 const char *code_str
;
485 const char *msg_str
= NULL
;
488 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
489 || bgp_flag_check(peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
490 code_str
= bgp_notify_code_str(bgp_notify
->code
);
491 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
492 bgp_notify
->subcode
);
494 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
495 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
496 || bgp_notify
->subcode
497 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
498 msg_str
= bgp_notify_admin_message(
499 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
505 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
506 strcmp(direct
, "received") == 0
509 peer
->host
, bgp_notify
->code
,
510 bgp_notify
->subcode
, code_str
, subcode_str
,
513 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
515 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
516 strcmp(direct
, "received") == 0
519 peer
->host
, bgp_notify
->code
,
520 bgp_notify
->subcode
, code_str
, subcode_str
,
521 bgp_notify
->length
, msg_str
);
526 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
529 bgp
= bgp_get_default();
530 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
534 /* Debug option setting interface. */
535 unsigned long bgp_debug_option
= 0;
537 int debug(unsigned int option
)
539 return bgp_debug_option
& option
;
542 DEFUN (debug_bgp_as4
,
549 if (vty
->node
== CONFIG_NODE
)
552 TERM_DEBUG_ON(as4
, AS4
);
553 vty_out(vty
, "BGP as4 debugging is on\n");
558 DEFUN (no_debug_bgp_as4
,
559 no_debug_bgp_as4_cmd
,
566 if (vty
->node
== CONFIG_NODE
)
569 TERM_DEBUG_OFF(as4
, AS4
);
570 vty_out(vty
, "BGP as4 debugging is off\n");
575 DEFUN (debug_bgp_as4_segment
,
576 debug_bgp_as4_segment_cmd
,
577 "debug bgp as4 segment",
581 "BGP AS4 aspath segment handling\n")
583 if (vty
->node
== CONFIG_NODE
)
584 DEBUG_ON(as4
, AS4_SEGMENT
);
586 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
587 vty_out(vty
, "BGP as4 segment debugging is on\n");
592 DEFUN (no_debug_bgp_as4_segment
,
593 no_debug_bgp_as4_segment_cmd
,
594 "no debug bgp as4 segment",
599 "BGP AS4 aspath segment handling\n")
601 if (vty
->node
== CONFIG_NODE
)
602 DEBUG_OFF(as4
, AS4_SEGMENT
);
604 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
605 vty_out(vty
, "BGP as4 segment debugging is off\n");
610 /* debug bgp neighbor_events */
611 DEFUN (debug_bgp_neighbor_events
,
612 debug_bgp_neighbor_events_cmd
,
613 "debug bgp neighbor-events",
616 "BGP Neighbor Events\n")
618 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
620 if (vty
->node
== CONFIG_NODE
)
621 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
623 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
624 vty_out(vty
, "BGP neighbor-events debugging is on\n");
629 DEFUN (debug_bgp_neighbor_events_peer
,
630 debug_bgp_neighbor_events_peer_cmd
,
631 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
634 "BGP Neighbor Events\n"
635 "BGP neighbor IP address to debug\n"
636 "BGP IPv6 neighbor to debug\n"
637 "BGP neighbor on interface to debug\n")
640 const char *host
= argv
[idx_peer
]->arg
;
642 if (!bgp_debug_neighbor_events_peers
)
643 bgp_debug_neighbor_events_peers
= list_new();
645 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
648 "BGP neighbor-events debugging is already enabled for %s\n",
653 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
655 if (vty
->node
== CONFIG_NODE
)
656 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
658 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
659 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
665 DEFUN (no_debug_bgp_neighbor_events
,
666 no_debug_bgp_neighbor_events_cmd
,
667 "no debug bgp neighbor-events",
673 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
675 if (vty
->node
== CONFIG_NODE
)
676 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
678 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
679 vty_out(vty
, "BGP neighbor-events debugging is off\n");
684 DEFUN (no_debug_bgp_neighbor_events_peer
,
685 no_debug_bgp_neighbor_events_peer_cmd
,
686 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
691 "BGP neighbor IP address to debug\n"
692 "BGP IPv6 neighbor to debug\n"
693 "BGP neighbor on interface to debug\n")
697 const char *host
= argv
[idx_peer
]->arg
;
699 if (bgp_debug_neighbor_events_peers
700 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
701 found_peer
= bgp_debug_list_remove_entry(
702 bgp_debug_neighbor_events_peers
, host
, NULL
);
704 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
705 if (vty
->node
== CONFIG_NODE
)
706 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
708 TERM_DEBUG_OFF(neighbor_events
,
714 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
718 "BGP neighbor-events debugging was not enabled for %s\n",
725 DEFUN (debug_bgp_nht
,
730 "BGP nexthop tracking events\n")
732 if (vty
->node
== CONFIG_NODE
)
735 TERM_DEBUG_ON(nht
, NHT
);
736 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
741 DEFUN (no_debug_bgp_nht
,
742 no_debug_bgp_nht_cmd
,
747 "BGP nexthop tracking events\n")
749 if (vty
->node
== CONFIG_NODE
)
752 TERM_DEBUG_OFF(nht
, NHT
);
753 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
758 /* debug bgp keepalives */
759 DEFUN (debug_bgp_keepalive
,
760 debug_bgp_keepalive_cmd
,
761 "debug bgp keepalives",
766 bgp_debug_list_free(bgp_debug_keepalive_peers
);
768 if (vty
->node
== CONFIG_NODE
)
769 DEBUG_ON(keepalive
, KEEPALIVE
);
771 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
772 vty_out(vty
, "BGP keepalives debugging is on\n");
777 DEFUN (debug_bgp_keepalive_peer
,
778 debug_bgp_keepalive_peer_cmd
,
779 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
782 "BGP Neighbor Events\n"
783 "BGP neighbor IP address to debug\n"
784 "BGP IPv6 neighbor to debug\n"
785 "BGP neighbor on interface to debug\n")
788 const char *host
= argv
[idx_peer
]->arg
;
790 if (!bgp_debug_keepalive_peers
)
791 bgp_debug_keepalive_peers
= list_new();
793 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
795 "BGP keepalive debugging is already enabled for %s\n",
800 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
802 if (vty
->node
== CONFIG_NODE
)
803 DEBUG_ON(keepalive
, KEEPALIVE
);
805 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
806 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
811 DEFUN (no_debug_bgp_keepalive
,
812 no_debug_bgp_keepalive_cmd
,
813 "no debug bgp keepalives",
819 bgp_debug_list_free(bgp_debug_keepalive_peers
);
821 if (vty
->node
== CONFIG_NODE
)
822 DEBUG_OFF(keepalive
, KEEPALIVE
);
824 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
825 vty_out(vty
, "BGP keepalives debugging is off\n");
830 DEFUN (no_debug_bgp_keepalive_peer
,
831 no_debug_bgp_keepalive_peer_cmd
,
832 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
837 "BGP neighbor IP address to debug\n"
838 "BGP IPv6 neighbor to debug\n"
839 "BGP neighbor on interface to debug\n")
843 const char *host
= argv
[idx_peer
]->arg
;
845 if (bgp_debug_keepalive_peers
846 && !list_isempty(bgp_debug_keepalive_peers
)) {
847 found_peer
= bgp_debug_list_remove_entry(
848 bgp_debug_keepalive_peers
, host
, NULL
);
850 if (list_isempty(bgp_debug_keepalive_peers
)) {
851 if (vty
->node
== CONFIG_NODE
)
852 DEBUG_OFF(keepalive
, KEEPALIVE
);
854 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
859 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
862 "BGP keepalives debugging was not enabled for %s\n",
868 #ifndef VTYSH_EXTRACT_PL
869 #include "bgp_debug_clippy.c"
872 /* debug bgp bestpath */
873 DEFPY (debug_bgp_bestpath_prefix
,
874 debug_bgp_bestpath_prefix_cmd
,
875 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>$bestpath",
882 if (!bgp_debug_bestpath_prefixes
)
883 bgp_debug_bestpath_prefixes
= list_new();
885 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
888 "BGP bestpath debugging is already enabled for %s\n",
893 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, bestpath
);
895 if (vty
->node
== CONFIG_NODE
) {
896 DEBUG_ON(bestpath
, BESTPATH
);
898 TERM_DEBUG_ON(bestpath
, BESTPATH
);
899 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
906 DEFUN (no_debug_bgp_bestpath_prefix
,
907 no_debug_bgp_bestpath_prefix_cmd
,
908 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
916 int idx_ipv4_ipv6_prefixlen
= 4;
917 struct prefix
*argv_p
;
918 int found_prefix
= 0;
921 argv_p
= prefix_new();
922 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
925 vty_out(vty
, "%% Malformed Prefix\n");
926 return CMD_WARNING_CONFIG_FAILED
;
929 if (bgp_debug_bestpath_prefixes
930 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
931 found_prefix
= bgp_debug_list_remove_entry(
932 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
934 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
935 if (vty
->node
== CONFIG_NODE
) {
936 DEBUG_OFF(bestpath
, BESTPATH
);
938 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
940 "BGP bestpath debugging (per prefix) is off\n");
946 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
947 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
949 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
950 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
955 DEFUN (no_debug_bgp_bestpath
,
956 no_debug_bgp_bestpath_cmd
,
957 "no debug bgp bestpath",
963 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
965 if (vty
->node
== CONFIG_NODE
)
966 DEBUG_OFF(bestpath
, BESTPATH
);
968 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
969 vty_out(vty
, "BGP bestpath debugging is off\n");
974 /* debug bgp updates */
975 DEFUN (debug_bgp_update
,
976 debug_bgp_update_cmd
,
982 bgp_debug_list_free(bgp_debug_update_in_peers
);
983 bgp_debug_list_free(bgp_debug_update_out_peers
);
984 bgp_debug_list_free(bgp_debug_update_prefixes
);
986 if (vty
->node
== CONFIG_NODE
) {
987 DEBUG_ON(update
, UPDATE_IN
);
988 DEBUG_ON(update
, UPDATE_OUT
);
990 TERM_DEBUG_ON(update
, UPDATE_IN
);
991 TERM_DEBUG_ON(update
, UPDATE_OUT
);
992 vty_out(vty
, "BGP updates debugging is on\n");
997 DEFUN (debug_bgp_update_direct
,
998 debug_bgp_update_direct_cmd
,
999 "debug bgp updates <in|out>",
1004 "Outbound updates\n")
1008 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1009 bgp_debug_list_free(bgp_debug_update_in_peers
);
1011 bgp_debug_list_free(bgp_debug_update_out_peers
);
1013 if (vty
->node
== CONFIG_NODE
) {
1014 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1015 DEBUG_ON(update
, UPDATE_IN
);
1017 DEBUG_ON(update
, UPDATE_OUT
);
1019 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1020 TERM_DEBUG_ON(update
, UPDATE_IN
);
1021 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1023 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1025 "BGP updates debugging is on (outbound)\n");
1031 DEFUN (debug_bgp_update_direct_peer
,
1032 debug_bgp_update_direct_peer_cmd
,
1033 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1038 "Outbound updates\n"
1039 "BGP neighbor IP address to debug\n"
1040 "BGP IPv6 neighbor to debug\n"
1041 "BGP neighbor on interface to debug\n")
1045 const char *host
= argv
[idx_peer
]->arg
;
1048 if (!bgp_debug_update_in_peers
)
1049 bgp_debug_update_in_peers
= list_new();
1051 if (!bgp_debug_update_out_peers
)
1052 bgp_debug_update_out_peers
= list_new();
1054 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1060 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1063 "BGP inbound update debugging is already enabled for %s\n",
1070 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1073 "BGP outbound update debugging is already enabled for %s\n",
1080 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1083 struct peer_af
*paf
;
1086 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1088 peer
= bgp_find_peer(vty
, host
);
1091 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1093 paf
= peer
->peer_af_array
[afidx
];
1095 if (PAF_SUBGRP(paf
)) {
1105 if (vty
->node
== CONFIG_NODE
) {
1107 DEBUG_ON(update
, UPDATE_IN
);
1109 DEBUG_ON(update
, UPDATE_OUT
);
1112 TERM_DEBUG_ON(update
, UPDATE_IN
);
1114 "BGP updates debugging is on (inbound) for %s\n",
1115 argv
[idx_peer
]->arg
);
1117 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1119 "BGP updates debugging is on (outbound) for %s\n",
1120 argv
[idx_peer
]->arg
);
1126 DEFUN (no_debug_bgp_update_direct
,
1127 no_debug_bgp_update_direct_cmd
,
1128 "no debug bgp updates <in|out>",
1134 "Outbound updates\n")
1137 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1138 bgp_debug_list_free(bgp_debug_update_in_peers
);
1140 if (vty
->node
== CONFIG_NODE
) {
1141 DEBUG_OFF(update
, UPDATE_IN
);
1143 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1145 "BGP updates debugging is off (inbound)\n");
1148 bgp_debug_list_free(bgp_debug_update_out_peers
);
1150 if (vty
->node
== CONFIG_NODE
) {
1151 DEBUG_OFF(update
, UPDATE_OUT
);
1153 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1155 "BGP updates debugging is off (outbound)\n");
1162 DEFUN (no_debug_bgp_update_direct_peer
,
1163 no_debug_bgp_update_direct_peer_cmd
,
1164 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1170 "Outbound updates\n"
1171 "BGP neighbor IP address to debug\n"
1172 "BGP IPv6 neighbor to debug\n"
1173 "BGP neighbor on interface to debug\n")
1179 const char *host
= argv
[idx_peer
]->arg
;
1181 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1186 if (inbound
&& bgp_debug_update_in_peers
1187 && !list_isempty(bgp_debug_update_in_peers
)) {
1188 found_peer
= bgp_debug_list_remove_entry(
1189 bgp_debug_update_in_peers
, host
, NULL
);
1191 if (list_isempty(bgp_debug_update_in_peers
)) {
1192 if (vty
->node
== CONFIG_NODE
)
1193 DEBUG_OFF(update
, UPDATE_IN
);
1195 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1197 "BGP updates debugging (inbound) is off\n");
1202 if (!inbound
&& bgp_debug_update_out_peers
1203 && !list_isempty(bgp_debug_update_out_peers
)) {
1204 found_peer
= bgp_debug_list_remove_entry(
1205 bgp_debug_update_out_peers
, host
, NULL
);
1207 if (list_isempty(bgp_debug_update_out_peers
)) {
1208 if (vty
->node
== CONFIG_NODE
)
1209 DEBUG_OFF(update
, UPDATE_OUT
);
1211 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1213 "BGP updates debugging (outbound) is off\n");
1218 struct peer_af
*paf
;
1220 peer
= bgp_find_peer(vty
, host
);
1223 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1225 paf
= peer
->peer_af_array
[afidx
];
1227 if (PAF_SUBGRP(paf
)) {
1228 UPDGRP_PEER_DBG_DIS(
1240 "BGP updates debugging (inbound) is off for %s\n",
1244 "BGP updates debugging (outbound) is off for %s\n",
1248 "BGP updates debugging (inbound) was not enabled for %s\n",
1252 "BGP updates debugging (outbound) was not enabled for %s\n",
1258 DEFUN (debug_bgp_update_prefix
,
1259 debug_bgp_update_prefix_cmd
,
1260 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1264 "Specify a prefix to debug\n"
1268 int idx_ipv4_ipv6_prefixlen
= 4;
1269 struct prefix
*argv_p
;
1272 argv_p
= prefix_new();
1273 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1275 prefix_free(argv_p
);
1276 vty_out(vty
, "%% Malformed Prefix\n");
1277 return CMD_WARNING_CONFIG_FAILED
;
1281 if (!bgp_debug_update_prefixes
)
1282 bgp_debug_update_prefixes
= list_new();
1284 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1286 "BGP updates debugging is already enabled for %s\n",
1287 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1291 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1293 if (vty
->node
== CONFIG_NODE
) {
1294 DEBUG_ON(update
, UPDATE_PREFIX
);
1296 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1297 vty_out(vty
, "BGP updates debugging is on for %s\n",
1298 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1304 DEFUN (no_debug_bgp_update_prefix
,
1305 no_debug_bgp_update_prefix_cmd
,
1306 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1311 "Specify a prefix to debug\n"
1315 int idx_ipv4_ipv6_prefixlen
= 5;
1316 struct prefix
*argv_p
;
1317 int found_prefix
= 0;
1320 argv_p
= prefix_new();
1321 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1323 prefix_free(argv_p
);
1324 vty_out(vty
, "%% Malformed Prefix\n");
1325 return CMD_WARNING_CONFIG_FAILED
;
1328 if (bgp_debug_update_prefixes
1329 && !list_isempty(bgp_debug_update_prefixes
)) {
1330 found_prefix
= bgp_debug_list_remove_entry(
1331 bgp_debug_update_prefixes
, NULL
, argv_p
);
1333 if (list_isempty(bgp_debug_update_prefixes
)) {
1334 if (vty
->node
== CONFIG_NODE
) {
1335 DEBUG_OFF(update
, UPDATE_PREFIX
);
1337 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1339 "BGP updates debugging (per prefix) is off\n");
1345 vty_out(vty
, "BGP updates debugging is off for %s\n",
1346 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1348 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1349 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1354 DEFUN (no_debug_bgp_update
,
1355 no_debug_bgp_update_cmd
,
1356 "no debug bgp updates",
1362 struct listnode
*ln
;
1365 bgp_debug_list_free(bgp_debug_update_in_peers
);
1366 bgp_debug_list_free(bgp_debug_update_out_peers
);
1367 bgp_debug_list_free(bgp_debug_update_prefixes
);
1369 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1370 bgp_debug_clear_updgrp_update_dbg(bgp
);
1372 if (vty
->node
== CONFIG_NODE
) {
1373 DEBUG_OFF(update
, UPDATE_IN
);
1374 DEBUG_OFF(update
, UPDATE_OUT
);
1375 DEBUG_OFF(update
, UPDATE_PREFIX
);
1377 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1378 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1379 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1380 vty_out(vty
, "BGP updates debugging is off\n");
1385 /* debug bgp zebra */
1386 DEFUN (debug_bgp_zebra
,
1387 debug_bgp_zebra_cmd
,
1391 "BGP Zebra messages\n")
1393 if (vty
->node
== CONFIG_NODE
)
1394 DEBUG_ON(zebra
, ZEBRA
);
1396 TERM_DEBUG_ON(zebra
, ZEBRA
);
1397 vty_out(vty
, "BGP zebra debugging is on\n");
1402 DEFUN (debug_bgp_zebra_prefix
,
1403 debug_bgp_zebra_prefix_cmd
,
1404 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1407 "BGP Zebra messages\n"
1408 "Specify a prefix to debug\n"
1412 int idx_ipv4_ipv6_prefixlen
= 4;
1413 struct prefix
*argv_p
;
1416 argv_p
= prefix_new();
1417 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1419 prefix_free(argv_p
);
1420 vty_out(vty
, "%% Malformed Prefix\n");
1421 return CMD_WARNING_CONFIG_FAILED
;
1424 if (!bgp_debug_zebra_prefixes
)
1425 bgp_debug_zebra_prefixes
= list_new();
1427 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1428 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1429 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1433 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1435 if (vty
->node
== CONFIG_NODE
)
1436 DEBUG_ON(zebra
, ZEBRA
);
1438 TERM_DEBUG_ON(zebra
, ZEBRA
);
1439 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1440 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1446 DEFUN (no_debug_bgp_zebra
,
1447 no_debug_bgp_zebra_cmd
,
1448 "no debug bgp zebra",
1452 "BGP Zebra messages\n")
1454 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1456 if (vty
->node
== CONFIG_NODE
)
1457 DEBUG_OFF(zebra
, ZEBRA
);
1459 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1460 vty_out(vty
, "BGP zebra debugging is off\n");
1465 DEFUN (no_debug_bgp_zebra_prefix
,
1466 no_debug_bgp_zebra_prefix_cmd
,
1467 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1471 "BGP Zebra messages\n"
1472 "Specify a prefix to debug\n"
1476 int idx_ipv4_ipv6_prefixlen
= 5;
1477 struct prefix
*argv_p
;
1478 int found_prefix
= 0;
1481 argv_p
= prefix_new();
1482 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1484 prefix_free(argv_p
);
1485 vty_out(vty
, "%% Malformed Prefix\n");
1486 return CMD_WARNING_CONFIG_FAILED
;
1489 if (bgp_debug_zebra_prefixes
1490 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1491 found_prefix
= bgp_debug_list_remove_entry(
1492 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1494 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1495 if (vty
->node
== CONFIG_NODE
)
1496 DEBUG_OFF(zebra
, ZEBRA
);
1498 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1499 vty_out(vty
, "BGP zebra debugging is off\n");
1505 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1506 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1508 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1509 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1514 DEFUN (debug_bgp_allow_martians
,
1515 debug_bgp_allow_martians_cmd
,
1516 "debug bgp allow-martians",
1519 "BGP allow martian next hops\n")
1521 if (vty
->node
== CONFIG_NODE
)
1522 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1524 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1525 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1530 DEFUN (no_debug_bgp_allow_martians
,
1531 no_debug_bgp_allow_martians_cmd
,
1532 "no debug bgp allow-martians",
1536 "BGP allow martian next hops\n")
1538 if (vty
->node
== CONFIG_NODE
)
1539 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1541 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1542 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1548 /* debug bgp update-groups */
1549 DEFUN (debug_bgp_update_groups
,
1550 debug_bgp_update_groups_cmd
,
1551 "debug bgp update-groups",
1554 "BGP update-groups\n")
1556 if (vty
->node
== CONFIG_NODE
)
1557 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1559 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1560 vty_out(vty
, "BGP update-groups debugging is on\n");
1565 DEFUN (no_debug_bgp_update_groups
,
1566 no_debug_bgp_update_groups_cmd
,
1567 "no debug bgp update-groups",
1571 "BGP update-groups\n")
1573 if (vty
->node
== CONFIG_NODE
)
1574 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1576 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1577 vty_out(vty
, "BGP update-groups debugging is off\n");
1582 DEFUN (no_debug_bgp
,
1590 struct listnode
*ln
;
1592 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
1593 bgp_debug_list_free(bgp_debug_keepalive_peers
);
1594 bgp_debug_list_free(bgp_debug_update_in_peers
);
1595 bgp_debug_list_free(bgp_debug_update_out_peers
);
1596 bgp_debug_list_free(bgp_debug_update_prefixes
);
1597 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1598 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1600 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1601 bgp_debug_clear_updgrp_update_dbg(bgp
);
1603 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
1604 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1605 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1606 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1607 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1608 TERM_DEBUG_OFF(as4
, AS4
);
1609 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
1610 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
1611 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1612 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1613 vty_out(vty
, "All possible debugging has been turned off\n");
1618 DEFUN_NOSH (show_debugging_bgp
,
1619 show_debugging_bgp_cmd
,
1620 "show debugging [bgp]",
1625 vty_out(vty
, "BGP debugging status:\n");
1627 if (BGP_DEBUG(as4
, AS4
))
1628 vty_out(vty
, " BGP as4 debugging is on\n");
1630 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
1631 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
1633 if (BGP_DEBUG(bestpath
, BESTPATH
))
1634 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
1635 bgp_debug_bestpath_prefixes
);
1637 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
1638 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
1639 bgp_debug_keepalive_peers
);
1641 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
1642 bgp_debug_list_print(vty
,
1643 " BGP neighbor-events debugging is on",
1644 bgp_debug_neighbor_events_peers
);
1646 if (BGP_DEBUG(nht
, NHT
))
1647 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
1649 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1650 vty_out(vty
, " BGP update-groups debugging is on\n");
1652 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
1653 bgp_debug_list_print(vty
, " BGP updates debugging is on",
1654 bgp_debug_update_prefixes
);
1656 if (BGP_DEBUG(update
, UPDATE_IN
))
1657 bgp_debug_list_print(vty
,
1658 " BGP updates debugging is on (inbound)",
1659 bgp_debug_update_in_peers
);
1661 if (BGP_DEBUG(update
, UPDATE_OUT
))
1662 bgp_debug_list_print(vty
,
1663 " BGP updates debugging is on (outbound)",
1664 bgp_debug_update_out_peers
);
1666 if (BGP_DEBUG(zebra
, ZEBRA
))
1667 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
1668 bgp_debug_zebra_prefixes
);
1670 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
1671 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
1676 /* return count of number of debug flags set */
1677 int bgp_debug_count(void)
1680 if (BGP_DEBUG(as4
, AS4
))
1683 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
1686 if (BGP_DEBUG(bestpath
, BESTPATH
))
1689 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
1692 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
1695 if (BGP_DEBUG(nht
, NHT
))
1698 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1701 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
1704 if (BGP_DEBUG(update
, UPDATE_IN
))
1707 if (BGP_DEBUG(update
, UPDATE_OUT
))
1710 if (BGP_DEBUG(zebra
, ZEBRA
))
1713 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
1719 static int bgp_config_write_debug(struct vty
*vty
)
1723 if (CONF_BGP_DEBUG(as4
, AS4
)) {
1724 vty_out(vty
, "debug bgp as4\n");
1728 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
1729 vty_out(vty
, "debug bgp as4 segment\n");
1733 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
1734 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
1735 bgp_debug_bestpath_prefixes
);
1738 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
1739 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
1740 bgp_debug_keepalive_peers
);
1743 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
1744 write
+= bgp_debug_list_conf_print(
1745 vty
, "debug bgp neighbor-events",
1746 bgp_debug_neighbor_events_peers
);
1749 if (CONF_BGP_DEBUG(nht
, NHT
)) {
1750 vty_out(vty
, "debug bgp nht\n");
1754 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
1755 vty_out(vty
, "debug bgp update-groups\n");
1759 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
1760 write
+= bgp_debug_list_conf_print(vty
,
1761 "debug bgp updates prefix",
1762 bgp_debug_update_prefixes
);
1765 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
1766 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
1767 bgp_debug_update_in_peers
);
1770 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
1771 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
1772 bgp_debug_update_out_peers
);
1775 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
1776 if (!bgp_debug_zebra_prefixes
1777 || list_isempty(bgp_debug_zebra_prefixes
)) {
1778 vty_out(vty
, "debug bgp zebra\n");
1781 write
+= bgp_debug_list_conf_print(
1782 vty
, "debug bgp zebra prefix",
1783 bgp_debug_zebra_prefixes
);
1787 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
1788 vty_out(vty
, "debug bgp allow-martians\n");
1795 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
1797 void bgp_debug_init(void)
1799 install_node(&debug_node
, bgp_config_write_debug
);
1801 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
1803 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
1804 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
1805 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
1806 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
1808 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
1809 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
1810 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
1811 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
1812 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
1813 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
1814 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
1815 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
1816 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
1817 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
1818 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
1819 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
1820 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
1821 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
1822 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1823 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1825 /* debug bgp updates (in|out) */
1826 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
1827 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
1828 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
1829 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
1831 /* debug bgp updates (in|out) A.B.C.D */
1832 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
1833 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
1834 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1835 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1837 /* debug bgp updates prefix A.B.C.D/M */
1838 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
1839 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
1840 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
1841 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
1843 /* debug bgp zebra prefix A.B.C.D/M */
1844 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
1845 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
1846 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1847 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1849 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
1850 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
1851 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
1852 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
1854 /* debug bgp neighbor-events A.B.C.D */
1855 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1856 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1857 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1858 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1860 /* debug bgp keepalive A.B.C.D */
1861 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
1862 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
1863 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1864 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1866 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1867 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1868 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
1869 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
1870 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
1871 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
1872 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
1873 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
1874 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
1875 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
1876 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
1877 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
1878 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
1879 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
1880 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
1881 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
1882 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
1883 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1884 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1887 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
1888 * for BGP_DEBUG_TYPE
1890 static int bgp_debug_per_prefix(struct prefix
*p
,
1891 unsigned long term_bgp_debug_type
,
1892 unsigned int BGP_DEBUG_TYPE
,
1893 struct list
*per_prefix_list
)
1895 struct bgp_debug_filter
*filter
;
1896 struct listnode
*node
, *nnode
;
1898 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
1899 /* We are debugging all prefixes so return true */
1900 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
1907 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
1909 if (filter
->p
->prefixlen
== p
->prefixlen
1910 && prefix_match(filter
->p
, p
))
1920 /* Return true if this peer is on the per_peer_list of peers to debug
1921 * for BGP_DEBUG_TYPE
1923 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
1924 unsigned int BGP_DEBUG_TYPE
,
1925 struct list
*per_peer_list
)
1927 struct bgp_debug_filter
*filter
;
1928 struct listnode
*node
, *nnode
;
1930 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
1931 /* We are debugging all peers so return true */
1932 if (!per_peer_list
|| list_isempty(per_peer_list
))
1939 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
1941 if (strcmp(filter
->host
, host
) == 0)
1951 int bgp_debug_neighbor_events(struct peer
*peer
)
1958 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
1959 BGP_DEBUG_NEIGHBOR_EVENTS
,
1960 bgp_debug_neighbor_events_peers
);
1963 int bgp_debug_keepalive(struct peer
*peer
)
1970 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
1971 BGP_DEBUG_KEEPALIVE
,
1972 bgp_debug_keepalive_peers
);
1975 int bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
1976 struct update_group
*updgrp
, unsigned int inbound
)
1984 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
1985 BGP_DEBUG_UPDATE_IN
,
1986 bgp_debug_update_in_peers
))
1992 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
1993 BGP_DEBUG_UPDATE_OUT
,
1994 bgp_debug_update_out_peers
))
1997 /* Check if update debugging implicitly enabled for the group.
1999 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2004 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2005 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2006 BGP_DEBUG_UPDATE_PREFIX
,
2007 bgp_debug_update_prefixes
))
2014 int bgp_debug_bestpath(struct prefix
*p
)
2016 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2017 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
2019 bgp_debug_bestpath_prefixes
))
2026 int bgp_debug_zebra(struct prefix
*p
)
2028 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2029 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2031 bgp_debug_zebra_prefixes
))
2038 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2039 struct prefix_rd
*prd
,
2040 union prefixconstptr pu
,
2041 mpls_label_t
*label
, int addpath_valid
,
2042 u_int32_t addpath_id
, char *str
, int size
)
2044 char rd_buf
[RD_ADDRSTRLEN
];
2045 char pfx_buf
[PREFIX_STRLEN
];
2047 /* ' with addpath ID ' 17
2048 * max strlen of uint32 + 10
2049 * +/- (just in case) + 1
2050 * null terminator + 1
2051 * ============================ 29 */
2052 char pathid_buf
[30];
2054 if (size
< BGP_PRD_PATH_STRLEN
)
2057 /* Note: Path-id is created by default, but only included in update
2059 pathid_buf
[0] = '\0';
2061 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2065 if (bgp_labeled_safi(safi
) && label
) {
2066 u_int32_t label_value
;
2068 label_value
= decode_label(label
);
2069 sprintf(tag_buf
, " label %u", label_value
);
2073 snprintf(str
, size
, "RD %s %s%s%s",
2074 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2075 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2078 snprintf(str
, size
, "%s%s%s",
2079 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,