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>
25 #include "lib/printfrr.h"
31 #include "sockunion.h"
36 #include "bgpd/bgpd.h"
37 #include "bgpd/bgp_aspath.h"
38 #include "bgpd/bgp_route.h"
39 #include "bgpd/bgp_attr.h"
40 #include "bgpd/bgp_debug.h"
41 #include "bgpd/bgp_community.h"
42 #include "bgpd/bgp_lcommunity.h"
43 #include "bgpd/bgp_updgrp.h"
44 #include "bgpd/bgp_mplsvpn.h"
45 #include "bgpd/bgp_ecommunity.h"
46 #include "bgpd/bgp_label.h"
47 #include "bgpd/bgp_evpn.h"
48 #include "bgpd/bgp_evpn_private.h"
49 #include "bgpd/bgp_evpn_vty.h"
50 #include "bgpd/bgp_vty.h"
51 #include "bgpd/bgp_flowspec.h"
53 unsigned long conf_bgp_debug_as4
;
54 unsigned long conf_bgp_debug_neighbor_events
;
55 unsigned long conf_bgp_debug_events
;
56 unsigned long conf_bgp_debug_packet
;
57 unsigned long conf_bgp_debug_filter
;
58 unsigned long conf_bgp_debug_keepalive
;
59 unsigned long conf_bgp_debug_update
;
60 unsigned long conf_bgp_debug_bestpath
;
61 unsigned long conf_bgp_debug_zebra
;
62 unsigned long conf_bgp_debug_allow_martians
;
63 unsigned long conf_bgp_debug_nht
;
64 unsigned long conf_bgp_debug_update_groups
;
65 unsigned long conf_bgp_debug_vpn
;
66 unsigned long conf_bgp_debug_flowspec
;
67 unsigned long conf_bgp_debug_labelpool
;
68 unsigned long conf_bgp_debug_pbr
;
69 unsigned long conf_bgp_debug_graceful_restart
;
70 unsigned long conf_bgp_debug_evpn_mh
;
71 unsigned long conf_bgp_debug_bfd
;
73 unsigned long term_bgp_debug_as4
;
74 unsigned long term_bgp_debug_neighbor_events
;
75 unsigned long term_bgp_debug_events
;
76 unsigned long term_bgp_debug_packet
;
77 unsigned long term_bgp_debug_filter
;
78 unsigned long term_bgp_debug_keepalive
;
79 unsigned long term_bgp_debug_update
;
80 unsigned long term_bgp_debug_bestpath
;
81 unsigned long term_bgp_debug_zebra
;
82 unsigned long term_bgp_debug_allow_martians
;
83 unsigned long term_bgp_debug_nht
;
84 unsigned long term_bgp_debug_update_groups
;
85 unsigned long term_bgp_debug_vpn
;
86 unsigned long term_bgp_debug_flowspec
;
87 unsigned long term_bgp_debug_labelpool
;
88 unsigned long term_bgp_debug_pbr
;
89 unsigned long term_bgp_debug_graceful_restart
;
90 unsigned long term_bgp_debug_evpn_mh
;
91 unsigned long term_bgp_debug_bfd
;
93 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
94 struct list
*bgp_debug_keepalive_peers
= NULL
;
95 struct list
*bgp_debug_update_out_peers
= NULL
;
96 struct list
*bgp_debug_update_in_peers
= NULL
;
97 struct list
*bgp_debug_update_prefixes
= NULL
;
98 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
99 struct list
*bgp_debug_zebra_prefixes
= NULL
;
101 /* messages for BGP-4 status */
102 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
103 {Connect
, "Connect"},
105 {OpenSent
, "OpenSent"},
106 {OpenConfirm
, "OpenConfirm"},
107 {Established
, "Established"},
108 {Clearing
, "Clearing"},
109 {Deleted
, "Deleted"},
112 /* BGP message type string. */
113 const char *const bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
114 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
117 /* message for BGP-4 Notify */
118 static const struct message bgp_notify_msg
[] = {
119 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
120 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
121 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
122 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
123 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
124 {BGP_NOTIFY_CEASE
, "Cease"},
125 {BGP_NOTIFY_ROUTE_REFRESH_ERR
, "ROUTE-REFRESH Message Error"},
128 static const struct message bgp_notify_head_msg
[] = {
129 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
130 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
131 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
134 static const struct message bgp_notify_open_msg
[] = {
135 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
136 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
137 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
138 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
139 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
140 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
141 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
142 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
145 static const struct message bgp_notify_update_msg
[] = {
146 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
147 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
148 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
149 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
150 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
151 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
152 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
153 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
154 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
155 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
156 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
157 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
160 static const struct message bgp_notify_cease_msg
[] = {
161 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
162 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
163 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
164 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
165 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
166 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
167 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
168 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
169 "/Connection collision resolution"},
170 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
173 static const struct message bgp_notify_route_refresh_msg
[] = {
174 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
175 {BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN
, "/Invalid Message Length"},
178 static const struct message bgp_notify_fsm_msg
[] = {
179 {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC
, "/Unspecific"},
180 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT
,
181 "/Receive Unexpected Message in OpenSent State"},
182 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM
,
183 "/Receive Unexpected Message in OpenConfirm State"},
184 {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED
,
185 "/Receive Unexpected Message in Established State"},
188 /* Origin strings. */
189 const char *const bgp_origin_str
[] = {"i", "e", "?"};
190 const char *const bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
192 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
194 /* Given a string return a pointer the corresponding peer structure */
195 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
197 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
205 ret
= str2sockunion(peer_str
, &su
);
209 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
212 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
216 return peer_lookup(bgp
, &su
);
219 static void bgp_debug_list_free(struct list
*list
)
221 struct bgp_debug_filter
*filter
;
222 struct listnode
*node
, *nnode
;
225 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
226 listnode_delete(list
, filter
);
227 prefix_free(&filter
->p
);
228 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
229 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
234 * Print the desc along with a list of peers/prefixes this debug is
237 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
240 struct bgp_debug_filter
*filter
;
241 struct listnode
*node
, *nnode
;
243 vty_out(vty
, "%s", desc
);
245 if (list
&& !list_isempty(list
)) {
246 vty_out(vty
, " for");
247 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
249 vty_out(vty
, " %s", filter
->host
);
251 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
252 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
254 vty_out(vty
, " %pFX", filter
->p
);
262 * Print the command to enable the debug for each peer/prefix this debug is
265 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
268 struct bgp_debug_filter
*filter
;
269 struct listnode
*node
, *nnode
;
272 if (list
&& !list_isempty(list
)) {
273 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
275 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
279 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
280 bgp_debug_print_evpn_prefix(vty
, desc
,
283 } else if (filter
->p
) {
284 vty_out(vty
, "%s %pFX\n", desc
, filter
->p
);
291 vty_out(vty
, "%s\n", desc
);
298 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
299 const struct prefix
*p
)
301 struct bgp_debug_filter
*filter
;
303 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
304 sizeof(struct bgp_debug_filter
));
307 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
311 filter
->p
= prefix_new();
312 prefix_copy(filter
->p
, p
);
315 listnode_add(list
, filter
);
318 static bool bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
321 struct bgp_debug_filter
*filter
;
322 struct listnode
*node
, *nnode
;
324 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
325 if (host
&& strcmp(filter
->host
, host
) == 0) {
326 listnode_delete(list
, filter
);
327 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
328 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
330 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
331 && prefix_match(filter
->p
, p
)) {
332 listnode_delete(list
, filter
);
333 prefix_free(&filter
->p
);
334 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
342 static bool bgp_debug_list_has_entry(struct list
*list
, const char *host
,
343 const struct prefix
*p
)
345 struct bgp_debug_filter
*filter
;
346 struct listnode
*node
, *nnode
;
348 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
350 if (strcmp(filter
->host
, host
) == 0) {
354 if (filter
->p
->prefixlen
== p
->prefixlen
355 && prefix_match(filter
->p
, p
)) {
364 bool bgp_debug_peer_updout_enabled(char *host
)
366 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
370 /* Dump attribute. */
371 bool bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
373 char addrbuf
[BUFSIZ
];
380 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
381 snprintfrr(buf
, size
, "nexthop %pI4", &attr
->nexthop
);
383 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
384 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
385 bgp_origin_str
[attr
->origin
]);
388 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
389 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
390 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
392 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
395 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
396 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
397 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
400 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
401 snprintfrr(buf
, size
, "nexthop %pI4", &attr
->nexthop
);
403 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
404 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
405 ", localpref %u", attr
->local_pref
);
407 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
408 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
411 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
412 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
414 community_str(attr
->community
, false));
416 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
)))
417 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
418 ", large-community %s",
419 lcommunity_str(attr
->lcommunity
, false));
421 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
422 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
423 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
425 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
426 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
427 ", atomic-aggregate");
429 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
430 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
431 ", aggregated by %u %pI4", attr
->aggregator_as
,
432 &attr
->aggregator_addr
);
434 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
435 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
436 ", originator %pI4", &attr
->originator_id
);
438 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
439 struct cluster_list
*cluster
;
442 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
445 cluster
= bgp_attr_get_cluster(attr
);
446 for (i
= 0; i
< cluster
->length
/ 4; i
++)
447 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
448 " %pI4", &cluster
->list
[i
]);
451 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
452 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
453 ", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr
));
455 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
456 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
457 aspath_print(attr
->aspath
));
459 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
460 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
461 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
462 ", label-index %u", attr
->label_index
);
471 const char *bgp_notify_code_str(char code
)
473 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
476 const char *bgp_notify_subcode_str(char code
, char subcode
)
480 case BGP_NOTIFY_HEADER_ERR
:
481 return lookup_msg(bgp_notify_head_msg
, subcode
,
482 "Unrecognized Error Subcode");
483 case BGP_NOTIFY_OPEN_ERR
:
484 return lookup_msg(bgp_notify_open_msg
, subcode
,
485 "Unrecognized Error Subcode");
486 case BGP_NOTIFY_UPDATE_ERR
:
487 return lookup_msg(bgp_notify_update_msg
, subcode
,
488 "Unrecognized Error Subcode");
489 case BGP_NOTIFY_HOLD_ERR
:
491 case BGP_NOTIFY_FSM_ERR
:
492 return lookup_msg(bgp_notify_fsm_msg
, subcode
,
493 "Unrecognized Error Subcode");
494 case BGP_NOTIFY_CEASE
:
495 return lookup_msg(bgp_notify_cease_msg
, subcode
,
496 "Unrecognized Error Subcode");
497 case BGP_NOTIFY_ROUTE_REFRESH_ERR
:
498 return lookup_msg(bgp_notify_route_refresh_msg
, subcode
,
499 "Unrecognized Error Subcode");
504 /* extract notify admin reason if correctly present */
505 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
508 if (!data
|| datalen
< 1)
511 uint8_t len
= data
[0];
512 if (len
> 128 || len
> datalen
- 1)
515 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
518 /* dump notify packet */
519 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
522 const char *subcode_str
;
523 const char *code_str
;
524 const char *msg_str
= NULL
;
527 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
528 || CHECK_FLAG(peer
->bgp
->flags
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
529 code_str
= bgp_notify_code_str(bgp_notify
->code
);
530 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
531 bgp_notify
->subcode
);
533 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
534 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
535 || bgp_notify
->subcode
536 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
537 msg_str
= bgp_notify_admin_message(
538 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
544 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
545 strcmp(direct
, "received") == 0
548 peer
->host
, bgp_notify
->code
,
549 bgp_notify
->subcode
, code_str
, subcode_str
,
552 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
554 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
555 strcmp(direct
, "received") == 0
558 peer
->host
, bgp_notify
->code
,
559 bgp_notify
->subcode
, code_str
, subcode_str
,
560 bgp_notify
->length
, msg_str
);
565 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
568 bgp
= bgp_get_default();
569 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
572 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
575 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
576 char buf
[PREFIX2STR_BUFFER
];
577 char buf2
[ETHER_ADDR_STRLEN
];
579 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
580 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
582 evpn_desc
, sizeof(evpn_desc
),
583 "l2vpn evpn type macip mac %s",
584 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
585 buf2
, sizeof(buf2
)));
587 uint8_t family
= is_evpn_prefix_ipaddr_v4(
588 (struct prefix_evpn
*)p
) ?
591 evpn_desc
, sizeof(evpn_desc
),
592 "l2vpn evpn type macip mac %s ip %s",
593 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
597 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
598 buf
, PREFIX2STR_BUFFER
));
600 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
601 snprintfrr(evpn_desc
, sizeof(evpn_desc
),
602 "l2vpn evpn type multicast ip %pI4",
603 &p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
);
604 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
605 uint8_t family
= is_evpn_prefix_ipaddr_v4(
606 (struct prefix_evpn
*)p
) ? AF_INET
608 snprintf(evpn_desc
, sizeof(evpn_desc
),
609 "l2vpn evpn type prefix ip %s/%d",
611 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
,
612 buf
, PREFIX2STR_BUFFER
),
613 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
616 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
619 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
620 int argc
, struct prefix
**argv_pp
)
622 struct prefix
*argv_p
;
631 if (bgp_evpn_cli_parse_type(&evpn_type
, argv
, argc
) < 0)
634 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
635 memset(&ip
, 0, sizeof(struct ipaddr
));
637 argv_find(argv
, argc
, "mac", &mac_idx
);
638 (void)prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
);
640 argv_find(argv
, argc
, "ip", &ip_idx
);
641 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
643 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
645 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
646 memset(&ip
, 0, sizeof(struct ipaddr
));
648 argv_find(argv
, argc
, "ip", &ip_idx
);
649 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
651 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
653 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
654 struct prefix ip_prefix
;
656 memset(&ip_prefix
, 0, sizeof(struct prefix
));
657 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
658 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
659 apply_mask(&ip_prefix
);
661 build_type5_prefix_from_ip_prefix(
662 (struct prefix_evpn
*)argv_p
,
669 /* Debug option setting interface. */
670 unsigned long bgp_debug_option
= 0;
672 int debug(unsigned int option
)
674 return bgp_debug_option
& option
;
677 DEFUN (debug_bgp_as4
,
684 if (vty
->node
== CONFIG_NODE
)
687 TERM_DEBUG_ON(as4
, AS4
);
688 vty_out(vty
, "BGP as4 debugging is on\n");
693 DEFUN (no_debug_bgp_as4
,
694 no_debug_bgp_as4_cmd
,
701 if (vty
->node
== CONFIG_NODE
)
704 TERM_DEBUG_OFF(as4
, AS4
);
705 vty_out(vty
, "BGP as4 debugging is off\n");
710 DEFUN (debug_bgp_as4_segment
,
711 debug_bgp_as4_segment_cmd
,
712 "debug bgp as4 segment",
716 "BGP AS4 aspath segment handling\n")
718 if (vty
->node
== CONFIG_NODE
)
719 DEBUG_ON(as4
, AS4_SEGMENT
);
721 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
722 vty_out(vty
, "BGP as4 segment debugging is on\n");
727 DEFUN (no_debug_bgp_as4_segment
,
728 no_debug_bgp_as4_segment_cmd
,
729 "no debug bgp as4 segment",
734 "BGP AS4 aspath segment handling\n")
736 if (vty
->node
== CONFIG_NODE
)
737 DEBUG_OFF(as4
, AS4_SEGMENT
);
739 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
740 vty_out(vty
, "BGP as4 segment debugging is off\n");
745 /* debug bgp neighbor_events */
746 DEFUN (debug_bgp_neighbor_events
,
747 debug_bgp_neighbor_events_cmd
,
748 "debug bgp neighbor-events",
751 "BGP Neighbor Events\n")
753 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
755 if (vty
->node
== CONFIG_NODE
)
756 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
758 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
759 vty_out(vty
, "BGP neighbor-events debugging is on\n");
764 DEFUN (debug_bgp_neighbor_events_peer
,
765 debug_bgp_neighbor_events_peer_cmd
,
766 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
769 "BGP Neighbor Events\n"
770 "BGP neighbor IP address to debug\n"
771 "BGP IPv6 neighbor to debug\n"
772 "BGP neighbor on interface to debug\n")
775 const char *host
= argv
[idx_peer
]->arg
;
777 if (!bgp_debug_neighbor_events_peers
)
778 bgp_debug_neighbor_events_peers
= list_new();
780 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
783 "BGP neighbor-events debugging is already enabled for %s\n",
788 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
790 if (vty
->node
== CONFIG_NODE
)
791 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
793 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
794 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
800 DEFUN (no_debug_bgp_neighbor_events
,
801 no_debug_bgp_neighbor_events_cmd
,
802 "no debug bgp neighbor-events",
808 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
810 if (vty
->node
== CONFIG_NODE
)
811 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
813 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
814 vty_out(vty
, "BGP neighbor-events debugging is off\n");
819 DEFUN (no_debug_bgp_neighbor_events_peer
,
820 no_debug_bgp_neighbor_events_peer_cmd
,
821 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
826 "BGP neighbor IP address to debug\n"
827 "BGP IPv6 neighbor to debug\n"
828 "BGP neighbor on interface to debug\n")
832 const char *host
= argv
[idx_peer
]->arg
;
834 if (bgp_debug_neighbor_events_peers
835 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
836 found_peer
= bgp_debug_list_remove_entry(
837 bgp_debug_neighbor_events_peers
, host
, NULL
);
839 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
840 if (vty
->node
== CONFIG_NODE
)
841 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
843 TERM_DEBUG_OFF(neighbor_events
,
849 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
853 "BGP neighbor-events debugging was not enabled for %s\n",
860 DEFUN (debug_bgp_nht
,
865 "BGP nexthop tracking events\n")
867 if (vty
->node
== CONFIG_NODE
)
870 TERM_DEBUG_ON(nht
, NHT
);
871 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
876 DEFUN (no_debug_bgp_nht
,
877 no_debug_bgp_nht_cmd
,
882 "BGP nexthop tracking events\n")
884 if (vty
->node
== CONFIG_NODE
)
887 TERM_DEBUG_OFF(nht
, NHT
);
888 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
893 /* debug bgp keepalives */
894 DEFUN (debug_bgp_keepalive
,
895 debug_bgp_keepalive_cmd
,
896 "debug bgp keepalives",
901 bgp_debug_list_free(bgp_debug_keepalive_peers
);
903 if (vty
->node
== CONFIG_NODE
)
904 DEBUG_ON(keepalive
, KEEPALIVE
);
906 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
907 vty_out(vty
, "BGP keepalives debugging is on\n");
912 DEFUN (debug_bgp_keepalive_peer
,
913 debug_bgp_keepalive_peer_cmd
,
914 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
918 "BGP IPv4 neighbor to debug\n"
919 "BGP IPv6 neighbor to debug\n"
920 "BGP neighbor on interface to debug\n")
923 const char *host
= argv
[idx_peer
]->arg
;
925 if (!bgp_debug_keepalive_peers
)
926 bgp_debug_keepalive_peers
= list_new();
928 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
930 "BGP keepalive debugging is already enabled for %s\n",
935 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
937 if (vty
->node
== CONFIG_NODE
)
938 DEBUG_ON(keepalive
, KEEPALIVE
);
940 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
941 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
946 DEFUN (no_debug_bgp_keepalive
,
947 no_debug_bgp_keepalive_cmd
,
948 "no debug bgp keepalives",
954 bgp_debug_list_free(bgp_debug_keepalive_peers
);
956 if (vty
->node
== CONFIG_NODE
)
957 DEBUG_OFF(keepalive
, KEEPALIVE
);
959 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
960 vty_out(vty
, "BGP keepalives debugging is off\n");
965 DEFUN (no_debug_bgp_keepalive_peer
,
966 no_debug_bgp_keepalive_peer_cmd
,
967 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
972 "BGP neighbor IP address to debug\n"
973 "BGP IPv6 neighbor to debug\n"
974 "BGP neighbor on interface to debug\n")
978 const char *host
= argv
[idx_peer
]->arg
;
980 if (bgp_debug_keepalive_peers
981 && !list_isempty(bgp_debug_keepalive_peers
)) {
982 found_peer
= bgp_debug_list_remove_entry(
983 bgp_debug_keepalive_peers
, host
, NULL
);
985 if (list_isempty(bgp_debug_keepalive_peers
)) {
986 if (vty
->node
== CONFIG_NODE
)
987 DEBUG_OFF(keepalive
, KEEPALIVE
);
989 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
994 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
997 "BGP keepalives debugging was not enabled for %s\n",
1003 /* debug bgp bestpath */
1004 DEFUN (debug_bgp_bestpath_prefix
,
1005 debug_bgp_bestpath_prefix_cmd
,
1006 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1013 struct prefix
*argv_p
;
1014 int idx_ipv4_ipv6_prefixlen
= 3;
1016 argv_p
= prefix_new();
1017 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1020 if (!bgp_debug_bestpath_prefixes
)
1021 bgp_debug_bestpath_prefixes
= list_new();
1023 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1026 "BGP bestpath debugging is already enabled for %s\n",
1027 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1031 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1033 if (vty
->node
== CONFIG_NODE
) {
1034 DEBUG_ON(bestpath
, BESTPATH
);
1036 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1037 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1038 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1044 DEFUN (no_debug_bgp_bestpath_prefix
,
1045 no_debug_bgp_bestpath_prefix_cmd
,
1046 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1054 int idx_ipv4_ipv6_prefixlen
= 4;
1055 struct prefix
*argv_p
;
1056 int found_prefix
= 0;
1058 argv_p
= prefix_new();
1059 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1062 if (bgp_debug_bestpath_prefixes
1063 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1064 found_prefix
= bgp_debug_list_remove_entry(
1065 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1067 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1068 if (vty
->node
== CONFIG_NODE
) {
1069 DEBUG_OFF(bestpath
, BESTPATH
);
1071 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1073 "BGP bestpath debugging (per prefix) is off\n");
1079 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1080 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1082 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1083 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1088 DEFUN (no_debug_bgp_bestpath
,
1089 no_debug_bgp_bestpath_cmd
,
1090 "no debug bgp bestpath",
1096 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1098 if (vty
->node
== CONFIG_NODE
)
1099 DEBUG_OFF(bestpath
, BESTPATH
);
1101 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1102 vty_out(vty
, "BGP bestpath debugging is off\n");
1107 /* debug bgp updates */
1108 DEFUN (debug_bgp_update
,
1109 debug_bgp_update_cmd
,
1110 "debug bgp updates",
1115 bgp_debug_list_free(bgp_debug_update_in_peers
);
1116 bgp_debug_list_free(bgp_debug_update_out_peers
);
1117 bgp_debug_list_free(bgp_debug_update_prefixes
);
1119 if (vty
->node
== CONFIG_NODE
) {
1120 DEBUG_ON(update
, UPDATE_IN
);
1121 DEBUG_ON(update
, UPDATE_OUT
);
1123 TERM_DEBUG_ON(update
, UPDATE_IN
);
1124 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1125 vty_out(vty
, "BGP updates debugging is on\n");
1130 DEFUN (debug_bgp_update_direct
,
1131 debug_bgp_update_direct_cmd
,
1132 "debug bgp updates <in|out>",
1137 "Outbound updates\n")
1141 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1142 bgp_debug_list_free(bgp_debug_update_in_peers
);
1144 bgp_debug_list_free(bgp_debug_update_out_peers
);
1146 if (vty
->node
== CONFIG_NODE
) {
1147 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1148 DEBUG_ON(update
, UPDATE_IN
);
1150 DEBUG_ON(update
, UPDATE_OUT
);
1152 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1153 TERM_DEBUG_ON(update
, UPDATE_IN
);
1154 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1156 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1158 "BGP updates debugging is on (outbound)\n");
1164 DEFUN (debug_bgp_update_direct_peer
,
1165 debug_bgp_update_direct_peer_cmd
,
1166 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1171 "Outbound updates\n"
1172 "BGP neighbor IP address to debug\n"
1173 "BGP IPv6 neighbor to debug\n"
1174 "BGP neighbor on interface to debug\n")
1178 const char *host
= argv
[idx_peer
]->arg
;
1181 if (!bgp_debug_update_in_peers
)
1182 bgp_debug_update_in_peers
= list_new();
1184 if (!bgp_debug_update_out_peers
)
1185 bgp_debug_update_out_peers
= list_new();
1187 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1193 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1196 "BGP inbound update debugging is already enabled for %s\n",
1203 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1206 "BGP outbound update debugging is already enabled for %s\n",
1213 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1216 struct peer_af
*paf
;
1219 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1221 peer
= bgp_find_peer(vty
, host
);
1224 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1226 paf
= peer
->peer_af_array
[afidx
];
1228 if (PAF_SUBGRP(paf
)) {
1238 if (vty
->node
== CONFIG_NODE
) {
1240 DEBUG_ON(update
, UPDATE_IN
);
1242 DEBUG_ON(update
, UPDATE_OUT
);
1245 TERM_DEBUG_ON(update
, UPDATE_IN
);
1247 "BGP updates debugging is on (inbound) for %s\n",
1248 argv
[idx_peer
]->arg
);
1250 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1252 "BGP updates debugging is on (outbound) for %s\n",
1253 argv
[idx_peer
]->arg
);
1259 DEFUN (no_debug_bgp_update_direct
,
1260 no_debug_bgp_update_direct_cmd
,
1261 "no debug bgp updates <in|out>",
1267 "Outbound updates\n")
1270 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1271 bgp_debug_list_free(bgp_debug_update_in_peers
);
1273 if (vty
->node
== CONFIG_NODE
) {
1274 DEBUG_OFF(update
, UPDATE_IN
);
1276 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1278 "BGP updates debugging is off (inbound)\n");
1281 bgp_debug_list_free(bgp_debug_update_out_peers
);
1283 if (vty
->node
== CONFIG_NODE
) {
1284 DEBUG_OFF(update
, UPDATE_OUT
);
1286 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1288 "BGP updates debugging is off (outbound)\n");
1295 DEFUN (no_debug_bgp_update_direct_peer
,
1296 no_debug_bgp_update_direct_peer_cmd
,
1297 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1303 "Outbound updates\n"
1304 "BGP neighbor IP address to debug\n"
1305 "BGP IPv6 neighbor to debug\n"
1306 "BGP neighbor on interface to debug\n")
1312 const char *host
= argv
[idx_peer
]->arg
;
1314 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1319 if (inbound
&& bgp_debug_update_in_peers
1320 && !list_isempty(bgp_debug_update_in_peers
)) {
1321 found_peer
= bgp_debug_list_remove_entry(
1322 bgp_debug_update_in_peers
, host
, NULL
);
1324 if (list_isempty(bgp_debug_update_in_peers
)) {
1325 if (vty
->node
== CONFIG_NODE
)
1326 DEBUG_OFF(update
, UPDATE_IN
);
1328 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1330 "BGP updates debugging (inbound) is off\n");
1335 if (!inbound
&& bgp_debug_update_out_peers
1336 && !list_isempty(bgp_debug_update_out_peers
)) {
1337 found_peer
= bgp_debug_list_remove_entry(
1338 bgp_debug_update_out_peers
, host
, NULL
);
1340 if (list_isempty(bgp_debug_update_out_peers
)) {
1341 if (vty
->node
== CONFIG_NODE
)
1342 DEBUG_OFF(update
, UPDATE_OUT
);
1344 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1346 "BGP updates debugging (outbound) is off\n");
1351 struct peer_af
*paf
;
1353 peer
= bgp_find_peer(vty
, host
);
1356 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1358 paf
= peer
->peer_af_array
[afidx
];
1360 if (PAF_SUBGRP(paf
)) {
1361 UPDGRP_PEER_DBG_DIS(
1373 "BGP updates debugging (inbound) is off for %s\n",
1377 "BGP updates debugging (outbound) is off for %s\n",
1381 "BGP updates debugging (inbound) was not enabled for %s\n",
1385 "BGP updates debugging (outbound) was not enabled for %s\n",
1391 #ifndef VTYSH_EXTRACT_PL
1392 #include "bgpd/bgp_debug_clippy.c"
1395 DEFPY (debug_bgp_update_prefix_afi_safi
,
1396 debug_bgp_update_prefix_afi_safi_cmd
,
1397 "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>>",
1401 "Specify a prefix to debug\n"
1405 EVPN_TYPE_2_HELP_STR
1406 EVPN_TYPE_2_HELP_STR
1407 MAC_STR MAC_STR MAC_STR
1411 EVPN_TYPE_3_HELP_STR
1412 EVPN_TYPE_3_HELP_STR
1416 EVPN_TYPE_5_HELP_STR
1417 EVPN_TYPE_5_HELP_STR
1422 struct prefix
*argv_p
;
1423 int ret
= CMD_SUCCESS
;
1425 argv_p
= prefix_new();
1427 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1428 if (ret
!= CMD_SUCCESS
) {
1429 prefix_free(&argv_p
);
1433 if (!bgp_debug_update_prefixes
)
1434 bgp_debug_update_prefixes
= list_new();
1436 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1438 "BGP updates debugging is already enabled for %pFX\n",
1440 prefix_free(&argv_p
);
1444 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1446 if (vty
->node
== CONFIG_NODE
) {
1447 DEBUG_ON(update
, UPDATE_PREFIX
);
1449 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1450 vty_out(vty
, "BGP updates debugging is on for %pFX\n", argv_p
);
1453 prefix_free(&argv_p
);
1458 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1459 no_debug_bgp_update_prefix_afi_safi_cmd
,
1460 "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>>",
1465 "Specify a prefix to debug\n"
1469 EVPN_TYPE_2_HELP_STR
1470 EVPN_TYPE_2_HELP_STR
1471 MAC_STR MAC_STR MAC_STR
1475 EVPN_TYPE_3_HELP_STR
1476 EVPN_TYPE_3_HELP_STR
1480 EVPN_TYPE_5_HELP_STR
1481 EVPN_TYPE_5_HELP_STR
1486 struct prefix
*argv_p
;
1487 bool found_prefix
= false;
1488 int ret
= CMD_SUCCESS
;
1490 argv_p
= prefix_new();
1492 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1493 if (ret
!= CMD_SUCCESS
) {
1494 prefix_free(&argv_p
);
1498 if (bgp_debug_update_prefixes
1499 && !list_isempty(bgp_debug_update_prefixes
)) {
1500 found_prefix
= bgp_debug_list_remove_entry(
1501 bgp_debug_update_prefixes
, NULL
, argv_p
);
1503 if (list_isempty(bgp_debug_update_prefixes
)) {
1504 if (vty
->node
== CONFIG_NODE
) {
1505 DEBUG_OFF(update
, UPDATE_PREFIX
);
1507 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1509 "BGP updates debugging (per prefix) is off\n");
1515 vty_out(vty
, "BGP updates debugging is off for %pFX\n", argv_p
);
1517 vty_out(vty
, "BGP updates debugging was not enabled for %pFX\n",
1520 prefix_free(&argv_p
);
1526 DEFUN (debug_bgp_update_prefix
,
1527 debug_bgp_update_prefix_cmd
,
1528 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1532 "Specify a prefix to debug\n"
1536 int idx_ipv4_ipv6_prefixlen
= 4;
1537 struct prefix
*argv_p
;
1539 argv_p
= prefix_new();
1540 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1543 if (!bgp_debug_update_prefixes
)
1544 bgp_debug_update_prefixes
= list_new();
1546 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1548 "BGP updates debugging is already enabled for %s\n",
1549 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1553 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1555 if (vty
->node
== CONFIG_NODE
) {
1556 DEBUG_ON(update
, UPDATE_PREFIX
);
1558 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1559 vty_out(vty
, "BGP updates debugging is on for %s\n",
1560 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1566 DEFUN (no_debug_bgp_update_prefix
,
1567 no_debug_bgp_update_prefix_cmd
,
1568 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1573 "Specify a prefix to debug\n"
1577 int idx_ipv4_ipv6_prefixlen
= 5;
1578 struct prefix
*argv_p
;
1579 int found_prefix
= 0;
1581 argv_p
= prefix_new();
1582 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1585 if (bgp_debug_update_prefixes
1586 && !list_isempty(bgp_debug_update_prefixes
)) {
1587 found_prefix
= bgp_debug_list_remove_entry(
1588 bgp_debug_update_prefixes
, NULL
, argv_p
);
1590 if (list_isempty(bgp_debug_update_prefixes
)) {
1591 if (vty
->node
== CONFIG_NODE
) {
1592 DEBUG_OFF(update
, UPDATE_PREFIX
);
1594 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1596 "BGP updates debugging (per prefix) is off\n");
1602 vty_out(vty
, "BGP updates debugging is off for %s\n",
1603 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1605 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1606 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1611 DEFUN (no_debug_bgp_update
,
1612 no_debug_bgp_update_cmd
,
1613 "no debug bgp updates",
1619 struct listnode
*ln
;
1622 bgp_debug_list_free(bgp_debug_update_in_peers
);
1623 bgp_debug_list_free(bgp_debug_update_out_peers
);
1624 bgp_debug_list_free(bgp_debug_update_prefixes
);
1626 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1627 bgp_debug_clear_updgrp_update_dbg(bgp
);
1629 if (vty
->node
== CONFIG_NODE
) {
1630 DEBUG_OFF(update
, UPDATE_IN
);
1631 DEBUG_OFF(update
, UPDATE_OUT
);
1632 DEBUG_OFF(update
, UPDATE_PREFIX
);
1634 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1635 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1636 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1637 vty_out(vty
, "BGP updates debugging is off\n");
1642 /* debug bgp zebra */
1643 DEFUN (debug_bgp_zebra
,
1644 debug_bgp_zebra_cmd
,
1648 "BGP Zebra messages\n")
1650 if (vty
->node
== CONFIG_NODE
)
1651 DEBUG_ON(zebra
, ZEBRA
);
1653 TERM_DEBUG_ON(zebra
, ZEBRA
);
1654 vty_out(vty
, "BGP zebra debugging is on\n");
1659 DEFUN (debug_bgp_graceful_restart
,
1660 debug_bgp_graceful_restart_cmd
,
1661 "debug bgp graceful-restart",
1666 if (vty
->node
== CONFIG_NODE
) {
1667 DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1669 TERM_DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1670 vty_out(vty
, "BGP Graceful Restart debugging is on\n");
1676 DEFUN (debug_bgp_zebra_prefix
,
1677 debug_bgp_zebra_prefix_cmd
,
1678 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1681 "BGP Zebra messages\n"
1682 "Specify a prefix to debug\n"
1686 int idx_ipv4_ipv6_prefixlen
= 4;
1687 struct prefix
*argv_p
;
1689 argv_p
= prefix_new();
1690 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1693 if (!bgp_debug_zebra_prefixes
)
1694 bgp_debug_zebra_prefixes
= list_new();
1696 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1697 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1698 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1702 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1704 if (vty
->node
== CONFIG_NODE
)
1705 DEBUG_ON(zebra
, ZEBRA
);
1707 TERM_DEBUG_ON(zebra
, ZEBRA
);
1708 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1709 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1715 DEFUN (no_debug_bgp_zebra
,
1716 no_debug_bgp_zebra_cmd
,
1717 "no debug bgp zebra",
1721 "BGP Zebra messages\n")
1723 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1725 if (vty
->node
== CONFIG_NODE
)
1726 DEBUG_OFF(zebra
, ZEBRA
);
1728 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1729 vty_out(vty
, "BGP zebra debugging is off\n");
1734 DEFUN (no_debug_bgp_graceful_restart
,
1735 no_debug_bgp_graceful_restart_cmd
,
1736 "no debug bgp graceful-restart",
1742 if (vty
->node
== CONFIG_NODE
) {
1743 DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1745 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1746 vty_out(vty
, "BGP Graceful Restart debugging is off\n");
1751 DEFUN (no_debug_bgp_zebra_prefix
,
1752 no_debug_bgp_zebra_prefix_cmd
,
1753 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1757 "BGP Zebra messages\n"
1758 "Specify a prefix to debug\n"
1762 int idx_ipv4_ipv6_prefixlen
= 5;
1763 struct prefix
*argv_p
;
1764 int found_prefix
= 0;
1766 argv_p
= prefix_new();
1767 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1770 if (bgp_debug_zebra_prefixes
1771 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1772 found_prefix
= bgp_debug_list_remove_entry(
1773 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1775 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1776 if (vty
->node
== CONFIG_NODE
)
1777 DEBUG_OFF(zebra
, ZEBRA
);
1779 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1780 vty_out(vty
, "BGP zebra debugging is off\n");
1786 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1787 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1789 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1790 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1795 DEFUN (debug_bgp_allow_martians
,
1796 debug_bgp_allow_martians_cmd
,
1797 "debug bgp allow-martians",
1800 "BGP allow martian next hops\n")
1802 if (vty
->node
== CONFIG_NODE
)
1803 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1805 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1806 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1811 DEFUN (no_debug_bgp_allow_martians
,
1812 no_debug_bgp_allow_martians_cmd
,
1813 "no debug bgp allow-martians",
1817 "BGP allow martian next hops\n")
1819 if (vty
->node
== CONFIG_NODE
)
1820 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1822 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1823 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1829 /* debug bgp update-groups */
1830 DEFUN (debug_bgp_update_groups
,
1831 debug_bgp_update_groups_cmd
,
1832 "debug bgp update-groups",
1835 "BGP update-groups\n")
1837 if (vty
->node
== CONFIG_NODE
)
1838 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1840 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1841 vty_out(vty
, "BGP update-groups debugging is on\n");
1846 DEFUN (no_debug_bgp_update_groups
,
1847 no_debug_bgp_update_groups_cmd
,
1848 "no debug bgp update-groups",
1852 "BGP update-groups\n")
1854 if (vty
->node
== CONFIG_NODE
)
1855 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1857 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1858 vty_out(vty
, "BGP update-groups debugging is off\n");
1863 DEFUN (debug_bgp_vpn
,
1865 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1869 "leaked from vrf to vpn\n"
1870 "leaked to vrf from vpn\n"
1871 "route-map updates\n"
1876 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1877 if (vty
->node
== CONFIG_NODE
)
1878 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1880 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1881 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1882 if (vty
->node
== CONFIG_NODE
)
1883 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1885 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1886 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1887 if (vty
->node
== CONFIG_NODE
)
1888 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1890 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1891 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1892 if (vty
->node
== CONFIG_NODE
)
1893 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1895 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1897 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1898 return CMD_WARNING_CONFIG_FAILED
;
1901 if (vty
->node
!= CONFIG_NODE
)
1902 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1907 DEFUN (no_debug_bgp_vpn
,
1908 no_debug_bgp_vpn_cmd
,
1909 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1914 "leaked from vrf to vpn\n"
1915 "leaked to vrf from vpn\n"
1916 "route-map updates\n"
1921 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1922 if (vty
->node
== CONFIG_NODE
)
1923 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1925 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1927 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1928 if (vty
->node
== CONFIG_NODE
)
1929 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1931 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1932 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1933 if (vty
->node
== CONFIG_NODE
)
1934 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1936 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1937 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1938 if (vty
->node
== CONFIG_NODE
)
1939 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1941 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1943 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1944 return CMD_WARNING_CONFIG_FAILED
;
1947 if (vty
->node
!= CONFIG_NODE
)
1948 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1953 DEFUN (debug_bgp_pbr
,
1955 "debug bgp pbr [error]",
1958 "BGP policy based routing\n"
1963 if (argv_find(argv
, argc
, "error", &idx
)) {
1964 if (vty
->node
== CONFIG_NODE
)
1965 DEBUG_ON(pbr
, PBR_ERROR
);
1967 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1968 vty_out(vty
, "BGP policy based routing error is on\n");
1972 if (vty
->node
== CONFIG_NODE
)
1975 TERM_DEBUG_ON(pbr
, PBR
);
1976 vty_out(vty
, "BGP policy based routing is on\n");
1981 DEFUN (no_debug_bgp_pbr
,
1982 no_debug_bgp_pbr_cmd
,
1983 "no debug bgp pbr [error]",
1987 "BGP policy based routing\n"
1992 if (argv_find(argv
, argc
, "error", &idx
)) {
1993 if (vty
->node
== CONFIG_NODE
)
1994 DEBUG_OFF(pbr
, PBR_ERROR
);
1996 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1997 vty_out(vty
, "BGP policy based routing error is off\n");
2001 if (vty
->node
== CONFIG_NODE
)
2002 DEBUG_OFF(pbr
, PBR
);
2004 TERM_DEBUG_OFF(pbr
, PBR
);
2005 vty_out(vty
, "BGP policy based routing is off\n");
2010 DEFPY (debug_bgp_evpn_mh
,
2011 debug_bgp_evpn_mh_cmd
,
2012 "[no$no] debug bgp evpn mh <es$es|route$rt>",
2018 "Ethernet Segment debugging\n"
2019 "Route debugging\n")
2022 if (vty
->node
== CONFIG_NODE
) {
2024 DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2026 DEBUG_ON(evpn_mh
, EVPN_MH_ES
);
2029 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2031 "BGP EVPN-MH ES debugging is off\n");
2033 TERM_DEBUG_ON(evpn_mh
, EVPN_MH_ES
);
2035 "BGP EVPN-MH ES debugging is on\n");
2040 if (vty
->node
== CONFIG_NODE
) {
2042 DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2044 DEBUG_ON(evpn_mh
, EVPN_MH_RT
);
2047 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2049 "BGP EVPN-MH route debugging is off\n");
2051 TERM_DEBUG_ON(evpn_mh
, EVPN_MH_RT
);
2053 "BGP EVPN-MH route debugging is on\n");
2061 DEFUN (debug_bgp_labelpool
,
2062 debug_bgp_labelpool_cmd
,
2063 "debug bgp labelpool",
2068 if (vty
->node
== CONFIG_NODE
)
2069 DEBUG_ON(labelpool
, LABELPOOL
);
2071 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
2073 if (vty
->node
!= CONFIG_NODE
)
2074 vty_out(vty
, "enabled debug bgp labelpool\n");
2079 DEFUN (no_debug_bgp_labelpool
,
2080 no_debug_bgp_labelpool_cmd
,
2081 "no debug bgp labelpool",
2087 if (vty
->node
== CONFIG_NODE
)
2088 DEBUG_OFF(labelpool
, LABELPOOL
);
2090 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2093 if (vty
->node
!= CONFIG_NODE
)
2094 vty_out(vty
, "disabled debug bgp labelpool\n");
2099 DEFPY(debug_bgp_bfd
, debug_bgp_bfd_cmd
,
2100 "[no] debug bgp bfd",
2104 "Bidirection Forwarding Detection\n")
2106 if (vty
->node
== CONFIG_NODE
) {
2108 DEBUG_OFF(bfd
, BFD_LIB
);
2109 bfd_protocol_integration_set_debug(false);
2111 DEBUG_ON(bfd
, BFD_LIB
);
2112 bfd_protocol_integration_set_debug(true);
2116 TERM_DEBUG_OFF(bfd
, BFD_LIB
);
2118 TERM_DEBUG_ON(bfd
, BFD_LIB
);
2124 DEFUN (no_debug_bgp
,
2132 struct listnode
*ln
;
2134 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2135 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2136 bgp_debug_list_free(bgp_debug_update_in_peers
);
2137 bgp_debug_list_free(bgp_debug_update_out_peers
);
2138 bgp_debug_list_free(bgp_debug_update_prefixes
);
2139 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2140 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2142 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2143 bgp_debug_clear_updgrp_update_dbg(bgp
);
2145 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2146 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2147 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2148 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2149 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2150 TERM_DEBUG_OFF(as4
, AS4
);
2151 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2152 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2153 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2154 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2155 TERM_DEBUG_OFF(nht
, NHT
);
2156 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2157 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2158 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2159 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2160 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2161 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2162 TERM_DEBUG_OFF(pbr
, PBR
);
2163 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2164 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
2165 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2166 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2167 TERM_DEBUG_OFF(bfd
, BFD_LIB
);
2169 vty_out(vty
, "All possible debugging has been turned off\n");
2174 DEFUN_NOSH (show_debugging_bgp
,
2175 show_debugging_bgp_cmd
,
2176 "show debugging [bgp]",
2181 vty_out(vty
, "BGP debugging status:\n");
2183 if (BGP_DEBUG(as4
, AS4
))
2184 vty_out(vty
, " BGP as4 debugging is on\n");
2186 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2187 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2189 if (BGP_DEBUG(bestpath
, BESTPATH
))
2190 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2191 bgp_debug_bestpath_prefixes
);
2193 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2194 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2195 bgp_debug_keepalive_peers
);
2197 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2198 bgp_debug_list_print(vty
,
2199 " BGP neighbor-events debugging is on",
2200 bgp_debug_neighbor_events_peers
);
2202 if (BGP_DEBUG(nht
, NHT
))
2203 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2205 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2206 vty_out(vty
, " BGP update-groups debugging is on\n");
2208 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2209 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2210 bgp_debug_update_prefixes
);
2212 if (BGP_DEBUG(update
, UPDATE_IN
))
2213 bgp_debug_list_print(vty
,
2214 " BGP updates debugging is on (inbound)",
2215 bgp_debug_update_in_peers
);
2217 if (BGP_DEBUG(update
, UPDATE_OUT
))
2218 bgp_debug_list_print(vty
,
2219 " BGP updates debugging is on (outbound)",
2220 bgp_debug_update_out_peers
);
2222 if (BGP_DEBUG(zebra
, ZEBRA
))
2223 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2224 bgp_debug_zebra_prefixes
);
2226 if (BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
))
2227 vty_out(vty
, " BGP graceful-restart debugging is on\n");
2229 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2230 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2232 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2234 " BGP route leak from vrf to vpn debugging is on\n");
2235 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2237 " BGP route leak to vrf from vpn debugging is on\n");
2238 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2239 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2240 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2241 vty_out(vty
, " BGP vpn label event debugging is on\n");
2242 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2243 vty_out(vty
, " BGP flowspec debugging is on\n");
2244 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2245 vty_out(vty
, " BGP labelpool debugging is on\n");
2247 if (BGP_DEBUG(pbr
, PBR
))
2248 vty_out(vty
, " BGP policy based routing debugging is on\n");
2249 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2250 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2252 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2253 vty_out(vty
, " BGP EVPN-MH ES debugging is on\n");
2254 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
2255 vty_out(vty
, " BGP EVPN-MH route debugging is on\n");
2257 if (BGP_DEBUG(bfd
, BFD_LIB
))
2258 vty_out(vty
, " BGP BFD library debugging is on\n");
2264 static int bgp_config_write_debug(struct vty
*vty
)
2268 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2269 vty_out(vty
, "debug bgp as4\n");
2273 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2274 vty_out(vty
, "debug bgp as4 segment\n");
2278 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2279 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2280 bgp_debug_bestpath_prefixes
);
2283 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2284 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2285 bgp_debug_keepalive_peers
);
2288 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2289 write
+= bgp_debug_list_conf_print(
2290 vty
, "debug bgp neighbor-events",
2291 bgp_debug_neighbor_events_peers
);
2294 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2295 vty_out(vty
, "debug bgp nht\n");
2299 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2300 vty_out(vty
, "debug bgp update-groups\n");
2304 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2305 write
+= bgp_debug_list_conf_print(vty
,
2306 "debug bgp updates prefix",
2307 bgp_debug_update_prefixes
);
2310 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2311 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2312 bgp_debug_update_in_peers
);
2315 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2316 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2317 bgp_debug_update_out_peers
);
2320 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2321 if (!bgp_debug_zebra_prefixes
2322 || list_isempty(bgp_debug_zebra_prefixes
)) {
2323 vty_out(vty
, "debug bgp zebra\n");
2326 write
+= bgp_debug_list_conf_print(
2327 vty
, "debug bgp zebra prefix",
2328 bgp_debug_zebra_prefixes
);
2332 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2333 vty_out(vty
, "debug bgp allow-martians\n");
2337 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2338 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2341 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2342 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2345 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2346 vty_out(vty
, "debug bgp vpn rmap-event\n");
2349 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2350 vty_out(vty
, "debug bgp vpn label\n");
2353 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2354 vty_out(vty
, "debug bgp flowspec\n");
2357 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2358 vty_out(vty
, "debug bgp labelpool\n");
2362 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2363 vty_out(vty
, "debug bgp pbr\n");
2366 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2367 vty_out(vty
, "debug bgp pbr error\n");
2371 if (CONF_BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
)) {
2372 vty_out(vty
, "debug bgp graceful-restart\n");
2376 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_ES
)) {
2377 vty_out(vty
, "debug bgp evpn mh es\n");
2380 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
2381 vty_out(vty
, "debug bgp evpn mh route\n");
2385 if (CONF_BGP_DEBUG(bfd
, BFD_LIB
)) {
2386 vty_out(vty
, "debug bgp bfd\n");
2393 static int bgp_config_write_debug(struct vty
*vty
);
2394 static struct cmd_node debug_node
= {
2398 .config_write
= bgp_config_write_debug
,
2401 void bgp_debug_init(void)
2403 install_node(&debug_node
);
2405 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2407 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2408 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2409 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2410 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2412 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2413 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2414 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2415 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2416 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2417 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2418 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2419 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2420 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2421 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2422 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2423 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2424 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2425 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2426 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2427 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2429 install_element(ENABLE_NODE
, &debug_bgp_graceful_restart_cmd
);
2430 install_element(CONFIG_NODE
, &debug_bgp_graceful_restart_cmd
);
2432 /* debug bgp updates (in|out) */
2433 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2434 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2435 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2436 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2438 /* debug bgp updates (in|out) A.B.C.D */
2439 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2440 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2441 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2442 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2444 /* debug bgp updates prefix A.B.C.D/M */
2445 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2446 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2447 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2448 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2449 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2450 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2451 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2452 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2454 /* debug bgp zebra prefix A.B.C.D/M */
2455 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2456 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2457 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2458 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2460 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2461 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2462 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2463 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2465 /* debug bgp neighbor-events A.B.C.D */
2466 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2467 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2468 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2469 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2471 /* debug bgp keepalive A.B.C.D */
2472 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2473 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2474 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2475 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2477 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2478 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2479 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2480 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2481 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2482 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2483 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2484 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2485 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2486 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2487 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2488 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2489 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2490 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2491 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2492 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2493 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2494 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2495 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2497 install_element(ENABLE_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2498 install_element(CONFIG_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2500 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2501 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2502 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2503 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2505 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2506 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2507 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2508 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2511 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2512 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2513 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2514 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2516 install_element(ENABLE_NODE
, &debug_bgp_evpn_mh_cmd
);
2517 install_element(CONFIG_NODE
, &debug_bgp_evpn_mh_cmd
);
2520 install_element(ENABLE_NODE
, &debug_bgp_bfd_cmd
);
2521 install_element(CONFIG_NODE
, &debug_bgp_bfd_cmd
);
2524 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2525 * for BGP_DEBUG_TYPE
2527 static int bgp_debug_per_prefix(const struct prefix
*p
,
2528 unsigned long term_bgp_debug_type
,
2529 unsigned int BGP_DEBUG_TYPE
,
2530 struct list
*per_prefix_list
)
2532 struct bgp_debug_filter
*filter
;
2533 struct listnode
*node
, *nnode
;
2535 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2536 /* We are debugging all prefixes so return true */
2537 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2544 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2546 if (filter
->p
->prefixlen
== p
->prefixlen
2547 && prefix_match(filter
->p
, p
))
2557 /* Return true if this peer is on the per_peer_list of peers to debug
2558 * for BGP_DEBUG_TYPE
2560 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2561 unsigned int BGP_DEBUG_TYPE
,
2562 struct list
*per_peer_list
)
2564 struct bgp_debug_filter
*filter
;
2565 struct listnode
*node
, *nnode
;
2567 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2568 /* We are debugging all peers so return true */
2569 if (!per_peer_list
|| list_isempty(per_peer_list
))
2576 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2578 if (strcmp(filter
->host
, host
) == 0)
2588 int bgp_debug_neighbor_events(struct peer
*peer
)
2595 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2596 BGP_DEBUG_NEIGHBOR_EVENTS
,
2597 bgp_debug_neighbor_events_peers
);
2600 int bgp_debug_keepalive(struct peer
*peer
)
2607 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2608 BGP_DEBUG_KEEPALIVE
,
2609 bgp_debug_keepalive_peers
);
2612 bool bgp_debug_update(struct peer
*peer
, const struct prefix
*p
,
2613 struct update_group
*updgrp
, unsigned int inbound
)
2621 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2622 BGP_DEBUG_UPDATE_IN
,
2623 bgp_debug_update_in_peers
))
2629 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2630 BGP_DEBUG_UPDATE_OUT
,
2631 bgp_debug_update_out_peers
))
2634 /* Check if update debugging implicitly enabled for the group.
2636 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2641 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2642 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2643 BGP_DEBUG_UPDATE_PREFIX
,
2644 bgp_debug_update_prefixes
))
2651 bool bgp_debug_bestpath(struct bgp_dest
*dest
)
2653 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2654 if (bgp_debug_per_prefix(
2655 bgp_dest_get_prefix(dest
), term_bgp_debug_bestpath
,
2656 BGP_DEBUG_BESTPATH
, bgp_debug_bestpath_prefixes
))
2663 bool bgp_debug_zebra(const struct prefix
*p
)
2665 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2666 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2668 bgp_debug_zebra_prefixes
))
2675 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2676 const struct prefix_rd
*prd
,
2677 union prefixconstptr pu
,
2678 mpls_label_t
*label
, uint32_t num_labels
,
2679 int addpath_valid
, uint32_t addpath_id
,
2680 char *str
, int size
)
2682 char rd_buf
[RD_ADDRSTRLEN
];
2684 /* ' with addpath ID ' 17
2685 * max strlen of uint32 + 10
2686 * +/- (just in case) + 1
2687 * null terminator + 1
2688 * ============================ 29 */
2689 char pathid_buf
[30];
2691 if (size
< BGP_PRD_PATH_STRLEN
)
2694 /* Note: Path-id is created by default, but only included in update
2696 pathid_buf
[0] = '\0';
2698 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2702 if (bgp_labeled_safi(safi
) && num_labels
) {
2704 if (safi
== SAFI_EVPN
) {
2707 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2708 snprintf(tag_buf
, sizeof(tag_buf
), " label %s",
2711 uint32_t label_value
;
2713 label_value
= decode_label(label
);
2714 snprintf(tag_buf
, sizeof(tag_buf
), " label %u",
2720 snprintfrr(str
, size
, "RD %s %pFX%s%s %s %s",
2721 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)), pu
.p
,
2722 tag_buf
, pathid_buf
, afi2str(afi
), safi2str(safi
));
2723 else if (safi
== SAFI_FLOWSPEC
) {
2724 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2725 const struct prefix_fs
*fs
= pu
.fs
;
2727 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2728 fs
->prefix
.prefixlen
,
2730 NLRI_STRING_FORMAT_DEBUG
, NULL
,
2731 family2afi(fs
->prefix
.family
));
2732 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2735 snprintfrr(str
, size
, "%pFX%s%s %s %s", pu
.p
, tag_buf
,
2736 pathid_buf
, afi2str(afi
), safi2str(safi
));