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
;
67 unsigned long term_bgp_debug_as4
;
68 unsigned long term_bgp_debug_neighbor_events
;
69 unsigned long term_bgp_debug_events
;
70 unsigned long term_bgp_debug_packet
;
71 unsigned long term_bgp_debug_filter
;
72 unsigned long term_bgp_debug_keepalive
;
73 unsigned long term_bgp_debug_update
;
74 unsigned long term_bgp_debug_bestpath
;
75 unsigned long term_bgp_debug_zebra
;
76 unsigned long term_bgp_debug_allow_martians
;
77 unsigned long term_bgp_debug_nht
;
78 unsigned long term_bgp_debug_update_groups
;
79 unsigned long term_bgp_debug_vpn
;
80 unsigned long term_bgp_debug_flowspec
;
81 unsigned long term_bgp_debug_labelpool
;
82 unsigned long term_bgp_debug_pbr
;
84 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
85 struct list
*bgp_debug_keepalive_peers
= NULL
;
86 struct list
*bgp_debug_update_out_peers
= NULL
;
87 struct list
*bgp_debug_update_in_peers
= NULL
;
88 struct list
*bgp_debug_update_prefixes
= NULL
;
89 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
90 struct list
*bgp_debug_zebra_prefixes
= NULL
;
92 /* messages for BGP-4 status */
93 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
96 {OpenSent
, "OpenSent"},
97 {OpenConfirm
, "OpenConfirm"},
98 {Established
, "Established"},
99 {Clearing
, "Clearing"},
100 {Deleted
, "Deleted"},
103 /* BGP message type string. */
104 const char *bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
105 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
108 /* message for BGP-4 Notify */
109 static const struct message bgp_notify_msg
[] = {
110 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
111 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
112 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
113 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
114 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
115 {BGP_NOTIFY_CEASE
, "Cease"},
116 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
119 static const struct message bgp_notify_head_msg
[] = {
120 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
121 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
122 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
125 static const struct message bgp_notify_open_msg
[] = {
126 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
127 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
128 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
129 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
130 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
131 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
132 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
133 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
136 static const struct message bgp_notify_update_msg
[] = {
137 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
138 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
139 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
140 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
141 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
142 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
143 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
144 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
145 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
146 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
147 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
148 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
151 static const struct message bgp_notify_cease_msg
[] = {
152 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
153 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
154 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
155 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
156 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
157 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
158 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
159 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
160 "/Connection collision resolution"},
161 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
164 static const struct message bgp_notify_capability_msg
[] = {
165 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
166 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
167 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
168 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
171 /* Origin strings. */
172 const char *bgp_origin_str
[] = {"i", "e", "?"};
173 const char *bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
175 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
177 /* Given a string return a pointer the corresponding peer structure */
178 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
180 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
188 ret
= str2sockunion(peer_str
, &su
);
192 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
195 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
199 return peer_lookup(bgp
, &su
);
202 static void bgp_debug_list_free(struct list
*list
)
204 struct bgp_debug_filter
*filter
;
205 struct listnode
*node
, *nnode
;
208 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
209 listnode_delete(list
, filter
);
212 prefix_free(filter
->p
);
215 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
217 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
222 * Print the desc along with a list of peers/prefixes this debug is
225 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
228 struct bgp_debug_filter
*filter
;
229 struct listnode
*node
, *nnode
;
230 char buf
[PREFIX2STR_BUFFER
];
232 vty_out(vty
, "%s", desc
);
234 if (list
&& !list_isempty(list
)) {
235 vty_out(vty
, " for");
236 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
238 vty_out(vty
, " %s", filter
->host
);
240 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
241 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
242 else if (filter
->p
) {
243 prefix2str(filter
->p
, buf
, sizeof(buf
));
244 vty_out(vty
, " %s", buf
);
253 * Print the command to enable the debug for each peer/prefix this debug is
256 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
259 struct bgp_debug_filter
*filter
;
260 struct listnode
*node
, *nnode
;
261 char buf
[PREFIX2STR_BUFFER
];
264 if (list
&& !list_isempty(list
)) {
265 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
267 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
271 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
272 bgp_debug_print_evpn_prefix(vty
, desc
,
275 } else if (filter
->p
) {
276 prefix2str(filter
->p
, buf
, sizeof(buf
));
277 vty_out(vty
, "%s %s\n", desc
, buf
);
284 vty_out(vty
, "%s\n", desc
);
291 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
292 const struct prefix
*p
)
294 struct bgp_debug_filter
*filter
;
296 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
297 sizeof(struct bgp_debug_filter
));
300 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
304 filter
->p
= prefix_new();
305 prefix_copy(filter
->p
, p
);
308 listnode_add(list
, filter
);
311 static int bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
314 struct bgp_debug_filter
*filter
;
315 struct listnode
*node
, *nnode
;
317 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
318 if (host
&& strcmp(filter
->host
, host
) == 0) {
319 listnode_delete(list
, filter
);
320 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
321 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
323 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
324 && prefix_match(filter
->p
, p
)) {
325 listnode_delete(list
, filter
);
326 prefix_free(filter
->p
);
327 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
335 static int bgp_debug_list_has_entry(struct list
*list
, const char *host
,
336 const struct prefix
*p
)
338 struct bgp_debug_filter
*filter
;
339 struct listnode
*node
, *nnode
;
341 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
343 if (strcmp(filter
->host
, host
) == 0) {
347 if (filter
->p
->prefixlen
== p
->prefixlen
348 && prefix_match(filter
->p
, p
)) {
357 int bgp_debug_peer_updout_enabled(char *host
)
359 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
363 /* Dump attribute. */
364 int bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
366 char addrbuf
[BUFSIZ
];
371 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
372 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
374 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
375 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
376 bgp_origin_str
[attr
->origin
]);
379 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
380 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
381 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
383 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
386 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
387 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
388 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
391 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
392 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
394 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
395 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
396 ", localpref %u", attr
->local_pref
);
398 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
399 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
402 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
403 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
405 community_str(attr
->community
, false));
407 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
408 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
409 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
411 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
412 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
413 ", atomic-aggregate");
415 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
416 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
417 ", aggregated by %u %s", attr
->aggregator_as
,
418 inet_ntoa(attr
->aggregator_addr
));
420 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
421 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
422 ", originator %s", inet_ntoa(attr
->originator_id
));
424 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
427 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
429 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
430 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
431 inet_ntoa(attr
->cluster
->list
[i
]));
434 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
435 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
436 ", pmsi tnltype %u", attr
->pmsi_tnl_type
);
438 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
439 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
440 aspath_print(attr
->aspath
));
442 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
443 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
444 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
445 ", label-index %u", attr
->label_index
);
454 const char *bgp_notify_code_str(char code
)
456 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
459 const char *bgp_notify_subcode_str(char code
, char subcode
)
463 case BGP_NOTIFY_HEADER_ERR
:
464 return lookup_msg(bgp_notify_head_msg
, subcode
,
465 "Unrecognized Error Subcode");
466 case BGP_NOTIFY_OPEN_ERR
:
467 return lookup_msg(bgp_notify_open_msg
, subcode
,
468 "Unrecognized Error Subcode");
469 case BGP_NOTIFY_UPDATE_ERR
:
470 return lookup_msg(bgp_notify_update_msg
, subcode
,
471 "Unrecognized Error Subcode");
472 case BGP_NOTIFY_HOLD_ERR
:
474 case BGP_NOTIFY_FSM_ERR
:
476 case BGP_NOTIFY_CEASE
:
477 return lookup_msg(bgp_notify_cease_msg
, subcode
,
478 "Unrecognized Error Subcode");
479 case BGP_NOTIFY_CAPABILITY_ERR
:
480 return lookup_msg(bgp_notify_capability_msg
, subcode
,
481 "Unrecognized Error Subcode");
486 /* extract notify admin reason if correctly present */
487 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
490 if (!data
|| datalen
< 1)
493 uint8_t len
= data
[0];
494 if (len
> 128 || len
> datalen
- 1)
497 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
500 /* dump notify packet */
501 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
504 const char *subcode_str
;
505 const char *code_str
;
506 const char *msg_str
= NULL
;
509 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
510 || bgp_flag_check(peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
511 code_str
= bgp_notify_code_str(bgp_notify
->code
);
512 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
513 bgp_notify
->subcode
);
515 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
516 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
517 || bgp_notify
->subcode
518 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
519 msg_str
= bgp_notify_admin_message(
520 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
526 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
527 strcmp(direct
, "received") == 0
530 peer
->host
, bgp_notify
->code
,
531 bgp_notify
->subcode
, code_str
, subcode_str
,
534 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
536 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
537 strcmp(direct
, "received") == 0
540 peer
->host
, bgp_notify
->code
,
541 bgp_notify
->subcode
, code_str
, subcode_str
,
542 bgp_notify
->length
, msg_str
);
547 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
550 bgp
= bgp_get_default();
551 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
554 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
557 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
558 char buf
[PREFIX2STR_BUFFER
];
559 char buf2
[ETHER_ADDR_STRLEN
];
561 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
562 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
563 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s",
565 &p
->u
.prefix_evpn
.macip_addr
.mac
,
566 buf2
, sizeof(buf2
)));
568 uint8_t family
= is_evpn_prefix_ipaddr_v4(
569 (struct prefix_evpn
*)p
) ?
571 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s ip %s",
573 &p
->u
.prefix_evpn
.macip_addr
.mac
,
576 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
577 buf
, PREFIX2STR_BUFFER
));
579 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
580 sprintf(evpn_desc
, "l2vpn evpn type multicast ip %s",
581 inet_ntoa(p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
));
582 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
583 uint8_t family
= is_evpn_prefix_ipaddr_v4(
584 (struct prefix_evpn
*)p
) ? AF_INET
586 sprintf(evpn_desc
, "l2vpn evpn type prefix ip %s/%d",
588 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
, buf
,
590 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
593 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
598 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
599 int argc
, struct prefix
**argv_pp
)
601 struct prefix
*argv_p
;
611 if (argv_find(argv
, argc
, "macip", &type_idx
))
612 evpn_type
= BGP_EVPN_MAC_IP_ROUTE
;
613 else if (argv_find(argv
, argc
, "multicast", &type_idx
))
614 evpn_type
= BGP_EVPN_IMET_ROUTE
;
615 else if (argv_find(argv
, argc
, "prefix", &type_idx
))
616 evpn_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
620 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
621 memset(&ip
, 0, sizeof(struct ipaddr
));
623 argv_find(argv
, argc
, "mac", &mac_idx
);
624 (void)prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
);
626 argv_find(argv
, argc
, "ip", &ip_idx
);
627 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
629 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
631 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
632 memset(&ip
, 0, sizeof(struct ipaddr
));
634 argv_find(argv
, argc
, "ip", &ip_idx
);
635 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
637 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
639 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
640 struct prefix ip_prefix
;
642 memset(&ip_prefix
, 0, sizeof(struct prefix
));
643 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
644 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
645 apply_mask(&ip_prefix
);
647 build_type5_prefix_from_ip_prefix(
648 (struct prefix_evpn
*)argv_p
,
655 /* Debug option setting interface. */
656 unsigned long bgp_debug_option
= 0;
658 int debug(unsigned int option
)
660 return bgp_debug_option
& option
;
663 DEFUN (debug_bgp_as4
,
670 if (vty
->node
== CONFIG_NODE
)
673 TERM_DEBUG_ON(as4
, AS4
);
674 vty_out(vty
, "BGP as4 debugging is on\n");
679 DEFUN (no_debug_bgp_as4
,
680 no_debug_bgp_as4_cmd
,
687 if (vty
->node
== CONFIG_NODE
)
690 TERM_DEBUG_OFF(as4
, AS4
);
691 vty_out(vty
, "BGP as4 debugging is off\n");
696 DEFUN (debug_bgp_as4_segment
,
697 debug_bgp_as4_segment_cmd
,
698 "debug bgp as4 segment",
702 "BGP AS4 aspath segment handling\n")
704 if (vty
->node
== CONFIG_NODE
)
705 DEBUG_ON(as4
, AS4_SEGMENT
);
707 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
708 vty_out(vty
, "BGP as4 segment debugging is on\n");
713 DEFUN (no_debug_bgp_as4_segment
,
714 no_debug_bgp_as4_segment_cmd
,
715 "no debug bgp as4 segment",
720 "BGP AS4 aspath segment handling\n")
722 if (vty
->node
== CONFIG_NODE
)
723 DEBUG_OFF(as4
, AS4_SEGMENT
);
725 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
726 vty_out(vty
, "BGP as4 segment debugging is off\n");
731 /* debug bgp neighbor_events */
732 DEFUN (debug_bgp_neighbor_events
,
733 debug_bgp_neighbor_events_cmd
,
734 "debug bgp neighbor-events",
737 "BGP Neighbor Events\n")
739 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
741 if (vty
->node
== CONFIG_NODE
)
742 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
744 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
745 vty_out(vty
, "BGP neighbor-events debugging is on\n");
750 DEFUN (debug_bgp_neighbor_events_peer
,
751 debug_bgp_neighbor_events_peer_cmd
,
752 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
755 "BGP Neighbor Events\n"
756 "BGP neighbor IP address to debug\n"
757 "BGP IPv6 neighbor to debug\n"
758 "BGP neighbor on interface to debug\n")
761 const char *host
= argv
[idx_peer
]->arg
;
763 if (!bgp_debug_neighbor_events_peers
)
764 bgp_debug_neighbor_events_peers
= list_new();
766 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
769 "BGP neighbor-events debugging is already enabled for %s\n",
774 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
776 if (vty
->node
== CONFIG_NODE
)
777 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
779 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
780 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
786 DEFUN (no_debug_bgp_neighbor_events
,
787 no_debug_bgp_neighbor_events_cmd
,
788 "no debug bgp neighbor-events",
794 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
796 if (vty
->node
== CONFIG_NODE
)
797 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
799 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
800 vty_out(vty
, "BGP neighbor-events debugging is off\n");
805 DEFUN (no_debug_bgp_neighbor_events_peer
,
806 no_debug_bgp_neighbor_events_peer_cmd
,
807 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
812 "BGP neighbor IP address to debug\n"
813 "BGP IPv6 neighbor to debug\n"
814 "BGP neighbor on interface to debug\n")
818 const char *host
= argv
[idx_peer
]->arg
;
820 if (bgp_debug_neighbor_events_peers
821 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
822 found_peer
= bgp_debug_list_remove_entry(
823 bgp_debug_neighbor_events_peers
, host
, NULL
);
825 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
826 if (vty
->node
== CONFIG_NODE
)
827 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
829 TERM_DEBUG_OFF(neighbor_events
,
835 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
839 "BGP neighbor-events debugging was not enabled for %s\n",
846 DEFUN (debug_bgp_nht
,
851 "BGP nexthop tracking events\n")
853 if (vty
->node
== CONFIG_NODE
)
856 TERM_DEBUG_ON(nht
, NHT
);
857 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
862 DEFUN (no_debug_bgp_nht
,
863 no_debug_bgp_nht_cmd
,
868 "BGP nexthop tracking events\n")
870 if (vty
->node
== CONFIG_NODE
)
873 TERM_DEBUG_OFF(nht
, NHT
);
874 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
879 /* debug bgp keepalives */
880 DEFUN (debug_bgp_keepalive
,
881 debug_bgp_keepalive_cmd
,
882 "debug bgp keepalives",
887 bgp_debug_list_free(bgp_debug_keepalive_peers
);
889 if (vty
->node
== CONFIG_NODE
)
890 DEBUG_ON(keepalive
, KEEPALIVE
);
892 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
893 vty_out(vty
, "BGP keepalives debugging is on\n");
898 DEFUN (debug_bgp_keepalive_peer
,
899 debug_bgp_keepalive_peer_cmd
,
900 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
903 "BGP Neighbor Events\n"
904 "BGP neighbor IP address to debug\n"
905 "BGP IPv6 neighbor to debug\n"
906 "BGP neighbor on interface to debug\n")
909 const char *host
= argv
[idx_peer
]->arg
;
911 if (!bgp_debug_keepalive_peers
)
912 bgp_debug_keepalive_peers
= list_new();
914 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
916 "BGP keepalive debugging is already enabled for %s\n",
921 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
923 if (vty
->node
== CONFIG_NODE
)
924 DEBUG_ON(keepalive
, KEEPALIVE
);
926 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
927 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
932 DEFUN (no_debug_bgp_keepalive
,
933 no_debug_bgp_keepalive_cmd
,
934 "no debug bgp keepalives",
940 bgp_debug_list_free(bgp_debug_keepalive_peers
);
942 if (vty
->node
== CONFIG_NODE
)
943 DEBUG_OFF(keepalive
, KEEPALIVE
);
945 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
946 vty_out(vty
, "BGP keepalives debugging is off\n");
951 DEFUN (no_debug_bgp_keepalive_peer
,
952 no_debug_bgp_keepalive_peer_cmd
,
953 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
958 "BGP neighbor IP address to debug\n"
959 "BGP IPv6 neighbor to debug\n"
960 "BGP neighbor on interface to debug\n")
964 const char *host
= argv
[idx_peer
]->arg
;
966 if (bgp_debug_keepalive_peers
967 && !list_isempty(bgp_debug_keepalive_peers
)) {
968 found_peer
= bgp_debug_list_remove_entry(
969 bgp_debug_keepalive_peers
, host
, NULL
);
971 if (list_isempty(bgp_debug_keepalive_peers
)) {
972 if (vty
->node
== CONFIG_NODE
)
973 DEBUG_OFF(keepalive
, KEEPALIVE
);
975 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
980 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
983 "BGP keepalives debugging was not enabled for %s\n",
989 /* debug bgp bestpath */
990 DEFUN (debug_bgp_bestpath_prefix
,
991 debug_bgp_bestpath_prefix_cmd
,
992 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
999 struct prefix
*argv_p
;
1000 int idx_ipv4_ipv6_prefixlen
= 3;
1002 argv_p
= prefix_new();
1003 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1006 if (!bgp_debug_bestpath_prefixes
)
1007 bgp_debug_bestpath_prefixes
= list_new();
1009 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1012 "BGP bestpath debugging is already enabled for %s\n",
1013 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1017 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1019 if (vty
->node
== CONFIG_NODE
) {
1020 DEBUG_ON(bestpath
, BESTPATH
);
1022 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1023 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1024 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1030 DEFUN (no_debug_bgp_bestpath_prefix
,
1031 no_debug_bgp_bestpath_prefix_cmd
,
1032 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1040 int idx_ipv4_ipv6_prefixlen
= 4;
1041 struct prefix
*argv_p
;
1042 int found_prefix
= 0;
1044 argv_p
= prefix_new();
1045 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1048 if (bgp_debug_bestpath_prefixes
1049 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1050 found_prefix
= bgp_debug_list_remove_entry(
1051 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1053 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1054 if (vty
->node
== CONFIG_NODE
) {
1055 DEBUG_OFF(bestpath
, BESTPATH
);
1057 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1059 "BGP bestpath debugging (per prefix) is off\n");
1065 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1066 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1068 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1069 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1074 DEFUN (no_debug_bgp_bestpath
,
1075 no_debug_bgp_bestpath_cmd
,
1076 "no debug bgp bestpath",
1082 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1084 if (vty
->node
== CONFIG_NODE
)
1085 DEBUG_OFF(bestpath
, BESTPATH
);
1087 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1088 vty_out(vty
, "BGP bestpath debugging is off\n");
1093 /* debug bgp updates */
1094 DEFUN (debug_bgp_update
,
1095 debug_bgp_update_cmd
,
1096 "debug bgp updates",
1101 bgp_debug_list_free(bgp_debug_update_in_peers
);
1102 bgp_debug_list_free(bgp_debug_update_out_peers
);
1103 bgp_debug_list_free(bgp_debug_update_prefixes
);
1105 if (vty
->node
== CONFIG_NODE
) {
1106 DEBUG_ON(update
, UPDATE_IN
);
1107 DEBUG_ON(update
, UPDATE_OUT
);
1109 TERM_DEBUG_ON(update
, UPDATE_IN
);
1110 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1111 vty_out(vty
, "BGP updates debugging is on\n");
1116 DEFUN (debug_bgp_update_direct
,
1117 debug_bgp_update_direct_cmd
,
1118 "debug bgp updates <in|out>",
1123 "Outbound updates\n")
1127 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1128 bgp_debug_list_free(bgp_debug_update_in_peers
);
1130 bgp_debug_list_free(bgp_debug_update_out_peers
);
1132 if (vty
->node
== CONFIG_NODE
) {
1133 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1134 DEBUG_ON(update
, UPDATE_IN
);
1136 DEBUG_ON(update
, UPDATE_OUT
);
1138 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1139 TERM_DEBUG_ON(update
, UPDATE_IN
);
1140 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1142 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1144 "BGP updates debugging is on (outbound)\n");
1150 DEFUN (debug_bgp_update_direct_peer
,
1151 debug_bgp_update_direct_peer_cmd
,
1152 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1157 "Outbound updates\n"
1158 "BGP neighbor IP address to debug\n"
1159 "BGP IPv6 neighbor to debug\n"
1160 "BGP neighbor on interface to debug\n")
1164 const char *host
= argv
[idx_peer
]->arg
;
1167 if (!bgp_debug_update_in_peers
)
1168 bgp_debug_update_in_peers
= list_new();
1170 if (!bgp_debug_update_out_peers
)
1171 bgp_debug_update_out_peers
= list_new();
1173 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1179 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1182 "BGP inbound update debugging is already enabled for %s\n",
1189 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1192 "BGP outbound update debugging is already enabled for %s\n",
1199 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1202 struct peer_af
*paf
;
1205 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1207 peer
= bgp_find_peer(vty
, host
);
1210 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1212 paf
= peer
->peer_af_array
[afidx
];
1214 if (PAF_SUBGRP(paf
)) {
1224 if (vty
->node
== CONFIG_NODE
) {
1226 DEBUG_ON(update
, UPDATE_IN
);
1228 DEBUG_ON(update
, UPDATE_OUT
);
1231 TERM_DEBUG_ON(update
, UPDATE_IN
);
1233 "BGP updates debugging is on (inbound) for %s\n",
1234 argv
[idx_peer
]->arg
);
1236 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1238 "BGP updates debugging is on (outbound) for %s\n",
1239 argv
[idx_peer
]->arg
);
1245 DEFUN (no_debug_bgp_update_direct
,
1246 no_debug_bgp_update_direct_cmd
,
1247 "no debug bgp updates <in|out>",
1253 "Outbound updates\n")
1256 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1257 bgp_debug_list_free(bgp_debug_update_in_peers
);
1259 if (vty
->node
== CONFIG_NODE
) {
1260 DEBUG_OFF(update
, UPDATE_IN
);
1262 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1264 "BGP updates debugging is off (inbound)\n");
1267 bgp_debug_list_free(bgp_debug_update_out_peers
);
1269 if (vty
->node
== CONFIG_NODE
) {
1270 DEBUG_OFF(update
, UPDATE_OUT
);
1272 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1274 "BGP updates debugging is off (outbound)\n");
1281 DEFUN (no_debug_bgp_update_direct_peer
,
1282 no_debug_bgp_update_direct_peer_cmd
,
1283 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1289 "Outbound updates\n"
1290 "BGP neighbor IP address to debug\n"
1291 "BGP IPv6 neighbor to debug\n"
1292 "BGP neighbor on interface to debug\n")
1298 const char *host
= argv
[idx_peer
]->arg
;
1300 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1305 if (inbound
&& bgp_debug_update_in_peers
1306 && !list_isempty(bgp_debug_update_in_peers
)) {
1307 found_peer
= bgp_debug_list_remove_entry(
1308 bgp_debug_update_in_peers
, host
, NULL
);
1310 if (list_isempty(bgp_debug_update_in_peers
)) {
1311 if (vty
->node
== CONFIG_NODE
)
1312 DEBUG_OFF(update
, UPDATE_IN
);
1314 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1316 "BGP updates debugging (inbound) is off\n");
1321 if (!inbound
&& bgp_debug_update_out_peers
1322 && !list_isempty(bgp_debug_update_out_peers
)) {
1323 found_peer
= bgp_debug_list_remove_entry(
1324 bgp_debug_update_out_peers
, host
, NULL
);
1326 if (list_isempty(bgp_debug_update_out_peers
)) {
1327 if (vty
->node
== CONFIG_NODE
)
1328 DEBUG_OFF(update
, UPDATE_OUT
);
1330 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1332 "BGP updates debugging (outbound) is off\n");
1337 struct peer_af
*paf
;
1339 peer
= bgp_find_peer(vty
, host
);
1342 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1344 paf
= peer
->peer_af_array
[afidx
];
1346 if (PAF_SUBGRP(paf
)) {
1347 UPDGRP_PEER_DBG_DIS(
1359 "BGP updates debugging (inbound) is off for %s\n",
1363 "BGP updates debugging (outbound) is off for %s\n",
1367 "BGP updates debugging (inbound) was not enabled for %s\n",
1371 "BGP updates debugging (outbound) was not enabled for %s\n",
1377 #ifndef VTYSH_EXTRACT_PL
1378 #include "bgpd/bgp_debug_clippy.c"
1381 DEFPY (debug_bgp_update_prefix_afi_safi
,
1382 debug_bgp_update_prefix_afi_safi_cmd
,
1383 "debug bgp updates prefix l2vpn$afi evpn$safi type <macip mac <M:A:C|M:A:C/M> [ip <A.B.C.D|X:X::X:X>]|multicast ip <A.B.C.D|X:X::X:X>|prefix ip <A.B.C.D/M|X:X::X:X/M>>",
1387 "Specify a prefix to debug\n"
1390 "Specify EVPN Route type\n"
1391 "MAC-IP (Type-2) route\n"
1392 MAC_STR MAC_STR MAC_STR
1396 "Multicast (Type-3) route\n"
1400 "Prefix (Type-5) route\n"
1405 struct prefix
*argv_p
;
1406 int ret
= CMD_SUCCESS
;
1407 char buf
[PREFIX2STR_BUFFER
];
1409 argv_p
= prefix_new();
1411 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1412 if (ret
!= CMD_SUCCESS
) {
1413 prefix_free(argv_p
);
1417 if (!bgp_debug_update_prefixes
)
1418 bgp_debug_update_prefixes
= list_new();
1420 prefix2str(argv_p
, buf
, sizeof(buf
));
1422 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1424 "BGP updates debugging is already enabled for %s\n",
1426 prefix_free(argv_p
);
1430 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1432 if (vty
->node
== CONFIG_NODE
) {
1433 DEBUG_ON(update
, UPDATE_PREFIX
);
1435 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1436 vty_out(vty
, "BGP updates debugging is on for %s\n", buf
);
1439 prefix_free(argv_p
);
1444 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1445 no_debug_bgp_update_prefix_afi_safi_cmd
,
1446 "no debug bgp updates prefix l2vpn$afi evpn$safi type <macip mac <M:A:C|M:A:C/M> [ip <A.B.C.D|X:X::X:X>]|multicast ip <A.B.C.D|X:X::X:X>|prefix ip <A.B.C.D/M|X:X::X:X/M>>",
1451 "Specify a prefix to debug\n"
1454 "Specify EVPN Route type\n"
1455 "MAC-IP (Type-2) route\n"
1456 MAC_STR MAC_STR MAC_STR
1460 "Multicast (Type-3) route\n"
1464 "Prefix (Type-5) route\n"
1469 struct prefix
*argv_p
;
1470 bool found_prefix
= false;
1471 int ret
= CMD_SUCCESS
;
1472 char buf
[PREFIX2STR_BUFFER
];
1474 argv_p
= prefix_new();
1476 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1477 if (ret
!= CMD_SUCCESS
) {
1478 prefix_free(argv_p
);
1482 if (bgp_debug_update_prefixes
1483 && !list_isempty(bgp_debug_update_prefixes
)) {
1484 found_prefix
= bgp_debug_list_remove_entry(
1485 bgp_debug_update_prefixes
, NULL
, argv_p
);
1487 if (list_isempty(bgp_debug_update_prefixes
)) {
1488 if (vty
->node
== CONFIG_NODE
) {
1489 DEBUG_OFF(update
, UPDATE_PREFIX
);
1491 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1493 "BGP updates debugging (per prefix) is off\n");
1498 prefix2str(argv_p
, buf
, sizeof(buf
));
1501 vty_out(vty
, "BGP updates debugging is off for %s\n", buf
);
1503 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1506 prefix_free(argv_p
);
1512 DEFUN (debug_bgp_update_prefix
,
1513 debug_bgp_update_prefix_cmd
,
1514 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1518 "Specify a prefix to debug\n"
1522 int idx_ipv4_ipv6_prefixlen
= 4;
1523 struct prefix
*argv_p
;
1525 argv_p
= prefix_new();
1526 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1529 if (!bgp_debug_update_prefixes
)
1530 bgp_debug_update_prefixes
= list_new();
1532 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1534 "BGP updates debugging is already enabled for %s\n",
1535 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1539 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1541 if (vty
->node
== CONFIG_NODE
) {
1542 DEBUG_ON(update
, UPDATE_PREFIX
);
1544 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1545 vty_out(vty
, "BGP updates debugging is on for %s\n",
1546 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1552 DEFUN (no_debug_bgp_update_prefix
,
1553 no_debug_bgp_update_prefix_cmd
,
1554 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1559 "Specify a prefix to debug\n"
1563 int idx_ipv4_ipv6_prefixlen
= 5;
1564 struct prefix
*argv_p
;
1565 int found_prefix
= 0;
1567 argv_p
= prefix_new();
1568 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1571 if (bgp_debug_update_prefixes
1572 && !list_isempty(bgp_debug_update_prefixes
)) {
1573 found_prefix
= bgp_debug_list_remove_entry(
1574 bgp_debug_update_prefixes
, NULL
, argv_p
);
1576 if (list_isempty(bgp_debug_update_prefixes
)) {
1577 if (vty
->node
== CONFIG_NODE
) {
1578 DEBUG_OFF(update
, UPDATE_PREFIX
);
1580 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1582 "BGP updates debugging (per prefix) is off\n");
1588 vty_out(vty
, "BGP updates debugging is off for %s\n",
1589 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1591 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1592 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1597 DEFUN (no_debug_bgp_update
,
1598 no_debug_bgp_update_cmd
,
1599 "no debug bgp updates",
1605 struct listnode
*ln
;
1608 bgp_debug_list_free(bgp_debug_update_in_peers
);
1609 bgp_debug_list_free(bgp_debug_update_out_peers
);
1610 bgp_debug_list_free(bgp_debug_update_prefixes
);
1612 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1613 bgp_debug_clear_updgrp_update_dbg(bgp
);
1615 if (vty
->node
== CONFIG_NODE
) {
1616 DEBUG_OFF(update
, UPDATE_IN
);
1617 DEBUG_OFF(update
, UPDATE_OUT
);
1618 DEBUG_OFF(update
, UPDATE_PREFIX
);
1620 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1621 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1622 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1623 vty_out(vty
, "BGP updates debugging is off\n");
1628 /* debug bgp zebra */
1629 DEFUN (debug_bgp_zebra
,
1630 debug_bgp_zebra_cmd
,
1634 "BGP Zebra messages\n")
1636 if (vty
->node
== CONFIG_NODE
)
1637 DEBUG_ON(zebra
, ZEBRA
);
1639 TERM_DEBUG_ON(zebra
, ZEBRA
);
1640 vty_out(vty
, "BGP zebra debugging is on\n");
1645 DEFUN (debug_bgp_zebra_prefix
,
1646 debug_bgp_zebra_prefix_cmd
,
1647 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1650 "BGP Zebra messages\n"
1651 "Specify a prefix to debug\n"
1655 int idx_ipv4_ipv6_prefixlen
= 4;
1656 struct prefix
*argv_p
;
1658 argv_p
= prefix_new();
1659 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1662 if (!bgp_debug_zebra_prefixes
)
1663 bgp_debug_zebra_prefixes
= list_new();
1665 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1666 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1667 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1671 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1673 if (vty
->node
== CONFIG_NODE
)
1674 DEBUG_ON(zebra
, ZEBRA
);
1676 TERM_DEBUG_ON(zebra
, ZEBRA
);
1677 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1678 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1684 DEFUN (no_debug_bgp_zebra
,
1685 no_debug_bgp_zebra_cmd
,
1686 "no debug bgp zebra",
1690 "BGP Zebra messages\n")
1692 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1694 if (vty
->node
== CONFIG_NODE
)
1695 DEBUG_OFF(zebra
, ZEBRA
);
1697 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1698 vty_out(vty
, "BGP zebra debugging is off\n");
1703 DEFUN (no_debug_bgp_zebra_prefix
,
1704 no_debug_bgp_zebra_prefix_cmd
,
1705 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1709 "BGP Zebra messages\n"
1710 "Specify a prefix to debug\n"
1714 int idx_ipv4_ipv6_prefixlen
= 5;
1715 struct prefix
*argv_p
;
1716 int found_prefix
= 0;
1718 argv_p
= prefix_new();
1719 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1722 if (bgp_debug_zebra_prefixes
1723 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1724 found_prefix
= bgp_debug_list_remove_entry(
1725 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1727 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1728 if (vty
->node
== CONFIG_NODE
)
1729 DEBUG_OFF(zebra
, ZEBRA
);
1731 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1732 vty_out(vty
, "BGP zebra debugging is off\n");
1738 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1739 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1741 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1742 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1747 DEFUN (debug_bgp_allow_martians
,
1748 debug_bgp_allow_martians_cmd
,
1749 "debug bgp allow-martians",
1752 "BGP allow martian next hops\n")
1754 if (vty
->node
== CONFIG_NODE
)
1755 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1757 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1758 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1763 DEFUN (no_debug_bgp_allow_martians
,
1764 no_debug_bgp_allow_martians_cmd
,
1765 "no debug bgp allow-martians",
1769 "BGP allow martian next hops\n")
1771 if (vty
->node
== CONFIG_NODE
)
1772 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1774 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1775 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1781 /* debug bgp update-groups */
1782 DEFUN (debug_bgp_update_groups
,
1783 debug_bgp_update_groups_cmd
,
1784 "debug bgp update-groups",
1787 "BGP update-groups\n")
1789 if (vty
->node
== CONFIG_NODE
)
1790 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1792 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1793 vty_out(vty
, "BGP update-groups debugging is on\n");
1798 DEFUN (no_debug_bgp_update_groups
,
1799 no_debug_bgp_update_groups_cmd
,
1800 "no debug bgp update-groups",
1804 "BGP update-groups\n")
1806 if (vty
->node
== CONFIG_NODE
)
1807 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1809 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1810 vty_out(vty
, "BGP update-groups debugging is off\n");
1815 DEFUN (debug_bgp_vpn
,
1817 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1821 "leaked from vrf to vpn\n"
1822 "leaked to vrf from vpn\n"
1823 "route-map updates\n"
1828 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1829 if (vty
->node
== CONFIG_NODE
)
1830 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1832 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1833 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1834 if (vty
->node
== CONFIG_NODE
)
1835 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1837 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1838 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1839 if (vty
->node
== CONFIG_NODE
)
1840 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1842 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1843 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1844 if (vty
->node
== CONFIG_NODE
)
1845 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1847 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1849 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1850 return CMD_WARNING_CONFIG_FAILED
;
1853 if (vty
->node
!= CONFIG_NODE
)
1854 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1859 DEFUN (no_debug_bgp_vpn
,
1860 no_debug_bgp_vpn_cmd
,
1861 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1866 "leaked from vrf to vpn\n"
1867 "leaked to vrf from vpn\n"
1868 "route-map updates\n"
1873 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1874 if (vty
->node
== CONFIG_NODE
)
1875 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1877 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1879 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1880 if (vty
->node
== CONFIG_NODE
)
1881 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1883 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1884 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1885 if (vty
->node
== CONFIG_NODE
)
1886 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1888 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1889 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1890 if (vty
->node
== CONFIG_NODE
)
1891 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1893 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1895 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1896 return CMD_WARNING_CONFIG_FAILED
;
1899 if (vty
->node
!= CONFIG_NODE
)
1900 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1905 DEFUN (debug_bgp_pbr
,
1907 "debug bgp pbr [error]",
1910 "BGP policy based routing\n"
1915 if (argv_find(argv
, argc
, "error", &idx
)) {
1916 if (vty
->node
== CONFIG_NODE
)
1917 DEBUG_ON(pbr
, PBR_ERROR
);
1919 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1920 vty_out(vty
, "BGP policy based routing error is on\n");
1924 if (vty
->node
== CONFIG_NODE
)
1927 TERM_DEBUG_ON(pbr
, PBR
);
1928 vty_out(vty
, "BGP policy based routing is on\n");
1933 DEFUN (no_debug_bgp_pbr
,
1934 no_debug_bgp_pbr_cmd
,
1935 "no debug bgp pbr [error]",
1939 "BGP policy based routing\n"
1944 if (argv_find(argv
, argc
, "error", &idx
)) {
1945 if (vty
->node
== CONFIG_NODE
)
1946 DEBUG_OFF(pbr
, PBR_ERROR
);
1948 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1949 vty_out(vty
, "BGP policy based routing error is off\n");
1953 if (vty
->node
== CONFIG_NODE
)
1954 DEBUG_OFF(pbr
, PBR
);
1956 TERM_DEBUG_OFF(pbr
, PBR
);
1957 vty_out(vty
, "BGP policy based routing is off\n");
1962 DEFUN (debug_bgp_labelpool
,
1963 debug_bgp_labelpool_cmd
,
1964 "debug bgp labelpool",
1969 if (vty
->node
== CONFIG_NODE
)
1970 DEBUG_ON(labelpool
, LABELPOOL
);
1972 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
1974 if (vty
->node
!= CONFIG_NODE
)
1975 vty_out(vty
, "enabled debug bgp labelpool\n");
1980 DEFUN (no_debug_bgp_labelpool
,
1981 no_debug_bgp_labelpool_cmd
,
1982 "no debug bgp labelpool",
1988 if (vty
->node
== CONFIG_NODE
)
1989 DEBUG_OFF(labelpool
, LABELPOOL
);
1991 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
1994 if (vty
->node
!= CONFIG_NODE
)
1995 vty_out(vty
, "disabled debug bgp labelpool\n");
2000 DEFUN (no_debug_bgp
,
2008 struct listnode
*ln
;
2010 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2011 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2012 bgp_debug_list_free(bgp_debug_update_in_peers
);
2013 bgp_debug_list_free(bgp_debug_update_out_peers
);
2014 bgp_debug_list_free(bgp_debug_update_prefixes
);
2015 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2016 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2018 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2019 bgp_debug_clear_updgrp_update_dbg(bgp
);
2021 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2022 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2023 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2024 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2025 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2026 TERM_DEBUG_OFF(as4
, AS4
);
2027 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2028 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2029 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2030 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2031 TERM_DEBUG_OFF(nht
, NHT
);
2032 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2033 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2034 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2035 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2036 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2037 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2038 TERM_DEBUG_OFF(pbr
, PBR
);
2039 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2040 vty_out(vty
, "All possible debugging has been turned off\n");
2045 DEFUN_NOSH (show_debugging_bgp
,
2046 show_debugging_bgp_cmd
,
2047 "show debugging [bgp]",
2052 vty_out(vty
, "BGP debugging status:\n");
2054 if (BGP_DEBUG(as4
, AS4
))
2055 vty_out(vty
, " BGP as4 debugging is on\n");
2057 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2058 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2060 if (BGP_DEBUG(bestpath
, BESTPATH
))
2061 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2062 bgp_debug_bestpath_prefixes
);
2064 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2065 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2066 bgp_debug_keepalive_peers
);
2068 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2069 bgp_debug_list_print(vty
,
2070 " BGP neighbor-events debugging is on",
2071 bgp_debug_neighbor_events_peers
);
2073 if (BGP_DEBUG(nht
, NHT
))
2074 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2076 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2077 vty_out(vty
, " BGP update-groups debugging is on\n");
2079 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2080 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2081 bgp_debug_update_prefixes
);
2083 if (BGP_DEBUG(update
, UPDATE_IN
))
2084 bgp_debug_list_print(vty
,
2085 " BGP updates debugging is on (inbound)",
2086 bgp_debug_update_in_peers
);
2088 if (BGP_DEBUG(update
, UPDATE_OUT
))
2089 bgp_debug_list_print(vty
,
2090 " BGP updates debugging is on (outbound)",
2091 bgp_debug_update_out_peers
);
2093 if (BGP_DEBUG(zebra
, ZEBRA
))
2094 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2095 bgp_debug_zebra_prefixes
);
2097 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2098 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2100 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2102 " BGP route leak from vrf to vpn debugging is on\n");
2103 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2105 " BGP route leak to vrf from vpn debugging is on\n");
2106 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2107 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2108 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2109 vty_out(vty
, " BGP vpn label event debugging is on\n");
2110 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2111 vty_out(vty
, " BGP flowspec debugging is on\n");
2112 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2113 vty_out(vty
, " BGP labelpool debugging is on\n");
2115 if (BGP_DEBUG(pbr
, PBR
))
2116 vty_out(vty
, " BGP policy based routing debugging is on\n");
2117 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2118 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2124 /* return count of number of debug flags set */
2125 int bgp_debug_count(void)
2128 if (BGP_DEBUG(as4
, AS4
))
2131 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2134 if (BGP_DEBUG(bestpath
, BESTPATH
))
2137 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2140 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2143 if (BGP_DEBUG(nht
, NHT
))
2146 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2149 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2152 if (BGP_DEBUG(update
, UPDATE_IN
))
2155 if (BGP_DEBUG(update
, UPDATE_OUT
))
2158 if (BGP_DEBUG(zebra
, ZEBRA
))
2161 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2164 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2166 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2168 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2170 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2172 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2174 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2177 if (BGP_DEBUG(pbr
, PBR
))
2179 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2185 static int bgp_config_write_debug(struct vty
*vty
)
2189 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2190 vty_out(vty
, "debug bgp as4\n");
2194 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2195 vty_out(vty
, "debug bgp as4 segment\n");
2199 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2200 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2201 bgp_debug_bestpath_prefixes
);
2204 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2205 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2206 bgp_debug_keepalive_peers
);
2209 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2210 write
+= bgp_debug_list_conf_print(
2211 vty
, "debug bgp neighbor-events",
2212 bgp_debug_neighbor_events_peers
);
2215 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2216 vty_out(vty
, "debug bgp nht\n");
2220 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2221 vty_out(vty
, "debug bgp update-groups\n");
2225 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2226 write
+= bgp_debug_list_conf_print(vty
,
2227 "debug bgp updates prefix",
2228 bgp_debug_update_prefixes
);
2231 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2232 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2233 bgp_debug_update_in_peers
);
2236 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2237 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2238 bgp_debug_update_out_peers
);
2241 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2242 if (!bgp_debug_zebra_prefixes
2243 || list_isempty(bgp_debug_zebra_prefixes
)) {
2244 vty_out(vty
, "debug bgp zebra\n");
2247 write
+= bgp_debug_list_conf_print(
2248 vty
, "debug bgp zebra prefix",
2249 bgp_debug_zebra_prefixes
);
2253 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2254 vty_out(vty
, "debug bgp allow-martians\n");
2258 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2259 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2262 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2263 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2266 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2267 vty_out(vty
, "debug bgp vpn rmap-event\n");
2270 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2271 vty_out(vty
, "debug bgp vpn label\n");
2274 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2275 vty_out(vty
, "debug bgp flowspec\n");
2278 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2279 vty_out(vty
, "debug bgp labelpool\n");
2283 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2284 vty_out(vty
, "debug bgp pbr\n");
2287 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2288 vty_out(vty
, "debug bgp pbr error\n");
2294 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
2296 void bgp_debug_init(void)
2298 install_node(&debug_node
, bgp_config_write_debug
);
2300 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2302 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2303 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2304 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2305 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2307 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2308 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2309 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2310 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2311 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2312 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2313 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2314 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2315 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2316 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2317 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2318 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2319 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2320 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2321 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2322 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2324 /* debug bgp updates (in|out) */
2325 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2326 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2327 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2328 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2330 /* debug bgp updates (in|out) A.B.C.D */
2331 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2332 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2333 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2334 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2336 /* debug bgp updates prefix A.B.C.D/M */
2337 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2338 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2339 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2340 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2341 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2342 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2343 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2344 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2346 /* debug bgp zebra prefix A.B.C.D/M */
2347 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2348 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2349 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2350 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2352 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2353 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2354 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2355 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2357 /* debug bgp neighbor-events A.B.C.D */
2358 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2359 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2360 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2361 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2363 /* debug bgp keepalive A.B.C.D */
2364 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2365 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2366 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2367 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2369 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2370 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2371 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2372 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2373 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2374 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2375 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2376 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2377 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2378 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2379 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2380 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2381 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2382 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2383 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2384 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2385 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2386 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2387 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2389 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2390 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2391 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2392 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2394 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2395 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2396 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2397 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2400 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2401 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2402 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2403 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2407 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2408 * for BGP_DEBUG_TYPE
2410 static int bgp_debug_per_prefix(struct prefix
*p
,
2411 unsigned long term_bgp_debug_type
,
2412 unsigned int BGP_DEBUG_TYPE
,
2413 struct list
*per_prefix_list
)
2415 struct bgp_debug_filter
*filter
;
2416 struct listnode
*node
, *nnode
;
2418 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2419 /* We are debugging all prefixes so return true */
2420 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2427 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2429 if (filter
->p
->prefixlen
== p
->prefixlen
2430 && prefix_match(filter
->p
, p
))
2440 /* Return true if this peer is on the per_peer_list of peers to debug
2441 * for BGP_DEBUG_TYPE
2443 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2444 unsigned int BGP_DEBUG_TYPE
,
2445 struct list
*per_peer_list
)
2447 struct bgp_debug_filter
*filter
;
2448 struct listnode
*node
, *nnode
;
2450 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2451 /* We are debugging all peers so return true */
2452 if (!per_peer_list
|| list_isempty(per_peer_list
))
2459 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2461 if (strcmp(filter
->host
, host
) == 0)
2471 int bgp_debug_neighbor_events(struct peer
*peer
)
2478 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2479 BGP_DEBUG_NEIGHBOR_EVENTS
,
2480 bgp_debug_neighbor_events_peers
);
2483 int bgp_debug_keepalive(struct peer
*peer
)
2490 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2491 BGP_DEBUG_KEEPALIVE
,
2492 bgp_debug_keepalive_peers
);
2495 int bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
2496 struct update_group
*updgrp
, unsigned int inbound
)
2504 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2505 BGP_DEBUG_UPDATE_IN
,
2506 bgp_debug_update_in_peers
))
2512 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2513 BGP_DEBUG_UPDATE_OUT
,
2514 bgp_debug_update_out_peers
))
2517 /* Check if update debugging implicitly enabled for the group.
2519 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2524 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2525 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2526 BGP_DEBUG_UPDATE_PREFIX
,
2527 bgp_debug_update_prefixes
))
2534 int bgp_debug_bestpath(struct prefix
*p
)
2536 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2537 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
2539 bgp_debug_bestpath_prefixes
))
2546 int bgp_debug_zebra(struct prefix
*p
)
2548 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2549 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2551 bgp_debug_zebra_prefixes
))
2558 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2559 struct prefix_rd
*prd
,
2560 union prefixconstptr pu
,
2561 mpls_label_t
*label
, uint32_t num_labels
,
2562 int addpath_valid
, uint32_t addpath_id
,
2563 char *str
, int size
)
2565 char rd_buf
[RD_ADDRSTRLEN
];
2566 char pfx_buf
[PREFIX_STRLEN
];
2568 /* ' with addpath ID ' 17
2569 * max strlen of uint32 + 10
2570 * +/- (just in case) + 1
2571 * null terminator + 1
2572 * ============================ 29 */
2573 char pathid_buf
[30];
2575 if (size
< BGP_PRD_PATH_STRLEN
)
2578 /* Note: Path-id is created by default, but only included in update
2580 pathid_buf
[0] = '\0';
2582 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2586 if (bgp_labeled_safi(safi
) && num_labels
) {
2588 if (safi
== SAFI_EVPN
) {
2591 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2592 sprintf(tag_buf
, " label %s", tag_buf2
);
2594 uint32_t label_value
;
2596 label_value
= decode_label(label
);
2597 sprintf(tag_buf
, " label %u", label_value
);
2602 snprintf(str
, size
, "RD %s %s%s%s %s %s",
2603 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2604 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2605 pathid_buf
, afi2str(afi
), safi2str(safi
));
2606 else if (safi
== SAFI_FLOWSPEC
) {
2607 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2608 const struct prefix_fs
*fs
= pu
.fs
;
2610 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2611 fs
->prefix
.prefixlen
,
2613 NLRI_STRING_FORMAT_DEBUG
, NULL
);
2614 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2617 snprintf(str
, size
, "%s%s%s %s %s",
2618 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2619 pathid_buf
, afi2str(afi
), safi2str(safi
));