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