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