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