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"
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
[] =
81 { Connect
, "Connect" },
83 { OpenSent
, "OpenSent" },
84 { OpenConfirm
, "OpenConfirm" },
85 { Established
, "Established" },
86 { Clearing
, "Clearing" },
87 { Deleted
, "Deleted" },
91 /* BGP message type string. */
92 const char *bgp_type_str
[] =
103 /* message for BGP-4 Notify */
104 static const struct message bgp_notify_msg
[] =
106 { BGP_NOTIFY_HEADER_ERR
, "Message Header Error"},
107 { BGP_NOTIFY_OPEN_ERR
, "OPEN Message Error"},
108 { BGP_NOTIFY_UPDATE_ERR
, "UPDATE Message Error"},
109 { BGP_NOTIFY_HOLD_ERR
, "Hold Timer Expired"},
110 { BGP_NOTIFY_FSM_ERR
, "Neighbor Events Error"},
111 { BGP_NOTIFY_CEASE
, "Cease"},
112 { BGP_NOTIFY_CAPABILITY_ERR
, "CAPABILITY Message Error"},
116 static const struct message bgp_notify_head_msg
[] =
118 { BGP_NOTIFY_HEADER_NOT_SYNC
, "/Connection Not Synchronized"},
119 { BGP_NOTIFY_HEADER_BAD_MESLEN
, "/Bad Message Length"},
120 { BGP_NOTIFY_HEADER_BAD_MESTYPE
, "/Bad Message Type"},
124 static const struct message bgp_notify_open_msg
[] =
126 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
127 { BGP_NOTIFY_OPEN_UNSUP_VERSION
, "/Unsupported Version Number" },
128 { BGP_NOTIFY_OPEN_BAD_PEER_AS
, "/Bad Peer AS"},
129 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT
, "/Bad BGP Identifier"},
130 { BGP_NOTIFY_OPEN_UNSUP_PARAM
, "/Unsupported Optional Parameter"},
131 { BGP_NOTIFY_OPEN_AUTH_FAILURE
, "/Authentication Failure"},
132 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
, "/Unacceptable Hold Time"},
133 { BGP_NOTIFY_OPEN_UNSUP_CAPBL
, "/Unsupported Capability"},
137 static const struct message bgp_notify_update_msg
[] =
139 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
140 { BGP_NOTIFY_UPDATE_MAL_ATTR
, "/Malformed Attribute List"},
141 { BGP_NOTIFY_UPDATE_UNREC_ATTR
, "/Unrecognized Well-known Attribute"},
142 { BGP_NOTIFY_UPDATE_MISS_ATTR
, "/Missing Well-known Attribute"},
143 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR
, "/Attribute Flags Error"},
144 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR
, "/Attribute Length Error"},
145 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN
, "/Invalid ORIGIN Attribute"},
146 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP
, "/AS Routing Loop"},
147 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP
, "/Invalid NEXT_HOP Attribute"},
148 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
, "/Optional Attribute Error"},
149 { BGP_NOTIFY_UPDATE_INVAL_NETWORK
, "/Invalid Network Field"},
150 { BGP_NOTIFY_UPDATE_MAL_AS_PATH
, "/Malformed AS_PATH"},
154 static const struct message bgp_notify_cease_msg
[] =
156 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
157 { BGP_NOTIFY_CEASE_MAX_PREFIX
, "/Maximum Number of Prefixes Reached"},
158 { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
, "/Administratively Shutdown"},
159 { BGP_NOTIFY_CEASE_PEER_UNCONFIG
, "/Peer Unconfigured"},
160 { BGP_NOTIFY_CEASE_ADMIN_RESET
, "/Administratively Reset"},
161 { BGP_NOTIFY_CEASE_CONNECT_REJECT
, "/Connection Rejected"},
162 { BGP_NOTIFY_CEASE_CONFIG_CHANGE
, "/Other Configuration Change"},
163 { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
, "/Connection collision resolution"},
164 { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE
, "/Out of Resource"},
168 static const struct message bgp_notify_capability_msg
[] =
170 { BGP_NOTIFY_SUBCODE_UNSPECIFIC
, "/Unspecific"},
171 { BGP_NOTIFY_CAPABILITY_INVALID_ACTION
, "/Invalid Action Value" },
172 { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH
, "/Invalid Capability Length"},
173 { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE
, "/Malformed Capability Value"},
177 /* Origin strings. */
178 const char *bgp_origin_str
[] = {"i","e","?"};
179 const char *bgp_origin_long_str
[] = {"IGP","EGP","incomplete"};
182 /* Given a string return a pointer the corresponding peer structure */
184 bgp_find_peer (struct vty
*vty
, const char *peer_str
)
186 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
194 ret
= str2sockunion (peer_str
, &su
);
199 peer
= peer_lookup_by_conf_if (bgp
, peer_str
);
202 peer
= peer_lookup_by_hostname (bgp
, peer_str
);
207 return peer_lookup (bgp
, &su
);
211 bgp_debug_list_free(struct list
*list
)
213 struct bgp_debug_filter
*filter
;
214 struct listnode
*node
, *nnode
;
217 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
219 listnode_delete (list
, filter
);
222 prefix_free(filter
->p
);
225 XFREE (MTYPE_BGP_DEBUG_STR
, filter
->host
);
227 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
231 /* Print the desc along with a list of peers/prefixes this debug is
234 bgp_debug_list_print (struct vty
*vty
, const char *desc
, struct list
*list
)
236 struct bgp_debug_filter
*filter
;
237 struct listnode
*node
, *nnode
;
238 char buf
[INET6_ADDRSTRLEN
];
240 vty_out (vty
, "%s", desc
);
242 if (list
&& !list_isempty(list
))
244 vty_out (vty
, " for");
245 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
248 vty_out (vty
, " %s", filter
->host
);
251 vty_out (vty
, " %s/%d",
252 inet_ntop (filter
->p
->family
, &filter
->p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
253 filter
->p
->prefixlen
);
260 /* Print the command to enable the debug for each peer/prefix this debug is
264 bgp_debug_list_conf_print (struct vty
*vty
, const char *desc
, struct list
*list
)
266 struct bgp_debug_filter
*filter
;
267 struct listnode
*node
, *nnode
;
268 char buf
[INET6_ADDRSTRLEN
];
271 if (list
&& !list_isempty(list
))
273 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
277 vty_outln (vty
, "%s %s", desc
, filter
->host
);
284 vty_outln (vty
, "%s %s/%d", desc
,
285 inet_ntop (filter
->p
->family
, &filter
->p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
286 filter
->p
->prefixlen
);
294 vty_outln (vty
, "%s", desc
);
302 bgp_debug_list_add_entry(struct list
*list
, const char *host
, const struct prefix
*p
)
304 struct bgp_debug_filter
*filter
;
306 filter
= XCALLOC (MTYPE_BGP_DEBUG_FILTER
, sizeof (struct bgp_debug_filter
));
310 filter
->host
= XSTRDUP (MTYPE_BGP_DEBUG_STR
, host
);
316 filter
->p
= prefix_new();
317 prefix_copy (filter
->p
, p
);
320 listnode_add(list
, filter
);
324 bgp_debug_list_remove_entry(struct list
*list
, const char *host
, struct prefix
*p
)
326 struct bgp_debug_filter
*filter
;
327 struct listnode
*node
, *nnode
;
329 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
331 if (host
&& strcmp (filter
->host
, host
) == 0)
333 listnode_delete (list
, filter
);
334 XFREE (MTYPE_BGP_DEBUG_STR
, filter
->host
);
335 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
338 else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
340 listnode_delete (list
, filter
);
341 prefix_free (filter
->p
);
342 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
351 bgp_debug_list_has_entry(struct list
*list
, const char *host
, const struct prefix
*p
)
353 struct bgp_debug_filter
*filter
;
354 struct listnode
*node
, *nnode
;
356 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
360 if (strcmp (filter
->host
, host
) == 0)
367 if (filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
378 bgp_debug_peer_updout_enabled(char *host
)
380 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
, NULL
));
383 /* Dump attribute. */
385 bgp_dump_attr (struct attr
*attr
, char *buf
, size_t size
)
390 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
)))
391 snprintf (buf
, size
, "nexthop %s", inet_ntoa (attr
->nexthop
));
393 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN
)))
394 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", origin %s",
395 bgp_origin_str
[attr
->origin
]);
399 char addrbuf
[BUFSIZ
];
402 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
403 || attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
404 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", mp_nexthop %s",
405 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
408 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
409 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), "(%s)",
410 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_local
,
414 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
)))
415 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", localpref %u",
418 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
)))
419 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", metric %u",
422 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
)))
423 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", community %s",
424 community_str (attr
->community
));
426 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
)))
427 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", atomic-aggregate");
429 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
)))
430 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", aggregated by %u %s",
431 attr
->extra
->aggregator_as
,
432 inet_ntoa (attr
->extra
->aggregator_addr
));
434 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
)))
435 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", originator %s",
436 inet_ntoa (attr
->extra
->originator_id
));
438 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST
)))
442 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", clusterlist");
443 for (i
= 0; i
< attr
->extra
->cluster
->length
/ 4; i
++)
444 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), " %s",
445 inet_ntoa (attr
->extra
->cluster
->list
[i
]));
448 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH
)))
449 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", path %s",
450 aspath_print (attr
->aspath
));
452 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID
)))
454 if (attr
->extra
->label_index
!= BGP_INVALID_LABEL_INDEX
)
455 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", label-index %u",
456 attr
->extra
->label_index
);
459 if (strlen (buf
) > 1)
466 bgp_notify_code_str (char code
)
468 return lookup_msg (bgp_notify_msg
, code
, "Unrecognized Error Code");
472 bgp_notify_subcode_str (char code
, char subcode
)
477 case BGP_NOTIFY_HEADER_ERR
:
478 return lookup_msg (bgp_notify_head_msg
, subcode
,
479 "Unrecognized Error Subcode");
480 case BGP_NOTIFY_OPEN_ERR
:
481 return lookup_msg (bgp_notify_open_msg
, subcode
,
482 "Unrecognized Error Subcode");
483 case BGP_NOTIFY_UPDATE_ERR
:
484 return lookup_msg (bgp_notify_update_msg
, subcode
,
485 "Unrecognized Error Subcode");
486 case BGP_NOTIFY_HOLD_ERR
:
488 case BGP_NOTIFY_FSM_ERR
:
490 case BGP_NOTIFY_CEASE
:
491 return lookup_msg (bgp_notify_cease_msg
, subcode
,
492 "Unrecognized Error Subcode");
493 case BGP_NOTIFY_CAPABILITY_ERR
:
494 return lookup_msg (bgp_notify_capability_msg
, subcode
,
495 "Unrecognized Error Subcode");
500 /* extract notify admin reason if correctly present */
502 bgp_notify_admin_message(char *buf
, size_t bufsz
, u_char
*data
, size_t datalen
)
504 if (!data
|| datalen
< 1)
507 u_char len
= data
[0];
509 || len
> datalen
- 1)
512 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
515 /* dump notify packet */
517 bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
520 const char *subcode_str
;
521 const char *code_str
;
522 const char *msg_str
= NULL
;
525 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
) || bgp_flag_check (peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
))
527 code_str
= bgp_notify_code_str(bgp_notify
->code
);
528 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
, bgp_notify
->subcode
);
530 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
531 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
532 || bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_RESET
))
534 msg_str
= bgp_notify_admin_message(msg_buf
, sizeof(msg_buf
),
535 bgp_notify
->raw_data
, bgp_notify
->length
);
540 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
541 strcmp (direct
, "received") == 0 ? "received from" : "sent to",
542 peer
->host
, bgp_notify
->code
, bgp_notify
->subcode
,
543 code_str
, subcode_str
, msg_str
);
547 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
548 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
549 strcmp (direct
, "received") == 0 ? "received from" : "sent to",
550 peer
->host
, bgp_notify
->code
, bgp_notify
->subcode
,
551 code_str
, subcode_str
, bgp_notify
->length
, msg_str
);
557 bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
560 bgp
= bgp_get_default();
561 update_group_walk (bgp
, update_group_clear_update_dbg
, NULL
);
565 /* Debug option setting interface. */
566 unsigned long bgp_debug_option
= 0;
569 debug (unsigned int option
)
571 return bgp_debug_option
& option
;
574 DEFUN (debug_bgp_as4
,
581 if (vty
->node
== CONFIG_NODE
)
585 TERM_DEBUG_ON (as4
, AS4
);
586 vty_outln (vty
, "BGP as4 debugging is on");
591 DEFUN (no_debug_bgp_as4
,
592 no_debug_bgp_as4_cmd
,
599 if (vty
->node
== CONFIG_NODE
)
600 DEBUG_OFF (as4
, AS4
);
603 TERM_DEBUG_OFF (as4
, AS4
);
604 vty_outln (vty
, "BGP as4 debugging is off");
609 DEFUN (debug_bgp_as4_segment
,
610 debug_bgp_as4_segment_cmd
,
611 "debug bgp as4 segment",
615 "BGP AS4 aspath segment handling\n")
617 if (vty
->node
== CONFIG_NODE
)
618 DEBUG_ON (as4
, AS4_SEGMENT
);
621 TERM_DEBUG_ON (as4
, AS4_SEGMENT
);
622 vty_outln (vty
, "BGP as4 segment debugging is on");
627 DEFUN (no_debug_bgp_as4_segment
,
628 no_debug_bgp_as4_segment_cmd
,
629 "no debug bgp as4 segment",
634 "BGP AS4 aspath segment handling\n")
636 if (vty
->node
== CONFIG_NODE
)
637 DEBUG_OFF (as4
, AS4_SEGMENT
);
640 TERM_DEBUG_OFF (as4
, AS4_SEGMENT
);
641 vty_outln (vty
, "BGP as4 segment debugging is off");
646 /* debug bgp neighbor_events */
647 DEFUN (debug_bgp_neighbor_events
,
648 debug_bgp_neighbor_events_cmd
,
649 "debug bgp neighbor-events",
652 "BGP Neighbor Events\n")
654 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
656 if (vty
->node
== CONFIG_NODE
)
657 DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
660 TERM_DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
661 vty_outln (vty
, "BGP neighbor-events debugging is on");
666 DEFUN (debug_bgp_neighbor_events_peer
,
667 debug_bgp_neighbor_events_peer_cmd
,
668 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
671 "BGP Neighbor Events\n"
672 "BGP neighbor IP address to debug\n"
673 "BGP IPv6 neighbor to debug\n"
674 "BGP neighbor on interface to debug\n")
677 const char *host
= argv
[idx_peer
]->arg
;
679 if (!bgp_debug_neighbor_events_peers
)
680 bgp_debug_neighbor_events_peers
= list_new ();
682 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
, NULL
))
684 vty_outln (vty
, "BGP neighbor-events debugging is already enabled for %s",
689 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
691 if (vty
->node
== CONFIG_NODE
)
692 DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
695 TERM_DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
696 vty_outln (vty
, "BGP neighbor-events debugging is on for %s", host
);
701 DEFUN (no_debug_bgp_neighbor_events
,
702 no_debug_bgp_neighbor_events_cmd
,
703 "no debug bgp neighbor-events",
709 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
711 if (vty
->node
== CONFIG_NODE
)
712 DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
715 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
716 vty_outln (vty
, "BGP neighbor-events debugging is off");
721 DEFUN (no_debug_bgp_neighbor_events_peer
,
722 no_debug_bgp_neighbor_events_peer_cmd
,
723 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
728 "BGP neighbor IP address to debug\n"
729 "BGP IPv6 neighbor to debug\n"
730 "BGP neighbor on interface to debug\n")
734 const char *host
= argv
[idx_peer
]->arg
;
736 if (bgp_debug_neighbor_events_peers
&& !list_isempty(bgp_debug_neighbor_events_peers
))
738 found_peer
= bgp_debug_list_remove_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
740 if (list_isempty(bgp_debug_neighbor_events_peers
))
742 if (vty
->node
== CONFIG_NODE
)
743 DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
745 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
750 vty_outln (vty
, "BGP neighbor-events debugging is off for %s", host
);
752 vty_outln (vty
, "BGP neighbor-events debugging was not enabled for %s",
759 DEFUN (debug_bgp_nht
,
764 "BGP nexthop tracking events\n")
766 if (vty
->node
== CONFIG_NODE
)
770 TERM_DEBUG_ON (nht
, NHT
);
771 vty_outln (vty
, "BGP nexthop tracking debugging is on");
776 DEFUN (no_debug_bgp_nht
,
777 no_debug_bgp_nht_cmd
,
782 "BGP nexthop tracking events\n")
784 if (vty
->node
== CONFIG_NODE
)
785 DEBUG_OFF (nht
, NHT
);
788 TERM_DEBUG_OFF (nht
, NHT
);
789 vty_outln (vty
, "BGP nexthop tracking debugging is off");
794 /* debug bgp keepalives */
795 DEFUN (debug_bgp_keepalive
,
796 debug_bgp_keepalive_cmd
,
797 "debug bgp keepalives",
802 bgp_debug_list_free(bgp_debug_keepalive_peers
);
804 if (vty
->node
== CONFIG_NODE
)
805 DEBUG_ON (keepalive
, KEEPALIVE
);
808 TERM_DEBUG_ON (keepalive
, KEEPALIVE
);
809 vty_outln (vty
, "BGP keepalives debugging is on");
814 DEFUN (debug_bgp_keepalive_peer
,
815 debug_bgp_keepalive_peer_cmd
,
816 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
819 "BGP Neighbor Events\n"
820 "BGP neighbor IP address to debug\n"
821 "BGP IPv6 neighbor to debug\n"
822 "BGP neighbor on interface to debug\n")
825 const char *host
= argv
[idx_peer
]->arg
;
827 if (!bgp_debug_keepalive_peers
)
828 bgp_debug_keepalive_peers
= list_new ();
830 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
))
832 vty_outln (vty
, "BGP keepalive debugging is already enabled for %s",
837 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
839 if (vty
->node
== CONFIG_NODE
)
840 DEBUG_ON (keepalive
, KEEPALIVE
);
843 TERM_DEBUG_ON (keepalive
, KEEPALIVE
);
844 vty_outln (vty
, "BGP keepalives debugging is on for %s", host
);
849 DEFUN (no_debug_bgp_keepalive
,
850 no_debug_bgp_keepalive_cmd
,
851 "no debug bgp keepalives",
857 bgp_debug_list_free(bgp_debug_keepalive_peers
);
859 if (vty
->node
== CONFIG_NODE
)
860 DEBUG_OFF (keepalive
, KEEPALIVE
);
863 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
864 vty_outln (vty
, "BGP keepalives debugging is off");
869 DEFUN (no_debug_bgp_keepalive_peer
,
870 no_debug_bgp_keepalive_peer_cmd
,
871 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
876 "BGP neighbor IP address to debug\n"
877 "BGP IPv6 neighbor to debug\n"
878 "BGP neighbor on interface to debug\n")
882 const char *host
= argv
[idx_peer
]->arg
;
884 if (bgp_debug_keepalive_peers
&& !list_isempty(bgp_debug_keepalive_peers
))
886 found_peer
= bgp_debug_list_remove_entry(bgp_debug_keepalive_peers
, host
, NULL
);
888 if (list_isempty(bgp_debug_keepalive_peers
))
890 if (vty
->node
== CONFIG_NODE
)
891 DEBUG_OFF (keepalive
, KEEPALIVE
);
893 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
898 vty_outln (vty
, "BGP keepalives debugging is off for %s", host
);
900 vty_outln (vty
, "BGP keepalives debugging was not enabled for %s", host
);
905 #ifndef VTYSH_EXTRACT_PL
906 #include "bgp_debug_clippy.c"
909 /* debug bgp bestpath */
910 DEFPY (debug_bgp_bestpath_prefix
,
911 debug_bgp_bestpath_prefix_cmd
,
912 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>$bestpath",
920 if (!bgp_debug_bestpath_prefixes
)
921 bgp_debug_bestpath_prefixes
= list_new ();
923 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
, bestpath
))
925 vty_outln (vty
, "BGP bestpath debugging is already enabled for %s", bestpath_str
);
929 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, bestpath
);
931 if (vty
->node
== CONFIG_NODE
)
933 DEBUG_ON (bestpath
, BESTPATH
);
937 TERM_DEBUG_ON (bestpath
, BESTPATH
);
938 vty_outln (vty
, "BGP bestpath debugging is on for %s", bestpath_str
);
944 DEFUN (no_debug_bgp_bestpath_prefix
,
945 no_debug_bgp_bestpath_prefix_cmd
,
946 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
955 int idx_ipv4_ipv6_prefixlen
= 4;
956 struct prefix
*argv_p
;
957 int found_prefix
= 0;
960 argv_p
= prefix_new();
961 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
965 vty_outln (vty
, "%% Malformed Prefix");
969 if (bgp_debug_bestpath_prefixes
&& !list_isempty(bgp_debug_bestpath_prefixes
))
971 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
973 if (list_isempty(bgp_debug_bestpath_prefixes
))
975 if (vty
->node
== CONFIG_NODE
)
977 DEBUG_OFF (bestpath
, BESTPATH
);
981 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
982 vty_outln (vty
, "BGP bestpath debugging (per prefix) is off");
988 vty_outln (vty
, "BGP bestpath debugging is off for %s",
989 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
991 vty_outln (vty
, "BGP bestpath debugging was not enabled for %s",
992 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
997 DEFUN (no_debug_bgp_bestpath
,
998 no_debug_bgp_bestpath_cmd
,
999 "no debug bgp bestpath",
1005 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1007 if (vty
->node
== CONFIG_NODE
)
1008 DEBUG_OFF (bestpath
, BESTPATH
);
1011 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
1012 vty_outln (vty
, "BGP bestpath debugging is off");
1017 /* debug bgp updates */
1018 DEFUN (debug_bgp_update
,
1019 debug_bgp_update_cmd
,
1020 "debug bgp updates",
1025 bgp_debug_list_free(bgp_debug_update_in_peers
);
1026 bgp_debug_list_free(bgp_debug_update_out_peers
);
1027 bgp_debug_list_free(bgp_debug_update_prefixes
);
1029 if (vty
->node
== CONFIG_NODE
)
1031 DEBUG_ON (update
, UPDATE_IN
);
1032 DEBUG_ON (update
, UPDATE_OUT
);
1036 TERM_DEBUG_ON (update
, UPDATE_IN
);
1037 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1038 vty_outln (vty
, "BGP updates debugging is on");
1043 DEFUN (debug_bgp_update_direct
,
1044 debug_bgp_update_direct_cmd
,
1045 "debug bgp updates <in|out>",
1050 "Outbound updates\n")
1054 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1055 bgp_debug_list_free(bgp_debug_update_in_peers
);
1057 bgp_debug_list_free(bgp_debug_update_out_peers
);
1059 if (vty
->node
== CONFIG_NODE
)
1061 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1062 DEBUG_ON (update
, UPDATE_IN
);
1064 DEBUG_ON (update
, UPDATE_OUT
);
1068 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1070 TERM_DEBUG_ON (update
, UPDATE_IN
);
1071 vty_outln (vty
, "BGP updates debugging is on (inbound)");
1075 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1076 vty_outln (vty
, "BGP updates debugging is on (outbound)");
1082 DEFUN (debug_bgp_update_direct_peer
,
1083 debug_bgp_update_direct_peer_cmd
,
1084 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1089 "Outbound updates\n"
1090 "BGP neighbor IP address to debug\n"
1091 "BGP IPv6 neighbor to debug\n"
1092 "BGP neighbor on interface to debug\n")
1096 const char *host
= argv
[idx_peer
]->arg
;
1099 if (!bgp_debug_update_in_peers
)
1100 bgp_debug_update_in_peers
= list_new ();
1102 if (!bgp_debug_update_out_peers
)
1103 bgp_debug_update_out_peers
= list_new ();
1105 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1112 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
, NULL
))
1114 vty_outln (vty
, "BGP inbound update debugging is already enabled for %s",
1122 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
, NULL
))
1124 vty_outln (vty
, "BGP outbound update debugging is already enabled for %s",
1131 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1135 struct peer_af
*paf
;
1138 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
, NULL
);
1139 peer
= bgp_find_peer (vty
, host
);
1143 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
; afidx
++)
1145 paf
= peer
->peer_af_array
[afidx
];
1148 if (PAF_SUBGRP (paf
))
1150 UPDGRP_PEER_DBG_EN(PAF_SUBGRP(paf
)->update_group
);
1157 if (vty
->node
== CONFIG_NODE
)
1160 DEBUG_ON (update
, UPDATE_IN
);
1162 DEBUG_ON (update
, UPDATE_OUT
);
1168 TERM_DEBUG_ON (update
, UPDATE_IN
);
1169 vty_outln (vty
, "BGP updates debugging is on (inbound) for %s",
1170 argv
[idx_peer
]->arg
);
1174 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1175 vty_outln (vty
, "BGP updates debugging is on (outbound) for %s",
1176 argv
[idx_peer
]->arg
);
1182 DEFUN (no_debug_bgp_update_direct
,
1183 no_debug_bgp_update_direct_cmd
,
1184 "no debug bgp updates <in|out>",
1190 "Outbound updates\n")
1193 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1195 bgp_debug_list_free(bgp_debug_update_in_peers
);
1197 if (vty
->node
== CONFIG_NODE
)
1199 DEBUG_OFF (update
, UPDATE_IN
);
1203 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1204 vty_outln (vty
, "BGP updates debugging is off (inbound)");
1209 bgp_debug_list_free(bgp_debug_update_out_peers
);
1211 if (vty
->node
== CONFIG_NODE
)
1213 DEBUG_OFF (update
, UPDATE_OUT
);
1217 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1218 vty_outln (vty
, "BGP updates debugging is off (outbound)");
1225 DEFUN (no_debug_bgp_update_direct_peer
,
1226 no_debug_bgp_update_direct_peer_cmd
,
1227 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1233 "Outbound updates\n"
1234 "BGP neighbor IP address to debug\n"
1235 "BGP IPv6 neighbor to debug\n"
1236 "BGP neighbor on interface to debug\n")
1242 const char *host
= argv
[idx_peer
]->arg
;
1244 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1249 if (inbound
&& bgp_debug_update_in_peers
&&
1250 !list_isempty(bgp_debug_update_in_peers
))
1252 found_peer
= bgp_debug_list_remove_entry(bgp_debug_update_in_peers
, host
, NULL
);
1254 if (list_isempty(bgp_debug_update_in_peers
))
1256 if (vty
->node
== CONFIG_NODE
)
1257 DEBUG_OFF (update
, UPDATE_IN
);
1260 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1261 vty_outln (vty
, "BGP updates debugging (inbound) is off");
1266 if (!inbound
&& bgp_debug_update_out_peers
&&
1267 !list_isempty(bgp_debug_update_out_peers
))
1269 found_peer
= bgp_debug_list_remove_entry(bgp_debug_update_out_peers
, host
, NULL
);
1271 if (list_isempty(bgp_debug_update_out_peers
))
1273 if (vty
->node
== CONFIG_NODE
)
1274 DEBUG_OFF (update
, UPDATE_OUT
);
1277 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1278 vty_outln (vty
, "BGP updates debugging (outbound) is off");
1283 struct peer_af
*paf
;
1285 peer
= bgp_find_peer (vty
, host
);
1289 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
; afidx
++)
1291 paf
= peer
->peer_af_array
[afidx
];
1294 if (PAF_SUBGRP (paf
))
1296 UPDGRP_PEER_DBG_DIS(PAF_SUBGRP(paf
)->update_group
);
1305 vty_outln (vty
, "BGP updates debugging (inbound) is off for %s", host
);
1307 vty_outln (vty
, "BGP updates debugging (outbound) is off for %s",
1311 vty_outln (vty
, "BGP updates debugging (inbound) was not enabled for %s",
1314 vty_outln (vty
, "BGP updates debugging (outbound) was not enabled for %s",
1320 DEFUN (debug_bgp_update_prefix
,
1321 debug_bgp_update_prefix_cmd
,
1322 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1326 "Specify a prefix to debug\n"
1331 int idx_ipv4_ipv6_prefixlen
= 4;
1332 struct prefix
*argv_p
;
1335 argv_p
= prefix_new();
1336 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1339 prefix_free(argv_p
);
1340 vty_outln (vty
, "%% Malformed Prefix");
1345 if (!bgp_debug_update_prefixes
)
1346 bgp_debug_update_prefixes
= list_new ();
1348 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
))
1350 vty_outln (vty
, "BGP updates debugging is already enabled for %s",
1351 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1355 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1357 if (vty
->node
== CONFIG_NODE
)
1359 DEBUG_ON (update
, UPDATE_PREFIX
);
1363 TERM_DEBUG_ON (update
, UPDATE_PREFIX
);
1364 vty_outln (vty
, "BGP updates debugging is on for %s",
1365 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1371 DEFUN (no_debug_bgp_update_prefix
,
1372 no_debug_bgp_update_prefix_cmd
,
1373 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1378 "Specify a prefix to debug\n"
1383 int idx_ipv4_ipv6_prefixlen
= 5;
1384 struct prefix
*argv_p
;
1385 int found_prefix
= 0;
1388 argv_p
= prefix_new();
1389 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1392 prefix_free(argv_p
);
1393 vty_outln (vty
, "%% Malformed Prefix");
1397 if (bgp_debug_update_prefixes
&& !list_isempty(bgp_debug_update_prefixes
))
1399 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1401 if (list_isempty(bgp_debug_update_prefixes
))
1403 if (vty
->node
== CONFIG_NODE
)
1405 DEBUG_OFF (update
, UPDATE_PREFIX
);
1409 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1410 vty_outln (vty
, "BGP updates debugging (per prefix) is off");
1416 vty_outln (vty
, "BGP updates debugging is off for %s",
1417 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1419 vty_outln (vty
, "BGP updates debugging was not enabled for %s",
1420 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1425 DEFUN (no_debug_bgp_update
,
1426 no_debug_bgp_update_cmd
,
1427 "no debug bgp updates",
1433 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1434 bgp_debug_list_free(bgp_debug_update_in_peers
);
1435 bgp_debug_list_free(bgp_debug_update_out_peers
);
1436 bgp_debug_list_free(bgp_debug_update_prefixes
);
1438 bgp_debug_clear_updgrp_update_dbg(bgp
);
1440 if (vty
->node
== CONFIG_NODE
)
1442 DEBUG_OFF (update
, UPDATE_IN
);
1443 DEBUG_OFF (update
, UPDATE_OUT
);
1444 DEBUG_OFF (update
, UPDATE_PREFIX
);
1448 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1449 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1450 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1451 vty_outln (vty
, "BGP updates debugging is off");
1456 /* debug bgp zebra */
1457 DEFUN (debug_bgp_zebra
,
1458 debug_bgp_zebra_cmd
,
1462 "BGP Zebra messages\n")
1464 if (vty
->node
== CONFIG_NODE
)
1465 DEBUG_ON (zebra
, ZEBRA
);
1468 TERM_DEBUG_ON (zebra
, ZEBRA
);
1469 vty_outln (vty
, "BGP zebra debugging is on");
1474 DEFUN (debug_bgp_zebra_prefix
,
1475 debug_bgp_zebra_prefix_cmd
,
1476 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1479 "BGP Zebra messages\n"
1480 "Specify a prefix to debug\n"
1485 int idx_ipv4_ipv6_prefixlen
= 4;
1486 struct prefix
*argv_p
;
1489 argv_p
= prefix_new();
1490 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1493 prefix_free(argv_p
);
1494 vty_outln (vty
, "%% Malformed Prefix");
1498 if (!bgp_debug_zebra_prefixes
)
1499 bgp_debug_zebra_prefixes
= list_new();
1501 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
))
1503 vty_outln (vty
, "BGP zebra debugging is already enabled for %s",
1504 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1508 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1510 if (vty
->node
== CONFIG_NODE
)
1511 DEBUG_ON (zebra
, ZEBRA
);
1514 TERM_DEBUG_ON (zebra
, ZEBRA
);
1515 vty_outln (vty
, "BGP zebra debugging is on for %s",
1516 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1522 DEFUN (no_debug_bgp_zebra
,
1523 no_debug_bgp_zebra_cmd
,
1524 "no debug bgp zebra",
1528 "BGP Zebra messages\n")
1530 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1532 if (vty
->node
== CONFIG_NODE
)
1533 DEBUG_OFF (zebra
, ZEBRA
);
1536 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1537 vty_outln (vty
, "BGP zebra debugging is off");
1542 DEFUN (no_debug_bgp_zebra_prefix
,
1543 no_debug_bgp_zebra_prefix_cmd
,
1544 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1548 "BGP Zebra messages\n"
1549 "Specify a prefix to debug\n"
1554 int idx_ipv4_ipv6_prefixlen
= 5;
1555 struct prefix
*argv_p
;
1556 int found_prefix
= 0;
1559 argv_p
= prefix_new();
1560 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1563 prefix_free(argv_p
);
1564 vty_outln (vty
, "%% Malformed Prefix");
1568 if (bgp_debug_zebra_prefixes
&& !list_isempty(bgp_debug_zebra_prefixes
))
1570 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1572 if (list_isempty(bgp_debug_zebra_prefixes
))
1574 if (vty
->node
== CONFIG_NODE
)
1575 DEBUG_OFF (zebra
, ZEBRA
);
1578 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1579 vty_outln (vty
, "BGP zebra debugging is off");
1585 vty_outln (vty
, "BGP zebra debugging is off for %s",
1586 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1588 vty_outln (vty
, "BGP zebra debugging was not enabled for %s",
1589 argv
[idx_ipv4_ipv6_prefixlen
]->arg
);
1594 DEFUN (debug_bgp_allow_martians
,
1595 debug_bgp_allow_martians_cmd
,
1596 "debug bgp allow-martians",
1599 "BGP allow martian next hops\n")
1601 if (vty
->node
== CONFIG_NODE
)
1602 DEBUG_ON (allow_martians
, ALLOW_MARTIANS
);
1605 TERM_DEBUG_ON (allow_martians
, ALLOW_MARTIANS
);
1606 vty_outln (vty
, "BGP allow_martian next hop debugging is on");
1611 DEFUN (no_debug_bgp_allow_martians
,
1612 no_debug_bgp_allow_martians_cmd
,
1613 "no debug bgp allow-martians",
1617 "BGP allow martian next hops\n")
1619 if (vty
->node
== CONFIG_NODE
)
1620 DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1623 TERM_DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1624 vty_outln (vty
, "BGP allow martian next hop debugging is off");
1630 /* debug bgp update-groups */
1631 DEFUN (debug_bgp_update_groups
,
1632 debug_bgp_update_groups_cmd
,
1633 "debug bgp update-groups",
1636 "BGP update-groups\n")
1638 if (vty
->node
== CONFIG_NODE
)
1639 DEBUG_ON (update_groups
, UPDATE_GROUPS
);
1642 TERM_DEBUG_ON (update_groups
, UPDATE_GROUPS
);
1643 vty_outln (vty
, "BGP update-groups debugging is on");
1648 DEFUN (no_debug_bgp_update_groups
,
1649 no_debug_bgp_update_groups_cmd
,
1650 "no debug bgp update-groups",
1654 "BGP update-groups\n")
1656 if (vty
->node
== CONFIG_NODE
)
1657 DEBUG_OFF (update_groups
, UPDATE_GROUPS
);
1660 TERM_DEBUG_OFF (update_groups
, UPDATE_GROUPS
);
1661 vty_outln (vty
, "BGP update-groups debugging is off");
1666 DEFUN (no_debug_bgp
,
1673 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1674 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
1675 bgp_debug_list_free(bgp_debug_keepalive_peers
);
1676 bgp_debug_list_free(bgp_debug_update_in_peers
);
1677 bgp_debug_list_free(bgp_debug_update_out_peers
);
1678 bgp_debug_list_free(bgp_debug_update_prefixes
);
1679 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1680 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1682 bgp_debug_clear_updgrp_update_dbg(bgp
);
1684 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
1685 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1686 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1687 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1688 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
1689 TERM_DEBUG_OFF (as4
, AS4
);
1690 TERM_DEBUG_OFF (as4
, AS4_SEGMENT
);
1691 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
1692 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1693 TERM_DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1694 vty_outln (vty
, "All possible debugging has been turned off");
1699 DEFUN (show_debugging_bgp
,
1700 show_debugging_bgp_cmd
,
1701 "show debugging bgp",
1706 vty_outln (vty
, "BGP debugging status:");
1708 if (BGP_DEBUG (as4
, AS4
))
1709 vty_outln (vty
, " BGP as4 debugging is on");
1711 if (BGP_DEBUG (as4
, AS4_SEGMENT
))
1712 vty_outln (vty
, " BGP as4 aspath segment debugging is on");
1714 if (BGP_DEBUG (bestpath
, BESTPATH
))
1715 bgp_debug_list_print (vty
, " BGP bestpath debugging is on",
1716 bgp_debug_bestpath_prefixes
);
1718 if (BGP_DEBUG (keepalive
, KEEPALIVE
))
1719 bgp_debug_list_print (vty
, " BGP keepalives debugging is on",
1720 bgp_debug_keepalive_peers
);
1722 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1723 bgp_debug_list_print (vty
, " BGP neighbor-events debugging is on",
1724 bgp_debug_neighbor_events_peers
);
1726 if (BGP_DEBUG (nht
, NHT
))
1727 vty_outln (vty
, " BGP next-hop tracking debugging is on");
1729 if (BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1730 vty_outln (vty
, " BGP update-groups debugging is on");
1732 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
1733 bgp_debug_list_print (vty
, " BGP updates debugging is on",
1734 bgp_debug_update_prefixes
);
1736 if (BGP_DEBUG (update
, UPDATE_IN
))
1737 bgp_debug_list_print (vty
, " BGP updates debugging is on (inbound)",
1738 bgp_debug_update_in_peers
);
1740 if (BGP_DEBUG (update
, UPDATE_OUT
))
1741 bgp_debug_list_print (vty
, " BGP updates debugging is on (outbound)",
1742 bgp_debug_update_out_peers
);
1744 if (BGP_DEBUG (zebra
, ZEBRA
))
1745 bgp_debug_list_print (vty
, " BGP zebra debugging is on",
1746 bgp_debug_zebra_prefixes
);
1748 if (BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1749 vty_outln (vty
, " BGP allow martian next hop debugging is on");
1750 vty_outln (vty
, "");
1754 /* return count of number of debug flags set */
1756 bgp_debug_count(void)
1759 if (BGP_DEBUG (as4
, AS4
))
1762 if (BGP_DEBUG (as4
, AS4_SEGMENT
))
1765 if (BGP_DEBUG (bestpath
, BESTPATH
))
1768 if (BGP_DEBUG (keepalive
, KEEPALIVE
))
1771 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1774 if (BGP_DEBUG (nht
, NHT
))
1777 if (BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1780 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
1783 if (BGP_DEBUG (update
, UPDATE_IN
))
1786 if (BGP_DEBUG (update
, UPDATE_OUT
))
1789 if (BGP_DEBUG (zebra
, ZEBRA
))
1792 if (BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1799 bgp_config_write_debug (struct vty
*vty
)
1803 if (CONF_BGP_DEBUG (as4
, AS4
))
1805 vty_outln (vty
, "debug bgp as4");
1809 if (CONF_BGP_DEBUG (as4
, AS4_SEGMENT
))
1811 vty_outln (vty
, "debug bgp as4 segment");
1815 if (CONF_BGP_DEBUG (bestpath
, BESTPATH
))
1817 write
+= bgp_debug_list_conf_print (vty
, "debug bgp bestpath",
1818 bgp_debug_bestpath_prefixes
);
1821 if (CONF_BGP_DEBUG (keepalive
, KEEPALIVE
))
1823 write
+= bgp_debug_list_conf_print (vty
, "debug bgp keepalives",
1824 bgp_debug_keepalive_peers
);
1827 if (CONF_BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1829 write
+= bgp_debug_list_conf_print (vty
, "debug bgp neighbor-events",
1830 bgp_debug_neighbor_events_peers
);
1833 if (CONF_BGP_DEBUG (nht
, NHT
))
1835 vty_outln (vty
, "debug bgp nht");
1839 if (CONF_BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1841 vty_outln (vty
, "debug bgp update-groups");
1845 if (CONF_BGP_DEBUG (update
, UPDATE_PREFIX
))
1847 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates prefix",
1848 bgp_debug_update_prefixes
);
1851 if (CONF_BGP_DEBUG (update
, UPDATE_IN
))
1853 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates in",
1854 bgp_debug_update_in_peers
);
1857 if (CONF_BGP_DEBUG (update
, UPDATE_OUT
))
1859 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates out",
1860 bgp_debug_update_out_peers
);
1863 if (CONF_BGP_DEBUG (zebra
, ZEBRA
))
1865 if (!bgp_debug_zebra_prefixes
|| list_isempty(bgp_debug_zebra_prefixes
))
1867 vty_outln (vty
, "debug bgp zebra");
1872 write
+= bgp_debug_list_conf_print (vty
, "debug bgp zebra prefix",
1873 bgp_debug_zebra_prefixes
);
1877 if (CONF_BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1879 vty_outln (vty
, "debug bgp allow-martians");
1886 static struct cmd_node debug_node
=
1894 bgp_debug_init (void)
1896 install_node (&debug_node
, bgp_config_write_debug
);
1898 install_element (ENABLE_NODE
, &show_debugging_bgp_cmd
);
1900 install_element (ENABLE_NODE
, &debug_bgp_as4_cmd
);
1901 install_element (CONFIG_NODE
, &debug_bgp_as4_cmd
);
1902 install_element (ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
1903 install_element (CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
1905 install_element (ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
1906 install_element (CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
1907 install_element (ENABLE_NODE
, &debug_bgp_nht_cmd
);
1908 install_element (CONFIG_NODE
, &debug_bgp_nht_cmd
);
1909 install_element (ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
1910 install_element (CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
1911 install_element (ENABLE_NODE
, &debug_bgp_update_cmd
);
1912 install_element (CONFIG_NODE
, &debug_bgp_update_cmd
);
1913 install_element (ENABLE_NODE
, &debug_bgp_zebra_cmd
);
1914 install_element (CONFIG_NODE
, &debug_bgp_zebra_cmd
);
1915 install_element (ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
1916 install_element (CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
1917 install_element (ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
1918 install_element (CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
1919 install_element (ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1920 install_element (CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1922 /* debug bgp updates (in|out) */
1923 install_element (ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
1924 install_element (CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
1925 install_element (ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
1926 install_element (CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
1928 /* debug bgp updates (in|out) A.B.C.D */
1929 install_element (ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
1930 install_element (CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
1931 install_element (ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1932 install_element (CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1934 /* debug bgp updates prefix A.B.C.D/M */
1935 install_element (ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
1936 install_element (CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
1937 install_element (ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
1938 install_element (CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
1940 /* debug bgp zebra prefix A.B.C.D/M */
1941 install_element (ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
1942 install_element (CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
1943 install_element (ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1944 install_element (CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1946 install_element (ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
1947 install_element (CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
1948 install_element (ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
1949 install_element (CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
1951 /* debug bgp neighbor-events A.B.C.D */
1952 install_element (ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1953 install_element (CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1954 install_element (ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1955 install_element (CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1957 /* debug bgp keepalive A.B.C.D */
1958 install_element (ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
1959 install_element (CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
1960 install_element (ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1961 install_element (CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1963 install_element (ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1964 install_element (CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1965 install_element (ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
1966 install_element (CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
1967 install_element (ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
1968 install_element (CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
1969 install_element (ENABLE_NODE
, &no_debug_bgp_update_cmd
);
1970 install_element (CONFIG_NODE
, &no_debug_bgp_update_cmd
);
1971 install_element (ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
1972 install_element (CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
1973 install_element (ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
1974 install_element (CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
1975 install_element (ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
1976 install_element (CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
1977 install_element (ENABLE_NODE
, &no_debug_bgp_cmd
);
1978 install_element (ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
1979 install_element (CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
1980 install_element (ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1981 install_element (CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1984 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
1985 * for BGP_DEBUG_TYPE
1988 bgp_debug_per_prefix (struct prefix
*p
, unsigned long term_bgp_debug_type
,
1989 unsigned int BGP_DEBUG_TYPE
, struct list
*per_prefix_list
)
1991 struct bgp_debug_filter
*filter
;
1992 struct listnode
*node
, *nnode
;
1994 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
)
1996 /* We are debugging all prefixes so return true */
1997 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
2005 for (ALL_LIST_ELEMENTS (per_prefix_list
, node
, nnode
, filter
))
2006 if (filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
2016 /* Return true if this peer is on the per_peer_list of peers to debug
2017 * for BGP_DEBUG_TYPE
2020 bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2021 unsigned int BGP_DEBUG_TYPE
, struct list
*per_peer_list
)
2023 struct bgp_debug_filter
*filter
;
2024 struct listnode
*node
, *nnode
;
2026 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
)
2028 /* We are debugging all peers so return true */
2029 if (!per_peer_list
|| list_isempty(per_peer_list
))
2037 for (ALL_LIST_ELEMENTS (per_peer_list
, node
, nnode
, filter
))
2038 if (strcmp (filter
->host
, host
) == 0)
2049 bgp_debug_neighbor_events (struct peer
*peer
)
2056 return bgp_debug_per_peer (host
,
2057 term_bgp_debug_neighbor_events
,
2058 BGP_DEBUG_NEIGHBOR_EVENTS
,
2059 bgp_debug_neighbor_events_peers
);
2063 bgp_debug_keepalive (struct peer
*peer
)
2070 return bgp_debug_per_peer (host
,
2071 term_bgp_debug_keepalive
,
2072 BGP_DEBUG_KEEPALIVE
,
2073 bgp_debug_keepalive_peers
);
2077 bgp_debug_update (struct peer
*peer
, struct prefix
*p
,
2078 struct update_group
*updgrp
, unsigned int inbound
)
2087 if (bgp_debug_per_peer (host
, term_bgp_debug_update
, BGP_DEBUG_UPDATE_IN
,
2088 bgp_debug_update_in_peers
))
2095 if (bgp_debug_per_peer (host
, term_bgp_debug_update
,
2096 BGP_DEBUG_UPDATE_OUT
,
2097 bgp_debug_update_out_peers
))
2100 /* Check if update debugging implicitly enabled for the group. */
2101 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2106 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
2108 if (bgp_debug_per_prefix (p
, term_bgp_debug_update
,
2109 BGP_DEBUG_UPDATE_PREFIX
,
2110 bgp_debug_update_prefixes
))
2118 bgp_debug_bestpath (struct prefix
*p
)
2120 if (BGP_DEBUG (bestpath
, BESTPATH
))
2122 if (bgp_debug_per_prefix (p
, term_bgp_debug_bestpath
,
2124 bgp_debug_bestpath_prefixes
))
2132 bgp_debug_zebra (struct prefix
*p
)
2134 if (BGP_DEBUG (zebra
, ZEBRA
))
2136 if (bgp_debug_per_prefix (p
, term_bgp_debug_zebra
, BGP_DEBUG_ZEBRA
,
2137 bgp_debug_zebra_prefixes
))
2145 bgp_debug_rdpfxpath2str (struct prefix_rd
*prd
, union prefixconstptr pu
,
2146 int addpath_valid
, u_int32_t addpath_id
,
2147 char *str
, int size
)
2149 char rd_buf
[RD_ADDRSTRLEN
];
2150 char pfx_buf
[PREFIX_STRLEN
];
2151 /* ' with addpath ID ' 17
2152 * max strlen of uint32 + 10
2153 * +/- (just in case) + 1
2154 * null terminator + 1
2155 * ============================ 29 */
2156 char pathid_buf
[30];
2158 if (size
< BGP_PRD_PATH_STRLEN
)
2161 /* Note: Path-id is created by default, but only included in update sometimes. */
2162 pathid_buf
[0] = '\0';
2164 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u", addpath_id
);
2167 snprintf (str
, size
, "RD %s %s%s",
2168 prefix_rd2str(prd
, rd_buf
, sizeof (rd_buf
)),
2169 prefix2str (pu
, pfx_buf
, sizeof (pfx_buf
)), pathid_buf
);
2171 snprintf (str
, size
, "%s%s",
2172 prefix2str (pu
, pfx_buf
, sizeof (pfx_buf
)), pathid_buf
);