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