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