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