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