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