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