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
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
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"
43 unsigned long conf_bgp_debug_as4
;
44 unsigned long conf_bgp_debug_neighbor_events
;
45 unsigned long conf_bgp_debug_events
;
46 unsigned long conf_bgp_debug_packet
;
47 unsigned long conf_bgp_debug_filter
;
48 unsigned long conf_bgp_debug_keepalive
;
49 unsigned long conf_bgp_debug_update
;
50 unsigned long conf_bgp_debug_bestpath
;
51 unsigned long conf_bgp_debug_zebra
;
52 unsigned long conf_bgp_debug_allow_martians
;
53 unsigned long conf_bgp_debug_nht
;
54 unsigned long conf_bgp_debug_update_groups
;
56 unsigned long term_bgp_debug_as4
;
57 unsigned long term_bgp_debug_neighbor_events
;
58 unsigned long term_bgp_debug_events
;
59 unsigned long term_bgp_debug_packet
;
60 unsigned long term_bgp_debug_filter
;
61 unsigned long term_bgp_debug_keepalive
;
62 unsigned long term_bgp_debug_update
;
63 unsigned long term_bgp_debug_bestpath
;
64 unsigned long term_bgp_debug_zebra
;
65 unsigned long term_bgp_debug_allow_martians
;
66 unsigned long term_bgp_debug_nht
;
67 unsigned long term_bgp_debug_update_groups
;
69 struct list
*bgp_debug_neighbor_events_peers
= NULL
;
70 struct list
*bgp_debug_keepalive_peers
= NULL
;
71 struct list
*bgp_debug_update_out_peers
= NULL
;
72 struct list
*bgp_debug_update_in_peers
= NULL
;
73 struct list
*bgp_debug_update_prefixes
= NULL
;
74 struct list
*bgp_debug_bestpath_prefixes
= NULL
;
75 struct list
*bgp_debug_zebra_prefixes
= NULL
;
77 /* messages for BGP-4 status */
78 const struct message bgp_status_msg
[] = {{Idle
, "Idle"},
81 {OpenSent
, "OpenSent"},
82 {OpenConfirm
, "OpenConfirm"},
83 {Established
, "Established"},
84 {Clearing
, "Clearing"},
88 /* BGP message type string. */
89 const char *bgp_type_str
[] = {NULL
, "OPEN", "UPDATE",
90 "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
93 /* message for BGP-4 Notify */
94 static const struct message bgp_notify_msg
[] = {
95 {BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
96 {BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
97 {BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
98 {BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
99 {BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
100 {BGP_NOTIFY_CEASE
, "Cease"},
101 {BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
104 static const struct message bgp_notify_head_msg
[] = {
105 {BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
106 {BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
107 {BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
110 static const struct message bgp_notify_open_msg
[] = {
111 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
112 {BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number"},
113 {BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
114 {BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
115 {BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
116 {BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
117 {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
118 {BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
121 static const struct message bgp_notify_update_msg
[] = {
122 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
123 {BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
124 {BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
125 {BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
126 {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
127 {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
128 {BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
129 {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
130 {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
131 {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
132 {BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
133 {BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
136 static const struct message bgp_notify_cease_msg
[] = {
137 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
138 {BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
139 {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
140 {BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
141 {BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
142 {BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
143 {BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
144 {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
,
145 "/Connection collision resolution"},
146 {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
149 static const struct message bgp_notify_capability_msg
[] = {
150 {BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
151 {BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value"},
152 {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
153 {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
156 /* Origin strings. */
157 const char *bgp_origin_str
[] = {"i", "e", "?"};
158 const char *bgp_origin_long_str
[] = {"IGP", "EGP", "incomplete"};
161 /* Given a string return a pointer the corresponding peer structure */
162 static struct peer
*bgp_find_peer(struct vty
*vty
, const char *peer_str
)
164 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
172 ret
= str2sockunion(peer_str
, &su
);
176 peer
= peer_lookup_by_conf_if(bgp
, peer_str
);
179 peer
= peer_lookup_by_hostname(bgp
, peer_str
);
183 return peer_lookup(bgp
, &su
);
186 static void bgp_debug_list_free(struct list
*list
)
188 struct bgp_debug_filter
*filter
;
189 struct listnode
*node
, *nnode
;
192 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
193 listnode_delete(list
, filter
);
196 prefix_free(filter
->p
);
199 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
201 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
205 /* Print the desc along with a list of peers/prefixes this debug is
207 static void bgp_debug_list_print(struct vty
*vty
, const char *desc
,
210 struct bgp_debug_filter
*filter
;
211 struct listnode
*node
, *nnode
;
212 char buf
[INET6_ADDRSTRLEN
];
214 vty_out(vty
, "%s", desc
);
216 if (list
&& !list_isempty(list
)) {
217 vty_out(vty
, " for");
218 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
220 vty_out(vty
, " %s", filter
->host
);
223 vty_out(vty
, " %s/%d",
224 inet_ntop(filter
->p
->family
,
225 &filter
->p
->u
.prefix
, buf
,
227 filter
->p
->prefixlen
);
231 vty_out(vty
, "%s", VTY_NEWLINE
);
234 /* Print the command to enable the debug for each peer/prefix this debug is
237 static int bgp_debug_list_conf_print(struct vty
*vty
, const char *desc
,
240 struct bgp_debug_filter
*filter
;
241 struct listnode
*node
, *nnode
;
242 char buf
[INET6_ADDRSTRLEN
];
245 if (list
&& !list_isempty(list
)) {
246 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
248 vty_out(vty
, "%s %s%s", desc
, filter
->host
,
255 vty_out(vty
, "%s %s/%d%s", desc
,
256 inet_ntop(filter
->p
->family
,
257 &filter
->p
->u
.prefix
, buf
,
259 filter
->p
->prefixlen
, VTY_NEWLINE
);
266 vty_out(vty
, "%s%s", desc
, VTY_NEWLINE
);
273 static void bgp_debug_list_add_entry(struct list
*list
, const char *host
,
276 struct bgp_debug_filter
*filter
;
278 filter
= XCALLOC(MTYPE_BGP_DEBUG_FILTER
,
279 sizeof(struct bgp_debug_filter
));
282 filter
->host
= XSTRDUP(MTYPE_BGP_DEBUG_STR
, host
);
289 listnode_add(list
, filter
);
292 static int bgp_debug_list_remove_entry(struct list
*list
, const char *host
,
295 struct bgp_debug_filter
*filter
;
296 struct listnode
*node
, *nnode
;
298 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
299 if (host
&& strcmp(filter
->host
, host
) == 0) {
300 listnode_delete(list
, filter
);
301 XFREE(MTYPE_BGP_DEBUG_STR
, filter
->host
);
302 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
304 } else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
305 && prefix_match(filter
->p
, p
)) {
306 listnode_delete(list
, filter
);
307 prefix_free(filter
->p
);
308 XFREE(MTYPE_BGP_DEBUG_FILTER
, filter
);
316 static int bgp_debug_list_has_entry(struct list
*list
, const char *host
,
319 struct bgp_debug_filter
*filter
;
320 struct listnode
*node
, *nnode
;
322 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, filter
)) {
324 if (strcmp(filter
->host
, host
) == 0) {
328 if (filter
->p
->prefixlen
== p
->prefixlen
329 && prefix_match(filter
->p
, p
)) {
338 int bgp_debug_peer_updout_enabled(char *host
)
340 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
344 /* Dump attribute. */
345 int bgp_dump_attr(struct peer
*peer
, struct attr
*attr
, char *buf
, size_t size
)
350 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)))
351 snprintf(buf
, size
, "nexthop %s", inet_ntoa(attr
->nexthop
));
353 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN
)))
354 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", origin %s",
355 bgp_origin_str
[attr
->origin
]);
358 char addrbuf
[BUFSIZ
];
361 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
362 || attr
->extra
->mp_nexthop_len
363 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
364 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
367 &attr
->extra
->mp_nexthop_global
,
370 if (attr
->extra
->mp_nexthop_len
371 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
372 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), "(%s)",
374 &attr
->extra
->mp_nexthop_local
,
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
));
390 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
)))
391 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
392 ", atomic-aggregate");
394 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
)))
395 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
396 ", aggregated by %u %s", attr
->extra
->aggregator_as
,
397 inet_ntoa(attr
->extra
->aggregator_addr
));
399 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)))
400 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
402 inet_ntoa(attr
->extra
->originator_id
));
404 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))) {
407 snprintf(buf
+ strlen(buf
), size
- strlen(buf
),
409 for (i
= 0; i
< attr
->extra
->cluster
->length
/ 4; i
++)
410 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), " %s",
411 inet_ntoa(attr
->extra
->cluster
->list
[i
]));
414 if (CHECK_FLAG(attr
->flag
, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH
)))
415 snprintf(buf
+ strlen(buf
), size
- strlen(buf
), ", path %s",
416 aspath_print(attr
->aspath
));
424 const char *bgp_notify_code_str(char code
)
426 return lookup_msg(bgp_notify_msg
, code
, "Unrecognized Error Code");
429 const char *bgp_notify_subcode_str(char code
, char subcode
)
433 case BGP_NOTIFY_HEADER_ERR
:
434 return lookup_msg(bgp_notify_head_msg
, subcode
,
435 "Unrecognized Error Subcode");
436 case BGP_NOTIFY_OPEN_ERR
:
437 return lookup_msg(bgp_notify_open_msg
, subcode
,
438 "Unrecognized Error Subcode");
439 case BGP_NOTIFY_UPDATE_ERR
:
440 return lookup_msg(bgp_notify_update_msg
, subcode
,
441 "Unrecognized Error Subcode");
442 case BGP_NOTIFY_HOLD_ERR
:
444 case BGP_NOTIFY_FSM_ERR
:
446 case BGP_NOTIFY_CEASE
:
447 return lookup_msg(bgp_notify_cease_msg
, subcode
,
448 "Unrecognized Error Subcode");
449 case BGP_NOTIFY_CAPABILITY_ERR
:
450 return lookup_msg(bgp_notify_capability_msg
, subcode
,
451 "Unrecognized Error Subcode");
456 /* extract notify admin reason if correctly present */
457 const char *bgp_notify_admin_message(char *buf
, size_t bufsz
, u_char
*data
,
460 if (!data
|| datalen
< 1)
463 u_char len
= data
[0];
464 if (len
> 128 || len
> datalen
- 1)
467 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
470 /* dump notify packet */
471 void bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
474 const char *subcode_str
;
475 const char *code_str
;
476 const char *msg_str
= NULL
;
479 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)
480 || bgp_flag_check(peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
)) {
481 code_str
= bgp_notify_code_str(bgp_notify
->code
);
482 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
,
483 bgp_notify
->subcode
);
485 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
486 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
487 || bgp_notify
->subcode
488 == BGP_NOTIFY_CEASE_ADMIN_RESET
)) {
489 msg_str
= bgp_notify_admin_message(
490 msg_buf
, sizeof(msg_buf
), bgp_notify
->raw_data
,
496 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
497 strcmp(direct
, "received") == 0
500 peer
->host
, bgp_notify
->code
,
501 bgp_notify
->subcode
, code_str
, subcode_str
,
504 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
506 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
507 strcmp(direct
, "received") == 0
510 peer
->host
, bgp_notify
->code
,
511 bgp_notify
->subcode
, code_str
, subcode_str
,
512 bgp_notify
->length
, msg_str
);
517 static void bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
520 bgp
= bgp_get_default();
521 update_group_walk(bgp
, update_group_clear_update_dbg
, NULL
);
525 /* Debug option setting interface. */
526 unsigned long bgp_debug_option
= 0;
528 int debug(unsigned int option
)
530 return bgp_debug_option
& option
;
533 DEFUN (debug_bgp_as4
,
540 if (vty
->node
== CONFIG_NODE
)
543 TERM_DEBUG_ON(as4
, AS4
);
544 vty_out(vty
, "BGP as4 debugging is on%s", VTY_NEWLINE
);
549 DEFUN (no_debug_bgp_as4
,
550 no_debug_bgp_as4_cmd
,
557 if (vty
->node
== CONFIG_NODE
)
560 TERM_DEBUG_OFF(as4
, AS4
);
561 vty_out(vty
, "BGP as4 debugging is off%s", VTY_NEWLINE
);
566 DEFUN (debug_bgp_as4_segment
,
567 debug_bgp_as4_segment_cmd
,
568 "debug bgp as4 segment",
572 "BGP AS4 aspath segment handling\n")
574 if (vty
->node
== CONFIG_NODE
)
575 DEBUG_ON(as4
, AS4_SEGMENT
);
577 TERM_DEBUG_ON(as4
, AS4_SEGMENT
);
578 vty_out(vty
, "BGP as4 segment debugging is on%s", VTY_NEWLINE
);
583 DEFUN (no_debug_bgp_as4_segment
,
584 no_debug_bgp_as4_segment_cmd
,
585 "no debug bgp as4 segment",
590 "BGP AS4 aspath segment handling\n")
592 if (vty
->node
== CONFIG_NODE
)
593 DEBUG_OFF(as4
, AS4_SEGMENT
);
595 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
596 vty_out(vty
, "BGP as4 segment debugging is off%s", VTY_NEWLINE
);
601 /* debug bgp neighbor_events */
602 DEFUN (debug_bgp_neighbor_events
,
603 debug_bgp_neighbor_events_cmd
,
604 "debug bgp neighbor-events",
607 "BGP Neighbor Events\n")
609 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
611 if (vty
->node
== CONFIG_NODE
)
612 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
614 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
615 vty_out(vty
, "BGP neighbor-events debugging is on%s",
621 DEFUN (debug_bgp_neighbor_events_peer
,
622 debug_bgp_neighbor_events_peer_cmd
,
623 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
626 "BGP Neighbor Events\n"
627 "BGP neighbor IP address to debug\n"
628 "BGP IPv6 neighbor to debug\n"
629 "BGP neighbor on interface to debug\n")
632 const char *host
= argv
[idx_peer
]->arg
;
634 if (!bgp_debug_neighbor_events_peers
)
635 bgp_debug_neighbor_events_peers
= list_new();
637 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
,
640 "BGP neighbor-events debugging is already enabled for %s%s",
645 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
647 if (vty
->node
== CONFIG_NODE
)
648 DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
650 TERM_DEBUG_ON(neighbor_events
, NEIGHBOR_EVENTS
);
651 vty_out(vty
, "BGP neighbor-events debugging is on for %s%s",
657 DEFUN (no_debug_bgp_neighbor_events
,
658 no_debug_bgp_neighbor_events_cmd
,
659 "no debug bgp neighbor-events",
665 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
667 if (vty
->node
== CONFIG_NODE
)
668 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
670 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
671 vty_out(vty
, "BGP neighbor-events debugging is off%s",
677 DEFUN (no_debug_bgp_neighbor_events_peer
,
678 no_debug_bgp_neighbor_events_peer_cmd
,
679 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
684 "BGP neighbor IP address to debug\n"
685 "BGP IPv6 neighbor to debug\n"
686 "BGP neighbor on interface to debug\n")
690 const char *host
= argv
[idx_peer
]->arg
;
692 if (bgp_debug_neighbor_events_peers
693 && !list_isempty(bgp_debug_neighbor_events_peers
)) {
694 found_peer
= bgp_debug_list_remove_entry(
695 bgp_debug_neighbor_events_peers
, host
, NULL
);
697 if (list_isempty(bgp_debug_neighbor_events_peers
)) {
698 if (vty
->node
== CONFIG_NODE
)
699 DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
701 TERM_DEBUG_OFF(neighbor_events
,
707 vty_out(vty
, "BGP neighbor-events debugging is off for %s%s",
711 "BGP neighbor-events debugging was not enabled for %s%s",
718 DEFUN (debug_bgp_nht
,
723 "BGP nexthop tracking events\n")
725 if (vty
->node
== CONFIG_NODE
)
728 TERM_DEBUG_ON(nht
, NHT
);
729 vty_out(vty
, "BGP nexthop tracking debugging is on%s",
735 DEFUN (no_debug_bgp_nht
,
736 no_debug_bgp_nht_cmd
,
741 "BGP nexthop tracking events\n")
743 if (vty
->node
== CONFIG_NODE
)
746 TERM_DEBUG_OFF(nht
, NHT
);
747 vty_out(vty
, "BGP nexthop tracking debugging is off%s",
753 /* debug bgp keepalives */
754 DEFUN (debug_bgp_keepalive
,
755 debug_bgp_keepalive_cmd
,
756 "debug bgp keepalives",
761 bgp_debug_list_free(bgp_debug_keepalive_peers
);
763 if (vty
->node
== CONFIG_NODE
)
764 DEBUG_ON(keepalive
, KEEPALIVE
);
766 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
767 vty_out(vty
, "BGP keepalives debugging is on%s", VTY_NEWLINE
);
772 DEFUN (debug_bgp_keepalive_peer
,
773 debug_bgp_keepalive_peer_cmd
,
774 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
777 "BGP Neighbor Events\n"
778 "BGP neighbor IP address to debug\n"
779 "BGP IPv6 neighbor to debug\n"
780 "BGP neighbor on interface to debug\n")
783 const char *host
= argv
[idx_peer
]->arg
;
785 if (!bgp_debug_keepalive_peers
)
786 bgp_debug_keepalive_peers
= list_new();
788 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
)) {
790 "BGP keepalive debugging is already enabled for %s%s",
795 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
797 if (vty
->node
== CONFIG_NODE
)
798 DEBUG_ON(keepalive
, KEEPALIVE
);
800 TERM_DEBUG_ON(keepalive
, KEEPALIVE
);
801 vty_out(vty
, "BGP keepalives debugging is on for %s%s", host
,
807 DEFUN (no_debug_bgp_keepalive
,
808 no_debug_bgp_keepalive_cmd
,
809 "no debug bgp keepalives",
815 bgp_debug_list_free(bgp_debug_keepalive_peers
);
817 if (vty
->node
== CONFIG_NODE
)
818 DEBUG_OFF(keepalive
, KEEPALIVE
);
820 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
821 vty_out(vty
, "BGP keepalives debugging is off%s", VTY_NEWLINE
);
826 DEFUN (no_debug_bgp_keepalive_peer
,
827 no_debug_bgp_keepalive_peer_cmd
,
828 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
833 "BGP neighbor IP address to debug\n"
834 "BGP IPv6 neighbor to debug\n"
835 "BGP neighbor on interface to debug\n")
839 const char *host
= argv
[idx_peer
]->arg
;
841 if (bgp_debug_keepalive_peers
842 && !list_isempty(bgp_debug_keepalive_peers
)) {
843 found_peer
= bgp_debug_list_remove_entry(
844 bgp_debug_keepalive_peers
, host
, NULL
);
846 if (list_isempty(bgp_debug_keepalive_peers
)) {
847 if (vty
->node
== CONFIG_NODE
)
848 DEBUG_OFF(keepalive
, KEEPALIVE
);
850 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
855 vty_out(vty
, "BGP keepalives debugging is off for %s%s", host
,
859 "BGP keepalives debugging was not enabled for %s%s",
865 /* debug bgp bestpath */
866 DEFUN (debug_bgp_bestpath_prefix
,
867 debug_bgp_bestpath_prefix_cmd
,
868 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
875 int idx_ipv4_ipv6_prefixlen
= 3;
876 struct prefix
*argv_p
;
879 argv_p
= prefix_new();
880 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
883 vty_out(vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
888 if (!bgp_debug_bestpath_prefixes
)
889 bgp_debug_bestpath_prefixes
= list_new();
891 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
,
894 "BGP bestptah debugging is already enabled for %s%s",
895 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
899 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
901 if (vty
->node
== CONFIG_NODE
) {
902 DEBUG_ON(bestpath
, BESTPATH
);
904 TERM_DEBUG_ON(bestpath
, BESTPATH
);
905 vty_out(vty
, "BGP bestpath debugging is on for %s%s",
906 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
912 DEFUN (no_debug_bgp_bestpath_prefix
,
913 no_debug_bgp_bestpath_prefix_cmd
,
914 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
922 int idx_ipv4_ipv6_prefixlen
= 4;
923 struct prefix
*argv_p
;
924 int found_prefix
= 0;
927 argv_p
= prefix_new();
928 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
931 vty_out(vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
935 if (bgp_debug_bestpath_prefixes
936 && !list_isempty(bgp_debug_bestpath_prefixes
)) {
937 found_prefix
= bgp_debug_list_remove_entry(
938 bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
940 if (list_isempty(bgp_debug_bestpath_prefixes
)) {
941 if (vty
->node
== CONFIG_NODE
) {
942 DEBUG_OFF(bestpath
, BESTPATH
);
944 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
946 "BGP bestpath debugging (per prefix) is off%s",
953 vty_out(vty
, "BGP bestpath debugging is off for %s%s",
954 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
956 vty_out(vty
, "BGP bestpath debugging was not enabled for %s%s",
957 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
962 DEFUN (no_debug_bgp_bestpath
,
963 no_debug_bgp_bestpath_cmd
,
964 "no debug bgp bestpath",
970 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
972 if (vty
->node
== CONFIG_NODE
)
973 DEBUG_OFF(bestpath
, BESTPATH
);
975 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
976 vty_out(vty
, "BGP bestpath debugging is off%s", VTY_NEWLINE
);
981 /* debug bgp updates */
982 DEFUN (debug_bgp_update
,
983 debug_bgp_update_cmd
,
989 bgp_debug_list_free(bgp_debug_update_in_peers
);
990 bgp_debug_list_free(bgp_debug_update_out_peers
);
991 bgp_debug_list_free(bgp_debug_update_prefixes
);
993 if (vty
->node
== CONFIG_NODE
) {
994 DEBUG_ON(update
, UPDATE_IN
);
995 DEBUG_ON(update
, UPDATE_OUT
);
997 TERM_DEBUG_ON(update
, UPDATE_IN
);
998 TERM_DEBUG_ON(update
, UPDATE_OUT
);
999 vty_out(vty
, "BGP updates debugging is on%s", VTY_NEWLINE
);
1004 DEFUN (debug_bgp_update_direct
,
1005 debug_bgp_update_direct_cmd
,
1006 "debug bgp updates <in|out>",
1011 "Outbound updates\n")
1015 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1016 bgp_debug_list_free(bgp_debug_update_in_peers
);
1018 bgp_debug_list_free(bgp_debug_update_out_peers
);
1020 if (vty
->node
== CONFIG_NODE
) {
1021 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1022 DEBUG_ON(update
, UPDATE_IN
);
1024 DEBUG_ON(update
, UPDATE_OUT
);
1026 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1027 TERM_DEBUG_ON(update
, UPDATE_IN
);
1028 vty_out(vty
, "BGP updates debugging is on (inbound)%s",
1031 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1032 vty_out(vty
, "BGP updates debugging is on (outbound)%s",
1039 DEFUN (debug_bgp_update_direct_peer
,
1040 debug_bgp_update_direct_peer_cmd
,
1041 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1046 "Outbound updates\n"
1047 "BGP neighbor IP address to debug\n"
1048 "BGP IPv6 neighbor to debug\n"
1049 "BGP neighbor on interface to debug\n")
1053 const char *host
= argv
[idx_peer
]->arg
;
1056 if (!bgp_debug_update_in_peers
)
1057 bgp_debug_update_in_peers
= list_new();
1059 if (!bgp_debug_update_out_peers
)
1060 bgp_debug_update_out_peers
= list_new();
1062 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
1068 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
,
1071 "BGP inbound update debugging is already enabled for %s%s",
1078 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
,
1081 "BGP outbound update debugging is already enabled for %s%s",
1088 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1091 struct peer_af
*paf
;
1094 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
,
1096 peer
= bgp_find_peer(vty
, host
);
1099 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1101 paf
= peer
->peer_af_array
[afidx
];
1103 if (PAF_SUBGRP(paf
)) {
1113 if (vty
->node
== CONFIG_NODE
) {
1115 DEBUG_ON(update
, UPDATE_IN
);
1117 DEBUG_ON(update
, UPDATE_OUT
);
1120 TERM_DEBUG_ON(update
, UPDATE_IN
);
1122 "BGP updates debugging is on (inbound) for %s%s",
1123 argv
[idx_peer
]->arg
, VTY_NEWLINE
);
1125 TERM_DEBUG_ON(update
, UPDATE_OUT
);
1127 "BGP updates debugging is on (outbound) for %s%s",
1128 argv
[idx_peer
]->arg
, VTY_NEWLINE
);
1134 DEFUN (no_debug_bgp_update_direct
,
1135 no_debug_bgp_update_direct_cmd
,
1136 "no debug bgp updates <in|out>",
1142 "Outbound updates\n")
1145 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0) {
1146 bgp_debug_list_free(bgp_debug_update_in_peers
);
1148 if (vty
->node
== CONFIG_NODE
) {
1149 DEBUG_OFF(update
, UPDATE_IN
);
1151 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1152 vty_out(vty
, "BGP updates debugging is off (inbound)%s",
1156 bgp_debug_list_free(bgp_debug_update_out_peers
);
1158 if (vty
->node
== CONFIG_NODE
) {
1159 DEBUG_OFF(update
, UPDATE_OUT
);
1161 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1163 "BGP updates debugging is off (outbound)%s",
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>",
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")
1188 const char *host
= argv
[idx_peer
]->arg
;
1190 if (strncmp("i", argv
[idx_in_out
]->arg
, 1) == 0)
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
);
1200 if (list_isempty(bgp_debug_update_in_peers
)) {
1201 if (vty
->node
== CONFIG_NODE
)
1202 DEBUG_OFF(update
, UPDATE_IN
);
1204 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1206 "BGP updates debugging (inbound) is off%s",
1212 if (!inbound
&& bgp_debug_update_out_peers
1213 && !list_isempty(bgp_debug_update_out_peers
)) {
1214 found_peer
= bgp_debug_list_remove_entry(
1215 bgp_debug_update_out_peers
, host
, NULL
);
1217 if (list_isempty(bgp_debug_update_out_peers
)) {
1218 if (vty
->node
== CONFIG_NODE
)
1219 DEBUG_OFF(update
, UPDATE_OUT
);
1221 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1223 "BGP updates debugging (outbound) is off%s",
1229 struct peer_af
*paf
;
1231 peer
= bgp_find_peer(vty
, host
);
1234 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
;
1236 paf
= peer
->peer_af_array
[afidx
];
1238 if (PAF_SUBGRP(paf
)) {
1239 UPDGRP_PEER_DBG_DIS(
1251 "BGP updates debugging (inbound) is off for %s%s",
1255 "BGP updates debugging (outbound) is off for %s%s",
1259 "BGP updates debugging (inbound) was not enabled for %s%s",
1263 "BGP updates debugging (outbound) was not enabled for %s%s",
1269 DEFUN (debug_bgp_update_prefix
,
1270 debug_bgp_update_prefix_cmd
,
1271 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1275 "Specify a prefix to debug\n"
1279 int idx_ipv4_ipv6_prefixlen
= 4;
1280 struct prefix
*argv_p
;
1283 argv_p
= prefix_new();
1284 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1286 prefix_free(argv_p
);
1287 vty_out(vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1292 if (!bgp_debug_update_prefixes
)
1293 bgp_debug_update_prefixes
= list_new();
1295 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
)) {
1297 "BGP updates debugging is already enabled for %s%s",
1298 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1302 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1304 if (vty
->node
== CONFIG_NODE
) {
1305 DEBUG_ON(update
, UPDATE_PREFIX
);
1307 TERM_DEBUG_ON(update
, UPDATE_PREFIX
);
1308 vty_out(vty
, "BGP updates debugging is on for %s%s",
1309 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1315 DEFUN (no_debug_bgp_update_prefix
,
1316 no_debug_bgp_update_prefix_cmd
,
1317 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1322 "Specify a prefix to debug\n"
1326 int idx_ipv4_ipv6_prefixlen
= 5;
1327 struct prefix
*argv_p
;
1328 int found_prefix
= 0;
1331 argv_p
= prefix_new();
1332 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1334 prefix_free(argv_p
);
1335 vty_out(vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1339 if (bgp_debug_update_prefixes
1340 && !list_isempty(bgp_debug_update_prefixes
)) {
1341 found_prefix
= bgp_debug_list_remove_entry(
1342 bgp_debug_update_prefixes
, NULL
, argv_p
);
1344 if (list_isempty(bgp_debug_update_prefixes
)) {
1345 if (vty
->node
== CONFIG_NODE
) {
1346 DEBUG_OFF(update
, UPDATE_PREFIX
);
1348 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1350 "BGP updates debugging (per prefix) is off%s",
1357 vty_out(vty
, "BGP updates debugging is off for %s%s",
1358 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1360 vty_out(vty
, "BGP updates debugging was not enabled for %s%s",
1361 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1366 DEFUN (no_debug_bgp_update
,
1367 no_debug_bgp_update_cmd
,
1368 "no debug bgp updates",
1374 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1375 bgp_debug_list_free(bgp_debug_update_in_peers
);
1376 bgp_debug_list_free(bgp_debug_update_out_peers
);
1377 bgp_debug_list_free(bgp_debug_update_prefixes
);
1379 bgp_debug_clear_updgrp_update_dbg(bgp
);
1381 if (vty
->node
== CONFIG_NODE
) {
1382 DEBUG_OFF(update
, UPDATE_IN
);
1383 DEBUG_OFF(update
, UPDATE_OUT
);
1384 DEBUG_OFF(update
, UPDATE_PREFIX
);
1386 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1387 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1388 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1389 vty_out(vty
, "BGP updates debugging is off%s", VTY_NEWLINE
);
1394 /* debug bgp zebra */
1395 DEFUN (debug_bgp_zebra
,
1396 debug_bgp_zebra_cmd
,
1400 "BGP Zebra messages\n")
1402 if (vty
->node
== CONFIG_NODE
)
1403 DEBUG_ON(zebra
, ZEBRA
);
1405 TERM_DEBUG_ON(zebra
, ZEBRA
);
1406 vty_out(vty
, "BGP zebra debugging is on%s", VTY_NEWLINE
);
1411 DEFUN (debug_bgp_zebra_prefix
,
1412 debug_bgp_zebra_prefix_cmd
,
1413 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1416 "BGP Zebra messages\n"
1417 "Specify a prefix to debug\n"
1421 int idx_ipv4_ipv6_prefixlen
= 4;
1422 struct prefix
*argv_p
;
1425 argv_p
= prefix_new();
1426 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1428 prefix_free(argv_p
);
1429 vty_out(vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1433 if (!bgp_debug_zebra_prefixes
)
1434 bgp_debug_zebra_prefixes
= list_new();
1436 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
)) {
1437 vty_out(vty
, "BGP zebra debugging is already enabled for %s%s",
1438 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1442 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1444 if (vty
->node
== CONFIG_NODE
)
1445 DEBUG_ON(zebra
, ZEBRA
);
1447 TERM_DEBUG_ON(zebra
, ZEBRA
);
1448 vty_out(vty
, "BGP zebra debugging is on for %s%s",
1449 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1455 DEFUN (no_debug_bgp_zebra
,
1456 no_debug_bgp_zebra_cmd
,
1457 "no debug bgp zebra",
1461 "BGP Zebra messages\n")
1463 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1465 if (vty
->node
== CONFIG_NODE
)
1466 DEBUG_OFF(zebra
, ZEBRA
);
1468 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1469 vty_out(vty
, "BGP zebra debugging is off%s", VTY_NEWLINE
);
1474 DEFUN (no_debug_bgp_zebra_prefix
,
1475 no_debug_bgp_zebra_prefix_cmd
,
1476 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1480 "BGP Zebra messages\n"
1481 "Specify a prefix to debug\n"
1485 int idx_ipv4_ipv6_prefixlen
= 5;
1486 struct prefix
*argv_p
;
1487 int found_prefix
= 0;
1490 argv_p
= prefix_new();
1491 ret
= str2prefix(argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1493 prefix_free(argv_p
);
1494 vty_out(vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1498 if (bgp_debug_zebra_prefixes
1499 && !list_isempty(bgp_debug_zebra_prefixes
)) {
1500 found_prefix
= bgp_debug_list_remove_entry(
1501 bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1503 if (list_isempty(bgp_debug_zebra_prefixes
)) {
1504 if (vty
->node
== CONFIG_NODE
)
1505 DEBUG_OFF(zebra
, ZEBRA
);
1507 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1508 vty_out(vty
, "BGP zebra debugging is off%s",
1515 vty_out(vty
, "BGP zebra debugging is off for %s%s",
1516 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1518 vty_out(vty
, "BGP zebra debugging was not enabled for %s%s",
1519 argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1524 DEFUN (debug_bgp_allow_martians
,
1525 debug_bgp_allow_martians_cmd
,
1526 "debug bgp allow-martians",
1529 "BGP allow martian next hops\n")
1531 if (vty
->node
== CONFIG_NODE
)
1532 DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1534 TERM_DEBUG_ON(allow_martians
, ALLOW_MARTIANS
);
1535 vty_out(vty
, "BGP allow_martian next hop debugging is on%s",
1541 DEFUN (no_debug_bgp_allow_martians
,
1542 no_debug_bgp_allow_martians_cmd
,
1543 "no debug bgp allow-martians",
1547 "BGP allow martian next hops\n")
1549 if (vty
->node
== CONFIG_NODE
)
1550 DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1552 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1553 vty_out(vty
, "BGP allow martian next hop debugging is off%s",
1560 /* debug bgp update-groups */
1561 DEFUN (debug_bgp_update_groups
,
1562 debug_bgp_update_groups_cmd
,
1563 "debug bgp update-groups",
1566 "BGP update-groups\n")
1568 if (vty
->node
== CONFIG_NODE
)
1569 DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1571 TERM_DEBUG_ON(update_groups
, UPDATE_GROUPS
);
1572 vty_out(vty
, "BGP update-groups debugging is on%s",
1578 DEFUN (no_debug_bgp_update_groups
,
1579 no_debug_bgp_update_groups_cmd
,
1580 "no debug bgp update-groups",
1584 "BGP update-groups\n")
1586 if (vty
->node
== CONFIG_NODE
)
1587 DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1589 TERM_DEBUG_OFF(update_groups
, UPDATE_GROUPS
);
1590 vty_out(vty
, "BGP update-groups debugging is off%s",
1596 DEFUN (no_debug_bgp
,
1603 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1604 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
1605 bgp_debug_list_free(bgp_debug_keepalive_peers
);
1606 bgp_debug_list_free(bgp_debug_update_in_peers
);
1607 bgp_debug_list_free(bgp_debug_update_out_peers
);
1608 bgp_debug_list_free(bgp_debug_update_prefixes
);
1609 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1610 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1612 bgp_debug_clear_updgrp_update_dbg(bgp
);
1614 TERM_DEBUG_OFF(keepalive
, KEEPALIVE
);
1615 TERM_DEBUG_OFF(update
, UPDATE_IN
);
1616 TERM_DEBUG_OFF(update
, UPDATE_OUT
);
1617 TERM_DEBUG_OFF(update
, UPDATE_PREFIX
);
1618 TERM_DEBUG_OFF(bestpath
, BESTPATH
);
1619 TERM_DEBUG_OFF(as4
, AS4
);
1620 TERM_DEBUG_OFF(as4
, AS4_SEGMENT
);
1621 TERM_DEBUG_OFF(neighbor_events
, NEIGHBOR_EVENTS
);
1622 TERM_DEBUG_OFF(zebra
, ZEBRA
);
1623 TERM_DEBUG_OFF(allow_martians
, ALLOW_MARTIANS
);
1624 vty_out(vty
, "All possible debugging has been turned off%s",
1630 DEFUN (show_debugging_bgp
,
1631 show_debugging_bgp_cmd
,
1632 "show debugging bgp",
1637 vty_out(vty
, "BGP debugging status:%s", VTY_NEWLINE
);
1639 if (BGP_DEBUG(as4
, AS4
))
1640 vty_out(vty
, " BGP as4 debugging is on%s", VTY_NEWLINE
);
1642 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
1643 vty_out(vty
, " BGP as4 aspath segment debugging is on%s",
1646 if (BGP_DEBUG(bestpath
, BESTPATH
))
1647 bgp_debug_list_print(vty
, " BGP bestpath debugging is on",
1648 bgp_debug_bestpath_prefixes
);
1650 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
1651 bgp_debug_list_print(vty
, " BGP keepalives debugging is on",
1652 bgp_debug_keepalive_peers
);
1654 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
1655 bgp_debug_list_print(vty
,
1656 " BGP neighbor-events debugging is on",
1657 bgp_debug_neighbor_events_peers
);
1659 if (BGP_DEBUG(nht
, NHT
))
1660 vty_out(vty
, " BGP next-hop tracking debugging is on%s",
1663 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1664 vty_out(vty
, " BGP update-groups debugging is on%s",
1667 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
1668 bgp_debug_list_print(vty
, " BGP updates debugging is on",
1669 bgp_debug_update_prefixes
);
1671 if (BGP_DEBUG(update
, UPDATE_IN
))
1672 bgp_debug_list_print(vty
,
1673 " BGP updates debugging is on (inbound)",
1674 bgp_debug_update_in_peers
);
1676 if (BGP_DEBUG(update
, UPDATE_OUT
))
1677 bgp_debug_list_print(vty
,
1678 " BGP updates debugging is on (outbound)",
1679 bgp_debug_update_out_peers
);
1681 if (BGP_DEBUG(zebra
, ZEBRA
))
1682 bgp_debug_list_print(vty
, " BGP zebra debugging is on",
1683 bgp_debug_zebra_prefixes
);
1685 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
1686 vty_out(vty
, " BGP allow martian next hop debugging is on%s",
1688 vty_out(vty
, "%s", VTY_NEWLINE
);
1692 /* return count of number of debug flags set */
1693 int bgp_debug_count(void)
1696 if (BGP_DEBUG(as4
, AS4
))
1699 if (BGP_DEBUG(as4
, AS4_SEGMENT
))
1702 if (BGP_DEBUG(bestpath
, BESTPATH
))
1705 if (BGP_DEBUG(keepalive
, KEEPALIVE
))
1708 if (BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
))
1711 if (BGP_DEBUG(nht
, NHT
))
1714 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1717 if (BGP_DEBUG(update
, UPDATE_PREFIX
))
1720 if (BGP_DEBUG(update
, UPDATE_IN
))
1723 if (BGP_DEBUG(update
, UPDATE_OUT
))
1726 if (BGP_DEBUG(zebra
, ZEBRA
))
1729 if (BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
))
1735 static int bgp_config_write_debug(struct vty
*vty
)
1739 if (CONF_BGP_DEBUG(as4
, AS4
)) {
1740 vty_out(vty
, "debug bgp as4%s", VTY_NEWLINE
);
1744 if (CONF_BGP_DEBUG(as4
, AS4_SEGMENT
)) {
1745 vty_out(vty
, "debug bgp as4 segment%s", VTY_NEWLINE
);
1749 if (CONF_BGP_DEBUG(bestpath
, BESTPATH
)) {
1750 write
+= bgp_debug_list_conf_print(vty
, "debug bgp bestpath",
1751 bgp_debug_bestpath_prefixes
);
1754 if (CONF_BGP_DEBUG(keepalive
, KEEPALIVE
)) {
1755 write
+= bgp_debug_list_conf_print(vty
, "debug bgp keepalives",
1756 bgp_debug_keepalive_peers
);
1759 if (CONF_BGP_DEBUG(neighbor_events
, NEIGHBOR_EVENTS
)) {
1760 write
+= bgp_debug_list_conf_print(
1761 vty
, "debug bgp neighbor-events",
1762 bgp_debug_neighbor_events_peers
);
1765 if (CONF_BGP_DEBUG(nht
, NHT
)) {
1766 vty_out(vty
, "debug bgp nht%s", VTY_NEWLINE
);
1770 if (CONF_BGP_DEBUG(update_groups
, UPDATE_GROUPS
)) {
1771 vty_out(vty
, "debug bgp update-groups%s", VTY_NEWLINE
);
1775 if (CONF_BGP_DEBUG(update
, UPDATE_PREFIX
)) {
1776 write
+= bgp_debug_list_conf_print(vty
,
1777 "debug bgp updates prefix",
1778 bgp_debug_update_prefixes
);
1781 if (CONF_BGP_DEBUG(update
, UPDATE_IN
)) {
1782 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates in",
1783 bgp_debug_update_in_peers
);
1786 if (CONF_BGP_DEBUG(update
, UPDATE_OUT
)) {
1787 write
+= bgp_debug_list_conf_print(vty
, "debug bgp updates out",
1788 bgp_debug_update_out_peers
);
1791 if (CONF_BGP_DEBUG(zebra
, ZEBRA
)) {
1792 if (!bgp_debug_zebra_prefixes
1793 || list_isempty(bgp_debug_zebra_prefixes
)) {
1794 vty_out(vty
, "debug bgp zebra%s", VTY_NEWLINE
);
1797 write
+= bgp_debug_list_conf_print(
1798 vty
, "debug bgp zebra prefix",
1799 bgp_debug_zebra_prefixes
);
1803 if (CONF_BGP_DEBUG(allow_martians
, ALLOW_MARTIANS
)) {
1804 vty_out(vty
, "debug bgp allow-martians%s", VTY_NEWLINE
);
1811 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
1813 void bgp_debug_init(void)
1815 install_node(&debug_node
, bgp_config_write_debug
);
1817 install_element(ENABLE_NODE
, &show_debugging_bgp_cmd
);
1819 install_element(ENABLE_NODE
, &debug_bgp_as4_cmd
);
1820 install_element(CONFIG_NODE
, &debug_bgp_as4_cmd
);
1821 install_element(ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
1822 install_element(CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
1824 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
1825 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
1826 install_element(ENABLE_NODE
, &debug_bgp_nht_cmd
);
1827 install_element(CONFIG_NODE
, &debug_bgp_nht_cmd
);
1828 install_element(ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
1829 install_element(CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
1830 install_element(ENABLE_NODE
, &debug_bgp_update_cmd
);
1831 install_element(CONFIG_NODE
, &debug_bgp_update_cmd
);
1832 install_element(ENABLE_NODE
, &debug_bgp_zebra_cmd
);
1833 install_element(CONFIG_NODE
, &debug_bgp_zebra_cmd
);
1834 install_element(ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
1835 install_element(CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
1836 install_element(ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
1837 install_element(CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
1838 install_element(ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1839 install_element(CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1841 /* debug bgp updates (in|out) */
1842 install_element(ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
1843 install_element(CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
1844 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
1845 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
1847 /* debug bgp updates (in|out) A.B.C.D */
1848 install_element(ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
1849 install_element(CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
1850 install_element(ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1851 install_element(CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1853 /* debug bgp updates prefix A.B.C.D/M */
1854 install_element(ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
1855 install_element(CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
1856 install_element(ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
1857 install_element(CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
1859 /* debug bgp zebra prefix A.B.C.D/M */
1860 install_element(ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
1861 install_element(CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
1862 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1863 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1865 install_element(ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
1866 install_element(CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
1867 install_element(ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
1868 install_element(CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
1870 /* debug bgp neighbor-events A.B.C.D */
1871 install_element(ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1872 install_element(CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1873 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1874 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1876 /* debug bgp keepalive A.B.C.D */
1877 install_element(ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
1878 install_element(CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
1879 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1880 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1882 install_element(ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1883 install_element(CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1884 install_element(ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
1885 install_element(CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
1886 install_element(ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
1887 install_element(CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
1888 install_element(ENABLE_NODE
, &no_debug_bgp_update_cmd
);
1889 install_element(CONFIG_NODE
, &no_debug_bgp_update_cmd
);
1890 install_element(ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
1891 install_element(CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
1892 install_element(ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
1893 install_element(CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
1894 install_element(ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
1895 install_element(CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
1896 install_element(ENABLE_NODE
, &no_debug_bgp_cmd
);
1897 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
1898 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
1899 install_element(ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1900 install_element(CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1903 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
1904 * for BGP_DEBUG_TYPE
1906 static int bgp_debug_per_prefix(struct prefix
*p
,
1907 unsigned long term_bgp_debug_type
,
1908 unsigned int BGP_DEBUG_TYPE
,
1909 struct list
*per_prefix_list
)
1911 struct bgp_debug_filter
*filter
;
1912 struct listnode
*node
, *nnode
;
1914 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
1915 /* We are debugging all prefixes so return true */
1916 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
1923 for (ALL_LIST_ELEMENTS(per_prefix_list
, node
, nnode
,
1925 if (filter
->p
->prefixlen
== p
->prefixlen
1926 && prefix_match(filter
->p
, p
))
1936 /* Return true if this peer is on the per_peer_list of peers to debug
1937 * for BGP_DEBUG_TYPE
1939 static int bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
1940 unsigned int BGP_DEBUG_TYPE
,
1941 struct list
*per_peer_list
)
1943 struct bgp_debug_filter
*filter
;
1944 struct listnode
*node
, *nnode
;
1946 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
) {
1947 /* We are debugging all peers so return true */
1948 if (!per_peer_list
|| list_isempty(per_peer_list
))
1955 for (ALL_LIST_ELEMENTS(per_peer_list
, node
, nnode
,
1957 if (strcmp(filter
->host
, host
) == 0)
1967 int bgp_debug_neighbor_events(struct peer
*peer
)
1974 return bgp_debug_per_peer(host
, term_bgp_debug_neighbor_events
,
1975 BGP_DEBUG_NEIGHBOR_EVENTS
,
1976 bgp_debug_neighbor_events_peers
);
1979 int bgp_debug_keepalive(struct peer
*peer
)
1986 return bgp_debug_per_peer(host
, term_bgp_debug_keepalive
,
1987 BGP_DEBUG_KEEPALIVE
,
1988 bgp_debug_keepalive_peers
);
1991 int bgp_debug_update(struct peer
*peer
, struct prefix
*p
,
1992 struct update_group
*updgrp
, unsigned int inbound
)
2000 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2001 BGP_DEBUG_UPDATE_IN
,
2002 bgp_debug_update_in_peers
))
2008 if (bgp_debug_per_peer(host
, term_bgp_debug_update
,
2009 BGP_DEBUG_UPDATE_OUT
,
2010 bgp_debug_update_out_peers
))
2013 /* Check if update debugging implicitly enabled for the group.
2015 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2020 if (BGP_DEBUG(update
, UPDATE_PREFIX
)) {
2021 if (bgp_debug_per_prefix(p
, term_bgp_debug_update
,
2022 BGP_DEBUG_UPDATE_PREFIX
,
2023 bgp_debug_update_prefixes
))
2030 int bgp_debug_bestpath(struct prefix
*p
)
2032 if (BGP_DEBUG(bestpath
, BESTPATH
)) {
2033 if (bgp_debug_per_prefix(p
, term_bgp_debug_bestpath
,
2035 bgp_debug_bestpath_prefixes
))
2042 int bgp_debug_zebra(struct prefix
*p
)
2044 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2045 if (bgp_debug_per_prefix(p
, term_bgp_debug_zebra
,
2047 bgp_debug_zebra_prefixes
))
2054 const char *bgp_debug_rdpfxpath2str(struct prefix_rd
*prd
,
2055 union prefixconstptr pu
, int addpath_valid
,
2056 u_int32_t addpath_id
, char *str
, int size
)
2058 char rd_buf
[RD_ADDRSTRLEN
];
2059 char pfx_buf
[PREFIX_STRLEN
];
2060 /* ' with addpath ID ' 17
2061 * max strlen of uint32 + 10
2062 * +/- (in case of idiocy) + 1
2063 * null terminator + 1
2064 * ============================ 29 */
2065 char pathid_buf
[30];
2067 if (size
< BGP_PRD_PATH_STRLEN
)
2070 /* Note: Path-id is created by default, but only included in update
2072 pathid_buf
[0] = '\0';
2074 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u",
2078 snprintf(str
, size
, "RD %s %s%s",
2079 prefix_rd2str(prd
, rd_buf
, sizeof(rd_buf
)),
2080 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), pathid_buf
);
2082 snprintf(str
, size
, "%s%s",
2083 prefix2str(pu
, pfx_buf
, sizeof(pfx_buf
)), pathid_buf
);