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