]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_debug.c
bgpd: Allow v6 LL peers to work when connected to as well
[mirror_frr.git] / bgpd / bgp_debug.c
CommitLineData
718e3744 1/* BGP-4, BGP-4+ packet debug routine
896014f4
DL
2 * Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
19 */
718e3744 20
21#include <zebra.h>
22
5e4fa164 23#include <lib/version.h>
259f4236 24#include "lib/bfd.h"
23d0a753 25#include "lib/printfrr.h"
718e3744 26#include "prefix.h"
27#include "linklist.h"
28#include "stream.h"
29#include "command.h"
718e3744 30#include "log.h"
31#include "sockunion.h"
16286195 32#include "memory.h"
3f9c7369 33#include "queue.h"
039f3a34 34#include "filter.h"
718e3744 35
36#include "bgpd/bgpd.h"
37#include "bgpd/bgp_aspath.h"
38#include "bgpd/bgp_route.h"
39#include "bgpd/bgp_attr.h"
40#include "bgpd/bgp_debug.h"
41#include "bgpd/bgp_community.h"
07b24afe 42#include "bgpd/bgp_lcommunity.h"
3f9c7369 43#include "bgpd/bgp_updgrp.h"
906ad49b 44#include "bgpd/bgp_mplsvpn.h"
a4638609 45#include "bgpd/bgp_ecommunity.h"
b16031a2 46#include "bgpd/bgp_label.h"
47#include "bgpd/bgp_evpn.h"
81cf0de5 48#include "bgpd/bgp_evpn_private.h"
377e3565 49#include "bgpd/bgp_evpn_vty.h"
81cf0de5 50#include "bgpd/bgp_vty.h"
268e1b9b 51#include "bgpd/bgp_flowspec.h"
718e3744 52
0b2aa3a0 53unsigned long conf_bgp_debug_as4;
16286195 54unsigned long conf_bgp_debug_neighbor_events;
718e3744 55unsigned long conf_bgp_debug_events;
56unsigned long conf_bgp_debug_packet;
57unsigned long conf_bgp_debug_filter;
58unsigned long conf_bgp_debug_keepalive;
59unsigned long conf_bgp_debug_update;
9fbdd100 60unsigned long conf_bgp_debug_bestpath;
a39275d7 61unsigned long conf_bgp_debug_zebra;
cebb7440 62unsigned long conf_bgp_debug_allow_martians;
fb018d25 63unsigned long conf_bgp_debug_nht;
3f9c7369 64unsigned long conf_bgp_debug_update_groups;
ddb5b488 65unsigned long conf_bgp_debug_vpn;
268e1b9b 66unsigned long conf_bgp_debug_flowspec;
955bfd98 67unsigned long conf_bgp_debug_labelpool;
1a80fc0f 68unsigned long conf_bgp_debug_pbr;
794b37d5 69unsigned long conf_bgp_debug_graceful_restart;
52653398 70unsigned long conf_bgp_debug_evpn_mh;
259f4236 71unsigned long conf_bgp_debug_bfd;
718e3744 72
0b2aa3a0 73unsigned long term_bgp_debug_as4;
16286195 74unsigned long term_bgp_debug_neighbor_events;
718e3744 75unsigned long term_bgp_debug_events;
76unsigned long term_bgp_debug_packet;
77unsigned long term_bgp_debug_filter;
78unsigned long term_bgp_debug_keepalive;
79unsigned long term_bgp_debug_update;
9fbdd100 80unsigned long term_bgp_debug_bestpath;
a39275d7 81unsigned long term_bgp_debug_zebra;
cebb7440 82unsigned long term_bgp_debug_allow_martians;
fb018d25 83unsigned long term_bgp_debug_nht;
3f9c7369 84unsigned long term_bgp_debug_update_groups;
ddb5b488 85unsigned long term_bgp_debug_vpn;
268e1b9b 86unsigned long term_bgp_debug_flowspec;
955bfd98 87unsigned long term_bgp_debug_labelpool;
1a80fc0f 88unsigned long term_bgp_debug_pbr;
794b37d5 89unsigned long term_bgp_debug_graceful_restart;
52653398 90unsigned long term_bgp_debug_evpn_mh;
259f4236 91unsigned long term_bgp_debug_bfd;
718e3744 92
16286195
DS
93struct list *bgp_debug_neighbor_events_peers = NULL;
94struct list *bgp_debug_keepalive_peers = NULL;
95struct list *bgp_debug_update_out_peers = NULL;
96struct list *bgp_debug_update_in_peers = NULL;
97struct list *bgp_debug_update_prefixes = NULL;
9fbdd100 98struct list *bgp_debug_bestpath_prefixes = NULL;
16286195
DS
99struct list *bgp_debug_zebra_prefixes = NULL;
100
718e3744 101/* messages for BGP-4 status */
d62a17ae 102const struct message bgp_status_msg[] = {{Idle, "Idle"},
103 {Connect, "Connect"},
104 {Active, "Active"},
105 {OpenSent, "OpenSent"},
106 {OpenConfirm, "OpenConfirm"},
107 {Established, "Established"},
108 {Clearing, "Clearing"},
109 {Deleted, "Deleted"},
110 {0}};
718e3744 111
112/* BGP message type string. */
2b64873d 113const char *const bgp_type_str[] = {NULL, "OPEN", "UPDATE",
d62a17ae 114 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
115 "CAPABILITY"};
718e3744 116
117/* message for BGP-4 Notify */
d62a17ae 118static const struct message bgp_notify_msg[] = {
119 {BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
120 {BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
121 {BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
122 {BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
123 {BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"},
124 {BGP_NOTIFY_CEASE, "Cease"},
9af52ccf 125 {BGP_NOTIFY_ROUTE_REFRESH_ERR, "ROUTE-REFRESH Message Error"},
d62a17ae 126 {0}};
127
128static const struct message bgp_notify_head_msg[] = {
129 {BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
130 {BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
131 {BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"},
132 {0}};
133
134static const struct message bgp_notify_open_msg[] = {
135 {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
136 {BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number"},
137 {BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
138 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
139 {BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
140 {BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
141 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
142 {BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
143 {0}};
144
145static const struct message bgp_notify_update_msg[] = {
146 {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
147 {BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
148 {BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
149 {BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
150 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
151 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
152 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
153 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
154 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
155 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
156 {BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
157 {BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
158 {0}};
159
160static const struct message bgp_notify_cease_msg[] = {
161 {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
162 {BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
163 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
164 {BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
165 {BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
166 {BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
167 {BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
168 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION,
169 "/Connection collision resolution"},
170 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
171 {0}};
172
9af52ccf 173static const struct message bgp_notify_route_refresh_msg[] = {
d62a17ae 174 {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
9af52ccf 175 {BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN, "/Invalid Message Length"},
d62a17ae 176 {0}};
718e3744 177
3893aeee
DA
178static const struct message bgp_notify_fsm_msg[] = {
179 {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC, "/Unspecific"},
180 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT,
181 "/Receive Unexpected Message in OpenSent State"},
182 {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM,
183 "/Receive Unexpected Message in OpenConfirm State"},
184 {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED,
185 "/Receive Unexpected Message in Established State"},
186 {0}};
187
718e3744 188/* Origin strings. */
2b64873d
DL
189const char *const bgp_origin_str[] = {"i", "e", "?"};
190const char *const bgp_origin_long_str[] = {"IGP", "EGP", "incomplete"};
718e3744 191
3dc339cd
DA
192static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc,
193 struct prefix *p);
16286195 194/* Given a string return a pointer the corresponding peer structure */
d62a17ae 195static struct peer *bgp_find_peer(struct vty *vty, const char *peer_str)
16286195 196{
d62a17ae 197 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
198 int ret;
199 union sockunion su;
200 struct peer *peer;
201
202 if (!bgp) {
203 return NULL;
204 }
205 ret = str2sockunion(peer_str, &su);
206
207 /* 'swpX' string */
208 if (ret < 0) {
209 peer = peer_lookup_by_conf_if(bgp, peer_str);
210
211 if (!peer)
212 peer = peer_lookup_by_hostname(bgp, peer_str);
213
214 return peer;
215 } else
216 return peer_lookup(bgp, &su);
16286195
DS
217}
218
d62a17ae 219static void bgp_debug_list_free(struct list *list)
16286195 220{
d62a17ae 221 struct bgp_debug_filter *filter;
222 struct listnode *node, *nnode;
16286195 223
d62a17ae 224 if (list)
225 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
226 listnode_delete(list, filter);
8fa77bc6
DA
227 prefix_free(&filter->p);
228 XFREE(MTYPE_BGP_DEBUG_STR, filter->host);
d62a17ae 229 XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
230 }
16286195
DS
231}
232
29a643ca
QY
233/*
234 * Print the desc along with a list of peers/prefixes this debug is
235 * enabled for
236 */
d62a17ae 237static void bgp_debug_list_print(struct vty *vty, const char *desc,
29a643ca 238 struct list *list)
d62a17ae 239{
240 struct bgp_debug_filter *filter;
241 struct listnode *node, *nnode;
d62a17ae 242
243 vty_out(vty, "%s", desc);
244
245 if (list && !list_isempty(list)) {
246 vty_out(vty, " for");
247 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
248 if (filter->host)
249 vty_out(vty, " %s", filter->host);
250
29a643ca
QY
251 if (filter->p && filter->p->family == AF_EVPN)
252 bgp_debug_print_evpn_prefix(vty, "", filter->p);
2dbe669b
DA
253 else if (filter->p)
254 vty_out(vty, " %pFX", filter->p);
d62a17ae 255 }
256 }
257
258 vty_out(vty, "\n");
16286195
DS
259}
260
29a643ca
QY
261/*
262 * Print the command to enable the debug for each peer/prefix this debug is
91ba2c8b
DS
263 * enabled for
264 */
d62a17ae 265static int bgp_debug_list_conf_print(struct vty *vty, const char *desc,
29a643ca 266 struct list *list)
d62a17ae 267{
268 struct bgp_debug_filter *filter;
269 struct listnode *node, *nnode;
d62a17ae 270 int write = 0;
271
272 if (list && !list_isempty(list)) {
273 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
274 if (filter->host) {
275 vty_out(vty, "%s %s\n", desc, filter->host);
276 write++;
277 }
278
29a643ca
QY
279 if (filter->p && filter->p->family == AF_EVPN) {
280 bgp_debug_print_evpn_prefix(vty, desc,
281 filter->p);
282 write++;
283 } else if (filter->p) {
2dbe669b 284 vty_out(vty, "%s %pFX\n", desc, filter->p);
29a643ca 285 write++;
d62a17ae 286 }
287 }
288 }
289
290 if (!write) {
291 vty_out(vty, "%s\n", desc);
292 write++;
293 }
294
295 return write;
91ba2c8b
DS
296}
297
d62a17ae 298static void bgp_debug_list_add_entry(struct list *list, const char *host,
299 const struct prefix *p)
16286195 300{
d62a17ae 301 struct bgp_debug_filter *filter;
302
303 filter = XCALLOC(MTYPE_BGP_DEBUG_FILTER,
304 sizeof(struct bgp_debug_filter));
305
306 if (host) {
307 filter->host = XSTRDUP(MTYPE_BGP_DEBUG_STR, host);
308 filter->p = NULL;
309 } else if (p) {
310 filter->host = NULL;
311 filter->p = prefix_new();
312 prefix_copy(filter->p, p);
313 }
314
315 listnode_add(list, filter);
16286195
DS
316}
317
3dc339cd
DA
318static bool bgp_debug_list_remove_entry(struct list *list, const char *host,
319 struct prefix *p)
d62a17ae 320{
321 struct bgp_debug_filter *filter;
322 struct listnode *node, *nnode;
323
324 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
325 if (host && strcmp(filter->host, host) == 0) {
326 listnode_delete(list, filter);
327 XFREE(MTYPE_BGP_DEBUG_STR, filter->host);
328 XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
3dc339cd 329 return true;
d62a17ae 330 } else if (p && filter->p->prefixlen == p->prefixlen
331 && prefix_match(filter->p, p)) {
332 listnode_delete(list, filter);
63265b5c 333 prefix_free(&filter->p);
d62a17ae 334 XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
3dc339cd 335 return true;
d62a17ae 336 }
337 }
338
3dc339cd 339 return false;
16286195
DS
340}
341
3dc339cd
DA
342static bool bgp_debug_list_has_entry(struct list *list, const char *host,
343 const struct prefix *p)
d62a17ae 344{
345 struct bgp_debug_filter *filter;
346 struct listnode *node, *nnode;
347
348 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
349 if (host) {
350 if (strcmp(filter->host, host) == 0) {
3dc339cd 351 return true;
d62a17ae 352 }
353 } else if (p) {
354 if (filter->p->prefixlen == p->prefixlen
355 && prefix_match(filter->p, p)) {
3dc339cd 356 return true;
d62a17ae 357 }
358 }
359 }
360
3dc339cd 361 return false;
16286195
DS
362}
363
3dc339cd 364bool bgp_debug_peer_updout_enabled(char *host)
3f9c7369 365{
d62a17ae 366 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host,
367 NULL));
3f9c7369
DS
368}
369
718e3744 370/* Dump attribute. */
3dc339cd 371bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
718e3744 372{
d62a17ae 373 char addrbuf[BUFSIZ];
718e3744 374
d62a17ae 375 if (!attr)
3dc339cd 376 return false;
d62a17ae 377
8ba71050
NS
378 buf[0] = '\0';
379
d62a17ae 380 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)))
23d0a753 381 snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);
d62a17ae 382
383 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
384 snprintf(buf + strlen(buf), size - strlen(buf), ", origin %s",
385 bgp_origin_str[attr->origin]);
386
387 /* Add MP case. */
388 if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL
389 || attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
390 snprintf(buf + strlen(buf), size - strlen(buf),
391 ", mp_nexthop %s",
392 inet_ntop(AF_INET6, &attr->mp_nexthop_global, addrbuf,
393 BUFSIZ));
394
395 if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
396 snprintf(buf + strlen(buf), size - strlen(buf), "(%s)",
397 inet_ntop(AF_INET6, &attr->mp_nexthop_local, addrbuf,
398 BUFSIZ));
399
400 if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4)
23d0a753 401 snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);
d62a17ae 402
403 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
404 snprintf(buf + strlen(buf), size - strlen(buf),
405 ", localpref %u", attr->local_pref);
406
407 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)))
408 snprintf(buf + strlen(buf), size - strlen(buf), ", metric %u",
409 attr->med);
410
411 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)))
412 snprintf(buf + strlen(buf), size - strlen(buf),
a4d82a8a
PZ
413 ", community %s",
414 community_str(attr->community, false));
d62a17ae 415
07b24afe
DA
416 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)))
417 snprintf(buf + strlen(buf), size - strlen(buf),
418 ", large-community %s",
419 lcommunity_str(attr->lcommunity, false));
420
d62a17ae 421 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
422 snprintf(buf + strlen(buf), size - strlen(buf),
423 ", extcommunity %s", ecommunity_str(attr->ecommunity));
424
425 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)))
426 snprintf(buf + strlen(buf), size - strlen(buf),
427 ", atomic-aggregate");
428
429 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)))
23d0a753
DA
430 snprintfrr(buf + strlen(buf), size - strlen(buf),
431 ", aggregated by %u %pI4", attr->aggregator_as,
432 &attr->aggregator_addr);
d62a17ae 433
434 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))
23d0a753
DA
435 snprintfrr(buf + strlen(buf), size - strlen(buf),
436 ", originator %pI4", &attr->originator_id);
d62a17ae 437
438 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) {
779fee93 439 struct cluster_list *cluster;
d62a17ae 440 int i;
441
442 snprintf(buf + strlen(buf), size - strlen(buf),
443 ", clusterlist");
779fee93
DS
444
445 cluster = bgp_attr_get_cluster(attr);
446 for (i = 0; i < cluster->length / 4; i++)
23d0a753 447 snprintfrr(buf + strlen(buf), size - strlen(buf),
779fee93 448 " %pI4", &cluster->list[i]);
d62a17ae 449 }
450
7fd077aa 451 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)))
052ea98b 452 snprintf(buf + strlen(buf), size - strlen(buf),
2a3f51cf 453 ", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr));
7fd077aa 454
d62a17ae 455 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
456 snprintf(buf + strlen(buf), size - strlen(buf), ", path %s",
457 aspath_print(attr->aspath));
458
459 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))) {
460 if (attr->label_index != BGP_INVALID_LABEL_INDEX)
461 snprintf(buf + strlen(buf), size - strlen(buf),
462 ", label-index %u", attr->label_index);
463 }
464
465 if (strlen(buf) > 1)
3dc339cd 466 return true;
d62a17ae 467 else
3dc339cd 468 return false;
3a8c7ba1 469}
718e3744 470
d62a17ae 471const char *bgp_notify_code_str(char code)
3a8c7ba1 472{
d62a17ae 473 return lookup_msg(bgp_notify_msg, code, "Unrecognized Error Code");
474}
718e3744 475
d62a17ae 476const char *bgp_notify_subcode_str(char code, char subcode)
477{
478
479 switch (code) {
480 case BGP_NOTIFY_HEADER_ERR:
481 return lookup_msg(bgp_notify_head_msg, subcode,
482 "Unrecognized Error Subcode");
483 case BGP_NOTIFY_OPEN_ERR:
484 return lookup_msg(bgp_notify_open_msg, subcode,
485 "Unrecognized Error Subcode");
486 case BGP_NOTIFY_UPDATE_ERR:
487 return lookup_msg(bgp_notify_update_msg, subcode,
488 "Unrecognized Error Subcode");
489 case BGP_NOTIFY_HOLD_ERR:
490 break;
491 case BGP_NOTIFY_FSM_ERR:
3893aeee
DA
492 return lookup_msg(bgp_notify_fsm_msg, subcode,
493 "Unrecognized Error Subcode");
d62a17ae 494 case BGP_NOTIFY_CEASE:
495 return lookup_msg(bgp_notify_cease_msg, subcode,
496 "Unrecognized Error Subcode");
9af52ccf
DA
497 case BGP_NOTIFY_ROUTE_REFRESH_ERR:
498 return lookup_msg(bgp_notify_route_refresh_msg, subcode,
d62a17ae 499 "Unrecognized Error Subcode");
500 }
501 return "";
3a8c7ba1
DW
502}
503
38de8d02 504/* extract notify admin reason if correctly present */
d7c0a89a 505const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data,
d62a17ae 506 size_t datalen)
38de8d02 507{
d62a17ae 508 if (!data || datalen < 1)
509 return NULL;
38de8d02 510
d7c0a89a 511 uint8_t len = data[0];
d62a17ae 512 if (len > 128 || len > datalen - 1)
513 return NULL;
38de8d02 514
d62a17ae 515 return zlog_sanitize(buf, bufsz, data + 1, len);
38de8d02
DL
516}
517
3a8c7ba1 518/* dump notify packet */
d62a17ae 519void bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
520 const char *direct)
521{
522 const char *subcode_str;
523 const char *code_str;
524 const char *msg_str = NULL;
525 char msg_buf[1024];
526
527 if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)
892fedb6 528 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) {
d62a17ae 529 code_str = bgp_notify_code_str(bgp_notify->code);
530 subcode_str = bgp_notify_subcode_str(bgp_notify->code,
531 bgp_notify->subcode);
532
533 if (bgp_notify->code == BGP_NOTIFY_CEASE
534 && (bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
535 || bgp_notify->subcode
536 == BGP_NOTIFY_CEASE_ADMIN_RESET)) {
537 msg_str = bgp_notify_admin_message(
538 msg_buf, sizeof(msg_buf), bgp_notify->raw_data,
539 bgp_notify->length);
540 }
541
542 if (msg_str) {
543 zlog_info(
544 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
545 strcmp(direct, "received") == 0
546 ? "received from"
547 : "sent to",
548 peer->host, bgp_notify->code,
549 bgp_notify->subcode, code_str, subcode_str,
550 msg_str);
551 } else {
552 msg_str = bgp_notify->data ? bgp_notify->data : "";
553 zlog_info(
554 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
555 strcmp(direct, "received") == 0
556 ? "received from"
557 : "sent to",
558 peer->host, bgp_notify->code,
559 bgp_notify->subcode, code_str, subcode_str,
560 bgp_notify->length, msg_str);
561 }
562 }
718e3744 563}
6b0655a2 564
d62a17ae 565static void bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp)
3f9c7369 566{
d62a17ae 567 if (!bgp)
568 bgp = bgp_get_default();
569 update_group_walk(bgp, update_group_clear_update_dbg, NULL);
3f9c7369
DS
570}
571
3dc339cd
DA
572static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc,
573 struct prefix *p)
81cf0de5
CS
574{
575 char evpn_desc[PREFIX2STR_BUFFER + INET_ADDRSTRLEN];
576 char buf[PREFIX2STR_BUFFER];
577 char buf2[ETHER_ADDR_STRLEN];
578
579 if (p->u.prefix_evpn.route_type == BGP_EVPN_MAC_IP_ROUTE) {
580 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)p)) {
772270f3
QY
581 snprintf(
582 evpn_desc, sizeof(evpn_desc),
583 "l2vpn evpn type macip mac %s",
584 prefix_mac2str(&p->u.prefix_evpn.macip_addr.mac,
585 buf2, sizeof(buf2)));
81cf0de5
CS
586 } else {
587 uint8_t family = is_evpn_prefix_ipaddr_v4(
588 (struct prefix_evpn *)p) ?
589 AF_INET : AF_INET6;
772270f3
QY
590 snprintf(
591 evpn_desc, sizeof(evpn_desc),
592 "l2vpn evpn type macip mac %s ip %s",
593 prefix_mac2str(&p->u.prefix_evpn.macip_addr.mac,
594 buf2, sizeof(buf2)),
595 inet_ntop(
596 family,
81cf0de5
CS
597 &p->u.prefix_evpn.macip_addr.ip.ip.addr,
598 buf, PREFIX2STR_BUFFER));
599 }
600 } else if (p->u.prefix_evpn.route_type == BGP_EVPN_IMET_ROUTE) {
23d0a753
DA
601 snprintfrr(evpn_desc, sizeof(evpn_desc),
602 "l2vpn evpn type multicast ip %pI4",
603 &p->u.prefix_evpn.imet_addr.ip.ipaddr_v4);
81cf0de5
CS
604 } else if (p->u.prefix_evpn.route_type == BGP_EVPN_IP_PREFIX_ROUTE) {
605 uint8_t family = is_evpn_prefix_ipaddr_v4(
606 (struct prefix_evpn *)p) ? AF_INET
607 : AF_INET6;
772270f3
QY
608 snprintf(evpn_desc, sizeof(evpn_desc),
609 "l2vpn evpn type prefix ip %s/%d",
610 inet_ntop(family,
611 &p->u.prefix_evpn.prefix_addr.ip.ip.addr,
612 buf, PREFIX2STR_BUFFER),
613 p->u.prefix_evpn.prefix_addr.ip_prefix_length);
81cf0de5
CS
614 }
615
616 vty_out(vty, "%s %s\n", desc, evpn_desc);
81cf0de5
CS
617}
618
619static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv,
620 int argc, struct prefix **argv_pp)
621{
622 struct prefix *argv_p;
623 struct ethaddr mac;
624 struct ipaddr ip;
15dc08a6 625 int evpn_type = 0;
81cf0de5
CS
626 int mac_idx = 0;
627 int ip_idx = 0;
628
629 argv_p = *argv_pp;
630
15dc08a6
SW
631 if (bgp_evpn_cli_parse_type(&evpn_type, argv, argc) < 0)
632 return CMD_WARNING;
81cf0de5
CS
633
634 if (evpn_type == BGP_EVPN_MAC_IP_ROUTE) {
635 memset(&ip, 0, sizeof(struct ipaddr));
377e3565 636
81cf0de5 637 argv_find(argv, argc, "mac", &mac_idx);
4d840569 638 (void)prefix_str2mac(argv[mac_idx + 1]->arg, &mac);
377e3565
QY
639
640 argv_find(argv, argc, "ip", &ip_idx);
641 str2ipaddr(argv[ip_idx + 1]->arg, &ip);
81cf0de5
CS
642
643 build_evpn_type2_prefix((struct prefix_evpn *)argv_p,
644 &mac, &ip);
645 } else if (evpn_type == BGP_EVPN_IMET_ROUTE) {
646 memset(&ip, 0, sizeof(struct ipaddr));
377e3565
QY
647
648 argv_find(argv, argc, "ip", &ip_idx);
649 str2ipaddr(argv[ip_idx + 1]->arg, &ip);
650
81cf0de5
CS
651 build_evpn_type3_prefix((struct prefix_evpn *)argv_p,
652 ip.ipaddr_v4);
653 } else if (evpn_type == BGP_EVPN_IP_PREFIX_ROUTE) {
654 struct prefix ip_prefix;
655
656 memset(&ip_prefix, 0, sizeof(struct prefix));
657 if (argv_find(argv, argc, "ip", &ip_idx)) {
658 (void)str2prefix(argv[ip_idx + 1]->arg, &ip_prefix);
659 apply_mask(&ip_prefix);
660 }
661 build_type5_prefix_from_ip_prefix(
662 (struct prefix_evpn *)argv_p,
663 &ip_prefix);
664 }
665
666 return CMD_SUCCESS;
667}
3f9c7369 668
718e3744 669/* Debug option setting interface. */
670unsigned long bgp_debug_option = 0;
671
d62a17ae 672int debug(unsigned int option)
718e3744 673{
d62a17ae 674 return bgp_debug_option & option;
718e3744 675}
676
0b2aa3a0
PJ
677DEFUN (debug_bgp_as4,
678 debug_bgp_as4_cmd,
679 "debug bgp as4",
680 DEBUG_STR
681 BGP_STR
682 "BGP AS4 actions\n")
683{
d62a17ae 684 if (vty->node == CONFIG_NODE)
685 DEBUG_ON(as4, AS4);
686 else {
687 TERM_DEBUG_ON(as4, AS4);
688 vty_out(vty, "BGP as4 debugging is on\n");
689 }
690 return CMD_SUCCESS;
0b2aa3a0
PJ
691}
692
693DEFUN (no_debug_bgp_as4,
694 no_debug_bgp_as4_cmd,
695 "no debug bgp as4",
696 NO_STR
697 DEBUG_STR
698 BGP_STR
699 "BGP AS4 actions\n")
700{
d62a17ae 701 if (vty->node == CONFIG_NODE)
702 DEBUG_OFF(as4, AS4);
703 else {
704 TERM_DEBUG_OFF(as4, AS4);
705 vty_out(vty, "BGP as4 debugging is off\n");
706 }
707 return CMD_SUCCESS;
0b2aa3a0
PJ
708}
709
0b2aa3a0
PJ
710DEFUN (debug_bgp_as4_segment,
711 debug_bgp_as4_segment_cmd,
712 "debug bgp as4 segment",
713 DEBUG_STR
714 BGP_STR
6e22b901 715 "BGP AS4 actions\n"
0b2aa3a0
PJ
716 "BGP AS4 aspath segment handling\n")
717{
d62a17ae 718 if (vty->node == CONFIG_NODE)
719 DEBUG_ON(as4, AS4_SEGMENT);
720 else {
721 TERM_DEBUG_ON(as4, AS4_SEGMENT);
722 vty_out(vty, "BGP as4 segment debugging is on\n");
723 }
724 return CMD_SUCCESS;
0b2aa3a0
PJ
725}
726
727DEFUN (no_debug_bgp_as4_segment,
728 no_debug_bgp_as4_segment_cmd,
729 "no debug bgp as4 segment",
730 NO_STR
731 DEBUG_STR
732 BGP_STR
6e22b901 733 "BGP AS4 actions\n"
0b2aa3a0
PJ
734 "BGP AS4 aspath segment handling\n")
735{
d62a17ae 736 if (vty->node == CONFIG_NODE)
737 DEBUG_OFF(as4, AS4_SEGMENT);
738 else {
739 TERM_DEBUG_OFF(as4, AS4_SEGMENT);
740 vty_out(vty, "BGP as4 segment debugging is off\n");
741 }
742 return CMD_SUCCESS;
0b2aa3a0
PJ
743}
744
16286195
DS
745/* debug bgp neighbor_events */
746DEFUN (debug_bgp_neighbor_events,
747 debug_bgp_neighbor_events_cmd,
748 "debug bgp neighbor-events",
718e3744 749 DEBUG_STR
750 BGP_STR
16286195 751 "BGP Neighbor Events\n")
718e3744 752{
d62a17ae 753 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
754
755 if (vty->node == CONFIG_NODE)
756 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
757 else {
758 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
759 vty_out(vty, "BGP neighbor-events debugging is on\n");
760 }
761 return CMD_SUCCESS;
718e3744 762}
763
16286195
DS
764DEFUN (debug_bgp_neighbor_events_peer,
765 debug_bgp_neighbor_events_peer_cmd,
6147e2c6 766 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
718e3744 767 DEBUG_STR
768 BGP_STR
16286195
DS
769 "BGP Neighbor Events\n"
770 "BGP neighbor IP address to debug\n"
771 "BGP IPv6 neighbor to debug\n"
772 "BGP neighbor on interface to debug\n")
718e3744 773{
d62a17ae 774 int idx_peer = 3;
775 const char *host = argv[idx_peer]->arg;
776
777 if (!bgp_debug_neighbor_events_peers)
778 bgp_debug_neighbor_events_peers = list_new();
779
780 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host,
781 NULL)) {
782 vty_out(vty,
783 "BGP neighbor-events debugging is already enabled for %s\n",
784 host);
785 return CMD_SUCCESS;
786 }
787
788 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL);
789
790 if (vty->node == CONFIG_NODE)
791 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
792 else {
793 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
794 vty_out(vty, "BGP neighbor-events debugging is on for %s\n",
795 host);
796 }
797 return CMD_SUCCESS;
718e3744 798}
799
16286195
DS
800DEFUN (no_debug_bgp_neighbor_events,
801 no_debug_bgp_neighbor_events_cmd,
802 "no debug bgp neighbor-events",
803 NO_STR
718e3744 804 DEBUG_STR
805 BGP_STR
16286195 806 "Neighbor Events\n")
718e3744 807{
d62a17ae 808 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
809
810 if (vty->node == CONFIG_NODE)
811 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
812 else {
813 TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
814 vty_out(vty, "BGP neighbor-events debugging is off\n");
815 }
816 return CMD_SUCCESS;
718e3744 817}
818
16286195
DS
819DEFUN (no_debug_bgp_neighbor_events_peer,
820 no_debug_bgp_neighbor_events_peer_cmd,
6147e2c6 821 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
718e3744 822 NO_STR
823 DEBUG_STR
824 BGP_STR
16286195
DS
825 "Neighbor Events\n"
826 "BGP neighbor IP address to debug\n"
827 "BGP IPv6 neighbor to debug\n"
828 "BGP neighbor on interface to debug\n")
718e3744 829{
d62a17ae 830 int idx_peer = 4;
831 int found_peer = 0;
832 const char *host = argv[idx_peer]->arg;
833
834 if (bgp_debug_neighbor_events_peers
835 && !list_isempty(bgp_debug_neighbor_events_peers)) {
836 found_peer = bgp_debug_list_remove_entry(
837 bgp_debug_neighbor_events_peers, host, NULL);
838
839 if (list_isempty(bgp_debug_neighbor_events_peers)) {
840 if (vty->node == CONFIG_NODE)
841 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
842 else
843 TERM_DEBUG_OFF(neighbor_events,
844 NEIGHBOR_EVENTS);
845 }
846 }
847
848 if (found_peer)
849 vty_out(vty, "BGP neighbor-events debugging is off for %s\n",
850 host);
851 else
852 vty_out(vty,
853 "BGP neighbor-events debugging was not enabled for %s\n",
854 host);
855
856 return CMD_SUCCESS;
718e3744 857}
858
16286195 859/* debug bgp nht */
fb018d25
DS
860DEFUN (debug_bgp_nht,
861 debug_bgp_nht_cmd,
862 "debug bgp nht",
863 DEBUG_STR
864 BGP_STR
865 "BGP nexthop tracking events\n")
866{
d62a17ae 867 if (vty->node == CONFIG_NODE)
868 DEBUG_ON(nht, NHT);
869 else {
870 TERM_DEBUG_ON(nht, NHT);
871 vty_out(vty, "BGP nexthop tracking debugging is on\n");
872 }
873 return CMD_SUCCESS;
fb018d25
DS
874}
875
876DEFUN (no_debug_bgp_nht,
877 no_debug_bgp_nht_cmd,
878 "no debug bgp nht",
879 NO_STR
880 DEBUG_STR
881 BGP_STR
882 "BGP nexthop tracking events\n")
883{
d62a17ae 884 if (vty->node == CONFIG_NODE)
885 DEBUG_OFF(nht, NHT);
886 else {
887 TERM_DEBUG_OFF(nht, NHT);
888 vty_out(vty, "BGP nexthop tracking debugging is off\n");
889 }
890 return CMD_SUCCESS;
fb018d25
DS
891}
892
16286195
DS
893/* debug bgp keepalives */
894DEFUN (debug_bgp_keepalive,
895 debug_bgp_keepalive_cmd,
896 "debug bgp keepalives",
718e3744 897 DEBUG_STR
898 BGP_STR
16286195 899 "BGP keepalives\n")
718e3744 900{
d62a17ae 901 bgp_debug_list_free(bgp_debug_keepalive_peers);
902
903 if (vty->node == CONFIG_NODE)
904 DEBUG_ON(keepalive, KEEPALIVE);
905 else {
906 TERM_DEBUG_ON(keepalive, KEEPALIVE);
907 vty_out(vty, "BGP keepalives debugging is on\n");
908 }
909 return CMD_SUCCESS;
718e3744 910}
911
16286195
DS
912DEFUN (debug_bgp_keepalive_peer,
913 debug_bgp_keepalive_peer_cmd,
6147e2c6 914 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
718e3744 915 DEBUG_STR
916 BGP_STR
bc6bc7a8
DA
917 "BGP keepalives\n"
918 "BGP IPv4 neighbor to debug\n"
16286195
DS
919 "BGP IPv6 neighbor to debug\n"
920 "BGP neighbor on interface to debug\n")
718e3744 921{
d62a17ae 922 int idx_peer = 3;
923 const char *host = argv[idx_peer]->arg;
924
925 if (!bgp_debug_keepalive_peers)
926 bgp_debug_keepalive_peers = list_new();
927
928 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL)) {
929 vty_out(vty,
930 "BGP keepalive debugging is already enabled for %s\n",
931 host);
932 return CMD_SUCCESS;
933 }
934
935 bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL);
936
937 if (vty->node == CONFIG_NODE)
938 DEBUG_ON(keepalive, KEEPALIVE);
939 else {
940 TERM_DEBUG_ON(keepalive, KEEPALIVE);
941 vty_out(vty, "BGP keepalives debugging is on for %s\n", host);
942 }
943 return CMD_SUCCESS;
718e3744 944}
945
946DEFUN (no_debug_bgp_keepalive,
947 no_debug_bgp_keepalive_cmd,
948 "no debug bgp keepalives",
949 NO_STR
950 DEBUG_STR
951 BGP_STR
952 "BGP keepalives\n")
953{
d62a17ae 954 bgp_debug_list_free(bgp_debug_keepalive_peers);
955
956 if (vty->node == CONFIG_NODE)
957 DEBUG_OFF(keepalive, KEEPALIVE);
958 else {
959 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
960 vty_out(vty, "BGP keepalives debugging is off\n");
961 }
962 return CMD_SUCCESS;
718e3744 963}
964
16286195
DS
965DEFUN (no_debug_bgp_keepalive_peer,
966 no_debug_bgp_keepalive_peer_cmd,
6147e2c6 967 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
16286195
DS
968 NO_STR
969 DEBUG_STR
718e3744 970 BGP_STR
16286195
DS
971 "BGP keepalives\n"
972 "BGP neighbor IP address to debug\n"
973 "BGP IPv6 neighbor to debug\n"
974 "BGP neighbor on interface to debug\n")
975{
d62a17ae 976 int idx_peer = 4;
977 int found_peer = 0;
978 const char *host = argv[idx_peer]->arg;
979
980 if (bgp_debug_keepalive_peers
981 && !list_isempty(bgp_debug_keepalive_peers)) {
982 found_peer = bgp_debug_list_remove_entry(
983 bgp_debug_keepalive_peers, host, NULL);
984
985 if (list_isempty(bgp_debug_keepalive_peers)) {
986 if (vty->node == CONFIG_NODE)
987 DEBUG_OFF(keepalive, KEEPALIVE);
988 else
989 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
990 }
991 }
992
993 if (found_peer)
994 vty_out(vty, "BGP keepalives debugging is off for %s\n", host);
995 else
996 vty_out(vty,
997 "BGP keepalives debugging was not enabled for %s\n",
998 host);
999
1000 return CMD_SUCCESS;
16286195
DS
1001}
1002
9fbdd100 1003/* debug bgp bestpath */
ffd71765 1004DEFUN (debug_bgp_bestpath_prefix,
9fbdd100 1005 debug_bgp_bestpath_prefix_cmd,
ffd71765 1006 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
9fbdd100
DS
1007 DEBUG_STR
1008 BGP_STR
1009 "BGP bestpath\n"
0c7b1b01
QY
1010 "IPv4 prefix\n"
1011 "IPv6 prefix\n")
9fbdd100 1012{
0be4b77c
DW
1013 struct prefix *argv_p;
1014 int idx_ipv4_ipv6_prefixlen = 3;
1015
1016 argv_p = prefix_new();
ffd71765 1017 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c
DW
1018 apply_mask(argv_p);
1019
d62a17ae 1020 if (!bgp_debug_bestpath_prefixes)
1021 bgp_debug_bestpath_prefixes = list_new();
1022
1023 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL,
ffd71765 1024 argv_p)) {
d62a17ae 1025 vty_out(vty,
1026 "BGP bestpath debugging is already enabled for %s\n",
ffd71765 1027 argv[idx_ipv4_ipv6_prefixlen]->arg);
d62a17ae 1028 return CMD_SUCCESS;
1029 }
1030
ffd71765 1031 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, argv_p);
d62a17ae 1032
1033 if (vty->node == CONFIG_NODE) {
1034 DEBUG_ON(bestpath, BESTPATH);
1035 } else {
1036 TERM_DEBUG_ON(bestpath, BESTPATH);
1037 vty_out(vty, "BGP bestpath debugging is on for %s\n",
ffd71765 1038 argv[idx_ipv4_ipv6_prefixlen]->arg);
d62a17ae 1039 }
1040
1041 return CMD_SUCCESS;
9fbdd100
DS
1042}
1043
1044DEFUN (no_debug_bgp_bestpath_prefix,
1045 no_debug_bgp_bestpath_prefix_cmd,
6147e2c6 1046 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
9fbdd100
DS
1047 NO_STR
1048 DEBUG_STR
1049 BGP_STR
1050 "BGP bestpath\n"
0c7b1b01
QY
1051 "IPv4 prefix\n"
1052 "IPv6 prefix\n")
9fbdd100 1053{
d62a17ae 1054 int idx_ipv4_ipv6_prefixlen = 4;
1055 struct prefix *argv_p;
1056 int found_prefix = 0;
d62a17ae 1057
1058 argv_p = prefix_new();
ffd71765 1059 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1060 apply_mask(argv_p);
d62a17ae 1061
1062 if (bgp_debug_bestpath_prefixes
1063 && !list_isempty(bgp_debug_bestpath_prefixes)) {
1064 found_prefix = bgp_debug_list_remove_entry(
1065 bgp_debug_bestpath_prefixes, NULL, argv_p);
1066
1067 if (list_isempty(bgp_debug_bestpath_prefixes)) {
1068 if (vty->node == CONFIG_NODE) {
1069 DEBUG_OFF(bestpath, BESTPATH);
1070 } else {
1071 TERM_DEBUG_OFF(bestpath, BESTPATH);
1072 vty_out(vty,
1073 "BGP bestpath debugging (per prefix) is off\n");
1074 }
1075 }
1076 }
1077
1078 if (found_prefix)
1079 vty_out(vty, "BGP bestpath debugging is off for %s\n",
1080 argv[idx_ipv4_ipv6_prefixlen]->arg);
1081 else
1082 vty_out(vty, "BGP bestpath debugging was not enabled for %s\n",
1083 argv[idx_ipv4_ipv6_prefixlen]->arg);
1084
1085 return CMD_SUCCESS;
9fbdd100
DS
1086}
1087
1088DEFUN (no_debug_bgp_bestpath,
1089 no_debug_bgp_bestpath_cmd,
1090 "no debug bgp bestpath",
1091 NO_STR
1092 DEBUG_STR
1093 BGP_STR
1094 "BGP bestpath\n")
1095{
d62a17ae 1096 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
1097
1098 if (vty->node == CONFIG_NODE)
1099 DEBUG_OFF(bestpath, BESTPATH);
1100 else {
1101 TERM_DEBUG_OFF(bestpath, BESTPATH);
1102 vty_out(vty, "BGP bestpath debugging is off\n");
1103 }
1104 return CMD_SUCCESS;
9fbdd100
DS
1105}
1106
16286195 1107/* debug bgp updates */
718e3744 1108DEFUN (debug_bgp_update,
1109 debug_bgp_update_cmd,
1110 "debug bgp updates",
1111 DEBUG_STR
1112 BGP_STR
1113 "BGP updates\n")
1114{
d62a17ae 1115 bgp_debug_list_free(bgp_debug_update_in_peers);
1116 bgp_debug_list_free(bgp_debug_update_out_peers);
1117 bgp_debug_list_free(bgp_debug_update_prefixes);
1118
1119 if (vty->node == CONFIG_NODE) {
1120 DEBUG_ON(update, UPDATE_IN);
1121 DEBUG_ON(update, UPDATE_OUT);
1122 } else {
1123 TERM_DEBUG_ON(update, UPDATE_IN);
1124 TERM_DEBUG_ON(update, UPDATE_OUT);
1125 vty_out(vty, "BGP updates debugging is on\n");
1126 }
1127 return CMD_SUCCESS;
718e3744 1128}
1129
1130DEFUN (debug_bgp_update_direct,
1131 debug_bgp_update_direct_cmd,
6147e2c6 1132 "debug bgp updates <in|out>",
718e3744 1133 DEBUG_STR
1134 BGP_STR
1135 "BGP updates\n"
1136 "Inbound updates\n"
1137 "Outbound updates\n")
1138{
d62a17ae 1139 int idx_in_out = 3;
1140
1141 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1142 bgp_debug_list_free(bgp_debug_update_in_peers);
1143 else
1144 bgp_debug_list_free(bgp_debug_update_out_peers);
1145
1146 if (vty->node == CONFIG_NODE) {
1147 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1148 DEBUG_ON(update, UPDATE_IN);
1149 else
1150 DEBUG_ON(update, UPDATE_OUT);
1151 } else {
1152 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
1153 TERM_DEBUG_ON(update, UPDATE_IN);
1154 vty_out(vty, "BGP updates debugging is on (inbound)\n");
1155 } else {
1156 TERM_DEBUG_ON(update, UPDATE_OUT);
1157 vty_out(vty,
1158 "BGP updates debugging is on (outbound)\n");
1159 }
1160 }
1161 return CMD_SUCCESS;
718e3744 1162}
1163
16286195
DS
1164DEFUN (debug_bgp_update_direct_peer,
1165 debug_bgp_update_direct_peer_cmd,
6147e2c6 1166 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
718e3744 1167 DEBUG_STR
1168 BGP_STR
16286195
DS
1169 "BGP updates\n"
1170 "Inbound updates\n"
1171 "Outbound updates\n"
1172 "BGP neighbor IP address to debug\n"
1173 "BGP IPv6 neighbor to debug\n"
1174 "BGP neighbor on interface to debug\n")
718e3744 1175{
d62a17ae 1176 int idx_in_out = 3;
1177 int idx_peer = 4;
1178 const char *host = argv[idx_peer]->arg;
1179 int inbound;
1180
1181 if (!bgp_debug_update_in_peers)
1182 bgp_debug_update_in_peers = list_new();
1183
1184 if (!bgp_debug_update_out_peers)
1185 bgp_debug_update_out_peers = list_new();
1186
1187 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1188 inbound = 1;
1189 else
1190 inbound = 0;
1191
1192 if (inbound) {
1193 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, host,
1194 NULL)) {
1195 vty_out(vty,
1196 "BGP inbound update debugging is already enabled for %s\n",
1197 host);
1198 return CMD_SUCCESS;
1199 }
1200 }
1201
1202 else {
1203 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host,
1204 NULL)) {
1205 vty_out(vty,
1206 "BGP outbound update debugging is already enabled for %s\n",
1207 host);
1208 return CMD_SUCCESS;
1209 }
1210 }
1211
1212 if (inbound)
1213 bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL);
1214 else {
1215 struct peer *peer;
1216 struct peer_af *paf;
1217 int afidx;
1218
1219 bgp_debug_list_add_entry(bgp_debug_update_out_peers, host,
1220 NULL);
1221 peer = bgp_find_peer(vty, host);
1222
1223 if (peer) {
1224 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
1225 afidx++) {
1226 paf = peer->peer_af_array[afidx];
1227 if (paf != NULL) {
1228 if (PAF_SUBGRP(paf)) {
1229 UPDGRP_PEER_DBG_EN(
1230 PAF_SUBGRP(paf)
1231 ->update_group);
1232 }
1233 }
1234 }
1235 }
1236 }
1237
1238 if (vty->node == CONFIG_NODE) {
1239 if (inbound)
1240 DEBUG_ON(update, UPDATE_IN);
1241 else
1242 DEBUG_ON(update, UPDATE_OUT);
1243 } else {
1244 if (inbound) {
1245 TERM_DEBUG_ON(update, UPDATE_IN);
1246 vty_out(vty,
1247 "BGP updates debugging is on (inbound) for %s\n",
1248 argv[idx_peer]->arg);
1249 } else {
1250 TERM_DEBUG_ON(update, UPDATE_OUT);
1251 vty_out(vty,
1252 "BGP updates debugging is on (outbound) for %s\n",
1253 argv[idx_peer]->arg);
1254 }
1255 }
1256 return CMD_SUCCESS;
718e3744 1257}
1258
91ba2c8b
DS
1259DEFUN (no_debug_bgp_update_direct,
1260 no_debug_bgp_update_direct_cmd,
6147e2c6 1261 "no debug bgp updates <in|out>",
91ba2c8b
DS
1262 NO_STR
1263 DEBUG_STR
1264 BGP_STR
1265 "BGP updates\n"
1266 "Inbound updates\n"
1267 "Outbound updates\n")
1268{
d62a17ae 1269 int idx_in_out = 4;
1270 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
1271 bgp_debug_list_free(bgp_debug_update_in_peers);
1272
1273 if (vty->node == CONFIG_NODE) {
1274 DEBUG_OFF(update, UPDATE_IN);
1275 } else {
1276 TERM_DEBUG_OFF(update, UPDATE_IN);
1277 vty_out(vty,
1278 "BGP updates debugging is off (inbound)\n");
1279 }
1280 } else {
1281 bgp_debug_list_free(bgp_debug_update_out_peers);
1282
1283 if (vty->node == CONFIG_NODE) {
1284 DEBUG_OFF(update, UPDATE_OUT);
1285 } else {
1286 TERM_DEBUG_OFF(update, UPDATE_OUT);
1287 vty_out(vty,
1288 "BGP updates debugging is off (outbound)\n");
1289 }
1290 }
1291
1292 return CMD_SUCCESS;
91ba2c8b
DS
1293}
1294
16286195
DS
1295DEFUN (no_debug_bgp_update_direct_peer,
1296 no_debug_bgp_update_direct_peer_cmd,
6147e2c6 1297 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
16286195
DS
1298 NO_STR
1299 DEBUG_STR
718e3744 1300 BGP_STR
16286195
DS
1301 "BGP updates\n"
1302 "Inbound updates\n"
1303 "Outbound updates\n"
1304 "BGP neighbor IP address to debug\n"
1305 "BGP IPv6 neighbor to debug\n"
1306 "BGP neighbor on interface to debug\n")
1307{
d62a17ae 1308 int idx_in_out = 4;
1309 int idx_peer = 5;
1310 int inbound;
1311 int found_peer = 0;
1312 const char *host = argv[idx_peer]->arg;
1313
1314 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1315 inbound = 1;
1316 else
1317 inbound = 0;
1318
1319 if (inbound && bgp_debug_update_in_peers
1320 && !list_isempty(bgp_debug_update_in_peers)) {
1321 found_peer = bgp_debug_list_remove_entry(
1322 bgp_debug_update_in_peers, host, NULL);
1323
1324 if (list_isempty(bgp_debug_update_in_peers)) {
1325 if (vty->node == CONFIG_NODE)
1326 DEBUG_OFF(update, UPDATE_IN);
1327 else {
1328 TERM_DEBUG_OFF(update, UPDATE_IN);
1329 vty_out(vty,
1330 "BGP updates debugging (inbound) is off\n");
1331 }
1332 }
1333 }
1334
1335 if (!inbound && bgp_debug_update_out_peers
1336 && !list_isempty(bgp_debug_update_out_peers)) {
1337 found_peer = bgp_debug_list_remove_entry(
1338 bgp_debug_update_out_peers, host, NULL);
1339
1340 if (list_isempty(bgp_debug_update_out_peers)) {
1341 if (vty->node == CONFIG_NODE)
1342 DEBUG_OFF(update, UPDATE_OUT);
1343 else {
1344 TERM_DEBUG_OFF(update, UPDATE_OUT);
1345 vty_out(vty,
1346 "BGP updates debugging (outbound) is off\n");
1347 }
1348 }
1349
1350 struct peer *peer;
1351 struct peer_af *paf;
1352 int afidx;
1353 peer = bgp_find_peer(vty, host);
1354
1355 if (peer) {
1356 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
1357 afidx++) {
1358 paf = peer->peer_af_array[afidx];
1359 if (paf != NULL) {
1360 if (PAF_SUBGRP(paf)) {
1361 UPDGRP_PEER_DBG_DIS(
1362 PAF_SUBGRP(paf)
1363 ->update_group);
1364 }
1365 }
1366 }
1367 }
1368 }
1369
1370 if (found_peer)
1371 if (inbound)
1372 vty_out(vty,
1373 "BGP updates debugging (inbound) is off for %s\n",
1374 host);
1375 else
1376 vty_out(vty,
1377 "BGP updates debugging (outbound) is off for %s\n",
1378 host);
1379 else if (inbound)
1380 vty_out(vty,
1381 "BGP updates debugging (inbound) was not enabled for %s\n",
1382 host);
1383 else
1384 vty_out(vty,
1385 "BGP updates debugging (outbound) was not enabled for %s\n",
1386 host);
1387
1388 return CMD_SUCCESS;
16286195
DS
1389}
1390
81cf0de5
CS
1391#ifndef VTYSH_EXTRACT_PL
1392#include "bgpd/bgp_debug_clippy.c"
1393#endif
1394
1395DEFPY (debug_bgp_update_prefix_afi_safi,
1396 debug_bgp_update_prefix_afi_safi_cmd,
15dc08a6 1397 "debug bgp updates prefix l2vpn$afi evpn$safi type <<macip|2> mac <X:X:X:X:X:X|X:X:X:X:X:X/M> [ip <A.B.C.D|X:X::X:X>]|<multicast|3> ip <A.B.C.D|X:X::X:X>|<prefix|5> ip <A.B.C.D/M|X:X::X:X/M>>",
81cf0de5
CS
1398 DEBUG_STR
1399 BGP_STR
1400 "BGP updates\n"
1401 "Specify a prefix to debug\n"
377e3565
QY
1402 L2VPN_HELP_STR
1403 EVPN_HELP_STR
31782fea
SW
1404 EVPN_TYPE_HELP_STR
1405 EVPN_TYPE_2_HELP_STR
15dc08a6 1406 EVPN_TYPE_2_HELP_STR
377e3565
QY
1407 MAC_STR MAC_STR MAC_STR
1408 IP_STR
1409 "IPv4 address\n"
1410 "IPv6 address\n"
31782fea 1411 EVPN_TYPE_3_HELP_STR
15dc08a6 1412 EVPN_TYPE_3_HELP_STR
377e3565
QY
1413 IP_STR
1414 "IPv4 address\n"
1415 "IPv6 address\n"
31782fea 1416 EVPN_TYPE_5_HELP_STR
15dc08a6 1417 EVPN_TYPE_5_HELP_STR
377e3565
QY
1418 IP_STR
1419 "IPv4 prefix\n"
1420 "IPv6 prefix\n")
81cf0de5 1421{
81cf0de5
CS
1422 struct prefix *argv_p;
1423 int ret = CMD_SUCCESS;
81cf0de5
CS
1424
1425 argv_p = prefix_new();
1426
377e3565
QY
1427 ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
1428 if (ret != CMD_SUCCESS) {
63265b5c 1429 prefix_free(&argv_p);
377e3565 1430 return ret;
81cf0de5
CS
1431 }
1432
1433 if (!bgp_debug_update_prefixes)
1434 bgp_debug_update_prefixes = list_new();
1435
1436 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) {
1437 vty_out(vty,
2dbe669b
DA
1438 "BGP updates debugging is already enabled for %pFX\n",
1439 argv_p);
63265b5c 1440 prefix_free(&argv_p);
377e3565 1441 return CMD_SUCCESS;
81cf0de5
CS
1442 }
1443
1444 bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p);
1445
1446 if (vty->node == CONFIG_NODE) {
1447 DEBUG_ON(update, UPDATE_PREFIX);
1448 } else {
1449 TERM_DEBUG_ON(update, UPDATE_PREFIX);
2dbe669b 1450 vty_out(vty, "BGP updates debugging is on for %pFX\n", argv_p);
81cf0de5
CS
1451 }
1452
63265b5c 1453 prefix_free(&argv_p);
360f9703 1454
377e3565 1455 return CMD_SUCCESS;
81cf0de5
CS
1456}
1457
1458DEFPY (no_debug_bgp_update_prefix_afi_safi,
1459 no_debug_bgp_update_prefix_afi_safi_cmd,
15dc08a6 1460 "no debug bgp updates prefix l2vpn$afi evpn$safi type <<macip|2> mac <X:X:X:X:X:X|X:X:X:X:X:X/M> [ip <A.B.C.D|X:X::X:X>]|<multicast|3> ip <A.B.C.D|X:X::X:X>|<prefix|5> ip <A.B.C.D/M|X:X::X:X/M>>",
81cf0de5
CS
1461 NO_STR
1462 DEBUG_STR
1463 BGP_STR
1464 "BGP updates\n"
1465 "Specify a prefix to debug\n"
377e3565
QY
1466 L2VPN_HELP_STR
1467 EVPN_HELP_STR
31782fea
SW
1468 EVPN_TYPE_HELP_STR
1469 EVPN_TYPE_2_HELP_STR
15dc08a6 1470 EVPN_TYPE_2_HELP_STR
377e3565
QY
1471 MAC_STR MAC_STR MAC_STR
1472 IP_STR
1473 "IPv4 address\n"
1474 "IPv6 address\n"
31782fea 1475 EVPN_TYPE_3_HELP_STR
15dc08a6 1476 EVPN_TYPE_3_HELP_STR
377e3565
QY
1477 IP_STR
1478 "IPv4 address\n"
1479 "IPv6 address\n"
31782fea 1480 EVPN_TYPE_5_HELP_STR
15dc08a6 1481 EVPN_TYPE_5_HELP_STR
377e3565
QY
1482 IP_STR
1483 "IPv4 prefix\n"
1484 "IPv6 prefix\n")
81cf0de5 1485{
81cf0de5 1486 struct prefix *argv_p;
377e3565 1487 bool found_prefix = false;
81cf0de5 1488 int ret = CMD_SUCCESS;
81cf0de5
CS
1489
1490 argv_p = prefix_new();
1491
377e3565
QY
1492 ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
1493 if (ret != CMD_SUCCESS) {
63265b5c 1494 prefix_free(&argv_p);
377e3565 1495 return ret;
81cf0de5
CS
1496 }
1497
1498 if (bgp_debug_update_prefixes
1499 && !list_isempty(bgp_debug_update_prefixes)) {
1500 found_prefix = bgp_debug_list_remove_entry(
1501 bgp_debug_update_prefixes, NULL, argv_p);
1502
1503 if (list_isempty(bgp_debug_update_prefixes)) {
1504 if (vty->node == CONFIG_NODE) {
1505 DEBUG_OFF(update, UPDATE_PREFIX);
1506 } else {
1507 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1508 vty_out(vty,
1509 "BGP updates debugging (per prefix) is off\n");
1510 }
1511 }
1512 }
1513
1514 if (found_prefix)
2dbe669b 1515 vty_out(vty, "BGP updates debugging is off for %pFX\n", argv_p);
81cf0de5 1516 else
2dbe669b
DA
1517 vty_out(vty, "BGP updates debugging was not enabled for %pFX\n",
1518 argv_p);
81cf0de5 1519
63265b5c 1520 prefix_free(&argv_p);
360f9703
A
1521
1522 return ret;
81cf0de5
CS
1523}
1524
1525
16286195
DS
1526DEFUN (debug_bgp_update_prefix,
1527 debug_bgp_update_prefix_cmd,
6147e2c6 1528 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
718e3744 1529 DEBUG_STR
16286195
DS
1530 BGP_STR
1531 "BGP updates\n"
1532 "Specify a prefix to debug\n"
0c7b1b01
QY
1533 "IPv4 prefix\n"
1534 "IPv6 prefix\n")
718e3744 1535{
d62a17ae 1536 int idx_ipv4_ipv6_prefixlen = 4;
1537 struct prefix *argv_p;
d62a17ae 1538
1539 argv_p = prefix_new();
ffd71765 1540 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1541 apply_mask(argv_p);
d62a17ae 1542
1543 if (!bgp_debug_update_prefixes)
1544 bgp_debug_update_prefixes = list_new();
1545
1546 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) {
1547 vty_out(vty,
1548 "BGP updates debugging is already enabled for %s\n",
1549 argv[idx_ipv4_ipv6_prefixlen]->arg);
1550 return CMD_SUCCESS;
1551 }
1552
1553 bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p);
1554
1555 if (vty->node == CONFIG_NODE) {
1556 DEBUG_ON(update, UPDATE_PREFIX);
1557 } else {
1558 TERM_DEBUG_ON(update, UPDATE_PREFIX);
1559 vty_out(vty, "BGP updates debugging is on for %s\n",
1560 argv[idx_ipv4_ipv6_prefixlen]->arg);
1561 }
1562
1563 return CMD_SUCCESS;
718e3744 1564}
1565
16286195
DS
1566DEFUN (no_debug_bgp_update_prefix,
1567 no_debug_bgp_update_prefix_cmd,
6147e2c6 1568 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
718e3744 1569 NO_STR
1570 DEBUG_STR
16286195
DS
1571 BGP_STR
1572 "BGP updates\n"
1573 "Specify a prefix to debug\n"
0c7b1b01
QY
1574 "IPv4 prefix\n"
1575 "IPv6 prefix\n")
16286195 1576{
d62a17ae 1577 int idx_ipv4_ipv6_prefixlen = 5;
1578 struct prefix *argv_p;
1579 int found_prefix = 0;
d62a17ae 1580
1581 argv_p = prefix_new();
ffd71765 1582 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1583 apply_mask(argv_p);
d62a17ae 1584
1585 if (bgp_debug_update_prefixes
1586 && !list_isempty(bgp_debug_update_prefixes)) {
1587 found_prefix = bgp_debug_list_remove_entry(
1588 bgp_debug_update_prefixes, NULL, argv_p);
1589
1590 if (list_isempty(bgp_debug_update_prefixes)) {
1591 if (vty->node == CONFIG_NODE) {
1592 DEBUG_OFF(update, UPDATE_PREFIX);
1593 } else {
1594 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1595 vty_out(vty,
1596 "BGP updates debugging (per prefix) is off\n");
1597 }
1598 }
1599 }
1600
1601 if (found_prefix)
1602 vty_out(vty, "BGP updates debugging is off for %s\n",
1603 argv[idx_ipv4_ipv6_prefixlen]->arg);
1604 else
1605 vty_out(vty, "BGP updates debugging was not enabled for %s\n",
1606 argv[idx_ipv4_ipv6_prefixlen]->arg);
1607
1608 return CMD_SUCCESS;
16286195
DS
1609}
1610
1611DEFUN (no_debug_bgp_update,
1612 no_debug_bgp_update_cmd,
1613 "no debug bgp updates",
1614 NO_STR
1615 DEBUG_STR
1616 BGP_STR
1617 "BGP updates\n")
718e3744 1618{
87f42c2c
QY
1619 struct listnode *ln;
1620 struct bgp *bgp;
1621
d62a17ae 1622 bgp_debug_list_free(bgp_debug_update_in_peers);
1623 bgp_debug_list_free(bgp_debug_update_out_peers);
1624 bgp_debug_list_free(bgp_debug_update_prefixes);
1625
87f42c2c
QY
1626 for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
1627 bgp_debug_clear_updgrp_update_dbg(bgp);
d62a17ae 1628
1629 if (vty->node == CONFIG_NODE) {
1630 DEBUG_OFF(update, UPDATE_IN);
1631 DEBUG_OFF(update, UPDATE_OUT);
1632 DEBUG_OFF(update, UPDATE_PREFIX);
1633 } else {
1634 TERM_DEBUG_OFF(update, UPDATE_IN);
1635 TERM_DEBUG_OFF(update, UPDATE_OUT);
1636 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1637 vty_out(vty, "BGP updates debugging is off\n");
1638 }
1639 return CMD_SUCCESS;
718e3744 1640}
1641
16286195 1642/* debug bgp zebra */
a39275d7
AS
1643DEFUN (debug_bgp_zebra,
1644 debug_bgp_zebra_cmd,
1645 "debug bgp zebra",
1646 DEBUG_STR
1647 BGP_STR
1648 "BGP Zebra messages\n")
1649{
d62a17ae 1650 if (vty->node == CONFIG_NODE)
1651 DEBUG_ON(zebra, ZEBRA);
1652 else {
1653 TERM_DEBUG_ON(zebra, ZEBRA);
1654 vty_out(vty, "BGP zebra debugging is on\n");
1655 }
1656 return CMD_SUCCESS;
a39275d7
AS
1657}
1658
794b37d5 1659DEFUN (debug_bgp_graceful_restart,
1660 debug_bgp_graceful_restart_cmd,
1661 "debug bgp graceful-restart",
1662 DEBUG_STR
1663 BGP_STR
1664 GR_DEBUG)
1665{
1666 if (vty->node == CONFIG_NODE) {
1667 DEBUG_ON(graceful_restart, GRACEFUL_RESTART);
1668 } else {
1669 TERM_DEBUG_ON(graceful_restart, GRACEFUL_RESTART);
1670 vty_out(vty, "BGP Graceful Restart debugging is on\n");
1671 }
1672 return CMD_SUCCESS;
1673}
1674
1675
16286195
DS
1676DEFUN (debug_bgp_zebra_prefix,
1677 debug_bgp_zebra_prefix_cmd,
6147e2c6 1678 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
16286195
DS
1679 DEBUG_STR
1680 BGP_STR
1681 "BGP Zebra messages\n"
1682 "Specify a prefix to debug\n"
0c7b1b01
QY
1683 "IPv4 prefix\n"
1684 "IPv6 prefix\n")
16286195 1685{
d62a17ae 1686 int idx_ipv4_ipv6_prefixlen = 4;
1687 struct prefix *argv_p;
d62a17ae 1688
1689 argv_p = prefix_new();
ffd71765 1690 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1691 apply_mask(argv_p);
d62a17ae 1692
1693 if (!bgp_debug_zebra_prefixes)
1694 bgp_debug_zebra_prefixes = list_new();
1695
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);
1699 return CMD_SUCCESS;
1700 }
1701
1702 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, argv_p);
1703
1704 if (vty->node == CONFIG_NODE)
1705 DEBUG_ON(zebra, ZEBRA);
1706 else {
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);
1710 }
1711
1712 return CMD_SUCCESS;
16286195
DS
1713}
1714
a39275d7
AS
1715DEFUN (no_debug_bgp_zebra,
1716 no_debug_bgp_zebra_cmd,
1717 "no debug bgp zebra",
1718 NO_STR
1719 DEBUG_STR
1720 BGP_STR
1721 "BGP Zebra messages\n")
1722{
d62a17ae 1723 bgp_debug_list_free(bgp_debug_zebra_prefixes);
1724
1725 if (vty->node == CONFIG_NODE)
1726 DEBUG_OFF(zebra, ZEBRA);
1727 else {
1728 TERM_DEBUG_OFF(zebra, ZEBRA);
1729 vty_out(vty, "BGP zebra debugging is off\n");
1730 }
1731 return CMD_SUCCESS;
a39275d7
AS
1732}
1733
794b37d5 1734DEFUN (no_debug_bgp_graceful_restart,
1735 no_debug_bgp_graceful_restart_cmd,
1736 "no debug bgp graceful-restart",
1737 DEBUG_STR
1738 BGP_STR
1739 GR_DEBUG
1740 NO_STR)
1741{
1742 if (vty->node == CONFIG_NODE) {
1743 DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
1744 } else {
1745 TERM_DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
1746 vty_out(vty, "BGP Graceful Restart debugging is off\n");
1747 }
1748 return CMD_SUCCESS;
1749}
1750
16286195
DS
1751DEFUN (no_debug_bgp_zebra_prefix,
1752 no_debug_bgp_zebra_prefix_cmd,
6147e2c6 1753 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
16286195
DS
1754 NO_STR
1755 DEBUG_STR
a39275d7 1756 BGP_STR
16286195
DS
1757 "BGP Zebra messages\n"
1758 "Specify a prefix to debug\n"
0c7b1b01
QY
1759 "IPv4 prefix\n"
1760 "IPv6 prefix\n")
16286195 1761{
d62a17ae 1762 int idx_ipv4_ipv6_prefixlen = 5;
1763 struct prefix *argv_p;
1764 int found_prefix = 0;
d62a17ae 1765
1766 argv_p = prefix_new();
ffd71765 1767 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1768 apply_mask(argv_p);
d62a17ae 1769
1770 if (bgp_debug_zebra_prefixes
1771 && !list_isempty(bgp_debug_zebra_prefixes)) {
1772 found_prefix = bgp_debug_list_remove_entry(
1773 bgp_debug_zebra_prefixes, NULL, argv_p);
1774
1775 if (list_isempty(bgp_debug_zebra_prefixes)) {
1776 if (vty->node == CONFIG_NODE)
1777 DEBUG_OFF(zebra, ZEBRA);
1778 else {
1779 TERM_DEBUG_OFF(zebra, ZEBRA);
1780 vty_out(vty, "BGP zebra debugging is off\n");
1781 }
1782 }
1783 }
1784
1785 if (found_prefix)
1786 vty_out(vty, "BGP zebra debugging is off for %s\n",
1787 argv[idx_ipv4_ipv6_prefixlen]->arg);
1788 else
1789 vty_out(vty, "BGP zebra debugging was not enabled for %s\n",
1790 argv[idx_ipv4_ipv6_prefixlen]->arg);
1791
1792 return CMD_SUCCESS;
16286195
DS
1793}
1794
cebb7440
LB
1795DEFUN (debug_bgp_allow_martians,
1796 debug_bgp_allow_martians_cmd,
1797 "debug bgp allow-martians",
1798 DEBUG_STR
1799 BGP_STR
1800 "BGP allow martian next hops\n")
1801{
d62a17ae 1802 if (vty->node == CONFIG_NODE)
1803 DEBUG_ON(allow_martians, ALLOW_MARTIANS);
1804 else {
1805 TERM_DEBUG_ON(allow_martians, ALLOW_MARTIANS);
1806 vty_out(vty, "BGP allow_martian next hop debugging is on\n");
1807 }
1808 return CMD_SUCCESS;
cebb7440
LB
1809}
1810
1811DEFUN (no_debug_bgp_allow_martians,
1812 no_debug_bgp_allow_martians_cmd,
1813 "no debug bgp allow-martians",
1814 NO_STR
1815 DEBUG_STR
1816 BGP_STR
1817 "BGP allow martian next hops\n")
1818{
d62a17ae 1819 if (vty->node == CONFIG_NODE)
1820 DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
1821 else {
1822 TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
1823 vty_out(vty, "BGP allow martian next hop debugging is off\n");
1824 }
1825 return CMD_SUCCESS;
cebb7440
LB
1826}
1827
cebb7440 1828
3f9c7369
DS
1829/* debug bgp update-groups */
1830DEFUN (debug_bgp_update_groups,
1831 debug_bgp_update_groups_cmd,
1832 "debug bgp update-groups",
1833 DEBUG_STR
1834 BGP_STR
1835 "BGP update-groups\n")
1836{
d62a17ae 1837 if (vty->node == CONFIG_NODE)
1838 DEBUG_ON(update_groups, UPDATE_GROUPS);
1839 else {
1840 TERM_DEBUG_ON(update_groups, UPDATE_GROUPS);
1841 vty_out(vty, "BGP update-groups debugging is on\n");
1842 }
1843 return CMD_SUCCESS;
3f9c7369
DS
1844}
1845
1846DEFUN (no_debug_bgp_update_groups,
1847 no_debug_bgp_update_groups_cmd,
1848 "no debug bgp update-groups",
1849 NO_STR
1850 DEBUG_STR
1851 BGP_STR
1852 "BGP update-groups\n")
1853{
d62a17ae 1854 if (vty->node == CONFIG_NODE)
1855 DEBUG_OFF(update_groups, UPDATE_GROUPS);
1856 else {
1857 TERM_DEBUG_OFF(update_groups, UPDATE_GROUPS);
1858 vty_out(vty, "BGP update-groups debugging is off\n");
1859 }
1860 return CMD_SUCCESS;
3f9c7369
DS
1861}
1862
ddb5b488
PZ
1863DEFUN (debug_bgp_vpn,
1864 debug_bgp_vpn_cmd,
1865 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1866 DEBUG_STR
1867 BGP_STR
1868 "VPN routes\n"
1869 "leaked from vrf to vpn\n"
1870 "leaked to vrf from vpn\n"
1871 "route-map updates\n"
1872 "labels\n")
1873{
1874 int idx = 3;
1875
1876 if (argv_find(argv, argc, "leak-from-vrf", &idx)) {
1877 if (vty->node == CONFIG_NODE)
1878 DEBUG_ON(vpn, VPN_LEAK_FROM_VRF);
1879 else
1880 TERM_DEBUG_ON(vpn, VPN_LEAK_FROM_VRF);
1881 } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) {
1882 if (vty->node == CONFIG_NODE)
1883 DEBUG_ON(vpn, VPN_LEAK_TO_VRF);
1884 else
1885 TERM_DEBUG_ON(vpn, VPN_LEAK_TO_VRF);
1886 } else if (argv_find(argv, argc, "rmap-event", &idx)) {
1887 if (vty->node == CONFIG_NODE)
1888 DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT);
1889 else
1890 TERM_DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT);
1891 } else if (argv_find(argv, argc, "label", &idx)) {
1892 if (vty->node == CONFIG_NODE)
1893 DEBUG_ON(vpn, VPN_LEAK_LABEL);
1894 else
1895 TERM_DEBUG_ON(vpn, VPN_LEAK_LABEL);
1896 } else {
1897 vty_out(vty, "%% unknown debug bgp vpn keyword\n");
1898 return CMD_WARNING_CONFIG_FAILED;
1899 }
1900
1901 if (vty->node != CONFIG_NODE)
1902 vty_out(vty, "enabled debug bgp vpn %s\n", argv[idx]->text);
1903
1904 return CMD_SUCCESS;
1905}
1906
1907DEFUN (no_debug_bgp_vpn,
1908 no_debug_bgp_vpn_cmd,
1909 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1910 NO_STR
1911 DEBUG_STR
1912 BGP_STR
1913 "VPN routes\n"
1914 "leaked from vrf to vpn\n"
1915 "leaked to vrf from vpn\n"
1916 "route-map updates\n"
1917 "labels\n")
1918{
1919 int idx = 4;
1920
1921 if (argv_find(argv, argc, "leak-from-vrf", &idx)) {
1922 if (vty->node == CONFIG_NODE)
1923 DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
1924 else
1925 TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
1926
1927 } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) {
1928 if (vty->node == CONFIG_NODE)
1929 DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
1930 else
1931 TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
1932 } else if (argv_find(argv, argc, "rmap-event", &idx)) {
1933 if (vty->node == CONFIG_NODE)
1934 DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
1935 else
1936 TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
1937 } else if (argv_find(argv, argc, "label", &idx)) {
1938 if (vty->node == CONFIG_NODE)
1939 DEBUG_OFF(vpn, VPN_LEAK_LABEL);
1940 else
1941 TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL);
1942 } else {
1943 vty_out(vty, "%% unknown debug bgp vpn keyword\n");
1944 return CMD_WARNING_CONFIG_FAILED;
1945 }
1946
1947 if (vty->node != CONFIG_NODE)
1948 vty_out(vty, "disabled debug bgp vpn %s\n", argv[idx]->text);
1a80fc0f
PG
1949 return CMD_SUCCESS;
1950}
ddb5b488 1951
1a80fc0f
PG
1952/* debug bgp pbr */
1953DEFUN (debug_bgp_pbr,
1954 debug_bgp_pbr_cmd,
e9d0aa99 1955 "debug bgp pbr [error]",
1a80fc0f
PG
1956 DEBUG_STR
1957 BGP_STR
e9d0aa99
PG
1958 "BGP policy based routing\n"
1959 "BGP PBR error\n")
1a80fc0f 1960{
e9d0aa99
PG
1961 int idx = 3;
1962
1963 if (argv_find(argv, argc, "error", &idx)) {
1964 if (vty->node == CONFIG_NODE)
1965 DEBUG_ON(pbr, PBR_ERROR);
1966 else {
1967 TERM_DEBUG_ON(pbr, PBR_ERROR);
1968 vty_out(vty, "BGP policy based routing error is on\n");
1969 }
1970 return CMD_SUCCESS;
1971 }
1a80fc0f
PG
1972 if (vty->node == CONFIG_NODE)
1973 DEBUG_ON(pbr, PBR);
1974 else {
1975 TERM_DEBUG_ON(pbr, PBR);
1976 vty_out(vty, "BGP policy based routing is on\n");
1977 }
1978 return CMD_SUCCESS;
1979}
1980
1981DEFUN (no_debug_bgp_pbr,
1982 no_debug_bgp_pbr_cmd,
e9d0aa99 1983 "no debug bgp pbr [error]",
1a80fc0f
PG
1984 NO_STR
1985 DEBUG_STR
1986 BGP_STR
e9d0aa99
PG
1987 "BGP policy based routing\n"
1988 "BGP PBR Error\n")
1a80fc0f 1989{
e9d0aa99
PG
1990 int idx = 3;
1991
1992 if (argv_find(argv, argc, "error", &idx)) {
1993 if (vty->node == CONFIG_NODE)
1994 DEBUG_OFF(pbr, PBR_ERROR);
1995 else {
1996 TERM_DEBUG_OFF(pbr, PBR_ERROR);
1997 vty_out(vty, "BGP policy based routing error is off\n");
1998 }
1999 return CMD_SUCCESS;
2000 }
1a80fc0f
PG
2001 if (vty->node == CONFIG_NODE)
2002 DEBUG_OFF(pbr, PBR);
2003 else {
2004 TERM_DEBUG_OFF(pbr, PBR);
2005 vty_out(vty, "BGP policy based routing is off\n");
2006 }
ddb5b488
PZ
2007 return CMD_SUCCESS;
2008}
2009
52653398
AK
2010DEFPY (debug_bgp_evpn_mh,
2011 debug_bgp_evpn_mh_cmd,
2012 "[no$no] debug bgp evpn mh <es$es|route$rt>",
2013 NO_STR
2014 DEBUG_STR
2015 BGP_STR
2016 "EVPN\n"
2017 "Multihoming\n"
2018 "Ethernet Segment debugging\n"
2019 "Route debugging\n")
2020{
2021 if (es) {
2022 if (vty->node == CONFIG_NODE) {
2023 if (no)
2024 DEBUG_OFF(evpn_mh, EVPN_MH_ES);
2025 else
2026 DEBUG_ON(evpn_mh, EVPN_MH_ES);
2027 } else {
2028 if (no) {
2029 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
2030 vty_out(vty,
2031 "BGP EVPN-MH ES debugging is off\n");
2032 } else {
2033 TERM_DEBUG_ON(evpn_mh, EVPN_MH_ES);
2034 vty_out(vty,
2035 "BGP EVPN-MH ES debugging is on\n");
2036 }
2037 }
2038 }
2039 if (rt) {
2040 if (vty->node == CONFIG_NODE) {
2041 if (no)
2042 DEBUG_OFF(evpn_mh, EVPN_MH_RT);
2043 else
2044 DEBUG_ON(evpn_mh, EVPN_MH_RT);
2045 } else {
2046 if (no) {
2047 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
2048 vty_out(vty,
2049 "BGP EVPN-MH route debugging is off\n");
2050 } else {
2051 TERM_DEBUG_ON(evpn_mh, EVPN_MH_RT);
2052 vty_out(vty,
2053 "BGP EVPN-MH route debugging is on\n");
2054 }
2055 }
2056 }
2057
2058 return CMD_SUCCESS;
2059}
2060
955bfd98
PZ
2061DEFUN (debug_bgp_labelpool,
2062 debug_bgp_labelpool_cmd,
2063 "debug bgp labelpool",
2064 DEBUG_STR
2065 BGP_STR
2066 "label pool\n")
2067{
2068 if (vty->node == CONFIG_NODE)
2069 DEBUG_ON(labelpool, LABELPOOL);
2070 else
2071 TERM_DEBUG_ON(labelpool, LABELPOOL);
2072
2073 if (vty->node != CONFIG_NODE)
2074 vty_out(vty, "enabled debug bgp labelpool\n");
2075
2076 return CMD_SUCCESS;
2077}
2078
2079DEFUN (no_debug_bgp_labelpool,
2080 no_debug_bgp_labelpool_cmd,
2081 "no debug bgp labelpool",
2082 NO_STR
2083 DEBUG_STR
2084 BGP_STR
2085 "label pool\n")
2086{
2087 if (vty->node == CONFIG_NODE)
2088 DEBUG_OFF(labelpool, LABELPOOL);
2089 else
2090 TERM_DEBUG_OFF(labelpool, LABELPOOL);
2091
2092
2093 if (vty->node != CONFIG_NODE)
2094 vty_out(vty, "disabled debug bgp labelpool\n");
2095
2096 return CMD_SUCCESS;
2097}
2098
259f4236
RZ
2099DEFPY(debug_bgp_bfd, debug_bgp_bfd_cmd,
2100 "[no] debug bgp bfd",
2101 NO_STR
2102 DEBUG_STR
2103 BGP_STR
2104 "Bidirection Forwarding Detection\n")
2105{
2106 if (vty->node == CONFIG_NODE) {
2107 if (no) {
2108 DEBUG_OFF(bfd, BFD_LIB);
2109 bfd_protocol_integration_set_debug(false);
2110 } else {
2111 DEBUG_ON(bfd, BFD_LIB);
2112 bfd_protocol_integration_set_debug(true);
2113 }
2114 } else {
edc0d8cf 2115 if (no) {
259f4236 2116 TERM_DEBUG_OFF(bfd, BFD_LIB);
edc0d8cf
IR
2117 bfd_protocol_integration_set_debug(false);
2118 } else {
259f4236 2119 TERM_DEBUG_ON(bfd, BFD_LIB);
edc0d8cf
IR
2120 bfd_protocol_integration_set_debug(true);
2121 }
259f4236
RZ
2122 }
2123
2124 return CMD_SUCCESS;
2125}
2126
16286195
DS
2127DEFUN (no_debug_bgp,
2128 no_debug_bgp_cmd,
2129 "no debug bgp",
718e3744 2130 NO_STR
2131 DEBUG_STR
718e3744 2132 BGP_STR)
2133{
87f42c2c
QY
2134 struct bgp *bgp;
2135 struct listnode *ln;
2136
d62a17ae 2137 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
2138 bgp_debug_list_free(bgp_debug_keepalive_peers);
2139 bgp_debug_list_free(bgp_debug_update_in_peers);
2140 bgp_debug_list_free(bgp_debug_update_out_peers);
2141 bgp_debug_list_free(bgp_debug_update_prefixes);
2142 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
2143 bgp_debug_list_free(bgp_debug_zebra_prefixes);
2144
87f42c2c
QY
2145 for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
2146 bgp_debug_clear_updgrp_update_dbg(bgp);
d62a17ae 2147
2148 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
2149 TERM_DEBUG_OFF(update, UPDATE_IN);
2150 TERM_DEBUG_OFF(update, UPDATE_OUT);
2151 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
2152 TERM_DEBUG_OFF(bestpath, BESTPATH);
2153 TERM_DEBUG_OFF(as4, AS4);
2154 TERM_DEBUG_OFF(as4, AS4_SEGMENT);
2155 TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
2156 TERM_DEBUG_OFF(zebra, ZEBRA);
2157 TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
c33b83b3 2158 TERM_DEBUG_OFF(nht, NHT);
ddb5b488
PZ
2159 TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
2160 TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
2161 TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
2162 TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL);
268e1b9b 2163 TERM_DEBUG_OFF(flowspec, FLOWSPEC);
955bfd98 2164 TERM_DEBUG_OFF(labelpool, LABELPOOL);
1a80fc0f 2165 TERM_DEBUG_OFF(pbr, PBR);
e9d0aa99 2166 TERM_DEBUG_OFF(pbr, PBR_ERROR);
794b37d5 2167 TERM_DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
52653398
AK
2168 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
2169 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
259f4236 2170 TERM_DEBUG_OFF(bfd, BFD_LIB);
794b37d5 2171
d62a17ae 2172 vty_out(vty, "All possible debugging has been turned off\n");
2173
2174 return CMD_SUCCESS;
718e3744 2175}
2176
87f6dc50
DS
2177DEFUN_NOSH (show_debugging_bgp,
2178 show_debugging_bgp_cmd,
2179 "show debugging [bgp]",
2180 SHOW_STR
2181 DEBUG_STR
2182 BGP_STR)
718e3744 2183{
d62a17ae 2184 vty_out(vty, "BGP debugging status:\n");
718e3744 2185
d62a17ae 2186 if (BGP_DEBUG(as4, AS4))
2187 vty_out(vty, " BGP as4 debugging is on\n");
16286195 2188
d62a17ae 2189 if (BGP_DEBUG(as4, AS4_SEGMENT))
2190 vty_out(vty, " BGP as4 aspath segment debugging is on\n");
16286195 2191
d62a17ae 2192 if (BGP_DEBUG(bestpath, BESTPATH))
2193 bgp_debug_list_print(vty, " BGP bestpath debugging is on",
29a643ca 2194 bgp_debug_bestpath_prefixes);
16286195 2195
d62a17ae 2196 if (BGP_DEBUG(keepalive, KEEPALIVE))
2197 bgp_debug_list_print(vty, " BGP keepalives debugging is on",
29a643ca 2198 bgp_debug_keepalive_peers);
16286195 2199
d62a17ae 2200 if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS))
2201 bgp_debug_list_print(vty,
2202 " BGP neighbor-events debugging is on",
29a643ca 2203 bgp_debug_neighbor_events_peers);
91ba2c8b 2204
d62a17ae 2205 if (BGP_DEBUG(nht, NHT))
2206 vty_out(vty, " BGP next-hop tracking debugging is on\n");
16286195 2207
d62a17ae 2208 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
2209 vty_out(vty, " BGP update-groups debugging is on\n");
91ba2c8b 2210
d62a17ae 2211 if (BGP_DEBUG(update, UPDATE_PREFIX))
2212 bgp_debug_list_print(vty, " BGP updates debugging is on",
29a643ca 2213 bgp_debug_update_prefixes);
16286195 2214
d62a17ae 2215 if (BGP_DEBUG(update, UPDATE_IN))
2216 bgp_debug_list_print(vty,
2217 " BGP updates debugging is on (inbound)",
29a643ca 2218 bgp_debug_update_in_peers);
16286195 2219
d62a17ae 2220 if (BGP_DEBUG(update, UPDATE_OUT))
2221 bgp_debug_list_print(vty,
2222 " BGP updates debugging is on (outbound)",
29a643ca 2223 bgp_debug_update_out_peers);
16286195 2224
d62a17ae 2225 if (BGP_DEBUG(zebra, ZEBRA))
2226 bgp_debug_list_print(vty, " BGP zebra debugging is on",
36235319 2227 bgp_debug_zebra_prefixes);
794b37d5 2228
2229 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
81bf7425 2230 vty_out(vty, " BGP graceful-restart debugging is on\n");
16286195 2231
d62a17ae 2232 if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS))
2233 vty_out(vty, " BGP allow martian next hop debugging is on\n");
ddb5b488
PZ
2234
2235 if (BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF))
2236 vty_out(vty,
2237 " BGP route leak from vrf to vpn debugging is on\n");
2238 if (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF))
2239 vty_out(vty,
2240 " BGP route leak to vrf from vpn debugging is on\n");
2241 if (BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT))
2242 vty_out(vty, " BGP vpn route-map event debugging is on\n");
2243 if (BGP_DEBUG(vpn, VPN_LEAK_LABEL))
2244 vty_out(vty, " BGP vpn label event debugging is on\n");
268e1b9b
PG
2245 if (BGP_DEBUG(flowspec, FLOWSPEC))
2246 vty_out(vty, " BGP flowspec debugging is on\n");
955bfd98
PZ
2247 if (BGP_DEBUG(labelpool, LABELPOOL))
2248 vty_out(vty, " BGP labelpool debugging is on\n");
ddb5b488 2249
1a80fc0f
PG
2250 if (BGP_DEBUG(pbr, PBR))
2251 vty_out(vty, " BGP policy based routing debugging is on\n");
e9d0aa99
PG
2252 if (BGP_DEBUG(pbr, PBR_ERROR))
2253 vty_out(vty, " BGP policy based routing error debugging is on\n");
1d4cfa5d 2254
52653398
AK
2255 if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
2256 vty_out(vty, " BGP EVPN-MH ES debugging is on\n");
2257 if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
2258 vty_out(vty, " BGP EVPN-MH route debugging is on\n");
2259
259f4236
RZ
2260 if (BGP_DEBUG(bfd, BFD_LIB))
2261 vty_out(vty, " BGP BFD library debugging is on\n");
2262
d62a17ae 2263 vty_out(vty, "\n");
2264 return CMD_SUCCESS;
718e3744 2265}
2266
d62a17ae 2267static int bgp_config_write_debug(struct vty *vty)
718e3744 2268{
d62a17ae 2269 int write = 0;
718e3744 2270
d62a17ae 2271 if (CONF_BGP_DEBUG(as4, AS4)) {
2272 vty_out(vty, "debug bgp as4\n");
2273 write++;
2274 }
718e3744 2275
d62a17ae 2276 if (CONF_BGP_DEBUG(as4, AS4_SEGMENT)) {
2277 vty_out(vty, "debug bgp as4 segment\n");
2278 write++;
2279 }
16286195 2280
d62a17ae 2281 if (CONF_BGP_DEBUG(bestpath, BESTPATH)) {
2282 write += bgp_debug_list_conf_print(vty, "debug bgp bestpath",
29a643ca 2283 bgp_debug_bestpath_prefixes);
d62a17ae 2284 }
2285
2286 if (CONF_BGP_DEBUG(keepalive, KEEPALIVE)) {
2287 write += bgp_debug_list_conf_print(vty, "debug bgp keepalives",
29a643ca 2288 bgp_debug_keepalive_peers);
d62a17ae 2289 }
2290
2291 if (CONF_BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)) {
2292 write += bgp_debug_list_conf_print(
2293 vty, "debug bgp neighbor-events",
29a643ca 2294 bgp_debug_neighbor_events_peers);
d62a17ae 2295 }
2296
2297 if (CONF_BGP_DEBUG(nht, NHT)) {
2298 vty_out(vty, "debug bgp nht\n");
2299 write++;
2300 }
2301
2302 if (CONF_BGP_DEBUG(update_groups, UPDATE_GROUPS)) {
2303 vty_out(vty, "debug bgp update-groups\n");
2304 write++;
2305 }
2306
2307 if (CONF_BGP_DEBUG(update, UPDATE_PREFIX)) {
2308 write += bgp_debug_list_conf_print(vty,
2309 "debug bgp updates prefix",
29a643ca 2310 bgp_debug_update_prefixes);
d62a17ae 2311 }
2312
2313 if (CONF_BGP_DEBUG(update, UPDATE_IN)) {
2314 write += bgp_debug_list_conf_print(vty, "debug bgp updates in",
29a643ca 2315 bgp_debug_update_in_peers);
d62a17ae 2316 }
2317
2318 if (CONF_BGP_DEBUG(update, UPDATE_OUT)) {
2319 write += bgp_debug_list_conf_print(vty, "debug bgp updates out",
29a643ca 2320 bgp_debug_update_out_peers);
d62a17ae 2321 }
16286195 2322
d62a17ae 2323 if (CONF_BGP_DEBUG(zebra, ZEBRA)) {
2324 if (!bgp_debug_zebra_prefixes
2325 || list_isempty(bgp_debug_zebra_prefixes)) {
2326 vty_out(vty, "debug bgp zebra\n");
2327 write++;
2328 } else {
2329 write += bgp_debug_list_conf_print(
2330 vty, "debug bgp zebra prefix",
29a643ca 2331 bgp_debug_zebra_prefixes);
d62a17ae 2332 }
2333 }
16286195 2334
d62a17ae 2335 if (CONF_BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) {
2336 vty_out(vty, "debug bgp allow-martians\n");
2337 write++;
2338 }
16286195 2339
ddb5b488
PZ
2340 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF)) {
2341 vty_out(vty, "debug bgp vpn leak-from-vrf\n");
2342 write++;
2343 }
2344 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_TO_VRF)) {
2345 vty_out(vty, "debug bgp vpn leak-to-vrf\n");
2346 write++;
2347 }
2348 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT)) {
2349 vty_out(vty, "debug bgp vpn rmap-event\n");
2350 write++;
2351 }
2352 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_LABEL)) {
2353 vty_out(vty, "debug bgp vpn label\n");
2354 write++;
2355 }
268e1b9b
PG
2356 if (CONF_BGP_DEBUG(flowspec, FLOWSPEC)) {
2357 vty_out(vty, "debug bgp flowspec\n");
2358 write++;
2359 }
955bfd98
PZ
2360 if (CONF_BGP_DEBUG(labelpool, LABELPOOL)) {
2361 vty_out(vty, "debug bgp labelpool\n");
2362 write++;
2363 }
ddb5b488 2364
1a80fc0f
PG
2365 if (CONF_BGP_DEBUG(pbr, PBR)) {
2366 vty_out(vty, "debug bgp pbr\n");
2367 write++;
e9d0aa99
PG
2368 }
2369 if (CONF_BGP_DEBUG(pbr, PBR_ERROR)) {
2370 vty_out(vty, "debug bgp pbr error\n");
2371 write++;
1a80fc0f 2372 }
794b37d5 2373
2374 if (CONF_BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) {
2375 vty_out(vty, "debug bgp graceful-restart\n");
2376 write++;
2377 }
52653398
AK
2378
2379 if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_ES)) {
2380 vty_out(vty, "debug bgp evpn mh es\n");
2381 write++;
2382 }
2383 if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_RT)) {
2384 vty_out(vty, "debug bgp evpn mh route\n");
2385 write++;
2386 }
2387
259f4236
RZ
2388 if (CONF_BGP_DEBUG(bfd, BFD_LIB)) {
2389 vty_out(vty, "debug bgp bfd\n");
2390 write++;
2391 }
2392
d62a17ae 2393 return write;
2394}
16286195 2395
612c2c15 2396static int bgp_config_write_debug(struct vty *vty);
62b346ee 2397static struct cmd_node debug_node = {
f4b8291f 2398 .name = "debug",
62b346ee
DL
2399 .node = DEBUG_NODE,
2400 .prompt = "",
612c2c15 2401 .config_write = bgp_config_write_debug,
62b346ee 2402};
d62a17ae 2403
2404void bgp_debug_init(void)
2405{
612c2c15 2406 install_node(&debug_node);
d62a17ae 2407
2408 install_element(ENABLE_NODE, &show_debugging_bgp_cmd);
2409
2410 install_element(ENABLE_NODE, &debug_bgp_as4_cmd);
2411 install_element(CONFIG_NODE, &debug_bgp_as4_cmd);
2412 install_element(ENABLE_NODE, &debug_bgp_as4_segment_cmd);
2413 install_element(CONFIG_NODE, &debug_bgp_as4_segment_cmd);
2414
2415 install_element(ENABLE_NODE, &debug_bgp_neighbor_events_cmd);
2416 install_element(CONFIG_NODE, &debug_bgp_neighbor_events_cmd);
2417 install_element(ENABLE_NODE, &debug_bgp_nht_cmd);
2418 install_element(CONFIG_NODE, &debug_bgp_nht_cmd);
2419 install_element(ENABLE_NODE, &debug_bgp_keepalive_cmd);
2420 install_element(CONFIG_NODE, &debug_bgp_keepalive_cmd);
2421 install_element(ENABLE_NODE, &debug_bgp_update_cmd);
2422 install_element(CONFIG_NODE, &debug_bgp_update_cmd);
2423 install_element(ENABLE_NODE, &debug_bgp_zebra_cmd);
2424 install_element(CONFIG_NODE, &debug_bgp_zebra_cmd);
2425 install_element(ENABLE_NODE, &debug_bgp_allow_martians_cmd);
2426 install_element(CONFIG_NODE, &debug_bgp_allow_martians_cmd);
2427 install_element(ENABLE_NODE, &debug_bgp_update_groups_cmd);
2428 install_element(CONFIG_NODE, &debug_bgp_update_groups_cmd);
2429 install_element(ENABLE_NODE, &debug_bgp_bestpath_prefix_cmd);
2430 install_element(CONFIG_NODE, &debug_bgp_bestpath_prefix_cmd);
2431
794b37d5 2432 install_element(ENABLE_NODE, &debug_bgp_graceful_restart_cmd);
2433 install_element(CONFIG_NODE, &debug_bgp_graceful_restart_cmd);
2434
d62a17ae 2435 /* debug bgp updates (in|out) */
2436 install_element(ENABLE_NODE, &debug_bgp_update_direct_cmd);
2437 install_element(CONFIG_NODE, &debug_bgp_update_direct_cmd);
2438 install_element(ENABLE_NODE, &no_debug_bgp_update_direct_cmd);
2439 install_element(CONFIG_NODE, &no_debug_bgp_update_direct_cmd);
2440
2441 /* debug bgp updates (in|out) A.B.C.D */
2442 install_element(ENABLE_NODE, &debug_bgp_update_direct_peer_cmd);
2443 install_element(CONFIG_NODE, &debug_bgp_update_direct_peer_cmd);
2444 install_element(ENABLE_NODE, &no_debug_bgp_update_direct_peer_cmd);
2445 install_element(CONFIG_NODE, &no_debug_bgp_update_direct_peer_cmd);
2446
2447 /* debug bgp updates prefix A.B.C.D/M */
2448 install_element(ENABLE_NODE, &debug_bgp_update_prefix_cmd);
2449 install_element(CONFIG_NODE, &debug_bgp_update_prefix_cmd);
2450 install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_cmd);
2451 install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_cmd);
81cf0de5
CS
2452 install_element(ENABLE_NODE, &debug_bgp_update_prefix_afi_safi_cmd);
2453 install_element(CONFIG_NODE, &debug_bgp_update_prefix_afi_safi_cmd);
2454 install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd);
2455 install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd);
d62a17ae 2456
2457 /* debug bgp zebra prefix A.B.C.D/M */
2458 install_element(ENABLE_NODE, &debug_bgp_zebra_prefix_cmd);
2459 install_element(CONFIG_NODE, &debug_bgp_zebra_prefix_cmd);
2460 install_element(ENABLE_NODE, &no_debug_bgp_zebra_prefix_cmd);
2461 install_element(CONFIG_NODE, &no_debug_bgp_zebra_prefix_cmd);
2462
2463 install_element(ENABLE_NODE, &no_debug_bgp_as4_cmd);
2464 install_element(CONFIG_NODE, &no_debug_bgp_as4_cmd);
2465 install_element(ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
2466 install_element(CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
2467
2468 /* debug bgp neighbor-events A.B.C.D */
2469 install_element(ENABLE_NODE, &debug_bgp_neighbor_events_peer_cmd);
2470 install_element(CONFIG_NODE, &debug_bgp_neighbor_events_peer_cmd);
2471 install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
2472 install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
2473
2474 /* debug bgp keepalive A.B.C.D */
2475 install_element(ENABLE_NODE, &debug_bgp_keepalive_peer_cmd);
2476 install_element(CONFIG_NODE, &debug_bgp_keepalive_peer_cmd);
2477 install_element(ENABLE_NODE, &no_debug_bgp_keepalive_peer_cmd);
2478 install_element(CONFIG_NODE, &no_debug_bgp_keepalive_peer_cmd);
2479
2480 install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_cmd);
2481 install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_cmd);
2482 install_element(ENABLE_NODE, &no_debug_bgp_nht_cmd);
2483 install_element(CONFIG_NODE, &no_debug_bgp_nht_cmd);
2484 install_element(ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
2485 install_element(CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
2486 install_element(ENABLE_NODE, &no_debug_bgp_update_cmd);
2487 install_element(CONFIG_NODE, &no_debug_bgp_update_cmd);
2488 install_element(ENABLE_NODE, &no_debug_bgp_zebra_cmd);
2489 install_element(CONFIG_NODE, &no_debug_bgp_zebra_cmd);
2490 install_element(ENABLE_NODE, &no_debug_bgp_allow_martians_cmd);
2491 install_element(CONFIG_NODE, &no_debug_bgp_allow_martians_cmd);
2492 install_element(ENABLE_NODE, &no_debug_bgp_update_groups_cmd);
2493 install_element(CONFIG_NODE, &no_debug_bgp_update_groups_cmd);
2494 install_element(ENABLE_NODE, &no_debug_bgp_cmd);
2495 install_element(ENABLE_NODE, &no_debug_bgp_bestpath_cmd);
2496 install_element(CONFIG_NODE, &no_debug_bgp_bestpath_cmd);
2497 install_element(ENABLE_NODE, &no_debug_bgp_bestpath_prefix_cmd);
2498 install_element(CONFIG_NODE, &no_debug_bgp_bestpath_prefix_cmd);
ddb5b488 2499
794b37d5 2500 install_element(ENABLE_NODE, &no_debug_bgp_graceful_restart_cmd);
2501 install_element(CONFIG_NODE, &no_debug_bgp_graceful_restart_cmd);
2502
ddb5b488
PZ
2503 install_element(ENABLE_NODE, &debug_bgp_vpn_cmd);
2504 install_element(CONFIG_NODE, &debug_bgp_vpn_cmd);
2505 install_element(ENABLE_NODE, &no_debug_bgp_vpn_cmd);
2506 install_element(CONFIG_NODE, &no_debug_bgp_vpn_cmd);
955bfd98
PZ
2507
2508 install_element(ENABLE_NODE, &debug_bgp_labelpool_cmd);
2509 install_element(CONFIG_NODE, &debug_bgp_labelpool_cmd);
2510 install_element(ENABLE_NODE, &no_debug_bgp_labelpool_cmd);
2511 install_element(CONFIG_NODE, &no_debug_bgp_labelpool_cmd);
1a80fc0f
PG
2512
2513 /* debug bgp pbr */
2514 install_element(ENABLE_NODE, &debug_bgp_pbr_cmd);
2515 install_element(CONFIG_NODE, &debug_bgp_pbr_cmd);
2516 install_element(ENABLE_NODE, &no_debug_bgp_pbr_cmd);
2517 install_element(CONFIG_NODE, &no_debug_bgp_pbr_cmd);
2518
52653398
AK
2519 install_element(ENABLE_NODE, &debug_bgp_evpn_mh_cmd);
2520 install_element(CONFIG_NODE, &debug_bgp_evpn_mh_cmd);
259f4236
RZ
2521
2522 /* debug bgp bfd */
2523 install_element(ENABLE_NODE, &debug_bgp_bfd_cmd);
2524 install_element(CONFIG_NODE, &debug_bgp_bfd_cmd);
d62a17ae 2525}
16286195 2526
d62a17ae 2527/* Return true if this prefix is on the per_prefix_list of prefixes to debug
2528 * for BGP_DEBUG_TYPE
2529 */
b8685f9b 2530static int bgp_debug_per_prefix(const struct prefix *p,
d62a17ae 2531 unsigned long term_bgp_debug_type,
2532 unsigned int BGP_DEBUG_TYPE,
2533 struct list *per_prefix_list)
2534{
2535 struct bgp_debug_filter *filter;
2536 struct listnode *node, *nnode;
2537
2538 if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
2539 /* We are debugging all prefixes so return true */
2540 if (!per_prefix_list || list_isempty(per_prefix_list))
2541 return 1;
2542
2543 else {
2544 if (!p)
2545 return 0;
2546
2547 for (ALL_LIST_ELEMENTS(per_prefix_list, node, nnode,
2548 filter))
2549 if (filter->p->prefixlen == p->prefixlen
2550 && prefix_match(filter->p, p))
2551 return 1;
2552
2553 return 0;
2554 }
2555 }
2556
2557 return 0;
16286195
DS
2558}
2559
2560/* Return true if this peer is on the per_peer_list of peers to debug
2561 * for BGP_DEBUG_TYPE
2562 */
d62a17ae 2563static int bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type,
2564 unsigned int BGP_DEBUG_TYPE,
2565 struct list *per_peer_list)
16286195 2566{
d62a17ae 2567 struct bgp_debug_filter *filter;
2568 struct listnode *node, *nnode;
16286195 2569
d62a17ae 2570 if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
2571 /* We are debugging all peers so return true */
2572 if (!per_peer_list || list_isempty(per_peer_list))
2573 return 1;
16286195 2574
d62a17ae 2575 else {
2576 if (!host)
2577 return 0;
16286195 2578
d62a17ae 2579 for (ALL_LIST_ELEMENTS(per_peer_list, node, nnode,
2580 filter))
2581 if (strcmp(filter->host, host) == 0)
2582 return 1;
16286195 2583
d62a17ae 2584 return 0;
2585 }
2586 }
16286195 2587
d62a17ae 2588 return 0;
16286195
DS
2589}
2590
d62a17ae 2591int bgp_debug_neighbor_events(struct peer *peer)
16286195 2592{
d62a17ae 2593 char *host = NULL;
167d390a 2594
d62a17ae 2595 if (peer)
2596 host = peer->host;
167d390a 2597
d62a17ae 2598 return bgp_debug_per_peer(host, term_bgp_debug_neighbor_events,
2599 BGP_DEBUG_NEIGHBOR_EVENTS,
2600 bgp_debug_neighbor_events_peers);
16286195
DS
2601}
2602
d62a17ae 2603int bgp_debug_keepalive(struct peer *peer)
16286195 2604{
d62a17ae 2605 char *host = NULL;
167d390a 2606
d62a17ae 2607 if (peer)
2608 host = peer->host;
167d390a 2609
d62a17ae 2610 return bgp_debug_per_peer(host, term_bgp_debug_keepalive,
2611 BGP_DEBUG_KEEPALIVE,
2612 bgp_debug_keepalive_peers);
16286195
DS
2613}
2614
b8685f9b 2615bool bgp_debug_update(struct peer *peer, const struct prefix *p,
3dc339cd 2616 struct update_group *updgrp, unsigned int inbound)
16286195 2617{
d62a17ae 2618 char *host = NULL;
2619
2620 if (peer)
2621 host = peer->host;
2622
2623 if (inbound) {
2624 if (bgp_debug_per_peer(host, term_bgp_debug_update,
2625 BGP_DEBUG_UPDATE_IN,
2626 bgp_debug_update_in_peers))
3dc339cd 2627 return true;
d62a17ae 2628 }
2629
2630 /* outbound */
2631 else {
2632 if (bgp_debug_per_peer(host, term_bgp_debug_update,
2633 BGP_DEBUG_UPDATE_OUT,
2634 bgp_debug_update_out_peers))
3dc339cd 2635 return true;
d62a17ae 2636
2637 /* Check if update debugging implicitly enabled for the group.
2638 */
2639 if (updgrp && UPDGRP_DBG_ON(updgrp))
3dc339cd 2640 return true;
d62a17ae 2641 }
2642
2643
2644 if (BGP_DEBUG(update, UPDATE_PREFIX)) {
2645 if (bgp_debug_per_prefix(p, term_bgp_debug_update,
2646 BGP_DEBUG_UPDATE_PREFIX,
2647 bgp_debug_update_prefixes))
3dc339cd 2648 return true;
d62a17ae 2649 }
2650
3dc339cd 2651 return false;
16286195
DS
2652}
2653
9bcb3eef 2654bool bgp_debug_bestpath(struct bgp_dest *dest)
9fbdd100 2655{
d62a17ae 2656 if (BGP_DEBUG(bestpath, BESTPATH)) {
cb9f254c 2657 if (bgp_debug_per_prefix(
9bcb3eef 2658 bgp_dest_get_prefix(dest), term_bgp_debug_bestpath,
cb9f254c 2659 BGP_DEBUG_BESTPATH, bgp_debug_bestpath_prefixes))
3dc339cd 2660 return true;
d62a17ae 2661 }
2662
3dc339cd 2663 return false;
9fbdd100
DS
2664}
2665
b8685f9b 2666bool bgp_debug_zebra(const struct prefix *p)
16286195 2667{
d62a17ae 2668 if (BGP_DEBUG(zebra, ZEBRA)) {
2669 if (bgp_debug_per_prefix(p, term_bgp_debug_zebra,
2670 BGP_DEBUG_ZEBRA,
2671 bgp_debug_zebra_prefixes))
3dc339cd 2672 return true;
d62a17ae 2673 }
2674
3dc339cd 2675 return false;
718e3744 2676}
906ad49b 2677
d62a17ae 2678const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi,
5f040085 2679 const struct prefix_rd *prd,
d62a17ae 2680 union prefixconstptr pu,
d7c0a89a
QY
2681 mpls_label_t *label, uint32_t num_labels,
2682 int addpath_valid, uint32_t addpath_id,
6c995628 2683 struct bgp_route_evpn *overlay_index,
b57ba6d2 2684 char *str, int size)
d62a17ae 2685{
2686 char rd_buf[RD_ADDRSTRLEN];
d62a17ae 2687 char tag_buf[30];
6c995628
AD
2688 char overlay_index_buf[INET6_ADDRSTRLEN + 14];
2689 const struct prefix_evpn *evp;
2690
d62a17ae 2691 /* ' with addpath ID ' 17
2692 * max strlen of uint32 + 10
2693 * +/- (just in case) + 1
2694 * null terminator + 1
2695 * ============================ 29 */
2696 char pathid_buf[30];
2697
2698 if (size < BGP_PRD_PATH_STRLEN)
2699 return NULL;
2700
2701 /* Note: Path-id is created by default, but only included in update
2702 * sometimes. */
2703 pathid_buf[0] = '\0';
2704 if (addpath_valid)
2705 snprintf(pathid_buf, sizeof(pathid_buf), " with addpath ID %u",
2706 addpath_id);
2707
6c995628
AD
2708 overlay_index_buf[0] = '\0';
2709 if (overlay_index && overlay_index->type == OVERLAY_INDEX_GATEWAY_IP) {
2710 char obuf[INET6_ADDRSTRLEN];
2711
2712 obuf[0] = '\0';
2713 evp = pu.evp;
2714 if (is_evpn_prefix_ipaddr_v4(evp))
2715 inet_ntop(AF_INET, &overlay_index->gw_ip, obuf,
2716 sizeof(obuf));
2717 else if (is_evpn_prefix_ipaddr_v6(evp))
2718 inet_ntop(AF_INET6, &overlay_index->gw_ip, obuf,
2719 sizeof(obuf));
2720
2721 snprintf(overlay_index_buf, sizeof(overlay_index_buf),
2722 " gateway IP %s", obuf);
2723 }
2724
d62a17ae 2725 tag_buf[0] = '\0';
b57ba6d2 2726 if (bgp_labeled_safi(safi) && num_labels) {
d62a17ae 2727
b57ba6d2
MK
2728 if (safi == SAFI_EVPN) {
2729 char tag_buf2[20];
2730
2731 bgp_evpn_label2str(label, num_labels, tag_buf2, 20);
772270f3
QY
2732 snprintf(tag_buf, sizeof(tag_buf), " label %s",
2733 tag_buf2);
b57ba6d2 2734 } else {
d7c0a89a 2735 uint32_t label_value;
b57ba6d2
MK
2736
2737 label_value = decode_label(label);
772270f3
QY
2738 snprintf(tag_buf, sizeof(tag_buf), " label %u",
2739 label_value);
b57ba6d2 2740 }
d62a17ae 2741 }
2742
2743 if (prd)
6c995628 2744 snprintfrr(str, size, "RD %s %pFX%s%s%s %s %s",
2dbe669b 2745 prefix_rd2str(prd, rd_buf, sizeof(rd_buf)), pu.p,
6c995628
AD
2746 overlay_index_buf, tag_buf, pathid_buf, afi2str(afi),
2747 safi2str(safi));
268e1b9b
PG
2748 else if (safi == SAFI_FLOWSPEC) {
2749 char return_string[BGP_FLOWSPEC_NLRI_STRING_MAX];
2750 const struct prefix_fs *fs = pu.fs;
2751
2752 bgp_fs_nlri_get_string((unsigned char *)fs->prefix.ptr,
2753 fs->prefix.prefixlen,
2754 return_string,
1840384b
PG
2755 NLRI_STRING_FORMAT_DEBUG, NULL,
2756 family2afi(fs->prefix.family));
268e1b9b
PG
2757 snprintf(str, size, "FS %s Match{%s}", afi2str(afi),
2758 return_string);
2759 } else
2dbe669b
DA
2760 snprintfrr(str, size, "%pFX%s%s %s %s", pu.p, tag_buf,
2761 pathid_buf, afi2str(afi), safi2str(safi));
d62a17ae 2762
2763 return str;
906ad49b 2764}