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" },
89 const int bgp_status_msg_max
= BGP_STATUS_MAX
;
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"},
114 static const int bgp_notify_msg_max
= BGP_NOTIFY_MAX
;
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"}
122 static const int bgp_notify_head_msg_max
= BGP_NOTIFY_HEADER_MAX
;
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"},
135 static const int bgp_notify_open_msg_max
= BGP_NOTIFY_OPEN_MAX
;
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"},
152 static const int bgp_notify_update_msg_max
= BGP_NOTIFY_UPDATE_MAX
;
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"},
166 static const int bgp_notify_cease_msg_max
= BGP_NOTIFY_CEASE_MAX
;
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"},
175 static const int bgp_notify_capability_msg_max
= BGP_NOTIFY_CAPABILITY_MAX
;
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
);
257 vty_out (vty
, "%s", VTY_NEWLINE
);
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_out (vty
, "%s %s%s", desc
, filter
->host
, VTY_NEWLINE
);
284 vty_out (vty
, "%s %s/%d%s", desc
,
285 inet_ntop (filter
->p
->family
, &filter
->p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
286 filter
->p
->prefixlen
, VTY_NEWLINE
);
294 vty_out (vty
, "%s%s", desc
, VTY_NEWLINE
);
302 bgp_debug_list_add_entry(struct list
*list
, const char *host
, 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
);
319 listnode_add(list
, filter
);
323 bgp_debug_list_remove_entry(struct list
*list
, const char *host
, struct prefix
*p
)
325 struct bgp_debug_filter
*filter
;
326 struct listnode
*node
, *nnode
;
328 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
330 if (host
&& strcmp (filter
->host
, host
) == 0)
332 listnode_delete (list
, filter
);
333 XFREE (MTYPE_BGP_DEBUG_STR
, filter
->host
);
334 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
337 else if (p
&& filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
339 listnode_delete (list
, filter
);
340 prefix_free (filter
->p
);
341 XFREE (MTYPE_BGP_DEBUG_FILTER
, filter
);
350 bgp_debug_list_has_entry(struct list
*list
, const char *host
, struct prefix
*p
)
352 struct bgp_debug_filter
*filter
;
353 struct listnode
*node
, *nnode
;
355 for (ALL_LIST_ELEMENTS (list
, node
, nnode
, filter
))
359 if (strcmp (filter
->host
, host
) == 0)
366 if (filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
377 bgp_debug_peer_updout_enabled(char *host
)
379 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
, NULL
));
382 /* Dump attribute. */
384 bgp_dump_attr (struct attr
*attr
, char *buf
, size_t size
)
389 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
)))
390 snprintf (buf
, size
, "nexthop %s", inet_ntoa (attr
->nexthop
));
392 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN
)))
393 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", origin %s",
394 bgp_origin_str
[attr
->origin
]);
398 char addrbuf
[BUFSIZ
];
401 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
402 || attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
403 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", mp_nexthop %s",
404 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
407 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
408 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), "(%s)",
409 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_local
,
413 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
)))
414 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", localpref %u",
417 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
)))
418 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", metric %u",
421 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
)))
422 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", community %s",
423 community_str (attr
->community
));
425 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
)))
426 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", atomic-aggregate");
428 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
)))
429 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", aggregated by %u %s",
430 attr
->extra
->aggregator_as
,
431 inet_ntoa (attr
->extra
->aggregator_addr
));
433 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
)))
434 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", originator %s",
435 inet_ntoa (attr
->extra
->originator_id
));
437 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST
)))
441 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", clusterlist");
442 for (i
= 0; i
< attr
->extra
->cluster
->length
/ 4; i
++)
443 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), " %s",
444 inet_ntoa (attr
->extra
->cluster
->list
[i
]));
447 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH
)))
448 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", path %s",
449 aspath_print (attr
->aspath
));
451 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID
)))
453 if (attr
->extra
->label_index
!= BGP_INVALID_LABEL_INDEX
)
454 snprintf (buf
+ strlen (buf
), size
- strlen (buf
), ", label-index %u",
455 attr
->extra
->label_index
);
458 if (strlen (buf
) > 1)
465 bgp_notify_code_str (char code
)
467 return LOOKUP_DEF (bgp_notify_msg
, code
, "Unrecognized Error Code");
471 bgp_notify_subcode_str (char code
, char subcode
)
476 case BGP_NOTIFY_HEADER_ERR
:
477 return LOOKUP_DEF (bgp_notify_head_msg
, subcode
,
478 "Unrecognized Error Subcode");
479 case BGP_NOTIFY_OPEN_ERR
:
480 return LOOKUP_DEF (bgp_notify_open_msg
, subcode
,
481 "Unrecognized Error Subcode");
482 case BGP_NOTIFY_UPDATE_ERR
:
483 return LOOKUP_DEF (bgp_notify_update_msg
, subcode
,
484 "Unrecognized Error Subcode");
485 case BGP_NOTIFY_HOLD_ERR
:
487 case BGP_NOTIFY_FSM_ERR
:
489 case BGP_NOTIFY_CEASE
:
490 return LOOKUP_DEF (bgp_notify_cease_msg
, subcode
,
491 "Unrecognized Error Subcode");
492 case BGP_NOTIFY_CAPABILITY_ERR
:
493 return LOOKUP_DEF (bgp_notify_capability_msg
, subcode
,
494 "Unrecognized Error Subcode");
499 /* extract notify admin reason if correctly present */
501 bgp_notify_admin_message(char *buf
, size_t bufsz
, u_char
*data
, size_t datalen
)
503 if (!data
|| datalen
< 1)
506 u_char len
= data
[0];
508 || len
> datalen
- 1)
511 return zlog_sanitize(buf
, bufsz
, data
+ 1, len
);
514 /* dump notify packet */
516 bgp_notify_print(struct peer
*peer
, struct bgp_notify
*bgp_notify
,
519 const char *subcode_str
;
520 const char *code_str
;
521 const char *msg_str
= NULL
;
524 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
) || bgp_flag_check (peer
->bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
))
526 code_str
= bgp_notify_code_str(bgp_notify
->code
);
527 subcode_str
= bgp_notify_subcode_str(bgp_notify
->code
, bgp_notify
->subcode
);
529 if (bgp_notify
->code
== BGP_NOTIFY_CEASE
530 && (bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
531 || bgp_notify
->subcode
== BGP_NOTIFY_CEASE_ADMIN_RESET
))
533 msg_str
= bgp_notify_admin_message(msg_buf
, sizeof(msg_buf
),
534 bgp_notify
->raw_data
, bgp_notify
->length
);
539 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
540 strcmp (direct
, "received") == 0 ? "received from" : "sent to",
541 peer
->host
, bgp_notify
->code
, bgp_notify
->subcode
,
542 code_str
, subcode_str
, msg_str
);
546 msg_str
= bgp_notify
->data
? bgp_notify
->data
: "";
547 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
548 strcmp (direct
, "received") == 0 ? "received from" : "sent to",
549 peer
->host
, bgp_notify
->code
, bgp_notify
->subcode
,
550 code_str
, subcode_str
, bgp_notify
->length
, msg_str
);
556 bgp_debug_clear_updgrp_update_dbg(struct bgp
*bgp
)
559 bgp
= bgp_get_default();
560 update_group_walk (bgp
, update_group_clear_update_dbg
, NULL
);
564 /* Debug option setting interface. */
565 unsigned long bgp_debug_option
= 0;
568 debug (unsigned int option
)
570 return bgp_debug_option
& option
;
573 DEFUN (debug_bgp_as4
,
580 if (vty
->node
== CONFIG_NODE
)
584 TERM_DEBUG_ON (as4
, AS4
);
585 vty_out (vty
, "BGP as4 debugging is on%s", VTY_NEWLINE
);
590 DEFUN (no_debug_bgp_as4
,
591 no_debug_bgp_as4_cmd
,
598 if (vty
->node
== CONFIG_NODE
)
599 DEBUG_OFF (as4
, AS4
);
602 TERM_DEBUG_OFF (as4
, AS4
);
603 vty_out (vty
, "BGP as4 debugging is off%s", VTY_NEWLINE
);
608 DEFUN (debug_bgp_as4_segment
,
609 debug_bgp_as4_segment_cmd
,
610 "debug bgp as4 segment",
614 "BGP AS4 aspath segment handling\n")
616 if (vty
->node
== CONFIG_NODE
)
617 DEBUG_ON (as4
, AS4_SEGMENT
);
620 TERM_DEBUG_ON (as4
, AS4_SEGMENT
);
621 vty_out (vty
, "BGP as4 segment debugging is on%s", VTY_NEWLINE
);
626 DEFUN (no_debug_bgp_as4_segment
,
627 no_debug_bgp_as4_segment_cmd
,
628 "no debug bgp as4 segment",
633 "BGP AS4 aspath segment handling\n")
635 if (vty
->node
== CONFIG_NODE
)
636 DEBUG_OFF (as4
, AS4_SEGMENT
);
639 TERM_DEBUG_OFF (as4
, AS4_SEGMENT
);
640 vty_out (vty
, "BGP as4 segment debugging is off%s", VTY_NEWLINE
);
645 /* debug bgp neighbor_events */
646 DEFUN (debug_bgp_neighbor_events
,
647 debug_bgp_neighbor_events_cmd
,
648 "debug bgp neighbor-events",
651 "BGP Neighbor Events\n")
653 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
655 if (vty
->node
== CONFIG_NODE
)
656 DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
659 TERM_DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
660 vty_out (vty
, "BGP neighbor-events debugging is on%s", VTY_NEWLINE
);
665 DEFUN (debug_bgp_neighbor_events_peer
,
666 debug_bgp_neighbor_events_peer_cmd
,
667 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
670 "BGP Neighbor Events\n"
671 "BGP neighbor IP address to debug\n"
672 "BGP IPv6 neighbor to debug\n"
673 "BGP neighbor on interface to debug\n")
676 const char *host
= argv
[idx_peer
]->arg
;
678 if (!bgp_debug_neighbor_events_peers
)
679 bgp_debug_neighbor_events_peers
= list_new ();
681 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers
, host
, NULL
))
683 vty_out (vty
, "BGP neighbor-events debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
687 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
689 if (vty
->node
== CONFIG_NODE
)
690 DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
693 TERM_DEBUG_ON (neighbor_events
, NEIGHBOR_EVENTS
);
694 vty_out (vty
, "BGP neighbor-events debugging is on for %s%s", host
, VTY_NEWLINE
);
699 DEFUN (no_debug_bgp_neighbor_events
,
700 no_debug_bgp_neighbor_events_cmd
,
701 "no debug bgp neighbor-events",
707 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
709 if (vty
->node
== CONFIG_NODE
)
710 DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
713 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
714 vty_out (vty
, "BGP neighbor-events debugging is off%s", VTY_NEWLINE
);
719 DEFUN (no_debug_bgp_neighbor_events_peer
,
720 no_debug_bgp_neighbor_events_peer_cmd
,
721 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
726 "BGP neighbor IP address to debug\n"
727 "BGP IPv6 neighbor to debug\n"
728 "BGP neighbor on interface to debug\n")
732 const char *host
= argv
[idx_peer
]->arg
;
734 if (bgp_debug_neighbor_events_peers
&& !list_isempty(bgp_debug_neighbor_events_peers
))
736 found_peer
= bgp_debug_list_remove_entry(bgp_debug_neighbor_events_peers
, host
, NULL
);
738 if (list_isempty(bgp_debug_neighbor_events_peers
))
740 if (vty
->node
== CONFIG_NODE
)
741 DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
743 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
748 vty_out (vty
, "BGP neighbor-events debugging is off for %s%s", host
, VTY_NEWLINE
);
750 vty_out (vty
, "BGP neighbor-events debugging was not enabled for %s%s", host
, VTY_NEWLINE
);
756 DEFUN (debug_bgp_nht
,
761 "BGP nexthop tracking events\n")
763 if (vty
->node
== CONFIG_NODE
)
767 TERM_DEBUG_ON (nht
, NHT
);
768 vty_out (vty
, "BGP nexthop tracking debugging is on%s", VTY_NEWLINE
);
773 DEFUN (no_debug_bgp_nht
,
774 no_debug_bgp_nht_cmd
,
779 "BGP nexthop tracking events\n")
781 if (vty
->node
== CONFIG_NODE
)
782 DEBUG_OFF (nht
, NHT
);
785 TERM_DEBUG_OFF (nht
, NHT
);
786 vty_out (vty
, "BGP nexthop tracking debugging is off%s", VTY_NEWLINE
);
791 /* debug bgp keepalives */
792 DEFUN (debug_bgp_keepalive
,
793 debug_bgp_keepalive_cmd
,
794 "debug bgp keepalives",
799 bgp_debug_list_free(bgp_debug_keepalive_peers
);
801 if (vty
->node
== CONFIG_NODE
)
802 DEBUG_ON (keepalive
, KEEPALIVE
);
805 TERM_DEBUG_ON (keepalive
, KEEPALIVE
);
806 vty_out (vty
, "BGP keepalives debugging is on%s", VTY_NEWLINE
);
811 DEFUN (debug_bgp_keepalive_peer
,
812 debug_bgp_keepalive_peer_cmd
,
813 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
816 "BGP Neighbor Events\n"
817 "BGP neighbor IP address to debug\n"
818 "BGP IPv6 neighbor to debug\n"
819 "BGP neighbor on interface to debug\n")
822 const char *host
= argv
[idx_peer
]->arg
;
824 if (!bgp_debug_keepalive_peers
)
825 bgp_debug_keepalive_peers
= list_new ();
827 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers
, host
, NULL
))
829 vty_out (vty
, "BGP keepalive debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
833 bgp_debug_list_add_entry(bgp_debug_keepalive_peers
, host
, NULL
);
835 if (vty
->node
== CONFIG_NODE
)
836 DEBUG_ON (keepalive
, KEEPALIVE
);
839 TERM_DEBUG_ON (keepalive
, KEEPALIVE
);
840 vty_out (vty
, "BGP keepalives debugging is on for %s%s", host
, VTY_NEWLINE
);
845 DEFUN (no_debug_bgp_keepalive
,
846 no_debug_bgp_keepalive_cmd
,
847 "no debug bgp keepalives",
853 bgp_debug_list_free(bgp_debug_keepalive_peers
);
855 if (vty
->node
== CONFIG_NODE
)
856 DEBUG_OFF (keepalive
, KEEPALIVE
);
859 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
860 vty_out (vty
, "BGP keepalives debugging is off%s", VTY_NEWLINE
);
865 DEFUN (no_debug_bgp_keepalive_peer
,
866 no_debug_bgp_keepalive_peer_cmd
,
867 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
872 "BGP neighbor IP address to debug\n"
873 "BGP IPv6 neighbor to debug\n"
874 "BGP neighbor on interface to debug\n")
878 const char *host
= argv
[idx_peer
]->arg
;
880 if (bgp_debug_keepalive_peers
&& !list_isempty(bgp_debug_keepalive_peers
))
882 found_peer
= bgp_debug_list_remove_entry(bgp_debug_keepalive_peers
, host
, NULL
);
884 if (list_isempty(bgp_debug_keepalive_peers
))
886 if (vty
->node
== CONFIG_NODE
)
887 DEBUG_OFF (keepalive
, KEEPALIVE
);
889 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
894 vty_out (vty
, "BGP keepalives debugging is off for %s%s", host
, VTY_NEWLINE
);
896 vty_out (vty
, "BGP keepalives debugging was not enabled for %s%s", host
, VTY_NEWLINE
);
901 /* debug bgp bestpath */
902 DEFUN (debug_bgp_bestpath_prefix
,
903 debug_bgp_bestpath_prefix_cmd
,
904 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
912 int idx_ipv4_ipv6_prefixlen
= 3;
913 struct prefix
*argv_p
;
916 argv_p
= prefix_new();
917 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
921 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
926 if (!bgp_debug_bestpath_prefixes
)
927 bgp_debug_bestpath_prefixes
= list_new ();
929 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
))
931 vty_out (vty
, "BGP bestptah debugging is already enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
935 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
937 if (vty
->node
== CONFIG_NODE
)
939 DEBUG_ON (bestpath
, BESTPATH
);
943 TERM_DEBUG_ON (bestpath
, BESTPATH
);
944 vty_out (vty
, "BGP bestpath debugging is on for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
950 DEFUN (no_debug_bgp_bestpath_prefix
,
951 no_debug_bgp_bestpath_prefix_cmd
,
952 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
961 int idx_ipv4_ipv6_prefixlen
= 4;
962 struct prefix
*argv_p
;
963 int found_prefix
= 0;
966 argv_p
= prefix_new();
967 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
971 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
975 if (bgp_debug_bestpath_prefixes
&& !list_isempty(bgp_debug_bestpath_prefixes
))
977 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_bestpath_prefixes
, NULL
, argv_p
);
979 if (list_isempty(bgp_debug_bestpath_prefixes
))
981 if (vty
->node
== CONFIG_NODE
)
983 DEBUG_OFF (bestpath
, BESTPATH
);
987 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
988 vty_out (vty
, "BGP bestpath debugging (per prefix) is off%s", VTY_NEWLINE
);
994 vty_out (vty
, "BGP bestpath debugging is off for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
996 vty_out (vty
, "BGP bestpath debugging was not enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1001 DEFUN (no_debug_bgp_bestpath
,
1002 no_debug_bgp_bestpath_cmd
,
1003 "no debug bgp bestpath",
1009 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1011 if (vty
->node
== CONFIG_NODE
)
1012 DEBUG_OFF (bestpath
, BESTPATH
);
1015 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
1016 vty_out (vty
, "BGP bestpath debugging is off%s", VTY_NEWLINE
);
1021 /* debug bgp updates */
1022 DEFUN (debug_bgp_update
,
1023 debug_bgp_update_cmd
,
1024 "debug bgp updates",
1029 bgp_debug_list_free(bgp_debug_update_in_peers
);
1030 bgp_debug_list_free(bgp_debug_update_out_peers
);
1031 bgp_debug_list_free(bgp_debug_update_prefixes
);
1033 if (vty
->node
== CONFIG_NODE
)
1035 DEBUG_ON (update
, UPDATE_IN
);
1036 DEBUG_ON (update
, UPDATE_OUT
);
1040 TERM_DEBUG_ON (update
, UPDATE_IN
);
1041 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1042 vty_out (vty
, "BGP updates debugging is on%s", VTY_NEWLINE
);
1047 DEFUN (debug_bgp_update_direct
,
1048 debug_bgp_update_direct_cmd
,
1049 "debug bgp updates <in|out>",
1054 "Outbound updates\n")
1058 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1059 bgp_debug_list_free(bgp_debug_update_in_peers
);
1061 bgp_debug_list_free(bgp_debug_update_out_peers
);
1063 if (vty
->node
== CONFIG_NODE
)
1065 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1066 DEBUG_ON (update
, UPDATE_IN
);
1068 DEBUG_ON (update
, UPDATE_OUT
);
1072 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1074 TERM_DEBUG_ON (update
, UPDATE_IN
);
1075 vty_out (vty
, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE
);
1079 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1080 vty_out (vty
, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE
);
1086 DEFUN (debug_bgp_update_direct_peer
,
1087 debug_bgp_update_direct_peer_cmd
,
1088 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1093 "Outbound updates\n"
1094 "BGP neighbor IP address to debug\n"
1095 "BGP IPv6 neighbor to debug\n"
1096 "BGP neighbor on interface to debug\n")
1100 const char *host
= argv
[idx_peer
]->arg
;
1103 if (!bgp_debug_update_in_peers
)
1104 bgp_debug_update_in_peers
= list_new ();
1106 if (!bgp_debug_update_out_peers
)
1107 bgp_debug_update_out_peers
= list_new ();
1109 if (strncmp ("i", argv
[idx_in_out
]->arg
, 1) == 0)
1116 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers
, host
, NULL
))
1118 vty_out (vty
, "BGP inbound update debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
1125 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers
, host
, NULL
))
1127 vty_out (vty
, "BGP outbound update debugging is already enabled for %s%s", host
, VTY_NEWLINE
);
1133 bgp_debug_list_add_entry(bgp_debug_update_in_peers
, host
, NULL
);
1137 struct peer_af
*paf
;
1140 bgp_debug_list_add_entry(bgp_debug_update_out_peers
, host
, NULL
);
1141 peer
= bgp_find_peer (vty
, host
);
1145 for (afidx
= BGP_AF_START
; afidx
< BGP_AF_MAX
; afidx
++)
1147 paf
= peer
->peer_af_array
[afidx
];
1150 if (PAF_SUBGRP (paf
))
1152 UPDGRP_PEER_DBG_EN(PAF_SUBGRP(paf
)->update_group
);
1159 if (vty
->node
== CONFIG_NODE
)
1162 DEBUG_ON (update
, UPDATE_IN
);
1164 DEBUG_ON (update
, UPDATE_OUT
);
1170 TERM_DEBUG_ON (update
, UPDATE_IN
);
1171 vty_out (vty
, "BGP updates debugging is on (inbound) for %s%s", argv
[idx_peer
]->arg
, VTY_NEWLINE
);
1175 TERM_DEBUG_ON (update
, UPDATE_OUT
);
1176 vty_out (vty
, "BGP updates debugging is on (outbound) for %s%s", argv
[idx_peer
]->arg
, VTY_NEWLINE
);
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_out (vty
, "BGP updates debugging is off (inbound)%s", VTY_NEWLINE
);
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_out (vty
, "BGP updates debugging is off (outbound)%s", VTY_NEWLINE
);
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_out (vty
, "BGP updates debugging (inbound) is off%s", VTY_NEWLINE
);
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_out (vty
, "BGP updates debugging (outbound) is off%s", VTY_NEWLINE
);
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_out (vty
, "BGP updates debugging (inbound) is off for %s%s", host
, VTY_NEWLINE
);
1307 vty_out (vty
, "BGP updates debugging (outbound) is off for %s%s", host
, VTY_NEWLINE
);
1310 vty_out (vty
, "BGP updates debugging (inbound) was not enabled for %s%s", host
, VTY_NEWLINE
);
1312 vty_out (vty
, "BGP updates debugging (outbound) was not enabled for %s%s", host
, VTY_NEWLINE
);
1317 DEFUN (debug_bgp_update_prefix
,
1318 debug_bgp_update_prefix_cmd
,
1319 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1323 "Specify a prefix to debug\n"
1328 int idx_ipv4_ipv6_prefixlen
= 4;
1329 struct prefix
*argv_p
;
1332 argv_p
= prefix_new();
1333 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1336 prefix_free(argv_p
);
1337 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1342 if (!bgp_debug_update_prefixes
)
1343 bgp_debug_update_prefixes
= list_new ();
1345 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes
, NULL
, argv_p
))
1347 vty_out (vty
, "BGP updates debugging is already enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1351 bgp_debug_list_add_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1353 if (vty
->node
== CONFIG_NODE
)
1355 DEBUG_ON (update
, UPDATE_PREFIX
);
1359 TERM_DEBUG_ON (update
, UPDATE_PREFIX
);
1360 vty_out (vty
, "BGP updates debugging is on for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1366 DEFUN (no_debug_bgp_update_prefix
,
1367 no_debug_bgp_update_prefix_cmd
,
1368 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1373 "Specify a prefix to debug\n"
1378 int idx_ipv4_ipv6_prefixlen
= 5;
1379 struct prefix
*argv_p
;
1380 int found_prefix
= 0;
1383 argv_p
= prefix_new();
1384 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1387 prefix_free(argv_p
);
1388 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1392 if (bgp_debug_update_prefixes
&& !list_isempty(bgp_debug_update_prefixes
))
1394 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_update_prefixes
, NULL
, argv_p
);
1396 if (list_isempty(bgp_debug_update_prefixes
))
1398 if (vty
->node
== CONFIG_NODE
)
1400 DEBUG_OFF (update
, UPDATE_PREFIX
);
1404 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1405 vty_out (vty
, "BGP updates debugging (per prefix) is off%s", VTY_NEWLINE
);
1411 vty_out (vty
, "BGP updates debugging is off for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1413 vty_out (vty
, "BGP updates debugging was not enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1418 DEFUN (no_debug_bgp_update
,
1419 no_debug_bgp_update_cmd
,
1420 "no debug bgp updates",
1426 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1427 bgp_debug_list_free(bgp_debug_update_in_peers
);
1428 bgp_debug_list_free(bgp_debug_update_out_peers
);
1429 bgp_debug_list_free(bgp_debug_update_prefixes
);
1431 bgp_debug_clear_updgrp_update_dbg(bgp
);
1433 if (vty
->node
== CONFIG_NODE
)
1435 DEBUG_OFF (update
, UPDATE_IN
);
1436 DEBUG_OFF (update
, UPDATE_OUT
);
1437 DEBUG_OFF (update
, UPDATE_PREFIX
);
1441 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1442 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1443 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1444 vty_out (vty
, "BGP updates debugging is off%s", VTY_NEWLINE
);
1449 /* debug bgp zebra */
1450 DEFUN (debug_bgp_zebra
,
1451 debug_bgp_zebra_cmd
,
1455 "BGP Zebra messages\n")
1457 if (vty
->node
== CONFIG_NODE
)
1458 DEBUG_ON (zebra
, ZEBRA
);
1461 TERM_DEBUG_ON (zebra
, ZEBRA
);
1462 vty_out (vty
, "BGP zebra debugging is on%s", VTY_NEWLINE
);
1467 DEFUN (debug_bgp_zebra_prefix
,
1468 debug_bgp_zebra_prefix_cmd
,
1469 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1472 "BGP Zebra messages\n"
1473 "Specify a prefix to debug\n"
1478 int idx_ipv4_ipv6_prefixlen
= 4;
1479 struct prefix
*argv_p
;
1482 argv_p
= prefix_new();
1483 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1486 prefix_free(argv_p
);
1487 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1491 if (!bgp_debug_zebra_prefixes
)
1492 bgp_debug_zebra_prefixes
= list_new();
1494 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
))
1496 vty_out (vty
, "BGP zebra debugging is already enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1500 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1502 if (vty
->node
== CONFIG_NODE
)
1503 DEBUG_ON (zebra
, ZEBRA
);
1506 TERM_DEBUG_ON (zebra
, ZEBRA
);
1507 vty_out (vty
, "BGP zebra debugging is on for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1513 DEFUN (no_debug_bgp_zebra
,
1514 no_debug_bgp_zebra_cmd
,
1515 "no debug bgp zebra",
1519 "BGP Zebra messages\n")
1521 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1523 if (vty
->node
== CONFIG_NODE
)
1524 DEBUG_OFF (zebra
, ZEBRA
);
1527 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1528 vty_out (vty
, "BGP zebra debugging is off%s", VTY_NEWLINE
);
1533 DEFUN (no_debug_bgp_zebra_prefix
,
1534 no_debug_bgp_zebra_prefix_cmd
,
1535 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1539 "BGP Zebra messages\n"
1540 "Specify a prefix to debug\n"
1545 int idx_ipv4_ipv6_prefixlen
= 5;
1546 struct prefix
*argv_p
;
1547 int found_prefix
= 0;
1550 argv_p
= prefix_new();
1551 ret
= str2prefix (argv
[idx_ipv4_ipv6_prefixlen
]->arg
, argv_p
);
1554 prefix_free(argv_p
);
1555 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1559 if (bgp_debug_zebra_prefixes
&& !list_isempty(bgp_debug_zebra_prefixes
))
1561 found_prefix
= bgp_debug_list_remove_entry(bgp_debug_zebra_prefixes
, NULL
, argv_p
);
1563 if (list_isempty(bgp_debug_zebra_prefixes
))
1565 if (vty
->node
== CONFIG_NODE
)
1566 DEBUG_OFF (zebra
, ZEBRA
);
1569 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1570 vty_out (vty
, "BGP zebra debugging is off%s", VTY_NEWLINE
);
1576 vty_out (vty
, "BGP zebra debugging is off for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1578 vty_out (vty
, "BGP zebra debugging was not enabled for %s%s", argv
[idx_ipv4_ipv6_prefixlen
]->arg
, VTY_NEWLINE
);
1583 DEFUN (debug_bgp_allow_martians
,
1584 debug_bgp_allow_martians_cmd
,
1585 "debug bgp allow-martians",
1588 "BGP allow martian next hops\n")
1590 if (vty
->node
== CONFIG_NODE
)
1591 DEBUG_ON (allow_martians
, ALLOW_MARTIANS
);
1594 TERM_DEBUG_ON (allow_martians
, ALLOW_MARTIANS
);
1595 vty_out (vty
, "BGP allow_martian next hop debugging is on%s", VTY_NEWLINE
);
1600 DEFUN (no_debug_bgp_allow_martians
,
1601 no_debug_bgp_allow_martians_cmd
,
1602 "no debug bgp allow-martians",
1606 "BGP allow martian next hops\n")
1608 if (vty
->node
== CONFIG_NODE
)
1609 DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1612 TERM_DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1613 vty_out (vty
, "BGP allow martian next hop debugging is off%s", VTY_NEWLINE
);
1619 /* debug bgp update-groups */
1620 DEFUN (debug_bgp_update_groups
,
1621 debug_bgp_update_groups_cmd
,
1622 "debug bgp update-groups",
1625 "BGP update-groups\n")
1627 if (vty
->node
== CONFIG_NODE
)
1628 DEBUG_ON (update_groups
, UPDATE_GROUPS
);
1631 TERM_DEBUG_ON (update_groups
, UPDATE_GROUPS
);
1632 vty_out (vty
, "BGP update-groups debugging is on%s", VTY_NEWLINE
);
1637 DEFUN (no_debug_bgp_update_groups
,
1638 no_debug_bgp_update_groups_cmd
,
1639 "no debug bgp update-groups",
1643 "BGP update-groups\n")
1645 if (vty
->node
== CONFIG_NODE
)
1646 DEBUG_OFF (update_groups
, UPDATE_GROUPS
);
1649 TERM_DEBUG_OFF (update_groups
, UPDATE_GROUPS
);
1650 vty_out (vty
, "BGP update-groups debugging is off%s", VTY_NEWLINE
);
1655 DEFUN (no_debug_bgp
,
1662 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1663 bgp_debug_list_free(bgp_debug_neighbor_events_peers
);
1664 bgp_debug_list_free(bgp_debug_keepalive_peers
);
1665 bgp_debug_list_free(bgp_debug_update_in_peers
);
1666 bgp_debug_list_free(bgp_debug_update_out_peers
);
1667 bgp_debug_list_free(bgp_debug_update_prefixes
);
1668 bgp_debug_list_free(bgp_debug_bestpath_prefixes
);
1669 bgp_debug_list_free(bgp_debug_zebra_prefixes
);
1671 bgp_debug_clear_updgrp_update_dbg(bgp
);
1673 TERM_DEBUG_OFF (keepalive
, KEEPALIVE
);
1674 TERM_DEBUG_OFF (update
, UPDATE_IN
);
1675 TERM_DEBUG_OFF (update
, UPDATE_OUT
);
1676 TERM_DEBUG_OFF (update
, UPDATE_PREFIX
);
1677 TERM_DEBUG_OFF (bestpath
, BESTPATH
);
1678 TERM_DEBUG_OFF (as4
, AS4
);
1679 TERM_DEBUG_OFF (as4
, AS4_SEGMENT
);
1680 TERM_DEBUG_OFF (neighbor_events
, NEIGHBOR_EVENTS
);
1681 TERM_DEBUG_OFF (zebra
, ZEBRA
);
1682 TERM_DEBUG_OFF (allow_martians
, ALLOW_MARTIANS
);
1683 vty_out (vty
, "All possible debugging has been turned off%s", VTY_NEWLINE
);
1688 DEFUN (show_debugging_bgp
,
1689 show_debugging_bgp_cmd
,
1690 "show debugging bgp",
1695 vty_out (vty
, "BGP debugging status:%s", VTY_NEWLINE
);
1697 if (BGP_DEBUG (as4
, AS4
))
1698 vty_out (vty
, " BGP as4 debugging is on%s", VTY_NEWLINE
);
1700 if (BGP_DEBUG (as4
, AS4_SEGMENT
))
1701 vty_out (vty
, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE
);
1703 if (BGP_DEBUG (bestpath
, BESTPATH
))
1704 bgp_debug_list_print (vty
, " BGP bestpath debugging is on",
1705 bgp_debug_bestpath_prefixes
);
1707 if (BGP_DEBUG (keepalive
, KEEPALIVE
))
1708 bgp_debug_list_print (vty
, " BGP keepalives debugging is on",
1709 bgp_debug_keepalive_peers
);
1711 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1712 bgp_debug_list_print (vty
, " BGP neighbor-events debugging is on",
1713 bgp_debug_neighbor_events_peers
);
1715 if (BGP_DEBUG (nht
, NHT
))
1716 vty_out (vty
, " BGP next-hop tracking debugging is on%s", VTY_NEWLINE
);
1718 if (BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1719 vty_out (vty
, " BGP update-groups debugging is on%s", VTY_NEWLINE
);
1721 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
1722 bgp_debug_list_print (vty
, " BGP updates debugging is on",
1723 bgp_debug_update_prefixes
);
1725 if (BGP_DEBUG (update
, UPDATE_IN
))
1726 bgp_debug_list_print (vty
, " BGP updates debugging is on (inbound)",
1727 bgp_debug_update_in_peers
);
1729 if (BGP_DEBUG (update
, UPDATE_OUT
))
1730 bgp_debug_list_print (vty
, " BGP updates debugging is on (outbound)",
1731 bgp_debug_update_out_peers
);
1733 if (BGP_DEBUG (zebra
, ZEBRA
))
1734 bgp_debug_list_print (vty
, " BGP zebra debugging is on",
1735 bgp_debug_zebra_prefixes
);
1737 if (BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1738 vty_out (vty
, " BGP allow martian next hop debugging is on%s", VTY_NEWLINE
);
1739 vty_out (vty
, "%s", VTY_NEWLINE
);
1743 /* return count of number of debug flags set */
1745 bgp_debug_count(void)
1748 if (BGP_DEBUG (as4
, AS4
))
1751 if (BGP_DEBUG (as4
, AS4_SEGMENT
))
1754 if (BGP_DEBUG (bestpath
, BESTPATH
))
1757 if (BGP_DEBUG (keepalive
, KEEPALIVE
))
1760 if (BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1763 if (BGP_DEBUG (nht
, NHT
))
1766 if (BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1769 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
1772 if (BGP_DEBUG (update
, UPDATE_IN
))
1775 if (BGP_DEBUG (update
, UPDATE_OUT
))
1778 if (BGP_DEBUG (zebra
, ZEBRA
))
1781 if (BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1788 bgp_config_write_debug (struct vty
*vty
)
1792 if (CONF_BGP_DEBUG (as4
, AS4
))
1794 vty_out (vty
, "debug bgp as4%s", VTY_NEWLINE
);
1798 if (CONF_BGP_DEBUG (as4
, AS4_SEGMENT
))
1800 vty_out (vty
, "debug bgp as4 segment%s", VTY_NEWLINE
);
1804 if (CONF_BGP_DEBUG (bestpath
, BESTPATH
))
1806 write
+= bgp_debug_list_conf_print (vty
, "debug bgp bestpath",
1807 bgp_debug_bestpath_prefixes
);
1810 if (CONF_BGP_DEBUG (keepalive
, KEEPALIVE
))
1812 write
+= bgp_debug_list_conf_print (vty
, "debug bgp keepalives",
1813 bgp_debug_keepalive_peers
);
1816 if (CONF_BGP_DEBUG (neighbor_events
, NEIGHBOR_EVENTS
))
1818 write
+= bgp_debug_list_conf_print (vty
, "debug bgp neighbor-events",
1819 bgp_debug_neighbor_events_peers
);
1822 if (CONF_BGP_DEBUG (nht
, NHT
))
1824 vty_out (vty
, "debug bgp nht%s", VTY_NEWLINE
);
1828 if (CONF_BGP_DEBUG (update_groups
, UPDATE_GROUPS
))
1830 vty_out (vty
, "debug bgp update-groups%s", VTY_NEWLINE
);
1834 if (CONF_BGP_DEBUG (update
, UPDATE_PREFIX
))
1836 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates prefix",
1837 bgp_debug_update_prefixes
);
1840 if (CONF_BGP_DEBUG (update
, UPDATE_IN
))
1842 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates in",
1843 bgp_debug_update_in_peers
);
1846 if (CONF_BGP_DEBUG (update
, UPDATE_OUT
))
1848 write
+= bgp_debug_list_conf_print (vty
, "debug bgp updates out",
1849 bgp_debug_update_out_peers
);
1852 if (CONF_BGP_DEBUG (zebra
, ZEBRA
))
1854 if (!bgp_debug_zebra_prefixes
|| list_isempty(bgp_debug_zebra_prefixes
))
1856 vty_out (vty
, "debug bgp zebra%s", VTY_NEWLINE
);
1861 write
+= bgp_debug_list_conf_print (vty
, "debug bgp zebra prefix",
1862 bgp_debug_zebra_prefixes
);
1866 if (CONF_BGP_DEBUG (allow_martians
, ALLOW_MARTIANS
))
1868 vty_out (vty
, "debug bgp allow-martians%s", VTY_NEWLINE
);
1875 static struct cmd_node debug_node
=
1883 bgp_debug_init (void)
1885 install_node (&debug_node
, bgp_config_write_debug
);
1887 install_element (ENABLE_NODE
, &show_debugging_bgp_cmd
);
1889 install_element (ENABLE_NODE
, &debug_bgp_as4_cmd
);
1890 install_element (CONFIG_NODE
, &debug_bgp_as4_cmd
);
1891 install_element (ENABLE_NODE
, &debug_bgp_as4_segment_cmd
);
1892 install_element (CONFIG_NODE
, &debug_bgp_as4_segment_cmd
);
1894 install_element (ENABLE_NODE
, &debug_bgp_neighbor_events_cmd
);
1895 install_element (CONFIG_NODE
, &debug_bgp_neighbor_events_cmd
);
1896 install_element (ENABLE_NODE
, &debug_bgp_nht_cmd
);
1897 install_element (CONFIG_NODE
, &debug_bgp_nht_cmd
);
1898 install_element (ENABLE_NODE
, &debug_bgp_keepalive_cmd
);
1899 install_element (CONFIG_NODE
, &debug_bgp_keepalive_cmd
);
1900 install_element (ENABLE_NODE
, &debug_bgp_update_cmd
);
1901 install_element (CONFIG_NODE
, &debug_bgp_update_cmd
);
1902 install_element (ENABLE_NODE
, &debug_bgp_zebra_cmd
);
1903 install_element (CONFIG_NODE
, &debug_bgp_zebra_cmd
);
1904 install_element (ENABLE_NODE
, &debug_bgp_allow_martians_cmd
);
1905 install_element (CONFIG_NODE
, &debug_bgp_allow_martians_cmd
);
1906 install_element (ENABLE_NODE
, &debug_bgp_update_groups_cmd
);
1907 install_element (CONFIG_NODE
, &debug_bgp_update_groups_cmd
);
1908 install_element (ENABLE_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1909 install_element (CONFIG_NODE
, &debug_bgp_bestpath_prefix_cmd
);
1911 /* debug bgp updates (in|out) */
1912 install_element (ENABLE_NODE
, &debug_bgp_update_direct_cmd
);
1913 install_element (CONFIG_NODE
, &debug_bgp_update_direct_cmd
);
1914 install_element (ENABLE_NODE
, &no_debug_bgp_update_direct_cmd
);
1915 install_element (CONFIG_NODE
, &no_debug_bgp_update_direct_cmd
);
1917 /* debug bgp updates (in|out) A.B.C.D */
1918 install_element (ENABLE_NODE
, &debug_bgp_update_direct_peer_cmd
);
1919 install_element (CONFIG_NODE
, &debug_bgp_update_direct_peer_cmd
);
1920 install_element (ENABLE_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1921 install_element (CONFIG_NODE
, &no_debug_bgp_update_direct_peer_cmd
);
1923 /* debug bgp updates prefix A.B.C.D/M */
1924 install_element (ENABLE_NODE
, &debug_bgp_update_prefix_cmd
);
1925 install_element (CONFIG_NODE
, &debug_bgp_update_prefix_cmd
);
1926 install_element (ENABLE_NODE
, &no_debug_bgp_update_prefix_cmd
);
1927 install_element (CONFIG_NODE
, &no_debug_bgp_update_prefix_cmd
);
1929 /* debug bgp zebra prefix A.B.C.D/M */
1930 install_element (ENABLE_NODE
, &debug_bgp_zebra_prefix_cmd
);
1931 install_element (CONFIG_NODE
, &debug_bgp_zebra_prefix_cmd
);
1932 install_element (ENABLE_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1933 install_element (CONFIG_NODE
, &no_debug_bgp_zebra_prefix_cmd
);
1935 install_element (ENABLE_NODE
, &no_debug_bgp_as4_cmd
);
1936 install_element (CONFIG_NODE
, &no_debug_bgp_as4_cmd
);
1937 install_element (ENABLE_NODE
, &no_debug_bgp_as4_segment_cmd
);
1938 install_element (CONFIG_NODE
, &no_debug_bgp_as4_segment_cmd
);
1940 /* debug bgp neighbor-events A.B.C.D */
1941 install_element (ENABLE_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1942 install_element (CONFIG_NODE
, &debug_bgp_neighbor_events_peer_cmd
);
1943 install_element (ENABLE_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1944 install_element (CONFIG_NODE
, &no_debug_bgp_neighbor_events_peer_cmd
);
1946 /* debug bgp keepalive A.B.C.D */
1947 install_element (ENABLE_NODE
, &debug_bgp_keepalive_peer_cmd
);
1948 install_element (CONFIG_NODE
, &debug_bgp_keepalive_peer_cmd
);
1949 install_element (ENABLE_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1950 install_element (CONFIG_NODE
, &no_debug_bgp_keepalive_peer_cmd
);
1952 install_element (ENABLE_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1953 install_element (CONFIG_NODE
, &no_debug_bgp_neighbor_events_cmd
);
1954 install_element (ENABLE_NODE
, &no_debug_bgp_nht_cmd
);
1955 install_element (CONFIG_NODE
, &no_debug_bgp_nht_cmd
);
1956 install_element (ENABLE_NODE
, &no_debug_bgp_keepalive_cmd
);
1957 install_element (CONFIG_NODE
, &no_debug_bgp_keepalive_cmd
);
1958 install_element (ENABLE_NODE
, &no_debug_bgp_update_cmd
);
1959 install_element (CONFIG_NODE
, &no_debug_bgp_update_cmd
);
1960 install_element (ENABLE_NODE
, &no_debug_bgp_zebra_cmd
);
1961 install_element (CONFIG_NODE
, &no_debug_bgp_zebra_cmd
);
1962 install_element (ENABLE_NODE
, &no_debug_bgp_allow_martians_cmd
);
1963 install_element (CONFIG_NODE
, &no_debug_bgp_allow_martians_cmd
);
1964 install_element (ENABLE_NODE
, &no_debug_bgp_update_groups_cmd
);
1965 install_element (CONFIG_NODE
, &no_debug_bgp_update_groups_cmd
);
1966 install_element (ENABLE_NODE
, &no_debug_bgp_cmd
);
1967 install_element (ENABLE_NODE
, &no_debug_bgp_bestpath_cmd
);
1968 install_element (CONFIG_NODE
, &no_debug_bgp_bestpath_cmd
);
1969 install_element (ENABLE_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1970 install_element (CONFIG_NODE
, &no_debug_bgp_bestpath_prefix_cmd
);
1973 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
1974 * for BGP_DEBUG_TYPE
1977 bgp_debug_per_prefix (struct prefix
*p
, unsigned long term_bgp_debug_type
,
1978 unsigned int BGP_DEBUG_TYPE
, struct list
*per_prefix_list
)
1980 struct bgp_debug_filter
*filter
;
1981 struct listnode
*node
, *nnode
;
1983 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
)
1985 /* We are debugging all prefixes so return true */
1986 if (!per_prefix_list
|| list_isempty(per_prefix_list
))
1994 for (ALL_LIST_ELEMENTS (per_prefix_list
, node
, nnode
, filter
))
1995 if (filter
->p
->prefixlen
== p
->prefixlen
&& prefix_match(filter
->p
, p
))
2005 /* Return true if this peer is on the per_peer_list of peers to debug
2006 * for BGP_DEBUG_TYPE
2009 bgp_debug_per_peer(char *host
, unsigned long term_bgp_debug_type
,
2010 unsigned int BGP_DEBUG_TYPE
, struct list
*per_peer_list
)
2012 struct bgp_debug_filter
*filter
;
2013 struct listnode
*node
, *nnode
;
2015 if (term_bgp_debug_type
& BGP_DEBUG_TYPE
)
2017 /* We are debugging all peers so return true */
2018 if (!per_peer_list
|| list_isempty(per_peer_list
))
2026 for (ALL_LIST_ELEMENTS (per_peer_list
, node
, nnode
, filter
))
2027 if (strcmp (filter
->host
, host
) == 0)
2038 bgp_debug_neighbor_events (struct peer
*peer
)
2045 return bgp_debug_per_peer (host
,
2046 term_bgp_debug_neighbor_events
,
2047 BGP_DEBUG_NEIGHBOR_EVENTS
,
2048 bgp_debug_neighbor_events_peers
);
2052 bgp_debug_keepalive (struct peer
*peer
)
2059 return bgp_debug_per_peer (host
,
2060 term_bgp_debug_keepalive
,
2061 BGP_DEBUG_KEEPALIVE
,
2062 bgp_debug_keepalive_peers
);
2066 bgp_debug_update (struct peer
*peer
, struct prefix
*p
,
2067 struct update_group
*updgrp
, unsigned int inbound
)
2076 if (bgp_debug_per_peer (host
, term_bgp_debug_update
, BGP_DEBUG_UPDATE_IN
,
2077 bgp_debug_update_in_peers
))
2084 if (bgp_debug_per_peer (host
, term_bgp_debug_update
,
2085 BGP_DEBUG_UPDATE_OUT
,
2086 bgp_debug_update_out_peers
))
2089 /* Check if update debugging implicitly enabled for the group. */
2090 if (updgrp
&& UPDGRP_DBG_ON(updgrp
))
2095 if (BGP_DEBUG (update
, UPDATE_PREFIX
))
2097 if (bgp_debug_per_prefix (p
, term_bgp_debug_update
,
2098 BGP_DEBUG_UPDATE_PREFIX
,
2099 bgp_debug_update_prefixes
))
2107 bgp_debug_bestpath (struct prefix
*p
)
2109 if (BGP_DEBUG (bestpath
, BESTPATH
))
2111 if (bgp_debug_per_prefix (p
, term_bgp_debug_bestpath
,
2113 bgp_debug_bestpath_prefixes
))
2121 bgp_debug_zebra (struct prefix
*p
)
2123 if (BGP_DEBUG (zebra
, ZEBRA
))
2125 if (bgp_debug_per_prefix (p
, term_bgp_debug_zebra
, BGP_DEBUG_ZEBRA
,
2126 bgp_debug_zebra_prefixes
))
2134 bgp_debug_rdpfxpath2str (struct prefix_rd
*prd
, union prefixconstptr pu
,
2135 int addpath_valid
, u_int32_t addpath_id
,
2136 char *str
, int size
)
2138 char rd_buf
[RD_ADDRSTRLEN
];
2139 char pfx_buf
[PREFIX_STRLEN
];
2140 /* ' with addpath ID ' 17
2141 * max strlen of uint32 + 10
2142 * +/- (just in case) + 1
2143 * null terminator + 1
2144 * ============================ 29 */
2145 char pathid_buf
[30];
2147 if (size
< BGP_PRD_PATH_STRLEN
)
2150 /* Note: Path-id is created by default, but only included in update sometimes. */
2151 pathid_buf
[0] = '\0';
2153 snprintf(pathid_buf
, sizeof(pathid_buf
), " with addpath ID %u", addpath_id
);
2156 snprintf (str
, size
, "RD %s %s%s",
2157 prefix_rd2str(prd
, rd_buf
, sizeof (rd_buf
)),
2158 prefix2str (pu
, pfx_buf
, sizeof (pfx_buf
)), pathid_buf
);
2160 snprintf (str
, size
, "%s%s",
2161 prefix2str (pu
, pfx_buf
, sizeof (pfx_buf
)), pathid_buf
);