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
;
68 unsigned long term_bgp_debug_as4
;
69 unsigned long term_bgp_debug_neighbor_events
;
70 unsigned long term_bgp_debug_events
;
71 unsigned long term_bgp_debug_packet
;
72 unsigned long term_bgp_debug_filter
;
73 unsigned long term_bgp_debug_keepalive
;
74 unsigned long term_bgp_debug_update
;
75 unsigned long term_bgp_debug_bestpath
;
76 unsigned long term_bgp_debug_zebra
;
77 unsigned long term_bgp_debug_allow_martians
;
78 unsigned long term_bgp_debug_nht
;
79 unsigned long term_bgp_debug_update_groups
;
80 unsigned long term_bgp_debug_vpn
;
81 unsigned long term_bgp_debug_flowspec
;
82 unsigned long term_bgp_debug_labelpool
;
83 unsigned long term_bgp_debug_pbr
;
84 unsigned long term_bgp_debug_graceful_restart
;
86 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
87 struct list
*bgp_debug_keepalive_peers
= NULL
;
88 struct list
*bgp_debug_update_out_peers
= NULL
;
89 struct list
*bgp_debug_update_in_peers
= NULL
;
90 struct list
*bgp_debug_update_prefixes
= NULL
;
91 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
92 struct list
*bgp_debug_zebra_prefixes
= NULL
;
94 /* messages for BGP-4 status */
95 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
98 {OpenSent
, "OpenSent"},
99 {OpenConfirm
, "OpenConfirm"},
100 {Established
, "Established"},
101 {Clearing
, "Clearing"},
102 {Deleted
, "Deleted"},
105 /* BGP message type string. */
106 const char *const bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
107 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
110 /* message for BGP-4 Notify */
111 static const struct message bgp_notify_msg
[] = {
112 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
113 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
114 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
115 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
116 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
117 {BGP_NOTIFY_CEASE
, "Cease"},
118 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
121 static const struct message bgp_notify_head_msg
[] = {
122 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
123 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
124 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
127 static const struct message bgp_notify_open_msg
[] = {
128 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
129 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
130 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
131 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
132 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
133 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
134 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
135 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
138 static const struct message bgp_notify_update_msg
[] = {
139 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
140 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
141 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
142 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
143 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
144 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
145 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
146 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
147 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
148 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
149 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
150 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
153 static const struct message bgp_notify_cease_msg
[] = {
154 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
155 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
156 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
157 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
158 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
159 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
160 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
161 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
162 "/Connection collision resolution"},
163 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
166 static const struct message bgp_notify_capability_msg
[] = {
167 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
168 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
169 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
170 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
173 /* Origin strings. */
174 const char *const bgp_origin_str
[] = {"i", "e", "?"};
175 const char *const bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
177 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
179 /* Given a string return a pointer the corresponding peer structure */
180 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
182 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
190 ret
= str2sockunion(peer_str
, &su
);
194 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
197 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
201 return peer_lookup(bgp
, &su
);
204 static void bgp_debug_list_free(struct list
*list
)
206 struct bgp_debug_filter
*filter
;
207 struct listnode
*node
, *nnode
;
210 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
211 listnode_delete(list
, filter
);
212 prefix_free(&filter
->p
);
213 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
214 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
219 * Print the desc along with a list of peers/prefixes this debug is
222 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
225 struct bgp_debug_filter
*filter
;
226 struct listnode
*node
, *nnode
;
227 char buf
[PREFIX2STR_BUFFER
];
229 vty_out(vty
, "%s", desc
);
231 if (list
&& !list_isempty(list
)) {
232 vty_out(vty
, " for");
233 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
235 vty_out(vty
, " %s", filter
->host
);
237 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
238 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
239 else if (filter
->p
) {
240 prefix2str(filter
->p
, buf
, sizeof(buf
));
241 vty_out(vty
, " %s", buf
);
250 * Print the command to enable the debug for each peer/prefix this debug is
253 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
256 struct bgp_debug_filter
*filter
;
257 struct listnode
*node
, *nnode
;
258 char buf
[PREFIX2STR_BUFFER
];
261 if (list
&& !list_isempty(list
)) {
262 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
264 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
268 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
269 bgp_debug_print_evpn_prefix(vty
, desc
,
272 } else if (filter
->p
) {
273 prefix2str(filter
->p
, buf
, sizeof(buf
));
274 vty_out(vty
, "%s %s\n", desc
, buf
);
281 vty_out(vty
, "%s\n", desc
);
288 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
289 const struct prefix
*p
)
291 struct bgp_debug_filter
*filter
;
293 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
294 sizeof(struct bgp_debug_filter
));
297 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
301 filter
->p
= prefix_new();
302 prefix_copy(filter
->p
, p
);
305 listnode_add(list
, filter
);
308 static int bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
311 struct bgp_debug_filter
*filter
;
312 struct listnode
*node
, *nnode
;
314 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
315 if (host
&& strcmp(filter
->host
, host
) == 0) {
316 listnode_delete(list
, filter
);
317 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
318 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
320 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
321 && prefix_match(filter
->p
, p
)) {
322 listnode_delete(list
, filter
);
323 prefix_free(&filter
->p
);
324 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
332 static int bgp_debug_list_has_entry(struct list
*list
, const char *host
,
333 const struct prefix
*p
)
335 struct bgp_debug_filter
*filter
;
336 struct listnode
*node
, *nnode
;
338 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
340 if (strcmp(filter
->host
, host
) == 0) {
344 if (filter
->p
->prefixlen
== p
->prefixlen
345 && prefix_match(filter
->p
, p
)) {
354 int bgp_debug_peer_updout_enabled(char *host
)
356 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
360 /* Dump attribute. */
361 int bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
363 char addrbuf
[BUFSIZ
];
370 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
371 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
373 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
374 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
375 bgp_origin_str
[attr
->origin
]);
378 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
379 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
380 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
382 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
385 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
386 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
387 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
390 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
391 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
393 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
394 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
395 ", localpref %u", attr
->local_pref
);
397 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
398 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
401 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
402 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
404 community_str(attr
->community
, false));
406 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
407 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
408 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
410 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
411 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
412 ", atomic-aggregate");
414 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
415 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
416 ", aggregated by %u %s", attr
->aggregator_as
,
417 inet_ntoa(attr
->aggregator_addr
));
419 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
420 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
421 ", originator %s", inet_ntoa(attr
->originator_id
));
423 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
426 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
428 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
429 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
430 inet_ntoa(attr
->cluster
->list
[i
]));
433 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
434 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
435 ", pmsi tnltype %u", attr
->pmsi_tnl_type
);
437 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
438 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
439 aspath_print(attr
->aspath
));
441 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
442 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
443 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
444 ", label-index %u", attr
->label_index
);
453 const char *bgp_notify_code_str(char code
)
455 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
458 const char *bgp_notify_subcode_str(char code
, char subcode
)
462 case BGP_NOTIFY_HEADER_ERR
:
463 return lookup_msg(bgp_notify_head_msg
, subcode
,
464 "Unrecognized Error Subcode");
465 case BGP_NOTIFY_OPEN_ERR
:
466 return lookup_msg(bgp_notify_open_msg
, subcode
,
467 "Unrecognized Error Subcode");
468 case BGP_NOTIFY_UPDATE_ERR
:
469 return lookup_msg(bgp_notify_update_msg
, subcode
,
470 "Unrecognized Error Subcode");
471 case BGP_NOTIFY_HOLD_ERR
:
473 case BGP_NOTIFY_FSM_ERR
:
475 case BGP_NOTIFY_CEASE
:
476 return lookup_msg(bgp_notify_cease_msg
, subcode
,
477 "Unrecognized Error Subcode");
478 case BGP_NOTIFY_CAPABILITY_ERR
:
479 return lookup_msg(bgp_notify_capability_msg
, subcode
,
480 "Unrecognized Error Subcode");
485 /* extract notify admin reason if correctly present */
486 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
489 if (!data
|| datalen
< 1)
492 uint8_t len
= data
[0];
493 if (len
> 128 || len
> datalen
- 1)
496 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
499 /* dump notify packet */
500 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
503 const char *subcode_str
;
504 const char *code_str
;
505 const char *msg_str
= NULL
;
508 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
509 || CHECK_FLAG(peer
->bgp
->flags
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
510 code_str
= bgp_notify_code_str(bgp_notify
->code
);
511 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
512 bgp_notify
->subcode
);
514 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
515 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
516 || bgp_notify
->subcode
517 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
518 msg_str
= bgp_notify_admin_message(
519 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
525 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
526 strcmp(direct
, "received") == 0
529 peer
->host
, bgp_notify
->code
,
530 bgp_notify
->subcode
, code_str
, subcode_str
,
533 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
535 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
536 strcmp(direct
, "received") == 0
539 peer
->host
, bgp_notify
->code
,
540 bgp_notify
->subcode
, code_str
, subcode_str
,
541 bgp_notify
->length
, msg_str
);
546 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
549 bgp
= bgp_get_default();
550 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
553 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
556 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
557 char buf
[PREFIX2STR_BUFFER
];
558 char buf2
[ETHER_ADDR_STRLEN
];
560 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
561 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
562 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s",
564 &p
->u
.prefix_evpn
.macip_addr
.mac
,
565 buf2
, sizeof(buf2
)));
567 uint8_t family
= is_evpn_prefix_ipaddr_v4(
568 (struct prefix_evpn
*)p
) ?
570 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s ip %s",
572 &p
->u
.prefix_evpn
.macip_addr
.mac
,
575 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
576 buf
, PREFIX2STR_BUFFER
));
578 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
579 sprintf(evpn_desc
, "l2vpn evpn type multicast ip %s",
580 inet_ntoa(p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
));
581 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
582 uint8_t family
= is_evpn_prefix_ipaddr_v4(
583 (struct prefix_evpn
*)p
) ? AF_INET
585 sprintf(evpn_desc
, "l2vpn evpn type prefix ip %s/%d",
587 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
, buf
,
589 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
592 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
597 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
598 int argc
, struct prefix
**argv_pp
)
600 struct prefix
*argv_p
;
610 if (argv_find(argv
, argc
, "macip", &type_idx
))
611 evpn_type
= BGP_EVPN_MAC_IP_ROUTE
;
612 else if (argv_find(argv
, argc
, "multicast", &type_idx
))
613 evpn_type
= BGP_EVPN_IMET_ROUTE
;
614 else if (argv_find(argv
, argc
, "prefix", &type_idx
))
615 evpn_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
619 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
620 memset(&ip
, 0, sizeof(struct ipaddr
));
622 argv_find(argv
, argc
, "mac", &mac_idx
);
623 (void)prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
);
625 argv_find(argv
, argc
, "ip", &ip_idx
);
626 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
628 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
630 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
631 memset(&ip
, 0, sizeof(struct ipaddr
));
633 argv_find(argv
, argc
, "ip", &ip_idx
);
634 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
636 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
638 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
639 struct prefix ip_prefix
;
641 memset(&ip_prefix
, 0, sizeof(struct prefix
));
642 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
643 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
644 apply_mask(&ip_prefix
);
646 build_type5_prefix_from_ip_prefix(
647 (struct prefix_evpn
*)argv_p
,
654 /* Debug option setting interface. */
655 unsigned long bgp_debug_option
= 0;
657 int debug(unsigned int option
)
659 return bgp_debug_option
& option
;
662 DEFUN (debug_bgp_as4
,
669 if (vty
->node
== CONFIG_NODE
)
672 TERM_DEBUG_ON(as4
, AS4
);
673 vty_out(vty
, "BGP as4 debugging is on\n");
678 DEFUN (no_debug_bgp_as4
,
679 no_debug_bgp_as4_cmd
,
686 if (vty
->node
== CONFIG_NODE
)
689 TERM_DEBUG_OFF(as4
, AS4
);
690 vty_out(vty
, "BGP as4 debugging is off\n");
695 DEFUN (debug_bgp_as4_segment
,
696 debug_bgp_as4_segment_cmd
,
697 "debug bgp as4 segment",
701 "BGP AS4 aspath segment handling\n")
703 if (vty
->node
== CONFIG_NODE
)
704 DEBUG_ON(as4
, AS4_SEGMENT
);
706 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
707 vty_out(vty
, "BGP as4 segment debugging is on\n");
712 DEFUN (no_debug_bgp_as4_segment
,
713 no_debug_bgp_as4_segment_cmd
,
714 "no debug bgp as4 segment",
719 "BGP AS4 aspath segment handling\n")
721 if (vty
->node
== CONFIG_NODE
)
722 DEBUG_OFF(as4
, AS4_SEGMENT
);
724 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
725 vty_out(vty
, "BGP as4 segment debugging is off\n");
730 /* debug bgp neighbor_events */
731 DEFUN (debug_bgp_neighbor_events
,
732 debug_bgp_neighbor_events_cmd
,
733 "debug bgp neighbor-events",
736 "BGP Neighbor Events\n")
738 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
740 if (vty
->node
== CONFIG_NODE
)
741 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
743 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
744 vty_out(vty
, "BGP neighbor-events debugging is on\n");
749 DEFUN (debug_bgp_neighbor_events_peer
,
750 debug_bgp_neighbor_events_peer_cmd
,
751 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
754 "BGP Neighbor Events\n"
755 "BGP neighbor IP address to debug\n"
756 "BGP IPv6 neighbor to debug\n"
757 "BGP neighbor on interface to debug\n")
760 const char *host
= argv
[idx_peer
]->arg
;
762 if (!bgp_debug_neighbor_events_peers
)
763 bgp_debug_neighbor_events_peers
= list_new();
765 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
768 "BGP neighbor-events debugging is already enabled for %s\n",
773 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
775 if (vty
->node
== CONFIG_NODE
)
776 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
778 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
779 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
785 DEFUN (no_debug_bgp_neighbor_events
,
786 no_debug_bgp_neighbor_events_cmd
,
787 "no debug bgp neighbor-events",
793 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
795 if (vty
->node
== CONFIG_NODE
)
796 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
798 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
799 vty_out(vty
, "BGP neighbor-events debugging is off\n");
804 DEFUN (no_debug_bgp_neighbor_events_peer
,
805 no_debug_bgp_neighbor_events_peer_cmd
,
806 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
811 "BGP neighbor IP address to debug\n"
812 "BGP IPv6 neighbor to debug\n"
813 "BGP neighbor on interface to debug\n")
817 const char *host
= argv
[idx_peer
]->arg
;
819 if (bgp_debug_neighbor_events_peers
820 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
821 found_peer
= bgp_debug_list_remove_entry(
822 bgp_debug_neighbor_events_peers
, host
, NULL
);
824 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
825 if (vty
->node
== CONFIG_NODE
)
826 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
828 TERM_DEBUG_OFF(neighbor_events
,
834 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
838 "BGP neighbor-events debugging was not enabled for %s\n",
845 DEFUN (debug_bgp_nht
,
850 "BGP nexthop tracking events\n")
852 if (vty
->node
== CONFIG_NODE
)
855 TERM_DEBUG_ON(nht
, NHT
);
856 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
861 DEFUN (no_debug_bgp_nht
,
862 no_debug_bgp_nht_cmd
,
867 "BGP nexthop tracking events\n")
869 if (vty
->node
== CONFIG_NODE
)
872 TERM_DEBUG_OFF(nht
, NHT
);
873 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
878 /* debug bgp keepalives */
879 DEFUN (debug_bgp_keepalive
,
880 debug_bgp_keepalive_cmd
,
881 "debug bgp keepalives",
886 bgp_debug_list_free(bgp_debug_keepalive_peers
);
888 if (vty
->node
== CONFIG_NODE
)
889 DEBUG_ON(keepalive
, KEEPALIVE
);
891 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
892 vty_out(vty
, "BGP keepalives debugging is on\n");
897 DEFUN (debug_bgp_keepalive_peer
,
898 debug_bgp_keepalive_peer_cmd
,
899 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
902 "BGP Neighbor Events\n"
903 "BGP neighbor IP address to debug\n"
904 "BGP IPv6 neighbor to debug\n"
905 "BGP neighbor on interface to debug\n")
908 const char *host
= argv
[idx_peer
]->arg
;
910 if (!bgp_debug_keepalive_peers
)
911 bgp_debug_keepalive_peers
= list_new();
913 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
915 "BGP keepalive debugging is already enabled for %s\n",
920 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
922 if (vty
->node
== CONFIG_NODE
)
923 DEBUG_ON(keepalive
, KEEPALIVE
);
925 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
926 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
931 DEFUN (no_debug_bgp_keepalive
,
932 no_debug_bgp_keepalive_cmd
,
933 "no debug bgp keepalives",
939 bgp_debug_list_free(bgp_debug_keepalive_peers
);
941 if (vty
->node
== CONFIG_NODE
)
942 DEBUG_OFF(keepalive
, KEEPALIVE
);
944 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
945 vty_out(vty
, "BGP keepalives debugging is off\n");
950 DEFUN (no_debug_bgp_keepalive_peer
,
951 no_debug_bgp_keepalive_peer_cmd
,
952 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
957 "BGP neighbor IP address to debug\n"
958 "BGP IPv6 neighbor to debug\n"
959 "BGP neighbor on interface to debug\n")
963 const char *host
= argv
[idx_peer
]->arg
;
965 if (bgp_debug_keepalive_peers
966 && !list_isempty(bgp_debug_keepalive_peers
)) {
967 found_peer
= bgp_debug_list_remove_entry(
968 bgp_debug_keepalive_peers
, host
, NULL
);
970 if (list_isempty(bgp_debug_keepalive_peers
)) {
971 if (vty
->node
== CONFIG_NODE
)
972 DEBUG_OFF(keepalive
, KEEPALIVE
);
974 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
979 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
982 "BGP keepalives debugging was not enabled for %s\n",
988 /* debug bgp bestpath */
989 DEFUN (debug_bgp_bestpath_prefix
,
990 debug_bgp_bestpath_prefix_cmd
,
991 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
998 struct prefix
*argv_p
;
999 int idx_ipv4_ipv6_prefixlen
= 3;
1001 argv_p
= prefix_new();
1002 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1005 if (!bgp_debug_bestpath_prefixes
)
1006 bgp_debug_bestpath_prefixes
= list_new();
1008 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1011 "BGP bestpath debugging is already enabled for %s\n",
1012 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1016 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1018 if (vty
->node
== CONFIG_NODE
) {
1019 DEBUG_ON(bestpath
, BESTPATH
);
1021 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1022 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1023 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1029 DEFUN (no_debug_bgp_bestpath_prefix
,
1030 no_debug_bgp_bestpath_prefix_cmd
,
1031 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1039 int idx_ipv4_ipv6_prefixlen
= 4;
1040 struct prefix
*argv_p
;
1041 int found_prefix
= 0;
1043 argv_p
= prefix_new();
1044 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1047 if (bgp_debug_bestpath_prefixes
1048 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1049 found_prefix
= bgp_debug_list_remove_entry(
1050 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1052 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1053 if (vty
->node
== CONFIG_NODE
) {
1054 DEBUG_OFF(bestpath
, BESTPATH
);
1056 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1058 "BGP bestpath debugging (per prefix) is off\n");
1064 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1065 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1067 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1068 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1073 DEFUN (no_debug_bgp_bestpath
,
1074 no_debug_bgp_bestpath_cmd
,
1075 "no debug bgp bestpath",
1081 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1083 if (vty
->node
== CONFIG_NODE
)
1084 DEBUG_OFF(bestpath
, BESTPATH
);
1086 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1087 vty_out(vty
, "BGP bestpath debugging is off\n");
1092 /* debug bgp updates */
1093 DEFUN (debug_bgp_update
,
1094 debug_bgp_update_cmd
,
1095 "debug bgp updates",
1100 bgp_debug_list_free(bgp_debug_update_in_peers
);
1101 bgp_debug_list_free(bgp_debug_update_out_peers
);
1102 bgp_debug_list_free(bgp_debug_update_prefixes
);
1104 if (vty
->node
== CONFIG_NODE
) {
1105 DEBUG_ON(update
, UPDATE_IN
);
1106 DEBUG_ON(update
, UPDATE_OUT
);
1108 TERM_DEBUG_ON(update
, UPDATE_IN
);
1109 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1110 vty_out(vty
, "BGP updates debugging is on\n");
1115 DEFUN (debug_bgp_update_direct
,
1116 debug_bgp_update_direct_cmd
,
1117 "debug bgp updates <in|out>",
1122 "Outbound updates\n")
1126 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1127 bgp_debug_list_free(bgp_debug_update_in_peers
);
1129 bgp_debug_list_free(bgp_debug_update_out_peers
);
1131 if (vty
->node
== CONFIG_NODE
) {
1132 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1133 DEBUG_ON(update
, UPDATE_IN
);
1135 DEBUG_ON(update
, UPDATE_OUT
);
1137 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1138 TERM_DEBUG_ON(update
, UPDATE_IN
);
1139 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1141 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1143 "BGP updates debugging is on (outbound)\n");
1149 DEFUN (debug_bgp_update_direct_peer
,
1150 debug_bgp_update_direct_peer_cmd
,
1151 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1156 "Outbound updates\n"
1157 "BGP neighbor IP address to debug\n"
1158 "BGP IPv6 neighbor to debug\n"
1159 "BGP neighbor on interface to debug\n")
1163 const char *host
= argv
[idx_peer
]->arg
;
1166 if (!bgp_debug_update_in_peers
)
1167 bgp_debug_update_in_peers
= list_new();
1169 if (!bgp_debug_update_out_peers
)
1170 bgp_debug_update_out_peers
= list_new();
1172 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1178 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1181 "BGP inbound update debugging is already enabled for %s\n",
1188 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1191 "BGP outbound update debugging is already enabled for %s\n",
1198 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1201 struct peer_af
*paf
;
1204 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1206 peer
= bgp_find_peer(vty
, host
);
1209 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1211 paf
= peer
->peer_af_array
[afidx
];
1213 if (PAF_SUBGRP(paf
)) {
1223 if (vty
->node
== CONFIG_NODE
) {
1225 DEBUG_ON(update
, UPDATE_IN
);
1227 DEBUG_ON(update
, UPDATE_OUT
);
1230 TERM_DEBUG_ON(update
, UPDATE_IN
);
1232 "BGP updates debugging is on (inbound) for %s\n",
1233 argv
[idx_peer
]->arg
);
1235 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1237 "BGP updates debugging is on (outbound) for %s\n",
1238 argv
[idx_peer
]->arg
);
1244 DEFUN (no_debug_bgp_update_direct
,
1245 no_debug_bgp_update_direct_cmd
,
1246 "no debug bgp updates <in|out>",
1252 "Outbound updates\n")
1255 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1256 bgp_debug_list_free(bgp_debug_update_in_peers
);
1258 if (vty
->node
== CONFIG_NODE
) {
1259 DEBUG_OFF(update
, UPDATE_IN
);
1261 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1263 "BGP updates debugging is off (inbound)\n");
1266 bgp_debug_list_free(bgp_debug_update_out_peers
);
1268 if (vty
->node
== CONFIG_NODE
) {
1269 DEBUG_OFF(update
, UPDATE_OUT
);
1271 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1273 "BGP updates debugging is off (outbound)\n");
1280 DEFUN (no_debug_bgp_update_direct_peer
,
1281 no_debug_bgp_update_direct_peer_cmd
,
1282 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1288 "Outbound updates\n"
1289 "BGP neighbor IP address to debug\n"
1290 "BGP IPv6 neighbor to debug\n"
1291 "BGP neighbor on interface to debug\n")
1297 const char *host
= argv
[idx_peer
]->arg
;
1299 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1304 if (inbound
&& bgp_debug_update_in_peers
1305 && !list_isempty(bgp_debug_update_in_peers
)) {
1306 found_peer
= bgp_debug_list_remove_entry(
1307 bgp_debug_update_in_peers
, host
, NULL
);
1309 if (list_isempty(bgp_debug_update_in_peers
)) {
1310 if (vty
->node
== CONFIG_NODE
)
1311 DEBUG_OFF(update
, UPDATE_IN
);
1313 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1315 "BGP updates debugging (inbound) is off\n");
1320 if (!inbound
&& bgp_debug_update_out_peers
1321 && !list_isempty(bgp_debug_update_out_peers
)) {
1322 found_peer
= bgp_debug_list_remove_entry(
1323 bgp_debug_update_out_peers
, host
, NULL
);
1325 if (list_isempty(bgp_debug_update_out_peers
)) {
1326 if (vty
->node
== CONFIG_NODE
)
1327 DEBUG_OFF(update
, UPDATE_OUT
);
1329 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1331 "BGP updates debugging (outbound) is off\n");
1336 struct peer_af
*paf
;
1338 peer
= bgp_find_peer(vty
, host
);
1341 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1343 paf
= peer
->peer_af_array
[afidx
];
1345 if (PAF_SUBGRP(paf
)) {
1346 UPDGRP_PEER_DBG_DIS(
1358 "BGP updates debugging (inbound) is off for %s\n",
1362 "BGP updates debugging (outbound) is off for %s\n",
1366 "BGP updates debugging (inbound) was not enabled for %s\n",
1370 "BGP updates debugging (outbound) was not enabled for %s\n",
1376 #ifndef VTYSH_EXTRACT_PL
1377 #include "bgpd/bgp_debug_clippy.c"
1380 DEFPY (debug_bgp_update_prefix_afi_safi
,
1381 debug_bgp_update_prefix_afi_safi_cmd
,
1382 "debug bgp updates prefix l2vpn$afi evpn$safi type <macip mac <X:X:X:X:X:X|X:X:X:X:X:X/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>>",
1386 "Specify a prefix to debug\n"
1389 "Specify EVPN Route type\n"
1390 "MAC-IP (Type-2) route\n"
1391 MAC_STR MAC_STR MAC_STR
1395 "Multicast (Type-3) route\n"
1399 "Prefix (Type-5) route\n"
1404 struct prefix
*argv_p
;
1405 int ret
= CMD_SUCCESS
;
1406 char buf
[PREFIX2STR_BUFFER
];
1408 argv_p
= prefix_new();
1410 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1411 if (ret
!= CMD_SUCCESS
) {
1412 prefix_free(&argv_p
);
1416 if (!bgp_debug_update_prefixes
)
1417 bgp_debug_update_prefixes
= list_new();
1419 prefix2str(argv_p
, buf
, sizeof(buf
));
1421 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1423 "BGP updates debugging is already enabled for %s\n",
1425 prefix_free(&argv_p
);
1429 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1431 if (vty
->node
== CONFIG_NODE
) {
1432 DEBUG_ON(update
, UPDATE_PREFIX
);
1434 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1435 vty_out(vty
, "BGP updates debugging is on for %s\n", buf
);
1438 prefix_free(&argv_p
);
1443 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1444 no_debug_bgp_update_prefix_afi_safi_cmd
,
1445 "no debug bgp updates prefix l2vpn$afi evpn$safi type <macip mac <X:X:X:X:X:X|X:X:X:X:X:X/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>>",
1450 "Specify a prefix to debug\n"
1453 "Specify EVPN Route type\n"
1454 "MAC-IP (Type-2) route\n"
1455 MAC_STR MAC_STR MAC_STR
1459 "Multicast (Type-3) route\n"
1463 "Prefix (Type-5) route\n"
1468 struct prefix
*argv_p
;
1469 bool found_prefix
= false;
1470 int ret
= CMD_SUCCESS
;
1471 char buf
[PREFIX2STR_BUFFER
];
1473 argv_p
= prefix_new();
1475 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1476 if (ret
!= CMD_SUCCESS
) {
1477 prefix_free(&argv_p
);
1481 if (bgp_debug_update_prefixes
1482 && !list_isempty(bgp_debug_update_prefixes
)) {
1483 found_prefix
= bgp_debug_list_remove_entry(
1484 bgp_debug_update_prefixes
, NULL
, argv_p
);
1486 if (list_isempty(bgp_debug_update_prefixes
)) {
1487 if (vty
->node
== CONFIG_NODE
) {
1488 DEBUG_OFF(update
, UPDATE_PREFIX
);
1490 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1492 "BGP updates debugging (per prefix) is off\n");
1497 prefix2str(argv_p
, buf
, sizeof(buf
));
1500 vty_out(vty
, "BGP updates debugging is off for %s\n", buf
);
1502 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1505 prefix_free(&argv_p
);
1511 DEFUN (debug_bgp_update_prefix
,
1512 debug_bgp_update_prefix_cmd
,
1513 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1517 "Specify a prefix to debug\n"
1521 int idx_ipv4_ipv6_prefixlen
= 4;
1522 struct prefix
*argv_p
;
1524 argv_p
= prefix_new();
1525 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1528 if (!bgp_debug_update_prefixes
)
1529 bgp_debug_update_prefixes
= list_new();
1531 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1533 "BGP updates debugging is already enabled for %s\n",
1534 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1538 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1540 if (vty
->node
== CONFIG_NODE
) {
1541 DEBUG_ON(update
, UPDATE_PREFIX
);
1543 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1544 vty_out(vty
, "BGP updates debugging is on for %s\n",
1545 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1551 DEFUN (no_debug_bgp_update_prefix
,
1552 no_debug_bgp_update_prefix_cmd
,
1553 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1558 "Specify a prefix to debug\n"
1562 int idx_ipv4_ipv6_prefixlen
= 5;
1563 struct prefix
*argv_p
;
1564 int found_prefix
= 0;
1566 argv_p
= prefix_new();
1567 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1570 if (bgp_debug_update_prefixes
1571 && !list_isempty(bgp_debug_update_prefixes
)) {
1572 found_prefix
= bgp_debug_list_remove_entry(
1573 bgp_debug_update_prefixes
, NULL
, argv_p
);
1575 if (list_isempty(bgp_debug_update_prefixes
)) {
1576 if (vty
->node
== CONFIG_NODE
) {
1577 DEBUG_OFF(update
, UPDATE_PREFIX
);
1579 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1581 "BGP updates debugging (per prefix) is off\n");
1587 vty_out(vty
, "BGP updates debugging is off for %s\n",
1588 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1590 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1591 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1596 DEFUN (no_debug_bgp_update
,
1597 no_debug_bgp_update_cmd
,
1598 "no debug bgp updates",
1604 struct listnode
*ln
;
1607 bgp_debug_list_free(bgp_debug_update_in_peers
);
1608 bgp_debug_list_free(bgp_debug_update_out_peers
);
1609 bgp_debug_list_free(bgp_debug_update_prefixes
);
1611 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1612 bgp_debug_clear_updgrp_update_dbg(bgp
);
1614 if (vty
->node
== CONFIG_NODE
) {
1615 DEBUG_OFF(update
, UPDATE_IN
);
1616 DEBUG_OFF(update
, UPDATE_OUT
);
1617 DEBUG_OFF(update
, UPDATE_PREFIX
);
1619 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1620 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1621 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1622 vty_out(vty
, "BGP updates debugging is off\n");
1627 /* debug bgp zebra */
1628 DEFUN (debug_bgp_zebra
,
1629 debug_bgp_zebra_cmd
,
1633 "BGP Zebra messages\n")
1635 if (vty
->node
== CONFIG_NODE
)
1636 DEBUG_ON(zebra
, ZEBRA
);
1638 TERM_DEBUG_ON(zebra
, ZEBRA
);
1639 vty_out(vty
, "BGP zebra debugging is on\n");
1644 DEFUN (debug_bgp_graceful_restart
,
1645 debug_bgp_graceful_restart_cmd
,
1646 "debug bgp graceful-restart",
1651 if (vty
->node
== CONFIG_NODE
) {
1652 DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1654 TERM_DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1655 vty_out(vty
, "BGP Graceful Restart debugging is on\n");
1661 DEFUN (debug_bgp_zebra_prefix
,
1662 debug_bgp_zebra_prefix_cmd
,
1663 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1666 "BGP Zebra messages\n"
1667 "Specify a prefix to debug\n"
1671 int idx_ipv4_ipv6_prefixlen
= 4;
1672 struct prefix
*argv_p
;
1674 argv_p
= prefix_new();
1675 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1678 if (!bgp_debug_zebra_prefixes
)
1679 bgp_debug_zebra_prefixes
= list_new();
1681 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1682 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1683 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1687 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1689 if (vty
->node
== CONFIG_NODE
)
1690 DEBUG_ON(zebra
, ZEBRA
);
1692 TERM_DEBUG_ON(zebra
, ZEBRA
);
1693 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1694 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1700 DEFUN (no_debug_bgp_zebra
,
1701 no_debug_bgp_zebra_cmd
,
1702 "no debug bgp zebra",
1706 "BGP Zebra messages\n")
1708 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1710 if (vty
->node
== CONFIG_NODE
)
1711 DEBUG_OFF(zebra
, ZEBRA
);
1713 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1714 vty_out(vty
, "BGP zebra debugging is off\n");
1719 DEFUN (no_debug_bgp_graceful_restart
,
1720 no_debug_bgp_graceful_restart_cmd
,
1721 "no debug bgp graceful-restart",
1727 if (vty
->node
== CONFIG_NODE
) {
1728 DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1730 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1731 vty_out(vty
, "BGP Graceful Restart debugging is off\n");
1736 DEFUN (no_debug_bgp_zebra_prefix
,
1737 no_debug_bgp_zebra_prefix_cmd
,
1738 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1742 "BGP Zebra messages\n"
1743 "Specify a prefix to debug\n"
1747 int idx_ipv4_ipv6_prefixlen
= 5;
1748 struct prefix
*argv_p
;
1749 int found_prefix
= 0;
1751 argv_p
= prefix_new();
1752 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1755 if (bgp_debug_zebra_prefixes
1756 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1757 found_prefix
= bgp_debug_list_remove_entry(
1758 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1760 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1761 if (vty
->node
== CONFIG_NODE
)
1762 DEBUG_OFF(zebra
, ZEBRA
);
1764 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1765 vty_out(vty
, "BGP zebra debugging is off\n");
1771 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1772 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1774 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1775 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1780 DEFUN (debug_bgp_allow_martians
,
1781 debug_bgp_allow_martians_cmd
,
1782 "debug bgp allow-martians",
1785 "BGP allow martian next hops\n")
1787 if (vty
->node
== CONFIG_NODE
)
1788 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1790 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1791 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1796 DEFUN (no_debug_bgp_allow_martians
,
1797 no_debug_bgp_allow_martians_cmd
,
1798 "no debug bgp allow-martians",
1802 "BGP allow martian next hops\n")
1804 if (vty
->node
== CONFIG_NODE
)
1805 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1807 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1808 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1814 /* debug bgp update-groups */
1815 DEFUN (debug_bgp_update_groups
,
1816 debug_bgp_update_groups_cmd
,
1817 "debug bgp update-groups",
1820 "BGP update-groups\n")
1822 if (vty
->node
== CONFIG_NODE
)
1823 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1825 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1826 vty_out(vty
, "BGP update-groups debugging is on\n");
1831 DEFUN (no_debug_bgp_update_groups
,
1832 no_debug_bgp_update_groups_cmd
,
1833 "no debug bgp update-groups",
1837 "BGP update-groups\n")
1839 if (vty
->node
== CONFIG_NODE
)
1840 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1842 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1843 vty_out(vty
, "BGP update-groups debugging is off\n");
1848 DEFUN (debug_bgp_vpn
,
1850 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1854 "leaked from vrf to vpn\n"
1855 "leaked to vrf from vpn\n"
1856 "route-map updates\n"
1861 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1862 if (vty
->node
== CONFIG_NODE
)
1863 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1865 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1866 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1867 if (vty
->node
== CONFIG_NODE
)
1868 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1870 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1871 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1872 if (vty
->node
== CONFIG_NODE
)
1873 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1875 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1876 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1877 if (vty
->node
== CONFIG_NODE
)
1878 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1880 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1882 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1883 return CMD_WARNING_CONFIG_FAILED
;
1886 if (vty
->node
!= CONFIG_NODE
)
1887 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1892 DEFUN (no_debug_bgp_vpn
,
1893 no_debug_bgp_vpn_cmd
,
1894 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1899 "leaked from vrf to vpn\n"
1900 "leaked to vrf from vpn\n"
1901 "route-map updates\n"
1906 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1907 if (vty
->node
== CONFIG_NODE
)
1908 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1910 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1912 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1913 if (vty
->node
== CONFIG_NODE
)
1914 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1916 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1917 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1918 if (vty
->node
== CONFIG_NODE
)
1919 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1921 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1922 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1923 if (vty
->node
== CONFIG_NODE
)
1924 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1926 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1928 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1929 return CMD_WARNING_CONFIG_FAILED
;
1932 if (vty
->node
!= CONFIG_NODE
)
1933 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1938 DEFUN (debug_bgp_pbr
,
1940 "debug bgp pbr [error]",
1943 "BGP policy based routing\n"
1948 if (argv_find(argv
, argc
, "error", &idx
)) {
1949 if (vty
->node
== CONFIG_NODE
)
1950 DEBUG_ON(pbr
, PBR_ERROR
);
1952 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1953 vty_out(vty
, "BGP policy based routing error is on\n");
1957 if (vty
->node
== CONFIG_NODE
)
1960 TERM_DEBUG_ON(pbr
, PBR
);
1961 vty_out(vty
, "BGP policy based routing is on\n");
1966 DEFUN (no_debug_bgp_pbr
,
1967 no_debug_bgp_pbr_cmd
,
1968 "no debug bgp pbr [error]",
1972 "BGP policy based routing\n"
1977 if (argv_find(argv
, argc
, "error", &idx
)) {
1978 if (vty
->node
== CONFIG_NODE
)
1979 DEBUG_OFF(pbr
, PBR_ERROR
);
1981 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1982 vty_out(vty
, "BGP policy based routing error is off\n");
1986 if (vty
->node
== CONFIG_NODE
)
1987 DEBUG_OFF(pbr
, PBR
);
1989 TERM_DEBUG_OFF(pbr
, PBR
);
1990 vty_out(vty
, "BGP policy based routing is off\n");
1995 DEFUN (debug_bgp_labelpool
,
1996 debug_bgp_labelpool_cmd
,
1997 "debug bgp labelpool",
2002 if (vty
->node
== CONFIG_NODE
)
2003 DEBUG_ON(labelpool
, LABELPOOL
);
2005 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
2007 if (vty
->node
!= CONFIG_NODE
)
2008 vty_out(vty
, "enabled debug bgp labelpool\n");
2013 DEFUN (no_debug_bgp_labelpool
,
2014 no_debug_bgp_labelpool_cmd
,
2015 "no debug bgp labelpool",
2021 if (vty
->node
== CONFIG_NODE
)
2022 DEBUG_OFF(labelpool
, LABELPOOL
);
2024 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2027 if (vty
->node
!= CONFIG_NODE
)
2028 vty_out(vty
, "disabled debug bgp labelpool\n");
2033 DEFUN (no_debug_bgp
,
2041 struct listnode
*ln
;
2043 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2044 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2045 bgp_debug_list_free(bgp_debug_update_in_peers
);
2046 bgp_debug_list_free(bgp_debug_update_out_peers
);
2047 bgp_debug_list_free(bgp_debug_update_prefixes
);
2048 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2049 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2051 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2052 bgp_debug_clear_updgrp_update_dbg(bgp
);
2054 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2055 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2056 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2057 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2058 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2059 TERM_DEBUG_OFF(as4
, AS4
);
2060 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2061 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2062 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2063 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2064 TERM_DEBUG_OFF(nht
, NHT
);
2065 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2066 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2067 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2068 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2069 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2070 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2071 TERM_DEBUG_OFF(pbr
, PBR
);
2072 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2073 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
2075 vty_out(vty
, "All possible debugging has been turned off\n");
2080 DEFUN_NOSH (show_debugging_bgp
,
2081 show_debugging_bgp_cmd
,
2082 "show debugging [bgp]",
2087 vty_out(vty
, "BGP debugging status:\n");
2089 if (BGP_DEBUG(as4
, AS4
))
2090 vty_out(vty
, " BGP as4 debugging is on\n");
2092 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2093 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2095 if (BGP_DEBUG(bestpath
, BESTPATH
))
2096 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2097 bgp_debug_bestpath_prefixes
);
2099 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2100 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2101 bgp_debug_keepalive_peers
);
2103 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2104 bgp_debug_list_print(vty
,
2105 " BGP neighbor-events debugging is on",
2106 bgp_debug_neighbor_events_peers
);
2108 if (BGP_DEBUG(nht
, NHT
))
2109 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2111 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2112 vty_out(vty
, " BGP update-groups debugging is on\n");
2114 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2115 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2116 bgp_debug_update_prefixes
);
2118 if (BGP_DEBUG(update
, UPDATE_IN
))
2119 bgp_debug_list_print(vty
,
2120 " BGP updates debugging is on (inbound)",
2121 bgp_debug_update_in_peers
);
2123 if (BGP_DEBUG(update
, UPDATE_OUT
))
2124 bgp_debug_list_print(vty
,
2125 " BGP updates debugging is on (outbound)",
2126 bgp_debug_update_out_peers
);
2128 if (BGP_DEBUG(zebra
, ZEBRA
))
2129 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2130 bgp_debug_zebra_prefixes
);
2132 if (BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
))
2133 vty_out(vty
, " BGP graceful-restart debugging is on");
2135 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2136 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2138 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2140 " BGP route leak from vrf to vpn debugging is on\n");
2141 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2143 " BGP route leak to vrf from vpn debugging is on\n");
2144 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2145 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2146 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2147 vty_out(vty
, " BGP vpn label event debugging is on\n");
2148 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2149 vty_out(vty
, " BGP flowspec debugging is on\n");
2150 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2151 vty_out(vty
, " BGP labelpool debugging is on\n");
2153 if (BGP_DEBUG(pbr
, PBR
))
2154 vty_out(vty
, " BGP policy based routing debugging is on\n");
2155 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2156 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2162 static int bgp_config_write_debug(struct vty
*vty
)
2166 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2167 vty_out(vty
, "debug bgp as4\n");
2171 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2172 vty_out(vty
, "debug bgp as4 segment\n");
2176 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2177 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2178 bgp_debug_bestpath_prefixes
);
2181 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2182 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2183 bgp_debug_keepalive_peers
);
2186 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2187 write
+= bgp_debug_list_conf_print(
2188 vty
, "debug bgp neighbor-events",
2189 bgp_debug_neighbor_events_peers
);
2192 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2193 vty_out(vty
, "debug bgp nht\n");
2197 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2198 vty_out(vty
, "debug bgp update-groups\n");
2202 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2203 write
+= bgp_debug_list_conf_print(vty
,
2204 "debug bgp updates prefix",
2205 bgp_debug_update_prefixes
);
2208 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2209 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2210 bgp_debug_update_in_peers
);
2213 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2214 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2215 bgp_debug_update_out_peers
);
2218 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2219 if (!bgp_debug_zebra_prefixes
2220 || list_isempty(bgp_debug_zebra_prefixes
)) {
2221 vty_out(vty
, "debug bgp zebra\n");
2224 write
+= bgp_debug_list_conf_print(
2225 vty
, "debug bgp zebra prefix",
2226 bgp_debug_zebra_prefixes
);
2230 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2231 vty_out(vty
, "debug bgp allow-martians\n");
2235 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2236 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2239 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2240 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2243 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2244 vty_out(vty
, "debug bgp vpn rmap-event\n");
2247 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2248 vty_out(vty
, "debug bgp vpn label\n");
2251 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2252 vty_out(vty
, "debug bgp flowspec\n");
2255 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2256 vty_out(vty
, "debug bgp labelpool\n");
2260 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2261 vty_out(vty
, "debug bgp pbr\n");
2264 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2265 vty_out(vty
, "debug bgp pbr error\n");
2269 if (CONF_BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
)) {
2270 vty_out(vty
, "debug bgp graceful-restart\n");
2276 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
2278 void bgp_debug_init(void)
2280 install_node(&debug_node
, bgp_config_write_debug
);
2282 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2284 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2285 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2286 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2287 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2289 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2290 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2291 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2292 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2293 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2294 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2295 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2296 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2297 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2298 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2299 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2300 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2301 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2302 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2303 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2304 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2306 install_element(ENABLE_NODE
, &debug_bgp_graceful_restart_cmd
);
2307 install_element(CONFIG_NODE
, &debug_bgp_graceful_restart_cmd
);
2309 /* debug bgp updates (in|out) */
2310 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2311 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2312 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2313 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2315 /* debug bgp updates (in|out) A.B.C.D */
2316 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2317 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2318 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2319 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2321 /* debug bgp updates prefix A.B.C.D/M */
2322 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2323 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2324 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2325 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2326 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2327 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2328 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2329 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2331 /* debug bgp zebra prefix A.B.C.D/M */
2332 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2333 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2334 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2335 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2337 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2338 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2339 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2340 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2342 /* debug bgp neighbor-events A.B.C.D */
2343 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2344 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2345 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2346 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2348 /* debug bgp keepalive A.B.C.D */
2349 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2350 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2351 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2352 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2354 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2355 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2356 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2357 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2358 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2359 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2360 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2361 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2362 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2363 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2364 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2365 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2366 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2367 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2368 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2369 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2370 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2371 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2372 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2374 install_element(ENABLE_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2375 install_element(CONFIG_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2377 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2378 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2379 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2380 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2382 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2383 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2384 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2385 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2388 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2389 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2390 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2391 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2395 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2396 * for BGP_DEBUG_TYPE
2398 static int bgp_debug_per_prefix(struct prefix
*p
,
2399 unsigned long term_bgp_debug_type
,
2400 unsigned int BGP_DEBUG_TYPE
,
2401 struct list
*per_prefix_list
)
2403 struct bgp_debug_filter
*filter
;
2404 struct listnode
*node
, *nnode
;
2406 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2407 /* We are debugging all prefixes so return true */
2408 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2415 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2417 if (filter
->p
->prefixlen
== p
->prefixlen
2418 && prefix_match(filter
->p
, p
))
2428 /* Return true if this peer is on the per_peer_list of peers to debug
2429 * for BGP_DEBUG_TYPE
2431 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2432 unsigned int BGP_DEBUG_TYPE
,
2433 struct list
*per_peer_list
)
2435 struct bgp_debug_filter
*filter
;
2436 struct listnode
*node
, *nnode
;
2438 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2439 /* We are debugging all peers so return true */
2440 if (!per_peer_list
|| list_isempty(per_peer_list
))
2447 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2449 if (strcmp(filter
->host
, host
) == 0)
2459 int bgp_debug_neighbor_events(struct peer
*peer
)
2466 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2467 BGP_DEBUG_NEIGHBOR_EVENTS
,
2468 bgp_debug_neighbor_events_peers
);
2471 int bgp_debug_keepalive(struct peer
*peer
)
2478 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2479 BGP_DEBUG_KEEPALIVE
,
2480 bgp_debug_keepalive_peers
);
2483 int bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
2484 struct update_group
*updgrp
, unsigned int inbound
)
2492 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2493 BGP_DEBUG_UPDATE_IN
,
2494 bgp_debug_update_in_peers
))
2500 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2501 BGP_DEBUG_UPDATE_OUT
,
2502 bgp_debug_update_out_peers
))
2505 /* Check if update debugging implicitly enabled for the group.
2507 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2512 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2513 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2514 BGP_DEBUG_UPDATE_PREFIX
,
2515 bgp_debug_update_prefixes
))
2522 int bgp_debug_bestpath(struct prefix
*p
)
2524 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2525 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
2527 bgp_debug_bestpath_prefixes
))
2534 int bgp_debug_zebra(struct prefix
*p
)
2536 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2537 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2539 bgp_debug_zebra_prefixes
))
2546 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2547 struct prefix_rd
*prd
,
2548 union prefixconstptr pu
,
2549 mpls_label_t
*label
, uint32_t num_labels
,
2550 int addpath_valid
, uint32_t addpath_id
,
2551 char *str
, int size
)
2553 char rd_buf
[RD_ADDRSTRLEN
];
2554 char pfx_buf
[PREFIX_STRLEN
];
2556 /* ' with addpath ID ' 17
2557 * max strlen of uint32 + 10
2558 * +/- (just in case) + 1
2559 * null terminator + 1
2560 * ============================ 29 */
2561 char pathid_buf
[30];
2563 if (size
< BGP_PRD_PATH_STRLEN
)
2566 /* Note: Path-id is created by default, but only included in update
2568 pathid_buf
[0] = '\0';
2570 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2574 if (bgp_labeled_safi(safi
) && num_labels
) {
2576 if (safi
== SAFI_EVPN
) {
2579 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2580 sprintf(tag_buf
, " label %s", tag_buf2
);
2582 uint32_t label_value
;
2584 label_value
= decode_label(label
);
2585 sprintf(tag_buf
, " label %u", label_value
);
2590 snprintf(str
, size
, "RD %s %s%s%s %s %s",
2591 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2592 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2593 pathid_buf
, afi2str(afi
), safi2str(safi
));
2594 else if (safi
== SAFI_FLOWSPEC
) {
2595 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2596 const struct prefix_fs
*fs
= pu
.fs
;
2598 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2599 fs
->prefix
.prefixlen
,
2601 NLRI_STRING_FORMAT_DEBUG
, NULL
);
2602 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2605 snprintf(str
, size
, "%s%s%s %s %s",
2606 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2607 pathid_buf
, afi2str(afi
), safi2str(safi
));