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