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 static const struct message bgp_notify_fsm_msg
[] = {
174 {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC
, "/Unspecific"},
175 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT
,
176 "/Receive Unexpected Message in OpenSent State"},
177 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM
,
178 "/Receive Unexpected Message in OpenConfirm State"},
179 {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED
,
180 "/Receive Unexpected Message in Established State"},
183 /* Origin strings. */
184 const char *const bgp_origin_str
[] = {"i", "e", "?"};
185 const char *const bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
187 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
189 /* Given a string return a pointer the corresponding peer structure */
190 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
192 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
200 ret
= str2sockunion(peer_str
, &su
);
204 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
207 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
211 return peer_lookup(bgp
, &su
);
214 static void bgp_debug_list_free(struct list
*list
)
216 struct bgp_debug_filter
*filter
;
217 struct listnode
*node
, *nnode
;
220 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
221 listnode_delete(list
, filter
);
222 prefix_free(&filter
->p
);
223 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
224 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
229 * Print the desc along with a list of peers/prefixes this debug is
232 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
235 struct bgp_debug_filter
*filter
;
236 struct listnode
*node
, *nnode
;
237 char buf
[PREFIX2STR_BUFFER
];
239 vty_out(vty
, "%s", desc
);
241 if (list
&& !list_isempty(list
)) {
242 vty_out(vty
, " for");
243 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
245 vty_out(vty
, " %s", filter
->host
);
247 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
248 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
249 else if (filter
->p
) {
250 prefix2str(filter
->p
, buf
, sizeof(buf
));
251 vty_out(vty
, " %s", buf
);
260 * Print the command to enable the debug for each peer/prefix this debug is
263 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
266 struct bgp_debug_filter
*filter
;
267 struct listnode
*node
, *nnode
;
268 char buf
[PREFIX2STR_BUFFER
];
271 if (list
&& !list_isempty(list
)) {
272 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
274 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
278 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
279 bgp_debug_print_evpn_prefix(vty
, desc
,
282 } else if (filter
->p
) {
283 prefix2str(filter
->p
, buf
, sizeof(buf
));
284 vty_out(vty
, "%s %s\n", desc
, buf
);
291 vty_out(vty
, "%s\n", desc
);
298 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
299 const struct prefix
*p
)
301 struct bgp_debug_filter
*filter
;
303 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
304 sizeof(struct bgp_debug_filter
));
307 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
311 filter
->p
= prefix_new();
312 prefix_copy(filter
->p
, p
);
315 listnode_add(list
, filter
);
318 static bool bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
321 struct bgp_debug_filter
*filter
;
322 struct listnode
*node
, *nnode
;
324 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
325 if (host
&& strcmp(filter
->host
, host
) == 0) {
326 listnode_delete(list
, filter
);
327 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
328 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
330 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
331 && prefix_match(filter
->p
, p
)) {
332 listnode_delete(list
, filter
);
333 prefix_free(&filter
->p
);
334 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
342 static bool bgp_debug_list_has_entry(struct list
*list
, const char *host
,
343 const struct prefix
*p
)
345 struct bgp_debug_filter
*filter
;
346 struct listnode
*node
, *nnode
;
348 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
350 if (strcmp(filter
->host
, host
) == 0) {
354 if (filter
->p
->prefixlen
== p
->prefixlen
355 && prefix_match(filter
->p
, p
)) {
364 bool bgp_debug_peer_updout_enabled(char *host
)
366 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
370 /* Dump attribute. */
371 bool bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
373 char addrbuf
[BUFSIZ
];
380 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
381 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
383 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
384 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
385 bgp_origin_str
[attr
->origin
]);
388 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
389 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
390 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
392 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
395 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
396 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
397 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
400 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
401 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
403 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
404 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
405 ", localpref %u", attr
->local_pref
);
407 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
408 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
411 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
412 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
414 community_str(attr
->community
, false));
416 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
417 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
418 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
420 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
421 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
422 ", atomic-aggregate");
424 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
425 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
426 ", aggregated by %u %s", attr
->aggregator_as
,
427 inet_ntoa(attr
->aggregator_addr
));
429 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
430 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
431 ", originator %s", inet_ntoa(attr
->originator_id
));
433 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
436 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
438 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
439 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
440 inet_ntoa(attr
->cluster
->list
[i
]));
443 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
444 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
445 ", pmsi tnltype %u", attr
->pmsi_tnl_type
);
447 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
448 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
449 aspath_print(attr
->aspath
));
451 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
452 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
453 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
454 ", label-index %u", attr
->label_index
);
463 const char *bgp_notify_code_str(char code
)
465 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
468 const char *bgp_notify_subcode_str(char code
, char subcode
)
472 case BGP_NOTIFY_HEADER_ERR
:
473 return lookup_msg(bgp_notify_head_msg
, subcode
,
474 "Unrecognized Error Subcode");
475 case BGP_NOTIFY_OPEN_ERR
:
476 return lookup_msg(bgp_notify_open_msg
, subcode
,
477 "Unrecognized Error Subcode");
478 case BGP_NOTIFY_UPDATE_ERR
:
479 return lookup_msg(bgp_notify_update_msg
, subcode
,
480 "Unrecognized Error Subcode");
481 case BGP_NOTIFY_HOLD_ERR
:
483 case BGP_NOTIFY_FSM_ERR
:
484 return lookup_msg(bgp_notify_fsm_msg
, subcode
,
485 "Unrecognized Error Subcode");
486 case BGP_NOTIFY_CEASE
:
487 return lookup_msg(bgp_notify_cease_msg
, subcode
,
488 "Unrecognized Error Subcode");
489 case BGP_NOTIFY_CAPABILITY_ERR
:
490 return lookup_msg(bgp_notify_capability_msg
, subcode
,
491 "Unrecognized Error Subcode");
496 /* extract notify admin reason if correctly present */
497 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
500 if (!data
|| datalen
< 1)
503 uint8_t len
= data
[0];
504 if (len
> 128 || len
> datalen
- 1)
507 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
510 /* dump notify packet */
511 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
514 const char *subcode_str
;
515 const char *code_str
;
516 const char *msg_str
= NULL
;
519 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
520 || CHECK_FLAG(peer
->bgp
->flags
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
521 code_str
= bgp_notify_code_str(bgp_notify
->code
);
522 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
523 bgp_notify
->subcode
);
525 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
526 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
527 || bgp_notify
->subcode
528 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
529 msg_str
= bgp_notify_admin_message(
530 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
536 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
537 strcmp(direct
, "received") == 0
540 peer
->host
, bgp_notify
->code
,
541 bgp_notify
->subcode
, code_str
, subcode_str
,
544 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
546 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
547 strcmp(direct
, "received") == 0
550 peer
->host
, bgp_notify
->code
,
551 bgp_notify
->subcode
, code_str
, subcode_str
,
552 bgp_notify
->length
, msg_str
);
557 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
560 bgp
= bgp_get_default();
561 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
564 static void bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
567 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
568 char buf
[PREFIX2STR_BUFFER
];
569 char buf2
[ETHER_ADDR_STRLEN
];
571 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
572 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
573 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s",
575 &p
->u
.prefix_evpn
.macip_addr
.mac
,
576 buf2
, sizeof(buf2
)));
578 uint8_t family
= is_evpn_prefix_ipaddr_v4(
579 (struct prefix_evpn
*)p
) ?
581 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s ip %s",
583 &p
->u
.prefix_evpn
.macip_addr
.mac
,
586 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
587 buf
, PREFIX2STR_BUFFER
));
589 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
590 sprintf(evpn_desc
, "l2vpn evpn type multicast ip %s",
591 inet_ntoa(p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
));
592 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
593 uint8_t family
= is_evpn_prefix_ipaddr_v4(
594 (struct prefix_evpn
*)p
) ? AF_INET
596 sprintf(evpn_desc
, "l2vpn evpn type prefix ip %s/%d",
598 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
, buf
,
600 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
603 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
606 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
607 int argc
, struct prefix
**argv_pp
)
609 struct prefix
*argv_p
;
619 if (argv_find(argv
, argc
, "macip", &type_idx
))
620 evpn_type
= BGP_EVPN_MAC_IP_ROUTE
;
621 else if (argv_find(argv
, argc
, "multicast", &type_idx
))
622 evpn_type
= BGP_EVPN_IMET_ROUTE
;
623 else if (argv_find(argv
, argc
, "prefix", &type_idx
))
624 evpn_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
628 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
629 memset(&ip
, 0, sizeof(struct ipaddr
));
631 argv_find(argv
, argc
, "mac", &mac_idx
);
632 (void)prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
);
634 argv_find(argv
, argc
, "ip", &ip_idx
);
635 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
637 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
639 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
640 memset(&ip
, 0, sizeof(struct ipaddr
));
642 argv_find(argv
, argc
, "ip", &ip_idx
);
643 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
645 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
647 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
648 struct prefix ip_prefix
;
650 memset(&ip_prefix
, 0, sizeof(struct prefix
));
651 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
652 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
653 apply_mask(&ip_prefix
);
655 build_type5_prefix_from_ip_prefix(
656 (struct prefix_evpn
*)argv_p
,
663 /* Debug option setting interface. */
664 unsigned long bgp_debug_option
= 0;
666 int debug(unsigned int option
)
668 return bgp_debug_option
& option
;
671 DEFUN (debug_bgp_as4
,
678 if (vty
->node
== CONFIG_NODE
)
681 TERM_DEBUG_ON(as4
, AS4
);
682 vty_out(vty
, "BGP as4 debugging is on\n");
687 DEFUN (no_debug_bgp_as4
,
688 no_debug_bgp_as4_cmd
,
695 if (vty
->node
== CONFIG_NODE
)
698 TERM_DEBUG_OFF(as4
, AS4
);
699 vty_out(vty
, "BGP as4 debugging is off\n");
704 DEFUN (debug_bgp_as4_segment
,
705 debug_bgp_as4_segment_cmd
,
706 "debug bgp as4 segment",
710 "BGP AS4 aspath segment handling\n")
712 if (vty
->node
== CONFIG_NODE
)
713 DEBUG_ON(as4
, AS4_SEGMENT
);
715 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
716 vty_out(vty
, "BGP as4 segment debugging is on\n");
721 DEFUN (no_debug_bgp_as4_segment
,
722 no_debug_bgp_as4_segment_cmd
,
723 "no debug bgp as4 segment",
728 "BGP AS4 aspath segment handling\n")
730 if (vty
->node
== CONFIG_NODE
)
731 DEBUG_OFF(as4
, AS4_SEGMENT
);
733 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
734 vty_out(vty
, "BGP as4 segment debugging is off\n");
739 /* debug bgp neighbor_events */
740 DEFUN (debug_bgp_neighbor_events
,
741 debug_bgp_neighbor_events_cmd
,
742 "debug bgp neighbor-events",
745 "BGP Neighbor Events\n")
747 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
749 if (vty
->node
== CONFIG_NODE
)
750 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
752 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
753 vty_out(vty
, "BGP neighbor-events debugging is on\n");
758 DEFUN (debug_bgp_neighbor_events_peer
,
759 debug_bgp_neighbor_events_peer_cmd
,
760 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
763 "BGP Neighbor Events\n"
764 "BGP neighbor IP address to debug\n"
765 "BGP IPv6 neighbor to debug\n"
766 "BGP neighbor on interface to debug\n")
769 const char *host
= argv
[idx_peer
]->arg
;
771 if (!bgp_debug_neighbor_events_peers
)
772 bgp_debug_neighbor_events_peers
= list_new();
774 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
777 "BGP neighbor-events debugging is already enabled for %s\n",
782 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
784 if (vty
->node
== CONFIG_NODE
)
785 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
787 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
788 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
794 DEFUN (no_debug_bgp_neighbor_events
,
795 no_debug_bgp_neighbor_events_cmd
,
796 "no debug bgp neighbor-events",
802 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
804 if (vty
->node
== CONFIG_NODE
)
805 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
807 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
808 vty_out(vty
, "BGP neighbor-events debugging is off\n");
813 DEFUN (no_debug_bgp_neighbor_events_peer
,
814 no_debug_bgp_neighbor_events_peer_cmd
,
815 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
820 "BGP neighbor IP address to debug\n"
821 "BGP IPv6 neighbor to debug\n"
822 "BGP neighbor on interface to debug\n")
826 const char *host
= argv
[idx_peer
]->arg
;
828 if (bgp_debug_neighbor_events_peers
829 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
830 found_peer
= bgp_debug_list_remove_entry(
831 bgp_debug_neighbor_events_peers
, host
, NULL
);
833 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
834 if (vty
->node
== CONFIG_NODE
)
835 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
837 TERM_DEBUG_OFF(neighbor_events
,
843 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
847 "BGP neighbor-events debugging was not enabled for %s\n",
854 DEFUN (debug_bgp_nht
,
859 "BGP nexthop tracking events\n")
861 if (vty
->node
== CONFIG_NODE
)
864 TERM_DEBUG_ON(nht
, NHT
);
865 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
870 DEFUN (no_debug_bgp_nht
,
871 no_debug_bgp_nht_cmd
,
876 "BGP nexthop tracking events\n")
878 if (vty
->node
== CONFIG_NODE
)
881 TERM_DEBUG_OFF(nht
, NHT
);
882 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
887 /* debug bgp keepalives */
888 DEFUN (debug_bgp_keepalive
,
889 debug_bgp_keepalive_cmd
,
890 "debug bgp keepalives",
895 bgp_debug_list_free(bgp_debug_keepalive_peers
);
897 if (vty
->node
== CONFIG_NODE
)
898 DEBUG_ON(keepalive
, KEEPALIVE
);
900 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
901 vty_out(vty
, "BGP keepalives debugging is on\n");
906 DEFUN (debug_bgp_keepalive_peer
,
907 debug_bgp_keepalive_peer_cmd
,
908 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
911 "BGP Neighbor Events\n"
912 "BGP neighbor IP address to debug\n"
913 "BGP IPv6 neighbor to debug\n"
914 "BGP neighbor on interface to debug\n")
917 const char *host
= argv
[idx_peer
]->arg
;
919 if (!bgp_debug_keepalive_peers
)
920 bgp_debug_keepalive_peers
= list_new();
922 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
924 "BGP keepalive debugging is already enabled for %s\n",
929 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
931 if (vty
->node
== CONFIG_NODE
)
932 DEBUG_ON(keepalive
, KEEPALIVE
);
934 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
935 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
940 DEFUN (no_debug_bgp_keepalive
,
941 no_debug_bgp_keepalive_cmd
,
942 "no debug bgp keepalives",
948 bgp_debug_list_free(bgp_debug_keepalive_peers
);
950 if (vty
->node
== CONFIG_NODE
)
951 DEBUG_OFF(keepalive
, KEEPALIVE
);
953 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
954 vty_out(vty
, "BGP keepalives debugging is off\n");
959 DEFUN (no_debug_bgp_keepalive_peer
,
960 no_debug_bgp_keepalive_peer_cmd
,
961 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
966 "BGP neighbor IP address to debug\n"
967 "BGP IPv6 neighbor to debug\n"
968 "BGP neighbor on interface to debug\n")
972 const char *host
= argv
[idx_peer
]->arg
;
974 if (bgp_debug_keepalive_peers
975 && !list_isempty(bgp_debug_keepalive_peers
)) {
976 found_peer
= bgp_debug_list_remove_entry(
977 bgp_debug_keepalive_peers
, host
, NULL
);
979 if (list_isempty(bgp_debug_keepalive_peers
)) {
980 if (vty
->node
== CONFIG_NODE
)
981 DEBUG_OFF(keepalive
, KEEPALIVE
);
983 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
988 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
991 "BGP keepalives debugging was not enabled for %s\n",
997 /* debug bgp bestpath */
998 DEFUN (debug_bgp_bestpath_prefix
,
999 debug_bgp_bestpath_prefix_cmd
,
1000 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1007 struct prefix
*argv_p
;
1008 int idx_ipv4_ipv6_prefixlen
= 3;
1010 argv_p
= prefix_new();
1011 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1014 if (!bgp_debug_bestpath_prefixes
)
1015 bgp_debug_bestpath_prefixes
= list_new();
1017 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1020 "BGP bestpath debugging is already enabled for %s\n",
1021 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1025 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1027 if (vty
->node
== CONFIG_NODE
) {
1028 DEBUG_ON(bestpath
, BESTPATH
);
1030 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1031 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1032 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1038 DEFUN (no_debug_bgp_bestpath_prefix
,
1039 no_debug_bgp_bestpath_prefix_cmd
,
1040 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1048 int idx_ipv4_ipv6_prefixlen
= 4;
1049 struct prefix
*argv_p
;
1050 int found_prefix
= 0;
1052 argv_p
= prefix_new();
1053 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1056 if (bgp_debug_bestpath_prefixes
1057 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1058 found_prefix
= bgp_debug_list_remove_entry(
1059 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1061 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1062 if (vty
->node
== CONFIG_NODE
) {
1063 DEBUG_OFF(bestpath
, BESTPATH
);
1065 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1067 "BGP bestpath debugging (per prefix) is off\n");
1073 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1074 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1076 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1077 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1082 DEFUN (no_debug_bgp_bestpath
,
1083 no_debug_bgp_bestpath_cmd
,
1084 "no debug bgp bestpath",
1090 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1092 if (vty
->node
== CONFIG_NODE
)
1093 DEBUG_OFF(bestpath
, BESTPATH
);
1095 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1096 vty_out(vty
, "BGP bestpath debugging is off\n");
1101 /* debug bgp updates */
1102 DEFUN (debug_bgp_update
,
1103 debug_bgp_update_cmd
,
1104 "debug bgp updates",
1109 bgp_debug_list_free(bgp_debug_update_in_peers
);
1110 bgp_debug_list_free(bgp_debug_update_out_peers
);
1111 bgp_debug_list_free(bgp_debug_update_prefixes
);
1113 if (vty
->node
== CONFIG_NODE
) {
1114 DEBUG_ON(update
, UPDATE_IN
);
1115 DEBUG_ON(update
, UPDATE_OUT
);
1117 TERM_DEBUG_ON(update
, UPDATE_IN
);
1118 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1119 vty_out(vty
, "BGP updates debugging is on\n");
1124 DEFUN (debug_bgp_update_direct
,
1125 debug_bgp_update_direct_cmd
,
1126 "debug bgp updates <in|out>",
1131 "Outbound updates\n")
1135 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1136 bgp_debug_list_free(bgp_debug_update_in_peers
);
1138 bgp_debug_list_free(bgp_debug_update_out_peers
);
1140 if (vty
->node
== CONFIG_NODE
) {
1141 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1142 DEBUG_ON(update
, UPDATE_IN
);
1144 DEBUG_ON(update
, UPDATE_OUT
);
1146 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1147 TERM_DEBUG_ON(update
, UPDATE_IN
);
1148 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1150 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1152 "BGP updates debugging is on (outbound)\n");
1158 DEFUN (debug_bgp_update_direct_peer
,
1159 debug_bgp_update_direct_peer_cmd
,
1160 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1165 "Outbound updates\n"
1166 "BGP neighbor IP address to debug\n"
1167 "BGP IPv6 neighbor to debug\n"
1168 "BGP neighbor on interface to debug\n")
1172 const char *host
= argv
[idx_peer
]->arg
;
1175 if (!bgp_debug_update_in_peers
)
1176 bgp_debug_update_in_peers
= list_new();
1178 if (!bgp_debug_update_out_peers
)
1179 bgp_debug_update_out_peers
= list_new();
1181 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1187 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1190 "BGP inbound update debugging is already enabled for %s\n",
1197 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1200 "BGP outbound update debugging is already enabled for %s\n",
1207 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1210 struct peer_af
*paf
;
1213 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1215 peer
= bgp_find_peer(vty
, host
);
1218 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1220 paf
= peer
->peer_af_array
[afidx
];
1222 if (PAF_SUBGRP(paf
)) {
1232 if (vty
->node
== CONFIG_NODE
) {
1234 DEBUG_ON(update
, UPDATE_IN
);
1236 DEBUG_ON(update
, UPDATE_OUT
);
1239 TERM_DEBUG_ON(update
, UPDATE_IN
);
1241 "BGP updates debugging is on (inbound) for %s\n",
1242 argv
[idx_peer
]->arg
);
1244 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1246 "BGP updates debugging is on (outbound) for %s\n",
1247 argv
[idx_peer
]->arg
);
1253 DEFUN (no_debug_bgp_update_direct
,
1254 no_debug_bgp_update_direct_cmd
,
1255 "no debug bgp updates <in|out>",
1261 "Outbound updates\n")
1264 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1265 bgp_debug_list_free(bgp_debug_update_in_peers
);
1267 if (vty
->node
== CONFIG_NODE
) {
1268 DEBUG_OFF(update
, UPDATE_IN
);
1270 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1272 "BGP updates debugging is off (inbound)\n");
1275 bgp_debug_list_free(bgp_debug_update_out_peers
);
1277 if (vty
->node
== CONFIG_NODE
) {
1278 DEBUG_OFF(update
, UPDATE_OUT
);
1280 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1282 "BGP updates debugging is off (outbound)\n");
1289 DEFUN (no_debug_bgp_update_direct_peer
,
1290 no_debug_bgp_update_direct_peer_cmd
,
1291 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1297 "Outbound updates\n"
1298 "BGP neighbor IP address to debug\n"
1299 "BGP IPv6 neighbor to debug\n"
1300 "BGP neighbor on interface to debug\n")
1306 const char *host
= argv
[idx_peer
]->arg
;
1308 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1313 if (inbound
&& bgp_debug_update_in_peers
1314 && !list_isempty(bgp_debug_update_in_peers
)) {
1315 found_peer
= bgp_debug_list_remove_entry(
1316 bgp_debug_update_in_peers
, host
, NULL
);
1318 if (list_isempty(bgp_debug_update_in_peers
)) {
1319 if (vty
->node
== CONFIG_NODE
)
1320 DEBUG_OFF(update
, UPDATE_IN
);
1322 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1324 "BGP updates debugging (inbound) is off\n");
1329 if (!inbound
&& bgp_debug_update_out_peers
1330 && !list_isempty(bgp_debug_update_out_peers
)) {
1331 found_peer
= bgp_debug_list_remove_entry(
1332 bgp_debug_update_out_peers
, host
, NULL
);
1334 if (list_isempty(bgp_debug_update_out_peers
)) {
1335 if (vty
->node
== CONFIG_NODE
)
1336 DEBUG_OFF(update
, UPDATE_OUT
);
1338 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1340 "BGP updates debugging (outbound) is off\n");
1345 struct peer_af
*paf
;
1347 peer
= bgp_find_peer(vty
, host
);
1350 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1352 paf
= peer
->peer_af_array
[afidx
];
1354 if (PAF_SUBGRP(paf
)) {
1355 UPDGRP_PEER_DBG_DIS(
1367 "BGP updates debugging (inbound) is off for %s\n",
1371 "BGP updates debugging (outbound) is off for %s\n",
1375 "BGP updates debugging (inbound) was not enabled for %s\n",
1379 "BGP updates debugging (outbound) was not enabled for %s\n",
1385 #ifndef VTYSH_EXTRACT_PL
1386 #include "bgpd/bgp_debug_clippy.c"
1389 DEFPY (debug_bgp_update_prefix_afi_safi
,
1390 debug_bgp_update_prefix_afi_safi_cmd
,
1391 "debug bgp updates prefix l2vpn$afi evpn$safi type <macip 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>>",
1395 "Specify a prefix to debug\n"
1398 "Specify EVPN Route type\n"
1399 "MAC-IP (Type-2) route\n"
1400 MAC_STR MAC_STR MAC_STR
1404 "Multicast (Type-3) route\n"
1408 "Prefix (Type-5) route\n"
1413 struct prefix
*argv_p
;
1414 int ret
= CMD_SUCCESS
;
1415 char buf
[PREFIX2STR_BUFFER
];
1417 argv_p
= prefix_new();
1419 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1420 if (ret
!= CMD_SUCCESS
) {
1421 prefix_free(&argv_p
);
1425 if (!bgp_debug_update_prefixes
)
1426 bgp_debug_update_prefixes
= list_new();
1428 prefix2str(argv_p
, buf
, sizeof(buf
));
1430 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1432 "BGP updates debugging is already enabled for %s\n",
1434 prefix_free(&argv_p
);
1438 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1440 if (vty
->node
== CONFIG_NODE
) {
1441 DEBUG_ON(update
, UPDATE_PREFIX
);
1443 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1444 vty_out(vty
, "BGP updates debugging is on for %s\n", buf
);
1447 prefix_free(&argv_p
);
1452 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1453 no_debug_bgp_update_prefix_afi_safi_cmd
,
1454 "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>>",
1459 "Specify a prefix to debug\n"
1462 "Specify EVPN Route type\n"
1463 "MAC-IP (Type-2) route\n"
1464 MAC_STR MAC_STR MAC_STR
1468 "Multicast (Type-3) route\n"
1472 "Prefix (Type-5) route\n"
1477 struct prefix
*argv_p
;
1478 bool found_prefix
= false;
1479 int ret
= CMD_SUCCESS
;
1480 char buf
[PREFIX2STR_BUFFER
];
1482 argv_p
= prefix_new();
1484 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1485 if (ret
!= CMD_SUCCESS
) {
1486 prefix_free(&argv_p
);
1490 if (bgp_debug_update_prefixes
1491 && !list_isempty(bgp_debug_update_prefixes
)) {
1492 found_prefix
= bgp_debug_list_remove_entry(
1493 bgp_debug_update_prefixes
, NULL
, argv_p
);
1495 if (list_isempty(bgp_debug_update_prefixes
)) {
1496 if (vty
->node
== CONFIG_NODE
) {
1497 DEBUG_OFF(update
, UPDATE_PREFIX
);
1499 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1501 "BGP updates debugging (per prefix) is off\n");
1506 prefix2str(argv_p
, buf
, sizeof(buf
));
1509 vty_out(vty
, "BGP updates debugging is off for %s\n", buf
);
1511 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1514 prefix_free(&argv_p
);
1520 DEFUN (debug_bgp_update_prefix
,
1521 debug_bgp_update_prefix_cmd
,
1522 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1526 "Specify a prefix to debug\n"
1530 int idx_ipv4_ipv6_prefixlen
= 4;
1531 struct prefix
*argv_p
;
1533 argv_p
= prefix_new();
1534 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1537 if (!bgp_debug_update_prefixes
)
1538 bgp_debug_update_prefixes
= list_new();
1540 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1542 "BGP updates debugging is already enabled for %s\n",
1543 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1547 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1549 if (vty
->node
== CONFIG_NODE
) {
1550 DEBUG_ON(update
, UPDATE_PREFIX
);
1552 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1553 vty_out(vty
, "BGP updates debugging is on for %s\n",
1554 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1560 DEFUN (no_debug_bgp_update_prefix
,
1561 no_debug_bgp_update_prefix_cmd
,
1562 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1567 "Specify a prefix to debug\n"
1571 int idx_ipv4_ipv6_prefixlen
= 5;
1572 struct prefix
*argv_p
;
1573 int found_prefix
= 0;
1575 argv_p
= prefix_new();
1576 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1579 if (bgp_debug_update_prefixes
1580 && !list_isempty(bgp_debug_update_prefixes
)) {
1581 found_prefix
= bgp_debug_list_remove_entry(
1582 bgp_debug_update_prefixes
, NULL
, argv_p
);
1584 if (list_isempty(bgp_debug_update_prefixes
)) {
1585 if (vty
->node
== CONFIG_NODE
) {
1586 DEBUG_OFF(update
, UPDATE_PREFIX
);
1588 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1590 "BGP updates debugging (per prefix) is off\n");
1596 vty_out(vty
, "BGP updates debugging is off for %s\n",
1597 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1599 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1600 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1605 DEFUN (no_debug_bgp_update
,
1606 no_debug_bgp_update_cmd
,
1607 "no debug bgp updates",
1613 struct listnode
*ln
;
1616 bgp_debug_list_free(bgp_debug_update_in_peers
);
1617 bgp_debug_list_free(bgp_debug_update_out_peers
);
1618 bgp_debug_list_free(bgp_debug_update_prefixes
);
1620 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1621 bgp_debug_clear_updgrp_update_dbg(bgp
);
1623 if (vty
->node
== CONFIG_NODE
) {
1624 DEBUG_OFF(update
, UPDATE_IN
);
1625 DEBUG_OFF(update
, UPDATE_OUT
);
1626 DEBUG_OFF(update
, UPDATE_PREFIX
);
1628 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1629 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1630 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1631 vty_out(vty
, "BGP updates debugging is off\n");
1636 /* debug bgp zebra */
1637 DEFUN (debug_bgp_zebra
,
1638 debug_bgp_zebra_cmd
,
1642 "BGP Zebra messages\n")
1644 if (vty
->node
== CONFIG_NODE
)
1645 DEBUG_ON(zebra
, ZEBRA
);
1647 TERM_DEBUG_ON(zebra
, ZEBRA
);
1648 vty_out(vty
, "BGP zebra debugging is on\n");
1653 DEFUN (debug_bgp_graceful_restart
,
1654 debug_bgp_graceful_restart_cmd
,
1655 "debug bgp graceful-restart",
1660 if (vty
->node
== CONFIG_NODE
) {
1661 DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1663 TERM_DEBUG_ON(graceful_restart
, GRACEFUL_RESTART
);
1664 vty_out(vty
, "BGP Graceful Restart debugging is on\n");
1670 DEFUN (debug_bgp_zebra_prefix
,
1671 debug_bgp_zebra_prefix_cmd
,
1672 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1675 "BGP Zebra messages\n"
1676 "Specify a prefix to debug\n"
1680 int idx_ipv4_ipv6_prefixlen
= 4;
1681 struct prefix
*argv_p
;
1683 argv_p
= prefix_new();
1684 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1687 if (!bgp_debug_zebra_prefixes
)
1688 bgp_debug_zebra_prefixes
= list_new();
1690 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1691 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1692 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1696 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1698 if (vty
->node
== CONFIG_NODE
)
1699 DEBUG_ON(zebra
, ZEBRA
);
1701 TERM_DEBUG_ON(zebra
, ZEBRA
);
1702 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1703 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1709 DEFUN (no_debug_bgp_zebra
,
1710 no_debug_bgp_zebra_cmd
,
1711 "no debug bgp zebra",
1715 "BGP Zebra messages\n")
1717 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1719 if (vty
->node
== CONFIG_NODE
)
1720 DEBUG_OFF(zebra
, ZEBRA
);
1722 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1723 vty_out(vty
, "BGP zebra debugging is off\n");
1728 DEFUN (no_debug_bgp_graceful_restart
,
1729 no_debug_bgp_graceful_restart_cmd
,
1730 "no debug bgp graceful-restart",
1736 if (vty
->node
== CONFIG_NODE
) {
1737 DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1739 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
1740 vty_out(vty
, "BGP Graceful Restart debugging is off\n");
1745 DEFUN (no_debug_bgp_zebra_prefix
,
1746 no_debug_bgp_zebra_prefix_cmd
,
1747 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1751 "BGP Zebra messages\n"
1752 "Specify a prefix to debug\n"
1756 int idx_ipv4_ipv6_prefixlen
= 5;
1757 struct prefix
*argv_p
;
1758 int found_prefix
= 0;
1760 argv_p
= prefix_new();
1761 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1764 if (bgp_debug_zebra_prefixes
1765 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1766 found_prefix
= bgp_debug_list_remove_entry(
1767 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1769 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1770 if (vty
->node
== CONFIG_NODE
)
1771 DEBUG_OFF(zebra
, ZEBRA
);
1773 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1774 vty_out(vty
, "BGP zebra debugging is off\n");
1780 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1781 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1783 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1784 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1789 DEFUN (debug_bgp_allow_martians
,
1790 debug_bgp_allow_martians_cmd
,
1791 "debug bgp allow-martians",
1794 "BGP allow martian next hops\n")
1796 if (vty
->node
== CONFIG_NODE
)
1797 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1799 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1800 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1805 DEFUN (no_debug_bgp_allow_martians
,
1806 no_debug_bgp_allow_martians_cmd
,
1807 "no debug bgp allow-martians",
1811 "BGP allow martian next hops\n")
1813 if (vty
->node
== CONFIG_NODE
)
1814 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1816 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1817 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1823 /* debug bgp update-groups */
1824 DEFUN (debug_bgp_update_groups
,
1825 debug_bgp_update_groups_cmd
,
1826 "debug bgp update-groups",
1829 "BGP update-groups\n")
1831 if (vty
->node
== CONFIG_NODE
)
1832 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1834 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1835 vty_out(vty
, "BGP update-groups debugging is on\n");
1840 DEFUN (no_debug_bgp_update_groups
,
1841 no_debug_bgp_update_groups_cmd
,
1842 "no debug bgp update-groups",
1846 "BGP update-groups\n")
1848 if (vty
->node
== CONFIG_NODE
)
1849 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1851 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1852 vty_out(vty
, "BGP update-groups debugging is off\n");
1857 DEFUN (debug_bgp_vpn
,
1859 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1863 "leaked from vrf to vpn\n"
1864 "leaked to vrf from vpn\n"
1865 "route-map updates\n"
1870 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1871 if (vty
->node
== CONFIG_NODE
)
1872 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1874 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1875 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1876 if (vty
->node
== CONFIG_NODE
)
1877 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1879 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1880 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1881 if (vty
->node
== CONFIG_NODE
)
1882 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1884 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1885 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1886 if (vty
->node
== CONFIG_NODE
)
1887 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1889 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1891 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1892 return CMD_WARNING_CONFIG_FAILED
;
1895 if (vty
->node
!= CONFIG_NODE
)
1896 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1901 DEFUN (no_debug_bgp_vpn
,
1902 no_debug_bgp_vpn_cmd
,
1903 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1908 "leaked from vrf to vpn\n"
1909 "leaked to vrf from vpn\n"
1910 "route-map updates\n"
1915 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1916 if (vty
->node
== CONFIG_NODE
)
1917 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1919 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1921 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1922 if (vty
->node
== CONFIG_NODE
)
1923 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1925 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1926 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1927 if (vty
->node
== CONFIG_NODE
)
1928 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1930 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1931 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1932 if (vty
->node
== CONFIG_NODE
)
1933 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1935 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1937 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1938 return CMD_WARNING_CONFIG_FAILED
;
1941 if (vty
->node
!= CONFIG_NODE
)
1942 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1947 DEFUN (debug_bgp_pbr
,
1949 "debug bgp pbr [error]",
1952 "BGP policy based routing\n"
1957 if (argv_find(argv
, argc
, "error", &idx
)) {
1958 if (vty
->node
== CONFIG_NODE
)
1959 DEBUG_ON(pbr
, PBR_ERROR
);
1961 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1962 vty_out(vty
, "BGP policy based routing error is on\n");
1966 if (vty
->node
== CONFIG_NODE
)
1969 TERM_DEBUG_ON(pbr
, PBR
);
1970 vty_out(vty
, "BGP policy based routing is on\n");
1975 DEFUN (no_debug_bgp_pbr
,
1976 no_debug_bgp_pbr_cmd
,
1977 "no debug bgp pbr [error]",
1981 "BGP policy based routing\n"
1986 if (argv_find(argv
, argc
, "error", &idx
)) {
1987 if (vty
->node
== CONFIG_NODE
)
1988 DEBUG_OFF(pbr
, PBR_ERROR
);
1990 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1991 vty_out(vty
, "BGP policy based routing error is off\n");
1995 if (vty
->node
== CONFIG_NODE
)
1996 DEBUG_OFF(pbr
, PBR
);
1998 TERM_DEBUG_OFF(pbr
, PBR
);
1999 vty_out(vty
, "BGP policy based routing is off\n");
2004 DEFUN (debug_bgp_labelpool
,
2005 debug_bgp_labelpool_cmd
,
2006 "debug bgp labelpool",
2011 if (vty
->node
== CONFIG_NODE
)
2012 DEBUG_ON(labelpool
, LABELPOOL
);
2014 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
2016 if (vty
->node
!= CONFIG_NODE
)
2017 vty_out(vty
, "enabled debug bgp labelpool\n");
2022 DEFUN (no_debug_bgp_labelpool
,
2023 no_debug_bgp_labelpool_cmd
,
2024 "no debug bgp labelpool",
2030 if (vty
->node
== CONFIG_NODE
)
2031 DEBUG_OFF(labelpool
, LABELPOOL
);
2033 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2036 if (vty
->node
!= CONFIG_NODE
)
2037 vty_out(vty
, "disabled debug bgp labelpool\n");
2042 DEFUN (no_debug_bgp
,
2050 struct listnode
*ln
;
2052 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2053 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2054 bgp_debug_list_free(bgp_debug_update_in_peers
);
2055 bgp_debug_list_free(bgp_debug_update_out_peers
);
2056 bgp_debug_list_free(bgp_debug_update_prefixes
);
2057 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2058 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2060 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2061 bgp_debug_clear_updgrp_update_dbg(bgp
);
2063 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2064 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2065 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2066 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2067 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2068 TERM_DEBUG_OFF(as4
, AS4
);
2069 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2070 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2071 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2072 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2073 TERM_DEBUG_OFF(nht
, NHT
);
2074 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2075 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2076 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2077 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2078 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2079 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2080 TERM_DEBUG_OFF(pbr
, PBR
);
2081 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2082 TERM_DEBUG_OFF(graceful_restart
, GRACEFUL_RESTART
);
2084 vty_out(vty
, "All possible debugging has been turned off\n");
2089 DEFUN_NOSH (show_debugging_bgp
,
2090 show_debugging_bgp_cmd
,
2091 "show debugging [bgp]",
2096 vty_out(vty
, "BGP debugging status:\n");
2098 if (BGP_DEBUG(as4
, AS4
))
2099 vty_out(vty
, " BGP as4 debugging is on\n");
2101 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2102 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2104 if (BGP_DEBUG(bestpath
, BESTPATH
))
2105 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2106 bgp_debug_bestpath_prefixes
);
2108 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2109 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2110 bgp_debug_keepalive_peers
);
2112 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2113 bgp_debug_list_print(vty
,
2114 " BGP neighbor-events debugging is on",
2115 bgp_debug_neighbor_events_peers
);
2117 if (BGP_DEBUG(nht
, NHT
))
2118 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2120 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2121 vty_out(vty
, " BGP update-groups debugging is on\n");
2123 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2124 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2125 bgp_debug_update_prefixes
);
2127 if (BGP_DEBUG(update
, UPDATE_IN
))
2128 bgp_debug_list_print(vty
,
2129 " BGP updates debugging is on (inbound)",
2130 bgp_debug_update_in_peers
);
2132 if (BGP_DEBUG(update
, UPDATE_OUT
))
2133 bgp_debug_list_print(vty
,
2134 " BGP updates debugging is on (outbound)",
2135 bgp_debug_update_out_peers
);
2137 if (BGP_DEBUG(zebra
, ZEBRA
))
2138 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2139 bgp_debug_zebra_prefixes
);
2141 if (BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
))
2142 vty_out(vty
, " BGP graceful-restart debugging is on");
2144 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2145 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2147 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2149 " BGP route leak from vrf to vpn debugging is on\n");
2150 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2152 " BGP route leak to vrf from vpn debugging is on\n");
2153 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2154 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2155 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2156 vty_out(vty
, " BGP vpn label event debugging is on\n");
2157 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2158 vty_out(vty
, " BGP flowspec debugging is on\n");
2159 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2160 vty_out(vty
, " BGP labelpool debugging is on\n");
2162 if (BGP_DEBUG(pbr
, PBR
))
2163 vty_out(vty
, " BGP policy based routing debugging is on\n");
2164 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2165 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2171 static int bgp_config_write_debug(struct vty
*vty
)
2175 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2176 vty_out(vty
, "debug bgp as4\n");
2180 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2181 vty_out(vty
, "debug bgp as4 segment\n");
2185 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2186 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2187 bgp_debug_bestpath_prefixes
);
2190 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2191 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2192 bgp_debug_keepalive_peers
);
2195 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2196 write
+= bgp_debug_list_conf_print(
2197 vty
, "debug bgp neighbor-events",
2198 bgp_debug_neighbor_events_peers
);
2201 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2202 vty_out(vty
, "debug bgp nht\n");
2206 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2207 vty_out(vty
, "debug bgp update-groups\n");
2211 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2212 write
+= bgp_debug_list_conf_print(vty
,
2213 "debug bgp updates prefix",
2214 bgp_debug_update_prefixes
);
2217 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2218 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2219 bgp_debug_update_in_peers
);
2222 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2223 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2224 bgp_debug_update_out_peers
);
2227 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2228 if (!bgp_debug_zebra_prefixes
2229 || list_isempty(bgp_debug_zebra_prefixes
)) {
2230 vty_out(vty
, "debug bgp zebra\n");
2233 write
+= bgp_debug_list_conf_print(
2234 vty
, "debug bgp zebra prefix",
2235 bgp_debug_zebra_prefixes
);
2239 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2240 vty_out(vty
, "debug bgp allow-martians\n");
2244 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2245 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2248 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2249 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2252 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2253 vty_out(vty
, "debug bgp vpn rmap-event\n");
2256 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2257 vty_out(vty
, "debug bgp vpn label\n");
2260 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2261 vty_out(vty
, "debug bgp flowspec\n");
2264 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2265 vty_out(vty
, "debug bgp labelpool\n");
2269 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2270 vty_out(vty
, "debug bgp pbr\n");
2273 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2274 vty_out(vty
, "debug bgp pbr error\n");
2278 if (CONF_BGP_DEBUG(graceful_restart
, GRACEFUL_RESTART
)) {
2279 vty_out(vty
, "debug bgp graceful-restart\n");
2285 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
2287 void bgp_debug_init(void)
2289 install_node(&debug_node
, bgp_config_write_debug
);
2291 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2293 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2294 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2295 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2296 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2298 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2299 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2300 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2301 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2302 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2303 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2304 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2305 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2306 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2307 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2308 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2309 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2310 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2311 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2312 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2313 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2315 install_element(ENABLE_NODE
, &debug_bgp_graceful_restart_cmd
);
2316 install_element(CONFIG_NODE
, &debug_bgp_graceful_restart_cmd
);
2318 /* debug bgp updates (in|out) */
2319 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2320 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2321 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2322 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2324 /* debug bgp updates (in|out) A.B.C.D */
2325 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2326 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2327 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2328 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2330 /* debug bgp updates prefix A.B.C.D/M */
2331 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2332 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2333 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2334 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2335 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2336 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2337 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2338 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2340 /* debug bgp zebra prefix A.B.C.D/M */
2341 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2342 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2343 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2344 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2346 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2347 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2348 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2349 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2351 /* debug bgp neighbor-events A.B.C.D */
2352 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2353 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2354 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2355 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2357 /* debug bgp keepalive A.B.C.D */
2358 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2359 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2360 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2361 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2363 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2364 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2365 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2366 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2367 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2368 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2369 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2370 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2371 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2372 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2373 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2374 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2375 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2376 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2377 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2378 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2379 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2380 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2381 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2383 install_element(ENABLE_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2384 install_element(CONFIG_NODE
, &no_debug_bgp_graceful_restart_cmd
);
2386 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2387 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2388 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2389 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2391 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2392 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2393 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2394 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2397 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2398 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2399 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2400 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2404 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2405 * for BGP_DEBUG_TYPE
2407 static int bgp_debug_per_prefix(struct prefix
*p
,
2408 unsigned long term_bgp_debug_type
,
2409 unsigned int BGP_DEBUG_TYPE
,
2410 struct list
*per_prefix_list
)
2412 struct bgp_debug_filter
*filter
;
2413 struct listnode
*node
, *nnode
;
2415 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2416 /* We are debugging all prefixes so return true */
2417 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2424 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2426 if (filter
->p
->prefixlen
== p
->prefixlen
2427 && prefix_match(filter
->p
, p
))
2437 /* Return true if this peer is on the per_peer_list of peers to debug
2438 * for BGP_DEBUG_TYPE
2440 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2441 unsigned int BGP_DEBUG_TYPE
,
2442 struct list
*per_peer_list
)
2444 struct bgp_debug_filter
*filter
;
2445 struct listnode
*node
, *nnode
;
2447 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2448 /* We are debugging all peers so return true */
2449 if (!per_peer_list
|| list_isempty(per_peer_list
))
2456 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2458 if (strcmp(filter
->host
, host
) == 0)
2468 int bgp_debug_neighbor_events(struct peer
*peer
)
2475 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2476 BGP_DEBUG_NEIGHBOR_EVENTS
,
2477 bgp_debug_neighbor_events_peers
);
2480 int bgp_debug_keepalive(struct peer
*peer
)
2487 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2488 BGP_DEBUG_KEEPALIVE
,
2489 bgp_debug_keepalive_peers
);
2492 bool bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
2493 struct update_group
*updgrp
, unsigned int inbound
)
2501 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2502 BGP_DEBUG_UPDATE_IN
,
2503 bgp_debug_update_in_peers
))
2509 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2510 BGP_DEBUG_UPDATE_OUT
,
2511 bgp_debug_update_out_peers
))
2514 /* Check if update debugging implicitly enabled for the group.
2516 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2521 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2522 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2523 BGP_DEBUG_UPDATE_PREFIX
,
2524 bgp_debug_update_prefixes
))
2531 bool bgp_debug_bestpath(struct prefix
*p
)
2533 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2534 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
2536 bgp_debug_bestpath_prefixes
))
2543 bool bgp_debug_zebra(struct prefix
*p
)
2545 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2546 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2548 bgp_debug_zebra_prefixes
))
2555 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2556 struct prefix_rd
*prd
,
2557 union prefixconstptr pu
,
2558 mpls_label_t
*label
, uint32_t num_labels
,
2559 int addpath_valid
, uint32_t addpath_id
,
2560 char *str
, int size
)
2562 char rd_buf
[RD_ADDRSTRLEN
];
2563 char pfx_buf
[PREFIX_STRLEN
];
2565 /* ' with addpath ID ' 17
2566 * max strlen of uint32 + 10
2567 * +/- (just in case) + 1
2568 * null terminator + 1
2569 * ============================ 29 */
2570 char pathid_buf
[30];
2572 if (size
< BGP_PRD_PATH_STRLEN
)
2575 /* Note: Path-id is created by default, but only included in update
2577 pathid_buf
[0] = '\0';
2579 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2583 if (bgp_labeled_safi(safi
) && num_labels
) {
2585 if (safi
== SAFI_EVPN
) {
2588 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2589 sprintf(tag_buf
, " label %s", tag_buf2
);
2591 uint32_t label_value
;
2593 label_value
= decode_label(label
);
2594 sprintf(tag_buf
, " label %u", label_value
);
2599 snprintf(str
, size
, "RD %s %s%s%s %s %s",
2600 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2601 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2602 pathid_buf
, afi2str(afi
), safi2str(safi
));
2603 else if (safi
== SAFI_FLOWSPEC
) {
2604 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2605 const struct prefix_fs
*fs
= pu
.fs
;
2607 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2608 fs
->prefix
.prefixlen
,
2610 NLRI_STRING_FORMAT_DEBUG
, NULL
);
2611 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2614 snprintf(str
, size
, "%s%s%s %s %s",
2615 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2616 pathid_buf
, afi2str(afi
), safi2str(safi
));