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