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