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