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