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