1 /* BGP-4, BGP-4+ packet debug routine
2 * Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <lib/version.h>
29 #include "sockunion.h"
34 #include "bgpd/bgpd.h"
35 #include "bgpd/bgp_aspath.h"
36 #include "bgpd/bgp_route.h"
37 #include "bgpd/bgp_attr.h"
38 #include "bgpd/bgp_debug.h"
39 #include "bgpd/bgp_community.h"
40 #include "bgpd/bgp_updgrp.h"
41 #include "bgpd/bgp_mplsvpn.h"
42 #include "bgpd/bgp_ecommunity.h"
43 #include "bgpd/bgp_label.h"
44 #include "bgpd/bgp_evpn.h"
45 #include "bgpd/bgp_evpn_private.h"
46 #include "bgpd/bgp_evpn_vty.h"
47 #include "bgpd/bgp_vty.h"
48 #include "bgpd/bgp_flowspec.h"
50 unsigned long conf_bgp_debug_as4
;
51 unsigned long conf_bgp_debug_neighbor_events
;
52 unsigned long conf_bgp_debug_events
;
53 unsigned long conf_bgp_debug_packet
;
54 unsigned long conf_bgp_debug_filter
;
55 unsigned long conf_bgp_debug_keepalive
;
56 unsigned long conf_bgp_debug_update
;
57 unsigned long conf_bgp_debug_bestpath
;
58 unsigned long conf_bgp_debug_zebra
;
59 unsigned long conf_bgp_debug_allow_martians
;
60 unsigned long conf_bgp_debug_nht
;
61 unsigned long conf_bgp_debug_update_groups
;
62 unsigned long conf_bgp_debug_vpn
;
63 unsigned long conf_bgp_debug_flowspec
;
64 unsigned long conf_bgp_debug_labelpool
;
65 unsigned long conf_bgp_debug_pbr
;
67 unsigned long term_bgp_debug_as4
;
68 unsigned long term_bgp_debug_neighbor_events
;
69 unsigned long term_bgp_debug_events
;
70 unsigned long term_bgp_debug_packet
;
71 unsigned long term_bgp_debug_filter
;
72 unsigned long term_bgp_debug_keepalive
;
73 unsigned long term_bgp_debug_update
;
74 unsigned long term_bgp_debug_bestpath
;
75 unsigned long term_bgp_debug_zebra
;
76 unsigned long term_bgp_debug_allow_martians
;
77 unsigned long term_bgp_debug_nht
;
78 unsigned long term_bgp_debug_update_groups
;
79 unsigned long term_bgp_debug_vpn
;
80 unsigned long term_bgp_debug_flowspec
;
81 unsigned long term_bgp_debug_labelpool
;
82 unsigned long term_bgp_debug_pbr
;
84 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
85 struct list
*bgp_debug_keepalive_peers
= NULL
;
86 struct list
*bgp_debug_update_out_peers
= NULL
;
87 struct list
*bgp_debug_update_in_peers
= NULL
;
88 struct list
*bgp_debug_update_prefixes
= NULL
;
89 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
90 struct list
*bgp_debug_zebra_prefixes
= NULL
;
92 /* messages for BGP-4 status */
93 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
96 {OpenSent
, "OpenSent"},
97 {OpenConfirm
, "OpenConfirm"},
98 {Established
, "Established"},
99 {Clearing
, "Clearing"},
100 {Deleted
, "Deleted"},
103 /* BGP message type string. */
104 const char *bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
105 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
108 /* message for BGP-4 Notify */
109 static const struct message bgp_notify_msg
[] = {
110 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
111 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
112 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
113 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
114 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
115 {BGP_NOTIFY_CEASE
, "Cease"},
116 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
119 static const struct message bgp_notify_head_msg
[] = {
120 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
121 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
122 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
125 static const struct message bgp_notify_open_msg
[] = {
126 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
127 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
128 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
129 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
130 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
131 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
132 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
133 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
136 static const struct message bgp_notify_update_msg
[] = {
137 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
138 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
139 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
140 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
141 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
142 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
143 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
144 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
145 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
146 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
147 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
148 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
151 static const struct message bgp_notify_cease_msg
[] = {
152 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
153 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
154 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
155 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
156 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
157 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
158 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
159 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
160 "/Connection collision resolution"},
161 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
164 static const struct message bgp_notify_capability_msg
[] = {
165 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
166 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
167 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
168 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
171 /* Origin strings. */
172 const char *bgp_origin_str
[] = {"i", "e", "?"};
173 const char *bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
175 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
177 /* Given a string return a pointer the corresponding peer structure */
178 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
180 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
188 ret
= str2sockunion(peer_str
, &su
);
192 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
195 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
199 return peer_lookup(bgp
, &su
);
202 static void bgp_debug_list_free(struct list
*list
)
204 struct bgp_debug_filter
*filter
;
205 struct listnode
*node
, *nnode
;
208 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
209 listnode_delete(list
, filter
);
212 prefix_free(&filter
->p
);
215 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
217 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
222 * Print the desc along with a list of peers/prefixes this debug is
225 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
228 struct bgp_debug_filter
*filter
;
229 struct listnode
*node
, *nnode
;
230 char buf
[PREFIX2STR_BUFFER
];
232 vty_out(vty
, "%s", desc
);
234 if (list
&& !list_isempty(list
)) {
235 vty_out(vty
, " for");
236 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
238 vty_out(vty
, " %s", filter
->host
);
240 if (filter
->p
&& filter
->p
->family
== AF_EVPN
)
241 bgp_debug_print_evpn_prefix(vty
, "", filter
->p
);
242 else if (filter
->p
) {
243 prefix2str(filter
->p
, buf
, sizeof(buf
));
244 vty_out(vty
, " %s", buf
);
253 * Print the command to enable the debug for each peer/prefix this debug is
256 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
259 struct bgp_debug_filter
*filter
;
260 struct listnode
*node
, *nnode
;
261 char buf
[PREFIX2STR_BUFFER
];
264 if (list
&& !list_isempty(list
)) {
265 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
267 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
271 if (filter
->p
&& filter
->p
->family
== AF_EVPN
) {
272 bgp_debug_print_evpn_prefix(vty
, desc
,
275 } else if (filter
->p
) {
276 prefix2str(filter
->p
, buf
, sizeof(buf
));
277 vty_out(vty
, "%s %s\n", desc
, buf
);
284 vty_out(vty
, "%s\n", desc
);
291 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
292 const struct prefix
*p
)
294 struct bgp_debug_filter
*filter
;
296 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
297 sizeof(struct bgp_debug_filter
));
300 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
304 filter
->p
= prefix_new();
305 prefix_copy(filter
->p
, p
);
308 listnode_add(list
, filter
);
311 static int bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
314 struct bgp_debug_filter
*filter
;
315 struct listnode
*node
, *nnode
;
317 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
318 if (host
&& strcmp(filter
->host
, host
) == 0) {
319 listnode_delete(list
, filter
);
320 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
321 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
323 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
324 && prefix_match(filter
->p
, p
)) {
325 listnode_delete(list
, filter
);
326 prefix_free(&filter
->p
);
327 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
335 static int bgp_debug_list_has_entry(struct list
*list
, const char *host
,
336 const struct prefix
*p
)
338 struct bgp_debug_filter
*filter
;
339 struct listnode
*node
, *nnode
;
341 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
343 if (strcmp(filter
->host
, host
) == 0) {
347 if (filter
->p
->prefixlen
== p
->prefixlen
348 && prefix_match(filter
->p
, p
)) {
357 int bgp_debug_peer_updout_enabled(char *host
)
359 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
363 /* Dump attribute. */
364 int bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
366 char addrbuf
[BUFSIZ
];
373 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
374 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
376 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
377 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
378 bgp_origin_str
[attr
->origin
]);
381 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
382 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
383 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
385 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
388 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
389 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
390 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
393 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
394 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
396 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
397 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
398 ", localpref %u", attr
->local_pref
);
400 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
401 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
404 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
405 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
407 community_str(attr
->community
, false));
409 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
410 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
411 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
413 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
414 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
415 ", atomic-aggregate");
417 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
418 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
419 ", aggregated by %u %s", attr
->aggregator_as
,
420 inet_ntoa(attr
->aggregator_addr
));
422 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
423 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
424 ", originator %s", inet_ntoa(attr
->originator_id
));
426 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
429 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
431 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
432 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
433 inet_ntoa(attr
->cluster
->list
[i
]));
436 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
)))
437 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
438 ", pmsi tnltype %u", attr
->pmsi_tnl_type
);
440 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
441 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
442 aspath_print(attr
->aspath
));
444 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
445 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
446 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
447 ", label-index %u", attr
->label_index
);
456 const char *bgp_notify_code_str(char code
)
458 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
461 const char *bgp_notify_subcode_str(char code
, char subcode
)
465 case BGP_NOTIFY_HEADER_ERR
:
466 return lookup_msg(bgp_notify_head_msg
, subcode
,
467 "Unrecognized Error Subcode");
468 case BGP_NOTIFY_OPEN_ERR
:
469 return lookup_msg(bgp_notify_open_msg
, subcode
,
470 "Unrecognized Error Subcode");
471 case BGP_NOTIFY_UPDATE_ERR
:
472 return lookup_msg(bgp_notify_update_msg
, subcode
,
473 "Unrecognized Error Subcode");
474 case BGP_NOTIFY_HOLD_ERR
:
476 case BGP_NOTIFY_FSM_ERR
:
478 case BGP_NOTIFY_CEASE
:
479 return lookup_msg(bgp_notify_cease_msg
, subcode
,
480 "Unrecognized Error Subcode");
481 case BGP_NOTIFY_CAPABILITY_ERR
:
482 return lookup_msg(bgp_notify_capability_msg
, subcode
,
483 "Unrecognized Error Subcode");
488 /* extract notify admin reason if correctly present */
489 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, uint8_t *data
,
492 if (!data
|| datalen
< 1)
495 uint8_t len
= data
[0];
496 if (len
> 128 || len
> datalen
- 1)
499 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
502 /* dump notify packet */
503 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
506 const char *subcode_str
;
507 const char *code_str
;
508 const char *msg_str
= NULL
;
511 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
512 || bgp_flag_check(peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
513 code_str
= bgp_notify_code_str(bgp_notify
->code
);
514 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
515 bgp_notify
->subcode
);
517 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
518 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
519 || bgp_notify
->subcode
520 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
521 msg_str
= bgp_notify_admin_message(
522 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
528 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
529 strcmp(direct
, "received") == 0
532 peer
->host
, bgp_notify
->code
,
533 bgp_notify
->subcode
, code_str
, subcode_str
,
536 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
538 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
539 strcmp(direct
, "received") == 0
542 peer
->host
, bgp_notify
->code
,
543 bgp_notify
->subcode
, code_str
, subcode_str
,
544 bgp_notify
->length
, msg_str
);
549 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
552 bgp
= bgp_get_default();
553 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
556 static int bgp_debug_print_evpn_prefix(struct vty
*vty
, const char *desc
,
559 char evpn_desc
[PREFIX2STR_BUFFER
+ INET_ADDRSTRLEN
];
560 char buf
[PREFIX2STR_BUFFER
];
561 char buf2
[ETHER_ADDR_STRLEN
];
563 if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
564 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)p
)) {
565 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s",
567 &p
->u
.prefix_evpn
.macip_addr
.mac
,
568 buf2
, sizeof(buf2
)));
570 uint8_t family
= is_evpn_prefix_ipaddr_v4(
571 (struct prefix_evpn
*)p
) ?
573 sprintf(evpn_desc
, "l2vpn evpn type macip mac %s ip %s",
575 &p
->u
.prefix_evpn
.macip_addr
.mac
,
578 &p
->u
.prefix_evpn
.macip_addr
.ip
.ip
.addr
,
579 buf
, PREFIX2STR_BUFFER
));
581 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IMET_ROUTE
) {
582 sprintf(evpn_desc
, "l2vpn evpn type multicast ip %s",
583 inet_ntoa(p
->u
.prefix_evpn
.imet_addr
.ip
.ipaddr_v4
));
584 } else if (p
->u
.prefix_evpn
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
585 uint8_t family
= is_evpn_prefix_ipaddr_v4(
586 (struct prefix_evpn
*)p
) ? AF_INET
588 sprintf(evpn_desc
, "l2vpn evpn type prefix ip %s/%d",
590 &p
->u
.prefix_evpn
.prefix_addr
.ip
.ip
.addr
, buf
,
592 p
->u
.prefix_evpn
.prefix_addr
.ip_prefix_length
);
595 vty_out(vty
, "%s %s\n", desc
, evpn_desc
);
600 static int bgp_debug_parse_evpn_prefix(struct vty
*vty
, struct cmd_token
**argv
,
601 int argc
, struct prefix
**argv_pp
)
603 struct prefix
*argv_p
;
613 if (argv_find(argv
, argc
, "macip", &type_idx
))
614 evpn_type
= BGP_EVPN_MAC_IP_ROUTE
;
615 else if (argv_find(argv
, argc
, "multicast", &type_idx
))
616 evpn_type
= BGP_EVPN_IMET_ROUTE
;
617 else if (argv_find(argv
, argc
, "prefix", &type_idx
))
618 evpn_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
622 if (evpn_type
== BGP_EVPN_MAC_IP_ROUTE
) {
623 memset(&ip
, 0, sizeof(struct ipaddr
));
625 argv_find(argv
, argc
, "mac", &mac_idx
);
626 (void)prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
);
628 argv_find(argv
, argc
, "ip", &ip_idx
);
629 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
631 build_evpn_type2_prefix((struct prefix_evpn
*)argv_p
,
633 } else if (evpn_type
== BGP_EVPN_IMET_ROUTE
) {
634 memset(&ip
, 0, sizeof(struct ipaddr
));
636 argv_find(argv
, argc
, "ip", &ip_idx
);
637 str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
);
639 build_evpn_type3_prefix((struct prefix_evpn
*)argv_p
,
641 } else if (evpn_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
642 struct prefix ip_prefix
;
644 memset(&ip_prefix
, 0, sizeof(struct prefix
));
645 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
646 (void)str2prefix(argv
[ip_idx
+ 1]->arg
, &ip_prefix
);
647 apply_mask(&ip_prefix
);
649 build_type5_prefix_from_ip_prefix(
650 (struct prefix_evpn
*)argv_p
,
657 /* Debug option setting interface. */
658 unsigned long bgp_debug_option
= 0;
660 int debug(unsigned int option
)
662 return bgp_debug_option
& option
;
665 DEFUN (debug_bgp_as4
,
672 if (vty
->node
== CONFIG_NODE
)
675 TERM_DEBUG_ON(as4
, AS4
);
676 vty_out(vty
, "BGP as4 debugging is on\n");
681 DEFUN (no_debug_bgp_as4
,
682 no_debug_bgp_as4_cmd
,
689 if (vty
->node
== CONFIG_NODE
)
692 TERM_DEBUG_OFF(as4
, AS4
);
693 vty_out(vty
, "BGP as4 debugging is off\n");
698 DEFUN (debug_bgp_as4_segment
,
699 debug_bgp_as4_segment_cmd
,
700 "debug bgp as4 segment",
704 "BGP AS4 aspath segment handling\n")
706 if (vty
->node
== CONFIG_NODE
)
707 DEBUG_ON(as4
, AS4_SEGMENT
);
709 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
710 vty_out(vty
, "BGP as4 segment debugging is on\n");
715 DEFUN (no_debug_bgp_as4_segment
,
716 no_debug_bgp_as4_segment_cmd
,
717 "no debug bgp as4 segment",
722 "BGP AS4 aspath segment handling\n")
724 if (vty
->node
== CONFIG_NODE
)
725 DEBUG_OFF(as4
, AS4_SEGMENT
);
727 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
728 vty_out(vty
, "BGP as4 segment debugging is off\n");
733 /* debug bgp neighbor_events */
734 DEFUN (debug_bgp_neighbor_events
,
735 debug_bgp_neighbor_events_cmd
,
736 "debug bgp neighbor-events",
739 "BGP Neighbor Events\n")
741 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
743 if (vty
->node
== CONFIG_NODE
)
744 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
746 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
747 vty_out(vty
, "BGP neighbor-events debugging is on\n");
752 DEFUN (debug_bgp_neighbor_events_peer
,
753 debug_bgp_neighbor_events_peer_cmd
,
754 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
757 "BGP Neighbor Events\n"
758 "BGP neighbor IP address to debug\n"
759 "BGP IPv6 neighbor to debug\n"
760 "BGP neighbor on interface to debug\n")
763 const char *host
= argv
[idx_peer
]->arg
;
765 if (!bgp_debug_neighbor_events_peers
)
766 bgp_debug_neighbor_events_peers
= list_new();
768 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
771 "BGP neighbor-events debugging is already enabled for %s\n",
776 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
778 if (vty
->node
== CONFIG_NODE
)
779 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
781 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
782 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
788 DEFUN (no_debug_bgp_neighbor_events
,
789 no_debug_bgp_neighbor_events_cmd
,
790 "no debug bgp neighbor-events",
796 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
798 if (vty
->node
== CONFIG_NODE
)
799 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
801 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
802 vty_out(vty
, "BGP neighbor-events debugging is off\n");
807 DEFUN (no_debug_bgp_neighbor_events_peer
,
808 no_debug_bgp_neighbor_events_peer_cmd
,
809 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
814 "BGP neighbor IP address to debug\n"
815 "BGP IPv6 neighbor to debug\n"
816 "BGP neighbor on interface to debug\n")
820 const char *host
= argv
[idx_peer
]->arg
;
822 if (bgp_debug_neighbor_events_peers
823 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
824 found_peer
= bgp_debug_list_remove_entry(
825 bgp_debug_neighbor_events_peers
, host
, NULL
);
827 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
828 if (vty
->node
== CONFIG_NODE
)
829 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
831 TERM_DEBUG_OFF(neighbor_events
,
837 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
841 "BGP neighbor-events debugging was not enabled for %s\n",
848 DEFUN (debug_bgp_nht
,
853 "BGP nexthop tracking events\n")
855 if (vty
->node
== CONFIG_NODE
)
858 TERM_DEBUG_ON(nht
, NHT
);
859 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
864 DEFUN (no_debug_bgp_nht
,
865 no_debug_bgp_nht_cmd
,
870 "BGP nexthop tracking events\n")
872 if (vty
->node
== CONFIG_NODE
)
875 TERM_DEBUG_OFF(nht
, NHT
);
876 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
881 /* debug bgp keepalives */
882 DEFUN (debug_bgp_keepalive
,
883 debug_bgp_keepalive_cmd
,
884 "debug bgp keepalives",
889 bgp_debug_list_free(bgp_debug_keepalive_peers
);
891 if (vty
->node
== CONFIG_NODE
)
892 DEBUG_ON(keepalive
, KEEPALIVE
);
894 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
895 vty_out(vty
, "BGP keepalives debugging is on\n");
900 DEFUN (debug_bgp_keepalive_peer
,
901 debug_bgp_keepalive_peer_cmd
,
902 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
905 "BGP Neighbor Events\n"
906 "BGP neighbor IP address to debug\n"
907 "BGP IPv6 neighbor to debug\n"
908 "BGP neighbor on interface to debug\n")
911 const char *host
= argv
[idx_peer
]->arg
;
913 if (!bgp_debug_keepalive_peers
)
914 bgp_debug_keepalive_peers
= list_new();
916 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
918 "BGP keepalive debugging is already enabled for %s\n",
923 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
925 if (vty
->node
== CONFIG_NODE
)
926 DEBUG_ON(keepalive
, KEEPALIVE
);
928 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
929 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
934 DEFUN (no_debug_bgp_keepalive
,
935 no_debug_bgp_keepalive_cmd
,
936 "no debug bgp keepalives",
942 bgp_debug_list_free(bgp_debug_keepalive_peers
);
944 if (vty
->node
== CONFIG_NODE
)
945 DEBUG_OFF(keepalive
, KEEPALIVE
);
947 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
948 vty_out(vty
, "BGP keepalives debugging is off\n");
953 DEFUN (no_debug_bgp_keepalive_peer
,
954 no_debug_bgp_keepalive_peer_cmd
,
955 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
960 "BGP neighbor IP address to debug\n"
961 "BGP IPv6 neighbor to debug\n"
962 "BGP neighbor on interface to debug\n")
966 const char *host
= argv
[idx_peer
]->arg
;
968 if (bgp_debug_keepalive_peers
969 && !list_isempty(bgp_debug_keepalive_peers
)) {
970 found_peer
= bgp_debug_list_remove_entry(
971 bgp_debug_keepalive_peers
, host
, NULL
);
973 if (list_isempty(bgp_debug_keepalive_peers
)) {
974 if (vty
->node
== CONFIG_NODE
)
975 DEBUG_OFF(keepalive
, KEEPALIVE
);
977 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
982 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
985 "BGP keepalives debugging was not enabled for %s\n",
991 /* debug bgp bestpath */
992 DEFUN (debug_bgp_bestpath_prefix
,
993 debug_bgp_bestpath_prefix_cmd
,
994 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1001 struct prefix
*argv_p
;
1002 int idx_ipv4_ipv6_prefixlen
= 3;
1004 argv_p
= prefix_new();
1005 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1008 if (!bgp_debug_bestpath_prefixes
)
1009 bgp_debug_bestpath_prefixes
= list_new();
1011 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
1014 "BGP bestpath debugging is already enabled for %s\n",
1015 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1019 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1021 if (vty
->node
== CONFIG_NODE
) {
1022 DEBUG_ON(bestpath
, BESTPATH
);
1024 TERM_DEBUG_ON(bestpath
, BESTPATH
);
1025 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
1026 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1032 DEFUN (no_debug_bgp_bestpath_prefix
,
1033 no_debug_bgp_bestpath_prefix_cmd
,
1034 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
1042 int idx_ipv4_ipv6_prefixlen
= 4;
1043 struct prefix
*argv_p
;
1044 int found_prefix
= 0;
1046 argv_p
= prefix_new();
1047 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1050 if (bgp_debug_bestpath_prefixes
1051 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
1052 found_prefix
= bgp_debug_list_remove_entry(
1053 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
1055 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
1056 if (vty
->node
== CONFIG_NODE
) {
1057 DEBUG_OFF(bestpath
, BESTPATH
);
1059 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1061 "BGP bestpath debugging (per prefix) is off\n");
1067 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
1068 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1070 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
1071 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1076 DEFUN (no_debug_bgp_bestpath
,
1077 no_debug_bgp_bestpath_cmd
,
1078 "no debug bgp bestpath",
1084 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1086 if (vty
->node
== CONFIG_NODE
)
1087 DEBUG_OFF(bestpath
, BESTPATH
);
1089 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1090 vty_out(vty
, "BGP bestpath debugging is off\n");
1095 /* debug bgp updates */
1096 DEFUN (debug_bgp_update
,
1097 debug_bgp_update_cmd
,
1098 "debug bgp updates",
1103 bgp_debug_list_free(bgp_debug_update_in_peers
);
1104 bgp_debug_list_free(bgp_debug_update_out_peers
);
1105 bgp_debug_list_free(bgp_debug_update_prefixes
);
1107 if (vty
->node
== CONFIG_NODE
) {
1108 DEBUG_ON(update
, UPDATE_IN
);
1109 DEBUG_ON(update
, UPDATE_OUT
);
1111 TERM_DEBUG_ON(update
, UPDATE_IN
);
1112 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1113 vty_out(vty
, "BGP updates debugging is on\n");
1118 DEFUN (debug_bgp_update_direct
,
1119 debug_bgp_update_direct_cmd
,
1120 "debug bgp updates <in|out>",
1125 "Outbound updates\n")
1129 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1130 bgp_debug_list_free(bgp_debug_update_in_peers
);
1132 bgp_debug_list_free(bgp_debug_update_out_peers
);
1134 if (vty
->node
== CONFIG_NODE
) {
1135 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1136 DEBUG_ON(update
, UPDATE_IN
);
1138 DEBUG_ON(update
, UPDATE_OUT
);
1140 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1141 TERM_DEBUG_ON(update
, UPDATE_IN
);
1142 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1144 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1146 "BGP updates debugging is on (outbound)\n");
1152 DEFUN (debug_bgp_update_direct_peer
,
1153 debug_bgp_update_direct_peer_cmd
,
1154 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1159 "Outbound updates\n"
1160 "BGP neighbor IP address to debug\n"
1161 "BGP IPv6 neighbor to debug\n"
1162 "BGP neighbor on interface to debug\n")
1166 const char *host
= argv
[idx_peer
]->arg
;
1169 if (!bgp_debug_update_in_peers
)
1170 bgp_debug_update_in_peers
= list_new();
1172 if (!bgp_debug_update_out_peers
)
1173 bgp_debug_update_out_peers
= list_new();
1175 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1181 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1184 "BGP inbound update debugging is already enabled for %s\n",
1191 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1194 "BGP outbound update debugging is already enabled for %s\n",
1201 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1204 struct peer_af
*paf
;
1207 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1209 peer
= bgp_find_peer(vty
, host
);
1212 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1214 paf
= peer
->peer_af_array
[afidx
];
1216 if (PAF_SUBGRP(paf
)) {
1226 if (vty
->node
== CONFIG_NODE
) {
1228 DEBUG_ON(update
, UPDATE_IN
);
1230 DEBUG_ON(update
, UPDATE_OUT
);
1233 TERM_DEBUG_ON(update
, UPDATE_IN
);
1235 "BGP updates debugging is on (inbound) for %s\n",
1236 argv
[idx_peer
]->arg
);
1238 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1240 "BGP updates debugging is on (outbound) for %s\n",
1241 argv
[idx_peer
]->arg
);
1247 DEFUN (no_debug_bgp_update_direct
,
1248 no_debug_bgp_update_direct_cmd
,
1249 "no debug bgp updates <in|out>",
1255 "Outbound updates\n")
1258 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1259 bgp_debug_list_free(bgp_debug_update_in_peers
);
1261 if (vty
->node
== CONFIG_NODE
) {
1262 DEBUG_OFF(update
, UPDATE_IN
);
1264 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1266 "BGP updates debugging is off (inbound)\n");
1269 bgp_debug_list_free(bgp_debug_update_out_peers
);
1271 if (vty
->node
== CONFIG_NODE
) {
1272 DEBUG_OFF(update
, UPDATE_OUT
);
1274 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1276 "BGP updates debugging is off (outbound)\n");
1283 DEFUN (no_debug_bgp_update_direct_peer
,
1284 no_debug_bgp_update_direct_peer_cmd
,
1285 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1291 "Outbound updates\n"
1292 "BGP neighbor IP address to debug\n"
1293 "BGP IPv6 neighbor to debug\n"
1294 "BGP neighbor on interface to debug\n")
1300 const char *host
= argv
[idx_peer
]->arg
;
1302 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1307 if (inbound
&& bgp_debug_update_in_peers
1308 && !list_isempty(bgp_debug_update_in_peers
)) {
1309 found_peer
= bgp_debug_list_remove_entry(
1310 bgp_debug_update_in_peers
, host
, NULL
);
1312 if (list_isempty(bgp_debug_update_in_peers
)) {
1313 if (vty
->node
== CONFIG_NODE
)
1314 DEBUG_OFF(update
, UPDATE_IN
);
1316 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1318 "BGP updates debugging (inbound) is off\n");
1323 if (!inbound
&& bgp_debug_update_out_peers
1324 && !list_isempty(bgp_debug_update_out_peers
)) {
1325 found_peer
= bgp_debug_list_remove_entry(
1326 bgp_debug_update_out_peers
, host
, NULL
);
1328 if (list_isempty(bgp_debug_update_out_peers
)) {
1329 if (vty
->node
== CONFIG_NODE
)
1330 DEBUG_OFF(update
, UPDATE_OUT
);
1332 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1334 "BGP updates debugging (outbound) is off\n");
1339 struct peer_af
*paf
;
1341 peer
= bgp_find_peer(vty
, host
);
1344 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1346 paf
= peer
->peer_af_array
[afidx
];
1348 if (PAF_SUBGRP(paf
)) {
1349 UPDGRP_PEER_DBG_DIS(
1361 "BGP updates debugging (inbound) is off for %s\n",
1365 "BGP updates debugging (outbound) is off for %s\n",
1369 "BGP updates debugging (inbound) was not enabled for %s\n",
1373 "BGP updates debugging (outbound) was not enabled for %s\n",
1379 #ifndef VTYSH_EXTRACT_PL
1380 #include "bgpd/bgp_debug_clippy.c"
1383 DEFPY (debug_bgp_update_prefix_afi_safi
,
1384 debug_bgp_update_prefix_afi_safi_cmd
,
1385 "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>>",
1389 "Specify a prefix to debug\n"
1392 "Specify EVPN Route type\n"
1393 "MAC-IP (Type-2) route\n"
1394 MAC_STR MAC_STR MAC_STR
1398 "Multicast (Type-3) route\n"
1402 "Prefix (Type-5) route\n"
1407 struct prefix
*argv_p
;
1408 int ret
= CMD_SUCCESS
;
1409 char buf
[PREFIX2STR_BUFFER
];
1411 argv_p
= prefix_new();
1413 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1414 if (ret
!= CMD_SUCCESS
) {
1415 prefix_free(&argv_p
);
1419 if (!bgp_debug_update_prefixes
)
1420 bgp_debug_update_prefixes
= list_new();
1422 prefix2str(argv_p
, buf
, sizeof(buf
));
1424 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1426 "BGP updates debugging is already enabled for %s\n",
1428 prefix_free(&argv_p
);
1432 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1434 if (vty
->node
== CONFIG_NODE
) {
1435 DEBUG_ON(update
, UPDATE_PREFIX
);
1437 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1438 vty_out(vty
, "BGP updates debugging is on for %s\n", buf
);
1441 prefix_free(&argv_p
);
1446 DEFPY (no_debug_bgp_update_prefix_afi_safi
,
1447 no_debug_bgp_update_prefix_afi_safi_cmd
,
1448 "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>>",
1453 "Specify a prefix to debug\n"
1456 "Specify EVPN Route type\n"
1457 "MAC-IP (Type-2) route\n"
1458 MAC_STR MAC_STR MAC_STR
1462 "Multicast (Type-3) route\n"
1466 "Prefix (Type-5) route\n"
1471 struct prefix
*argv_p
;
1472 bool found_prefix
= false;
1473 int ret
= CMD_SUCCESS
;
1474 char buf
[PREFIX2STR_BUFFER
];
1476 argv_p
= prefix_new();
1478 ret
= bgp_debug_parse_evpn_prefix(vty
, argv
, argc
, &argv_p
);
1479 if (ret
!= CMD_SUCCESS
) {
1480 prefix_free(&argv_p
);
1484 if (bgp_debug_update_prefixes
1485 && !list_isempty(bgp_debug_update_prefixes
)) {
1486 found_prefix
= bgp_debug_list_remove_entry(
1487 bgp_debug_update_prefixes
, NULL
, argv_p
);
1489 if (list_isempty(bgp_debug_update_prefixes
)) {
1490 if (vty
->node
== CONFIG_NODE
) {
1491 DEBUG_OFF(update
, UPDATE_PREFIX
);
1493 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1495 "BGP updates debugging (per prefix) is off\n");
1500 prefix2str(argv_p
, buf
, sizeof(buf
));
1503 vty_out(vty
, "BGP updates debugging is off for %s\n", buf
);
1505 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1508 prefix_free(&argv_p
);
1514 DEFUN (debug_bgp_update_prefix
,
1515 debug_bgp_update_prefix_cmd
,
1516 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1520 "Specify a prefix to debug\n"
1524 int idx_ipv4_ipv6_prefixlen
= 4;
1525 struct prefix
*argv_p
;
1527 argv_p
= prefix_new();
1528 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1531 if (!bgp_debug_update_prefixes
)
1532 bgp_debug_update_prefixes
= list_new();
1534 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1536 "BGP updates debugging is already enabled for %s\n",
1537 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1541 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1543 if (vty
->node
== CONFIG_NODE
) {
1544 DEBUG_ON(update
, UPDATE_PREFIX
);
1546 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1547 vty_out(vty
, "BGP updates debugging is on for %s\n",
1548 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1554 DEFUN (no_debug_bgp_update_prefix
,
1555 no_debug_bgp_update_prefix_cmd
,
1556 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1561 "Specify a prefix to debug\n"
1565 int idx_ipv4_ipv6_prefixlen
= 5;
1566 struct prefix
*argv_p
;
1567 int found_prefix
= 0;
1569 argv_p
= prefix_new();
1570 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1573 if (bgp_debug_update_prefixes
1574 && !list_isempty(bgp_debug_update_prefixes
)) {
1575 found_prefix
= bgp_debug_list_remove_entry(
1576 bgp_debug_update_prefixes
, NULL
, argv_p
);
1578 if (list_isempty(bgp_debug_update_prefixes
)) {
1579 if (vty
->node
== CONFIG_NODE
) {
1580 DEBUG_OFF(update
, UPDATE_PREFIX
);
1582 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1584 "BGP updates debugging (per prefix) is off\n");
1590 vty_out(vty
, "BGP updates debugging is off for %s\n",
1591 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1593 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1594 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1599 DEFUN (no_debug_bgp_update
,
1600 no_debug_bgp_update_cmd
,
1601 "no debug bgp updates",
1607 struct listnode
*ln
;
1610 bgp_debug_list_free(bgp_debug_update_in_peers
);
1611 bgp_debug_list_free(bgp_debug_update_out_peers
);
1612 bgp_debug_list_free(bgp_debug_update_prefixes
);
1614 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1615 bgp_debug_clear_updgrp_update_dbg(bgp
);
1617 if (vty
->node
== CONFIG_NODE
) {
1618 DEBUG_OFF(update
, UPDATE_IN
);
1619 DEBUG_OFF(update
, UPDATE_OUT
);
1620 DEBUG_OFF(update
, UPDATE_PREFIX
);
1622 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1623 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1624 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1625 vty_out(vty
, "BGP updates debugging is off\n");
1630 /* debug bgp zebra */
1631 DEFUN (debug_bgp_zebra
,
1632 debug_bgp_zebra_cmd
,
1636 "BGP Zebra messages\n")
1638 if (vty
->node
== CONFIG_NODE
)
1639 DEBUG_ON(zebra
, ZEBRA
);
1641 TERM_DEBUG_ON(zebra
, ZEBRA
);
1642 vty_out(vty
, "BGP zebra debugging is on\n");
1647 DEFUN (debug_bgp_zebra_prefix
,
1648 debug_bgp_zebra_prefix_cmd
,
1649 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1652 "BGP Zebra messages\n"
1653 "Specify a prefix to debug\n"
1657 int idx_ipv4_ipv6_prefixlen
= 4;
1658 struct prefix
*argv_p
;
1660 argv_p
= prefix_new();
1661 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1664 if (!bgp_debug_zebra_prefixes
)
1665 bgp_debug_zebra_prefixes
= list_new();
1667 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1668 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1669 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1673 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1675 if (vty
->node
== CONFIG_NODE
)
1676 DEBUG_ON(zebra
, ZEBRA
);
1678 TERM_DEBUG_ON(zebra
, ZEBRA
);
1679 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1680 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1686 DEFUN (no_debug_bgp_zebra
,
1687 no_debug_bgp_zebra_cmd
,
1688 "no debug bgp zebra",
1692 "BGP Zebra messages\n")
1694 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1696 if (vty
->node
== CONFIG_NODE
)
1697 DEBUG_OFF(zebra
, ZEBRA
);
1699 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1700 vty_out(vty
, "BGP zebra debugging is off\n");
1705 DEFUN (no_debug_bgp_zebra_prefix
,
1706 no_debug_bgp_zebra_prefix_cmd
,
1707 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1711 "BGP Zebra messages\n"
1712 "Specify a prefix to debug\n"
1716 int idx_ipv4_ipv6_prefixlen
= 5;
1717 struct prefix
*argv_p
;
1718 int found_prefix
= 0;
1720 argv_p
= prefix_new();
1721 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1724 if (bgp_debug_zebra_prefixes
1725 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1726 found_prefix
= bgp_debug_list_remove_entry(
1727 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1729 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1730 if (vty
->node
== CONFIG_NODE
)
1731 DEBUG_OFF(zebra
, ZEBRA
);
1733 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1734 vty_out(vty
, "BGP zebra debugging is off\n");
1740 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1741 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1743 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1744 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1749 DEFUN (debug_bgp_allow_martians
,
1750 debug_bgp_allow_martians_cmd
,
1751 "debug bgp allow-martians",
1754 "BGP allow martian next hops\n")
1756 if (vty
->node
== CONFIG_NODE
)
1757 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1759 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1760 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1765 DEFUN (no_debug_bgp_allow_martians
,
1766 no_debug_bgp_allow_martians_cmd
,
1767 "no debug bgp allow-martians",
1771 "BGP allow martian next hops\n")
1773 if (vty
->node
== CONFIG_NODE
)
1774 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1776 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1777 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1783 /* debug bgp update-groups */
1784 DEFUN (debug_bgp_update_groups
,
1785 debug_bgp_update_groups_cmd
,
1786 "debug bgp update-groups",
1789 "BGP update-groups\n")
1791 if (vty
->node
== CONFIG_NODE
)
1792 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1794 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1795 vty_out(vty
, "BGP update-groups debugging is on\n");
1800 DEFUN (no_debug_bgp_update_groups
,
1801 no_debug_bgp_update_groups_cmd
,
1802 "no debug bgp update-groups",
1806 "BGP update-groups\n")
1808 if (vty
->node
== CONFIG_NODE
)
1809 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1811 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1812 vty_out(vty
, "BGP update-groups debugging is off\n");
1817 DEFUN (debug_bgp_vpn
,
1819 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1823 "leaked from vrf to vpn\n"
1824 "leaked to vrf from vpn\n"
1825 "route-map updates\n"
1830 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1831 if (vty
->node
== CONFIG_NODE
)
1832 DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1834 TERM_DEBUG_ON(vpn
, VPN_LEAK_FROM_VRF
);
1835 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1836 if (vty
->node
== CONFIG_NODE
)
1837 DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1839 TERM_DEBUG_ON(vpn
, VPN_LEAK_TO_VRF
);
1840 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1841 if (vty
->node
== CONFIG_NODE
)
1842 DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1844 TERM_DEBUG_ON(vpn
, VPN_LEAK_RMAP_EVENT
);
1845 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1846 if (vty
->node
== CONFIG_NODE
)
1847 DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1849 TERM_DEBUG_ON(vpn
, VPN_LEAK_LABEL
);
1851 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1852 return CMD_WARNING_CONFIG_FAILED
;
1855 if (vty
->node
!= CONFIG_NODE
)
1856 vty_out(vty
, "enabled debug bgp vpn %s\n", argv
[idx
]->text
);
1861 DEFUN (no_debug_bgp_vpn
,
1862 no_debug_bgp_vpn_cmd
,
1863 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1868 "leaked from vrf to vpn\n"
1869 "leaked to vrf from vpn\n"
1870 "route-map updates\n"
1875 if (argv_find(argv
, argc
, "leak-from-vrf", &idx
)) {
1876 if (vty
->node
== CONFIG_NODE
)
1877 DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1879 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
1881 } else if (argv_find(argv
, argc
, "leak-to-vrf", &idx
)) {
1882 if (vty
->node
== CONFIG_NODE
)
1883 DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1885 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
1886 } else if (argv_find(argv
, argc
, "rmap-event", &idx
)) {
1887 if (vty
->node
== CONFIG_NODE
)
1888 DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1890 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
1891 } else if (argv_find(argv
, argc
, "label", &idx
)) {
1892 if (vty
->node
== CONFIG_NODE
)
1893 DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1895 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
1897 vty_out(vty
, "%% unknown debug bgp vpn keyword\n");
1898 return CMD_WARNING_CONFIG_FAILED
;
1901 if (vty
->node
!= CONFIG_NODE
)
1902 vty_out(vty
, "disabled debug bgp vpn %s\n", argv
[idx
]->text
);
1907 DEFUN (debug_bgp_pbr
,
1909 "debug bgp pbr [error]",
1912 "BGP policy based routing\n"
1917 if (argv_find(argv
, argc
, "error", &idx
)) {
1918 if (vty
->node
== CONFIG_NODE
)
1919 DEBUG_ON(pbr
, PBR_ERROR
);
1921 TERM_DEBUG_ON(pbr
, PBR_ERROR
);
1922 vty_out(vty
, "BGP policy based routing error is on\n");
1926 if (vty
->node
== CONFIG_NODE
)
1929 TERM_DEBUG_ON(pbr
, PBR
);
1930 vty_out(vty
, "BGP policy based routing is on\n");
1935 DEFUN (no_debug_bgp_pbr
,
1936 no_debug_bgp_pbr_cmd
,
1937 "no 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_OFF(pbr
, PBR_ERROR
);
1950 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
1951 vty_out(vty
, "BGP policy based routing error is off\n");
1955 if (vty
->node
== CONFIG_NODE
)
1956 DEBUG_OFF(pbr
, PBR
);
1958 TERM_DEBUG_OFF(pbr
, PBR
);
1959 vty_out(vty
, "BGP policy based routing is off\n");
1964 DEFUN (debug_bgp_labelpool
,
1965 debug_bgp_labelpool_cmd
,
1966 "debug bgp labelpool",
1971 if (vty
->node
== CONFIG_NODE
)
1972 DEBUG_ON(labelpool
, LABELPOOL
);
1974 TERM_DEBUG_ON(labelpool
, LABELPOOL
);
1976 if (vty
->node
!= CONFIG_NODE
)
1977 vty_out(vty
, "enabled debug bgp labelpool\n");
1982 DEFUN (no_debug_bgp_labelpool
,
1983 no_debug_bgp_labelpool_cmd
,
1984 "no debug bgp labelpool",
1990 if (vty
->node
== CONFIG_NODE
)
1991 DEBUG_OFF(labelpool
, LABELPOOL
);
1993 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
1996 if (vty
->node
!= CONFIG_NODE
)
1997 vty_out(vty
, "disabled debug bgp labelpool\n");
2002 DEFUN (no_debug_bgp
,
2010 struct listnode
*ln
;
2012 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
2013 bgp_debug_list_free(bgp_debug_keepalive_peers
);
2014 bgp_debug_list_free(bgp_debug_update_in_peers
);
2015 bgp_debug_list_free(bgp_debug_update_out_peers
);
2016 bgp_debug_list_free(bgp_debug_update_prefixes
);
2017 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
2018 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
2020 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
2021 bgp_debug_clear_updgrp_update_dbg(bgp
);
2023 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
2024 TERM_DEBUG_OFF(update
, UPDATE_IN
);
2025 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
2026 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
2027 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
2028 TERM_DEBUG_OFF(as4
, AS4
);
2029 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
2030 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
2031 TERM_DEBUG_OFF(zebra
, ZEBRA
);
2032 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
2033 TERM_DEBUG_OFF(nht
, NHT
);
2034 TERM_DEBUG_OFF(vpn
, VPN_LEAK_FROM_VRF
);
2035 TERM_DEBUG_OFF(vpn
, VPN_LEAK_TO_VRF
);
2036 TERM_DEBUG_OFF(vpn
, VPN_LEAK_RMAP_EVENT
);
2037 TERM_DEBUG_OFF(vpn
, VPN_LEAK_LABEL
);
2038 TERM_DEBUG_OFF(flowspec
, FLOWSPEC
);
2039 TERM_DEBUG_OFF(labelpool
, LABELPOOL
);
2040 TERM_DEBUG_OFF(pbr
, PBR
);
2041 TERM_DEBUG_OFF(pbr
, PBR_ERROR
);
2042 vty_out(vty
, "All possible debugging has been turned off\n");
2047 DEFUN_NOSH (show_debugging_bgp
,
2048 show_debugging_bgp_cmd
,
2049 "show debugging [bgp]",
2054 vty_out(vty
, "BGP debugging status:\n");
2056 if (BGP_DEBUG(as4
, AS4
))
2057 vty_out(vty
, " BGP as4 debugging is on\n");
2059 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
2060 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
2062 if (BGP_DEBUG(bestpath
, BESTPATH
))
2063 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
2064 bgp_debug_bestpath_prefixes
);
2066 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
2067 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
2068 bgp_debug_keepalive_peers
);
2070 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
2071 bgp_debug_list_print(vty
,
2072 " BGP neighbor-events debugging is on",
2073 bgp_debug_neighbor_events_peers
);
2075 if (BGP_DEBUG(nht
, NHT
))
2076 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
2078 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
2079 vty_out(vty
, " BGP update-groups debugging is on\n");
2081 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
2082 bgp_debug_list_print(vty
, " BGP updates debugging is on",
2083 bgp_debug_update_prefixes
);
2085 if (BGP_DEBUG(update
, UPDATE_IN
))
2086 bgp_debug_list_print(vty
,
2087 " BGP updates debugging is on (inbound)",
2088 bgp_debug_update_in_peers
);
2090 if (BGP_DEBUG(update
, UPDATE_OUT
))
2091 bgp_debug_list_print(vty
,
2092 " BGP updates debugging is on (outbound)",
2093 bgp_debug_update_out_peers
);
2095 if (BGP_DEBUG(zebra
, ZEBRA
))
2096 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
2097 bgp_debug_zebra_prefixes
);
2099 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
2100 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
2102 if (BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
))
2104 " BGP route leak from vrf to vpn debugging is on\n");
2105 if (BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
))
2107 " BGP route leak to vrf from vpn debugging is on\n");
2108 if (BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
))
2109 vty_out(vty
, " BGP vpn route-map event debugging is on\n");
2110 if (BGP_DEBUG(vpn
, VPN_LEAK_LABEL
))
2111 vty_out(vty
, " BGP vpn label event debugging is on\n");
2112 if (BGP_DEBUG(flowspec
, FLOWSPEC
))
2113 vty_out(vty
, " BGP flowspec debugging is on\n");
2114 if (BGP_DEBUG(labelpool
, LABELPOOL
))
2115 vty_out(vty
, " BGP labelpool debugging is on\n");
2117 if (BGP_DEBUG(pbr
, PBR
))
2118 vty_out(vty
, " BGP policy based routing debugging is on\n");
2119 if (BGP_DEBUG(pbr
, PBR_ERROR
))
2120 vty_out(vty
, " BGP policy based routing error debugging is on\n");
2126 static int bgp_config_write_debug(struct vty
*vty
)
2130 if (CONF_BGP_DEBUG(as4
, AS4
)) {
2131 vty_out(vty
, "debug bgp as4\n");
2135 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
2136 vty_out(vty
, "debug bgp as4 segment\n");
2140 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
2141 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
2142 bgp_debug_bestpath_prefixes
);
2145 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
2146 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
2147 bgp_debug_keepalive_peers
);
2150 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
2151 write
+= bgp_debug_list_conf_print(
2152 vty
, "debug bgp neighbor-events",
2153 bgp_debug_neighbor_events_peers
);
2156 if (CONF_BGP_DEBUG(nht
, NHT
)) {
2157 vty_out(vty
, "debug bgp nht\n");
2161 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
2162 vty_out(vty
, "debug bgp update-groups\n");
2166 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2167 write
+= bgp_debug_list_conf_print(vty
,
2168 "debug bgp updates prefix",
2169 bgp_debug_update_prefixes
);
2172 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
2173 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
2174 bgp_debug_update_in_peers
);
2177 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
2178 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
2179 bgp_debug_update_out_peers
);
2182 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
2183 if (!bgp_debug_zebra_prefixes
2184 || list_isempty(bgp_debug_zebra_prefixes
)) {
2185 vty_out(vty
, "debug bgp zebra\n");
2188 write
+= bgp_debug_list_conf_print(
2189 vty
, "debug bgp zebra prefix",
2190 bgp_debug_zebra_prefixes
);
2194 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
2195 vty_out(vty
, "debug bgp allow-martians\n");
2199 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
)) {
2200 vty_out(vty
, "debug bgp vpn leak-from-vrf\n");
2203 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
)) {
2204 vty_out(vty
, "debug bgp vpn leak-to-vrf\n");
2207 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
)) {
2208 vty_out(vty
, "debug bgp vpn rmap-event\n");
2211 if (CONF_BGP_DEBUG(vpn
, VPN_LEAK_LABEL
)) {
2212 vty_out(vty
, "debug bgp vpn label\n");
2215 if (CONF_BGP_DEBUG(flowspec
, FLOWSPEC
)) {
2216 vty_out(vty
, "debug bgp flowspec\n");
2219 if (CONF_BGP_DEBUG(labelpool
, LABELPOOL
)) {
2220 vty_out(vty
, "debug bgp labelpool\n");
2224 if (CONF_BGP_DEBUG(pbr
, PBR
)) {
2225 vty_out(vty
, "debug bgp pbr\n");
2228 if (CONF_BGP_DEBUG(pbr
, PBR_ERROR
)) {
2229 vty_out(vty
, "debug bgp pbr error\n");
2235 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
2237 void bgp_debug_init(void)
2239 install_node(&debug_node
, bgp_config_write_debug
);
2241 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
2243 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
2244 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
2245 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
2246 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
2248 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
2249 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
2250 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
2251 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
2252 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
2253 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
2254 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
2255 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
2256 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
2257 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
2258 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
2259 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
2260 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
2261 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
2262 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2263 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
2265 /* debug bgp updates (in|out) */
2266 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
2267 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
2268 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
2269 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
2271 /* debug bgp updates (in|out) A.B.C.D */
2272 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
2273 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
2274 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2275 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
2277 /* debug bgp updates prefix A.B.C.D/M */
2278 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
2279 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
2280 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
2281 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
2282 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2283 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_afi_safi_cmd
);
2284 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2285 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_afi_safi_cmd
);
2287 /* debug bgp zebra prefix A.B.C.D/M */
2288 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
2289 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
2290 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2291 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
2293 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
2294 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
2295 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
2296 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
2298 /* debug bgp neighbor-events A.B.C.D */
2299 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2300 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
2301 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2302 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
2304 /* debug bgp keepalive A.B.C.D */
2305 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
2306 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
2307 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2308 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
2310 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2311 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
2312 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
2313 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
2314 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
2315 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
2316 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
2317 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
2318 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
2319 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
2320 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
2321 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
2322 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
2323 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
2324 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
2325 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
2326 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
2327 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2328 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
2330 install_element(ENABLE_NODE
, &debug_bgp_vpn_cmd
);
2331 install_element(CONFIG_NODE
, &debug_bgp_vpn_cmd
);
2332 install_element(ENABLE_NODE
, &no_debug_bgp_vpn_cmd
);
2333 install_element(CONFIG_NODE
, &no_debug_bgp_vpn_cmd
);
2335 install_element(ENABLE_NODE
, &debug_bgp_labelpool_cmd
);
2336 install_element(CONFIG_NODE
, &debug_bgp_labelpool_cmd
);
2337 install_element(ENABLE_NODE
, &no_debug_bgp_labelpool_cmd
);
2338 install_element(CONFIG_NODE
, &no_debug_bgp_labelpool_cmd
);
2341 install_element(ENABLE_NODE
, &debug_bgp_pbr_cmd
);
2342 install_element(CONFIG_NODE
, &debug_bgp_pbr_cmd
);
2343 install_element(ENABLE_NODE
, &no_debug_bgp_pbr_cmd
);
2344 install_element(CONFIG_NODE
, &no_debug_bgp_pbr_cmd
);
2348 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
2349 * for BGP_DEBUG_TYPE
2351 static int bgp_debug_per_prefix(struct prefix
*p
,
2352 unsigned long term_bgp_debug_type
,
2353 unsigned int BGP_DEBUG_TYPE
,
2354 struct list
*per_prefix_list
)
2356 struct bgp_debug_filter
*filter
;
2357 struct listnode
*node
, *nnode
;
2359 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2360 /* We are debugging all prefixes so return true */
2361 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2368 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
2370 if (filter
->p
->prefixlen
== p
->prefixlen
2371 && prefix_match(filter
->p
, p
))
2381 /* Return true if this peer is on the per_peer_list of peers to debug
2382 * for BGP_DEBUG_TYPE
2384 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2385 unsigned int BGP_DEBUG_TYPE
,
2386 struct list
*per_peer_list
)
2388 struct bgp_debug_filter
*filter
;
2389 struct listnode
*node
, *nnode
;
2391 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
2392 /* We are debugging all peers so return true */
2393 if (!per_peer_list
|| list_isempty(per_peer_list
))
2400 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
2402 if (strcmp(filter
->host
, host
) == 0)
2412 int bgp_debug_neighbor_events(struct peer
*peer
)
2419 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
2420 BGP_DEBUG_NEIGHBOR_EVENTS
,
2421 bgp_debug_neighbor_events_peers
);
2424 int bgp_debug_keepalive(struct peer
*peer
)
2431 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
2432 BGP_DEBUG_KEEPALIVE
,
2433 bgp_debug_keepalive_peers
);
2436 int bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
2437 struct update_group
*updgrp
, unsigned int inbound
)
2445 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2446 BGP_DEBUG_UPDATE_IN
,
2447 bgp_debug_update_in_peers
))
2453 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2454 BGP_DEBUG_UPDATE_OUT
,
2455 bgp_debug_update_out_peers
))
2458 /* Check if update debugging implicitly enabled for the group.
2460 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2465 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2466 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2467 BGP_DEBUG_UPDATE_PREFIX
,
2468 bgp_debug_update_prefixes
))
2475 int bgp_debug_bestpath(struct prefix
*p
)
2477 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2478 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
2480 bgp_debug_bestpath_prefixes
))
2487 int bgp_debug_zebra(struct prefix
*p
)
2489 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2490 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2492 bgp_debug_zebra_prefixes
))
2499 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2500 struct prefix_rd
*prd
,
2501 union prefixconstptr pu
,
2502 mpls_label_t
*label
, uint32_t num_labels
,
2503 int addpath_valid
, uint32_t addpath_id
,
2504 char *str
, int size
)
2506 char rd_buf
[RD_ADDRSTRLEN
];
2507 char pfx_buf
[PREFIX_STRLEN
];
2509 /* ' with addpath ID ' 17
2510 * max strlen of uint32 + 10
2511 * +/- (just in case) + 1
2512 * null terminator + 1
2513 * ============================ 29 */
2514 char pathid_buf
[30];
2516 if (size
< BGP_PRD_PATH_STRLEN
)
2519 /* Note: Path-id is created by default, but only included in update
2521 pathid_buf
[0] = '\0';
2523 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2527 if (bgp_labeled_safi(safi
) && num_labels
) {
2529 if (safi
== SAFI_EVPN
) {
2532 bgp_evpn_label2str(label
, num_labels
, tag_buf2
, 20);
2533 sprintf(tag_buf
, " label %s", tag_buf2
);
2535 uint32_t label_value
;
2537 label_value
= decode_label(label
);
2538 sprintf(tag_buf
, " label %u", label_value
);
2543 snprintf(str
, size
, "RD %s %s%s%s %s %s",
2544 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2545 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2546 pathid_buf
, afi2str(afi
), safi2str(safi
));
2547 else if (safi
== SAFI_FLOWSPEC
) {
2548 char return_string
[BGP_FLOWSPEC_NLRI_STRING_MAX
];
2549 const struct prefix_fs
*fs
= pu
.fs
;
2551 bgp_fs_nlri_get_string((unsigned char *)fs
->prefix
.ptr
,
2552 fs
->prefix
.prefixlen
,
2554 NLRI_STRING_FORMAT_DEBUG
, NULL
);
2555 snprintf(str
, size
, "FS %s Match{%s}", afi2str(afi
),
2558 snprintf(str
, size
, "%s%s%s %s %s",
2559 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2560 pathid_buf
, afi2str(afi
), safi2str(safi
));