1 /* BGP-4, BGP-4+ packet debug routine
2 * Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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
23 #include <lib/version.h>
29 #include "sockunion.h"
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"
46 unsigned long conf_bgp_debug_as4
;
47 unsigned long conf_bgp_debug_neighbor_events
;
48 unsigned long conf_bgp_debug_events
;
49 unsigned long conf_bgp_debug_packet
;
50 unsigned long conf_bgp_debug_filter
;
51 unsigned long conf_bgp_debug_keepalive
;
52 unsigned long conf_bgp_debug_update
;
53 unsigned long conf_bgp_debug_bestpath
;
54 unsigned long conf_bgp_debug_zebra
;
55 unsigned long conf_bgp_debug_allow_martians
;
56 unsigned long conf_bgp_debug_nht
;
57 unsigned long conf_bgp_debug_update_groups
;
59 unsigned long term_bgp_debug_as4
;
60 unsigned long term_bgp_debug_neighbor_events
;
61 unsigned long term_bgp_debug_events
;
62 unsigned long term_bgp_debug_packet
;
63 unsigned long term_bgp_debug_filter
;
64 unsigned long term_bgp_debug_keepalive
;
65 unsigned long term_bgp_debug_update
;
66 unsigned long term_bgp_debug_bestpath
;
67 unsigned long term_bgp_debug_zebra
;
68 unsigned long term_bgp_debug_allow_martians
;
69 unsigned long term_bgp_debug_nht
;
70 unsigned long term_bgp_debug_update_groups
;
72 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
73 struct list
*bgp_debug_keepalive_peers
= NULL
;
74 struct list
*bgp_debug_update_out_peers
= NULL
;
75 struct list
*bgp_debug_update_in_peers
= NULL
;
76 struct list
*bgp_debug_update_prefixes
= NULL
;
77 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
78 struct list
*bgp_debug_zebra_prefixes
= NULL
;
80 /* messages for BGP-4 status */
81 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
84 {OpenSent
, "OpenSent"},
85 {OpenConfirm
, "OpenConfirm"},
86 {Established
, "Established"},
87 {Clearing
, "Clearing"},
91 /* BGP message type string. */
92 const char *bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
93 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
96 /* message for BGP-4 Notify */
97 static const struct message bgp_notify_msg
[] = {
98 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
99 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
100 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
101 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
102 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
103 {BGP_NOTIFY_CEASE
, "Cease"},
104 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
107 static const struct message bgp_notify_head_msg
[] = {
108 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
109 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
110 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
113 static const struct message bgp_notify_open_msg
[] = {
114 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
115 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
116 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
117 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
118 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
119 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
120 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
121 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
124 static const struct message bgp_notify_update_msg
[] = {
125 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
126 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
127 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
128 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
129 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
130 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
131 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
132 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
133 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
134 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
135 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
136 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
139 static const struct message bgp_notify_cease_msg
[] = {
140 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
141 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
142 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
143 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
144 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
145 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
146 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
147 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
148 "/Connection collision resolution"},
149 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
152 static const struct message bgp_notify_capability_msg
[] = {
153 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
154 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
155 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
156 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
159 /* Origin strings. */
160 const char *bgp_origin_str
[] = {"i", "e", "?"};
161 const char *bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
164 /* Given a string return a pointer the corresponding peer structure */
165 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
167 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
175 ret
= str2sockunion(peer_str
, &su
);
179 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
182 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
186 return peer_lookup(bgp
, &su
);
189 static void bgp_debug_list_free(struct list
*list
)
191 struct bgp_debug_filter
*filter
;
192 struct listnode
*node
, *nnode
;
195 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
196 listnode_delete(list
, filter
);
199 prefix_free(filter
->p
);
202 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
204 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
208 /* Print the desc along with a list of peers/prefixes this debug is
210 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
213 struct bgp_debug_filter
*filter
;
214 struct listnode
*node
, *nnode
;
215 char buf
[INET6_ADDRSTRLEN
];
217 vty_out(vty
, "%s", desc
);
219 if (list
&& !list_isempty(list
)) {
220 vty_out(vty
, " for");
221 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
223 vty_out(vty
, " %s", filter
->host
);
226 vty_out(vty
, " %s/%d",
227 inet_ntop(filter
->p
->family
,
228 &filter
->p
->u
.prefix
, buf
,
230 filter
->p
->prefixlen
);
237 /* Print the command to enable the debug for each peer/prefix this debug is
240 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
243 struct bgp_debug_filter
*filter
;
244 struct listnode
*node
, *nnode
;
245 char buf
[INET6_ADDRSTRLEN
];
248 if (list
&& !list_isempty(list
)) {
249 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
251 vty_out(vty
, "%s %s\n", desc
, filter
->host
);
257 vty_out(vty
, "%s %s/%d\n", desc
,
258 inet_ntop(filter
->p
->family
,
259 &filter
->p
->u
.prefix
, buf
,
261 filter
->p
->prefixlen
);
268 vty_out(vty
, "%s\n", desc
);
275 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
276 const struct prefix
*p
)
278 struct bgp_debug_filter
*filter
;
280 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
281 sizeof(struct bgp_debug_filter
));
284 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
288 filter
->p
= prefix_new();
289 prefix_copy(filter
->p
, p
);
292 listnode_add(list
, filter
);
295 static int bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
298 struct bgp_debug_filter
*filter
;
299 struct listnode
*node
, *nnode
;
301 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
302 if (host
&& strcmp(filter
->host
, host
) == 0) {
303 listnode_delete(list
, filter
);
304 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
305 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
307 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
308 && prefix_match(filter
->p
, p
)) {
309 listnode_delete(list
, filter
);
310 prefix_free(filter
->p
);
311 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
319 static int bgp_debug_list_has_entry(struct list
*list
, const char *host
,
320 const struct prefix
*p
)
322 struct bgp_debug_filter
*filter
;
323 struct listnode
*node
, *nnode
;
325 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
327 if (strcmp(filter
->host
, host
) == 0) {
331 if (filter
->p
->prefixlen
== p
->prefixlen
332 && prefix_match(filter
->p
, p
)) {
341 int bgp_debug_peer_updout_enabled(char *host
)
343 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
347 /* Dump attribute. */
348 int bgp_dump_attr(struct attr
*attr
, char *buf
, size_t size
)
350 char addrbuf
[BUFSIZ
];
355 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
356 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
358 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
359 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
360 bgp_origin_str
[attr
->origin
]);
363 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
364 || attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
365 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
367 inet_ntop(AF_INET6
, &attr
->mp_nexthop_global
, addrbuf
,
370 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
371 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
372 inet_ntop(AF_INET6
, &attr
->mp_nexthop_local
, addrbuf
,
375 if (attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
376 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
378 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
)))
379 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
380 ", localpref %u", attr
->local_pref
);
382 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
)))
383 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", metric %u",
386 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
)))
387 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
388 ", community %s", community_str(attr
->community
,
391 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
392 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
393 ", extcommunity %s", ecommunity_str(attr
->ecommunity
));
395 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
396 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
397 ", atomic-aggregate");
399 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
400 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
401 ", aggregated by %u %s", attr
->aggregator_as
,
402 inet_ntoa(attr
->aggregator_addr
));
404 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
405 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
406 ", originator %s", inet_ntoa(attr
->originator_id
));
408 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
411 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
413 for (i
= 0; i
< attr
->cluster
->length
/ 4; i
++)
414 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
415 inet_ntoa(attr
->cluster
->list
[i
]));
418 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
419 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
420 aspath_print(attr
->aspath
));
422 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
))) {
423 if (attr
->label_index
!= BGP_INVALID_LABEL_INDEX
)
424 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
425 ", label-index %u", attr
->label_index
);
434 const char *bgp_notify_code_str(char code
)
436 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
439 const char *bgp_notify_subcode_str(char code
, char subcode
)
443 case BGP_NOTIFY_HEADER_ERR
:
444 return lookup_msg(bgp_notify_head_msg
, subcode
,
445 "Unrecognized Error Subcode");
446 case BGP_NOTIFY_OPEN_ERR
:
447 return lookup_msg(bgp_notify_open_msg
, subcode
,
448 "Unrecognized Error Subcode");
449 case BGP_NOTIFY_UPDATE_ERR
:
450 return lookup_msg(bgp_notify_update_msg
, subcode
,
451 "Unrecognized Error Subcode");
452 case BGP_NOTIFY_HOLD_ERR
:
454 case BGP_NOTIFY_FSM_ERR
:
456 case BGP_NOTIFY_CEASE
:
457 return lookup_msg(bgp_notify_cease_msg
, subcode
,
458 "Unrecognized Error Subcode");
459 case BGP_NOTIFY_CAPABILITY_ERR
:
460 return lookup_msg(bgp_notify_capability_msg
, subcode
,
461 "Unrecognized Error Subcode");
466 /* extract notify admin reason if correctly present */
467 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, u_char
*data
,
470 if (!data
|| datalen
< 1)
473 u_char len
= data
[0];
474 if (len
> 128 || len
> datalen
- 1)
477 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
480 /* dump notify packet */
481 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
484 const char *subcode_str
;
485 const char *code_str
;
486 const char *msg_str
= NULL
;
489 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
490 || bgp_flag_check(peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
491 code_str
= bgp_notify_code_str(bgp_notify
->code
);
492 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
493 bgp_notify
->subcode
);
495 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
496 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
497 || bgp_notify
->subcode
498 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
499 msg_str
= bgp_notify_admin_message(
500 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
506 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
507 strcmp(direct
, "received") == 0
510 peer
->host
, bgp_notify
->code
,
511 bgp_notify
->subcode
, code_str
, subcode_str
,
514 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
516 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
517 strcmp(direct
, "received") == 0
520 peer
->host
, bgp_notify
->code
,
521 bgp_notify
->subcode
, code_str
, subcode_str
,
522 bgp_notify
->length
, msg_str
);
527 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
530 bgp
= bgp_get_default();
531 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
535 /* Debug option setting interface. */
536 unsigned long bgp_debug_option
= 0;
538 int debug(unsigned int option
)
540 return bgp_debug_option
& option
;
543 DEFUN (debug_bgp_as4
,
550 if (vty
->node
== CONFIG_NODE
)
553 TERM_DEBUG_ON(as4
, AS4
);
554 vty_out(vty
, "BGP as4 debugging is on\n");
559 DEFUN (no_debug_bgp_as4
,
560 no_debug_bgp_as4_cmd
,
567 if (vty
->node
== CONFIG_NODE
)
570 TERM_DEBUG_OFF(as4
, AS4
);
571 vty_out(vty
, "BGP as4 debugging is off\n");
576 DEFUN (debug_bgp_as4_segment
,
577 debug_bgp_as4_segment_cmd
,
578 "debug bgp as4 segment",
582 "BGP AS4 aspath segment handling\n")
584 if (vty
->node
== CONFIG_NODE
)
585 DEBUG_ON(as4
, AS4_SEGMENT
);
587 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
588 vty_out(vty
, "BGP as4 segment debugging is on\n");
593 DEFUN (no_debug_bgp_as4_segment
,
594 no_debug_bgp_as4_segment_cmd
,
595 "no debug bgp as4 segment",
600 "BGP AS4 aspath segment handling\n")
602 if (vty
->node
== CONFIG_NODE
)
603 DEBUG_OFF(as4
, AS4_SEGMENT
);
605 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
606 vty_out(vty
, "BGP as4 segment debugging is off\n");
611 /* debug bgp neighbor_events */
612 DEFUN (debug_bgp_neighbor_events
,
613 debug_bgp_neighbor_events_cmd
,
614 "debug bgp neighbor-events",
617 "BGP Neighbor Events\n")
619 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
621 if (vty
->node
== CONFIG_NODE
)
622 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
624 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
625 vty_out(vty
, "BGP neighbor-events debugging is on\n");
630 DEFUN (debug_bgp_neighbor_events_peer
,
631 debug_bgp_neighbor_events_peer_cmd
,
632 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
635 "BGP Neighbor Events\n"
636 "BGP neighbor IP address to debug\n"
637 "BGP IPv6 neighbor to debug\n"
638 "BGP neighbor on interface to debug\n")
641 const char *host
= argv
[idx_peer
]->arg
;
643 if (!bgp_debug_neighbor_events_peers
)
644 bgp_debug_neighbor_events_peers
= list_new();
646 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
649 "BGP neighbor-events debugging is already enabled for %s\n",
654 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
656 if (vty
->node
== CONFIG_NODE
)
657 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
659 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
660 vty_out(vty
, "BGP neighbor-events debugging is on for %s\n",
666 DEFUN (no_debug_bgp_neighbor_events
,
667 no_debug_bgp_neighbor_events_cmd
,
668 "no debug bgp neighbor-events",
674 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
676 if (vty
->node
== CONFIG_NODE
)
677 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
679 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
680 vty_out(vty
, "BGP neighbor-events debugging is off\n");
685 DEFUN (no_debug_bgp_neighbor_events_peer
,
686 no_debug_bgp_neighbor_events_peer_cmd
,
687 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
692 "BGP neighbor IP address to debug\n"
693 "BGP IPv6 neighbor to debug\n"
694 "BGP neighbor on interface to debug\n")
698 const char *host
= argv
[idx_peer
]->arg
;
700 if (bgp_debug_neighbor_events_peers
701 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
702 found_peer
= bgp_debug_list_remove_entry(
703 bgp_debug_neighbor_events_peers
, host
, NULL
);
705 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
706 if (vty
->node
== CONFIG_NODE
)
707 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
709 TERM_DEBUG_OFF(neighbor_events
,
715 vty_out(vty
, "BGP neighbor-events debugging is off for %s\n",
719 "BGP neighbor-events debugging was not enabled for %s\n",
726 DEFUN (debug_bgp_nht
,
731 "BGP nexthop tracking events\n")
733 if (vty
->node
== CONFIG_NODE
)
736 TERM_DEBUG_ON(nht
, NHT
);
737 vty_out(vty
, "BGP nexthop tracking debugging is on\n");
742 DEFUN (no_debug_bgp_nht
,
743 no_debug_bgp_nht_cmd
,
748 "BGP nexthop tracking events\n")
750 if (vty
->node
== CONFIG_NODE
)
753 TERM_DEBUG_OFF(nht
, NHT
);
754 vty_out(vty
, "BGP nexthop tracking debugging is off\n");
759 /* debug bgp keepalives */
760 DEFUN (debug_bgp_keepalive
,
761 debug_bgp_keepalive_cmd
,
762 "debug bgp keepalives",
767 bgp_debug_list_free(bgp_debug_keepalive_peers
);
769 if (vty
->node
== CONFIG_NODE
)
770 DEBUG_ON(keepalive
, KEEPALIVE
);
772 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
773 vty_out(vty
, "BGP keepalives debugging is on\n");
778 DEFUN (debug_bgp_keepalive_peer
,
779 debug_bgp_keepalive_peer_cmd
,
780 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
783 "BGP Neighbor Events\n"
784 "BGP neighbor IP address to debug\n"
785 "BGP IPv6 neighbor to debug\n"
786 "BGP neighbor on interface to debug\n")
789 const char *host
= argv
[idx_peer
]->arg
;
791 if (!bgp_debug_keepalive_peers
)
792 bgp_debug_keepalive_peers
= list_new();
794 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
796 "BGP keepalive debugging is already enabled for %s\n",
801 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
803 if (vty
->node
== CONFIG_NODE
)
804 DEBUG_ON(keepalive
, KEEPALIVE
);
806 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
807 vty_out(vty
, "BGP keepalives debugging is on for %s\n", host
);
812 DEFUN (no_debug_bgp_keepalive
,
813 no_debug_bgp_keepalive_cmd
,
814 "no debug bgp keepalives",
820 bgp_debug_list_free(bgp_debug_keepalive_peers
);
822 if (vty
->node
== CONFIG_NODE
)
823 DEBUG_OFF(keepalive
, KEEPALIVE
);
825 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
826 vty_out(vty
, "BGP keepalives debugging is off\n");
831 DEFUN (no_debug_bgp_keepalive_peer
,
832 no_debug_bgp_keepalive_peer_cmd
,
833 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
838 "BGP neighbor IP address to debug\n"
839 "BGP IPv6 neighbor to debug\n"
840 "BGP neighbor on interface to debug\n")
844 const char *host
= argv
[idx_peer
]->arg
;
846 if (bgp_debug_keepalive_peers
847 && !list_isempty(bgp_debug_keepalive_peers
)) {
848 found_peer
= bgp_debug_list_remove_entry(
849 bgp_debug_keepalive_peers
, host
, NULL
);
851 if (list_isempty(bgp_debug_keepalive_peers
)) {
852 if (vty
->node
== CONFIG_NODE
)
853 DEBUG_OFF(keepalive
, KEEPALIVE
);
855 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
860 vty_out(vty
, "BGP keepalives debugging is off for %s\n", host
);
863 "BGP keepalives debugging was not enabled for %s\n",
869 /* debug bgp bestpath */
870 DEFUN (debug_bgp_bestpath_prefix
,
871 debug_bgp_bestpath_prefix_cmd
,
872 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
879 struct prefix
*argv_p
;
880 int idx_ipv4_ipv6_prefixlen
= 3;
882 argv_p
= prefix_new();
883 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
886 if (!bgp_debug_bestpath_prefixes
)
887 bgp_debug_bestpath_prefixes
= list_new();
889 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
892 "BGP bestpath debugging is already enabled for %s\n",
893 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
897 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
899 if (vty
->node
== CONFIG_NODE
) {
900 DEBUG_ON(bestpath
, BESTPATH
);
902 TERM_DEBUG_ON(bestpath
, BESTPATH
);
903 vty_out(vty
, "BGP bestpath debugging is on for %s\n",
904 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
910 DEFUN (no_debug_bgp_bestpath_prefix
,
911 no_debug_bgp_bestpath_prefix_cmd
,
912 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
920 int idx_ipv4_ipv6_prefixlen
= 4;
921 struct prefix
*argv_p
;
922 int found_prefix
= 0;
924 argv_p
= prefix_new();
925 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
928 if (bgp_debug_bestpath_prefixes
929 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
930 found_prefix
= bgp_debug_list_remove_entry(
931 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
933 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
934 if (vty
->node
== CONFIG_NODE
) {
935 DEBUG_OFF(bestpath
, BESTPATH
);
937 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
939 "BGP bestpath debugging (per prefix) is off\n");
945 vty_out(vty
, "BGP bestpath debugging is off for %s\n",
946 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
948 vty_out(vty
, "BGP bestpath debugging was not enabled for %s\n",
949 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
954 DEFUN (no_debug_bgp_bestpath
,
955 no_debug_bgp_bestpath_cmd
,
956 "no debug bgp bestpath",
962 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
964 if (vty
->node
== CONFIG_NODE
)
965 DEBUG_OFF(bestpath
, BESTPATH
);
967 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
968 vty_out(vty
, "BGP bestpath debugging is off\n");
973 /* debug bgp updates */
974 DEFUN (debug_bgp_update
,
975 debug_bgp_update_cmd
,
981 bgp_debug_list_free(bgp_debug_update_in_peers
);
982 bgp_debug_list_free(bgp_debug_update_out_peers
);
983 bgp_debug_list_free(bgp_debug_update_prefixes
);
985 if (vty
->node
== CONFIG_NODE
) {
986 DEBUG_ON(update
, UPDATE_IN
);
987 DEBUG_ON(update
, UPDATE_OUT
);
989 TERM_DEBUG_ON(update
, UPDATE_IN
);
990 TERM_DEBUG_ON(update
, UPDATE_OUT
);
991 vty_out(vty
, "BGP updates debugging is on\n");
996 DEFUN (debug_bgp_update_direct
,
997 debug_bgp_update_direct_cmd
,
998 "debug bgp updates <in|out>",
1003 "Outbound updates\n")
1007 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1008 bgp_debug_list_free(bgp_debug_update_in_peers
);
1010 bgp_debug_list_free(bgp_debug_update_out_peers
);
1012 if (vty
->node
== CONFIG_NODE
) {
1013 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1014 DEBUG_ON(update
, UPDATE_IN
);
1016 DEBUG_ON(update
, UPDATE_OUT
);
1018 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1019 TERM_DEBUG_ON(update
, UPDATE_IN
);
1020 vty_out(vty
, "BGP updates debugging is on (inbound)\n");
1022 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1024 "BGP updates debugging is on (outbound)\n");
1030 DEFUN (debug_bgp_update_direct_peer
,
1031 debug_bgp_update_direct_peer_cmd
,
1032 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1037 "Outbound updates\n"
1038 "BGP neighbor IP address to debug\n"
1039 "BGP IPv6 neighbor to debug\n"
1040 "BGP neighbor on interface to debug\n")
1044 const char *host
= argv
[idx_peer
]->arg
;
1047 if (!bgp_debug_update_in_peers
)
1048 bgp_debug_update_in_peers
= list_new();
1050 if (!bgp_debug_update_out_peers
)
1051 bgp_debug_update_out_peers
= list_new();
1053 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1059 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1062 "BGP inbound update debugging is already enabled for %s\n",
1069 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1072 "BGP outbound update debugging is already enabled for %s\n",
1079 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1082 struct peer_af
*paf
;
1085 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1087 peer
= bgp_find_peer(vty
, host
);
1090 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1092 paf
= peer
->peer_af_array
[afidx
];
1094 if (PAF_SUBGRP(paf
)) {
1104 if (vty
->node
== CONFIG_NODE
) {
1106 DEBUG_ON(update
, UPDATE_IN
);
1108 DEBUG_ON(update
, UPDATE_OUT
);
1111 TERM_DEBUG_ON(update
, UPDATE_IN
);
1113 "BGP updates debugging is on (inbound) for %s\n",
1114 argv
[idx_peer
]->arg
);
1116 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1118 "BGP updates debugging is on (outbound) for %s\n",
1119 argv
[idx_peer
]->arg
);
1125 DEFUN (no_debug_bgp_update_direct
,
1126 no_debug_bgp_update_direct_cmd
,
1127 "no debug bgp updates <in|out>",
1133 "Outbound updates\n")
1136 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1137 bgp_debug_list_free(bgp_debug_update_in_peers
);
1139 if (vty
->node
== CONFIG_NODE
) {
1140 DEBUG_OFF(update
, UPDATE_IN
);
1142 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1144 "BGP updates debugging is off (inbound)\n");
1147 bgp_debug_list_free(bgp_debug_update_out_peers
);
1149 if (vty
->node
== CONFIG_NODE
) {
1150 DEBUG_OFF(update
, UPDATE_OUT
);
1152 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1154 "BGP updates debugging is off (outbound)\n");
1161 DEFUN (no_debug_bgp_update_direct_peer
,
1162 no_debug_bgp_update_direct_peer_cmd
,
1163 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1169 "Outbound updates\n"
1170 "BGP neighbor IP address to debug\n"
1171 "BGP IPv6 neighbor to debug\n"
1172 "BGP neighbor on interface to debug\n")
1178 const char *host
= argv
[idx_peer
]->arg
;
1180 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1185 if (inbound
&& bgp_debug_update_in_peers
1186 && !list_isempty(bgp_debug_update_in_peers
)) {
1187 found_peer
= bgp_debug_list_remove_entry(
1188 bgp_debug_update_in_peers
, host
, NULL
);
1190 if (list_isempty(bgp_debug_update_in_peers
)) {
1191 if (vty
->node
== CONFIG_NODE
)
1192 DEBUG_OFF(update
, UPDATE_IN
);
1194 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1196 "BGP updates debugging (inbound) is off\n");
1201 if (!inbound
&& bgp_debug_update_out_peers
1202 && !list_isempty(bgp_debug_update_out_peers
)) {
1203 found_peer
= bgp_debug_list_remove_entry(
1204 bgp_debug_update_out_peers
, host
, NULL
);
1206 if (list_isempty(bgp_debug_update_out_peers
)) {
1207 if (vty
->node
== CONFIG_NODE
)
1208 DEBUG_OFF(update
, UPDATE_OUT
);
1210 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1212 "BGP updates debugging (outbound) is off\n");
1217 struct peer_af
*paf
;
1219 peer
= bgp_find_peer(vty
, host
);
1222 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1224 paf
= peer
->peer_af_array
[afidx
];
1226 if (PAF_SUBGRP(paf
)) {
1227 UPDGRP_PEER_DBG_DIS(
1239 "BGP updates debugging (inbound) is off for %s\n",
1243 "BGP updates debugging (outbound) is off for %s\n",
1247 "BGP updates debugging (inbound) was not enabled for %s\n",
1251 "BGP updates debugging (outbound) was not enabled for %s\n",
1257 DEFUN (debug_bgp_update_prefix
,
1258 debug_bgp_update_prefix_cmd
,
1259 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1263 "Specify a prefix to debug\n"
1267 int idx_ipv4_ipv6_prefixlen
= 4;
1268 struct prefix
*argv_p
;
1270 argv_p
= prefix_new();
1271 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1274 if (!bgp_debug_update_prefixes
)
1275 bgp_debug_update_prefixes
= list_new();
1277 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1279 "BGP updates debugging is already enabled for %s\n",
1280 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1284 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1286 if (vty
->node
== CONFIG_NODE
) {
1287 DEBUG_ON(update
, UPDATE_PREFIX
);
1289 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1290 vty_out(vty
, "BGP updates debugging is on for %s\n",
1291 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1297 DEFUN (no_debug_bgp_update_prefix
,
1298 no_debug_bgp_update_prefix_cmd
,
1299 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1304 "Specify a prefix to debug\n"
1308 int idx_ipv4_ipv6_prefixlen
= 5;
1309 struct prefix
*argv_p
;
1310 int found_prefix
= 0;
1312 argv_p
= prefix_new();
1313 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1316 if (bgp_debug_update_prefixes
1317 && !list_isempty(bgp_debug_update_prefixes
)) {
1318 found_prefix
= bgp_debug_list_remove_entry(
1319 bgp_debug_update_prefixes
, NULL
, argv_p
);
1321 if (list_isempty(bgp_debug_update_prefixes
)) {
1322 if (vty
->node
== CONFIG_NODE
) {
1323 DEBUG_OFF(update
, UPDATE_PREFIX
);
1325 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1327 "BGP updates debugging (per prefix) is off\n");
1333 vty_out(vty
, "BGP updates debugging is off for %s\n",
1334 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1336 vty_out(vty
, "BGP updates debugging was not enabled for %s\n",
1337 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1342 DEFUN (no_debug_bgp_update
,
1343 no_debug_bgp_update_cmd
,
1344 "no debug bgp updates",
1350 struct listnode
*ln
;
1353 bgp_debug_list_free(bgp_debug_update_in_peers
);
1354 bgp_debug_list_free(bgp_debug_update_out_peers
);
1355 bgp_debug_list_free(bgp_debug_update_prefixes
);
1357 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1358 bgp_debug_clear_updgrp_update_dbg(bgp
);
1360 if (vty
->node
== CONFIG_NODE
) {
1361 DEBUG_OFF(update
, UPDATE_IN
);
1362 DEBUG_OFF(update
, UPDATE_OUT
);
1363 DEBUG_OFF(update
, UPDATE_PREFIX
);
1365 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1366 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1367 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1368 vty_out(vty
, "BGP updates debugging is off\n");
1373 /* debug bgp zebra */
1374 DEFUN (debug_bgp_zebra
,
1375 debug_bgp_zebra_cmd
,
1379 "BGP Zebra messages\n")
1381 if (vty
->node
== CONFIG_NODE
)
1382 DEBUG_ON(zebra
, ZEBRA
);
1384 TERM_DEBUG_ON(zebra
, ZEBRA
);
1385 vty_out(vty
, "BGP zebra debugging is on\n");
1390 DEFUN (debug_bgp_zebra_prefix
,
1391 debug_bgp_zebra_prefix_cmd
,
1392 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1395 "BGP Zebra messages\n"
1396 "Specify a prefix to debug\n"
1400 int idx_ipv4_ipv6_prefixlen
= 4;
1401 struct prefix
*argv_p
;
1403 argv_p
= prefix_new();
1404 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1407 if (!bgp_debug_zebra_prefixes
)
1408 bgp_debug_zebra_prefixes
= list_new();
1410 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1411 vty_out(vty
, "BGP zebra debugging is already enabled for %s\n",
1412 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1416 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1418 if (vty
->node
== CONFIG_NODE
)
1419 DEBUG_ON(zebra
, ZEBRA
);
1421 TERM_DEBUG_ON(zebra
, ZEBRA
);
1422 vty_out(vty
, "BGP zebra debugging is on for %s\n",
1423 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1429 DEFUN (no_debug_bgp_zebra
,
1430 no_debug_bgp_zebra_cmd
,
1431 "no debug bgp zebra",
1435 "BGP Zebra messages\n")
1437 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1439 if (vty
->node
== CONFIG_NODE
)
1440 DEBUG_OFF(zebra
, ZEBRA
);
1442 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1443 vty_out(vty
, "BGP zebra debugging is off\n");
1448 DEFUN (no_debug_bgp_zebra_prefix
,
1449 no_debug_bgp_zebra_prefix_cmd
,
1450 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1454 "BGP Zebra messages\n"
1455 "Specify a prefix to debug\n"
1459 int idx_ipv4_ipv6_prefixlen
= 5;
1460 struct prefix
*argv_p
;
1461 int found_prefix
= 0;
1463 argv_p
= prefix_new();
1464 (void)str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1467 if (bgp_debug_zebra_prefixes
1468 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1469 found_prefix
= bgp_debug_list_remove_entry(
1470 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1472 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1473 if (vty
->node
== CONFIG_NODE
)
1474 DEBUG_OFF(zebra
, ZEBRA
);
1476 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1477 vty_out(vty
, "BGP zebra debugging is off\n");
1483 vty_out(vty
, "BGP zebra debugging is off for %s\n",
1484 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1486 vty_out(vty
, "BGP zebra debugging was not enabled for %s\n",
1487 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1492 DEFUN (debug_bgp_allow_martians
,
1493 debug_bgp_allow_martians_cmd
,
1494 "debug bgp allow-martians",
1497 "BGP allow martian next hops\n")
1499 if (vty
->node
== CONFIG_NODE
)
1500 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1502 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1503 vty_out(vty
, "BGP allow_martian next hop debugging is on\n");
1508 DEFUN (no_debug_bgp_allow_martians
,
1509 no_debug_bgp_allow_martians_cmd
,
1510 "no debug bgp allow-martians",
1514 "BGP allow martian next hops\n")
1516 if (vty
->node
== CONFIG_NODE
)
1517 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1519 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1520 vty_out(vty
, "BGP allow martian next hop debugging is off\n");
1526 /* debug bgp update-groups */
1527 DEFUN (debug_bgp_update_groups
,
1528 debug_bgp_update_groups_cmd
,
1529 "debug bgp update-groups",
1532 "BGP update-groups\n")
1534 if (vty
->node
== CONFIG_NODE
)
1535 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1537 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1538 vty_out(vty
, "BGP update-groups debugging is on\n");
1543 DEFUN (no_debug_bgp_update_groups
,
1544 no_debug_bgp_update_groups_cmd
,
1545 "no debug bgp update-groups",
1549 "BGP update-groups\n")
1551 if (vty
->node
== CONFIG_NODE
)
1552 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1554 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1555 vty_out(vty
, "BGP update-groups debugging is off\n");
1560 DEFUN (no_debug_bgp
,
1568 struct listnode
*ln
;
1570 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
1571 bgp_debug_list_free(bgp_debug_keepalive_peers
);
1572 bgp_debug_list_free(bgp_debug_update_in_peers
);
1573 bgp_debug_list_free(bgp_debug_update_out_peers
);
1574 bgp_debug_list_free(bgp_debug_update_prefixes
);
1575 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1576 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1578 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, ln
, bgp
))
1579 bgp_debug_clear_updgrp_update_dbg(bgp
);
1581 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
1582 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1583 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1584 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1585 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1586 TERM_DEBUG_OFF(as4
, AS4
);
1587 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
1588 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
1589 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1590 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1591 TERM_DEBUG_OFF(nht
, NHT
);
1592 vty_out(vty
, "All possible debugging has been turned off\n");
1597 DEFUN_NOSH (show_debugging_bgp
,
1598 show_debugging_bgp_cmd
,
1599 "show debugging [bgp]",
1604 vty_out(vty
, "BGP debugging status:\n");
1606 if (BGP_DEBUG(as4
, AS4
))
1607 vty_out(vty
, " BGP as4 debugging is on\n");
1609 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
1610 vty_out(vty
, " BGP as4 aspath segment debugging is on\n");
1612 if (BGP_DEBUG(bestpath
, BESTPATH
))
1613 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
1614 bgp_debug_bestpath_prefixes
);
1616 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
1617 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
1618 bgp_debug_keepalive_peers
);
1620 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
1621 bgp_debug_list_print(vty
,
1622 " BGP neighbor-events debugging is on",
1623 bgp_debug_neighbor_events_peers
);
1625 if (BGP_DEBUG(nht
, NHT
))
1626 vty_out(vty
, " BGP next-hop tracking debugging is on\n");
1628 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1629 vty_out(vty
, " BGP update-groups debugging is on\n");
1631 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
1632 bgp_debug_list_print(vty
, " BGP updates debugging is on",
1633 bgp_debug_update_prefixes
);
1635 if (BGP_DEBUG(update
, UPDATE_IN
))
1636 bgp_debug_list_print(vty
,
1637 " BGP updates debugging is on (inbound)",
1638 bgp_debug_update_in_peers
);
1640 if (BGP_DEBUG(update
, UPDATE_OUT
))
1641 bgp_debug_list_print(vty
,
1642 " BGP updates debugging is on (outbound)",
1643 bgp_debug_update_out_peers
);
1645 if (BGP_DEBUG(zebra
, ZEBRA
))
1646 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
1647 bgp_debug_zebra_prefixes
);
1649 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
1650 vty_out(vty
, " BGP allow martian next hop debugging is on\n");
1655 /* return count of number of debug flags set */
1656 int bgp_debug_count(void)
1659 if (BGP_DEBUG(as4
, AS4
))
1662 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
1665 if (BGP_DEBUG(bestpath
, BESTPATH
))
1668 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
1671 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
1674 if (BGP_DEBUG(nht
, NHT
))
1677 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1680 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
1683 if (BGP_DEBUG(update
, UPDATE_IN
))
1686 if (BGP_DEBUG(update
, UPDATE_OUT
))
1689 if (BGP_DEBUG(zebra
, ZEBRA
))
1692 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
1698 static int bgp_config_write_debug(struct vty
*vty
)
1702 if (CONF_BGP_DEBUG(as4
, AS4
)) {
1703 vty_out(vty
, "debug bgp as4\n");
1707 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
1708 vty_out(vty
, "debug bgp as4 segment\n");
1712 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
1713 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
1714 bgp_debug_bestpath_prefixes
);
1717 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
1718 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
1719 bgp_debug_keepalive_peers
);
1722 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
1723 write
+= bgp_debug_list_conf_print(
1724 vty
, "debug bgp neighbor-events",
1725 bgp_debug_neighbor_events_peers
);
1728 if (CONF_BGP_DEBUG(nht
, NHT
)) {
1729 vty_out(vty
, "debug bgp nht\n");
1733 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
1734 vty_out(vty
, "debug bgp update-groups\n");
1738 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
1739 write
+= bgp_debug_list_conf_print(vty
,
1740 "debug bgp updates prefix",
1741 bgp_debug_update_prefixes
);
1744 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
1745 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
1746 bgp_debug_update_in_peers
);
1749 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
1750 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
1751 bgp_debug_update_out_peers
);
1754 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
1755 if (!bgp_debug_zebra_prefixes
1756 || list_isempty(bgp_debug_zebra_prefixes
)) {
1757 vty_out(vty
, "debug bgp zebra\n");
1760 write
+= bgp_debug_list_conf_print(
1761 vty
, "debug bgp zebra prefix",
1762 bgp_debug_zebra_prefixes
);
1766 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
1767 vty_out(vty
, "debug bgp allow-martians\n");
1774 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
1776 void bgp_debug_init(void)
1778 install_node(&debug_node
, bgp_config_write_debug
);
1780 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
1782 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
1783 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
1784 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
1785 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
1787 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
1788 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
1789 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
1790 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
1791 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
1792 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
1793 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
1794 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
1795 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
1796 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
1797 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
1798 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
1799 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
1800 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
1801 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1802 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1804 /* debug bgp updates (in|out) */
1805 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
1806 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
1807 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
1808 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
1810 /* debug bgp updates (in|out) A.B.C.D */
1811 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
1812 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
1813 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1814 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1816 /* debug bgp updates prefix A.B.C.D/M */
1817 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
1818 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
1819 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
1820 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
1822 /* debug bgp zebra prefix A.B.C.D/M */
1823 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
1824 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
1825 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1826 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1828 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
1829 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
1830 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
1831 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
1833 /* debug bgp neighbor-events A.B.C.D */
1834 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1835 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1836 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1837 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1839 /* debug bgp keepalive A.B.C.D */
1840 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
1841 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
1842 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1843 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1845 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1846 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1847 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
1848 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
1849 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
1850 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
1851 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
1852 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
1853 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
1854 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
1855 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
1856 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
1857 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
1858 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
1859 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
1860 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
1861 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
1862 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1863 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1866 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
1867 * for BGP_DEBUG_TYPE
1869 static int bgp_debug_per_prefix(struct prefix
*p
,
1870 unsigned long term_bgp_debug_type
,
1871 unsigned int BGP_DEBUG_TYPE
,
1872 struct list
*per_prefix_list
)
1874 struct bgp_debug_filter
*filter
;
1875 struct listnode
*node
, *nnode
;
1877 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
1878 /* We are debugging all prefixes so return true */
1879 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
1886 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
1888 if (filter
->p
->prefixlen
== p
->prefixlen
1889 && prefix_match(filter
->p
, p
))
1899 /* Return true if this peer is on the per_peer_list of peers to debug
1900 * for BGP_DEBUG_TYPE
1902 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
1903 unsigned int BGP_DEBUG_TYPE
,
1904 struct list
*per_peer_list
)
1906 struct bgp_debug_filter
*filter
;
1907 struct listnode
*node
, *nnode
;
1909 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
1910 /* We are debugging all peers so return true */
1911 if (!per_peer_list
|| list_isempty(per_peer_list
))
1918 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
1920 if (strcmp(filter
->host
, host
) == 0)
1930 int bgp_debug_neighbor_events(struct peer
*peer
)
1937 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
1938 BGP_DEBUG_NEIGHBOR_EVENTS
,
1939 bgp_debug_neighbor_events_peers
);
1942 int bgp_debug_keepalive(struct peer
*peer
)
1949 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
1950 BGP_DEBUG_KEEPALIVE
,
1951 bgp_debug_keepalive_peers
);
1954 int bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
1955 struct update_group
*updgrp
, unsigned int inbound
)
1963 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
1964 BGP_DEBUG_UPDATE_IN
,
1965 bgp_debug_update_in_peers
))
1971 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
1972 BGP_DEBUG_UPDATE_OUT
,
1973 bgp_debug_update_out_peers
))
1976 /* Check if update debugging implicitly enabled for the group.
1978 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
1983 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
1984 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
1985 BGP_DEBUG_UPDATE_PREFIX
,
1986 bgp_debug_update_prefixes
))
1993 int bgp_debug_bestpath(struct prefix
*p
)
1995 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
1996 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
1998 bgp_debug_bestpath_prefixes
))
2005 int bgp_debug_zebra(struct prefix
*p
)
2007 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2008 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2010 bgp_debug_zebra_prefixes
))
2017 const char *bgp_debug_rdpfxpath2str(afi_t afi
, safi_t safi
,
2018 struct prefix_rd
*prd
,
2019 union prefixconstptr pu
,
2020 mpls_label_t
*label
, int addpath_valid
,
2021 u_int32_t addpath_id
, char *str
, int size
)
2023 char rd_buf
[RD_ADDRSTRLEN
];
2024 char pfx_buf
[PREFIX_STRLEN
];
2026 /* ' with addpath ID ' 17
2027 * max strlen of uint32 + 10
2028 * +/- (just in case) + 1
2029 * null terminator + 1
2030 * ============================ 29 */
2031 char pathid_buf
[30];
2033 if (size
< BGP_PRD_PATH_STRLEN
)
2036 /* Note: Path-id is created by default, but only included in update
2038 pathid_buf
[0] = '\0';
2040 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2044 if (bgp_labeled_safi(safi
) && label
) {
2045 u_int32_t label_value
;
2047 label_value
= decode_label(label
);
2048 sprintf(tag_buf
, " label %u", label_value
);
2052 snprintf(str
, size
, "RD %s %s%s%s %s %s",
2053 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2054 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2055 pathid_buf
, afi2str(afi
), safi2str(safi
));
2057 snprintf(str
, size
, "%s%s%s %s %s",
2058 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), tag_buf
,
2059 pathid_buf
, afi2str(afi
), safi2str(safi
));