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