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