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