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