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>
24 #include "lib/printfrr.h"
30 #include "sockunion.h"
35 #include "bgpd/bgpd.h"
36 #include "bgpd/bgp_aspath.h"
37 #include "bgpd/bgp_route.h"
38 #include "bgpd/bgp_attr.h"
39 #include "bgpd/bgp_debug.h"
40 #include "bgpd/bgp_community.h"
41 #include "bgpd/bgp_lcommunity.h"
42 #include "bgpd/bgp_updgrp.h"
43 #include "bgpd/bgp_mplsvpn.h"
44 #include "bgpd/bgp_ecommunity.h"
45 #include "bgpd/bgp_label.h"
46 #include "bgpd/bgp_evpn.h"
47 #include "bgpd/bgp_evpn_private.h"
48 #include "bgpd/bgp_evpn_vty.h"
49 #include "bgpd/bgp_vty.h"
50 #include "bgpd/bgp_flowspec.h"
52 unsigned long conf_bgp_debug_as4
;
53 unsigned long conf_bgp_debug_neighbor_events
;
54 unsigned long conf_bgp_debug_events
;
55 unsigned long conf_bgp_debug_packet
;
56 unsigned long conf_bgp_debug_filter
;
57 unsigned long conf_bgp_debug_keepalive
;
58 unsigned long conf_bgp_debug_update
;
59 unsigned long conf_bgp_debug_bestpath
;
60 unsigned long conf_bgp_debug_zebra
;
61 unsigned long conf_bgp_debug_allow_martians
;
62 unsigned long conf_bgp_debug_nht
;
63 unsigned long conf_bgp_debug_update_groups
;
64 unsigned long conf_bgp_debug_vpn
;
65 unsigned long conf_bgp_debug_flowspec
;
66 unsigned long conf_bgp_debug_labelpool
;
67 unsigned long conf_bgp_debug_pbr
;
68 unsigned long conf_bgp_debug_graceful_restart
;
69 unsigned long conf_bgp_debug_evpn_mh
;
71 unsigned long term_bgp_debug_as4
;
72 unsigned long term_bgp_debug_neighbor_events
;
73 unsigned long term_bgp_debug_events
;
74 unsigned long term_bgp_debug_packet
;
75 unsigned long term_bgp_debug_filter
;
76 unsigned long term_bgp_debug_keepalive
;
77 unsigned long term_bgp_debug_update
;
78 unsigned long term_bgp_debug_bestpath
;
79 unsigned long term_bgp_debug_zebra
;
80 unsigned long term_bgp_debug_allow_martians
;
81 unsigned long term_bgp_debug_nht
;
82 unsigned long term_bgp_debug_update_groups
;
83 unsigned long term_bgp_debug_vpn
;
84 unsigned long term_bgp_debug_flowspec
;
85 unsigned long term_bgp_debug_labelpool
;
86 unsigned long term_bgp_debug_pbr
;
87 unsigned long term_bgp_debug_graceful_restart
;
88 unsigned long term_bgp_debug_evpn_mh
;
90 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
91 struct list
*bgp_debug_keepalive_peers
= NULL
;
92 struct list
*bgp_debug_update_out_peers
= NULL
;
93 struct list
*bgp_debug_update_in_peers
= NULL
;
94 struct list
*bgp_debug_update_prefixes
= NULL
;
95 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
96 struct list
*bgp_debug_zebra_prefixes
= NULL
;
98 /* messages for BGP-4 status */
99 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
100 {Connect
, "Connect"},
102 {OpenSent
, "OpenSent"},
103 {OpenConfirm
, "OpenConfirm"},
104 {Established
, "Established"},
105 {Clearing
, "Clearing"},
106 {Deleted
, "Deleted"},
109 /* BGP message type string. */
110 const char *const bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
111 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
114 /* message for BGP-4 Notify */
115 static const struct message bgp_notify_msg
[] = {
116 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
117 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
118 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
119 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
120 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
121 {BGP_NOTIFY_CEASE
, "Cease"},
122 {BGP_NOTIFY_ROUTE_REFRESH_ERR
, "ROUTE-REFRESH Message Error"},
125 static const struct message bgp_notify_head_msg
[] = {
126 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
127 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
128 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
131 static const struct message bgp_notify_open_msg
[] = {
132 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
133 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
134 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
135 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
136 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
137 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
138 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
139 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
142 static const struct message bgp_notify_update_msg
[] = {
143 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
144 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
145 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
146 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
147 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
148 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
149 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
150 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
151 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
152 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
153 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
154 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
157 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
,
166 "/Connection collision resolution"},
167 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
170 static const struct message bgp_notify_route_refresh_msg
[] = {
171 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
172 {BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN
, "/Invalid Message Length"},
175 static const struct message bgp_notify_fsm_msg
[] = {
176 {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC
, "/Unspecific"},
177 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT
,
178 "/Receive Unexpected Message in OpenSent State"},
179 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM
,
180 "/Receive Unexpected Message in OpenConfirm State"},
181 {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED
,
182 "/Receive Unexpected Message in Established State"},
185 /* Origin strings. */
186 const char *const bgp_origin_str
[] = {"i", "e", "?"};
187 const char *const bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
189 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
191 /* Given a string return a pointer the corresponding peer structure */
192 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
194 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
202 ret
= str2sockunion(peer_str
, &su
);
206 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
209 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
213 return peer_lookup(bgp
, &su
);
216 static void bgp_debug_list_free(struct list
*list
)
218 struct bgp_debug_filter
*filter
;
219 struct listnode
*node
, *nnode
;
222 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
223 listnode_delete(list
, filter
);
224 prefix_free(&filter
->p
);
225 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
226 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
231 * Print the desc along with a list of peers/prefixes this debug is
234 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
237 struct bgp_debug_filter
*filter
;
238 struct listnode
*node
, *nnode
;
240 vty_out(vty
, "%s", desc
);
242 if (list
&& !list_isempty(list
)) {
243 vty_out(vty
, " for");
244 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
246 vty_out(vty
, " %s", filter
->host
);
248 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
249 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
251 vty_out(vty
, " %pFX", filter
->p
);
259 * Print the command to enable the debug for each peer/prefix this debug is
262 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
265 struct bgp_debug_filter
*filter
;
266 struct listnode
*node
, *nnode
;
269 if (list
&& !list_isempty(list
)) {
270 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
272 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
276 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
277 bgp_debug_print_evpn_prefix(vty
, desc
,
280 } else if (filter
->p
) {
281 vty_out(vty
, "%s %pFX\n", desc
, filter
->p
);
288 vty_out(vty
, "%s\n", desc
);
295 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
296 const struct prefix
*p
)
298 struct bgp_debug_filter
*filter
;
300 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
301 sizeof(struct bgp_debug_filter
));
304 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
308 filter
->p
= prefix_new();
309 prefix_copy(filter
->p
, p
);
312 listnode_add(list
, filter
);
315 static bool bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
318 struct bgp_debug_filter
*filter
;
319 struct listnode
*node
, *nnode
;
321 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
322 if (host
&& strcmp(filter
->host
, host
) == 0) {
323 listnode_delete(list
, filter
);
324 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
325 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
327 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
328 && prefix_match(filter
->p
, p
)) {
329 listnode_delete(list
, filter
);
330 prefix_free(&filter
->p
);
331 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
339 static bool bgp_debug_list_has_entry(struct list
*list
, const char *host
,
340 const struct prefix
*p
)
342 struct bgp_debug_filter
*filter
;
343 struct listnode
*node
, *nnode
;
345 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
347 if (strcmp(filter
->host
, host
) == 0) {
351 if (filter
->p
->prefixlen
== p
->prefixlen
352 && prefix_match(filter
->p
, p
)) {
361 bool bgp_debug_peer_updout_enabled(char *host
)
363 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
367 /* Dump attribute. */
368 bool bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
370 char addrbuf
[BUFSIZ
];
377 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
378 snprintfrr(buf
, size
, "nexthop %pI4", &attr
->nexthop
);
380 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
381 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
382 bgp_origin_str
[attr
->origin
]);
385 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
386 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
387 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
389 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
392 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
393 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
394 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
397 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
398 snprintfrr(buf
, size
, "nexthop %pI4", &attr
->nexthop
);
400 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
401 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
402 ", localpref %u", attr
->local_pref
);
404 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
405 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
408 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
409 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
411 community_str(attr
->community
, false));
413 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
)))
414 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
415 ", large-community %s",
416 lcommunity_str(attr
->lcommunity
, false));
418 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
419 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
420 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
422 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
423 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
424 ", atomic-aggregate");
426 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
427 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
428 ", aggregated by %u %pI4", attr
->aggregator_as
,
429 &attr
->aggregator_addr
);
431 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
432 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
433 ", originator %pI4", &attr
->originator_id
);
435 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
436 struct cluster_list
*cluster
;
439 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
442 cluster
= bgp_attr_get_cluster(attr
);
443 for (i
= 0; i
< cluster
->length
/ 4; i
++)
444 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
445 " %pI4", &cluster
->list
[i
]);
448 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
449 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
450 ", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr
));
452 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
453 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
454 aspath_print(attr
->aspath
));
456 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
457 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
458 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
459 ", label-index %u", attr
->label_index
);
468 const char *bgp_notify_code_str(char code
)
470 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
473 const char *bgp_notify_subcode_str(char code
, char subcode
)
477 case BGP_NOTIFY_HEADER_ERR
:
478 return lookup_msg(bgp_notify_head_msg
, subcode
,
479 "Unrecognized Error Subcode");
480 case BGP_NOTIFY_OPEN_ERR
:
481 return lookup_msg(bgp_notify_open_msg
, subcode
,
482 "Unrecognized Error Subcode");
483 case BGP_NOTIFY_UPDATE_ERR
:
484 return lookup_msg(bgp_notify_update_msg
, subcode
,
485 "Unrecognized Error Subcode");
486 case BGP_NOTIFY_HOLD_ERR
:
488 case BGP_NOTIFY_FSM_ERR
:
489 return lookup_msg(bgp_notify_fsm_msg
, subcode
,
490 "Unrecognized Error Subcode");
491 case BGP_NOTIFY_CEASE
:
492 return lookup_msg(bgp_notify_cease_msg
, subcode
,
493 "Unrecognized Error Subcode");
494 case BGP_NOTIFY_ROUTE_REFRESH_ERR
:
495 return lookup_msg(bgp_notify_route_refresh_msg
, subcode
,
496 "Unrecognized Error Subcode");
501 /* extract notify admin reason if correctly present */
502 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
505 if (!data
|| datalen
< 1)
508 uint8_t len
= data
[0];
509 if (len
> 128 || len
> datalen
- 1)
512 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
515 /* dump notify packet */
516 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
519 const char *subcode_str
;
520 const char *code_str
;
521 const char *msg_str
= NULL
;
524 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
525 || CHECK_FLAG(peer
->bgp
->flags
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
526 code_str
= bgp_notify_code_str(bgp_notify
->code
);
527 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
528 bgp_notify
->subcode
);
530 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
531 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
532 || bgp_notify
->subcode
533 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
534 msg_str
= bgp_notify_admin_message(
535 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
541 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
542 strcmp(direct
, "received") == 0
545 peer
->host
, bgp_notify
->code
,
546 bgp_notify
->subcode
, code_str
, subcode_str
,
549 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
551 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
552 strcmp(direct
, "received") == 0
555 peer
->host
, bgp_notify
->code
,
556 bgp_notify
->subcode
, code_str
, subcode_str
,
557 bgp_notify
->length
, msg_str
);
562 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
565 bgp
= bgp_get_default();
566 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
569 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
572 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
573 char buf
[PREFIX2STR_BUFFER
];
574 char buf2
[ETHER_ADDR_STRLEN
];
576 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
577 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
579 evpn_desc
, sizeof(evpn_desc
),
580 "l2vpn evpn type macip mac %s",
581 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
582 buf2
, sizeof(buf2
)));
584 uint8_t family
= is_evpn_prefix_ipaddr_v4(
585 (struct prefix_evpn
*)p
) ?
588 evpn_desc
, sizeof(evpn_desc
),
589 "l2vpn evpn type macip mac %s ip %s",
590 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
594 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
595 buf
, PREFIX2STR_BUFFER
));
597 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
598 snprintfrr(evpn_desc
, sizeof(evpn_desc
),
599 "l2vpn evpn type multicast ip %pI4",
600 &p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
);
601 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
602 uint8_t family
= is_evpn_prefix_ipaddr_v4(
603 (struct prefix_evpn
*)p
) ? AF_INET
605 snprintf(evpn_desc
, sizeof(evpn_desc
),
606 "l2vpn evpn type prefix ip %s/%d",
608 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
,
609 buf
, PREFIX2STR_BUFFER
),
610 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
613 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
616 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
617 int argc
, struct prefix
**argv_pp
)
619 struct prefix
*argv_p
;
628 if (bgp_evpn_cli_parse_type(&evpn_type
, argv
, argc
) < 0)
631 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
632 memset(&ip
, 0, sizeof(struct ipaddr
));
634 argv_find(argv
, argc
, "mac", &mac_idx
);
635 (void)prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
);
637 argv_find(argv
, argc
, "ip", &ip_idx
);
638 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
640 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
642 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
643 memset(&ip
, 0, sizeof(struct ipaddr
));
645 argv_find(argv
, argc
, "ip", &ip_idx
);
646 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
648 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
650 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
651 struct prefix ip_prefix
;
653 memset(&ip_prefix
, 0, sizeof(struct prefix
));
654 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
655 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
656 apply_mask(&ip_prefix
);
658 build_type5_prefix_from_ip_prefix(
659 (struct prefix_evpn
*)argv_p
,
666 /* Debug option setting interface. */
667 unsigned long bgp_debug_option
= 0;
669 int debug(unsigned int option
)
671 return bgp_debug_option
& option
;
674 DEFUN (debug_bgp_as4
,
681 if (vty
->node
== CONFIG_NODE
)
684 TERM_DEBUG_ON(as4
, AS4
);
685 vty_out(vty
, "BGP as4 debugging is on\n");
690 DEFUN (no_debug_bgp_as4
,
691 no_debug_bgp_as4_cmd
,
698 if (vty
->node
== CONFIG_NODE
)
701 TERM_DEBUG_OFF(as4
, AS4
);
702 vty_out(vty
, "BGP as4 debugging is off\n");
707 DEFUN (debug_bgp_as4_segment
,
708 debug_bgp_as4_segment_cmd
,
709 "debug bgp as4 segment",
713 "BGP AS4 aspath segment handling\n")
715 if (vty
->node
== CONFIG_NODE
)
716 DEBUG_ON(as4
, AS4_SEGMENT
);
718 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
719 vty_out(vty
, "BGP as4 segment debugging is on\n");
724 DEFUN (no_debug_bgp_as4_segment
,
725 no_debug_bgp_as4_segment_cmd
,
726 "no debug bgp as4 segment",
731 "BGP AS4 aspath segment handling\n")
733 if (vty
->node
== CONFIG_NODE
)
734 DEBUG_OFF(as4
, AS4_SEGMENT
);
736 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
737 vty_out(vty
, "BGP as4 segment debugging is off\n");
742 /* debug bgp neighbor_events */
743 DEFUN (debug_bgp_neighbor_events
,
744 debug_bgp_neighbor_events_cmd
,
745 "debug bgp neighbor-events",
748 "BGP Neighbor Events\n")
750 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
752 if (vty
->node
== CONFIG_NODE
)
753 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
755 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
756 vty_out(vty
, "BGP neighbor-events debugging is on\n");
761 DEFUN (debug_bgp_neighbor_events_peer
,
762 debug_bgp_neighbor_events_peer_cmd
,
763 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
766 "BGP Neighbor Events\n"
767 "BGP neighbor IP address to debug\n"
768 "BGP IPv6 neighbor to debug\n"
769 "BGP neighbor on interface to debug\n")
772 const char *host
= argv
[idx_peer
]->arg
;
774 if (!bgp_debug_neighbor_events_peers
)
775 bgp_debug_neighbor_events_peers
= list_new();
777 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
780 "BGP neighbor-events debugging is already enabled for %s\n",
785 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
787 if (vty
->node
== CONFIG_NODE
)
788 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
790 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
791 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
797 DEFUN (no_debug_bgp_neighbor_events
,
798 no_debug_bgp_neighbor_events_cmd
,
799 "no debug bgp neighbor-events",
805 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
807 if (vty
->node
== CONFIG_NODE
)
808 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
810 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
811 vty_out(vty
, "BGP neighbor-events debugging is off\n");
816 DEFUN (no_debug_bgp_neighbor_events_peer
,
817 no_debug_bgp_neighbor_events_peer_cmd
,
818 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
823 "BGP neighbor IP address to debug\n"
824 "BGP IPv6 neighbor to debug\n"
825 "BGP neighbor on interface to debug\n")
829 const char *host
= argv
[idx_peer
]->arg
;
831 if (bgp_debug_neighbor_events_peers
832 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
833 found_peer
= bgp_debug_list_remove_entry(
834 bgp_debug_neighbor_events_peers
, host
, NULL
);
836 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
837 if (vty
->node
== CONFIG_NODE
)
838 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
840 TERM_DEBUG_OFF(neighbor_events
,
846 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
850 "BGP neighbor-events debugging was not enabled for %s\n",
857 DEFUN (debug_bgp_nht
,
862 "BGP nexthop tracking events\n")
864 if (vty
->node
== CONFIG_NODE
)
867 TERM_DEBUG_ON(nht
, NHT
);
868 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
873 DEFUN (no_debug_bgp_nht
,
874 no_debug_bgp_nht_cmd
,
879 "BGP nexthop tracking events\n")
881 if (vty
->node
== CONFIG_NODE
)
884 TERM_DEBUG_OFF(nht
, NHT
);
885 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
890 /* debug bgp keepalives */
891 DEFUN (debug_bgp_keepalive
,
892 debug_bgp_keepalive_cmd
,
893 "debug bgp keepalives",
898 bgp_debug_list_free(bgp_debug_keepalive_peers
);
900 if (vty
->node
== CONFIG_NODE
)
901 DEBUG_ON(keepalive
, KEEPALIVE
);
903 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
904 vty_out(vty
, "BGP keepalives debugging is on\n");
909 DEFUN (debug_bgp_keepalive_peer
,
910 debug_bgp_keepalive_peer_cmd
,
911 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
915 "BGP IPv4 neighbor to debug\n"
916 "BGP IPv6 neighbor to debug\n"
917 "BGP neighbor on interface to debug\n")
920 const char *host
= argv
[idx_peer
]->arg
;
922 if (!bgp_debug_keepalive_peers
)
923 bgp_debug_keepalive_peers
= list_new();
925 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
927 "BGP keepalive debugging is already enabled for %s\n",
932 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
934 if (vty
->node
== CONFIG_NODE
)
935 DEBUG_ON(keepalive
, KEEPALIVE
);
937 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
938 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
943 DEFUN (no_debug_bgp_keepalive
,
944 no_debug_bgp_keepalive_cmd
,
945 "no debug bgp keepalives",
951 bgp_debug_list_free(bgp_debug_keepalive_peers
);
953 if (vty
->node
== CONFIG_NODE
)
954 DEBUG_OFF(keepalive
, KEEPALIVE
);
956 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
957 vty_out(vty
, "BGP keepalives debugging is off\n");
962 DEFUN (no_debug_bgp_keepalive_peer
,
963 no_debug_bgp_keepalive_peer_cmd
,
964 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
969 "BGP neighbor IP address to debug\n"
970 "BGP IPv6 neighbor to debug\n"
971 "BGP neighbor on interface to debug\n")
975 const char *host
= argv
[idx_peer
]->arg
;
977 if (bgp_debug_keepalive_peers
978 && !list_isempty(bgp_debug_keepalive_peers
)) {
979 found_peer
= bgp_debug_list_remove_entry(
980 bgp_debug_keepalive_peers
, host
, NULL
);
982 if (list_isempty(bgp_debug_keepalive_peers
)) {
983 if (vty
->node
== CONFIG_NODE
)
984 DEBUG_OFF(keepalive
, KEEPALIVE
);
986 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
991 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
994 "BGP keepalives debugging was not enabled for %s\n",
1000 /* debug bgp bestpath */
1001 DEFUN (debug_bgp_bestpath_prefix
,
1002 debug_bgp_bestpath_prefix_cmd
,
1003 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1010 struct prefix
*argv_p
;
1011 int idx_ipv4_ipv6_prefixlen
= 3;
1013 argv_p
= prefix_new();
1014 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1017 if (!bgp_debug_bestpath_prefixes
)
1018 bgp_debug_bestpath_prefixes
= list_new();
1020 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1023 "BGP bestpath debugging is already enabled for %s\n",
1024 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1028 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1030 if (vty
->node
== CONFIG_NODE
) {
1031 DEBUG_ON(bestpath
, BESTPATH
);
1033 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1034 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1035 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1041 DEFUN (no_debug_bgp_bestpath_prefix
,
1042 no_debug_bgp_bestpath_prefix_cmd
,
1043 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1051 int idx_ipv4_ipv6_prefixlen
= 4;
1052 struct prefix
*argv_p
;
1053 int found_prefix
= 0;
1055 argv_p
= prefix_new();
1056 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1059 if (bgp_debug_bestpath_prefixes
1060 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1061 found_prefix
= bgp_debug_list_remove_entry(
1062 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1064 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1065 if (vty
->node
== CONFIG_NODE
) {
1066 DEBUG_OFF(bestpath
, BESTPATH
);
1068 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1070 "BGP bestpath debugging (per prefix) is off\n");
1076 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1077 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1079 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1080 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1085 DEFUN (no_debug_bgp_bestpath
,
1086 no_debug_bgp_bestpath_cmd
,
1087 "no debug bgp bestpath",
1093 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1095 if (vty
->node
== CONFIG_NODE
)
1096 DEBUG_OFF(bestpath
, BESTPATH
);
1098 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1099 vty_out(vty
, "BGP bestpath debugging is off\n");
1104 /* debug bgp updates */
1105 DEFUN (debug_bgp_update
,
1106 debug_bgp_update_cmd
,
1107 "debug bgp updates",
1112 bgp_debug_list_free(bgp_debug_update_in_peers
);
1113 bgp_debug_list_free(bgp_debug_update_out_peers
);
1114 bgp_debug_list_free(bgp_debug_update_prefixes
);
1116 if (vty
->node
== CONFIG_NODE
) {
1117 DEBUG_ON(update
, UPDATE_IN
);
1118 DEBUG_ON(update
, UPDATE_OUT
);
1120 TERM_DEBUG_ON(update
, UPDATE_IN
);
1121 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1122 vty_out(vty
, "BGP updates debugging is on\n");
1127 DEFUN (debug_bgp_update_direct
,
1128 debug_bgp_update_direct_cmd
,
1129 "debug bgp updates <in|out>",
1134 "Outbound updates\n")
1138 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1139 bgp_debug_list_free(bgp_debug_update_in_peers
);
1141 bgp_debug_list_free(bgp_debug_update_out_peers
);
1143 if (vty
->node
== CONFIG_NODE
) {
1144 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1145 DEBUG_ON(update
, UPDATE_IN
);
1147 DEBUG_ON(update
, UPDATE_OUT
);
1149 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1150 TERM_DEBUG_ON(update
, UPDATE_IN
);
1151 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1153 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1155 "BGP updates debugging is on (outbound)\n");
1161 DEFUN (debug_bgp_update_direct_peer
,
1162 debug_bgp_update_direct_peer_cmd
,
1163 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1168 "Outbound updates\n"
1169 "BGP neighbor IP address to debug\n"
1170 "BGP IPv6 neighbor to debug\n"
1171 "BGP neighbor on interface to debug\n")
1175 const char *host
= argv
[idx_peer
]->arg
;
1178 if (!bgp_debug_update_in_peers
)
1179 bgp_debug_update_in_peers
= list_new();
1181 if (!bgp_debug_update_out_peers
)
1182 bgp_debug_update_out_peers
= list_new();
1184 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1190 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1193 "BGP inbound update debugging is already enabled for %s\n",
1200 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1203 "BGP outbound update debugging is already enabled for %s\n",
1210 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1213 struct peer_af
*paf
;
1216 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1218 peer
= bgp_find_peer(vty
, host
);
1221 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1223 paf
= peer
->peer_af_array
[afidx
];
1225 if (PAF_SUBGRP(paf
)) {
1235 if (vty
->node
== CONFIG_NODE
) {
1237 DEBUG_ON(update
, UPDATE_IN
);
1239 DEBUG_ON(update
, UPDATE_OUT
);
1242 TERM_DEBUG_ON(update
, UPDATE_IN
);
1244 "BGP updates debugging is on (inbound) for %s\n",
1245 argv
[idx_peer
]->arg
);
1247 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1249 "BGP updates debugging is on (outbound) for %s\n",
1250 argv
[idx_peer
]->arg
);
1256 DEFUN (no_debug_bgp_update_direct
,
1257 no_debug_bgp_update_direct_cmd
,
1258 "no debug bgp updates <in|out>",
1264 "Outbound updates\n")
1267 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1268 bgp_debug_list_free(bgp_debug_update_in_peers
);
1270 if (vty
->node
== CONFIG_NODE
) {
1271 DEBUG_OFF(update
, UPDATE_IN
);
1273 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1275 "BGP updates debugging is off (inbound)\n");
1278 bgp_debug_list_free(bgp_debug_update_out_peers
);
1280 if (vty
->node
== CONFIG_NODE
) {
1281 DEBUG_OFF(update
, UPDATE_OUT
);
1283 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1285 "BGP updates debugging is off (outbound)\n");
1292 DEFUN (no_debug_bgp_update_direct_peer
,
1293 no_debug_bgp_update_direct_peer_cmd
,
1294 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1300 "Outbound updates\n"
1301 "BGP neighbor IP address to debug\n"
1302 "BGP IPv6 neighbor to debug\n"
1303 "BGP neighbor on interface to debug\n")
1309 const char *host
= argv
[idx_peer
]->arg
;
1311 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1316 if (inbound
&& bgp_debug_update_in_peers
1317 && !list_isempty(bgp_debug_update_in_peers
)) {
1318 found_peer
= bgp_debug_list_remove_entry(
1319 bgp_debug_update_in_peers
, host
, NULL
);
1321 if (list_isempty(bgp_debug_update_in_peers
)) {
1322 if (vty
->node
== CONFIG_NODE
)
1323 DEBUG_OFF(update
, UPDATE_IN
);
1325 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1327 "BGP updates debugging (inbound) is off\n");
1332 if (!inbound
&& bgp_debug_update_out_peers
1333 && !list_isempty(bgp_debug_update_out_peers
)) {
1334 found_peer
= bgp_debug_list_remove_entry(
1335 bgp_debug_update_out_peers
, host
, NULL
);
1337 if (list_isempty(bgp_debug_update_out_peers
)) {
1338 if (vty
->node
== CONFIG_NODE
)
1339 DEBUG_OFF(update
, UPDATE_OUT
);
1341 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1343 "BGP updates debugging (outbound) is off\n");
1348 struct peer_af
*paf
;
1350 peer
= bgp_find_peer(vty
, host
);
1353 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1355 paf
= peer
->peer_af_array
[afidx
];
1357 if (PAF_SUBGRP(paf
)) {
1358 UPDGRP_PEER_DBG_DIS(
1370 "BGP updates debugging (inbound) is off for %s\n",
1374 "BGP updates debugging (outbound) is off for %s\n",
1378 "BGP updates debugging (inbound) was not enabled for %s\n",
1382 "BGP updates debugging (outbound) was not enabled for %s\n",
1388 #ifndef VTYSH_EXTRACT_PL
1389 #include "bgpd/bgp_debug_clippy.c"
1392 DEFPY (debug_bgp_update_prefix_afi_safi
,
1393 debug_bgp_update_prefix_afi_safi_cmd
,
1394 "debug bgp updates prefix l2vpn$afi evpn$safi type <<macip|2> mac <X:X:X:X:X:X|X:X:X:X:X:X/M> [ip <A.B.C.D|X:X::X:X>]|<multicast|3> ip <A.B.C.D|X:X::X:X>|<prefix|5> ip <A.B.C.D/M|X:X::X:X/M>>",
1398 "Specify a prefix to debug\n"
1402 EVPN_TYPE_2_HELP_STR
1403 EVPN_TYPE_2_HELP_STR
1404 MAC_STR MAC_STR MAC_STR
1408 EVPN_TYPE_3_HELP_STR
1409 EVPN_TYPE_3_HELP_STR
1413 EVPN_TYPE_5_HELP_STR
1414 EVPN_TYPE_5_HELP_STR
1419 struct prefix
*argv_p
;
1420 int ret
= CMD_SUCCESS
;
1422 argv_p
= prefix_new();
1424 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1425 if (ret
!= CMD_SUCCESS
) {
1426 prefix_free(&argv_p
);
1430 if (!bgp_debug_update_prefixes
)
1431 bgp_debug_update_prefixes
= list_new();
1433 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1435 "BGP updates debugging is already enabled for %pFX\n",
1437 prefix_free(&argv_p
);
1441 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1443 if (vty
->node
== CONFIG_NODE
) {
1444 DEBUG_ON(update
, UPDATE_PREFIX
);
1446 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1447 vty_out(vty
, "BGP updates debugging is on for %pFX\n", argv_p
);
1450 prefix_free(&argv_p
);
1455 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1456 no_debug_bgp_update_prefix_afi_safi_cmd
,
1457 "no debug bgp updates prefix l2vpn$afi evpn$safi type <<macip|2> mac <X:X:X:X:X:X|X:X:X:X:X:X/M> [ip <A.B.C.D|X:X::X:X>]|<multicast|3> ip <A.B.C.D|X:X::X:X>|<prefix|5> ip <A.B.C.D/M|X:X::X:X/M>>",
1462 "Specify a prefix to debug\n"
1466 EVPN_TYPE_2_HELP_STR
1467 EVPN_TYPE_2_HELP_STR
1468 MAC_STR MAC_STR MAC_STR
1472 EVPN_TYPE_3_HELP_STR
1473 EVPN_TYPE_3_HELP_STR
1477 EVPN_TYPE_5_HELP_STR
1478 EVPN_TYPE_5_HELP_STR
1483 struct prefix
*argv_p
;
1484 bool found_prefix
= false;
1485 int ret
= CMD_SUCCESS
;
1487 argv_p
= prefix_new();
1489 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1490 if (ret
!= CMD_SUCCESS
) {
1491 prefix_free(&argv_p
);
1495 if (bgp_debug_update_prefixes
1496 && !list_isempty(bgp_debug_update_prefixes
)) {
1497 found_prefix
= bgp_debug_list_remove_entry(
1498 bgp_debug_update_prefixes
, NULL
, argv_p
);
1500 if (list_isempty(bgp_debug_update_prefixes
)) {
1501 if (vty
->node
== CONFIG_NODE
) {
1502 DEBUG_OFF(update
, UPDATE_PREFIX
);
1504 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1506 "BGP updates debugging (per prefix) is off\n");
1512 vty_out(vty
, "BGP updates debugging is off for %pFX\n", argv_p
);
1514 vty_out(vty
, "BGP updates debugging was not enabled for %pFX\n",
1517 prefix_free(&argv_p
);
1523 DEFUN (debug_bgp_update_prefix
,
1524 debug_bgp_update_prefix_cmd
,
1525 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1529 "Specify a prefix to debug\n"
1533 int idx_ipv4_ipv6_prefixlen
= 4;
1534 struct prefix
*argv_p
;
1536 argv_p
= prefix_new();
1537 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1540 if (!bgp_debug_update_prefixes
)
1541 bgp_debug_update_prefixes
= list_new();
1543 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1545 "BGP updates debugging is already enabled for %s\n",
1546 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1550 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1552 if (vty
->node
== CONFIG_NODE
) {
1553 DEBUG_ON(update
, UPDATE_PREFIX
);
1555 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1556 vty_out(vty
, "BGP updates debugging is on for %s\n",
1557 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1563 DEFUN (no_debug_bgp_update_prefix
,
1564 no_debug_bgp_update_prefix_cmd
,
1565 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1570 "Specify a prefix to debug\n"
1574 int idx_ipv4_ipv6_prefixlen
= 5;
1575 struct prefix
*argv_p
;
1576 int found_prefix
= 0;
1578 argv_p
= prefix_new();
1579 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1582 if (bgp_debug_update_prefixes
1583 && !list_isempty(bgp_debug_update_prefixes
)) {
1584 found_prefix
= bgp_debug_list_remove_entry(
1585 bgp_debug_update_prefixes
, NULL
, argv_p
);
1587 if (list_isempty(bgp_debug_update_prefixes
)) {
1588 if (vty
->node
== CONFIG_NODE
) {
1589 DEBUG_OFF(update
, UPDATE_PREFIX
);
1591 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1593 "BGP updates debugging (per prefix) is off\n");
1599 vty_out(vty
, "BGP updates debugging is off for %s\n",
1600 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1602 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1603 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1608 DEFUN (no_debug_bgp_update
,
1609 no_debug_bgp_update_cmd
,
1610 "no debug bgp updates",
1616 struct listnode
*ln
;
1619 bgp_debug_list_free(bgp_debug_update_in_peers
);
1620 bgp_debug_list_free(bgp_debug_update_out_peers
);
1621 bgp_debug_list_free(bgp_debug_update_prefixes
);
1623 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1624 bgp_debug_clear_updgrp_update_dbg(bgp
);
1626 if (vty
->node
== CONFIG_NODE
) {
1627 DEBUG_OFF(update
, UPDATE_IN
);
1628 DEBUG_OFF(update
, UPDATE_OUT
);
1629 DEBUG_OFF(update
, UPDATE_PREFIX
);
1631 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1632 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1633 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1634 vty_out(vty
, "BGP updates debugging is off\n");
1639 /* debug bgp zebra */
1640 DEFUN (debug_bgp_zebra
,
1641 debug_bgp_zebra_cmd
,
1645 "BGP Zebra messages\n")
1647 if (vty
->node
== CONFIG_NODE
)
1648 DEBUG_ON(zebra
, ZEBRA
);
1650 TERM_DEBUG_ON(zebra
, ZEBRA
);
1651 vty_out(vty
, "BGP zebra debugging is on\n");
1656 DEFUN (debug_bgp_graceful_restart
,
1657 debug_bgp_graceful_restart_cmd
,
1658 "debug bgp graceful-restart",
1663 if (vty
->node
== CONFIG_NODE
) {
1664 DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1666 TERM_DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1667 vty_out(vty
, "BGP Graceful Restart debugging is on\n");
1673 DEFUN (debug_bgp_zebra_prefix
,
1674 debug_bgp_zebra_prefix_cmd
,
1675 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1678 "BGP Zebra messages\n"
1679 "Specify a prefix to debug\n"
1683 int idx_ipv4_ipv6_prefixlen
= 4;
1684 struct prefix
*argv_p
;
1686 argv_p
= prefix_new();
1687 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1690 if (!bgp_debug_zebra_prefixes
)
1691 bgp_debug_zebra_prefixes
= list_new();
1693 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1694 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1695 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1699 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1701 if (vty
->node
== CONFIG_NODE
)
1702 DEBUG_ON(zebra
, ZEBRA
);
1704 TERM_DEBUG_ON(zebra
, ZEBRA
);
1705 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1706 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1712 DEFUN (no_debug_bgp_zebra
,
1713 no_debug_bgp_zebra_cmd
,
1714 "no debug bgp zebra",
1718 "BGP Zebra messages\n")
1720 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1722 if (vty
->node
== CONFIG_NODE
)
1723 DEBUG_OFF(zebra
, ZEBRA
);
1725 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1726 vty_out(vty
, "BGP zebra debugging is off\n");
1731 DEFUN (no_debug_bgp_graceful_restart
,
1732 no_debug_bgp_graceful_restart_cmd
,
1733 "no debug bgp graceful-restart",
1739 if (vty
->node
== CONFIG_NODE
) {
1740 DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1742 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1743 vty_out(vty
, "BGP Graceful Restart debugging is off\n");
1748 DEFUN (no_debug_bgp_zebra_prefix
,
1749 no_debug_bgp_zebra_prefix_cmd
,
1750 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1754 "BGP Zebra messages\n"
1755 "Specify a prefix to debug\n"
1759 int idx_ipv4_ipv6_prefixlen
= 5;
1760 struct prefix
*argv_p
;
1761 int found_prefix
= 0;
1763 argv_p
= prefix_new();
1764 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1767 if (bgp_debug_zebra_prefixes
1768 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1769 found_prefix
= bgp_debug_list_remove_entry(
1770 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1772 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1773 if (vty
->node
== CONFIG_NODE
)
1774 DEBUG_OFF(zebra
, ZEBRA
);
1776 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1777 vty_out(vty
, "BGP zebra debugging is off\n");
1783 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1784 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1786 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1787 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1792 DEFUN (debug_bgp_allow_martians
,
1793 debug_bgp_allow_martians_cmd
,
1794 "debug bgp allow-martians",
1797 "BGP allow martian next hops\n")
1799 if (vty
->node
== CONFIG_NODE
)
1800 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1802 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1803 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1808 DEFUN (no_debug_bgp_allow_martians
,
1809 no_debug_bgp_allow_martians_cmd
,
1810 "no debug bgp allow-martians",
1814 "BGP allow martian next hops\n")
1816 if (vty
->node
== CONFIG_NODE
)
1817 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1819 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1820 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1826 /* debug bgp update-groups */
1827 DEFUN (debug_bgp_update_groups
,
1828 debug_bgp_update_groups_cmd
,
1829 "debug bgp update-groups",
1832 "BGP update-groups\n")
1834 if (vty
->node
== CONFIG_NODE
)
1835 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1837 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1838 vty_out(vty
, "BGP update-groups debugging is on\n");
1843 DEFUN (no_debug_bgp_update_groups
,
1844 no_debug_bgp_update_groups_cmd
,
1845 "no debug bgp update-groups",
1849 "BGP update-groups\n")
1851 if (vty
->node
== CONFIG_NODE
)
1852 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1854 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1855 vty_out(vty
, "BGP update-groups debugging is off\n");
1860 DEFUN (debug_bgp_vpn
,
1862 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1866 "leaked from vrf to vpn\n"
1867 "leaked to vrf from vpn\n"
1868 "route-map updates\n"
1873 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1874 if (vty
->node
== CONFIG_NODE
)
1875 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1877 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1878 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1879 if (vty
->node
== CONFIG_NODE
)
1880 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1882 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1883 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1884 if (vty
->node
== CONFIG_NODE
)
1885 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1887 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1888 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1889 if (vty
->node
== CONFIG_NODE
)
1890 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1892 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1894 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1895 return CMD_WARNING_CONFIG_FAILED
;
1898 if (vty
->node
!= CONFIG_NODE
)
1899 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1904 DEFUN (no_debug_bgp_vpn
,
1905 no_debug_bgp_vpn_cmd
,
1906 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1911 "leaked from vrf to vpn\n"
1912 "leaked to vrf from vpn\n"
1913 "route-map updates\n"
1918 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1919 if (vty
->node
== CONFIG_NODE
)
1920 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1922 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1924 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1925 if (vty
->node
== CONFIG_NODE
)
1926 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1928 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1929 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1930 if (vty
->node
== CONFIG_NODE
)
1931 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1933 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1934 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1935 if (vty
->node
== CONFIG_NODE
)
1936 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1938 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1940 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1941 return CMD_WARNING_CONFIG_FAILED
;
1944 if (vty
->node
!= CONFIG_NODE
)
1945 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1950 DEFUN (debug_bgp_pbr
,
1952 "debug bgp pbr [error]",
1955 "BGP policy based routing\n"
1960 if (argv_find(argv
, argc
, "error", &idx
)) {
1961 if (vty
->node
== CONFIG_NODE
)
1962 DEBUG_ON(pbr
, PBR_ERROR
);
1964 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1965 vty_out(vty
, "BGP policy based routing error is on\n");
1969 if (vty
->node
== CONFIG_NODE
)
1972 TERM_DEBUG_ON(pbr
, PBR
);
1973 vty_out(vty
, "BGP policy based routing is on\n");
1978 DEFUN (no_debug_bgp_pbr
,
1979 no_debug_bgp_pbr_cmd
,
1980 "no debug bgp pbr [error]",
1984 "BGP policy based routing\n"
1989 if (argv_find(argv
, argc
, "error", &idx
)) {
1990 if (vty
->node
== CONFIG_NODE
)
1991 DEBUG_OFF(pbr
, PBR_ERROR
);
1993 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1994 vty_out(vty
, "BGP policy based routing error is off\n");
1998 if (vty
->node
== CONFIG_NODE
)
1999 DEBUG_OFF(pbr
, PBR
);
2001 TERM_DEBUG_OFF(pbr
, PBR
);
2002 vty_out(vty
, "BGP policy based routing is off\n");
2007 DEFPY (debug_bgp_evpn_mh
,
2008 debug_bgp_evpn_mh_cmd
,
2009 "[no$no] debug bgp evpn mh <es$es|route$rt>",
2015 "Ethernet Segment debugging\n"
2016 "Route debugging\n")
2019 if (vty
->node
== CONFIG_NODE
) {
2021 DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2023 DEBUG_ON(evpn_mh
, EVPN_MH_ES
);
2026 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2028 "BGP EVPN-MH ES debugging is off\n");
2030 TERM_DEBUG_ON(evpn_mh
, EVPN_MH_ES
);
2032 "BGP EVPN-MH ES debugging is on\n");
2037 if (vty
->node
== CONFIG_NODE
) {
2039 DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2041 DEBUG_ON(evpn_mh
, EVPN_MH_RT
);
2044 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2046 "BGP EVPN-MH route debugging is off\n");
2048 TERM_DEBUG_ON(evpn_mh
, EVPN_MH_RT
);
2050 "BGP EVPN-MH route debugging is on\n");
2058 DEFUN (debug_bgp_labelpool
,
2059 debug_bgp_labelpool_cmd
,
2060 "debug bgp labelpool",
2065 if (vty
->node
== CONFIG_NODE
)
2066 DEBUG_ON(labelpool
, LABELPOOL
);
2068 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
2070 if (vty
->node
!= CONFIG_NODE
)
2071 vty_out(vty
, "enabled debug bgp labelpool\n");
2076 DEFUN (no_debug_bgp_labelpool
,
2077 no_debug_bgp_labelpool_cmd
,
2078 "no debug bgp labelpool",
2084 if (vty
->node
== CONFIG_NODE
)
2085 DEBUG_OFF(labelpool
, LABELPOOL
);
2087 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2090 if (vty
->node
!= CONFIG_NODE
)
2091 vty_out(vty
, "disabled debug bgp labelpool\n");
2096 DEFUN (no_debug_bgp
,
2104 struct listnode
*ln
;
2106 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2107 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2108 bgp_debug_list_free(bgp_debug_update_in_peers
);
2109 bgp_debug_list_free(bgp_debug_update_out_peers
);
2110 bgp_debug_list_free(bgp_debug_update_prefixes
);
2111 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2112 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2114 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2115 bgp_debug_clear_updgrp_update_dbg(bgp
);
2117 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2118 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2119 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2120 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2121 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2122 TERM_DEBUG_OFF(as4
, AS4
);
2123 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2124 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2125 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2126 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2127 TERM_DEBUG_OFF(nht
, NHT
);
2128 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2129 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2130 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2131 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2132 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2133 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2134 TERM_DEBUG_OFF(pbr
, PBR
);
2135 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2136 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
2137 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2138 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2140 vty_out(vty
, "All possible debugging has been turned off\n");
2145 DEFUN_NOSH (show_debugging_bgp
,
2146 show_debugging_bgp_cmd
,
2147 "show debugging [bgp]",
2152 vty_out(vty
, "BGP debugging status:\n");
2154 if (BGP_DEBUG(as4
, AS4
))
2155 vty_out(vty
, " BGP as4 debugging is on\n");
2157 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2158 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2160 if (BGP_DEBUG(bestpath
, BESTPATH
))
2161 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2162 bgp_debug_bestpath_prefixes
);
2164 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2165 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2166 bgp_debug_keepalive_peers
);
2168 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2169 bgp_debug_list_print(vty
,
2170 " BGP neighbor-events debugging is on",
2171 bgp_debug_neighbor_events_peers
);
2173 if (BGP_DEBUG(nht
, NHT
))
2174 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2176 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2177 vty_out(vty
, " BGP update-groups debugging is on\n");
2179 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2180 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2181 bgp_debug_update_prefixes
);
2183 if (BGP_DEBUG(update
, UPDATE_IN
))
2184 bgp_debug_list_print(vty
,
2185 " BGP updates debugging is on (inbound)",
2186 bgp_debug_update_in_peers
);
2188 if (BGP_DEBUG(update
, UPDATE_OUT
))
2189 bgp_debug_list_print(vty
,
2190 " BGP updates debugging is on (outbound)",
2191 bgp_debug_update_out_peers
);
2193 if (BGP_DEBUG(zebra
, ZEBRA
))
2194 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2195 bgp_debug_zebra_prefixes
);
2197 if (BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
))
2198 vty_out(vty
, " BGP graceful-restart debugging is on\n");
2200 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2201 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2203 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2205 " BGP route leak from vrf to vpn debugging is on\n");
2206 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2208 " BGP route leak to vrf from vpn debugging is on\n");
2209 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2210 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2211 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2212 vty_out(vty
, " BGP vpn label event debugging is on\n");
2213 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2214 vty_out(vty
, " BGP flowspec debugging is on\n");
2215 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2216 vty_out(vty
, " BGP labelpool debugging is on\n");
2218 if (BGP_DEBUG(pbr
, PBR
))
2219 vty_out(vty
, " BGP policy based routing debugging is on\n");
2220 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2221 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2223 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2224 vty_out(vty
, " BGP EVPN-MH ES debugging is on\n");
2225 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
2226 vty_out(vty
, " BGP EVPN-MH route debugging is on\n");
2232 static int bgp_config_write_debug(struct vty
*vty
)
2236 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2237 vty_out(vty
, "debug bgp as4\n");
2241 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2242 vty_out(vty
, "debug bgp as4 segment\n");
2246 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2247 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2248 bgp_debug_bestpath_prefixes
);
2251 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2252 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2253 bgp_debug_keepalive_peers
);
2256 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2257 write
+= bgp_debug_list_conf_print(
2258 vty
, "debug bgp neighbor-events",
2259 bgp_debug_neighbor_events_peers
);
2262 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2263 vty_out(vty
, "debug bgp nht\n");
2267 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2268 vty_out(vty
, "debug bgp update-groups\n");
2272 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2273 write
+= bgp_debug_list_conf_print(vty
,
2274 "debug bgp updates prefix",
2275 bgp_debug_update_prefixes
);
2278 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2279 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2280 bgp_debug_update_in_peers
);
2283 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2284 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2285 bgp_debug_update_out_peers
);
2288 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2289 if (!bgp_debug_zebra_prefixes
2290 || list_isempty(bgp_debug_zebra_prefixes
)) {
2291 vty_out(vty
, "debug bgp zebra\n");
2294 write
+= bgp_debug_list_conf_print(
2295 vty
, "debug bgp zebra prefix",
2296 bgp_debug_zebra_prefixes
);
2300 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2301 vty_out(vty
, "debug bgp allow-martians\n");
2305 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2306 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2309 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2310 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2313 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2314 vty_out(vty
, "debug bgp vpn rmap-event\n");
2317 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2318 vty_out(vty
, "debug bgp vpn label\n");
2321 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2322 vty_out(vty
, "debug bgp flowspec\n");
2325 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2326 vty_out(vty
, "debug bgp labelpool\n");
2330 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2331 vty_out(vty
, "debug bgp pbr\n");
2334 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2335 vty_out(vty
, "debug bgp pbr error\n");
2339 if (CONF_BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
)) {
2340 vty_out(vty
, "debug bgp graceful-restart\n");
2344 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_ES
)) {
2345 vty_out(vty
, "debug bgp evpn mh es\n");
2348 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
2349 vty_out(vty
, "debug bgp evpn mh route\n");
2356 static int bgp_config_write_debug(struct vty
*vty
);
2357 static struct cmd_node debug_node
= {
2361 .config_write
= bgp_config_write_debug
,
2364 void bgp_debug_init(void)
2366 install_node(&debug_node
);
2368 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2370 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2371 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2372 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2373 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2375 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2376 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2377 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2378 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2379 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2380 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2381 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2382 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2383 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2384 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2385 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2386 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2387 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2388 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2389 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2390 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2392 install_element(ENABLE_NODE
, &debug_bgp_graceful_restart_cmd
);
2393 install_element(CONFIG_NODE
, &debug_bgp_graceful_restart_cmd
);
2395 /* debug bgp updates (in|out) */
2396 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2397 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2398 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2399 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2401 /* debug bgp updates (in|out) A.B.C.D */
2402 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2403 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2404 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2405 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2407 /* debug bgp updates prefix A.B.C.D/M */
2408 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2409 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2410 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2411 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2412 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2413 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2414 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2415 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2417 /* debug bgp zebra prefix A.B.C.D/M */
2418 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2419 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2420 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2421 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2423 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2424 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2425 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2426 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2428 /* debug bgp neighbor-events A.B.C.D */
2429 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2430 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2431 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2432 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2434 /* debug bgp keepalive A.B.C.D */
2435 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2436 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2437 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2438 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2440 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2441 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2442 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2443 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2444 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2445 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2446 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2447 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2448 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2449 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2450 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2451 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2452 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2453 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2454 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2455 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2456 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2457 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2458 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2460 install_element(ENABLE_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2461 install_element(CONFIG_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2463 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2464 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2465 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2466 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2468 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2469 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2470 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2471 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2474 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2475 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2476 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2477 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2479 install_element(ENABLE_NODE
, &debug_bgp_evpn_mh_cmd
);
2480 install_element(CONFIG_NODE
, &debug_bgp_evpn_mh_cmd
);
2483 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2484 * for BGP_DEBUG_TYPE
2486 static int bgp_debug_per_prefix(const struct prefix
*p
,
2487 unsigned long term_bgp_debug_type
,
2488 unsigned int BGP_DEBUG_TYPE
,
2489 struct list
*per_prefix_list
)
2491 struct bgp_debug_filter
*filter
;
2492 struct listnode
*node
, *nnode
;
2494 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2495 /* We are debugging all prefixes so return true */
2496 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2503 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2505 if (filter
->p
->prefixlen
== p
->prefixlen
2506 && prefix_match(filter
->p
, p
))
2516 /* Return true if this peer is on the per_peer_list of peers to debug
2517 * for BGP_DEBUG_TYPE
2519 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2520 unsigned int BGP_DEBUG_TYPE
,
2521 struct list
*per_peer_list
)
2523 struct bgp_debug_filter
*filter
;
2524 struct listnode
*node
, *nnode
;
2526 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2527 /* We are debugging all peers so return true */
2528 if (!per_peer_list
|| list_isempty(per_peer_list
))
2535 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2537 if (strcmp(filter
->host
, host
) == 0)
2547 int bgp_debug_neighbor_events(struct peer
*peer
)
2554 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2555 BGP_DEBUG_NEIGHBOR_EVENTS
,
2556 bgp_debug_neighbor_events_peers
);
2559 int bgp_debug_keepalive(struct peer
*peer
)
2566 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2567 BGP_DEBUG_KEEPALIVE
,
2568 bgp_debug_keepalive_peers
);
2571 bool bgp_debug_update(struct peer
*peer
, const struct prefix
*p
,
2572 struct update_group
*updgrp
, unsigned int inbound
)
2580 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2581 BGP_DEBUG_UPDATE_IN
,
2582 bgp_debug_update_in_peers
))
2588 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2589 BGP_DEBUG_UPDATE_OUT
,
2590 bgp_debug_update_out_peers
))
2593 /* Check if update debugging implicitly enabled for the group.
2595 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2600 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2601 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2602 BGP_DEBUG_UPDATE_PREFIX
,
2603 bgp_debug_update_prefixes
))
2610 bool bgp_debug_bestpath(struct bgp_dest
*dest
)
2612 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2613 if (bgp_debug_per_prefix(
2614 bgp_dest_get_prefix(dest
), term_bgp_debug_bestpath
,
2615 BGP_DEBUG_BESTPATH
, bgp_debug_bestpath_prefixes
))
2622 bool bgp_debug_zebra(const struct prefix
*p
)
2624 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2625 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2627 bgp_debug_zebra_prefixes
))
2634 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2635 const struct prefix_rd
*prd
,
2636 union prefixconstptr pu
,
2637 mpls_label_t
*label
, uint32_t num_labels
,
2638 int addpath_valid
, uint32_t addpath_id
,
2639 char *str
, int size
)
2641 char rd_buf
[RD_ADDRSTRLEN
];
2643 /* ' with addpath ID ' 17
2644 * max strlen of uint32 + 10
2645 * +/- (just in case) + 1
2646 * null terminator + 1
2647 * ============================ 29 */
2648 char pathid_buf
[30];
2650 if (size
< BGP_PRD_PATH_STRLEN
)
2653 /* Note: Path-id is created by default, but only included in update
2655 pathid_buf
[0] = '\0';
2657 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2661 if (bgp_labeled_safi(safi
) && num_labels
) {
2663 if (safi
== SAFI_EVPN
) {
2666 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2667 snprintf(tag_buf
, sizeof(tag_buf
), " label %s",
2670 uint32_t label_value
;
2672 label_value
= decode_label(label
);
2673 snprintf(tag_buf
, sizeof(tag_buf
), " label %u",
2679 snprintfrr(str
, size
, "RD %s %pFX%s%s %s %s",
2680 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)), pu
.p
,
2681 tag_buf
, pathid_buf
, afi2str(afi
), safi2str(safi
));
2682 else if (safi
== SAFI_FLOWSPEC
) {
2683 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2684 const struct prefix_fs
*fs
= pu
.fs
;
2686 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2687 fs
->prefix
.prefixlen
,
2689 NLRI_STRING_FORMAT_DEBUG
, NULL
,
2690 family2afi(fs
->prefix
.family
));
2691 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2694 snprintfrr(str
, size
, "%pFX%s%s %s %s", pu
.p
, tag_buf
,
2695 pathid_buf
, afi2str(afi
), safi2str(safi
));