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"
52 #include "bgpd/bgp_packet.h"
54 unsigned long conf_bgp_debug_as4
;
55 unsigned long conf_bgp_debug_neighbor_events
;
56 unsigned long conf_bgp_debug_events
;
57 unsigned long conf_bgp_debug_packet
;
58 unsigned long conf_bgp_debug_filter
;
59 unsigned long conf_bgp_debug_keepalive
;
60 unsigned long conf_bgp_debug_update
;
61 unsigned long conf_bgp_debug_bestpath
;
62 unsigned long conf_bgp_debug_zebra
;
63 unsigned long conf_bgp_debug_allow_martians
;
64 unsigned long conf_bgp_debug_nht
;
65 unsigned long conf_bgp_debug_update_groups
;
66 unsigned long conf_bgp_debug_vpn
;
67 unsigned long conf_bgp_debug_flowspec
;
68 unsigned long conf_bgp_debug_labelpool
;
69 unsigned long conf_bgp_debug_pbr
;
70 unsigned long conf_bgp_debug_graceful_restart
;
71 unsigned long conf_bgp_debug_evpn_mh
;
72 unsigned long conf_bgp_debug_bfd
;
74 unsigned long term_bgp_debug_as4
;
75 unsigned long term_bgp_debug_neighbor_events
;
76 unsigned long term_bgp_debug_events
;
77 unsigned long term_bgp_debug_packet
;
78 unsigned long term_bgp_debug_filter
;
79 unsigned long term_bgp_debug_keepalive
;
80 unsigned long term_bgp_debug_update
;
81 unsigned long term_bgp_debug_bestpath
;
82 unsigned long term_bgp_debug_zebra
;
83 unsigned long term_bgp_debug_allow_martians
;
84 unsigned long term_bgp_debug_nht
;
85 unsigned long term_bgp_debug_update_groups
;
86 unsigned long term_bgp_debug_vpn
;
87 unsigned long term_bgp_debug_flowspec
;
88 unsigned long term_bgp_debug_labelpool
;
89 unsigned long term_bgp_debug_pbr
;
90 unsigned long term_bgp_debug_graceful_restart
;
91 unsigned long term_bgp_debug_evpn_mh
;
92 unsigned long term_bgp_debug_bfd
;
94 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
95 struct list
*bgp_debug_keepalive_peers
= NULL
;
96 struct list
*bgp_debug_update_out_peers
= NULL
;
97 struct list
*bgp_debug_update_in_peers
= NULL
;
98 struct list
*bgp_debug_update_prefixes
= NULL
;
99 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
100 struct list
*bgp_debug_zebra_prefixes
= NULL
;
102 /* messages for BGP-4 status */
103 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
104 {Connect
, "Connect"},
106 {OpenSent
, "OpenSent"},
107 {OpenConfirm
, "OpenConfirm"},
108 {Established
, "Established"},
109 {Clearing
, "Clearing"},
110 {Deleted
, "Deleted"},
113 /* BGP message type string. */
114 const char *const bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
115 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
118 /* message for BGP-4 Notify */
119 static const struct message bgp_notify_msg
[] = {
120 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
121 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
122 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
123 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
124 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
125 {BGP_NOTIFY_CEASE
, "Cease"},
126 {BGP_NOTIFY_ROUTE_REFRESH_ERR
, "ROUTE-REFRESH Message Error"},
129 static const struct message bgp_notify_head_msg
[] = {
130 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
131 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
132 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
135 static const struct message bgp_notify_open_msg
[] = {
136 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
137 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
138 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
139 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
140 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
141 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
142 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
143 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
144 {BGP_NOTIFY_OPEN_ROLE_MISMATCH
, "/Role Mismatch"},
147 static const struct message bgp_notify_update_msg
[] = {
148 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
149 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
150 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
151 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
152 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
153 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
154 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
155 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
156 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
157 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
158 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
159 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
162 static const struct message bgp_notify_cease_msg
[] = {
163 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
164 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
165 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administrative Shutdown"},
166 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer De-configured"},
167 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administrative Reset"},
168 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
169 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
170 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
171 "/Connection Collision Resolution"},
172 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resources"},
173 {BGP_NOTIFY_CEASE_HARD_RESET
, "/Hard Reset"},
174 {BGP_NOTIFY_CEASE_BFD_DOWN
, "/BFD Down"},
177 static const struct message bgp_notify_route_refresh_msg
[] = {
178 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
179 {BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN
, "/Invalid Message Length"},
182 static const struct message bgp_notify_fsm_msg
[] = {
183 {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC
, "/Unspecific"},
184 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT
,
185 "/Receive Unexpected Message in OpenSent State"},
186 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM
,
187 "/Receive Unexpected Message in OpenConfirm State"},
188 {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED
,
189 "/Receive Unexpected Message in Established State"},
192 /* Origin strings. */
193 const char *const bgp_origin_str
[] = {"i", "e", "?"};
194 const char *const bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
196 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
198 /* Given a string return a pointer the corresponding peer structure */
199 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
201 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
209 ret
= str2sockunion(peer_str
, &su
);
213 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
216 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
220 return peer_lookup(bgp
, &su
);
223 static void bgp_debug_list_free(struct list
*list
)
225 struct bgp_debug_filter
*filter
;
226 struct listnode
*node
, *nnode
;
229 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
230 listnode_delete(list
, filter
);
231 prefix_free(&filter
->p
);
232 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
233 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
238 * Print the desc along with a list of peers/prefixes this debug is
241 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
244 struct bgp_debug_filter
*filter
;
245 struct listnode
*node
, *nnode
;
247 vty_out(vty
, "%s", desc
);
249 if (list
&& !list_isempty(list
)) {
250 vty_out(vty
, " for");
251 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
253 vty_out(vty
, " %s", filter
->host
);
255 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
256 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
258 vty_out(vty
, " %pFX", filter
->p
);
266 * Print the command to enable the debug for each peer/prefix this debug is
269 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
272 struct bgp_debug_filter
*filter
;
273 struct listnode
*node
, *nnode
;
276 if (list
&& !list_isempty(list
)) {
277 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
279 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
283 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
284 bgp_debug_print_evpn_prefix(vty
, desc
,
287 } else if (filter
->p
) {
288 vty_out(vty
, "%s %pFX\n", desc
, filter
->p
);
295 vty_out(vty
, "%s\n", desc
);
302 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
303 const struct prefix
*p
)
305 struct bgp_debug_filter
*filter
;
307 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
308 sizeof(struct bgp_debug_filter
));
311 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
315 filter
->p
= prefix_new();
316 prefix_copy(filter
->p
, p
);
319 listnode_add(list
, filter
);
322 static bool bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
325 struct bgp_debug_filter
*filter
;
326 struct listnode
*node
, *nnode
;
328 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
329 if (host
&& strcmp(filter
->host
, host
) == 0) {
330 listnode_delete(list
, filter
);
331 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
332 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
334 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
335 && prefix_match(filter
->p
, p
)) {
336 listnode_delete(list
, filter
);
337 prefix_free(&filter
->p
);
338 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
346 static bool bgp_debug_list_has_entry(struct list
*list
, const char *host
,
347 const struct prefix
*p
)
349 struct bgp_debug_filter
*filter
;
350 struct listnode
*node
, *nnode
;
352 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
354 if (strcmp(filter
->host
, host
) == 0) {
358 if (filter
->p
->prefixlen
== p
->prefixlen
359 && prefix_match(filter
->p
, p
)) {
368 bool bgp_debug_peer_updout_enabled(char *host
)
370 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
374 /* Dump attribute. */
375 bool bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
377 char addrbuf
[BUFSIZ
];
384 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
385 snprintfrr(buf
, size
, "nexthop %pI4", &attr
->nexthop
);
387 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
388 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
389 bgp_origin_str
[attr
->origin
]);
392 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
393 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
394 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
396 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
399 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
400 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
401 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
404 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
405 snprintfrr(buf
, size
, "nexthop %pI4", &attr
->nexthop
);
407 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
408 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
409 ", localpref %u", attr
->local_pref
);
411 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
412 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
415 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
416 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
418 community_str(bgp_attr_get_community(attr
), false,
421 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
)))
422 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
423 ", large-community %s",
424 lcommunity_str(bgp_attr_get_lcommunity(attr
), false,
427 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
428 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
430 ecommunity_str(bgp_attr_get_ecommunity(attr
)));
432 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
433 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
434 ", atomic-aggregate");
436 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
437 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
438 ", aggregated by %u %pI4", attr
->aggregator_as
,
439 &attr
->aggregator_addr
);
441 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
442 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
443 ", originator %pI4", &attr
->originator_id
);
445 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
446 struct cluster_list
*cluster
;
449 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
452 cluster
= bgp_attr_get_cluster(attr
);
453 for (i
= 0; i
< cluster
->length
/ 4; i
++)
454 snprintfrr(buf
+ strlen(buf
), size
- strlen(buf
),
455 " %pI4", &cluster
->list
[i
]);
458 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
459 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
460 ", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr
));
462 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
463 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
464 aspath_print(attr
->aspath
));
466 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
467 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
468 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
469 ", label-index %u", attr
->label_index
);
478 const char *bgp_notify_code_str(char code
)
480 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
483 const char *bgp_notify_subcode_str(char code
, char subcode
)
487 case BGP_NOTIFY_HEADER_ERR
:
488 return lookup_msg(bgp_notify_head_msg
, subcode
,
489 "Unrecognized Error Subcode");
490 case BGP_NOTIFY_OPEN_ERR
:
491 return lookup_msg(bgp_notify_open_msg
, subcode
,
492 "Unrecognized Error Subcode");
493 case BGP_NOTIFY_UPDATE_ERR
:
494 return lookup_msg(bgp_notify_update_msg
, subcode
,
495 "Unrecognized Error Subcode");
496 case BGP_NOTIFY_HOLD_ERR
:
498 case BGP_NOTIFY_FSM_ERR
:
499 return lookup_msg(bgp_notify_fsm_msg
, subcode
,
500 "Unrecognized Error Subcode");
501 case BGP_NOTIFY_CEASE
:
502 return lookup_msg(bgp_notify_cease_msg
, subcode
,
503 "Unrecognized Error Subcode");
504 case BGP_NOTIFY_ROUTE_REFRESH_ERR
:
505 return lookup_msg(bgp_notify_route_refresh_msg
, subcode
,
506 "Unrecognized Error Subcode");
511 /* extract notify admin reason if correctly present */
512 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
515 if (!data
|| datalen
< 1)
518 uint8_t len
= data
[0];
519 if (!len
|| len
> datalen
- 1)
522 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
525 /* dump notify packet */
526 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
527 const char *direct
, bool hard_reset
)
529 const char *subcode_str
;
530 const char *code_str
;
531 const char *msg_str
= NULL
;
534 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
535 || CHECK_FLAG(peer
->bgp
->flags
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
536 code_str
= bgp_notify_code_str(bgp_notify
->code
);
537 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
538 bgp_notify
->subcode
);
540 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
541 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
542 || bgp_notify
->subcode
543 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
544 msg_str
= bgp_notify_admin_message(
545 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
551 "%%NOTIFICATION%s: %s neighbor %s %d/%d (%s%s) \"%s\"",
552 hard_reset
? "(Hard Reset)" : "",
553 strcmp(direct
, "received") == 0
556 peer
->host
, bgp_notify
->code
,
557 bgp_notify
->subcode
, code_str
, subcode_str
,
560 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
562 "%%NOTIFICATION%s: %s neighbor %s %d/%d (%s%s) %d bytes %s",
563 hard_reset
? "(Hard Reset)" : "",
564 strcmp(direct
, "received") == 0
567 peer
->host
, bgp_notify
->code
,
568 bgp_notify
->subcode
, code_str
, subcode_str
,
569 bgp_notify
->length
, msg_str
);
574 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
577 bgp
= bgp_get_default();
578 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
581 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
584 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
585 char buf
[PREFIX2STR_BUFFER
];
586 char buf2
[ETHER_ADDR_STRLEN
];
588 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
589 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
591 evpn_desc
, sizeof(evpn_desc
),
592 "l2vpn evpn type macip mac %s",
593 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
594 buf2
, sizeof(buf2
)));
596 uint8_t family
= is_evpn_prefix_ipaddr_v4(
597 (struct prefix_evpn
*)p
) ?
600 evpn_desc
, sizeof(evpn_desc
),
601 "l2vpn evpn type macip mac %s ip %s",
602 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
606 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
607 buf
, PREFIX2STR_BUFFER
));
609 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
610 snprintfrr(evpn_desc
, sizeof(evpn_desc
),
611 "l2vpn evpn type multicast ip %pI4",
612 &p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
);
613 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
614 uint8_t family
= is_evpn_prefix_ipaddr_v4(
615 (struct prefix_evpn
*)p
) ? AF_INET
617 snprintf(evpn_desc
, sizeof(evpn_desc
),
618 "l2vpn evpn type prefix ip %s/%d",
620 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
,
621 buf
, PREFIX2STR_BUFFER
),
622 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
625 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
628 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
629 int argc
, struct prefix
**argv_pp
)
631 struct prefix
*argv_p
;
632 struct ethaddr mac
= {};
633 struct ipaddr ip
= {};
640 if (bgp_evpn_cli_parse_type(&evpn_type
, argv
, argc
) < 0)
643 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
644 memset(&ip
, 0, sizeof(ip
));
646 if (argv_find(argv
, argc
, "mac", &mac_idx
))
647 if (!prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
)) {
648 vty_out(vty
, "%% Malformed MAC address\n");
652 if (argv_find(argv
, argc
, "ip", &ip_idx
))
653 if (str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
) != 0) {
654 vty_out(vty
, "%% Malformed IP address\n");
658 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
660 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
661 memset(&ip
, 0, sizeof(ip
));
663 if (argv_find(argv
, argc
, "ip", &ip_idx
))
664 if (str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
) != 0) {
665 vty_out(vty
, "%% Malformed IP address\n");
669 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
671 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
672 struct prefix ip_prefix
;
674 memset(&ip_prefix
, 0, sizeof(ip_prefix
));
675 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
676 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
677 apply_mask(&ip_prefix
);
679 build_type5_prefix_from_ip_prefix(
680 (struct prefix_evpn
*)argv_p
,
687 /* Debug option setting interface. */
688 unsigned long bgp_debug_option
= 0;
690 int debug(unsigned int option
)
692 return bgp_debug_option
& option
;
695 DEFUN (debug_bgp_as4
,
702 if (vty
->node
== CONFIG_NODE
)
705 TERM_DEBUG_ON(as4
, AS4
);
706 vty_out(vty
, "BGP as4 debugging is on\n");
711 DEFUN (no_debug_bgp_as4
,
712 no_debug_bgp_as4_cmd
,
719 if (vty
->node
== CONFIG_NODE
)
722 TERM_DEBUG_OFF(as4
, AS4
);
723 vty_out(vty
, "BGP as4 debugging is off\n");
728 DEFUN (debug_bgp_as4_segment
,
729 debug_bgp_as4_segment_cmd
,
730 "debug bgp as4 segment",
734 "BGP AS4 aspath segment handling\n")
736 if (vty
->node
== CONFIG_NODE
)
737 DEBUG_ON(as4
, AS4_SEGMENT
);
739 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
740 vty_out(vty
, "BGP as4 segment debugging is on\n");
745 DEFUN (no_debug_bgp_as4_segment
,
746 no_debug_bgp_as4_segment_cmd
,
747 "no debug bgp as4 segment",
752 "BGP AS4 aspath segment handling\n")
754 if (vty
->node
== CONFIG_NODE
)
755 DEBUG_OFF(as4
, AS4_SEGMENT
);
757 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
758 vty_out(vty
, "BGP as4 segment debugging is off\n");
763 /* debug bgp neighbor_events */
764 DEFUN (debug_bgp_neighbor_events
,
765 debug_bgp_neighbor_events_cmd
,
766 "debug bgp neighbor-events",
769 "BGP Neighbor Events\n")
771 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
773 if (vty
->node
== CONFIG_NODE
)
774 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
776 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
777 vty_out(vty
, "BGP neighbor-events debugging is on\n");
782 DEFUN (debug_bgp_neighbor_events_peer
,
783 debug_bgp_neighbor_events_peer_cmd
,
784 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
787 "BGP Neighbor Events\n"
788 "BGP neighbor IP address to debug\n"
789 "BGP IPv6 neighbor to debug\n"
790 "BGP neighbor on interface to debug\n")
793 const char *host
= argv
[idx_peer
]->arg
;
795 if (!bgp_debug_neighbor_events_peers
)
796 bgp_debug_neighbor_events_peers
= list_new();
798 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
801 "BGP neighbor-events debugging is already enabled for %s\n",
806 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
808 if (vty
->node
== CONFIG_NODE
)
809 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
811 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
812 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
818 DEFUN (no_debug_bgp_neighbor_events
,
819 no_debug_bgp_neighbor_events_cmd
,
820 "no debug bgp neighbor-events",
826 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
828 if (vty
->node
== CONFIG_NODE
)
829 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
831 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
832 vty_out(vty
, "BGP neighbor-events debugging is off\n");
837 DEFUN (no_debug_bgp_neighbor_events_peer
,
838 no_debug_bgp_neighbor_events_peer_cmd
,
839 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
844 "BGP neighbor IP address to debug\n"
845 "BGP IPv6 neighbor to debug\n"
846 "BGP neighbor on interface to debug\n")
850 const char *host
= argv
[idx_peer
]->arg
;
852 if (bgp_debug_neighbor_events_peers
853 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
854 found_peer
= bgp_debug_list_remove_entry(
855 bgp_debug_neighbor_events_peers
, host
, NULL
);
857 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
858 if (vty
->node
== CONFIG_NODE
)
859 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
861 TERM_DEBUG_OFF(neighbor_events
,
867 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
871 "BGP neighbor-events debugging was not enabled for %s\n",
878 DEFUN (debug_bgp_nht
,
883 "BGP nexthop tracking events\n")
885 if (vty
->node
== CONFIG_NODE
)
888 TERM_DEBUG_ON(nht
, NHT
);
889 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
894 DEFUN (no_debug_bgp_nht
,
895 no_debug_bgp_nht_cmd
,
900 "BGP nexthop tracking events\n")
902 if (vty
->node
== CONFIG_NODE
)
905 TERM_DEBUG_OFF(nht
, NHT
);
906 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
911 /* debug bgp keepalives */
912 DEFUN (debug_bgp_keepalive
,
913 debug_bgp_keepalive_cmd
,
914 "debug bgp keepalives",
919 bgp_debug_list_free(bgp_debug_keepalive_peers
);
921 if (vty
->node
== CONFIG_NODE
)
922 DEBUG_ON(keepalive
, KEEPALIVE
);
924 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
925 vty_out(vty
, "BGP keepalives debugging is on\n");
930 DEFUN (debug_bgp_keepalive_peer
,
931 debug_bgp_keepalive_peer_cmd
,
932 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
936 "BGP IPv4 neighbor to debug\n"
937 "BGP IPv6 neighbor to debug\n"
938 "BGP neighbor on interface to debug\n")
941 const char *host
= argv
[idx_peer
]->arg
;
943 if (!bgp_debug_keepalive_peers
)
944 bgp_debug_keepalive_peers
= list_new();
946 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
948 "BGP keepalive debugging is already enabled for %s\n",
953 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
955 if (vty
->node
== CONFIG_NODE
)
956 DEBUG_ON(keepalive
, KEEPALIVE
);
958 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
959 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
964 DEFUN (no_debug_bgp_keepalive
,
965 no_debug_bgp_keepalive_cmd
,
966 "no debug bgp keepalives",
972 bgp_debug_list_free(bgp_debug_keepalive_peers
);
974 if (vty
->node
== CONFIG_NODE
)
975 DEBUG_OFF(keepalive
, KEEPALIVE
);
977 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
978 vty_out(vty
, "BGP keepalives debugging is off\n");
983 DEFUN (no_debug_bgp_keepalive_peer
,
984 no_debug_bgp_keepalive_peer_cmd
,
985 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
990 "BGP neighbor IP address to debug\n"
991 "BGP IPv6 neighbor to debug\n"
992 "BGP neighbor on interface to debug\n")
996 const char *host
= argv
[idx_peer
]->arg
;
998 if (bgp_debug_keepalive_peers
999 && !list_isempty(bgp_debug_keepalive_peers
)) {
1000 found_peer
= bgp_debug_list_remove_entry(
1001 bgp_debug_keepalive_peers
, host
, NULL
);
1003 if (list_isempty(bgp_debug_keepalive_peers
)) {
1004 if (vty
->node
== CONFIG_NODE
)
1005 DEBUG_OFF(keepalive
, KEEPALIVE
);
1007 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
1012 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
1015 "BGP keepalives debugging was not enabled for %s\n",
1021 /* debug bgp bestpath */
1022 DEFUN (debug_bgp_bestpath_prefix
,
1023 debug_bgp_bestpath_prefix_cmd
,
1024 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1031 struct prefix
*argv_p
;
1032 int idx_ipv4_ipv6_prefixlen
= 3;
1034 argv_p
= prefix_new();
1035 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1038 if (!bgp_debug_bestpath_prefixes
)
1039 bgp_debug_bestpath_prefixes
= list_new();
1041 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1044 "BGP bestpath debugging is already enabled for %s\n",
1045 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1049 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1051 if (vty
->node
== CONFIG_NODE
) {
1052 DEBUG_ON(bestpath
, BESTPATH
);
1054 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1055 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1056 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1062 DEFUN (no_debug_bgp_bestpath_prefix
,
1063 no_debug_bgp_bestpath_prefix_cmd
,
1064 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1072 int idx_ipv4_ipv6_prefixlen
= 4;
1073 struct prefix
*argv_p
;
1074 int found_prefix
= 0;
1076 argv_p
= prefix_new();
1077 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1080 if (bgp_debug_bestpath_prefixes
1081 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1082 found_prefix
= bgp_debug_list_remove_entry(
1083 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1085 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1086 if (vty
->node
== CONFIG_NODE
) {
1087 DEBUG_OFF(bestpath
, BESTPATH
);
1089 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1091 "BGP bestpath debugging (per prefix) is off\n");
1097 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1098 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1100 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1101 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1106 DEFUN (no_debug_bgp_bestpath
,
1107 no_debug_bgp_bestpath_cmd
,
1108 "no debug bgp bestpath",
1114 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1116 if (vty
->node
== CONFIG_NODE
)
1117 DEBUG_OFF(bestpath
, BESTPATH
);
1119 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1120 vty_out(vty
, "BGP bestpath debugging is off\n");
1125 /* debug bgp updates */
1126 DEFUN (debug_bgp_update
,
1127 debug_bgp_update_cmd
,
1128 "debug bgp updates",
1133 bgp_debug_list_free(bgp_debug_update_in_peers
);
1134 bgp_debug_list_free(bgp_debug_update_out_peers
);
1135 bgp_debug_list_free(bgp_debug_update_prefixes
);
1137 if (vty
->node
== CONFIG_NODE
) {
1138 DEBUG_ON(update
, UPDATE_IN
);
1139 DEBUG_ON(update
, UPDATE_OUT
);
1141 TERM_DEBUG_ON(update
, UPDATE_IN
);
1142 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1143 vty_out(vty
, "BGP updates debugging is on\n");
1148 DEFUN (debug_bgp_update_direct
,
1149 debug_bgp_update_direct_cmd
,
1150 "debug bgp updates <in|out>",
1155 "Outbound updates\n")
1159 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1160 bgp_debug_list_free(bgp_debug_update_in_peers
);
1162 bgp_debug_list_free(bgp_debug_update_out_peers
);
1164 if (vty
->node
== CONFIG_NODE
) {
1165 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1166 DEBUG_ON(update
, UPDATE_IN
);
1168 DEBUG_ON(update
, UPDATE_OUT
);
1170 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1171 TERM_DEBUG_ON(update
, UPDATE_IN
);
1172 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1174 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1176 "BGP updates debugging is on (outbound)\n");
1182 DEFUN (debug_bgp_update_direct_peer
,
1183 debug_bgp_update_direct_peer_cmd
,
1184 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1189 "Outbound updates\n"
1190 "BGP neighbor IP address to debug\n"
1191 "BGP IPv6 neighbor to debug\n"
1192 "BGP neighbor on interface to debug\n")
1196 const char *host
= argv
[idx_peer
]->arg
;
1199 if (!bgp_debug_update_in_peers
)
1200 bgp_debug_update_in_peers
= list_new();
1202 if (!bgp_debug_update_out_peers
)
1203 bgp_debug_update_out_peers
= list_new();
1205 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1211 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1214 "BGP inbound update debugging is already enabled for %s\n",
1221 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1224 "BGP outbound update debugging is already enabled for %s\n",
1231 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1234 struct peer_af
*paf
;
1237 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1239 peer
= bgp_find_peer(vty
, host
);
1242 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1244 paf
= peer
->peer_af_array
[afidx
];
1246 if (PAF_SUBGRP(paf
)) {
1256 if (vty
->node
== CONFIG_NODE
) {
1258 DEBUG_ON(update
, UPDATE_IN
);
1260 DEBUG_ON(update
, UPDATE_OUT
);
1263 TERM_DEBUG_ON(update
, UPDATE_IN
);
1265 "BGP updates debugging is on (inbound) for %s\n",
1266 argv
[idx_peer
]->arg
);
1268 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1270 "BGP updates debugging is on (outbound) for %s\n",
1271 argv
[idx_peer
]->arg
);
1277 DEFUN (no_debug_bgp_update_direct
,
1278 no_debug_bgp_update_direct_cmd
,
1279 "no debug bgp updates <in|out>",
1285 "Outbound updates\n")
1288 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1289 bgp_debug_list_free(bgp_debug_update_in_peers
);
1291 if (vty
->node
== CONFIG_NODE
) {
1292 DEBUG_OFF(update
, UPDATE_IN
);
1294 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1296 "BGP updates debugging is off (inbound)\n");
1299 bgp_debug_list_free(bgp_debug_update_out_peers
);
1301 if (vty
->node
== CONFIG_NODE
) {
1302 DEBUG_OFF(update
, UPDATE_OUT
);
1304 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1306 "BGP updates debugging is off (outbound)\n");
1313 DEFUN (no_debug_bgp_update_direct_peer
,
1314 no_debug_bgp_update_direct_peer_cmd
,
1315 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1321 "Outbound updates\n"
1322 "BGP neighbor IP address to debug\n"
1323 "BGP IPv6 neighbor to debug\n"
1324 "BGP neighbor on interface to debug\n")
1330 const char *host
= argv
[idx_peer
]->arg
;
1332 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1337 if (inbound
&& bgp_debug_update_in_peers
1338 && !list_isempty(bgp_debug_update_in_peers
)) {
1339 found_peer
= bgp_debug_list_remove_entry(
1340 bgp_debug_update_in_peers
, host
, NULL
);
1342 if (list_isempty(bgp_debug_update_in_peers
)) {
1343 if (vty
->node
== CONFIG_NODE
)
1344 DEBUG_OFF(update
, UPDATE_IN
);
1346 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1348 "BGP updates debugging (inbound) is off\n");
1353 if (!inbound
&& bgp_debug_update_out_peers
1354 && !list_isempty(bgp_debug_update_out_peers
)) {
1355 found_peer
= bgp_debug_list_remove_entry(
1356 bgp_debug_update_out_peers
, host
, NULL
);
1358 if (list_isempty(bgp_debug_update_out_peers
)) {
1359 if (vty
->node
== CONFIG_NODE
)
1360 DEBUG_OFF(update
, UPDATE_OUT
);
1362 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1364 "BGP updates debugging (outbound) is off\n");
1369 struct peer_af
*paf
;
1371 peer
= bgp_find_peer(vty
, host
);
1374 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1376 paf
= peer
->peer_af_array
[afidx
];
1378 if (PAF_SUBGRP(paf
)) {
1379 UPDGRP_PEER_DBG_DIS(
1391 "BGP updates debugging (inbound) is off for %s\n",
1395 "BGP updates debugging (outbound) is off for %s\n",
1399 "BGP updates debugging (inbound) was not enabled for %s\n",
1403 "BGP updates debugging (outbound) was not enabled for %s\n",
1409 #ifndef VTYSH_EXTRACT_PL
1410 #include "bgpd/bgp_debug_clippy.c"
1413 DEFPY (debug_bgp_update_prefix_afi_safi
,
1414 debug_bgp_update_prefix_afi_safi_cmd
,
1415 "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>>",
1419 "Specify a prefix to debug\n"
1423 EVPN_TYPE_2_HELP_STR
1424 EVPN_TYPE_2_HELP_STR
1425 MAC_STR MAC_STR MAC_STR
1429 EVPN_TYPE_3_HELP_STR
1430 EVPN_TYPE_3_HELP_STR
1434 EVPN_TYPE_5_HELP_STR
1435 EVPN_TYPE_5_HELP_STR
1440 struct prefix
*argv_p
;
1441 int ret
= CMD_SUCCESS
;
1443 argv_p
= prefix_new();
1445 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1446 if (ret
!= CMD_SUCCESS
) {
1447 prefix_free(&argv_p
);
1451 if (!bgp_debug_update_prefixes
)
1452 bgp_debug_update_prefixes
= list_new();
1454 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1456 "BGP updates debugging is already enabled for %pFX\n",
1458 prefix_free(&argv_p
);
1462 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1464 if (vty
->node
== CONFIG_NODE
) {
1465 DEBUG_ON(update
, UPDATE_PREFIX
);
1467 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1468 vty_out(vty
, "BGP updates debugging is on for %pFX\n", argv_p
);
1471 prefix_free(&argv_p
);
1476 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1477 no_debug_bgp_update_prefix_afi_safi_cmd
,
1478 "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>>",
1483 "Specify a prefix to debug\n"
1487 EVPN_TYPE_2_HELP_STR
1488 EVPN_TYPE_2_HELP_STR
1489 MAC_STR MAC_STR MAC_STR
1493 EVPN_TYPE_3_HELP_STR
1494 EVPN_TYPE_3_HELP_STR
1498 EVPN_TYPE_5_HELP_STR
1499 EVPN_TYPE_5_HELP_STR
1504 struct prefix
*argv_p
;
1505 bool found_prefix
= false;
1506 int ret
= CMD_SUCCESS
;
1508 argv_p
= prefix_new();
1510 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1511 if (ret
!= CMD_SUCCESS
) {
1512 prefix_free(&argv_p
);
1516 if (bgp_debug_update_prefixes
1517 && !list_isempty(bgp_debug_update_prefixes
)) {
1518 found_prefix
= bgp_debug_list_remove_entry(
1519 bgp_debug_update_prefixes
, NULL
, argv_p
);
1521 if (list_isempty(bgp_debug_update_prefixes
)) {
1522 if (vty
->node
== CONFIG_NODE
) {
1523 DEBUG_OFF(update
, UPDATE_PREFIX
);
1525 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1527 "BGP updates debugging (per prefix) is off\n");
1533 vty_out(vty
, "BGP updates debugging is off for %pFX\n", argv_p
);
1535 vty_out(vty
, "BGP updates debugging was not enabled for %pFX\n",
1538 prefix_free(&argv_p
);
1544 DEFUN (debug_bgp_update_prefix
,
1545 debug_bgp_update_prefix_cmd
,
1546 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1550 "Specify a prefix to debug\n"
1554 int idx_ipv4_ipv6_prefixlen
= 4;
1555 struct prefix
*argv_p
;
1557 argv_p
= prefix_new();
1558 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1561 if (!bgp_debug_update_prefixes
)
1562 bgp_debug_update_prefixes
= list_new();
1564 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1566 "BGP updates debugging is already enabled for %s\n",
1567 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1571 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1573 if (vty
->node
== CONFIG_NODE
) {
1574 DEBUG_ON(update
, UPDATE_PREFIX
);
1576 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1577 vty_out(vty
, "BGP updates debugging is on for %s\n",
1578 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1584 DEFUN (no_debug_bgp_update_prefix
,
1585 no_debug_bgp_update_prefix_cmd
,
1586 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1591 "Specify a prefix to debug\n"
1595 int idx_ipv4_ipv6_prefixlen
= 5;
1596 struct prefix
*argv_p
;
1597 int found_prefix
= 0;
1599 argv_p
= prefix_new();
1600 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1603 if (bgp_debug_update_prefixes
1604 && !list_isempty(bgp_debug_update_prefixes
)) {
1605 found_prefix
= bgp_debug_list_remove_entry(
1606 bgp_debug_update_prefixes
, NULL
, argv_p
);
1608 if (list_isempty(bgp_debug_update_prefixes
)) {
1609 if (vty
->node
== CONFIG_NODE
) {
1610 DEBUG_OFF(update
, UPDATE_PREFIX
);
1612 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1614 "BGP updates debugging (per prefix) is off\n");
1620 vty_out(vty
, "BGP updates debugging is off for %s\n",
1621 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1623 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1624 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1629 DEFUN (no_debug_bgp_update
,
1630 no_debug_bgp_update_cmd
,
1631 "no debug bgp updates",
1637 struct listnode
*ln
;
1640 bgp_debug_list_free(bgp_debug_update_in_peers
);
1641 bgp_debug_list_free(bgp_debug_update_out_peers
);
1642 bgp_debug_list_free(bgp_debug_update_prefixes
);
1644 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1645 bgp_debug_clear_updgrp_update_dbg(bgp
);
1647 if (vty
->node
== CONFIG_NODE
) {
1648 DEBUG_OFF(update
, UPDATE_IN
);
1649 DEBUG_OFF(update
, UPDATE_OUT
);
1650 DEBUG_OFF(update
, UPDATE_PREFIX
);
1652 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1653 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1654 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1655 vty_out(vty
, "BGP updates debugging is off\n");
1660 /* debug bgp zebra */
1661 DEFUN (debug_bgp_zebra
,
1662 debug_bgp_zebra_cmd
,
1666 "BGP Zebra messages\n")
1668 if (vty
->node
== CONFIG_NODE
)
1669 DEBUG_ON(zebra
, ZEBRA
);
1671 TERM_DEBUG_ON(zebra
, ZEBRA
);
1672 vty_out(vty
, "BGP zebra debugging is on\n");
1677 DEFUN (debug_bgp_graceful_restart
,
1678 debug_bgp_graceful_restart_cmd
,
1679 "debug bgp graceful-restart",
1684 if (vty
->node
== CONFIG_NODE
) {
1685 DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1687 TERM_DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1688 vty_out(vty
, "BGP Graceful Restart debugging is on\n");
1694 DEFUN (debug_bgp_zebra_prefix
,
1695 debug_bgp_zebra_prefix_cmd
,
1696 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1699 "BGP Zebra messages\n"
1700 "Specify a prefix to debug\n"
1704 int idx_ipv4_ipv6_prefixlen
= 4;
1705 struct prefix
*argv_p
;
1707 argv_p
= prefix_new();
1708 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1711 if (!bgp_debug_zebra_prefixes
)
1712 bgp_debug_zebra_prefixes
= list_new();
1714 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1715 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1716 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1720 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1722 if (vty
->node
== CONFIG_NODE
)
1723 DEBUG_ON(zebra
, ZEBRA
);
1725 TERM_DEBUG_ON(zebra
, ZEBRA
);
1726 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1727 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1733 DEFUN (no_debug_bgp_zebra
,
1734 no_debug_bgp_zebra_cmd
,
1735 "no debug bgp zebra",
1739 "BGP Zebra messages\n")
1741 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1743 if (vty
->node
== CONFIG_NODE
)
1744 DEBUG_OFF(zebra
, ZEBRA
);
1746 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1747 vty_out(vty
, "BGP zebra debugging is off\n");
1752 DEFUN (no_debug_bgp_graceful_restart
,
1753 no_debug_bgp_graceful_restart_cmd
,
1754 "no debug bgp graceful-restart",
1760 if (vty
->node
== CONFIG_NODE
) {
1761 DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1763 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1764 vty_out(vty
, "BGP Graceful Restart debugging is off\n");
1769 DEFUN (no_debug_bgp_zebra_prefix
,
1770 no_debug_bgp_zebra_prefix_cmd
,
1771 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1775 "BGP Zebra messages\n"
1776 "Specify a prefix to debug\n"
1780 int idx_ipv4_ipv6_prefixlen
= 5;
1781 struct prefix
*argv_p
;
1782 int found_prefix
= 0;
1784 argv_p
= prefix_new();
1785 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1788 if (bgp_debug_zebra_prefixes
1789 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1790 found_prefix
= bgp_debug_list_remove_entry(
1791 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1793 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1794 if (vty
->node
== CONFIG_NODE
)
1795 DEBUG_OFF(zebra
, ZEBRA
);
1797 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1798 vty_out(vty
, "BGP zebra debugging is off\n");
1804 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1805 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1807 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1808 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1813 /* debug bgp update-groups */
1814 DEFUN (debug_bgp_update_groups
,
1815 debug_bgp_update_groups_cmd
,
1816 "debug bgp update-groups",
1819 "BGP update-groups\n")
1821 if (vty
->node
== CONFIG_NODE
)
1822 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1824 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1825 vty_out(vty
, "BGP update-groups debugging is on\n");
1830 DEFUN (no_debug_bgp_update_groups
,
1831 no_debug_bgp_update_groups_cmd
,
1832 "no debug bgp update-groups",
1836 "BGP update-groups\n")
1838 if (vty
->node
== CONFIG_NODE
)
1839 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1841 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1842 vty_out(vty
, "BGP update-groups debugging is off\n");
1847 DEFUN (debug_bgp_vpn
,
1849 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1853 "leaked from vrf to vpn\n"
1854 "leaked to vrf from vpn\n"
1855 "route-map updates\n"
1860 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1861 if (vty
->node
== CONFIG_NODE
)
1862 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1864 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1865 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1866 if (vty
->node
== CONFIG_NODE
)
1867 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1869 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1870 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1871 if (vty
->node
== CONFIG_NODE
)
1872 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1874 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1875 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1876 if (vty
->node
== CONFIG_NODE
)
1877 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1879 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1881 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1882 return CMD_WARNING_CONFIG_FAILED
;
1885 if (vty
->node
!= CONFIG_NODE
)
1886 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1891 DEFUN (no_debug_bgp_vpn
,
1892 no_debug_bgp_vpn_cmd
,
1893 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1898 "leaked from vrf to vpn\n"
1899 "leaked to vrf from vpn\n"
1900 "route-map updates\n"
1905 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1906 if (vty
->node
== CONFIG_NODE
)
1907 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1909 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1911 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1912 if (vty
->node
== CONFIG_NODE
)
1913 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1915 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1916 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1917 if (vty
->node
== CONFIG_NODE
)
1918 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1920 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1921 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1922 if (vty
->node
== CONFIG_NODE
)
1923 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1925 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1927 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1928 return CMD_WARNING_CONFIG_FAILED
;
1931 if (vty
->node
!= CONFIG_NODE
)
1932 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1937 DEFUN (debug_bgp_pbr
,
1939 "debug bgp pbr [error]",
1942 "BGP policy based routing\n"
1947 if (argv_find(argv
, argc
, "error", &idx
)) {
1948 if (vty
->node
== CONFIG_NODE
)
1949 DEBUG_ON(pbr
, PBR_ERROR
);
1951 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1952 vty_out(vty
, "BGP policy based routing error is on\n");
1956 if (vty
->node
== CONFIG_NODE
)
1959 TERM_DEBUG_ON(pbr
, PBR
);
1960 vty_out(vty
, "BGP policy based routing is on\n");
1965 DEFUN (no_debug_bgp_pbr
,
1966 no_debug_bgp_pbr_cmd
,
1967 "no debug bgp pbr [error]",
1971 "BGP policy based routing\n"
1976 if (argv_find(argv
, argc
, "error", &idx
)) {
1977 if (vty
->node
== CONFIG_NODE
)
1978 DEBUG_OFF(pbr
, PBR_ERROR
);
1980 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1981 vty_out(vty
, "BGP policy based routing error is off\n");
1985 if (vty
->node
== CONFIG_NODE
)
1986 DEBUG_OFF(pbr
, PBR
);
1988 TERM_DEBUG_OFF(pbr
, PBR
);
1989 vty_out(vty
, "BGP policy based routing is off\n");
1994 DEFPY (debug_bgp_evpn_mh
,
1995 debug_bgp_evpn_mh_cmd
,
1996 "[no$no] debug bgp evpn mh <es$es|route$rt>",
2002 "Ethernet Segment debugging\n"
2003 "Route debugging\n")
2006 if (vty
->node
== CONFIG_NODE
) {
2008 DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2010 DEBUG_ON(evpn_mh
, EVPN_MH_ES
);
2013 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2015 "BGP EVPN-MH ES debugging is off\n");
2017 TERM_DEBUG_ON(evpn_mh
, EVPN_MH_ES
);
2019 "BGP EVPN-MH ES debugging is on\n");
2024 if (vty
->node
== CONFIG_NODE
) {
2026 DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2028 DEBUG_ON(evpn_mh
, EVPN_MH_RT
);
2031 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2033 "BGP EVPN-MH route debugging is off\n");
2035 TERM_DEBUG_ON(evpn_mh
, EVPN_MH_RT
);
2037 "BGP EVPN-MH route debugging is on\n");
2045 DEFUN (debug_bgp_labelpool
,
2046 debug_bgp_labelpool_cmd
,
2047 "debug bgp labelpool",
2052 if (vty
->node
== CONFIG_NODE
)
2053 DEBUG_ON(labelpool
, LABELPOOL
);
2055 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
2057 if (vty
->node
!= CONFIG_NODE
)
2058 vty_out(vty
, "enabled debug bgp labelpool\n");
2063 DEFUN (no_debug_bgp_labelpool
,
2064 no_debug_bgp_labelpool_cmd
,
2065 "no debug bgp labelpool",
2071 if (vty
->node
== CONFIG_NODE
)
2072 DEBUG_OFF(labelpool
, LABELPOOL
);
2074 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2077 if (vty
->node
!= CONFIG_NODE
)
2078 vty_out(vty
, "disabled debug bgp labelpool\n");
2083 DEFPY(debug_bgp_bfd
, debug_bgp_bfd_cmd
,
2084 "[no] debug bgp bfd",
2088 "Bidirection Forwarding Detection\n")
2090 if (vty
->node
== CONFIG_NODE
) {
2092 DEBUG_OFF(bfd
, BFD_LIB
);
2093 bfd_protocol_integration_set_debug(false);
2095 DEBUG_ON(bfd
, BFD_LIB
);
2096 bfd_protocol_integration_set_debug(true);
2100 TERM_DEBUG_OFF(bfd
, BFD_LIB
);
2101 bfd_protocol_integration_set_debug(false);
2103 TERM_DEBUG_ON(bfd
, BFD_LIB
);
2104 bfd_protocol_integration_set_debug(true);
2111 DEFUN (no_debug_bgp
,
2119 struct listnode
*ln
;
2121 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2122 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2123 bgp_debug_list_free(bgp_debug_update_in_peers
);
2124 bgp_debug_list_free(bgp_debug_update_out_peers
);
2125 bgp_debug_list_free(bgp_debug_update_prefixes
);
2126 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2127 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2129 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2130 bgp_debug_clear_updgrp_update_dbg(bgp
);
2132 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2133 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2134 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2135 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2136 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2137 TERM_DEBUG_OFF(as4
, AS4
);
2138 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2139 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2140 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2141 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2142 TERM_DEBUG_OFF(nht
, NHT
);
2143 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2144 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2145 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2146 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2147 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2148 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2149 TERM_DEBUG_OFF(pbr
, PBR
);
2150 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2151 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
2152 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2153 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2154 TERM_DEBUG_OFF(bfd
, BFD_LIB
);
2156 vty_out(vty
, "All possible debugging has been turned off\n");
2161 DEFUN_NOSH (show_debugging_bgp
,
2162 show_debugging_bgp_cmd
,
2163 "show debugging [bgp]",
2168 vty_out(vty
, "BGP debugging status:\n");
2170 if (BGP_DEBUG(as4
, AS4
))
2171 vty_out(vty
, " BGP as4 debugging is on\n");
2173 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2174 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2176 if (BGP_DEBUG(bestpath
, BESTPATH
))
2177 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2178 bgp_debug_bestpath_prefixes
);
2180 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2181 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2182 bgp_debug_keepalive_peers
);
2184 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2185 bgp_debug_list_print(vty
,
2186 " BGP neighbor-events debugging is on",
2187 bgp_debug_neighbor_events_peers
);
2189 if (BGP_DEBUG(nht
, NHT
))
2190 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2192 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2193 vty_out(vty
, " BGP update-groups debugging is on\n");
2195 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2196 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2197 bgp_debug_update_prefixes
);
2199 if (BGP_DEBUG(update
, UPDATE_IN
))
2200 bgp_debug_list_print(vty
,
2201 " BGP updates debugging is on (inbound)",
2202 bgp_debug_update_in_peers
);
2204 if (BGP_DEBUG(update
, UPDATE_OUT
))
2205 bgp_debug_list_print(vty
,
2206 " BGP updates debugging is on (outbound)",
2207 bgp_debug_update_out_peers
);
2209 if (BGP_DEBUG(zebra
, ZEBRA
))
2210 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2211 bgp_debug_zebra_prefixes
);
2213 if (BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
))
2214 vty_out(vty
, " BGP graceful-restart debugging is on\n");
2216 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2217 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2219 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2221 " BGP route leak from vrf to vpn debugging is on\n");
2222 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2224 " BGP route leak to vrf from vpn debugging is on\n");
2225 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2226 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2227 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2228 vty_out(vty
, " BGP vpn label event debugging is on\n");
2229 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2230 vty_out(vty
, " BGP flowspec debugging is on\n");
2231 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2232 vty_out(vty
, " BGP labelpool debugging is on\n");
2234 if (BGP_DEBUG(pbr
, PBR
))
2235 vty_out(vty
, " BGP policy based routing debugging is on\n");
2236 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2237 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2239 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2240 vty_out(vty
, " BGP EVPN-MH ES debugging is on\n");
2241 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
2242 vty_out(vty
, " BGP EVPN-MH route debugging is on\n");
2244 if (BGP_DEBUG(bfd
, BFD_LIB
))
2245 vty_out(vty
, " BGP BFD library debugging is on\n");
2250 static int bgp_config_write_debug(struct vty
*vty
)
2254 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2255 vty_out(vty
, "debug bgp as4\n");
2259 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2260 vty_out(vty
, "debug bgp as4 segment\n");
2264 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2265 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2266 bgp_debug_bestpath_prefixes
);
2269 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2270 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2271 bgp_debug_keepalive_peers
);
2274 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2275 write
+= bgp_debug_list_conf_print(
2276 vty
, "debug bgp neighbor-events",
2277 bgp_debug_neighbor_events_peers
);
2280 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2281 vty_out(vty
, "debug bgp nht\n");
2285 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2286 vty_out(vty
, "debug bgp update-groups\n");
2290 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2291 write
+= bgp_debug_list_conf_print(vty
,
2292 "debug bgp updates prefix",
2293 bgp_debug_update_prefixes
);
2296 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2297 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2298 bgp_debug_update_in_peers
);
2301 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2302 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2303 bgp_debug_update_out_peers
);
2306 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2307 if (!bgp_debug_zebra_prefixes
2308 || list_isempty(bgp_debug_zebra_prefixes
)) {
2309 vty_out(vty
, "debug bgp zebra\n");
2312 write
+= bgp_debug_list_conf_print(
2313 vty
, "debug bgp zebra prefix",
2314 bgp_debug_zebra_prefixes
);
2318 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2319 vty_out(vty
, "debug bgp allow-martians\n");
2323 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2324 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2327 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2328 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2331 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2332 vty_out(vty
, "debug bgp vpn rmap-event\n");
2335 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2336 vty_out(vty
, "debug bgp vpn label\n");
2339 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2340 vty_out(vty
, "debug bgp flowspec\n");
2343 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2344 vty_out(vty
, "debug bgp labelpool\n");
2348 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2349 vty_out(vty
, "debug bgp pbr\n");
2352 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2353 vty_out(vty
, "debug bgp pbr error\n");
2357 if (CONF_BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
)) {
2358 vty_out(vty
, "debug bgp graceful-restart\n");
2362 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_ES
)) {
2363 vty_out(vty
, "debug bgp evpn mh es\n");
2366 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
2367 vty_out(vty
, "debug bgp evpn mh route\n");
2371 if (CONF_BGP_DEBUG(bfd
, BFD_LIB
)) {
2372 vty_out(vty
, "debug bgp bfd\n");
2379 static int bgp_config_write_debug(struct vty
*vty
);
2380 static struct cmd_node debug_node
= {
2384 .config_write
= bgp_config_write_debug
,
2387 void bgp_debug_init(void)
2389 install_node(&debug_node
);
2391 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2393 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2394 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2395 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2396 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2398 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2399 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2400 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2401 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2402 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2403 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2404 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2405 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2406 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2407 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2408 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2409 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2410 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2411 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2413 install_element(ENABLE_NODE
, &debug_bgp_graceful_restart_cmd
);
2414 install_element(CONFIG_NODE
, &debug_bgp_graceful_restart_cmd
);
2416 /* debug bgp updates (in|out) */
2417 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2418 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2419 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2420 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2422 /* debug bgp updates (in|out) A.B.C.D */
2423 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2424 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2425 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2426 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2428 /* debug bgp updates prefix A.B.C.D/M */
2429 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2430 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2431 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2432 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2433 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2434 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2435 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2436 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2438 /* debug bgp zebra prefix A.B.C.D/M */
2439 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2440 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2441 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2442 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2444 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2445 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2446 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2447 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2449 /* debug bgp neighbor-events A.B.C.D */
2450 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2451 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2452 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2453 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2455 /* debug bgp keepalive A.B.C.D */
2456 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2457 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2458 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2459 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2461 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2462 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2463 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2464 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2465 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2466 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2467 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2468 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2469 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2470 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2471 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2472 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2473 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2474 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2475 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2476 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2477 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2479 install_element(ENABLE_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2480 install_element(CONFIG_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2482 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2483 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2484 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2485 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2487 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2488 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2489 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2490 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2493 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2494 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2495 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2496 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2498 install_element(ENABLE_NODE
, &debug_bgp_evpn_mh_cmd
);
2499 install_element(CONFIG_NODE
, &debug_bgp_evpn_mh_cmd
);
2502 install_element(ENABLE_NODE
, &debug_bgp_bfd_cmd
);
2503 install_element(CONFIG_NODE
, &debug_bgp_bfd_cmd
);
2506 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2507 * for BGP_DEBUG_TYPE
2509 static int bgp_debug_per_prefix(const struct prefix
*p
,
2510 unsigned long term_bgp_debug_type
,
2511 unsigned int BGP_DEBUG_TYPE
,
2512 struct list
*per_prefix_list
)
2514 struct bgp_debug_filter
*filter
;
2515 struct listnode
*node
, *nnode
;
2517 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2518 /* We are debugging all prefixes so return true */
2519 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2526 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2528 if (filter
->p
->prefixlen
== p
->prefixlen
2529 && prefix_match(filter
->p
, p
))
2539 /* Return true if this peer is on the per_peer_list of peers to debug
2540 * for BGP_DEBUG_TYPE
2542 static bool bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2543 unsigned int BGP_DEBUG_TYPE
,
2544 struct list
*per_peer_list
)
2546 struct bgp_debug_filter
*filter
;
2547 struct listnode
*node
, *nnode
;
2549 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2550 /* We are debugging all peers so return true */
2551 if (!per_peer_list
|| list_isempty(per_peer_list
))
2558 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2560 if (strcmp(filter
->host
, host
) == 0)
2570 bool bgp_debug_neighbor_events(const struct peer
*peer
)
2577 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2578 BGP_DEBUG_NEIGHBOR_EVENTS
,
2579 bgp_debug_neighbor_events_peers
);
2582 bool bgp_debug_keepalive(const struct peer
*peer
)
2589 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2590 BGP_DEBUG_KEEPALIVE
,
2591 bgp_debug_keepalive_peers
);
2594 bool bgp_debug_update(const struct peer
*peer
, const struct prefix
*p
,
2595 struct update_group
*updgrp
, unsigned int inbound
)
2603 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2604 BGP_DEBUG_UPDATE_IN
,
2605 bgp_debug_update_in_peers
))
2611 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2612 BGP_DEBUG_UPDATE_OUT
,
2613 bgp_debug_update_out_peers
))
2616 /* Check if update debugging implicitly enabled for the group.
2618 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2623 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2624 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2625 BGP_DEBUG_UPDATE_PREFIX
,
2626 bgp_debug_update_prefixes
))
2633 bool bgp_debug_bestpath(struct bgp_dest
*dest
)
2635 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2636 if (bgp_debug_per_prefix(
2637 bgp_dest_get_prefix(dest
), term_bgp_debug_bestpath
,
2638 BGP_DEBUG_BESTPATH
, bgp_debug_bestpath_prefixes
))
2645 bool bgp_debug_zebra(const struct prefix
*p
)
2647 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2648 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2650 bgp_debug_zebra_prefixes
))
2657 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2658 const struct prefix_rd
*prd
,
2659 union prefixconstptr pu
,
2660 mpls_label_t
*label
, uint32_t num_labels
,
2661 int addpath_valid
, uint32_t addpath_id
,
2662 struct bgp_route_evpn
*overlay_index
,
2663 char *str
, int size
)
2666 char overlay_index_buf
[INET6_ADDRSTRLEN
+ 14];
2667 const struct prefix_evpn
*evp
;
2669 /* ' with addpath ID ' 17
2670 * max strlen of uint32 + 10
2671 * +/- (just in case) + 1
2672 * null terminator + 1
2673 * ============================ 29 */
2674 char pathid_buf
[30];
2676 if (size
< BGP_PRD_PATH_STRLEN
)
2679 /* Note: Path-id is created by default, but only included in update
2681 pathid_buf
[0] = '\0';
2683 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2686 overlay_index_buf
[0] = '\0';
2687 if (overlay_index
&& overlay_index
->type
== OVERLAY_INDEX_GATEWAY_IP
) {
2688 char obuf
[INET6_ADDRSTRLEN
];
2692 if (is_evpn_prefix_ipaddr_v4(evp
))
2693 inet_ntop(AF_INET
, &overlay_index
->gw_ip
, obuf
,
2695 else if (is_evpn_prefix_ipaddr_v6(evp
))
2696 inet_ntop(AF_INET6
, &overlay_index
->gw_ip
, obuf
,
2699 snprintf(overlay_index_buf
, sizeof(overlay_index_buf
),
2700 " gateway IP %s", obuf
);
2704 if (bgp_labeled_safi(safi
) && num_labels
) {
2706 if (safi
== SAFI_EVPN
) {
2709 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2710 snprintf(tag_buf
, sizeof(tag_buf
), " label %s",
2713 uint32_t label_value
;
2715 label_value
= decode_label(label
);
2716 snprintf(tag_buf
, sizeof(tag_buf
), " label %u",
2722 snprintfrr(str
, size
, "RD %pRD %pFX%s%s%s %s %s", prd
, pu
.p
,
2723 overlay_index_buf
, tag_buf
, pathid_buf
, afi2str(afi
),
2725 else if (safi
== SAFI_FLOWSPEC
) {
2726 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2727 const struct prefix_fs
*fs
= pu
.fs
;
2729 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2730 fs
->prefix
.prefixlen
,
2732 NLRI_STRING_FORMAT_DEBUG
, NULL
,
2733 family2afi(fs
->prefix
.family
));
2734 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2737 snprintfrr(str
, size
, "%pFX%s%s %s %s", pu
.p
, tag_buf
,
2738 pathid_buf
, afi2str(afi
), safi2str(safi
));