]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_debug.c
Merge pull request #11197 from opensourcerouting/feature/gr_notification_docs
[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;
9b01d289
DA
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) {
6006b807 642 memset(&ip, 0, sizeof(ip));
377e3565 643
9b01d289 644 if (argv_find(argv, argc, "mac", &mac_idx))
7aad5e6a
DA
645 if (!prefix_str2mac(argv[mac_idx + 1]->arg, &mac)) {
646 vty_out(vty, "%% Malformed MAC address\n");
647 return CMD_WARNING;
648 }
377e3565 649
9b01d289 650 if (argv_find(argv, argc, "ip", &ip_idx))
7aad5e6a
DA
651 if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
652 vty_out(vty, "%% Malformed IP address\n");
653 return CMD_WARNING;
654 }
81cf0de5
CS
655
656 build_evpn_type2_prefix((struct prefix_evpn *)argv_p,
657 &mac, &ip);
658 } else if (evpn_type == BGP_EVPN_IMET_ROUTE) {
6006b807 659 memset(&ip, 0, sizeof(ip));
377e3565 660
9b01d289 661 if (argv_find(argv, argc, "ip", &ip_idx))
7aad5e6a
DA
662 if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
663 vty_out(vty, "%% Malformed IP address\n");
664 return CMD_WARNING;
665 }
377e3565 666
81cf0de5
CS
667 build_evpn_type3_prefix((struct prefix_evpn *)argv_p,
668 ip.ipaddr_v4);
669 } else if (evpn_type == BGP_EVPN_IP_PREFIX_ROUTE) {
670 struct prefix ip_prefix;
671
6006b807 672 memset(&ip_prefix, 0, sizeof(ip_prefix));
81cf0de5
CS
673 if (argv_find(argv, argc, "ip", &ip_idx)) {
674 (void)str2prefix(argv[ip_idx + 1]->arg, &ip_prefix);
675 apply_mask(&ip_prefix);
676 }
677 build_type5_prefix_from_ip_prefix(
678 (struct prefix_evpn *)argv_p,
679 &ip_prefix);
680 }
681
682 return CMD_SUCCESS;
683}
3f9c7369 684
718e3744 685/* Debug option setting interface. */
686unsigned long bgp_debug_option = 0;
687
d62a17ae 688int debug(unsigned int option)
718e3744 689{
d62a17ae 690 return bgp_debug_option & option;
718e3744 691}
692
0b2aa3a0
PJ
693DEFUN (debug_bgp_as4,
694 debug_bgp_as4_cmd,
695 "debug bgp as4",
696 DEBUG_STR
697 BGP_STR
698 "BGP AS4 actions\n")
699{
d62a17ae 700 if (vty->node == CONFIG_NODE)
701 DEBUG_ON(as4, AS4);
702 else {
703 TERM_DEBUG_ON(as4, AS4);
704 vty_out(vty, "BGP as4 debugging is on\n");
705 }
706 return CMD_SUCCESS;
0b2aa3a0
PJ
707}
708
709DEFUN (no_debug_bgp_as4,
710 no_debug_bgp_as4_cmd,
711 "no debug bgp as4",
712 NO_STR
713 DEBUG_STR
714 BGP_STR
715 "BGP AS4 actions\n")
716{
d62a17ae 717 if (vty->node == CONFIG_NODE)
718 DEBUG_OFF(as4, AS4);
719 else {
720 TERM_DEBUG_OFF(as4, AS4);
721 vty_out(vty, "BGP as4 debugging is off\n");
722 }
723 return CMD_SUCCESS;
0b2aa3a0
PJ
724}
725
0b2aa3a0
PJ
726DEFUN (debug_bgp_as4_segment,
727 debug_bgp_as4_segment_cmd,
728 "debug bgp as4 segment",
729 DEBUG_STR
730 BGP_STR
6e22b901 731 "BGP AS4 actions\n"
0b2aa3a0
PJ
732 "BGP AS4 aspath segment handling\n")
733{
d62a17ae 734 if (vty->node == CONFIG_NODE)
735 DEBUG_ON(as4, AS4_SEGMENT);
736 else {
737 TERM_DEBUG_ON(as4, AS4_SEGMENT);
738 vty_out(vty, "BGP as4 segment debugging is on\n");
739 }
740 return CMD_SUCCESS;
0b2aa3a0
PJ
741}
742
743DEFUN (no_debug_bgp_as4_segment,
744 no_debug_bgp_as4_segment_cmd,
745 "no debug bgp as4 segment",
746 NO_STR
747 DEBUG_STR
748 BGP_STR
6e22b901 749 "BGP AS4 actions\n"
0b2aa3a0
PJ
750 "BGP AS4 aspath segment handling\n")
751{
d62a17ae 752 if (vty->node == CONFIG_NODE)
753 DEBUG_OFF(as4, AS4_SEGMENT);
754 else {
755 TERM_DEBUG_OFF(as4, AS4_SEGMENT);
756 vty_out(vty, "BGP as4 segment debugging is off\n");
757 }
758 return CMD_SUCCESS;
0b2aa3a0
PJ
759}
760
16286195
DS
761/* debug bgp neighbor_events */
762DEFUN (debug_bgp_neighbor_events,
763 debug_bgp_neighbor_events_cmd,
764 "debug bgp neighbor-events",
718e3744 765 DEBUG_STR
766 BGP_STR
16286195 767 "BGP Neighbor Events\n")
718e3744 768{
d62a17ae 769 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
770
771 if (vty->node == CONFIG_NODE)
772 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
773 else {
774 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
775 vty_out(vty, "BGP neighbor-events debugging is on\n");
776 }
777 return CMD_SUCCESS;
718e3744 778}
779
16286195
DS
780DEFUN (debug_bgp_neighbor_events_peer,
781 debug_bgp_neighbor_events_peer_cmd,
6147e2c6 782 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
718e3744 783 DEBUG_STR
784 BGP_STR
16286195
DS
785 "BGP Neighbor Events\n"
786 "BGP neighbor IP address to debug\n"
787 "BGP IPv6 neighbor to debug\n"
788 "BGP neighbor on interface to debug\n")
718e3744 789{
d62a17ae 790 int idx_peer = 3;
791 const char *host = argv[idx_peer]->arg;
792
793 if (!bgp_debug_neighbor_events_peers)
794 bgp_debug_neighbor_events_peers = list_new();
795
796 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host,
797 NULL)) {
798 vty_out(vty,
799 "BGP neighbor-events debugging is already enabled for %s\n",
800 host);
801 return CMD_SUCCESS;
802 }
803
804 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL);
805
806 if (vty->node == CONFIG_NODE)
807 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
808 else {
809 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
810 vty_out(vty, "BGP neighbor-events debugging is on for %s\n",
811 host);
812 }
813 return CMD_SUCCESS;
718e3744 814}
815
16286195
DS
816DEFUN (no_debug_bgp_neighbor_events,
817 no_debug_bgp_neighbor_events_cmd,
818 "no debug bgp neighbor-events",
819 NO_STR
718e3744 820 DEBUG_STR
821 BGP_STR
16286195 822 "Neighbor Events\n")
718e3744 823{
d62a17ae 824 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
825
826 if (vty->node == CONFIG_NODE)
827 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
828 else {
829 TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
830 vty_out(vty, "BGP neighbor-events debugging is off\n");
831 }
832 return CMD_SUCCESS;
718e3744 833}
834
16286195
DS
835DEFUN (no_debug_bgp_neighbor_events_peer,
836 no_debug_bgp_neighbor_events_peer_cmd,
6147e2c6 837 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
718e3744 838 NO_STR
839 DEBUG_STR
840 BGP_STR
16286195
DS
841 "Neighbor Events\n"
842 "BGP neighbor IP address to debug\n"
843 "BGP IPv6 neighbor to debug\n"
844 "BGP neighbor on interface to debug\n")
718e3744 845{
d62a17ae 846 int idx_peer = 4;
847 int found_peer = 0;
848 const char *host = argv[idx_peer]->arg;
849
850 if (bgp_debug_neighbor_events_peers
851 && !list_isempty(bgp_debug_neighbor_events_peers)) {
852 found_peer = bgp_debug_list_remove_entry(
853 bgp_debug_neighbor_events_peers, host, NULL);
854
855 if (list_isempty(bgp_debug_neighbor_events_peers)) {
856 if (vty->node == CONFIG_NODE)
857 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
858 else
859 TERM_DEBUG_OFF(neighbor_events,
860 NEIGHBOR_EVENTS);
861 }
862 }
863
864 if (found_peer)
865 vty_out(vty, "BGP neighbor-events debugging is off for %s\n",
866 host);
867 else
868 vty_out(vty,
869 "BGP neighbor-events debugging was not enabled for %s\n",
870 host);
871
872 return CMD_SUCCESS;
718e3744 873}
874
16286195 875/* debug bgp nht */
fb018d25
DS
876DEFUN (debug_bgp_nht,
877 debug_bgp_nht_cmd,
878 "debug bgp nht",
879 DEBUG_STR
880 BGP_STR
881 "BGP nexthop tracking events\n")
882{
d62a17ae 883 if (vty->node == CONFIG_NODE)
884 DEBUG_ON(nht, NHT);
885 else {
886 TERM_DEBUG_ON(nht, NHT);
887 vty_out(vty, "BGP nexthop tracking debugging is on\n");
888 }
889 return CMD_SUCCESS;
fb018d25
DS
890}
891
892DEFUN (no_debug_bgp_nht,
893 no_debug_bgp_nht_cmd,
894 "no debug bgp nht",
895 NO_STR
896 DEBUG_STR
897 BGP_STR
898 "BGP nexthop tracking events\n")
899{
d62a17ae 900 if (vty->node == CONFIG_NODE)
901 DEBUG_OFF(nht, NHT);
902 else {
903 TERM_DEBUG_OFF(nht, NHT);
904 vty_out(vty, "BGP nexthop tracking debugging is off\n");
905 }
906 return CMD_SUCCESS;
fb018d25
DS
907}
908
16286195
DS
909/* debug bgp keepalives */
910DEFUN (debug_bgp_keepalive,
911 debug_bgp_keepalive_cmd,
912 "debug bgp keepalives",
718e3744 913 DEBUG_STR
914 BGP_STR
16286195 915 "BGP keepalives\n")
718e3744 916{
d62a17ae 917 bgp_debug_list_free(bgp_debug_keepalive_peers);
918
919 if (vty->node == CONFIG_NODE)
920 DEBUG_ON(keepalive, KEEPALIVE);
921 else {
922 TERM_DEBUG_ON(keepalive, KEEPALIVE);
923 vty_out(vty, "BGP keepalives debugging is on\n");
924 }
925 return CMD_SUCCESS;
718e3744 926}
927
16286195
DS
928DEFUN (debug_bgp_keepalive_peer,
929 debug_bgp_keepalive_peer_cmd,
6147e2c6 930 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
718e3744 931 DEBUG_STR
932 BGP_STR
bc6bc7a8
DA
933 "BGP keepalives\n"
934 "BGP IPv4 neighbor to debug\n"
16286195
DS
935 "BGP IPv6 neighbor to debug\n"
936 "BGP neighbor on interface to debug\n")
718e3744 937{
d62a17ae 938 int idx_peer = 3;
939 const char *host = argv[idx_peer]->arg;
940
941 if (!bgp_debug_keepalive_peers)
942 bgp_debug_keepalive_peers = list_new();
943
944 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL)) {
945 vty_out(vty,
946 "BGP keepalive debugging is already enabled for %s\n",
947 host);
948 return CMD_SUCCESS;
949 }
950
951 bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL);
952
953 if (vty->node == CONFIG_NODE)
954 DEBUG_ON(keepalive, KEEPALIVE);
955 else {
956 TERM_DEBUG_ON(keepalive, KEEPALIVE);
957 vty_out(vty, "BGP keepalives debugging is on for %s\n", host);
958 }
959 return CMD_SUCCESS;
718e3744 960}
961
962DEFUN (no_debug_bgp_keepalive,
963 no_debug_bgp_keepalive_cmd,
964 "no debug bgp keepalives",
965 NO_STR
966 DEBUG_STR
967 BGP_STR
968 "BGP keepalives\n")
969{
d62a17ae 970 bgp_debug_list_free(bgp_debug_keepalive_peers);
971
972 if (vty->node == CONFIG_NODE)
973 DEBUG_OFF(keepalive, KEEPALIVE);
974 else {
975 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
976 vty_out(vty, "BGP keepalives debugging is off\n");
977 }
978 return CMD_SUCCESS;
718e3744 979}
980
16286195
DS
981DEFUN (no_debug_bgp_keepalive_peer,
982 no_debug_bgp_keepalive_peer_cmd,
6147e2c6 983 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
16286195
DS
984 NO_STR
985 DEBUG_STR
718e3744 986 BGP_STR
16286195
DS
987 "BGP keepalives\n"
988 "BGP neighbor IP address to debug\n"
989 "BGP IPv6 neighbor to debug\n"
990 "BGP neighbor on interface to debug\n")
991{
d62a17ae 992 int idx_peer = 4;
993 int found_peer = 0;
994 const char *host = argv[idx_peer]->arg;
995
996 if (bgp_debug_keepalive_peers
997 && !list_isempty(bgp_debug_keepalive_peers)) {
998 found_peer = bgp_debug_list_remove_entry(
999 bgp_debug_keepalive_peers, host, NULL);
1000
1001 if (list_isempty(bgp_debug_keepalive_peers)) {
1002 if (vty->node == CONFIG_NODE)
1003 DEBUG_OFF(keepalive, KEEPALIVE);
1004 else
1005 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
1006 }
1007 }
1008
1009 if (found_peer)
1010 vty_out(vty, "BGP keepalives debugging is off for %s\n", host);
1011 else
1012 vty_out(vty,
1013 "BGP keepalives debugging was not enabled for %s\n",
1014 host);
1015
1016 return CMD_SUCCESS;
16286195
DS
1017}
1018
9fbdd100 1019/* debug bgp bestpath */
ffd71765 1020DEFUN (debug_bgp_bestpath_prefix,
9fbdd100 1021 debug_bgp_bestpath_prefix_cmd,
ffd71765 1022 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
9fbdd100
DS
1023 DEBUG_STR
1024 BGP_STR
1025 "BGP bestpath\n"
0c7b1b01
QY
1026 "IPv4 prefix\n"
1027 "IPv6 prefix\n")
9fbdd100 1028{
0be4b77c
DW
1029 struct prefix *argv_p;
1030 int idx_ipv4_ipv6_prefixlen = 3;
1031
1032 argv_p = prefix_new();
ffd71765 1033 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c
DW
1034 apply_mask(argv_p);
1035
d62a17ae 1036 if (!bgp_debug_bestpath_prefixes)
1037 bgp_debug_bestpath_prefixes = list_new();
1038
1039 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL,
ffd71765 1040 argv_p)) {
d62a17ae 1041 vty_out(vty,
1042 "BGP bestpath debugging is already enabled for %s\n",
ffd71765 1043 argv[idx_ipv4_ipv6_prefixlen]->arg);
d62a17ae 1044 return CMD_SUCCESS;
1045 }
1046
ffd71765 1047 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, argv_p);
d62a17ae 1048
1049 if (vty->node == CONFIG_NODE) {
1050 DEBUG_ON(bestpath, BESTPATH);
1051 } else {
1052 TERM_DEBUG_ON(bestpath, BESTPATH);
1053 vty_out(vty, "BGP bestpath debugging is on for %s\n",
ffd71765 1054 argv[idx_ipv4_ipv6_prefixlen]->arg);
d62a17ae 1055 }
1056
1057 return CMD_SUCCESS;
9fbdd100
DS
1058}
1059
1060DEFUN (no_debug_bgp_bestpath_prefix,
1061 no_debug_bgp_bestpath_prefix_cmd,
6147e2c6 1062 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
9fbdd100
DS
1063 NO_STR
1064 DEBUG_STR
1065 BGP_STR
1066 "BGP bestpath\n"
0c7b1b01
QY
1067 "IPv4 prefix\n"
1068 "IPv6 prefix\n")
9fbdd100 1069{
d62a17ae 1070 int idx_ipv4_ipv6_prefixlen = 4;
1071 struct prefix *argv_p;
1072 int found_prefix = 0;
d62a17ae 1073
1074 argv_p = prefix_new();
ffd71765 1075 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1076 apply_mask(argv_p);
d62a17ae 1077
1078 if (bgp_debug_bestpath_prefixes
1079 && !list_isempty(bgp_debug_bestpath_prefixes)) {
1080 found_prefix = bgp_debug_list_remove_entry(
1081 bgp_debug_bestpath_prefixes, NULL, argv_p);
1082
1083 if (list_isempty(bgp_debug_bestpath_prefixes)) {
1084 if (vty->node == CONFIG_NODE) {
1085 DEBUG_OFF(bestpath, BESTPATH);
1086 } else {
1087 TERM_DEBUG_OFF(bestpath, BESTPATH);
1088 vty_out(vty,
1089 "BGP bestpath debugging (per prefix) is off\n");
1090 }
1091 }
1092 }
1093
1094 if (found_prefix)
1095 vty_out(vty, "BGP bestpath debugging is off for %s\n",
1096 argv[idx_ipv4_ipv6_prefixlen]->arg);
1097 else
1098 vty_out(vty, "BGP bestpath debugging was not enabled for %s\n",
1099 argv[idx_ipv4_ipv6_prefixlen]->arg);
1100
1101 return CMD_SUCCESS;
9fbdd100
DS
1102}
1103
1104DEFUN (no_debug_bgp_bestpath,
1105 no_debug_bgp_bestpath_cmd,
1106 "no debug bgp bestpath",
1107 NO_STR
1108 DEBUG_STR
1109 BGP_STR
1110 "BGP bestpath\n")
1111{
d62a17ae 1112 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
1113
1114 if (vty->node == CONFIG_NODE)
1115 DEBUG_OFF(bestpath, BESTPATH);
1116 else {
1117 TERM_DEBUG_OFF(bestpath, BESTPATH);
1118 vty_out(vty, "BGP bestpath debugging is off\n");
1119 }
1120 return CMD_SUCCESS;
9fbdd100
DS
1121}
1122
16286195 1123/* debug bgp updates */
718e3744 1124DEFUN (debug_bgp_update,
1125 debug_bgp_update_cmd,
1126 "debug bgp updates",
1127 DEBUG_STR
1128 BGP_STR
1129 "BGP updates\n")
1130{
d62a17ae 1131 bgp_debug_list_free(bgp_debug_update_in_peers);
1132 bgp_debug_list_free(bgp_debug_update_out_peers);
1133 bgp_debug_list_free(bgp_debug_update_prefixes);
1134
1135 if (vty->node == CONFIG_NODE) {
1136 DEBUG_ON(update, UPDATE_IN);
1137 DEBUG_ON(update, UPDATE_OUT);
1138 } else {
1139 TERM_DEBUG_ON(update, UPDATE_IN);
1140 TERM_DEBUG_ON(update, UPDATE_OUT);
1141 vty_out(vty, "BGP updates debugging is on\n");
1142 }
1143 return CMD_SUCCESS;
718e3744 1144}
1145
1146DEFUN (debug_bgp_update_direct,
1147 debug_bgp_update_direct_cmd,
6147e2c6 1148 "debug bgp updates <in|out>",
718e3744 1149 DEBUG_STR
1150 BGP_STR
1151 "BGP updates\n"
1152 "Inbound updates\n"
1153 "Outbound updates\n")
1154{
d62a17ae 1155 int idx_in_out = 3;
1156
1157 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1158 bgp_debug_list_free(bgp_debug_update_in_peers);
1159 else
1160 bgp_debug_list_free(bgp_debug_update_out_peers);
1161
1162 if (vty->node == CONFIG_NODE) {
1163 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1164 DEBUG_ON(update, UPDATE_IN);
1165 else
1166 DEBUG_ON(update, UPDATE_OUT);
1167 } else {
1168 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
1169 TERM_DEBUG_ON(update, UPDATE_IN);
1170 vty_out(vty, "BGP updates debugging is on (inbound)\n");
1171 } else {
1172 TERM_DEBUG_ON(update, UPDATE_OUT);
1173 vty_out(vty,
1174 "BGP updates debugging is on (outbound)\n");
1175 }
1176 }
1177 return CMD_SUCCESS;
718e3744 1178}
1179
16286195
DS
1180DEFUN (debug_bgp_update_direct_peer,
1181 debug_bgp_update_direct_peer_cmd,
6147e2c6 1182 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
718e3744 1183 DEBUG_STR
1184 BGP_STR
16286195
DS
1185 "BGP updates\n"
1186 "Inbound updates\n"
1187 "Outbound updates\n"
1188 "BGP neighbor IP address to debug\n"
1189 "BGP IPv6 neighbor to debug\n"
1190 "BGP neighbor on interface to debug\n")
718e3744 1191{
d62a17ae 1192 int idx_in_out = 3;
1193 int idx_peer = 4;
1194 const char *host = argv[idx_peer]->arg;
1195 int inbound;
1196
1197 if (!bgp_debug_update_in_peers)
1198 bgp_debug_update_in_peers = list_new();
1199
1200 if (!bgp_debug_update_out_peers)
1201 bgp_debug_update_out_peers = list_new();
1202
1203 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1204 inbound = 1;
1205 else
1206 inbound = 0;
1207
1208 if (inbound) {
1209 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, host,
1210 NULL)) {
1211 vty_out(vty,
1212 "BGP inbound update debugging is already enabled for %s\n",
1213 host);
1214 return CMD_SUCCESS;
1215 }
1216 }
1217
1218 else {
1219 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host,
1220 NULL)) {
1221 vty_out(vty,
1222 "BGP outbound update debugging is already enabled for %s\n",
1223 host);
1224 return CMD_SUCCESS;
1225 }
1226 }
1227
1228 if (inbound)
1229 bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL);
1230 else {
1231 struct peer *peer;
1232 struct peer_af *paf;
1233 int afidx;
1234
1235 bgp_debug_list_add_entry(bgp_debug_update_out_peers, host,
1236 NULL);
1237 peer = bgp_find_peer(vty, host);
1238
1239 if (peer) {
1240 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
1241 afidx++) {
1242 paf = peer->peer_af_array[afidx];
1243 if (paf != NULL) {
1244 if (PAF_SUBGRP(paf)) {
1245 UPDGRP_PEER_DBG_EN(
1246 PAF_SUBGRP(paf)
1247 ->update_group);
1248 }
1249 }
1250 }
1251 }
1252 }
1253
1254 if (vty->node == CONFIG_NODE) {
1255 if (inbound)
1256 DEBUG_ON(update, UPDATE_IN);
1257 else
1258 DEBUG_ON(update, UPDATE_OUT);
1259 } else {
1260 if (inbound) {
1261 TERM_DEBUG_ON(update, UPDATE_IN);
1262 vty_out(vty,
1263 "BGP updates debugging is on (inbound) for %s\n",
1264 argv[idx_peer]->arg);
1265 } else {
1266 TERM_DEBUG_ON(update, UPDATE_OUT);
1267 vty_out(vty,
1268 "BGP updates debugging is on (outbound) for %s\n",
1269 argv[idx_peer]->arg);
1270 }
1271 }
1272 return CMD_SUCCESS;
718e3744 1273}
1274
91ba2c8b
DS
1275DEFUN (no_debug_bgp_update_direct,
1276 no_debug_bgp_update_direct_cmd,
6147e2c6 1277 "no debug bgp updates <in|out>",
91ba2c8b
DS
1278 NO_STR
1279 DEBUG_STR
1280 BGP_STR
1281 "BGP updates\n"
1282 "Inbound updates\n"
1283 "Outbound updates\n")
1284{
d62a17ae 1285 int idx_in_out = 4;
1286 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
1287 bgp_debug_list_free(bgp_debug_update_in_peers);
1288
1289 if (vty->node == CONFIG_NODE) {
1290 DEBUG_OFF(update, UPDATE_IN);
1291 } else {
1292 TERM_DEBUG_OFF(update, UPDATE_IN);
1293 vty_out(vty,
1294 "BGP updates debugging is off (inbound)\n");
1295 }
1296 } else {
1297 bgp_debug_list_free(bgp_debug_update_out_peers);
1298
1299 if (vty->node == CONFIG_NODE) {
1300 DEBUG_OFF(update, UPDATE_OUT);
1301 } else {
1302 TERM_DEBUG_OFF(update, UPDATE_OUT);
1303 vty_out(vty,
1304 "BGP updates debugging is off (outbound)\n");
1305 }
1306 }
1307
1308 return CMD_SUCCESS;
91ba2c8b
DS
1309}
1310
16286195
DS
1311DEFUN (no_debug_bgp_update_direct_peer,
1312 no_debug_bgp_update_direct_peer_cmd,
6147e2c6 1313 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
16286195
DS
1314 NO_STR
1315 DEBUG_STR
718e3744 1316 BGP_STR
16286195
DS
1317 "BGP updates\n"
1318 "Inbound updates\n"
1319 "Outbound updates\n"
1320 "BGP neighbor IP address to debug\n"
1321 "BGP IPv6 neighbor to debug\n"
1322 "BGP neighbor on interface to debug\n")
1323{
d62a17ae 1324 int idx_in_out = 4;
1325 int idx_peer = 5;
1326 int inbound;
1327 int found_peer = 0;
1328 const char *host = argv[idx_peer]->arg;
1329
1330 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1331 inbound = 1;
1332 else
1333 inbound = 0;
1334
1335 if (inbound && bgp_debug_update_in_peers
1336 && !list_isempty(bgp_debug_update_in_peers)) {
1337 found_peer = bgp_debug_list_remove_entry(
1338 bgp_debug_update_in_peers, host, NULL);
1339
1340 if (list_isempty(bgp_debug_update_in_peers)) {
1341 if (vty->node == CONFIG_NODE)
1342 DEBUG_OFF(update, UPDATE_IN);
1343 else {
1344 TERM_DEBUG_OFF(update, UPDATE_IN);
1345 vty_out(vty,
1346 "BGP updates debugging (inbound) is off\n");
1347 }
1348 }
1349 }
1350
1351 if (!inbound && bgp_debug_update_out_peers
1352 && !list_isempty(bgp_debug_update_out_peers)) {
1353 found_peer = bgp_debug_list_remove_entry(
1354 bgp_debug_update_out_peers, host, NULL);
1355
1356 if (list_isempty(bgp_debug_update_out_peers)) {
1357 if (vty->node == CONFIG_NODE)
1358 DEBUG_OFF(update, UPDATE_OUT);
1359 else {
1360 TERM_DEBUG_OFF(update, UPDATE_OUT);
1361 vty_out(vty,
1362 "BGP updates debugging (outbound) is off\n");
1363 }
1364 }
1365
1366 struct peer *peer;
1367 struct peer_af *paf;
1368 int afidx;
1369 peer = bgp_find_peer(vty, host);
1370
1371 if (peer) {
1372 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
1373 afidx++) {
1374 paf = peer->peer_af_array[afidx];
1375 if (paf != NULL) {
1376 if (PAF_SUBGRP(paf)) {
1377 UPDGRP_PEER_DBG_DIS(
1378 PAF_SUBGRP(paf)
1379 ->update_group);
1380 }
1381 }
1382 }
1383 }
1384 }
1385
1386 if (found_peer)
1387 if (inbound)
1388 vty_out(vty,
1389 "BGP updates debugging (inbound) is off for %s\n",
1390 host);
1391 else
1392 vty_out(vty,
1393 "BGP updates debugging (outbound) is off for %s\n",
1394 host);
1395 else if (inbound)
1396 vty_out(vty,
1397 "BGP updates debugging (inbound) was not enabled for %s\n",
1398 host);
1399 else
1400 vty_out(vty,
1401 "BGP updates debugging (outbound) was not enabled for %s\n",
1402 host);
1403
1404 return CMD_SUCCESS;
16286195
DS
1405}
1406
81cf0de5
CS
1407#ifndef VTYSH_EXTRACT_PL
1408#include "bgpd/bgp_debug_clippy.c"
1409#endif
1410
1411DEFPY (debug_bgp_update_prefix_afi_safi,
1412 debug_bgp_update_prefix_afi_safi_cmd,
15dc08a6 1413 "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
1414 DEBUG_STR
1415 BGP_STR
1416 "BGP updates\n"
1417 "Specify a prefix to debug\n"
377e3565
QY
1418 L2VPN_HELP_STR
1419 EVPN_HELP_STR
31782fea
SW
1420 EVPN_TYPE_HELP_STR
1421 EVPN_TYPE_2_HELP_STR
15dc08a6 1422 EVPN_TYPE_2_HELP_STR
377e3565
QY
1423 MAC_STR MAC_STR MAC_STR
1424 IP_STR
1425 "IPv4 address\n"
1426 "IPv6 address\n"
31782fea 1427 EVPN_TYPE_3_HELP_STR
15dc08a6 1428 EVPN_TYPE_3_HELP_STR
377e3565
QY
1429 IP_STR
1430 "IPv4 address\n"
1431 "IPv6 address\n"
31782fea 1432 EVPN_TYPE_5_HELP_STR
15dc08a6 1433 EVPN_TYPE_5_HELP_STR
377e3565
QY
1434 IP_STR
1435 "IPv4 prefix\n"
1436 "IPv6 prefix\n")
81cf0de5 1437{
81cf0de5
CS
1438 struct prefix *argv_p;
1439 int ret = CMD_SUCCESS;
81cf0de5
CS
1440
1441 argv_p = prefix_new();
1442
377e3565
QY
1443 ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
1444 if (ret != CMD_SUCCESS) {
63265b5c 1445 prefix_free(&argv_p);
377e3565 1446 return ret;
81cf0de5
CS
1447 }
1448
1449 if (!bgp_debug_update_prefixes)
1450 bgp_debug_update_prefixes = list_new();
1451
1452 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) {
1453 vty_out(vty,
2dbe669b
DA
1454 "BGP updates debugging is already enabled for %pFX\n",
1455 argv_p);
63265b5c 1456 prefix_free(&argv_p);
377e3565 1457 return CMD_SUCCESS;
81cf0de5
CS
1458 }
1459
1460 bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p);
1461
1462 if (vty->node == CONFIG_NODE) {
1463 DEBUG_ON(update, UPDATE_PREFIX);
1464 } else {
1465 TERM_DEBUG_ON(update, UPDATE_PREFIX);
2dbe669b 1466 vty_out(vty, "BGP updates debugging is on for %pFX\n", argv_p);
81cf0de5
CS
1467 }
1468
63265b5c 1469 prefix_free(&argv_p);
360f9703 1470
377e3565 1471 return CMD_SUCCESS;
81cf0de5
CS
1472}
1473
1474DEFPY (no_debug_bgp_update_prefix_afi_safi,
1475 no_debug_bgp_update_prefix_afi_safi_cmd,
15dc08a6 1476 "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
1477 NO_STR
1478 DEBUG_STR
1479 BGP_STR
1480 "BGP updates\n"
1481 "Specify a prefix to debug\n"
377e3565
QY
1482 L2VPN_HELP_STR
1483 EVPN_HELP_STR
31782fea
SW
1484 EVPN_TYPE_HELP_STR
1485 EVPN_TYPE_2_HELP_STR
15dc08a6 1486 EVPN_TYPE_2_HELP_STR
377e3565
QY
1487 MAC_STR MAC_STR MAC_STR
1488 IP_STR
1489 "IPv4 address\n"
1490 "IPv6 address\n"
31782fea 1491 EVPN_TYPE_3_HELP_STR
15dc08a6 1492 EVPN_TYPE_3_HELP_STR
377e3565
QY
1493 IP_STR
1494 "IPv4 address\n"
1495 "IPv6 address\n"
31782fea 1496 EVPN_TYPE_5_HELP_STR
15dc08a6 1497 EVPN_TYPE_5_HELP_STR
377e3565
QY
1498 IP_STR
1499 "IPv4 prefix\n"
1500 "IPv6 prefix\n")
81cf0de5 1501{
81cf0de5 1502 struct prefix *argv_p;
377e3565 1503 bool found_prefix = false;
81cf0de5 1504 int ret = CMD_SUCCESS;
81cf0de5
CS
1505
1506 argv_p = prefix_new();
1507
377e3565
QY
1508 ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
1509 if (ret != CMD_SUCCESS) {
63265b5c 1510 prefix_free(&argv_p);
377e3565 1511 return ret;
81cf0de5
CS
1512 }
1513
1514 if (bgp_debug_update_prefixes
1515 && !list_isempty(bgp_debug_update_prefixes)) {
1516 found_prefix = bgp_debug_list_remove_entry(
1517 bgp_debug_update_prefixes, NULL, argv_p);
1518
1519 if (list_isempty(bgp_debug_update_prefixes)) {
1520 if (vty->node == CONFIG_NODE) {
1521 DEBUG_OFF(update, UPDATE_PREFIX);
1522 } else {
1523 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1524 vty_out(vty,
1525 "BGP updates debugging (per prefix) is off\n");
1526 }
1527 }
1528 }
1529
1530 if (found_prefix)
2dbe669b 1531 vty_out(vty, "BGP updates debugging is off for %pFX\n", argv_p);
81cf0de5 1532 else
2dbe669b
DA
1533 vty_out(vty, "BGP updates debugging was not enabled for %pFX\n",
1534 argv_p);
81cf0de5 1535
63265b5c 1536 prefix_free(&argv_p);
360f9703
A
1537
1538 return ret;
81cf0de5
CS
1539}
1540
1541
16286195
DS
1542DEFUN (debug_bgp_update_prefix,
1543 debug_bgp_update_prefix_cmd,
6147e2c6 1544 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
718e3744 1545 DEBUG_STR
16286195
DS
1546 BGP_STR
1547 "BGP updates\n"
1548 "Specify a prefix to debug\n"
0c7b1b01
QY
1549 "IPv4 prefix\n"
1550 "IPv6 prefix\n")
718e3744 1551{
d62a17ae 1552 int idx_ipv4_ipv6_prefixlen = 4;
1553 struct prefix *argv_p;
d62a17ae 1554
1555 argv_p = prefix_new();
ffd71765 1556 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1557 apply_mask(argv_p);
d62a17ae 1558
1559 if (!bgp_debug_update_prefixes)
1560 bgp_debug_update_prefixes = list_new();
1561
1562 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) {
1563 vty_out(vty,
1564 "BGP updates debugging is already enabled for %s\n",
1565 argv[idx_ipv4_ipv6_prefixlen]->arg);
1566 return CMD_SUCCESS;
1567 }
1568
1569 bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p);
1570
1571 if (vty->node == CONFIG_NODE) {
1572 DEBUG_ON(update, UPDATE_PREFIX);
1573 } else {
1574 TERM_DEBUG_ON(update, UPDATE_PREFIX);
1575 vty_out(vty, "BGP updates debugging is on for %s\n",
1576 argv[idx_ipv4_ipv6_prefixlen]->arg);
1577 }
1578
1579 return CMD_SUCCESS;
718e3744 1580}
1581
16286195
DS
1582DEFUN (no_debug_bgp_update_prefix,
1583 no_debug_bgp_update_prefix_cmd,
6147e2c6 1584 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
718e3744 1585 NO_STR
1586 DEBUG_STR
16286195
DS
1587 BGP_STR
1588 "BGP updates\n"
1589 "Specify a prefix to debug\n"
0c7b1b01
QY
1590 "IPv4 prefix\n"
1591 "IPv6 prefix\n")
16286195 1592{
d62a17ae 1593 int idx_ipv4_ipv6_prefixlen = 5;
1594 struct prefix *argv_p;
1595 int found_prefix = 0;
d62a17ae 1596
1597 argv_p = prefix_new();
ffd71765 1598 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1599 apply_mask(argv_p);
d62a17ae 1600
1601 if (bgp_debug_update_prefixes
1602 && !list_isempty(bgp_debug_update_prefixes)) {
1603 found_prefix = bgp_debug_list_remove_entry(
1604 bgp_debug_update_prefixes, NULL, argv_p);
1605
1606 if (list_isempty(bgp_debug_update_prefixes)) {
1607 if (vty->node == CONFIG_NODE) {
1608 DEBUG_OFF(update, UPDATE_PREFIX);
1609 } else {
1610 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1611 vty_out(vty,
1612 "BGP updates debugging (per prefix) is off\n");
1613 }
1614 }
1615 }
1616
1617 if (found_prefix)
1618 vty_out(vty, "BGP updates debugging is off for %s\n",
1619 argv[idx_ipv4_ipv6_prefixlen]->arg);
1620 else
1621 vty_out(vty, "BGP updates debugging was not enabled for %s\n",
1622 argv[idx_ipv4_ipv6_prefixlen]->arg);
1623
1624 return CMD_SUCCESS;
16286195
DS
1625}
1626
1627DEFUN (no_debug_bgp_update,
1628 no_debug_bgp_update_cmd,
1629 "no debug bgp updates",
1630 NO_STR
1631 DEBUG_STR
1632 BGP_STR
1633 "BGP updates\n")
718e3744 1634{
87f42c2c
QY
1635 struct listnode *ln;
1636 struct bgp *bgp;
1637
d62a17ae 1638 bgp_debug_list_free(bgp_debug_update_in_peers);
1639 bgp_debug_list_free(bgp_debug_update_out_peers);
1640 bgp_debug_list_free(bgp_debug_update_prefixes);
1641
87f42c2c
QY
1642 for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
1643 bgp_debug_clear_updgrp_update_dbg(bgp);
d62a17ae 1644
1645 if (vty->node == CONFIG_NODE) {
1646 DEBUG_OFF(update, UPDATE_IN);
1647 DEBUG_OFF(update, UPDATE_OUT);
1648 DEBUG_OFF(update, UPDATE_PREFIX);
1649 } else {
1650 TERM_DEBUG_OFF(update, UPDATE_IN);
1651 TERM_DEBUG_OFF(update, UPDATE_OUT);
1652 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1653 vty_out(vty, "BGP updates debugging is off\n");
1654 }
1655 return CMD_SUCCESS;
718e3744 1656}
1657
16286195 1658/* debug bgp zebra */
a39275d7
AS
1659DEFUN (debug_bgp_zebra,
1660 debug_bgp_zebra_cmd,
1661 "debug bgp zebra",
1662 DEBUG_STR
1663 BGP_STR
1664 "BGP Zebra messages\n")
1665{
d62a17ae 1666 if (vty->node == CONFIG_NODE)
1667 DEBUG_ON(zebra, ZEBRA);
1668 else {
1669 TERM_DEBUG_ON(zebra, ZEBRA);
1670 vty_out(vty, "BGP zebra debugging is on\n");
1671 }
1672 return CMD_SUCCESS;
a39275d7
AS
1673}
1674
794b37d5 1675DEFUN (debug_bgp_graceful_restart,
1676 debug_bgp_graceful_restart_cmd,
1677 "debug bgp graceful-restart",
1678 DEBUG_STR
1679 BGP_STR
1680 GR_DEBUG)
1681{
1682 if (vty->node == CONFIG_NODE) {
1683 DEBUG_ON(graceful_restart, GRACEFUL_RESTART);
1684 } else {
1685 TERM_DEBUG_ON(graceful_restart, GRACEFUL_RESTART);
1686 vty_out(vty, "BGP Graceful Restart debugging is on\n");
1687 }
1688 return CMD_SUCCESS;
1689}
1690
1691
16286195
DS
1692DEFUN (debug_bgp_zebra_prefix,
1693 debug_bgp_zebra_prefix_cmd,
6147e2c6 1694 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
16286195
DS
1695 DEBUG_STR
1696 BGP_STR
1697 "BGP Zebra messages\n"
1698 "Specify a prefix to debug\n"
0c7b1b01
QY
1699 "IPv4 prefix\n"
1700 "IPv6 prefix\n")
16286195 1701{
d62a17ae 1702 int idx_ipv4_ipv6_prefixlen = 4;
1703 struct prefix *argv_p;
d62a17ae 1704
1705 argv_p = prefix_new();
ffd71765 1706 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1707 apply_mask(argv_p);
d62a17ae 1708
1709 if (!bgp_debug_zebra_prefixes)
1710 bgp_debug_zebra_prefixes = list_new();
1711
1712 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, argv_p)) {
1713 vty_out(vty, "BGP zebra debugging is already enabled for %s\n",
1714 argv[idx_ipv4_ipv6_prefixlen]->arg);
1715 return CMD_SUCCESS;
1716 }
1717
1718 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, argv_p);
1719
1720 if (vty->node == CONFIG_NODE)
1721 DEBUG_ON(zebra, ZEBRA);
1722 else {
1723 TERM_DEBUG_ON(zebra, ZEBRA);
1724 vty_out(vty, "BGP zebra debugging is on for %s\n",
1725 argv[idx_ipv4_ipv6_prefixlen]->arg);
1726 }
1727
1728 return CMD_SUCCESS;
16286195
DS
1729}
1730
a39275d7
AS
1731DEFUN (no_debug_bgp_zebra,
1732 no_debug_bgp_zebra_cmd,
1733 "no debug bgp zebra",
1734 NO_STR
1735 DEBUG_STR
1736 BGP_STR
1737 "BGP Zebra messages\n")
1738{
d62a17ae 1739 bgp_debug_list_free(bgp_debug_zebra_prefixes);
1740
1741 if (vty->node == CONFIG_NODE)
1742 DEBUG_OFF(zebra, ZEBRA);
1743 else {
1744 TERM_DEBUG_OFF(zebra, ZEBRA);
1745 vty_out(vty, "BGP zebra debugging is off\n");
1746 }
1747 return CMD_SUCCESS;
a39275d7
AS
1748}
1749
794b37d5 1750DEFUN (no_debug_bgp_graceful_restart,
1751 no_debug_bgp_graceful_restart_cmd,
1752 "no debug bgp graceful-restart",
1753 DEBUG_STR
1754 BGP_STR
1755 GR_DEBUG
1756 NO_STR)
1757{
1758 if (vty->node == CONFIG_NODE) {
1759 DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
1760 } else {
1761 TERM_DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
1762 vty_out(vty, "BGP Graceful Restart debugging is off\n");
1763 }
1764 return CMD_SUCCESS;
1765}
1766
16286195
DS
1767DEFUN (no_debug_bgp_zebra_prefix,
1768 no_debug_bgp_zebra_prefix_cmd,
6147e2c6 1769 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
16286195
DS
1770 NO_STR
1771 DEBUG_STR
a39275d7 1772 BGP_STR
16286195
DS
1773 "BGP Zebra messages\n"
1774 "Specify a prefix to debug\n"
0c7b1b01
QY
1775 "IPv4 prefix\n"
1776 "IPv6 prefix\n")
16286195 1777{
d62a17ae 1778 int idx_ipv4_ipv6_prefixlen = 5;
1779 struct prefix *argv_p;
1780 int found_prefix = 0;
d62a17ae 1781
1782 argv_p = prefix_new();
ffd71765 1783 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
0be4b77c 1784 apply_mask(argv_p);
d62a17ae 1785
1786 if (bgp_debug_zebra_prefixes
1787 && !list_isempty(bgp_debug_zebra_prefixes)) {
1788 found_prefix = bgp_debug_list_remove_entry(
1789 bgp_debug_zebra_prefixes, NULL, argv_p);
1790
1791 if (list_isempty(bgp_debug_zebra_prefixes)) {
1792 if (vty->node == CONFIG_NODE)
1793 DEBUG_OFF(zebra, ZEBRA);
1794 else {
1795 TERM_DEBUG_OFF(zebra, ZEBRA);
1796 vty_out(vty, "BGP zebra debugging is off\n");
1797 }
1798 }
1799 }
1800
1801 if (found_prefix)
1802 vty_out(vty, "BGP zebra debugging is off for %s\n",
1803 argv[idx_ipv4_ipv6_prefixlen]->arg);
1804 else
1805 vty_out(vty, "BGP zebra debugging was not enabled for %s\n",
1806 argv[idx_ipv4_ipv6_prefixlen]->arg);
1807
1808 return CMD_SUCCESS;
16286195
DS
1809}
1810
cebb7440
LB
1811DEFUN (debug_bgp_allow_martians,
1812 debug_bgp_allow_martians_cmd,
1813 "debug bgp allow-martians",
1814 DEBUG_STR
1815 BGP_STR
1816 "BGP allow martian next hops\n")
1817{
d62a17ae 1818 if (vty->node == CONFIG_NODE)
1819 DEBUG_ON(allow_martians, ALLOW_MARTIANS);
1820 else {
1821 TERM_DEBUG_ON(allow_martians, ALLOW_MARTIANS);
1822 vty_out(vty, "BGP allow_martian next hop debugging is on\n");
1823 }
1824 return CMD_SUCCESS;
cebb7440
LB
1825}
1826
1827DEFUN (no_debug_bgp_allow_martians,
1828 no_debug_bgp_allow_martians_cmd,
1829 "no debug bgp allow-martians",
1830 NO_STR
1831 DEBUG_STR
1832 BGP_STR
1833 "BGP allow martian next hops\n")
1834{
d62a17ae 1835 if (vty->node == CONFIG_NODE)
1836 DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
1837 else {
1838 TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
1839 vty_out(vty, "BGP allow martian next hop debugging is off\n");
1840 }
1841 return CMD_SUCCESS;
cebb7440
LB
1842}
1843
cebb7440 1844
3f9c7369
DS
1845/* debug bgp update-groups */
1846DEFUN (debug_bgp_update_groups,
1847 debug_bgp_update_groups_cmd,
1848 "debug bgp update-groups",
1849 DEBUG_STR
1850 BGP_STR
1851 "BGP update-groups\n")
1852{
d62a17ae 1853 if (vty->node == CONFIG_NODE)
1854 DEBUG_ON(update_groups, UPDATE_GROUPS);
1855 else {
1856 TERM_DEBUG_ON(update_groups, UPDATE_GROUPS);
1857 vty_out(vty, "BGP update-groups debugging is on\n");
1858 }
1859 return CMD_SUCCESS;
3f9c7369
DS
1860}
1861
1862DEFUN (no_debug_bgp_update_groups,
1863 no_debug_bgp_update_groups_cmd,
1864 "no debug bgp update-groups",
1865 NO_STR
1866 DEBUG_STR
1867 BGP_STR
1868 "BGP update-groups\n")
1869{
d62a17ae 1870 if (vty->node == CONFIG_NODE)
1871 DEBUG_OFF(update_groups, UPDATE_GROUPS);
1872 else {
1873 TERM_DEBUG_OFF(update_groups, UPDATE_GROUPS);
1874 vty_out(vty, "BGP update-groups debugging is off\n");
1875 }
1876 return CMD_SUCCESS;
3f9c7369
DS
1877}
1878
ddb5b488
PZ
1879DEFUN (debug_bgp_vpn,
1880 debug_bgp_vpn_cmd,
1881 "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1882 DEBUG_STR
1883 BGP_STR
1884 "VPN routes\n"
1885 "leaked from vrf to vpn\n"
1886 "leaked to vrf from vpn\n"
1887 "route-map updates\n"
1888 "labels\n")
1889{
1890 int idx = 3;
1891
1892 if (argv_find(argv, argc, "leak-from-vrf", &idx)) {
1893 if (vty->node == CONFIG_NODE)
1894 DEBUG_ON(vpn, VPN_LEAK_FROM_VRF);
1895 else
1896 TERM_DEBUG_ON(vpn, VPN_LEAK_FROM_VRF);
1897 } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) {
1898 if (vty->node == CONFIG_NODE)
1899 DEBUG_ON(vpn, VPN_LEAK_TO_VRF);
1900 else
1901 TERM_DEBUG_ON(vpn, VPN_LEAK_TO_VRF);
1902 } else if (argv_find(argv, argc, "rmap-event", &idx)) {
1903 if (vty->node == CONFIG_NODE)
1904 DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT);
1905 else
1906 TERM_DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT);
1907 } else if (argv_find(argv, argc, "label", &idx)) {
1908 if (vty->node == CONFIG_NODE)
1909 DEBUG_ON(vpn, VPN_LEAK_LABEL);
1910 else
1911 TERM_DEBUG_ON(vpn, VPN_LEAK_LABEL);
1912 } else {
1913 vty_out(vty, "%% unknown debug bgp vpn keyword\n");
1914 return CMD_WARNING_CONFIG_FAILED;
1915 }
1916
1917 if (vty->node != CONFIG_NODE)
1918 vty_out(vty, "enabled debug bgp vpn %s\n", argv[idx]->text);
1919
1920 return CMD_SUCCESS;
1921}
1922
1923DEFUN (no_debug_bgp_vpn,
1924 no_debug_bgp_vpn_cmd,
1925 "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
1926 NO_STR
1927 DEBUG_STR
1928 BGP_STR
1929 "VPN routes\n"
1930 "leaked from vrf to vpn\n"
1931 "leaked to vrf from vpn\n"
1932 "route-map updates\n"
1933 "labels\n")
1934{
1935 int idx = 4;
1936
1937 if (argv_find(argv, argc, "leak-from-vrf", &idx)) {
1938 if (vty->node == CONFIG_NODE)
1939 DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
1940 else
1941 TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
1942
1943 } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) {
1944 if (vty->node == CONFIG_NODE)
1945 DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
1946 else
1947 TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
1948 } else if (argv_find(argv, argc, "rmap-event", &idx)) {
1949 if (vty->node == CONFIG_NODE)
1950 DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
1951 else
1952 TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
1953 } else if (argv_find(argv, argc, "label", &idx)) {
1954 if (vty->node == CONFIG_NODE)
1955 DEBUG_OFF(vpn, VPN_LEAK_LABEL);
1956 else
1957 TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL);
1958 } else {
1959 vty_out(vty, "%% unknown debug bgp vpn keyword\n");
1960 return CMD_WARNING_CONFIG_FAILED;
1961 }
1962
1963 if (vty->node != CONFIG_NODE)
1964 vty_out(vty, "disabled debug bgp vpn %s\n", argv[idx]->text);
1a80fc0f
PG
1965 return CMD_SUCCESS;
1966}
ddb5b488 1967
1a80fc0f
PG
1968/* debug bgp pbr */
1969DEFUN (debug_bgp_pbr,
1970 debug_bgp_pbr_cmd,
e9d0aa99 1971 "debug bgp pbr [error]",
1a80fc0f
PG
1972 DEBUG_STR
1973 BGP_STR
e9d0aa99
PG
1974 "BGP policy based routing\n"
1975 "BGP PBR error\n")
1a80fc0f 1976{
e9d0aa99
PG
1977 int idx = 3;
1978
1979 if (argv_find(argv, argc, "error", &idx)) {
1980 if (vty->node == CONFIG_NODE)
1981 DEBUG_ON(pbr, PBR_ERROR);
1982 else {
1983 TERM_DEBUG_ON(pbr, PBR_ERROR);
1984 vty_out(vty, "BGP policy based routing error is on\n");
1985 }
1986 return CMD_SUCCESS;
1987 }
1a80fc0f
PG
1988 if (vty->node == CONFIG_NODE)
1989 DEBUG_ON(pbr, PBR);
1990 else {
1991 TERM_DEBUG_ON(pbr, PBR);
1992 vty_out(vty, "BGP policy based routing is on\n");
1993 }
1994 return CMD_SUCCESS;
1995}
1996
1997DEFUN (no_debug_bgp_pbr,
1998 no_debug_bgp_pbr_cmd,
e9d0aa99 1999 "no debug bgp pbr [error]",
1a80fc0f
PG
2000 NO_STR
2001 DEBUG_STR
2002 BGP_STR
e9d0aa99
PG
2003 "BGP policy based routing\n"
2004 "BGP PBR Error\n")
1a80fc0f 2005{
e9d0aa99
PG
2006 int idx = 3;
2007
2008 if (argv_find(argv, argc, "error", &idx)) {
2009 if (vty->node == CONFIG_NODE)
2010 DEBUG_OFF(pbr, PBR_ERROR);
2011 else {
2012 TERM_DEBUG_OFF(pbr, PBR_ERROR);
2013 vty_out(vty, "BGP policy based routing error is off\n");
2014 }
2015 return CMD_SUCCESS;
2016 }
1a80fc0f
PG
2017 if (vty->node == CONFIG_NODE)
2018 DEBUG_OFF(pbr, PBR);
2019 else {
2020 TERM_DEBUG_OFF(pbr, PBR);
2021 vty_out(vty, "BGP policy based routing is off\n");
2022 }
ddb5b488
PZ
2023 return CMD_SUCCESS;
2024}
2025
52653398
AK
2026DEFPY (debug_bgp_evpn_mh,
2027 debug_bgp_evpn_mh_cmd,
2028 "[no$no] debug bgp evpn mh <es$es|route$rt>",
2029 NO_STR
2030 DEBUG_STR
2031 BGP_STR
2032 "EVPN\n"
2033 "Multihoming\n"
2034 "Ethernet Segment debugging\n"
2035 "Route debugging\n")
2036{
2037 if (es) {
2038 if (vty->node == CONFIG_NODE) {
2039 if (no)
2040 DEBUG_OFF(evpn_mh, EVPN_MH_ES);
2041 else
2042 DEBUG_ON(evpn_mh, EVPN_MH_ES);
2043 } else {
2044 if (no) {
2045 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
2046 vty_out(vty,
2047 "BGP EVPN-MH ES debugging is off\n");
2048 } else {
2049 TERM_DEBUG_ON(evpn_mh, EVPN_MH_ES);
2050 vty_out(vty,
2051 "BGP EVPN-MH ES debugging is on\n");
2052 }
2053 }
2054 }
2055 if (rt) {
2056 if (vty->node == CONFIG_NODE) {
2057 if (no)
2058 DEBUG_OFF(evpn_mh, EVPN_MH_RT);
2059 else
2060 DEBUG_ON(evpn_mh, EVPN_MH_RT);
2061 } else {
2062 if (no) {
2063 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
2064 vty_out(vty,
2065 "BGP EVPN-MH route debugging is off\n");
2066 } else {
2067 TERM_DEBUG_ON(evpn_mh, EVPN_MH_RT);
2068 vty_out(vty,
2069 "BGP EVPN-MH route debugging is on\n");
2070 }
2071 }
2072 }
2073
2074 return CMD_SUCCESS;
2075}
2076
955bfd98
PZ
2077DEFUN (debug_bgp_labelpool,
2078 debug_bgp_labelpool_cmd,
2079 "debug bgp labelpool",
2080 DEBUG_STR
2081 BGP_STR
2082 "label pool\n")
2083{
2084 if (vty->node == CONFIG_NODE)
2085 DEBUG_ON(labelpool, LABELPOOL);
2086 else
2087 TERM_DEBUG_ON(labelpool, LABELPOOL);
2088
2089 if (vty->node != CONFIG_NODE)
2090 vty_out(vty, "enabled debug bgp labelpool\n");
2091
2092 return CMD_SUCCESS;
2093}
2094
2095DEFUN (no_debug_bgp_labelpool,
2096 no_debug_bgp_labelpool_cmd,
2097 "no debug bgp labelpool",
2098 NO_STR
2099 DEBUG_STR
2100 BGP_STR
2101 "label pool\n")
2102{
2103 if (vty->node == CONFIG_NODE)
2104 DEBUG_OFF(labelpool, LABELPOOL);
2105 else
2106 TERM_DEBUG_OFF(labelpool, LABELPOOL);
2107
2108
2109 if (vty->node != CONFIG_NODE)
2110 vty_out(vty, "disabled debug bgp labelpool\n");
2111
2112 return CMD_SUCCESS;
2113}
2114
259f4236
RZ
2115DEFPY(debug_bgp_bfd, debug_bgp_bfd_cmd,
2116 "[no] debug bgp bfd",
2117 NO_STR
2118 DEBUG_STR
2119 BGP_STR
2120 "Bidirection Forwarding Detection\n")
2121{
2122 if (vty->node == CONFIG_NODE) {
2123 if (no) {
2124 DEBUG_OFF(bfd, BFD_LIB);
2125 bfd_protocol_integration_set_debug(false);
2126 } else {
2127 DEBUG_ON(bfd, BFD_LIB);
2128 bfd_protocol_integration_set_debug(true);
2129 }
2130 } else {
edc0d8cf 2131 if (no) {
259f4236 2132 TERM_DEBUG_OFF(bfd, BFD_LIB);
edc0d8cf
IR
2133 bfd_protocol_integration_set_debug(false);
2134 } else {
259f4236 2135 TERM_DEBUG_ON(bfd, BFD_LIB);
edc0d8cf
IR
2136 bfd_protocol_integration_set_debug(true);
2137 }
259f4236
RZ
2138 }
2139
2140 return CMD_SUCCESS;
2141}
2142
16286195
DS
2143DEFUN (no_debug_bgp,
2144 no_debug_bgp_cmd,
2145 "no debug bgp",
718e3744 2146 NO_STR
2147 DEBUG_STR
718e3744 2148 BGP_STR)
2149{
87f42c2c
QY
2150 struct bgp *bgp;
2151 struct listnode *ln;
2152
d62a17ae 2153 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
2154 bgp_debug_list_free(bgp_debug_keepalive_peers);
2155 bgp_debug_list_free(bgp_debug_update_in_peers);
2156 bgp_debug_list_free(bgp_debug_update_out_peers);
2157 bgp_debug_list_free(bgp_debug_update_prefixes);
2158 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
2159 bgp_debug_list_free(bgp_debug_zebra_prefixes);
2160
87f42c2c
QY
2161 for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
2162 bgp_debug_clear_updgrp_update_dbg(bgp);
d62a17ae 2163
2164 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
2165 TERM_DEBUG_OFF(update, UPDATE_IN);
2166 TERM_DEBUG_OFF(update, UPDATE_OUT);
2167 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
2168 TERM_DEBUG_OFF(bestpath, BESTPATH);
2169 TERM_DEBUG_OFF(as4, AS4);
2170 TERM_DEBUG_OFF(as4, AS4_SEGMENT);
2171 TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
2172 TERM_DEBUG_OFF(zebra, ZEBRA);
2173 TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
c33b83b3 2174 TERM_DEBUG_OFF(nht, NHT);
ddb5b488
PZ
2175 TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
2176 TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
2177 TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
2178 TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL);
268e1b9b 2179 TERM_DEBUG_OFF(flowspec, FLOWSPEC);
955bfd98 2180 TERM_DEBUG_OFF(labelpool, LABELPOOL);
1a80fc0f 2181 TERM_DEBUG_OFF(pbr, PBR);
e9d0aa99 2182 TERM_DEBUG_OFF(pbr, PBR_ERROR);
794b37d5 2183 TERM_DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
52653398
AK
2184 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
2185 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
259f4236 2186 TERM_DEBUG_OFF(bfd, BFD_LIB);
794b37d5 2187
d62a17ae 2188 vty_out(vty, "All possible debugging has been turned off\n");
2189
2190 return CMD_SUCCESS;
718e3744 2191}
2192
87f6dc50
DS
2193DEFUN_NOSH (show_debugging_bgp,
2194 show_debugging_bgp_cmd,
2195 "show debugging [bgp]",
2196 SHOW_STR
2197 DEBUG_STR
2198 BGP_STR)
718e3744 2199{
d62a17ae 2200 vty_out(vty, "BGP debugging status:\n");
718e3744 2201
d62a17ae 2202 if (BGP_DEBUG(as4, AS4))
2203 vty_out(vty, " BGP as4 debugging is on\n");
16286195 2204
d62a17ae 2205 if (BGP_DEBUG(as4, AS4_SEGMENT))
2206 vty_out(vty, " BGP as4 aspath segment debugging is on\n");
16286195 2207
d62a17ae 2208 if (BGP_DEBUG(bestpath, BESTPATH))
2209 bgp_debug_list_print(vty, " BGP bestpath debugging is on",
29a643ca 2210 bgp_debug_bestpath_prefixes);
16286195 2211
d62a17ae 2212 if (BGP_DEBUG(keepalive, KEEPALIVE))
2213 bgp_debug_list_print(vty, " BGP keepalives debugging is on",
29a643ca 2214 bgp_debug_keepalive_peers);
16286195 2215
d62a17ae 2216 if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS))
2217 bgp_debug_list_print(vty,
2218 " BGP neighbor-events debugging is on",
29a643ca 2219 bgp_debug_neighbor_events_peers);
91ba2c8b 2220
d62a17ae 2221 if (BGP_DEBUG(nht, NHT))
2222 vty_out(vty, " BGP next-hop tracking debugging is on\n");
16286195 2223
d62a17ae 2224 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
2225 vty_out(vty, " BGP update-groups debugging is on\n");
91ba2c8b 2226
d62a17ae 2227 if (BGP_DEBUG(update, UPDATE_PREFIX))
2228 bgp_debug_list_print(vty, " BGP updates debugging is on",
29a643ca 2229 bgp_debug_update_prefixes);
16286195 2230
d62a17ae 2231 if (BGP_DEBUG(update, UPDATE_IN))
2232 bgp_debug_list_print(vty,
2233 " BGP updates debugging is on (inbound)",
29a643ca 2234 bgp_debug_update_in_peers);
16286195 2235
d62a17ae 2236 if (BGP_DEBUG(update, UPDATE_OUT))
2237 bgp_debug_list_print(vty,
2238 " BGP updates debugging is on (outbound)",
29a643ca 2239 bgp_debug_update_out_peers);
16286195 2240
d62a17ae 2241 if (BGP_DEBUG(zebra, ZEBRA))
2242 bgp_debug_list_print(vty, " BGP zebra debugging is on",
36235319 2243 bgp_debug_zebra_prefixes);
794b37d5 2244
2245 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
81bf7425 2246 vty_out(vty, " BGP graceful-restart debugging is on\n");
16286195 2247
d62a17ae 2248 if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS))
2249 vty_out(vty, " BGP allow martian next hop debugging is on\n");
ddb5b488
PZ
2250
2251 if (BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF))
2252 vty_out(vty,
2253 " BGP route leak from vrf to vpn debugging is on\n");
2254 if (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF))
2255 vty_out(vty,
2256 " BGP route leak to vrf from vpn debugging is on\n");
2257 if (BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT))
2258 vty_out(vty, " BGP vpn route-map event debugging is on\n");
2259 if (BGP_DEBUG(vpn, VPN_LEAK_LABEL))
2260 vty_out(vty, " BGP vpn label event debugging is on\n");
268e1b9b
PG
2261 if (BGP_DEBUG(flowspec, FLOWSPEC))
2262 vty_out(vty, " BGP flowspec debugging is on\n");
955bfd98
PZ
2263 if (BGP_DEBUG(labelpool, LABELPOOL))
2264 vty_out(vty, " BGP labelpool debugging is on\n");
ddb5b488 2265
1a80fc0f
PG
2266 if (BGP_DEBUG(pbr, PBR))
2267 vty_out(vty, " BGP policy based routing debugging is on\n");
e9d0aa99
PG
2268 if (BGP_DEBUG(pbr, PBR_ERROR))
2269 vty_out(vty, " BGP policy based routing error debugging is on\n");
1d4cfa5d 2270
52653398
AK
2271 if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
2272 vty_out(vty, " BGP EVPN-MH ES debugging is on\n");
2273 if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
2274 vty_out(vty, " BGP EVPN-MH route debugging is on\n");
2275
259f4236
RZ
2276 if (BGP_DEBUG(bfd, BFD_LIB))
2277 vty_out(vty, " BGP BFD library debugging is on\n");
2278
d62a17ae 2279 vty_out(vty, "\n");
2280 return CMD_SUCCESS;
718e3744 2281}
2282
d62a17ae 2283static int bgp_config_write_debug(struct vty *vty)
718e3744 2284{
d62a17ae 2285 int write = 0;
718e3744 2286
d62a17ae 2287 if (CONF_BGP_DEBUG(as4, AS4)) {
2288 vty_out(vty, "debug bgp as4\n");
2289 write++;
2290 }
718e3744 2291
d62a17ae 2292 if (CONF_BGP_DEBUG(as4, AS4_SEGMENT)) {
2293 vty_out(vty, "debug bgp as4 segment\n");
2294 write++;
2295 }
16286195 2296
d62a17ae 2297 if (CONF_BGP_DEBUG(bestpath, BESTPATH)) {
2298 write += bgp_debug_list_conf_print(vty, "debug bgp bestpath",
29a643ca 2299 bgp_debug_bestpath_prefixes);
d62a17ae 2300 }
2301
2302 if (CONF_BGP_DEBUG(keepalive, KEEPALIVE)) {
2303 write += bgp_debug_list_conf_print(vty, "debug bgp keepalives",
29a643ca 2304 bgp_debug_keepalive_peers);
d62a17ae 2305 }
2306
2307 if (CONF_BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)) {
2308 write += bgp_debug_list_conf_print(
2309 vty, "debug bgp neighbor-events",
29a643ca 2310 bgp_debug_neighbor_events_peers);
d62a17ae 2311 }
2312
2313 if (CONF_BGP_DEBUG(nht, NHT)) {
2314 vty_out(vty, "debug bgp nht\n");
2315 write++;
2316 }
2317
2318 if (CONF_BGP_DEBUG(update_groups, UPDATE_GROUPS)) {
2319 vty_out(vty, "debug bgp update-groups\n");
2320 write++;
2321 }
2322
2323 if (CONF_BGP_DEBUG(update, UPDATE_PREFIX)) {
2324 write += bgp_debug_list_conf_print(vty,
2325 "debug bgp updates prefix",
29a643ca 2326 bgp_debug_update_prefixes);
d62a17ae 2327 }
2328
2329 if (CONF_BGP_DEBUG(update, UPDATE_IN)) {
2330 write += bgp_debug_list_conf_print(vty, "debug bgp updates in",
29a643ca 2331 bgp_debug_update_in_peers);
d62a17ae 2332 }
2333
2334 if (CONF_BGP_DEBUG(update, UPDATE_OUT)) {
2335 write += bgp_debug_list_conf_print(vty, "debug bgp updates out",
29a643ca 2336 bgp_debug_update_out_peers);
d62a17ae 2337 }
16286195 2338
d62a17ae 2339 if (CONF_BGP_DEBUG(zebra, ZEBRA)) {
2340 if (!bgp_debug_zebra_prefixes
2341 || list_isempty(bgp_debug_zebra_prefixes)) {
2342 vty_out(vty, "debug bgp zebra\n");
2343 write++;
2344 } else {
2345 write += bgp_debug_list_conf_print(
2346 vty, "debug bgp zebra prefix",
29a643ca 2347 bgp_debug_zebra_prefixes);
d62a17ae 2348 }
2349 }
16286195 2350
d62a17ae 2351 if (CONF_BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) {
2352 vty_out(vty, "debug bgp allow-martians\n");
2353 write++;
2354 }
16286195 2355
ddb5b488
PZ
2356 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF)) {
2357 vty_out(vty, "debug bgp vpn leak-from-vrf\n");
2358 write++;
2359 }
2360 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_TO_VRF)) {
2361 vty_out(vty, "debug bgp vpn leak-to-vrf\n");
2362 write++;
2363 }
2364 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT)) {
2365 vty_out(vty, "debug bgp vpn rmap-event\n");
2366 write++;
2367 }
2368 if (CONF_BGP_DEBUG(vpn, VPN_LEAK_LABEL)) {
2369 vty_out(vty, "debug bgp vpn label\n");
2370 write++;
2371 }
268e1b9b
PG
2372 if (CONF_BGP_DEBUG(flowspec, FLOWSPEC)) {
2373 vty_out(vty, "debug bgp flowspec\n");
2374 write++;
2375 }
955bfd98
PZ
2376 if (CONF_BGP_DEBUG(labelpool, LABELPOOL)) {
2377 vty_out(vty, "debug bgp labelpool\n");
2378 write++;
2379 }
ddb5b488 2380
1a80fc0f
PG
2381 if (CONF_BGP_DEBUG(pbr, PBR)) {
2382 vty_out(vty, "debug bgp pbr\n");
2383 write++;
e9d0aa99
PG
2384 }
2385 if (CONF_BGP_DEBUG(pbr, PBR_ERROR)) {
2386 vty_out(vty, "debug bgp pbr error\n");
2387 write++;
1a80fc0f 2388 }
794b37d5 2389
2390 if (CONF_BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) {
2391 vty_out(vty, "debug bgp graceful-restart\n");
2392 write++;
2393 }
52653398
AK
2394
2395 if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_ES)) {
2396 vty_out(vty, "debug bgp evpn mh es\n");
2397 write++;
2398 }
2399 if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_RT)) {
2400 vty_out(vty, "debug bgp evpn mh route\n");
2401 write++;
2402 }
2403
259f4236
RZ
2404 if (CONF_BGP_DEBUG(bfd, BFD_LIB)) {
2405 vty_out(vty, "debug bgp bfd\n");
2406 write++;
2407 }
2408
d62a17ae 2409 return write;
2410}
16286195 2411
612c2c15 2412static int bgp_config_write_debug(struct vty *vty);
62b346ee 2413static struct cmd_node debug_node = {
f4b8291f 2414 .name = "debug",
62b346ee
DL
2415 .node = DEBUG_NODE,
2416 .prompt = "",
612c2c15 2417 .config_write = bgp_config_write_debug,
62b346ee 2418};
d62a17ae 2419
2420void bgp_debug_init(void)
2421{
612c2c15 2422 install_node(&debug_node);
d62a17ae 2423
2424 install_element(ENABLE_NODE, &show_debugging_bgp_cmd);
2425
2426 install_element(ENABLE_NODE, &debug_bgp_as4_cmd);
2427 install_element(CONFIG_NODE, &debug_bgp_as4_cmd);
2428 install_element(ENABLE_NODE, &debug_bgp_as4_segment_cmd);
2429 install_element(CONFIG_NODE, &debug_bgp_as4_segment_cmd);
2430
2431 install_element(ENABLE_NODE, &debug_bgp_neighbor_events_cmd);
2432 install_element(CONFIG_NODE, &debug_bgp_neighbor_events_cmd);
2433 install_element(ENABLE_NODE, &debug_bgp_nht_cmd);
2434 install_element(CONFIG_NODE, &debug_bgp_nht_cmd);
2435 install_element(ENABLE_NODE, &debug_bgp_keepalive_cmd);
2436 install_element(CONFIG_NODE, &debug_bgp_keepalive_cmd);
2437 install_element(ENABLE_NODE, &debug_bgp_update_cmd);
2438 install_element(CONFIG_NODE, &debug_bgp_update_cmd);
2439 install_element(ENABLE_NODE, &debug_bgp_zebra_cmd);
2440 install_element(CONFIG_NODE, &debug_bgp_zebra_cmd);
2441 install_element(ENABLE_NODE, &debug_bgp_allow_martians_cmd);
2442 install_element(CONFIG_NODE, &debug_bgp_allow_martians_cmd);
2443 install_element(ENABLE_NODE, &debug_bgp_update_groups_cmd);
2444 install_element(CONFIG_NODE, &debug_bgp_update_groups_cmd);
2445 install_element(ENABLE_NODE, &debug_bgp_bestpath_prefix_cmd);
2446 install_element(CONFIG_NODE, &debug_bgp_bestpath_prefix_cmd);
2447
794b37d5 2448 install_element(ENABLE_NODE, &debug_bgp_graceful_restart_cmd);
2449 install_element(CONFIG_NODE, &debug_bgp_graceful_restart_cmd);
2450
d62a17ae 2451 /* debug bgp updates (in|out) */
2452 install_element(ENABLE_NODE, &debug_bgp_update_direct_cmd);
2453 install_element(CONFIG_NODE, &debug_bgp_update_direct_cmd);
2454 install_element(ENABLE_NODE, &no_debug_bgp_update_direct_cmd);
2455 install_element(CONFIG_NODE, &no_debug_bgp_update_direct_cmd);
2456
2457 /* debug bgp updates (in|out) A.B.C.D */
2458 install_element(ENABLE_NODE, &debug_bgp_update_direct_peer_cmd);
2459 install_element(CONFIG_NODE, &debug_bgp_update_direct_peer_cmd);
2460 install_element(ENABLE_NODE, &no_debug_bgp_update_direct_peer_cmd);
2461 install_element(CONFIG_NODE, &no_debug_bgp_update_direct_peer_cmd);
2462
2463 /* debug bgp updates prefix A.B.C.D/M */
2464 install_element(ENABLE_NODE, &debug_bgp_update_prefix_cmd);
2465 install_element(CONFIG_NODE, &debug_bgp_update_prefix_cmd);
2466 install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_cmd);
2467 install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_cmd);
81cf0de5
CS
2468 install_element(ENABLE_NODE, &debug_bgp_update_prefix_afi_safi_cmd);
2469 install_element(CONFIG_NODE, &debug_bgp_update_prefix_afi_safi_cmd);
2470 install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd);
2471 install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd);
d62a17ae 2472
2473 /* debug bgp zebra prefix A.B.C.D/M */
2474 install_element(ENABLE_NODE, &debug_bgp_zebra_prefix_cmd);
2475 install_element(CONFIG_NODE, &debug_bgp_zebra_prefix_cmd);
2476 install_element(ENABLE_NODE, &no_debug_bgp_zebra_prefix_cmd);
2477 install_element(CONFIG_NODE, &no_debug_bgp_zebra_prefix_cmd);
2478
2479 install_element(ENABLE_NODE, &no_debug_bgp_as4_cmd);
2480 install_element(CONFIG_NODE, &no_debug_bgp_as4_cmd);
2481 install_element(ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
2482 install_element(CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
2483
2484 /* debug bgp neighbor-events A.B.C.D */
2485 install_element(ENABLE_NODE, &debug_bgp_neighbor_events_peer_cmd);
2486 install_element(CONFIG_NODE, &debug_bgp_neighbor_events_peer_cmd);
2487 install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
2488 install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
2489
2490 /* debug bgp keepalive A.B.C.D */
2491 install_element(ENABLE_NODE, &debug_bgp_keepalive_peer_cmd);
2492 install_element(CONFIG_NODE, &debug_bgp_keepalive_peer_cmd);
2493 install_element(ENABLE_NODE, &no_debug_bgp_keepalive_peer_cmd);
2494 install_element(CONFIG_NODE, &no_debug_bgp_keepalive_peer_cmd);
2495
2496 install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_cmd);
2497 install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_cmd);
2498 install_element(ENABLE_NODE, &no_debug_bgp_nht_cmd);
2499 install_element(CONFIG_NODE, &no_debug_bgp_nht_cmd);
2500 install_element(ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
2501 install_element(CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
2502 install_element(ENABLE_NODE, &no_debug_bgp_update_cmd);
2503 install_element(CONFIG_NODE, &no_debug_bgp_update_cmd);
2504 install_element(ENABLE_NODE, &no_debug_bgp_zebra_cmd);
2505 install_element(CONFIG_NODE, &no_debug_bgp_zebra_cmd);
2506 install_element(ENABLE_NODE, &no_debug_bgp_allow_martians_cmd);
2507 install_element(CONFIG_NODE, &no_debug_bgp_allow_martians_cmd);
2508 install_element(ENABLE_NODE, &no_debug_bgp_update_groups_cmd);
2509 install_element(CONFIG_NODE, &no_debug_bgp_update_groups_cmd);
2510 install_element(ENABLE_NODE, &no_debug_bgp_cmd);
2511 install_element(ENABLE_NODE, &no_debug_bgp_bestpath_cmd);
2512 install_element(CONFIG_NODE, &no_debug_bgp_bestpath_cmd);
2513 install_element(ENABLE_NODE, &no_debug_bgp_bestpath_prefix_cmd);
2514 install_element(CONFIG_NODE, &no_debug_bgp_bestpath_prefix_cmd);
ddb5b488 2515
794b37d5 2516 install_element(ENABLE_NODE, &no_debug_bgp_graceful_restart_cmd);
2517 install_element(CONFIG_NODE, &no_debug_bgp_graceful_restart_cmd);
2518
ddb5b488
PZ
2519 install_element(ENABLE_NODE, &debug_bgp_vpn_cmd);
2520 install_element(CONFIG_NODE, &debug_bgp_vpn_cmd);
2521 install_element(ENABLE_NODE, &no_debug_bgp_vpn_cmd);
2522 install_element(CONFIG_NODE, &no_debug_bgp_vpn_cmd);
955bfd98
PZ
2523
2524 install_element(ENABLE_NODE, &debug_bgp_labelpool_cmd);
2525 install_element(CONFIG_NODE, &debug_bgp_labelpool_cmd);
2526 install_element(ENABLE_NODE, &no_debug_bgp_labelpool_cmd);
2527 install_element(CONFIG_NODE, &no_debug_bgp_labelpool_cmd);
1a80fc0f
PG
2528
2529 /* debug bgp pbr */
2530 install_element(ENABLE_NODE, &debug_bgp_pbr_cmd);
2531 install_element(CONFIG_NODE, &debug_bgp_pbr_cmd);
2532 install_element(ENABLE_NODE, &no_debug_bgp_pbr_cmd);
2533 install_element(CONFIG_NODE, &no_debug_bgp_pbr_cmd);
2534
52653398
AK
2535 install_element(ENABLE_NODE, &debug_bgp_evpn_mh_cmd);
2536 install_element(CONFIG_NODE, &debug_bgp_evpn_mh_cmd);
259f4236
RZ
2537
2538 /* debug bgp bfd */
2539 install_element(ENABLE_NODE, &debug_bgp_bfd_cmd);
2540 install_element(CONFIG_NODE, &debug_bgp_bfd_cmd);
d62a17ae 2541}
16286195 2542
d62a17ae 2543/* Return true if this prefix is on the per_prefix_list of prefixes to debug
2544 * for BGP_DEBUG_TYPE
2545 */
b8685f9b 2546static int bgp_debug_per_prefix(const struct prefix *p,
d62a17ae 2547 unsigned long term_bgp_debug_type,
2548 unsigned int BGP_DEBUG_TYPE,
2549 struct list *per_prefix_list)
2550{
2551 struct bgp_debug_filter *filter;
2552 struct listnode *node, *nnode;
2553
2554 if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
2555 /* We are debugging all prefixes so return true */
2556 if (!per_prefix_list || list_isempty(per_prefix_list))
2557 return 1;
2558
2559 else {
2560 if (!p)
2561 return 0;
2562
2563 for (ALL_LIST_ELEMENTS(per_prefix_list, node, nnode,
2564 filter))
2565 if (filter->p->prefixlen == p->prefixlen
2566 && prefix_match(filter->p, p))
2567 return 1;
2568
2569 return 0;
2570 }
2571 }
2572
2573 return 0;
16286195
DS
2574}
2575
2576/* Return true if this peer is on the per_peer_list of peers to debug
2577 * for BGP_DEBUG_TYPE
2578 */
d62a17ae 2579static int bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type,
2580 unsigned int BGP_DEBUG_TYPE,
2581 struct list *per_peer_list)
16286195 2582{
d62a17ae 2583 struct bgp_debug_filter *filter;
2584 struct listnode *node, *nnode;
16286195 2585
d62a17ae 2586 if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
2587 /* We are debugging all peers so return true */
2588 if (!per_peer_list || list_isempty(per_peer_list))
2589 return 1;
16286195 2590
d62a17ae 2591 else {
2592 if (!host)
2593 return 0;
16286195 2594
d62a17ae 2595 for (ALL_LIST_ELEMENTS(per_peer_list, node, nnode,
2596 filter))
2597 if (strcmp(filter->host, host) == 0)
2598 return 1;
16286195 2599
d62a17ae 2600 return 0;
2601 }
2602 }
16286195 2603
d62a17ae 2604 return 0;
16286195
DS
2605}
2606
d62a17ae 2607int bgp_debug_neighbor_events(struct peer *peer)
16286195 2608{
d62a17ae 2609 char *host = NULL;
167d390a 2610
d62a17ae 2611 if (peer)
2612 host = peer->host;
167d390a 2613
d62a17ae 2614 return bgp_debug_per_peer(host, term_bgp_debug_neighbor_events,
2615 BGP_DEBUG_NEIGHBOR_EVENTS,
2616 bgp_debug_neighbor_events_peers);
16286195
DS
2617}
2618
d62a17ae 2619int bgp_debug_keepalive(struct peer *peer)
16286195 2620{
d62a17ae 2621 char *host = NULL;
167d390a 2622
d62a17ae 2623 if (peer)
2624 host = peer->host;
167d390a 2625
d62a17ae 2626 return bgp_debug_per_peer(host, term_bgp_debug_keepalive,
2627 BGP_DEBUG_KEEPALIVE,
2628 bgp_debug_keepalive_peers);
16286195
DS
2629}
2630
b8685f9b 2631bool bgp_debug_update(struct peer *peer, const struct prefix *p,
3dc339cd 2632 struct update_group *updgrp, unsigned int inbound)
16286195 2633{
d62a17ae 2634 char *host = NULL;
2635
2636 if (peer)
2637 host = peer->host;
2638
2639 if (inbound) {
2640 if (bgp_debug_per_peer(host, term_bgp_debug_update,
2641 BGP_DEBUG_UPDATE_IN,
2642 bgp_debug_update_in_peers))
3dc339cd 2643 return true;
d62a17ae 2644 }
2645
2646 /* outbound */
2647 else {
2648 if (bgp_debug_per_peer(host, term_bgp_debug_update,
2649 BGP_DEBUG_UPDATE_OUT,
2650 bgp_debug_update_out_peers))
3dc339cd 2651 return true;
d62a17ae 2652
2653 /* Check if update debugging implicitly enabled for the group.
2654 */
2655 if (updgrp && UPDGRP_DBG_ON(updgrp))
3dc339cd 2656 return true;
d62a17ae 2657 }
2658
2659
2660 if (BGP_DEBUG(update, UPDATE_PREFIX)) {
2661 if (bgp_debug_per_prefix(p, term_bgp_debug_update,
2662 BGP_DEBUG_UPDATE_PREFIX,
2663 bgp_debug_update_prefixes))
3dc339cd 2664 return true;
d62a17ae 2665 }
2666
3dc339cd 2667 return false;
16286195
DS
2668}
2669
9bcb3eef 2670bool bgp_debug_bestpath(struct bgp_dest *dest)
9fbdd100 2671{
d62a17ae 2672 if (BGP_DEBUG(bestpath, BESTPATH)) {
cb9f254c 2673 if (bgp_debug_per_prefix(
9bcb3eef 2674 bgp_dest_get_prefix(dest), term_bgp_debug_bestpath,
cb9f254c 2675 BGP_DEBUG_BESTPATH, bgp_debug_bestpath_prefixes))
3dc339cd 2676 return true;
d62a17ae 2677 }
2678
3dc339cd 2679 return false;
9fbdd100
DS
2680}
2681
b8685f9b 2682bool bgp_debug_zebra(const struct prefix *p)
16286195 2683{
d62a17ae 2684 if (BGP_DEBUG(zebra, ZEBRA)) {
2685 if (bgp_debug_per_prefix(p, term_bgp_debug_zebra,
2686 BGP_DEBUG_ZEBRA,
2687 bgp_debug_zebra_prefixes))
3dc339cd 2688 return true;
d62a17ae 2689 }
2690
3dc339cd 2691 return false;
718e3744 2692}
906ad49b 2693
d62a17ae 2694const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi,
5f040085 2695 const struct prefix_rd *prd,
d62a17ae 2696 union prefixconstptr pu,
d7c0a89a
QY
2697 mpls_label_t *label, uint32_t num_labels,
2698 int addpath_valid, uint32_t addpath_id,
6c995628 2699 struct bgp_route_evpn *overlay_index,
b57ba6d2 2700 char *str, int size)
d62a17ae 2701{
2702 char rd_buf[RD_ADDRSTRLEN];
d62a17ae 2703 char tag_buf[30];
6c995628
AD
2704 char overlay_index_buf[INET6_ADDRSTRLEN + 14];
2705 const struct prefix_evpn *evp;
2706
d62a17ae 2707 /* ' with addpath ID ' 17
2708 * max strlen of uint32 + 10
2709 * +/- (just in case) + 1
2710 * null terminator + 1
2711 * ============================ 29 */
2712 char pathid_buf[30];
2713
2714 if (size < BGP_PRD_PATH_STRLEN)
2715 return NULL;
2716
2717 /* Note: Path-id is created by default, but only included in update
2718 * sometimes. */
2719 pathid_buf[0] = '\0';
2720 if (addpath_valid)
2721 snprintf(pathid_buf, sizeof(pathid_buf), " with addpath ID %u",
2722 addpath_id);
2723
6c995628
AD
2724 overlay_index_buf[0] = '\0';
2725 if (overlay_index && overlay_index->type == OVERLAY_INDEX_GATEWAY_IP) {
2726 char obuf[INET6_ADDRSTRLEN];
2727
2728 obuf[0] = '\0';
2729 evp = pu.evp;
2730 if (is_evpn_prefix_ipaddr_v4(evp))
2731 inet_ntop(AF_INET, &overlay_index->gw_ip, obuf,
2732 sizeof(obuf));
2733 else if (is_evpn_prefix_ipaddr_v6(evp))
2734 inet_ntop(AF_INET6, &overlay_index->gw_ip, obuf,
2735 sizeof(obuf));
2736
2737 snprintf(overlay_index_buf, sizeof(overlay_index_buf),
2738 " gateway IP %s", obuf);
2739 }
2740
d62a17ae 2741 tag_buf[0] = '\0';
b57ba6d2 2742 if (bgp_labeled_safi(safi) && num_labels) {
d62a17ae 2743
b57ba6d2
MK
2744 if (safi == SAFI_EVPN) {
2745 char tag_buf2[20];
2746
2747 bgp_evpn_label2str(label, num_labels, tag_buf2, 20);
772270f3
QY
2748 snprintf(tag_buf, sizeof(tag_buf), " label %s",
2749 tag_buf2);
b57ba6d2 2750 } else {
d7c0a89a 2751 uint32_t label_value;
b57ba6d2
MK
2752
2753 label_value = decode_label(label);
772270f3
QY
2754 snprintf(tag_buf, sizeof(tag_buf), " label %u",
2755 label_value);
b57ba6d2 2756 }
d62a17ae 2757 }
2758
2759 if (prd)
6c995628 2760 snprintfrr(str, size, "RD %s %pFX%s%s%s %s %s",
2dbe669b 2761 prefix_rd2str(prd, rd_buf, sizeof(rd_buf)), pu.p,
6c995628
AD
2762 overlay_index_buf, tag_buf, pathid_buf, afi2str(afi),
2763 safi2str(safi));
268e1b9b
PG
2764 else if (safi == SAFI_FLOWSPEC) {
2765 char return_string[BGP_FLOWSPEC_NLRI_STRING_MAX];
2766 const struct prefix_fs *fs = pu.fs;
2767
2768 bgp_fs_nlri_get_string((unsigned char *)fs->prefix.ptr,
2769 fs->prefix.prefixlen,
2770 return_string,
1840384b
PG
2771 NLRI_STRING_FORMAT_DEBUG, NULL,
2772 family2afi(fs->prefix.family));
268e1b9b
PG
2773 snprintf(str, size, "FS %s Match{%s}", afi2str(afi),
2774 return_string);
2775 } else
2dbe669b
DA
2776 snprintfrr(str, size, "%pFX%s%s %s %s", pu.p, tag_buf,
2777 pathid_buf, afi2str(afi), safi2str(safi));
d62a17ae 2778
2779 return str;
906ad49b 2780}