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