1 /* BGP-4, BGP-4+ packet debug routine
2 * Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <lib/version.h>
29 #include "sockunion.h"
34 #include "bgpd/bgpd.h"
35 #include "bgpd/bgp_aspath.h"
36 #include "bgpd/bgp_route.h"
37 #include "bgpd/bgp_attr.h"
38 #include "bgpd/bgp_debug.h"
39 #include "bgpd/bgp_community.h"
40 #include "bgpd/bgp_updgrp.h"
41 #include "bgpd/bgp_mplsvpn.h"
42 #include "bgpd/bgp_ecommunity.h"
43 #include "bgpd/bgp_label.h"
44 #include "bgpd/bgp_evpn.h"
45 #include "bgpd/bgp_evpn_private.h"
46 #include "bgpd/bgp_evpn_vty.h"
47 #include "bgpd/bgp_vty.h"
48 #include "bgpd/bgp_flowspec.h"
50 unsigned long conf_bgp_debug_as4
;
51 unsigned long conf_bgp_debug_neighbor_events
;
52 unsigned long conf_bgp_debug_events
;
53 unsigned long conf_bgp_debug_packet
;
54 unsigned long conf_bgp_debug_filter
;
55 unsigned long conf_bgp_debug_keepalive
;
56 unsigned long conf_bgp_debug_update
;
57 unsigned long conf_bgp_debug_bestpath
;
58 unsigned long conf_bgp_debug_zebra
;
59 unsigned long conf_bgp_debug_allow_martians
;
60 unsigned long conf_bgp_debug_nht
;
61 unsigned long conf_bgp_debug_update_groups
;
62 unsigned long conf_bgp_debug_vpn
;
63 unsigned long conf_bgp_debug_flowspec
;
64 unsigned long conf_bgp_debug_labelpool
;
65 unsigned long conf_bgp_debug_pbr
;
66 unsigned long conf_bgp_debug_graceful_restart
;
67 unsigned long conf_bgp_debug_evpn_mh
;
69 unsigned long term_bgp_debug_as4
;
70 unsigned long term_bgp_debug_neighbor_events
;
71 unsigned long term_bgp_debug_events
;
72 unsigned long term_bgp_debug_packet
;
73 unsigned long term_bgp_debug_filter
;
74 unsigned long term_bgp_debug_keepalive
;
75 unsigned long term_bgp_debug_update
;
76 unsigned long term_bgp_debug_bestpath
;
77 unsigned long term_bgp_debug_zebra
;
78 unsigned long term_bgp_debug_allow_martians
;
79 unsigned long term_bgp_debug_nht
;
80 unsigned long term_bgp_debug_update_groups
;
81 unsigned long term_bgp_debug_vpn
;
82 unsigned long term_bgp_debug_flowspec
;
83 unsigned long term_bgp_debug_labelpool
;
84 unsigned long term_bgp_debug_pbr
;
85 unsigned long term_bgp_debug_graceful_restart
;
86 unsigned long term_bgp_debug_evpn_mh
;
88 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
89 struct list
*bgp_debug_keepalive_peers
= NULL
;
90 struct list
*bgp_debug_update_out_peers
= NULL
;
91 struct list
*bgp_debug_update_in_peers
= NULL
;
92 struct list
*bgp_debug_update_prefixes
= NULL
;
93 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
94 struct list
*bgp_debug_zebra_prefixes
= NULL
;
96 /* messages for BGP-4 status */
97 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
100 {OpenSent
, "OpenSent"},
101 {OpenConfirm
, "OpenConfirm"},
102 {Established
, "Established"},
103 {Clearing
, "Clearing"},
104 {Deleted
, "Deleted"},
107 /* BGP message type string. */
108 const char *const bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
109 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
112 /* message for BGP-4 Notify */
113 static const struct message bgp_notify_msg
[] = {
114 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
115 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
116 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
117 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
118 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
119 {BGP_NOTIFY_CEASE
, "Cease"},
120 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
123 static const struct message bgp_notify_head_msg
[] = {
124 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
125 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
126 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
129 static const struct message bgp_notify_open_msg
[] = {
130 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
131 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
132 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
133 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
134 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
135 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
136 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
137 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
140 static const struct message bgp_notify_update_msg
[] = {
141 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
142 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
143 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
144 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
145 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
146 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
147 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
148 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
149 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
150 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
151 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
152 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
155 static const struct message bgp_notify_cease_msg
[] = {
156 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
157 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
158 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
159 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
160 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
161 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
162 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
163 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
164 "/Connection collision resolution"},
165 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
168 static const struct message bgp_notify_capability_msg
[] = {
169 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
170 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
171 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
172 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
175 static const struct message bgp_notify_fsm_msg
[] = {
176 {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC
, "/Unspecific"},
177 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT
,
178 "/Receive Unexpected Message in OpenSent State"},
179 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM
,
180 "/Receive Unexpected Message in OpenConfirm State"},
181 {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED
,
182 "/Receive Unexpected Message in Established State"},
185 /* Origin strings. */
186 const char *const bgp_origin_str
[] = {"i", "e", "?"};
187 const char *const bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
189 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
191 /* Given a string return a pointer the corresponding peer structure */
192 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
194 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
202 ret
= str2sockunion(peer_str
, &su
);
206 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
209 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
213 return peer_lookup(bgp
, &su
);
216 static void bgp_debug_list_free(struct list
*list
)
218 struct bgp_debug_filter
*filter
;
219 struct listnode
*node
, *nnode
;
222 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
223 listnode_delete(list
, filter
);
224 prefix_free(&filter
->p
);
225 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
226 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
231 * Print the desc along with a list of peers/prefixes this debug is
234 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
237 struct bgp_debug_filter
*filter
;
238 struct listnode
*node
, *nnode
;
239 char buf
[PREFIX2STR_BUFFER
];
241 vty_out(vty
, "%s", desc
);
243 if (list
&& !list_isempty(list
)) {
244 vty_out(vty
, " for");
245 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
247 vty_out(vty
, " %s", filter
->host
);
249 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
250 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
251 else if (filter
->p
) {
252 prefix2str(filter
->p
, buf
, sizeof(buf
));
253 vty_out(vty
, " %s", buf
);
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
;
270 char buf
[PREFIX2STR_BUFFER
];
273 if (list
&& !list_isempty(list
)) {
274 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
276 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
280 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
281 bgp_debug_print_evpn_prefix(vty
, desc
,
284 } else if (filter
->p
) {
285 prefix2str(filter
->p
, buf
, sizeof(buf
));
286 vty_out(vty
, "%s %s\n", desc
, buf
);
293 vty_out(vty
, "%s\n", desc
);
300 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
301 const struct prefix
*p
)
303 struct bgp_debug_filter
*filter
;
305 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
306 sizeof(struct bgp_debug_filter
));
309 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
313 filter
->p
= prefix_new();
314 prefix_copy(filter
->p
, p
);
317 listnode_add(list
, filter
);
320 static bool bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
323 struct bgp_debug_filter
*filter
;
324 struct listnode
*node
, *nnode
;
326 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
327 if (host
&& strcmp(filter
->host
, host
) == 0) {
328 listnode_delete(list
, filter
);
329 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
330 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
332 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
333 && prefix_match(filter
->p
, p
)) {
334 listnode_delete(list
, filter
);
335 prefix_free(&filter
->p
);
336 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
344 static bool bgp_debug_list_has_entry(struct list
*list
, const char *host
,
345 const struct prefix
*p
)
347 struct bgp_debug_filter
*filter
;
348 struct listnode
*node
, *nnode
;
350 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
352 if (strcmp(filter
->host
, host
) == 0) {
356 if (filter
->p
->prefixlen
== p
->prefixlen
357 && prefix_match(filter
->p
, p
)) {
366 bool bgp_debug_peer_updout_enabled(char *host
)
368 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
372 /* Dump attribute. */
373 bool bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
375 char addrbuf
[BUFSIZ
];
382 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
383 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
385 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
386 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
387 bgp_origin_str
[attr
->origin
]);
390 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
391 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
392 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
394 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
397 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
398 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
399 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
402 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
403 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
405 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
406 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
407 ", localpref %u", attr
->local_pref
);
409 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
410 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
413 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
414 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
416 community_str(attr
->community
, false));
418 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
419 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
420 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
422 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
423 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
424 ", atomic-aggregate");
426 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
427 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
428 ", aggregated by %u %s", attr
->aggregator_as
,
429 inet_ntoa(attr
->aggregator_addr
));
431 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
432 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
433 ", originator %s", inet_ntoa(attr
->originator_id
));
435 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
438 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
440 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
441 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
442 inet_ntoa(attr
->cluster
->list
[i
]));
445 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
446 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
447 ", pmsi tnltype %u", attr
->pmsi_tnl_type
);
449 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
450 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
451 aspath_print(attr
->aspath
));
453 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
454 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
455 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
456 ", label-index %u", attr
->label_index
);
465 const char *bgp_notify_code_str(char code
)
467 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
470 const char *bgp_notify_subcode_str(char code
, char subcode
)
474 case BGP_NOTIFY_HEADER_ERR
:
475 return lookup_msg(bgp_notify_head_msg
, subcode
,
476 "Unrecognized Error Subcode");
477 case BGP_NOTIFY_OPEN_ERR
:
478 return lookup_msg(bgp_notify_open_msg
, subcode
,
479 "Unrecognized Error Subcode");
480 case BGP_NOTIFY_UPDATE_ERR
:
481 return lookup_msg(bgp_notify_update_msg
, subcode
,
482 "Unrecognized Error Subcode");
483 case BGP_NOTIFY_HOLD_ERR
:
485 case BGP_NOTIFY_FSM_ERR
:
486 return lookup_msg(bgp_notify_fsm_msg
, subcode
,
487 "Unrecognized Error Subcode");
488 case BGP_NOTIFY_CEASE
:
489 return lookup_msg(bgp_notify_cease_msg
, subcode
,
490 "Unrecognized Error Subcode");
491 case BGP_NOTIFY_CAPABILITY_ERR
:
492 return lookup_msg(bgp_notify_capability_msg
, subcode
,
493 "Unrecognized Error Subcode");
498 /* extract notify admin reason if correctly present */
499 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
502 if (!data
|| datalen
< 1)
505 uint8_t len
= data
[0];
506 if (len
> 128 || len
> datalen
- 1)
509 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
512 /* dump notify packet */
513 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
516 const char *subcode_str
;
517 const char *code_str
;
518 const char *msg_str
= NULL
;
521 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
522 || CHECK_FLAG(peer
->bgp
->flags
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
523 code_str
= bgp_notify_code_str(bgp_notify
->code
);
524 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
525 bgp_notify
->subcode
);
527 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
528 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
529 || bgp_notify
->subcode
530 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
531 msg_str
= bgp_notify_admin_message(
532 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
538 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
539 strcmp(direct
, "received") == 0
542 peer
->host
, bgp_notify
->code
,
543 bgp_notify
->subcode
, code_str
, subcode_str
,
546 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
548 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
549 strcmp(direct
, "received") == 0
552 peer
->host
, bgp_notify
->code
,
553 bgp_notify
->subcode
, code_str
, subcode_str
,
554 bgp_notify
->length
, msg_str
);
559 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
562 bgp
= bgp_get_default();
563 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
566 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
569 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
570 char buf
[PREFIX2STR_BUFFER
];
571 char buf2
[ETHER_ADDR_STRLEN
];
573 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
574 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
576 evpn_desc
, sizeof(evpn_desc
),
577 "l2vpn evpn type macip mac %s",
578 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
579 buf2
, sizeof(buf2
)));
581 uint8_t family
= is_evpn_prefix_ipaddr_v4(
582 (struct prefix_evpn
*)p
) ?
585 evpn_desc
, sizeof(evpn_desc
),
586 "l2vpn evpn type macip mac %s ip %s",
587 prefix_mac2str(&p
->u
.prefix_evpn
.macip_addr
.mac
,
591 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
592 buf
, PREFIX2STR_BUFFER
));
594 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
595 snprintf(evpn_desc
, sizeof(evpn_desc
),
596 "l2vpn evpn type multicast ip %s",
597 inet_ntoa(p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
));
598 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
599 uint8_t family
= is_evpn_prefix_ipaddr_v4(
600 (struct prefix_evpn
*)p
) ? AF_INET
602 snprintf(evpn_desc
, sizeof(evpn_desc
),
603 "l2vpn evpn type prefix ip %s/%d",
605 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
,
606 buf
, PREFIX2STR_BUFFER
),
607 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
610 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
613 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
614 int argc
, struct prefix
**argv_pp
)
616 struct prefix
*argv_p
;
625 if (bgp_evpn_cli_parse_type(&evpn_type
, argv
, argc
) < 0)
628 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
629 memset(&ip
, 0, sizeof(struct ipaddr
));
631 argv_find(argv
, argc
, "mac", &mac_idx
);
632 (void)prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
);
634 argv_find(argv
, argc
, "ip", &ip_idx
);
635 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
637 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
639 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
640 memset(&ip
, 0, sizeof(struct ipaddr
));
642 argv_find(argv
, argc
, "ip", &ip_idx
);
643 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
645 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
647 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
648 struct prefix ip_prefix
;
650 memset(&ip_prefix
, 0, sizeof(struct prefix
));
651 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
652 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
653 apply_mask(&ip_prefix
);
655 build_type5_prefix_from_ip_prefix(
656 (struct prefix_evpn
*)argv_p
,
663 /* Debug option setting interface. */
664 unsigned long bgp_debug_option
= 0;
666 int debug(unsigned int option
)
668 return bgp_debug_option
& option
;
671 DEFUN (debug_bgp_as4
,
678 if (vty
->node
== CONFIG_NODE
)
681 TERM_DEBUG_ON(as4
, AS4
);
682 vty_out(vty
, "BGP as4 debugging is on\n");
687 DEFUN (no_debug_bgp_as4
,
688 no_debug_bgp_as4_cmd
,
695 if (vty
->node
== CONFIG_NODE
)
698 TERM_DEBUG_OFF(as4
, AS4
);
699 vty_out(vty
, "BGP as4 debugging is off\n");
704 DEFUN (debug_bgp_as4_segment
,
705 debug_bgp_as4_segment_cmd
,
706 "debug bgp as4 segment",
710 "BGP AS4 aspath segment handling\n")
712 if (vty
->node
== CONFIG_NODE
)
713 DEBUG_ON(as4
, AS4_SEGMENT
);
715 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
716 vty_out(vty
, "BGP as4 segment debugging is on\n");
721 DEFUN (no_debug_bgp_as4_segment
,
722 no_debug_bgp_as4_segment_cmd
,
723 "no debug bgp as4 segment",
728 "BGP AS4 aspath segment handling\n")
730 if (vty
->node
== CONFIG_NODE
)
731 DEBUG_OFF(as4
, AS4_SEGMENT
);
733 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
734 vty_out(vty
, "BGP as4 segment debugging is off\n");
739 /* debug bgp neighbor_events */
740 DEFUN (debug_bgp_neighbor_events
,
741 debug_bgp_neighbor_events_cmd
,
742 "debug bgp neighbor-events",
745 "BGP Neighbor Events\n")
747 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
749 if (vty
->node
== CONFIG_NODE
)
750 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
752 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
753 vty_out(vty
, "BGP neighbor-events debugging is on\n");
758 DEFUN (debug_bgp_neighbor_events_peer
,
759 debug_bgp_neighbor_events_peer_cmd
,
760 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
763 "BGP Neighbor Events\n"
764 "BGP neighbor IP address to debug\n"
765 "BGP IPv6 neighbor to debug\n"
766 "BGP neighbor on interface to debug\n")
769 const char *host
= argv
[idx_peer
]->arg
;
771 if (!bgp_debug_neighbor_events_peers
)
772 bgp_debug_neighbor_events_peers
= list_new();
774 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
777 "BGP neighbor-events debugging is already enabled for %s\n",
782 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
784 if (vty
->node
== CONFIG_NODE
)
785 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
787 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
788 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
794 DEFUN (no_debug_bgp_neighbor_events
,
795 no_debug_bgp_neighbor_events_cmd
,
796 "no debug bgp neighbor-events",
802 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
804 if (vty
->node
== CONFIG_NODE
)
805 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
807 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
808 vty_out(vty
, "BGP neighbor-events debugging is off\n");
813 DEFUN (no_debug_bgp_neighbor_events_peer
,
814 no_debug_bgp_neighbor_events_peer_cmd
,
815 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
820 "BGP neighbor IP address to debug\n"
821 "BGP IPv6 neighbor to debug\n"
822 "BGP neighbor on interface to debug\n")
826 const char *host
= argv
[idx_peer
]->arg
;
828 if (bgp_debug_neighbor_events_peers
829 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
830 found_peer
= bgp_debug_list_remove_entry(
831 bgp_debug_neighbor_events_peers
, host
, NULL
);
833 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
834 if (vty
->node
== CONFIG_NODE
)
835 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
837 TERM_DEBUG_OFF(neighbor_events
,
843 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
847 "BGP neighbor-events debugging was not enabled for %s\n",
854 DEFUN (debug_bgp_nht
,
859 "BGP nexthop tracking events\n")
861 if (vty
->node
== CONFIG_NODE
)
864 TERM_DEBUG_ON(nht
, NHT
);
865 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
870 DEFUN (no_debug_bgp_nht
,
871 no_debug_bgp_nht_cmd
,
876 "BGP nexthop tracking events\n")
878 if (vty
->node
== CONFIG_NODE
)
881 TERM_DEBUG_OFF(nht
, NHT
);
882 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
887 /* debug bgp keepalives */
888 DEFUN (debug_bgp_keepalive
,
889 debug_bgp_keepalive_cmd
,
890 "debug bgp keepalives",
895 bgp_debug_list_free(bgp_debug_keepalive_peers
);
897 if (vty
->node
== CONFIG_NODE
)
898 DEBUG_ON(keepalive
, KEEPALIVE
);
900 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
901 vty_out(vty
, "BGP keepalives debugging is on\n");
906 DEFUN (debug_bgp_keepalive_peer
,
907 debug_bgp_keepalive_peer_cmd
,
908 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
911 "BGP Neighbor Events\n"
912 "BGP neighbor IP address to debug\n"
913 "BGP IPv6 neighbor to debug\n"
914 "BGP neighbor on interface to debug\n")
917 const char *host
= argv
[idx_peer
]->arg
;
919 if (!bgp_debug_keepalive_peers
)
920 bgp_debug_keepalive_peers
= list_new();
922 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
924 "BGP keepalive debugging is already enabled for %s\n",
929 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
931 if (vty
->node
== CONFIG_NODE
)
932 DEBUG_ON(keepalive
, KEEPALIVE
);
934 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
935 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
940 DEFUN (no_debug_bgp_keepalive
,
941 no_debug_bgp_keepalive_cmd
,
942 "no debug bgp keepalives",
948 bgp_debug_list_free(bgp_debug_keepalive_peers
);
950 if (vty
->node
== CONFIG_NODE
)
951 DEBUG_OFF(keepalive
, KEEPALIVE
);
953 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
954 vty_out(vty
, "BGP keepalives debugging is off\n");
959 DEFUN (no_debug_bgp_keepalive_peer
,
960 no_debug_bgp_keepalive_peer_cmd
,
961 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
966 "BGP neighbor IP address to debug\n"
967 "BGP IPv6 neighbor to debug\n"
968 "BGP neighbor on interface to debug\n")
972 const char *host
= argv
[idx_peer
]->arg
;
974 if (bgp_debug_keepalive_peers
975 && !list_isempty(bgp_debug_keepalive_peers
)) {
976 found_peer
= bgp_debug_list_remove_entry(
977 bgp_debug_keepalive_peers
, host
, NULL
);
979 if (list_isempty(bgp_debug_keepalive_peers
)) {
980 if (vty
->node
== CONFIG_NODE
)
981 DEBUG_OFF(keepalive
, KEEPALIVE
);
983 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
988 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
991 "BGP keepalives debugging was not enabled for %s\n",
997 /* debug bgp bestpath */
998 DEFUN (debug_bgp_bestpath_prefix
,
999 debug_bgp_bestpath_prefix_cmd
,
1000 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1007 struct prefix
*argv_p
;
1008 int idx_ipv4_ipv6_prefixlen
= 3;
1010 argv_p
= prefix_new();
1011 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1014 if (!bgp_debug_bestpath_prefixes
)
1015 bgp_debug_bestpath_prefixes
= list_new();
1017 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1020 "BGP bestpath debugging is already enabled for %s\n",
1021 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1025 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1027 if (vty
->node
== CONFIG_NODE
) {
1028 DEBUG_ON(bestpath
, BESTPATH
);
1030 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1031 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1032 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1038 DEFUN (no_debug_bgp_bestpath_prefix
,
1039 no_debug_bgp_bestpath_prefix_cmd
,
1040 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1048 int idx_ipv4_ipv6_prefixlen
= 4;
1049 struct prefix
*argv_p
;
1050 int found_prefix
= 0;
1052 argv_p
= prefix_new();
1053 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1056 if (bgp_debug_bestpath_prefixes
1057 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1058 found_prefix
= bgp_debug_list_remove_entry(
1059 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1061 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1062 if (vty
->node
== CONFIG_NODE
) {
1063 DEBUG_OFF(bestpath
, BESTPATH
);
1065 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1067 "BGP bestpath debugging (per prefix) is off\n");
1073 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1074 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1076 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1077 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1082 DEFUN (no_debug_bgp_bestpath
,
1083 no_debug_bgp_bestpath_cmd
,
1084 "no debug bgp bestpath",
1090 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1092 if (vty
->node
== CONFIG_NODE
)
1093 DEBUG_OFF(bestpath
, BESTPATH
);
1095 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1096 vty_out(vty
, "BGP bestpath debugging is off\n");
1101 /* debug bgp updates */
1102 DEFUN (debug_bgp_update
,
1103 debug_bgp_update_cmd
,
1104 "debug bgp updates",
1109 bgp_debug_list_free(bgp_debug_update_in_peers
);
1110 bgp_debug_list_free(bgp_debug_update_out_peers
);
1111 bgp_debug_list_free(bgp_debug_update_prefixes
);
1113 if (vty
->node
== CONFIG_NODE
) {
1114 DEBUG_ON(update
, UPDATE_IN
);
1115 DEBUG_ON(update
, UPDATE_OUT
);
1117 TERM_DEBUG_ON(update
, UPDATE_IN
);
1118 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1119 vty_out(vty
, "BGP updates debugging is on\n");
1124 DEFUN (debug_bgp_update_direct
,
1125 debug_bgp_update_direct_cmd
,
1126 "debug bgp updates <in|out>",
1131 "Outbound updates\n")
1135 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1136 bgp_debug_list_free(bgp_debug_update_in_peers
);
1138 bgp_debug_list_free(bgp_debug_update_out_peers
);
1140 if (vty
->node
== CONFIG_NODE
) {
1141 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1142 DEBUG_ON(update
, UPDATE_IN
);
1144 DEBUG_ON(update
, UPDATE_OUT
);
1146 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1147 TERM_DEBUG_ON(update
, UPDATE_IN
);
1148 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1150 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1152 "BGP updates debugging is on (outbound)\n");
1158 DEFUN (debug_bgp_update_direct_peer
,
1159 debug_bgp_update_direct_peer_cmd
,
1160 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1165 "Outbound updates\n"
1166 "BGP neighbor IP address to debug\n"
1167 "BGP IPv6 neighbor to debug\n"
1168 "BGP neighbor on interface to debug\n")
1172 const char *host
= argv
[idx_peer
]->arg
;
1175 if (!bgp_debug_update_in_peers
)
1176 bgp_debug_update_in_peers
= list_new();
1178 if (!bgp_debug_update_out_peers
)
1179 bgp_debug_update_out_peers
= list_new();
1181 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1187 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1190 "BGP inbound update debugging is already enabled for %s\n",
1197 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1200 "BGP outbound update debugging is already enabled for %s\n",
1207 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1210 struct peer_af
*paf
;
1213 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1215 peer
= bgp_find_peer(vty
, host
);
1218 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1220 paf
= peer
->peer_af_array
[afidx
];
1222 if (PAF_SUBGRP(paf
)) {
1232 if (vty
->node
== CONFIG_NODE
) {
1234 DEBUG_ON(update
, UPDATE_IN
);
1236 DEBUG_ON(update
, UPDATE_OUT
);
1239 TERM_DEBUG_ON(update
, UPDATE_IN
);
1241 "BGP updates debugging is on (inbound) for %s\n",
1242 argv
[idx_peer
]->arg
);
1244 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1246 "BGP updates debugging is on (outbound) for %s\n",
1247 argv
[idx_peer
]->arg
);
1253 DEFUN (no_debug_bgp_update_direct
,
1254 no_debug_bgp_update_direct_cmd
,
1255 "no debug bgp updates <in|out>",
1261 "Outbound updates\n")
1264 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1265 bgp_debug_list_free(bgp_debug_update_in_peers
);
1267 if (vty
->node
== CONFIG_NODE
) {
1268 DEBUG_OFF(update
, UPDATE_IN
);
1270 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1272 "BGP updates debugging is off (inbound)\n");
1275 bgp_debug_list_free(bgp_debug_update_out_peers
);
1277 if (vty
->node
== CONFIG_NODE
) {
1278 DEBUG_OFF(update
, UPDATE_OUT
);
1280 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1282 "BGP updates debugging is off (outbound)\n");
1289 DEFUN (no_debug_bgp_update_direct_peer
,
1290 no_debug_bgp_update_direct_peer_cmd
,
1291 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1297 "Outbound updates\n"
1298 "BGP neighbor IP address to debug\n"
1299 "BGP IPv6 neighbor to debug\n"
1300 "BGP neighbor on interface to debug\n")
1306 const char *host
= argv
[idx_peer
]->arg
;
1308 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1313 if (inbound
&& bgp_debug_update_in_peers
1314 && !list_isempty(bgp_debug_update_in_peers
)) {
1315 found_peer
= bgp_debug_list_remove_entry(
1316 bgp_debug_update_in_peers
, host
, NULL
);
1318 if (list_isempty(bgp_debug_update_in_peers
)) {
1319 if (vty
->node
== CONFIG_NODE
)
1320 DEBUG_OFF(update
, UPDATE_IN
);
1322 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1324 "BGP updates debugging (inbound) is off\n");
1329 if (!inbound
&& bgp_debug_update_out_peers
1330 && !list_isempty(bgp_debug_update_out_peers
)) {
1331 found_peer
= bgp_debug_list_remove_entry(
1332 bgp_debug_update_out_peers
, host
, NULL
);
1334 if (list_isempty(bgp_debug_update_out_peers
)) {
1335 if (vty
->node
== CONFIG_NODE
)
1336 DEBUG_OFF(update
, UPDATE_OUT
);
1338 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1340 "BGP updates debugging (outbound) is off\n");
1345 struct peer_af
*paf
;
1347 peer
= bgp_find_peer(vty
, host
);
1350 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1352 paf
= peer
->peer_af_array
[afidx
];
1354 if (PAF_SUBGRP(paf
)) {
1355 UPDGRP_PEER_DBG_DIS(
1367 "BGP updates debugging (inbound) is off for %s\n",
1371 "BGP updates debugging (outbound) is off for %s\n",
1375 "BGP updates debugging (inbound) was not enabled for %s\n",
1379 "BGP updates debugging (outbound) was not enabled for %s\n",
1385 #ifndef VTYSH_EXTRACT_PL
1386 #include "bgpd/bgp_debug_clippy.c"
1389 DEFPY (debug_bgp_update_prefix_afi_safi
,
1390 debug_bgp_update_prefix_afi_safi_cmd
,
1391 "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>>",
1395 "Specify a prefix to debug\n"
1399 EVPN_TYPE_2_HELP_STR
1400 EVPN_TYPE_2_HELP_STR
1401 MAC_STR MAC_STR MAC_STR
1405 EVPN_TYPE_3_HELP_STR
1406 EVPN_TYPE_3_HELP_STR
1410 EVPN_TYPE_5_HELP_STR
1411 EVPN_TYPE_5_HELP_STR
1416 struct prefix
*argv_p
;
1417 int ret
= CMD_SUCCESS
;
1418 char buf
[PREFIX2STR_BUFFER
];
1420 argv_p
= prefix_new();
1422 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1423 if (ret
!= CMD_SUCCESS
) {
1424 prefix_free(&argv_p
);
1428 if (!bgp_debug_update_prefixes
)
1429 bgp_debug_update_prefixes
= list_new();
1431 prefix2str(argv_p
, buf
, sizeof(buf
));
1433 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1435 "BGP updates debugging is already enabled for %s\n",
1437 prefix_free(&argv_p
);
1441 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1443 if (vty
->node
== CONFIG_NODE
) {
1444 DEBUG_ON(update
, UPDATE_PREFIX
);
1446 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1447 vty_out(vty
, "BGP updates debugging is on for %s\n", buf
);
1450 prefix_free(&argv_p
);
1455 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1456 no_debug_bgp_update_prefix_afi_safi_cmd
,
1457 "no debug bgp updates prefix l2vpn$afi evpn$safi type <<macip|2> mac <X:X:X:X:X:X|X:X:X:X:X:X/M> [ip <A.B.C.D|X:X::X:X>]|<multicast|3> ip <A.B.C.D|X:X::X:X>|<prefix|5> ip <A.B.C.D/M|X:X::X:X/M>>",
1462 "Specify a prefix to debug\n"
1466 EVPN_TYPE_2_HELP_STR
1467 EVPN_TYPE_2_HELP_STR
1468 MAC_STR MAC_STR MAC_STR
1472 EVPN_TYPE_3_HELP_STR
1473 EVPN_TYPE_3_HELP_STR
1477 EVPN_TYPE_5_HELP_STR
1478 EVPN_TYPE_5_HELP_STR
1483 struct prefix
*argv_p
;
1484 bool found_prefix
= false;
1485 int ret
= CMD_SUCCESS
;
1486 char buf
[PREFIX2STR_BUFFER
];
1488 argv_p
= prefix_new();
1490 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1491 if (ret
!= CMD_SUCCESS
) {
1492 prefix_free(&argv_p
);
1496 if (bgp_debug_update_prefixes
1497 && !list_isempty(bgp_debug_update_prefixes
)) {
1498 found_prefix
= bgp_debug_list_remove_entry(
1499 bgp_debug_update_prefixes
, NULL
, argv_p
);
1501 if (list_isempty(bgp_debug_update_prefixes
)) {
1502 if (vty
->node
== CONFIG_NODE
) {
1503 DEBUG_OFF(update
, UPDATE_PREFIX
);
1505 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1507 "BGP updates debugging (per prefix) is off\n");
1512 prefix2str(argv_p
, buf
, sizeof(buf
));
1515 vty_out(vty
, "BGP updates debugging is off for %s\n", buf
);
1517 vty_out(vty
, "BGP updates debugging was not enabled for %s\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 DEFUN (no_debug_bgp
,
2107 struct listnode
*ln
;
2109 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2110 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2111 bgp_debug_list_free(bgp_debug_update_in_peers
);
2112 bgp_debug_list_free(bgp_debug_update_out_peers
);
2113 bgp_debug_list_free(bgp_debug_update_prefixes
);
2114 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2115 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2117 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2118 bgp_debug_clear_updgrp_update_dbg(bgp
);
2120 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2121 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2122 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2123 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2124 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2125 TERM_DEBUG_OFF(as4
, AS4
);
2126 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2127 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2128 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2129 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2130 TERM_DEBUG_OFF(nht
, NHT
);
2131 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2132 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2133 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2134 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2135 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2136 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2137 TERM_DEBUG_OFF(pbr
, PBR
);
2138 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2139 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
2140 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_ES
);
2141 TERM_DEBUG_OFF(evpn_mh
, EVPN_MH_RT
);
2143 vty_out(vty
, "All possible debugging has been turned off\n");
2148 DEFUN_NOSH (show_debugging_bgp
,
2149 show_debugging_bgp_cmd
,
2150 "show debugging [bgp]",
2155 vty_out(vty
, "BGP debugging status:\n");
2157 if (BGP_DEBUG(as4
, AS4
))
2158 vty_out(vty
, " BGP as4 debugging is on\n");
2160 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2161 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2163 if (BGP_DEBUG(bestpath
, BESTPATH
))
2164 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2165 bgp_debug_bestpath_prefixes
);
2167 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2168 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2169 bgp_debug_keepalive_peers
);
2171 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2172 bgp_debug_list_print(vty
,
2173 " BGP neighbor-events debugging is on",
2174 bgp_debug_neighbor_events_peers
);
2176 if (BGP_DEBUG(nht
, NHT
))
2177 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2179 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2180 vty_out(vty
, " BGP update-groups debugging is on\n");
2182 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2183 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2184 bgp_debug_update_prefixes
);
2186 if (BGP_DEBUG(update
, UPDATE_IN
))
2187 bgp_debug_list_print(vty
,
2188 " BGP updates debugging is on (inbound)",
2189 bgp_debug_update_in_peers
);
2191 if (BGP_DEBUG(update
, UPDATE_OUT
))
2192 bgp_debug_list_print(vty
,
2193 " BGP updates debugging is on (outbound)",
2194 bgp_debug_update_out_peers
);
2196 if (BGP_DEBUG(zebra
, ZEBRA
))
2197 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2198 bgp_debug_zebra_prefixes
);
2200 if (BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
))
2201 vty_out(vty
, " BGP graceful-restart debugging is on\n");
2203 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2204 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2206 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2208 " BGP route leak from vrf to vpn debugging is on\n");
2209 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2211 " BGP route leak to vrf from vpn debugging is on\n");
2212 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2213 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2214 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2215 vty_out(vty
, " BGP vpn label event debugging is on\n");
2216 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2217 vty_out(vty
, " BGP flowspec debugging is on\n");
2218 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2219 vty_out(vty
, " BGP labelpool debugging is on\n");
2221 if (BGP_DEBUG(pbr
, PBR
))
2222 vty_out(vty
, " BGP policy based routing debugging is on\n");
2223 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2224 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2226 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2227 vty_out(vty
, " BGP EVPN-MH ES debugging is on\n");
2228 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
2229 vty_out(vty
, " BGP EVPN-MH route debugging is on\n");
2235 static int bgp_config_write_debug(struct vty
*vty
)
2239 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2240 vty_out(vty
, "debug bgp as4\n");
2244 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2245 vty_out(vty
, "debug bgp as4 segment\n");
2249 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2250 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2251 bgp_debug_bestpath_prefixes
);
2254 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2255 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2256 bgp_debug_keepalive_peers
);
2259 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2260 write
+= bgp_debug_list_conf_print(
2261 vty
, "debug bgp neighbor-events",
2262 bgp_debug_neighbor_events_peers
);
2265 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2266 vty_out(vty
, "debug bgp nht\n");
2270 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2271 vty_out(vty
, "debug bgp update-groups\n");
2275 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2276 write
+= bgp_debug_list_conf_print(vty
,
2277 "debug bgp updates prefix",
2278 bgp_debug_update_prefixes
);
2281 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2282 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2283 bgp_debug_update_in_peers
);
2286 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2287 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2288 bgp_debug_update_out_peers
);
2291 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2292 if (!bgp_debug_zebra_prefixes
2293 || list_isempty(bgp_debug_zebra_prefixes
)) {
2294 vty_out(vty
, "debug bgp zebra\n");
2297 write
+= bgp_debug_list_conf_print(
2298 vty
, "debug bgp zebra prefix",
2299 bgp_debug_zebra_prefixes
);
2303 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2304 vty_out(vty
, "debug bgp allow-martians\n");
2308 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2309 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2312 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2313 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2316 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2317 vty_out(vty
, "debug bgp vpn rmap-event\n");
2320 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2321 vty_out(vty
, "debug bgp vpn label\n");
2324 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2325 vty_out(vty
, "debug bgp flowspec\n");
2328 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2329 vty_out(vty
, "debug bgp labelpool\n");
2333 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2334 vty_out(vty
, "debug bgp pbr\n");
2337 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2338 vty_out(vty
, "debug bgp pbr error\n");
2342 if (CONF_BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
)) {
2343 vty_out(vty
, "debug bgp graceful-restart\n");
2347 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_ES
)) {
2348 vty_out(vty
, "debug bgp evpn mh es\n");
2351 if (CONF_BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
2352 vty_out(vty
, "debug bgp evpn mh route\n");
2359 static int bgp_config_write_debug(struct vty
*vty
);
2360 static struct cmd_node debug_node
= {
2364 .config_write
= bgp_config_write_debug
,
2367 void bgp_debug_init(void)
2369 install_node(&debug_node
);
2371 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2373 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2374 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2375 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2376 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2378 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2379 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2380 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2381 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2382 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2383 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2384 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2385 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2386 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2387 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2388 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2389 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2390 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2391 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2392 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2393 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2395 install_element(ENABLE_NODE
, &debug_bgp_graceful_restart_cmd
);
2396 install_element(CONFIG_NODE
, &debug_bgp_graceful_restart_cmd
);
2398 /* debug bgp updates (in|out) */
2399 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2400 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2401 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2402 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2404 /* debug bgp updates (in|out) A.B.C.D */
2405 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2406 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2407 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2408 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2410 /* debug bgp updates prefix A.B.C.D/M */
2411 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2412 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2413 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2414 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2415 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2416 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2417 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2418 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2420 /* debug bgp zebra prefix A.B.C.D/M */
2421 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2422 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2423 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2424 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2426 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2427 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2428 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2429 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2431 /* debug bgp neighbor-events A.B.C.D */
2432 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2433 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2434 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2435 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2437 /* debug bgp keepalive A.B.C.D */
2438 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2439 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2440 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2441 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2443 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2444 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2445 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2446 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2447 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2448 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2449 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2450 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2451 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2452 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2453 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2454 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2455 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2456 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2457 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2458 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2459 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2460 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2461 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2463 install_element(ENABLE_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2464 install_element(CONFIG_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2466 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2467 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2468 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2469 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2471 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2472 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2473 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2474 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2477 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2478 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2479 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2480 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2482 install_element(ENABLE_NODE
, &debug_bgp_evpn_mh_cmd
);
2483 install_element(CONFIG_NODE
, &debug_bgp_evpn_mh_cmd
);
2486 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2487 * for BGP_DEBUG_TYPE
2489 static int bgp_debug_per_prefix(const struct prefix
*p
,
2490 unsigned long term_bgp_debug_type
,
2491 unsigned int BGP_DEBUG_TYPE
,
2492 struct list
*per_prefix_list
)
2494 struct bgp_debug_filter
*filter
;
2495 struct listnode
*node
, *nnode
;
2497 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2498 /* We are debugging all prefixes so return true */
2499 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2506 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2508 if (filter
->p
->prefixlen
== p
->prefixlen
2509 && prefix_match(filter
->p
, p
))
2519 /* Return true if this peer is on the per_peer_list of peers to debug
2520 * for BGP_DEBUG_TYPE
2522 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2523 unsigned int BGP_DEBUG_TYPE
,
2524 struct list
*per_peer_list
)
2526 struct bgp_debug_filter
*filter
;
2527 struct listnode
*node
, *nnode
;
2529 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2530 /* We are debugging all peers so return true */
2531 if (!per_peer_list
|| list_isempty(per_peer_list
))
2538 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2540 if (strcmp(filter
->host
, host
) == 0)
2550 int bgp_debug_neighbor_events(struct peer
*peer
)
2557 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2558 BGP_DEBUG_NEIGHBOR_EVENTS
,
2559 bgp_debug_neighbor_events_peers
);
2562 int bgp_debug_keepalive(struct peer
*peer
)
2569 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2570 BGP_DEBUG_KEEPALIVE
,
2571 bgp_debug_keepalive_peers
);
2574 bool bgp_debug_update(struct peer
*peer
, const struct prefix
*p
,
2575 struct update_group
*updgrp
, unsigned int inbound
)
2583 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2584 BGP_DEBUG_UPDATE_IN
,
2585 bgp_debug_update_in_peers
))
2591 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2592 BGP_DEBUG_UPDATE_OUT
,
2593 bgp_debug_update_out_peers
))
2596 /* Check if update debugging implicitly enabled for the group.
2598 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2603 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2604 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2605 BGP_DEBUG_UPDATE_PREFIX
,
2606 bgp_debug_update_prefixes
))
2613 bool bgp_debug_bestpath(struct bgp_dest
*dest
)
2615 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2616 if (bgp_debug_per_prefix(
2617 bgp_dest_get_prefix(dest
), term_bgp_debug_bestpath
,
2618 BGP_DEBUG_BESTPATH
, bgp_debug_bestpath_prefixes
))
2625 bool bgp_debug_zebra(const struct prefix
*p
)
2627 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2628 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2630 bgp_debug_zebra_prefixes
))
2637 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2638 const struct prefix_rd
*prd
,
2639 union prefixconstptr pu
,
2640 mpls_label_t
*label
, uint32_t num_labels
,
2641 int addpath_valid
, uint32_t addpath_id
,
2642 char *str
, int size
)
2644 char rd_buf
[RD_ADDRSTRLEN
];
2645 char pfx_buf
[PREFIX_STRLEN
];
2647 /* ' with addpath ID ' 17
2648 * max strlen of uint32 + 10
2649 * +/- (just in case) + 1
2650 * null terminator + 1
2651 * ============================ 29 */
2652 char pathid_buf
[30];
2654 if (size
< BGP_PRD_PATH_STRLEN
)
2657 /* Note: Path-id is created by default, but only included in update
2659 pathid_buf
[0] = '\0';
2661 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2665 if (bgp_labeled_safi(safi
) && num_labels
) {
2667 if (safi
== SAFI_EVPN
) {
2670 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2671 snprintf(tag_buf
, sizeof(tag_buf
), " label %s",
2674 uint32_t label_value
;
2676 label_value
= decode_label(label
);
2677 snprintf(tag_buf
, sizeof(tag_buf
), " label %u",
2683 snprintf(str
, size
, "RD %s %s%s%s %s %s",
2684 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2685 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2686 pathid_buf
, afi2str(afi
), safi2str(safi
));
2687 else if (safi
== SAFI_FLOWSPEC
) {
2688 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2689 const struct prefix_fs
*fs
= pu
.fs
;
2691 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2692 fs
->prefix
.prefixlen
,
2694 NLRI_STRING_FORMAT_DEBUG
, NULL
,
2695 family2afi(fs
->prefix
.family
));
2696 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2699 snprintf(str
, size
, "%s%s%s %s %s",
2700 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2701 pathid_buf
, afi2str(afi
), safi2str(safi
));