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