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