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_vty.h"
47 #include "bgpd/bgp_flowspec.h"
49 unsigned long conf_bgp_debug_as4
;
50 unsigned long conf_bgp_debug_neighbor_events
;
51 unsigned long conf_bgp_debug_events
;
52 unsigned long conf_bgp_debug_packet
;
53 unsigned long conf_bgp_debug_filter
;
54 unsigned long conf_bgp_debug_keepalive
;
55 unsigned long conf_bgp_debug_update
;
56 unsigned long conf_bgp_debug_bestpath
;
57 unsigned long conf_bgp_debug_zebra
;
58 unsigned long conf_bgp_debug_allow_martians
;
59 unsigned long conf_bgp_debug_nht
;
60 unsigned long conf_bgp_debug_update_groups
;
61 unsigned long conf_bgp_debug_vpn
;
62 unsigned long conf_bgp_debug_flowspec
;
63 unsigned long conf_bgp_debug_labelpool
;
64 unsigned long conf_bgp_debug_pbr
;
66 unsigned long term_bgp_debug_as4
;
67 unsigned long term_bgp_debug_neighbor_events
;
68 unsigned long term_bgp_debug_events
;
69 unsigned long term_bgp_debug_packet
;
70 unsigned long term_bgp_debug_filter
;
71 unsigned long term_bgp_debug_keepalive
;
72 unsigned long term_bgp_debug_update
;
73 unsigned long term_bgp_debug_bestpath
;
74 unsigned long term_bgp_debug_zebra
;
75 unsigned long term_bgp_debug_allow_martians
;
76 unsigned long term_bgp_debug_nht
;
77 unsigned long term_bgp_debug_update_groups
;
78 unsigned long term_bgp_debug_vpn
;
79 unsigned long term_bgp_debug_flowspec
;
80 unsigned long term_bgp_debug_labelpool
;
81 unsigned long term_bgp_debug_pbr
;
83 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
84 struct list
*bgp_debug_keepalive_peers
= NULL
;
85 struct list
*bgp_debug_update_out_peers
= NULL
;
86 struct list
*bgp_debug_update_in_peers
= NULL
;
87 struct list
*bgp_debug_update_prefixes
= NULL
;
88 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
89 struct list
*bgp_debug_zebra_prefixes
= NULL
;
91 /* messages for BGP-4 status */
92 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
95 {OpenSent
, "OpenSent"},
96 {OpenConfirm
, "OpenConfirm"},
97 {Established
, "Established"},
98 {Clearing
, "Clearing"},
102 /* BGP message type string. */
103 const char *bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
104 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
107 /* message for BGP-4 Notify */
108 static const struct message bgp_notify_msg
[] = {
109 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
110 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
111 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
112 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
113 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
114 {BGP_NOTIFY_CEASE
, "Cease"},
115 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
118 static const struct message bgp_notify_head_msg
[] = {
119 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
120 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
121 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
124 static const struct message bgp_notify_open_msg
[] = {
125 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
126 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
127 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
128 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
129 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
130 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
131 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
132 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
135 static const struct message bgp_notify_update_msg
[] = {
136 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
137 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
138 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
139 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
140 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
141 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
142 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
143 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
144 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
145 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
146 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
147 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
150 static const struct message bgp_notify_cease_msg
[] = {
151 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
152 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
153 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
154 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
155 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
156 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
157 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
158 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
159 "/Connection collision resolution"},
160 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
163 static const struct message bgp_notify_capability_msg
[] = {
164 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
165 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
166 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
167 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
170 /* Origin strings. */
171 const char *bgp_origin_str
[] = {"i", "e", "?"};
172 const char *bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
174 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
176 /* Given a string return a pointer the corresponding peer structure */
177 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
179 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
187 ret
= str2sockunion(peer_str
, &su
);
191 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
194 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
198 return peer_lookup(bgp
, &su
);
201 static void bgp_debug_list_free(struct list
*list
)
203 struct bgp_debug_filter
*filter
;
204 struct listnode
*node
, *nnode
;
207 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
208 listnode_delete(list
, filter
);
211 prefix_free(filter
->p
);
214 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
216 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
220 /* 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
,
223 struct list
*list
, uint8_t evpn_dbg
)
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
);
240 prefix2str(filter
->p
, buf
,
243 if (filter
->p
->family
== AF_EVPN
)
244 bgp_debug_print_evpn_prefix(vty
,
254 /* Print the command to enable the debug for each peer/prefix this debug is
257 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
258 struct list
*list
, uint8_t evpn_dbg
)
260 struct bgp_debug_filter
*filter
;
261 struct listnode
*node
, *nnode
;
262 char buf
[PREFIX2STR_BUFFER
];
265 if (list
&& !list_isempty(list
)) {
266 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
268 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
275 vty_out(vty
, "%s %s\n", desc
,
276 prefix2str(filter
->p
, buf
,
280 if (filter
->p
->family
== AF_EVPN
)
281 bgp_debug_print_evpn_prefix(vty
,
290 vty_out(vty
, "%s\n", desc
);
297 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
298 const struct prefix
*p
)
300 struct bgp_debug_filter
*filter
;
302 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
303 sizeof(struct bgp_debug_filter
));
306 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
310 filter
->p
= prefix_new();
311 prefix_copy(filter
->p
, p
);
314 listnode_add(list
, filter
);
317 static int bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
320 struct bgp_debug_filter
*filter
;
321 struct listnode
*node
, *nnode
;
323 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
324 if (host
&& strcmp(filter
->host
, host
) == 0) {
325 listnode_delete(list
, filter
);
326 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
327 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
329 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
330 && prefix_match(filter
->p
, p
)) {
331 listnode_delete(list
, filter
);
332 prefix_free(filter
->p
);
333 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
341 static int bgp_debug_list_has_entry(struct list
*list
, const char *host
,
342 const struct prefix
*p
)
344 struct bgp_debug_filter
*filter
;
345 struct listnode
*node
, *nnode
;
347 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
349 if (strcmp(filter
->host
, host
) == 0) {
353 if (filter
->p
->prefixlen
== p
->prefixlen
354 && prefix_match(filter
->p
, p
)) {
363 int bgp_debug_peer_updout_enabled(char *host
)
365 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
369 /* Dump attribute. */
370 int bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
372 char addrbuf
[BUFSIZ
];
377 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
378 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
380 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
381 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
382 bgp_origin_str
[attr
->origin
]);
385 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
386 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
387 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
389 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
392 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
393 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
394 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
397 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
398 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
400 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
401 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
402 ", localpref %u", attr
->local_pref
);
404 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
405 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
408 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
409 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
411 community_str(attr
->community
, false));
413 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
414 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
415 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
417 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
418 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
419 ", atomic-aggregate");
421 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
422 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
423 ", aggregated by %u %s", attr
->aggregator_as
,
424 inet_ntoa(attr
->aggregator_addr
));
426 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
427 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
428 ", originator %s", inet_ntoa(attr
->originator_id
));
430 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
433 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
435 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
436 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
437 inet_ntoa(attr
->cluster
->list
[i
]));
440 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
441 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
442 ", pmsi tnltype %u", attr
->pmsi_tnl_type
);
444 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
445 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
446 aspath_print(attr
->aspath
));
448 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
449 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
450 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
451 ", label-index %u", attr
->label_index
);
460 const char *bgp_notify_code_str(char code
)
462 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
465 const char *bgp_notify_subcode_str(char code
, char subcode
)
469 case BGP_NOTIFY_HEADER_ERR
:
470 return lookup_msg(bgp_notify_head_msg
, subcode
,
471 "Unrecognized Error Subcode");
472 case BGP_NOTIFY_OPEN_ERR
:
473 return lookup_msg(bgp_notify_open_msg
, subcode
,
474 "Unrecognized Error Subcode");
475 case BGP_NOTIFY_UPDATE_ERR
:
476 return lookup_msg(bgp_notify_update_msg
, subcode
,
477 "Unrecognized Error Subcode");
478 case BGP_NOTIFY_HOLD_ERR
:
480 case BGP_NOTIFY_FSM_ERR
:
482 case BGP_NOTIFY_CEASE
:
483 return lookup_msg(bgp_notify_cease_msg
, subcode
,
484 "Unrecognized Error Subcode");
485 case BGP_NOTIFY_CAPABILITY_ERR
:
486 return lookup_msg(bgp_notify_capability_msg
, subcode
,
487 "Unrecognized Error Subcode");
492 /* extract notify admin reason if correctly present */
493 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
496 if (!data
|| datalen
< 1)
499 uint8_t len
= data
[0];
500 if (len
> 128 || len
> datalen
- 1)
503 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
506 /* dump notify packet */
507 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
510 const char *subcode_str
;
511 const char *code_str
;
512 const char *msg_str
= NULL
;
515 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
516 || bgp_flag_check(peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
517 code_str
= bgp_notify_code_str(bgp_notify
->code
);
518 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
519 bgp_notify
->subcode
);
521 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
522 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
523 || bgp_notify
->subcode
524 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
525 msg_str
= bgp_notify_admin_message(
526 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
532 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
533 strcmp(direct
, "received") == 0
536 peer
->host
, bgp_notify
->code
,
537 bgp_notify
->subcode
, code_str
, subcode_str
,
540 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
542 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
543 strcmp(direct
, "received") == 0
546 peer
->host
, bgp_notify
->code
,
547 bgp_notify
->subcode
, code_str
, subcode_str
,
548 bgp_notify
->length
, msg_str
);
553 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
556 bgp
= bgp_get_default();
557 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
560 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
563 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
564 char buf
[PREFIX2STR_BUFFER
];
565 char buf2
[ETHER_ADDR_STRLEN
];
567 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
568 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
569 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s",
571 &p
->u
.prefix_evpn
.macip_addr
.mac
,
572 buf2
, sizeof(buf2
)));
574 uint8_t family
= is_evpn_prefix_ipaddr_v4(
575 (struct prefix_evpn
*)p
) ?
577 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s ip %s",
579 &p
->u
.prefix_evpn
.macip_addr
.mac
,
582 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
583 buf
, PREFIX2STR_BUFFER
));
585 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
586 sprintf(evpn_desc
, "l2vpn evpn type multicast ip %s",
587 inet_ntoa(p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
));
588 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
589 uint8_t family
= is_evpn_prefix_ipaddr_v4(
590 (struct prefix_evpn
*)p
) ? AF_INET
592 sprintf(evpn_desc
, "l2vpn evpn type prefix ip %s/%d",
594 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
, buf
,
596 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
599 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
604 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
605 int argc
, struct prefix
**argv_pp
)
607 struct prefix
*argv_p
;
617 if (argv_find(argv
, argc
, "type", &type_idx
) == 0)
620 if (strncmp(argv
[type_idx
+ 1]->arg
, "ma", 2) == 0)
621 evpn_type
= BGP_EVPN_MAC_IP_ROUTE
;
622 else if (strncmp(argv
[type_idx
+ 1]->arg
, "mu", 2) == 0)
623 evpn_type
= BGP_EVPN_IMET_ROUTE
;
624 else if (strncmp(argv
[type_idx
+ 1]->arg
, "pr", 2) == 0)
625 evpn_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
629 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
630 memset(&ip
, 0, sizeof(struct ipaddr
));
631 /* get the ip if specified */
632 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
633 if (str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
) != 0) {
634 vty_out(vty
, "%% Malformed IP address\n");
638 argv_find(argv
, argc
, "mac", &mac_idx
);
639 if (!prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
)) {
640 vty_out(vty
, "%% Malformed MAC address\n");
644 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
646 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
647 memset(&ip
, 0, sizeof(struct ipaddr
));
648 /* get the ip if specified */
649 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
650 if (str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
) != 0) {
651 vty_out(vty
, "%% Malformed IP address\n");
655 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
657 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
658 struct prefix ip_prefix
;
660 memset(&ip_prefix
, 0, sizeof(struct prefix
));
661 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
662 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
663 apply_mask(&ip_prefix
);
665 build_type5_prefix_from_ip_prefix(
666 (struct prefix_evpn
*)argv_p
,
673 /* Debug option setting interface. */
674 unsigned long bgp_debug_option
= 0;
676 int debug(unsigned int option
)
678 return bgp_debug_option
& option
;
681 DEFUN (debug_bgp_as4
,
688 if (vty
->node
== CONFIG_NODE
)
691 TERM_DEBUG_ON(as4
, AS4
);
692 vty_out(vty
, "BGP as4 debugging is on\n");
697 DEFUN (no_debug_bgp_as4
,
698 no_debug_bgp_as4_cmd
,
705 if (vty
->node
== CONFIG_NODE
)
708 TERM_DEBUG_OFF(as4
, AS4
);
709 vty_out(vty
, "BGP as4 debugging is off\n");
714 DEFUN (debug_bgp_as4_segment
,
715 debug_bgp_as4_segment_cmd
,
716 "debug bgp as4 segment",
720 "BGP AS4 aspath segment handling\n")
722 if (vty
->node
== CONFIG_NODE
)
723 DEBUG_ON(as4
, AS4_SEGMENT
);
725 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
726 vty_out(vty
, "BGP as4 segment debugging is on\n");
731 DEFUN (no_debug_bgp_as4_segment
,
732 no_debug_bgp_as4_segment_cmd
,
733 "no debug bgp as4 segment",
738 "BGP AS4 aspath segment handling\n")
740 if (vty
->node
== CONFIG_NODE
)
741 DEBUG_OFF(as4
, AS4_SEGMENT
);
743 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
744 vty_out(vty
, "BGP as4 segment debugging is off\n");
749 /* debug bgp neighbor_events */
750 DEFUN (debug_bgp_neighbor_events
,
751 debug_bgp_neighbor_events_cmd
,
752 "debug bgp neighbor-events",
755 "BGP Neighbor Events\n")
757 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
759 if (vty
->node
== CONFIG_NODE
)
760 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
762 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
763 vty_out(vty
, "BGP neighbor-events debugging is on\n");
768 DEFUN (debug_bgp_neighbor_events_peer
,
769 debug_bgp_neighbor_events_peer_cmd
,
770 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
773 "BGP Neighbor Events\n"
774 "BGP neighbor IP address to debug\n"
775 "BGP IPv6 neighbor to debug\n"
776 "BGP neighbor on interface to debug\n")
779 const char *host
= argv
[idx_peer
]->arg
;
781 if (!bgp_debug_neighbor_events_peers
)
782 bgp_debug_neighbor_events_peers
= list_new();
784 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
787 "BGP neighbor-events debugging is already enabled for %s\n",
792 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
794 if (vty
->node
== CONFIG_NODE
)
795 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
797 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
798 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
804 DEFUN (no_debug_bgp_neighbor_events
,
805 no_debug_bgp_neighbor_events_cmd
,
806 "no debug bgp neighbor-events",
812 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
814 if (vty
->node
== CONFIG_NODE
)
815 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
817 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
818 vty_out(vty
, "BGP neighbor-events debugging is off\n");
823 DEFUN (no_debug_bgp_neighbor_events_peer
,
824 no_debug_bgp_neighbor_events_peer_cmd
,
825 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
830 "BGP neighbor IP address to debug\n"
831 "BGP IPv6 neighbor to debug\n"
832 "BGP neighbor on interface to debug\n")
836 const char *host
= argv
[idx_peer
]->arg
;
838 if (bgp_debug_neighbor_events_peers
839 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
840 found_peer
= bgp_debug_list_remove_entry(
841 bgp_debug_neighbor_events_peers
, host
, NULL
);
843 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
844 if (vty
->node
== CONFIG_NODE
)
845 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
847 TERM_DEBUG_OFF(neighbor_events
,
853 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
857 "BGP neighbor-events debugging was not enabled for %s\n",
864 DEFUN (debug_bgp_nht
,
869 "BGP nexthop tracking events\n")
871 if (vty
->node
== CONFIG_NODE
)
874 TERM_DEBUG_ON(nht
, NHT
);
875 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
880 DEFUN (no_debug_bgp_nht
,
881 no_debug_bgp_nht_cmd
,
886 "BGP nexthop tracking events\n")
888 if (vty
->node
== CONFIG_NODE
)
891 TERM_DEBUG_OFF(nht
, NHT
);
892 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
897 /* debug bgp keepalives */
898 DEFUN (debug_bgp_keepalive
,
899 debug_bgp_keepalive_cmd
,
900 "debug bgp keepalives",
905 bgp_debug_list_free(bgp_debug_keepalive_peers
);
907 if (vty
->node
== CONFIG_NODE
)
908 DEBUG_ON(keepalive
, KEEPALIVE
);
910 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
911 vty_out(vty
, "BGP keepalives debugging is on\n");
916 DEFUN (debug_bgp_keepalive_peer
,
917 debug_bgp_keepalive_peer_cmd
,
918 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
921 "BGP Neighbor Events\n"
922 "BGP neighbor IP address to debug\n"
923 "BGP IPv6 neighbor to debug\n"
924 "BGP neighbor on interface to debug\n")
927 const char *host
= argv
[idx_peer
]->arg
;
929 if (!bgp_debug_keepalive_peers
)
930 bgp_debug_keepalive_peers
= list_new();
932 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
934 "BGP keepalive debugging is already enabled for %s\n",
939 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
941 if (vty
->node
== CONFIG_NODE
)
942 DEBUG_ON(keepalive
, KEEPALIVE
);
944 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
945 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
950 DEFUN (no_debug_bgp_keepalive
,
951 no_debug_bgp_keepalive_cmd
,
952 "no debug bgp keepalives",
958 bgp_debug_list_free(bgp_debug_keepalive_peers
);
960 if (vty
->node
== CONFIG_NODE
)
961 DEBUG_OFF(keepalive
, KEEPALIVE
);
963 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
964 vty_out(vty
, "BGP keepalives debugging is off\n");
969 DEFUN (no_debug_bgp_keepalive_peer
,
970 no_debug_bgp_keepalive_peer_cmd
,
971 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
976 "BGP neighbor IP address to debug\n"
977 "BGP IPv6 neighbor to debug\n"
978 "BGP neighbor on interface to debug\n")
982 const char *host
= argv
[idx_peer
]->arg
;
984 if (bgp_debug_keepalive_peers
985 && !list_isempty(bgp_debug_keepalive_peers
)) {
986 found_peer
= bgp_debug_list_remove_entry(
987 bgp_debug_keepalive_peers
, host
, NULL
);
989 if (list_isempty(bgp_debug_keepalive_peers
)) {
990 if (vty
->node
== CONFIG_NODE
)
991 DEBUG_OFF(keepalive
, KEEPALIVE
);
993 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
998 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
1001 "BGP keepalives debugging was not enabled for %s\n",
1007 /* debug bgp bestpath */
1008 DEFUN (debug_bgp_bestpath_prefix
,
1009 debug_bgp_bestpath_prefix_cmd
,
1010 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1017 struct prefix
*argv_p
;
1018 int idx_ipv4_ipv6_prefixlen
= 3;
1020 argv_p
= prefix_new();
1021 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1024 if (!bgp_debug_bestpath_prefixes
)
1025 bgp_debug_bestpath_prefixes
= list_new();
1027 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1030 "BGP bestpath debugging is already enabled for %s\n",
1031 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1035 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1037 if (vty
->node
== CONFIG_NODE
) {
1038 DEBUG_ON(bestpath
, BESTPATH
);
1040 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1041 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1042 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1048 DEFUN (no_debug_bgp_bestpath_prefix
,
1049 no_debug_bgp_bestpath_prefix_cmd
,
1050 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1058 int idx_ipv4_ipv6_prefixlen
= 4;
1059 struct prefix
*argv_p
;
1060 int found_prefix
= 0;
1062 argv_p
= prefix_new();
1063 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1066 if (bgp_debug_bestpath_prefixes
1067 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1068 found_prefix
= bgp_debug_list_remove_entry(
1069 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1071 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1072 if (vty
->node
== CONFIG_NODE
) {
1073 DEBUG_OFF(bestpath
, BESTPATH
);
1075 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1077 "BGP bestpath debugging (per prefix) is off\n");
1083 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1084 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1086 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1087 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1092 DEFUN (no_debug_bgp_bestpath
,
1093 no_debug_bgp_bestpath_cmd
,
1094 "no debug bgp bestpath",
1100 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1102 if (vty
->node
== CONFIG_NODE
)
1103 DEBUG_OFF(bestpath
, BESTPATH
);
1105 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1106 vty_out(vty
, "BGP bestpath debugging is off\n");
1111 /* debug bgp updates */
1112 DEFUN (debug_bgp_update
,
1113 debug_bgp_update_cmd
,
1114 "debug bgp updates",
1119 bgp_debug_list_free(bgp_debug_update_in_peers
);
1120 bgp_debug_list_free(bgp_debug_update_out_peers
);
1121 bgp_debug_list_free(bgp_debug_update_prefixes
);
1123 if (vty
->node
== CONFIG_NODE
) {
1124 DEBUG_ON(update
, UPDATE_IN
);
1125 DEBUG_ON(update
, UPDATE_OUT
);
1127 TERM_DEBUG_ON(update
, UPDATE_IN
);
1128 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1129 vty_out(vty
, "BGP updates debugging is on\n");
1134 DEFUN (debug_bgp_update_direct
,
1135 debug_bgp_update_direct_cmd
,
1136 "debug bgp updates <in|out>",
1141 "Outbound updates\n")
1145 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1146 bgp_debug_list_free(bgp_debug_update_in_peers
);
1148 bgp_debug_list_free(bgp_debug_update_out_peers
);
1150 if (vty
->node
== CONFIG_NODE
) {
1151 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1152 DEBUG_ON(update
, UPDATE_IN
);
1154 DEBUG_ON(update
, UPDATE_OUT
);
1156 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1157 TERM_DEBUG_ON(update
, UPDATE_IN
);
1158 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1160 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1162 "BGP updates debugging is on (outbound)\n");
1168 DEFUN (debug_bgp_update_direct_peer
,
1169 debug_bgp_update_direct_peer_cmd
,
1170 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1175 "Outbound updates\n"
1176 "BGP neighbor IP address to debug\n"
1177 "BGP IPv6 neighbor to debug\n"
1178 "BGP neighbor on interface to debug\n")
1182 const char *host
= argv
[idx_peer
]->arg
;
1185 if (!bgp_debug_update_in_peers
)
1186 bgp_debug_update_in_peers
= list_new();
1188 if (!bgp_debug_update_out_peers
)
1189 bgp_debug_update_out_peers
= list_new();
1191 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1197 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1200 "BGP inbound update debugging is already enabled for %s\n",
1207 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1210 "BGP outbound update debugging is already enabled for %s\n",
1217 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1220 struct peer_af
*paf
;
1223 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1225 peer
= bgp_find_peer(vty
, host
);
1228 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1230 paf
= peer
->peer_af_array
[afidx
];
1232 if (PAF_SUBGRP(paf
)) {
1242 if (vty
->node
== CONFIG_NODE
) {
1244 DEBUG_ON(update
, UPDATE_IN
);
1246 DEBUG_ON(update
, UPDATE_OUT
);
1249 TERM_DEBUG_ON(update
, UPDATE_IN
);
1251 "BGP updates debugging is on (inbound) for %s\n",
1252 argv
[idx_peer
]->arg
);
1254 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1256 "BGP updates debugging is on (outbound) for %s\n",
1257 argv
[idx_peer
]->arg
);
1263 DEFUN (no_debug_bgp_update_direct
,
1264 no_debug_bgp_update_direct_cmd
,
1265 "no debug bgp updates <in|out>",
1271 "Outbound updates\n")
1274 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1275 bgp_debug_list_free(bgp_debug_update_in_peers
);
1277 if (vty
->node
== CONFIG_NODE
) {
1278 DEBUG_OFF(update
, UPDATE_IN
);
1280 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1282 "BGP updates debugging is off (inbound)\n");
1285 bgp_debug_list_free(bgp_debug_update_out_peers
);
1287 if (vty
->node
== CONFIG_NODE
) {
1288 DEBUG_OFF(update
, UPDATE_OUT
);
1290 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1292 "BGP updates debugging is off (outbound)\n");
1299 DEFUN (no_debug_bgp_update_direct_peer
,
1300 no_debug_bgp_update_direct_peer_cmd
,
1301 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1307 "Outbound updates\n"
1308 "BGP neighbor IP address to debug\n"
1309 "BGP IPv6 neighbor to debug\n"
1310 "BGP neighbor on interface to debug\n")
1316 const char *host
= argv
[idx_peer
]->arg
;
1318 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1323 if (inbound
&& bgp_debug_update_in_peers
1324 && !list_isempty(bgp_debug_update_in_peers
)) {
1325 found_peer
= bgp_debug_list_remove_entry(
1326 bgp_debug_update_in_peers
, host
, NULL
);
1328 if (list_isempty(bgp_debug_update_in_peers
)) {
1329 if (vty
->node
== CONFIG_NODE
)
1330 DEBUG_OFF(update
, UPDATE_IN
);
1332 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1334 "BGP updates debugging (inbound) is off\n");
1339 if (!inbound
&& bgp_debug_update_out_peers
1340 && !list_isempty(bgp_debug_update_out_peers
)) {
1341 found_peer
= bgp_debug_list_remove_entry(
1342 bgp_debug_update_out_peers
, host
, NULL
);
1344 if (list_isempty(bgp_debug_update_out_peers
)) {
1345 if (vty
->node
== CONFIG_NODE
)
1346 DEBUG_OFF(update
, UPDATE_OUT
);
1348 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1350 "BGP updates debugging (outbound) is off\n");
1355 struct peer_af
*paf
;
1357 peer
= bgp_find_peer(vty
, host
);
1360 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1362 paf
= peer
->peer_af_array
[afidx
];
1364 if (PAF_SUBGRP(paf
)) {
1365 UPDGRP_PEER_DBG_DIS(
1377 "BGP updates debugging (inbound) is off for %s\n",
1381 "BGP updates debugging (outbound) is off for %s\n",
1385 "BGP updates debugging (inbound) was not enabled for %s\n",
1389 "BGP updates debugging (outbound) was not enabled for %s\n",
1395 #ifndef VTYSH_EXTRACT_PL
1396 #include "bgpd/bgp_debug_clippy.c"
1399 DEFPY (debug_bgp_update_prefix_afi_safi
,
1400 debug_bgp_update_prefix_afi_safi_cmd
,
1401 "debug bgp updates prefix <l2vpn>$afi <evpn>$safi type <macip mac WORD [ip WORD]|multicast ip WORD |prefix ip WORD>",
1405 "Specify a prefix to debug\n"
1408 "Specify EVPN Route type\n"
1409 "MAC-IP (Type-2) route\n"
1411 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
1413 "IP address (IPv4 or IPv6)\n"
1414 "Multicast (Type-3) route\n"
1416 "IP address (IPv4 or IPv6)\n"
1417 "Prefix (Type-5) route\n"
1421 int idx_ipv4_ipv6_prefixlen
= 4;
1422 struct prefix
*argv_p
;
1423 int ret
= CMD_SUCCESS
;
1427 argv_p
= prefix_new();
1429 afiz
= bgp_vty_afi_from_str(afi
);
1430 safiz
= safi
? bgp_vty_safi_from_str(safi
) : SAFI_UNICAST
;
1432 /* check for evpn route type */
1433 if (afiz
== AFI_L2VPN
&& safiz
== SAFI_EVPN
) {
1434 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1435 if (ret
!= CMD_SUCCESS
)
1438 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1442 if (!bgp_debug_update_prefixes
)
1443 bgp_debug_update_prefixes
= list_new();
1445 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1447 "BGP updates debugging is already enabled for %s\n",
1448 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1452 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1454 if (vty
->node
== CONFIG_NODE
) {
1455 DEBUG_ON(update
, UPDATE_PREFIX
);
1457 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1458 vty_out(vty
, "BGP updates debugging is on for %s\n",
1459 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1463 prefix_free(argv_p
);
1468 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1469 no_debug_bgp_update_prefix_afi_safi_cmd
,
1470 "no debug bgp updates prefix <l2vpn>$afi <evpn>$safi type <macip mac WORD [ip WORD]|multicast ip WORD |prefix ip WORD>",
1475 "Specify a prefix to debug\n"
1478 "Specify EVPN Route type\n"
1479 "MAC-IP (Type-2) route\n"
1481 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
1483 "IP address (IPv4 or IPv6)\n"
1484 "Multicast (Type-3) route\n"
1486 "IP address (IPv4 or IPv6)\n"
1487 "Prefix (Type-5) route\n"
1491 int idx_ipv4_ipv6_prefixlen
= 5;
1492 struct prefix
*argv_p
;
1493 int found_prefix
= 0;
1494 int ret
= CMD_SUCCESS
;
1498 argv_p
= prefix_new();
1500 afiz
= bgp_vty_afi_from_str(afi
);
1501 safiz
= safi
? bgp_vty_safi_from_str(safi
) : SAFI_UNICAST
;
1503 /* check for evpn route type */
1504 if (afiz
== AFI_L2VPN
&& safiz
== SAFI_EVPN
) {
1505 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1506 if (ret
!= CMD_SUCCESS
)
1509 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1513 if (bgp_debug_update_prefixes
1514 && !list_isempty(bgp_debug_update_prefixes
)) {
1515 found_prefix
= bgp_debug_list_remove_entry(
1516 bgp_debug_update_prefixes
, NULL
, argv_p
);
1518 if (list_isempty(bgp_debug_update_prefixes
)) {
1519 if (vty
->node
== CONFIG_NODE
) {
1520 DEBUG_OFF(update
, UPDATE_PREFIX
);
1522 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1524 "BGP updates debugging (per prefix) is off\n");
1530 vty_out(vty
, "BGP updates debugging is off for %s\n",
1531 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1533 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1534 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1537 prefix_free(argv_p
);
1543 DEFUN (debug_bgp_update_prefix
,
1544 debug_bgp_update_prefix_cmd
,
1545 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1549 "Specify a prefix to debug\n"
1553 int idx_ipv4_ipv6_prefixlen
= 4;
1554 struct prefix
*argv_p
;
1556 argv_p
= prefix_new();
1557 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1560 if (!bgp_debug_update_prefixes
)
1561 bgp_debug_update_prefixes
= list_new();
1563 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1565 "BGP updates debugging is already enabled for %s\n",
1566 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1570 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1572 if (vty
->node
== CONFIG_NODE
) {
1573 DEBUG_ON(update
, UPDATE_PREFIX
);
1575 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1576 vty_out(vty
, "BGP updates debugging is on for %s\n",
1577 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1583 DEFUN (no_debug_bgp_update_prefix
,
1584 no_debug_bgp_update_prefix_cmd
,
1585 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1590 "Specify a prefix to debug\n"
1594 int idx_ipv4_ipv6_prefixlen
= 5;
1595 struct prefix
*argv_p
;
1596 int found_prefix
= 0;
1598 argv_p
= prefix_new();
1599 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1602 if (bgp_debug_update_prefixes
1603 && !list_isempty(bgp_debug_update_prefixes
)) {
1604 found_prefix
= bgp_debug_list_remove_entry(
1605 bgp_debug_update_prefixes
, NULL
, argv_p
);
1607 if (list_isempty(bgp_debug_update_prefixes
)) {
1608 if (vty
->node
== CONFIG_NODE
) {
1609 DEBUG_OFF(update
, UPDATE_PREFIX
);
1611 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1613 "BGP updates debugging (per prefix) is off\n");
1619 vty_out(vty
, "BGP updates debugging is off for %s\n",
1620 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1622 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1623 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1628 DEFUN (no_debug_bgp_update
,
1629 no_debug_bgp_update_cmd
,
1630 "no debug bgp updates",
1636 struct listnode
*ln
;
1639 bgp_debug_list_free(bgp_debug_update_in_peers
);
1640 bgp_debug_list_free(bgp_debug_update_out_peers
);
1641 bgp_debug_list_free(bgp_debug_update_prefixes
);
1643 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1644 bgp_debug_clear_updgrp_update_dbg(bgp
);
1646 if (vty
->node
== CONFIG_NODE
) {
1647 DEBUG_OFF(update
, UPDATE_IN
);
1648 DEBUG_OFF(update
, UPDATE_OUT
);
1649 DEBUG_OFF(update
, UPDATE_PREFIX
);
1651 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1652 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1653 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1654 vty_out(vty
, "BGP updates debugging is off\n");
1659 /* debug bgp zebra */
1660 DEFUN (debug_bgp_zebra
,
1661 debug_bgp_zebra_cmd
,
1665 "BGP Zebra messages\n")
1667 if (vty
->node
== CONFIG_NODE
)
1668 DEBUG_ON(zebra
, ZEBRA
);
1670 TERM_DEBUG_ON(zebra
, ZEBRA
);
1671 vty_out(vty
, "BGP zebra debugging is on\n");
1676 DEFUN (debug_bgp_zebra_prefix
,
1677 debug_bgp_zebra_prefix_cmd
,
1678 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1681 "BGP Zebra messages\n"
1682 "Specify a prefix to debug\n"
1686 int idx_ipv4_ipv6_prefixlen
= 4;
1687 struct prefix
*argv_p
;
1689 argv_p
= prefix_new();
1690 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1693 if (!bgp_debug_zebra_prefixes
)
1694 bgp_debug_zebra_prefixes
= list_new();
1696 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1697 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1698 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1702 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1704 if (vty
->node
== CONFIG_NODE
)
1705 DEBUG_ON(zebra
, ZEBRA
);
1707 TERM_DEBUG_ON(zebra
, ZEBRA
);
1708 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1709 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1715 DEFUN (no_debug_bgp_zebra
,
1716 no_debug_bgp_zebra_cmd
,
1717 "no debug bgp zebra",
1721 "BGP Zebra messages\n")
1723 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1725 if (vty
->node
== CONFIG_NODE
)
1726 DEBUG_OFF(zebra
, ZEBRA
);
1728 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1729 vty_out(vty
, "BGP zebra debugging is off\n");
1734 DEFUN (no_debug_bgp_zebra_prefix
,
1735 no_debug_bgp_zebra_prefix_cmd
,
1736 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1740 "BGP Zebra messages\n"
1741 "Specify a prefix to debug\n"
1745 int idx_ipv4_ipv6_prefixlen
= 5;
1746 struct prefix
*argv_p
;
1747 int found_prefix
= 0;
1749 argv_p
= prefix_new();
1750 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1753 if (bgp_debug_zebra_prefixes
1754 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1755 found_prefix
= bgp_debug_list_remove_entry(
1756 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1758 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1759 if (vty
->node
== CONFIG_NODE
)
1760 DEBUG_OFF(zebra
, ZEBRA
);
1762 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1763 vty_out(vty
, "BGP zebra debugging is off\n");
1769 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1770 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1772 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1773 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1778 DEFUN (debug_bgp_allow_martians
,
1779 debug_bgp_allow_martians_cmd
,
1780 "debug bgp allow-martians",
1783 "BGP allow martian next hops\n")
1785 if (vty
->node
== CONFIG_NODE
)
1786 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1788 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1789 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1794 DEFUN (no_debug_bgp_allow_martians
,
1795 no_debug_bgp_allow_martians_cmd
,
1796 "no debug bgp allow-martians",
1800 "BGP allow martian next hops\n")
1802 if (vty
->node
== CONFIG_NODE
)
1803 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1805 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1806 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1812 /* debug bgp update-groups */
1813 DEFUN (debug_bgp_update_groups
,
1814 debug_bgp_update_groups_cmd
,
1815 "debug bgp update-groups",
1818 "BGP update-groups\n")
1820 if (vty
->node
== CONFIG_NODE
)
1821 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1823 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1824 vty_out(vty
, "BGP update-groups debugging is on\n");
1829 DEFUN (no_debug_bgp_update_groups
,
1830 no_debug_bgp_update_groups_cmd
,
1831 "no debug bgp update-groups",
1835 "BGP update-groups\n")
1837 if (vty
->node
== CONFIG_NODE
)
1838 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1840 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1841 vty_out(vty
, "BGP update-groups debugging is off\n");
1846 DEFUN (debug_bgp_vpn
,
1848 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1852 "leaked from vrf to vpn\n"
1853 "leaked to vrf from vpn\n"
1854 "route-map updates\n"
1859 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1860 if (vty
->node
== CONFIG_NODE
)
1861 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1863 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1864 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1865 if (vty
->node
== CONFIG_NODE
)
1866 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1868 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1869 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1870 if (vty
->node
== CONFIG_NODE
)
1871 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1873 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1874 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1875 if (vty
->node
== CONFIG_NODE
)
1876 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1878 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1880 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1881 return CMD_WARNING_CONFIG_FAILED
;
1884 if (vty
->node
!= CONFIG_NODE
)
1885 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1890 DEFUN (no_debug_bgp_vpn
,
1891 no_debug_bgp_vpn_cmd
,
1892 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1897 "leaked from vrf to vpn\n"
1898 "leaked to vrf from vpn\n"
1899 "route-map updates\n"
1904 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1905 if (vty
->node
== CONFIG_NODE
)
1906 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1908 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1910 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1911 if (vty
->node
== CONFIG_NODE
)
1912 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1914 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1915 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1916 if (vty
->node
== CONFIG_NODE
)
1917 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1919 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1920 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1921 if (vty
->node
== CONFIG_NODE
)
1922 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1924 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1926 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1927 return CMD_WARNING_CONFIG_FAILED
;
1930 if (vty
->node
!= CONFIG_NODE
)
1931 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1936 DEFUN (debug_bgp_pbr
,
1938 "debug bgp pbr [error]",
1941 "BGP policy based routing\n"
1946 if (argv_find(argv
, argc
, "error", &idx
)) {
1947 if (vty
->node
== CONFIG_NODE
)
1948 DEBUG_ON(pbr
, PBR_ERROR
);
1950 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1951 vty_out(vty
, "BGP policy based routing error is on\n");
1955 if (vty
->node
== CONFIG_NODE
)
1958 TERM_DEBUG_ON(pbr
, PBR
);
1959 vty_out(vty
, "BGP policy based routing is on\n");
1964 DEFUN (no_debug_bgp_pbr
,
1965 no_debug_bgp_pbr_cmd
,
1966 "no debug bgp pbr [error]",
1970 "BGP policy based routing\n"
1975 if (argv_find(argv
, argc
, "error", &idx
)) {
1976 if (vty
->node
== CONFIG_NODE
)
1977 DEBUG_OFF(pbr
, PBR_ERROR
);
1979 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1980 vty_out(vty
, "BGP policy based routing error is off\n");
1984 if (vty
->node
== CONFIG_NODE
)
1985 DEBUG_OFF(pbr
, PBR
);
1987 TERM_DEBUG_OFF(pbr
, PBR
);
1988 vty_out(vty
, "BGP policy based routing is off\n");
1993 DEFUN (debug_bgp_labelpool
,
1994 debug_bgp_labelpool_cmd
,
1995 "debug bgp labelpool",
2000 if (vty
->node
== CONFIG_NODE
)
2001 DEBUG_ON(labelpool
, LABELPOOL
);
2003 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
2005 if (vty
->node
!= CONFIG_NODE
)
2006 vty_out(vty
, "enabled debug bgp labelpool\n");
2011 DEFUN (no_debug_bgp_labelpool
,
2012 no_debug_bgp_labelpool_cmd
,
2013 "no debug bgp labelpool",
2019 if (vty
->node
== CONFIG_NODE
)
2020 DEBUG_OFF(labelpool
, LABELPOOL
);
2022 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2025 if (vty
->node
!= CONFIG_NODE
)
2026 vty_out(vty
, "disabled debug bgp labelpool\n");
2031 DEFUN (no_debug_bgp
,
2039 struct listnode
*ln
;
2041 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2042 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2043 bgp_debug_list_free(bgp_debug_update_in_peers
);
2044 bgp_debug_list_free(bgp_debug_update_out_peers
);
2045 bgp_debug_list_free(bgp_debug_update_prefixes
);
2046 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2047 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2049 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2050 bgp_debug_clear_updgrp_update_dbg(bgp
);
2052 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2053 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2054 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2055 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2056 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2057 TERM_DEBUG_OFF(as4
, AS4
);
2058 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2059 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2060 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2061 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2062 TERM_DEBUG_OFF(nht
, NHT
);
2063 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2064 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2065 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2066 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2067 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2068 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2069 TERM_DEBUG_OFF(pbr
, PBR
);
2070 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2071 vty_out(vty
, "All possible debugging has been turned off\n");
2076 DEFUN_NOSH (show_debugging_bgp
,
2077 show_debugging_bgp_cmd
,
2078 "show debugging [bgp]",
2083 vty_out(vty
, "BGP debugging status:\n");
2085 if (BGP_DEBUG(as4
, AS4
))
2086 vty_out(vty
, " BGP as4 debugging is on\n");
2088 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2089 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2091 if (BGP_DEBUG(bestpath
, BESTPATH
))
2092 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2093 bgp_debug_bestpath_prefixes
, 0);
2095 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2096 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2097 bgp_debug_keepalive_peers
, 0);
2099 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2100 bgp_debug_list_print(vty
,
2101 " BGP neighbor-events debugging is on",
2102 bgp_debug_neighbor_events_peers
, 0);
2104 if (BGP_DEBUG(nht
, NHT
))
2105 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2107 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2108 vty_out(vty
, " BGP update-groups debugging is on\n");
2110 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2111 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2112 bgp_debug_update_prefixes
, 1);
2114 if (BGP_DEBUG(update
, UPDATE_IN
))
2115 bgp_debug_list_print(vty
,
2116 " BGP updates debugging is on (inbound)",
2117 bgp_debug_update_in_peers
, 0);
2119 if (BGP_DEBUG(update
, UPDATE_OUT
))
2120 bgp_debug_list_print(vty
,
2121 " BGP updates debugging is on (outbound)",
2122 bgp_debug_update_out_peers
, 0);
2124 if (BGP_DEBUG(zebra
, ZEBRA
))
2125 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2126 bgp_debug_zebra_prefixes
, 0);
2128 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2129 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2131 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2133 " BGP route leak from vrf to vpn debugging is on\n");
2134 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2136 " BGP route leak to vrf from vpn debugging is on\n");
2137 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2138 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2139 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2140 vty_out(vty
, " BGP vpn label event debugging is on\n");
2141 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2142 vty_out(vty
, " BGP flowspec debugging is on\n");
2143 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2144 vty_out(vty
, " BGP labelpool debugging is on\n");
2146 if (BGP_DEBUG(pbr
, PBR
))
2147 vty_out(vty
, " BGP policy based routing debugging is on\n");
2148 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2149 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2155 /* return count of number of debug flags set */
2156 int bgp_debug_count(void)
2159 if (BGP_DEBUG(as4
, AS4
))
2162 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2165 if (BGP_DEBUG(bestpath
, BESTPATH
))
2168 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2171 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2174 if (BGP_DEBUG(nht
, NHT
))
2177 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2180 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2183 if (BGP_DEBUG(update
, UPDATE_IN
))
2186 if (BGP_DEBUG(update
, UPDATE_OUT
))
2189 if (BGP_DEBUG(zebra
, ZEBRA
))
2192 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2195 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2197 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2199 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2201 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2203 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2205 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2208 if (BGP_DEBUG(pbr
, PBR
))
2210 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2216 static int bgp_config_write_debug(struct vty
*vty
)
2220 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2221 vty_out(vty
, "debug bgp as4\n");
2225 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2226 vty_out(vty
, "debug bgp as4 segment\n");
2230 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2231 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2232 bgp_debug_bestpath_prefixes
,
2236 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2237 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2238 bgp_debug_keepalive_peers
,
2242 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2243 write
+= bgp_debug_list_conf_print(
2244 vty
, "debug bgp neighbor-events",
2245 bgp_debug_neighbor_events_peers
, 0);
2248 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2249 vty_out(vty
, "debug bgp nht\n");
2253 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2254 vty_out(vty
, "debug bgp update-groups\n");
2258 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2259 write
+= bgp_debug_list_conf_print(vty
,
2260 "debug bgp updates prefix",
2261 bgp_debug_update_prefixes
,
2265 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2266 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2267 bgp_debug_update_in_peers
,
2271 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2272 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2273 bgp_debug_update_out_peers
,
2277 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2278 if (!bgp_debug_zebra_prefixes
2279 || list_isempty(bgp_debug_zebra_prefixes
)) {
2280 vty_out(vty
, "debug bgp zebra\n");
2283 write
+= bgp_debug_list_conf_print(
2284 vty
, "debug bgp zebra prefix",
2285 bgp_debug_zebra_prefixes
, 0);
2289 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2290 vty_out(vty
, "debug bgp allow-martians\n");
2294 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2295 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2298 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2299 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2302 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2303 vty_out(vty
, "debug bgp vpn rmap-event\n");
2306 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2307 vty_out(vty
, "debug bgp vpn label\n");
2310 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2311 vty_out(vty
, "debug bgp flowspec\n");
2314 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2315 vty_out(vty
, "debug bgp labelpool\n");
2319 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2320 vty_out(vty
, "debug bgp pbr\n");
2323 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2324 vty_out(vty
, "debug bgp pbr error\n");
2330 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
2332 void bgp_debug_init(void)
2334 install_node(&debug_node
, bgp_config_write_debug
);
2336 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2338 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2339 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2340 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2341 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2343 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2344 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2345 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2346 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2347 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2348 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2349 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2350 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2351 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2352 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2353 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2354 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2355 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2356 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2357 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2358 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2360 /* debug bgp updates (in|out) */
2361 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2362 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2363 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2364 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2366 /* debug bgp updates (in|out) A.B.C.D */
2367 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2368 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2369 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2370 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2372 /* debug bgp updates prefix A.B.C.D/M */
2373 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2374 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2375 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2376 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2377 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2378 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2379 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2380 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2382 /* debug bgp zebra prefix A.B.C.D/M */
2383 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2384 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2385 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2386 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2388 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2389 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2390 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2391 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2393 /* debug bgp neighbor-events A.B.C.D */
2394 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2395 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2396 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2397 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2399 /* debug bgp keepalive A.B.C.D */
2400 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2401 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2402 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2403 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2405 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2406 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2407 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2408 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2409 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2410 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2411 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2412 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2413 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2414 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2415 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2416 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2417 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2418 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2419 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2420 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2421 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2422 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2423 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2425 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2426 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2427 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2428 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2430 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2431 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2432 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2433 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2436 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2437 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2438 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2439 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2443 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2444 * for BGP_DEBUG_TYPE
2446 static int bgp_debug_per_prefix(struct prefix
*p
,
2447 unsigned long term_bgp_debug_type
,
2448 unsigned int BGP_DEBUG_TYPE
,
2449 struct list
*per_prefix_list
)
2451 struct bgp_debug_filter
*filter
;
2452 struct listnode
*node
, *nnode
;
2454 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2455 /* We are debugging all prefixes so return true */
2456 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2463 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2465 if (filter
->p
->prefixlen
== p
->prefixlen
2466 && prefix_match(filter
->p
, p
))
2476 /* Return true if this peer is on the per_peer_list of peers to debug
2477 * for BGP_DEBUG_TYPE
2479 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2480 unsigned int BGP_DEBUG_TYPE
,
2481 struct list
*per_peer_list
)
2483 struct bgp_debug_filter
*filter
;
2484 struct listnode
*node
, *nnode
;
2486 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2487 /* We are debugging all peers so return true */
2488 if (!per_peer_list
|| list_isempty(per_peer_list
))
2495 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2497 if (strcmp(filter
->host
, host
) == 0)
2507 int bgp_debug_neighbor_events(struct peer
*peer
)
2514 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2515 BGP_DEBUG_NEIGHBOR_EVENTS
,
2516 bgp_debug_neighbor_events_peers
);
2519 int bgp_debug_keepalive(struct peer
*peer
)
2526 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2527 BGP_DEBUG_KEEPALIVE
,
2528 bgp_debug_keepalive_peers
);
2531 int bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
2532 struct update_group
*updgrp
, unsigned int inbound
)
2540 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2541 BGP_DEBUG_UPDATE_IN
,
2542 bgp_debug_update_in_peers
))
2548 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2549 BGP_DEBUG_UPDATE_OUT
,
2550 bgp_debug_update_out_peers
))
2553 /* Check if update debugging implicitly enabled for the group.
2555 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2560 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2561 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2562 BGP_DEBUG_UPDATE_PREFIX
,
2563 bgp_debug_update_prefixes
))
2570 int bgp_debug_bestpath(struct prefix
*p
)
2572 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2573 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
2575 bgp_debug_bestpath_prefixes
))
2582 int bgp_debug_zebra(struct prefix
*p
)
2584 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2585 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2587 bgp_debug_zebra_prefixes
))
2594 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2595 struct prefix_rd
*prd
,
2596 union prefixconstptr pu
,
2597 mpls_label_t
*label
, uint32_t num_labels
,
2598 int addpath_valid
, uint32_t addpath_id
,
2599 char *str
, int size
)
2601 char rd_buf
[RD_ADDRSTRLEN
];
2602 char pfx_buf
[PREFIX_STRLEN
];
2604 /* ' with addpath ID ' 17
2605 * max strlen of uint32 + 10
2606 * +/- (just in case) + 1
2607 * null terminator + 1
2608 * ============================ 29 */
2609 char pathid_buf
[30];
2611 if (size
< BGP_PRD_PATH_STRLEN
)
2614 /* Note: Path-id is created by default, but only included in update
2616 pathid_buf
[0] = '\0';
2618 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2622 if (bgp_labeled_safi(safi
) && num_labels
) {
2624 if (safi
== SAFI_EVPN
) {
2627 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2628 sprintf(tag_buf
, " label %s", tag_buf2
);
2630 uint32_t label_value
;
2632 label_value
= decode_label(label
);
2633 sprintf(tag_buf
, " label %u", label_value
);
2638 snprintf(str
, size
, "RD %s %s%s%s %s %s",
2639 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2640 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2641 pathid_buf
, afi2str(afi
), safi2str(safi
));
2642 else if (safi
== SAFI_FLOWSPEC
) {
2643 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2644 const struct prefix_fs
*fs
= pu
.fs
;
2646 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2647 fs
->prefix
.prefixlen
,
2649 NLRI_STRING_FORMAT_DEBUG
, NULL
);
2650 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2653 snprintf(str
, size
, "%s%s%s %s %s",
2654 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2655 pathid_buf
, afi2str(afi
), safi2str(safi
));