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