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