]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* BGP-4, BGP-4+ packet debug routine |
2 | Copyright (C) 1996, 97, 99 Kunihiro Ishiguro | |
3 | ||
4 | This file is part of GNU Zebra. | |
5 | ||
6 | GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by the | |
8 | Free Software Foundation; either version 2, or (at your option) any | |
9 | later version. | |
10 | ||
11 | GNU Zebra is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
20 | ||
21 | #include <zebra.h> | |
22 | ||
5e4fa164 | 23 | #include <lib/version.h> |
718e3744 | 24 | #include "prefix.h" |
25 | #include "linklist.h" | |
26 | #include "stream.h" | |
27 | #include "command.h" | |
28 | #include "str.h" | |
29 | #include "log.h" | |
30 | #include "sockunion.h" | |
16286195 | 31 | #include "memory.h" |
3f9c7369 | 32 | #include "queue.h" |
039f3a34 | 33 | #include "filter.h" |
718e3744 | 34 | |
35 | #include "bgpd/bgpd.h" | |
36 | #include "bgpd/bgp_aspath.h" | |
37 | #include "bgpd/bgp_route.h" | |
38 | #include "bgpd/bgp_attr.h" | |
39 | #include "bgpd/bgp_debug.h" | |
40 | #include "bgpd/bgp_community.h" | |
3f9c7369 | 41 | #include "bgpd/bgp_updgrp.h" |
718e3744 | 42 | |
0b2aa3a0 | 43 | unsigned long conf_bgp_debug_as4; |
16286195 | 44 | unsigned long conf_bgp_debug_neighbor_events; |
718e3744 | 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; | |
9fbdd100 | 50 | unsigned long conf_bgp_debug_bestpath; |
a39275d7 | 51 | unsigned long conf_bgp_debug_zebra; |
cebb7440 | 52 | unsigned long conf_bgp_debug_allow_martians; |
fb018d25 | 53 | unsigned long conf_bgp_debug_nht; |
3f9c7369 | 54 | unsigned long conf_bgp_debug_update_groups; |
718e3744 | 55 | |
0b2aa3a0 | 56 | unsigned long term_bgp_debug_as4; |
16286195 | 57 | unsigned long term_bgp_debug_neighbor_events; |
718e3744 | 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; | |
9fbdd100 | 63 | unsigned long term_bgp_debug_bestpath; |
a39275d7 | 64 | unsigned long term_bgp_debug_zebra; |
cebb7440 | 65 | unsigned long term_bgp_debug_allow_martians; |
fb018d25 | 66 | unsigned long term_bgp_debug_nht; |
3f9c7369 | 67 | unsigned long term_bgp_debug_update_groups; |
718e3744 | 68 | |
16286195 DS |
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; | |
9fbdd100 | 74 | struct list *bgp_debug_bestpath_prefixes = NULL; |
16286195 DS |
75 | struct list *bgp_debug_zebra_prefixes = NULL; |
76 | ||
718e3744 | 77 | /* messages for BGP-4 status */ |
b2d933f8 | 78 | const struct message bgp_status_msg[] = |
718e3744 | 79 | { |
718e3744 | 80 | { Idle, "Idle" }, |
81 | { Connect, "Connect" }, | |
82 | { Active, "Active" }, | |
83 | { OpenSent, "OpenSent" }, | |
84 | { OpenConfirm, "OpenConfirm" }, | |
85 | { Established, "Established" }, | |
ca058a30 PJ |
86 | { Clearing, "Clearing" }, |
87 | { Deleted, "Deleted" }, | |
718e3744 | 88 | }; |
b2d933f8 | 89 | const int bgp_status_msg_max = BGP_STATUS_MAX; |
718e3744 | 90 | |
91 | /* BGP message type string. */ | |
fd79ac91 | 92 | const char *bgp_type_str[] = |
718e3744 | 93 | { |
94 | NULL, | |
95 | "OPEN", | |
96 | "UPDATE", | |
97 | "NOTIFICATION", | |
98 | "KEEPALIVE", | |
99 | "ROUTE-REFRESH", | |
100 | "CAPABILITY" | |
101 | }; | |
102 | ||
103 | /* message for BGP-4 Notify */ | |
b2d933f8 | 104 | static const struct message bgp_notify_msg[] = |
718e3744 | 105 | { |
718e3744 | 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"}, | |
16286195 | 110 | { BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"}, |
718e3744 | 111 | { BGP_NOTIFY_CEASE, "Cease"}, |
112 | { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"}, | |
113 | }; | |
b2d933f8 | 114 | static const int bgp_notify_msg_max = BGP_NOTIFY_MAX; |
718e3744 | 115 | |
b2d933f8 | 116 | static const struct message bgp_notify_head_msg[] = |
718e3744 | 117 | { |
3950fda5 | 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"} | |
718e3744 | 121 | }; |
b2d933f8 | 122 | static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX; |
718e3744 | 123 | |
b2d933f8 | 124 | static const struct message bgp_notify_open_msg[] = |
718e3744 | 125 | { |
4b4e07d2 | 126 | { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, |
3950fda5 | 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"}, | |
718e3744 | 134 | }; |
b2d933f8 | 135 | static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX; |
718e3744 | 136 | |
b2d933f8 | 137 | static const struct message bgp_notify_update_msg[] = |
718e3744 | 138 | { |
4b4e07d2 | 139 | { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, |
3950fda5 | 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"}, | |
718e3744 | 151 | }; |
b2d933f8 | 152 | static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX; |
718e3744 | 153 | |
b2d933f8 | 154 | static const struct message bgp_notify_cease_msg[] = |
718e3744 | 155 | { |
4b4e07d2 | 156 | { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, |
3950fda5 | 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"}, | |
718e3744 | 165 | }; |
b2d933f8 | 166 | static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX; |
718e3744 | 167 | |
b2d933f8 | 168 | static const struct message bgp_notify_capability_msg[] = |
718e3744 | 169 | { |
4b4e07d2 | 170 | { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, |
3950fda5 | 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"}, | |
718e3744 | 174 | }; |
b2d933f8 | 175 | static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX; |
718e3744 | 176 | |
177 | /* Origin strings. */ | |
fd79ac91 | 178 | const char *bgp_origin_str[] = {"i","e","?"}; |
179 | const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"}; | |
718e3744 | 180 | |
16286195 DS |
181 | |
182 | /* Given a string return a pointer the corresponding peer structure */ | |
183 | static struct peer * | |
184 | bgp_find_peer (struct vty *vty, const char *peer_str) | |
185 | { | |
186 | int ret; | |
187 | union sockunion su; | |
188 | struct bgp *bgp; | |
04b6bdc0 | 189 | struct peer *peer; |
16286195 DS |
190 | |
191 | bgp = vty->index; | |
192 | ret = str2sockunion (peer_str, &su); | |
193 | ||
194 | /* 'swpX' string */ | |
195 | if (ret < 0) | |
6410e93a | 196 | { |
04b6bdc0 DW |
197 | peer = peer_lookup_by_conf_if (bgp, peer_str); |
198 | ||
199 | if (!peer) | |
200 | peer = peer_lookup_by_hostname (bgp, peer_str); | |
201 | ||
202 | return peer; | |
6410e93a | 203 | } |
16286195 DS |
204 | else |
205 | return peer_lookup (bgp, &su); | |
206 | } | |
207 | ||
208 | static void | |
209 | bgp_debug_list_free(struct list *list) | |
210 | { | |
211 | struct bgp_debug_filter *filter; | |
212 | struct listnode *node, *nnode; | |
213 | ||
214 | if (list) | |
215 | for (ALL_LIST_ELEMENTS (list, node, nnode, filter)) | |
216 | { | |
217 | listnode_delete (list, filter); | |
218 | ||
219 | if (filter->p) | |
220 | prefix_free(filter->p); | |
221 | ||
167d390a | 222 | if (filter->host) |
6e919709 | 223 | XFREE (MTYPE_BGP_DEBUG_STR, filter->host); |
16286195 DS |
224 | |
225 | XFREE (MTYPE_BGP_DEBUG_FILTER, filter); | |
226 | } | |
227 | } | |
228 | ||
229 | /* Print the desc along with a list of peers/prefixes this debug is | |
230 | * enabled for */ | |
231 | static void | |
232 | bgp_debug_list_print (struct vty *vty, const char *desc, struct list *list) | |
233 | { | |
234 | struct bgp_debug_filter *filter; | |
235 | struct listnode *node, *nnode; | |
236 | char buf[INET6_ADDRSTRLEN]; | |
237 | ||
238 | vty_out (vty, "%s", desc); | |
239 | ||
240 | if (list && !list_isempty(list)) | |
241 | { | |
242 | vty_out (vty, " for"); | |
243 | for (ALL_LIST_ELEMENTS (list, node, nnode, filter)) | |
244 | { | |
167d390a DS |
245 | if (filter->host) |
246 | vty_out (vty, " %s", filter->host); | |
16286195 DS |
247 | |
248 | if (filter->p) | |
249 | vty_out (vty, " %s/%d", | |
250 | inet_ntop (filter->p->family, &filter->p->u.prefix, buf, INET6_ADDRSTRLEN), | |
251 | filter->p->prefixlen); | |
252 | } | |
253 | } | |
254 | ||
255 | vty_out (vty, "%s", VTY_NEWLINE); | |
256 | } | |
257 | ||
91ba2c8b DS |
258 | /* Print the command to enable the debug for each peer/prefix this debug is |
259 | * enabled for | |
260 | */ | |
261 | static int | |
262 | bgp_debug_list_conf_print (struct vty *vty, const char *desc, struct list *list) | |
263 | { | |
264 | struct bgp_debug_filter *filter; | |
265 | struct listnode *node, *nnode; | |
266 | char buf[INET6_ADDRSTRLEN]; | |
267 | int write = 0; | |
268 | ||
269 | if (list && !list_isempty(list)) | |
270 | { | |
271 | for (ALL_LIST_ELEMENTS (list, node, nnode, filter)) | |
272 | { | |
167d390a | 273 | if (filter->host) |
91ba2c8b | 274 | { |
167d390a | 275 | vty_out (vty, "%s %s%s", desc, filter->host, VTY_NEWLINE); |
91ba2c8b DS |
276 | write++; |
277 | } | |
278 | ||
279 | ||
280 | if (filter->p) | |
281 | { | |
282 | vty_out (vty, "%s %s/%d%s", desc, | |
283 | inet_ntop (filter->p->family, &filter->p->u.prefix, buf, INET6_ADDRSTRLEN), | |
284 | filter->p->prefixlen, VTY_NEWLINE); | |
285 | write++; | |
286 | } | |
287 | } | |
288 | } | |
289 | ||
290 | if (!write) | |
291 | { | |
292 | vty_out (vty, "%s%s", desc, VTY_NEWLINE); | |
293 | write++; | |
294 | } | |
295 | ||
296 | return write; | |
297 | } | |
298 | ||
16286195 | 299 | static void |
ffd0c037 | 300 | bgp_debug_list_add_entry(struct list *list, const char *host, struct prefix *p) |
16286195 DS |
301 | { |
302 | struct bgp_debug_filter *filter; | |
303 | ||
304 | filter = XCALLOC (MTYPE_BGP_DEBUG_FILTER, sizeof (struct bgp_debug_filter)); | |
305 | ||
167d390a | 306 | if (host) |
16286195 | 307 | { |
6e919709 | 308 | filter->host = XSTRDUP (MTYPE_BGP_DEBUG_STR, host); |
16286195 DS |
309 | filter->p = NULL; |
310 | } | |
311 | else if (p) | |
312 | { | |
167d390a | 313 | filter->host = NULL; |
16286195 DS |
314 | filter->p = p; |
315 | } | |
316 | ||
317 | listnode_add(list, filter); | |
318 | } | |
319 | ||
320 | static int | |
ffd0c037 | 321 | bgp_debug_list_remove_entry(struct list *list, const char *host, struct prefix *p) |
16286195 DS |
322 | { |
323 | struct bgp_debug_filter *filter; | |
324 | struct listnode *node, *nnode; | |
325 | ||
326 | for (ALL_LIST_ELEMENTS (list, node, nnode, filter)) | |
327 | { | |
167d390a | 328 | if (host && strcmp (filter->host, host) == 0) |
16286195 DS |
329 | { |
330 | listnode_delete (list, filter); | |
6e919709 | 331 | XFREE (MTYPE_BGP_DEBUG_STR, filter->host); |
16286195 DS |
332 | XFREE (MTYPE_BGP_DEBUG_FILTER, filter); |
333 | return 1; | |
334 | } | |
335 | else if (p && filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p)) | |
336 | { | |
337 | listnode_delete (list, filter); | |
338 | prefix_free (filter->p); | |
339 | XFREE (MTYPE_BGP_DEBUG_FILTER, filter); | |
340 | return 1; | |
341 | } | |
342 | } | |
343 | ||
344 | return 0; | |
345 | } | |
346 | ||
347 | static int | |
ffd0c037 | 348 | bgp_debug_list_has_entry(struct list *list, const char *host, struct prefix *p) |
16286195 DS |
349 | { |
350 | struct bgp_debug_filter *filter; | |
351 | struct listnode *node, *nnode; | |
352 | ||
353 | for (ALL_LIST_ELEMENTS (list, node, nnode, filter)) | |
354 | { | |
167d390a | 355 | if (host) |
16286195 | 356 | { |
167d390a | 357 | if (strcmp (filter->host, host) == 0) |
16286195 DS |
358 | { |
359 | return 1; | |
360 | } | |
361 | } | |
362 | else if (p) | |
363 | { | |
364 | if (filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p)) | |
365 | { | |
366 | return 1; | |
367 | } | |
368 | } | |
369 | } | |
370 | ||
371 | return 0; | |
372 | } | |
373 | ||
3f9c7369 | 374 | int |
167d390a | 375 | bgp_debug_peer_updout_enabled(char *host) |
3f9c7369 | 376 | { |
167d390a | 377 | return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, NULL)); |
3f9c7369 DS |
378 | } |
379 | ||
718e3744 | 380 | /* Dump attribute. */ |
e01f9cbb | 381 | int |
718e3744 | 382 | bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size) |
383 | { | |
718e3744 | 384 | if (! attr) |
e01f9cbb | 385 | return 0; |
718e3744 | 386 | |
e01f9cbb | 387 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))) |
388 | snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop)); | |
389 | ||
390 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN))) | |
391 | snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s", | |
392 | bgp_origin_str[attr->origin]); | |
718e3744 | 393 | |
394 | #ifdef HAVE_IPV6 | |
fb982c25 PJ |
395 | if (attr->extra) |
396 | { | |
397 | char addrbuf[BUFSIZ]; | |
398 | ||
399 | /* Add MP case. */ | |
801a9bcc DS |
400 | if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL |
401 | || attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) | |
fb982c25 PJ |
402 | snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s", |
403 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
404 | addrbuf, BUFSIZ)); | |
405 | ||
801a9bcc | 406 | if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) |
fb982c25 PJ |
407 | snprintf (buf + strlen (buf), size - strlen (buf), "(%s)", |
408 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
409 | addrbuf, BUFSIZ)); | |
410 | } | |
718e3744 | 411 | #endif /* HAVE_IPV6 */ |
412 | ||
e01f9cbb | 413 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))) |
ddc943de | 414 | snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u", |
718e3744 | 415 | attr->local_pref); |
416 | ||
e01f9cbb | 417 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))) |
ddc943de | 418 | snprintf (buf + strlen (buf), size - strlen (buf), ", metric %u", |
718e3744 | 419 | attr->med); |
420 | ||
e01f9cbb | 421 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES))) |
718e3744 | 422 | snprintf (buf + strlen (buf), size - strlen (buf), ", community %s", |
423 | community_str (attr->community)); | |
424 | ||
e01f9cbb | 425 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))) |
718e3744 | 426 | snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate"); |
427 | ||
e01f9cbb | 428 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR))) |
aea339f7 | 429 | snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s", |
fb982c25 PJ |
430 | attr->extra->aggregator_as, |
431 | inet_ntoa (attr->extra->aggregator_addr)); | |
718e3744 | 432 | |
e01f9cbb | 433 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))) |
718e3744 | 434 | snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s", |
fb982c25 | 435 | inet_ntoa (attr->extra->originator_id)); |
718e3744 | 436 | |
e01f9cbb | 437 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST))) |
718e3744 | 438 | { |
439 | int i; | |
440 | ||
e01f9cbb | 441 | snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist"); |
fb982c25 | 442 | for (i = 0; i < attr->extra->cluster->length / 4; i++) |
e01f9cbb | 443 | snprintf (buf + strlen (buf), size - strlen (buf), " %s", |
fb982c25 | 444 | inet_ntoa (attr->extra->cluster->list[i])); |
718e3744 | 445 | } |
446 | ||
e01f9cbb | 447 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH))) |
718e3744 | 448 | snprintf (buf + strlen (buf), size - strlen (buf), ", path %s", |
449 | aspath_print (attr->aspath)); | |
e01f9cbb | 450 | |
451 | if (strlen (buf) > 1) | |
452 | return 1; | |
453 | else | |
454 | return 0; | |
718e3744 | 455 | } |
456 | ||
3a8c7ba1 DW |
457 | const char * |
458 | bgp_notify_code_str (char code) | |
718e3744 | 459 | { |
3a8c7ba1 DW |
460 | return LOOKUP_DEF (bgp_notify_msg, code, "Unrecognized Error Code"); |
461 | } | |
718e3744 | 462 | |
3a8c7ba1 DW |
463 | const char * |
464 | bgp_notify_subcode_str (char code, char subcode) | |
465 | { | |
718e3744 | 466 | |
3a8c7ba1 | 467 | switch (code) |
718e3744 | 468 | { |
469 | case BGP_NOTIFY_HEADER_ERR: | |
3a8c7ba1 DW |
470 | return LOOKUP_DEF (bgp_notify_head_msg, subcode, |
471 | "Unrecognized Error Subcode"); | |
718e3744 | 472 | case BGP_NOTIFY_OPEN_ERR: |
3a8c7ba1 DW |
473 | return LOOKUP_DEF (bgp_notify_open_msg, subcode, |
474 | "Unrecognized Error Subcode"); | |
718e3744 | 475 | case BGP_NOTIFY_UPDATE_ERR: |
3a8c7ba1 DW |
476 | return LOOKUP_DEF (bgp_notify_update_msg, subcode, |
477 | "Unrecognized Error Subcode"); | |
718e3744 | 478 | case BGP_NOTIFY_HOLD_ERR: |
718e3744 | 479 | break; |
480 | case BGP_NOTIFY_FSM_ERR: | |
718e3744 | 481 | break; |
482 | case BGP_NOTIFY_CEASE: | |
3a8c7ba1 DW |
483 | return LOOKUP_DEF (bgp_notify_cease_msg, subcode, |
484 | "Unrecognized Error Subcode"); | |
718e3744 | 485 | case BGP_NOTIFY_CAPABILITY_ERR: |
3a8c7ba1 DW |
486 | return LOOKUP_DEF (bgp_notify_capability_msg, subcode, |
487 | "Unrecognized Error Subcode"); | |
718e3744 | 488 | } |
3a8c7ba1 DW |
489 | return ""; |
490 | } | |
491 | ||
492 | /* dump notify packet */ | |
493 | void | |
494 | bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, | |
495 | const char *direct) | |
496 | { | |
497 | const char *subcode_str; | |
498 | const char *code_str; | |
3950fda5 | 499 | |
16286195 | 500 | if (BGP_DEBUG (neighbor_events, NEIGHBOR_EVENTS) || bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) |
3a8c7ba1 DW |
501 | { |
502 | code_str = bgp_notify_code_str(bgp_notify->code); | |
503 | subcode_str = bgp_notify_subcode_str(bgp_notify->code, bgp_notify->subcode); | |
504 | ||
505 | zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s", | |
506 | strcmp (direct, "received") == 0 ? "received from" : "sent to", | |
507 | peer->host, bgp_notify->code, bgp_notify->subcode, | |
508 | code_str, subcode_str, bgp_notify->length, | |
509 | bgp_notify->data ? bgp_notify->data : ""); | |
510 | } | |
718e3744 | 511 | } |
6b0655a2 | 512 | |
3f9c7369 DS |
513 | static void |
514 | bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp) | |
515 | { | |
516 | if (!bgp) | |
517 | bgp = bgp_get_default(); | |
518 | update_group_walk (bgp, update_group_clear_update_dbg, NULL); | |
519 | } | |
520 | ||
521 | ||
718e3744 | 522 | /* Debug option setting interface. */ |
523 | unsigned long bgp_debug_option = 0; | |
524 | ||
525 | int | |
526 | debug (unsigned int option) | |
527 | { | |
528 | return bgp_debug_option & option; | |
529 | } | |
530 | ||
0b2aa3a0 PJ |
531 | DEFUN (debug_bgp_as4, |
532 | debug_bgp_as4_cmd, | |
533 | "debug bgp as4", | |
534 | DEBUG_STR | |
535 | BGP_STR | |
536 | "BGP AS4 actions\n") | |
537 | { | |
538 | if (vty->node == CONFIG_NODE) | |
539 | DEBUG_ON (as4, AS4); | |
540 | else | |
541 | { | |
542 | TERM_DEBUG_ON (as4, AS4); | |
543 | vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE); | |
544 | } | |
545 | return CMD_SUCCESS; | |
546 | } | |
547 | ||
548 | DEFUN (no_debug_bgp_as4, | |
549 | no_debug_bgp_as4_cmd, | |
550 | "no debug bgp as4", | |
551 | NO_STR | |
552 | DEBUG_STR | |
553 | BGP_STR | |
554 | "BGP AS4 actions\n") | |
555 | { | |
556 | if (vty->node == CONFIG_NODE) | |
557 | DEBUG_OFF (as4, AS4); | |
558 | else | |
559 | { | |
560 | TERM_DEBUG_OFF (as4, AS4); | |
561 | vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE); | |
562 | } | |
563 | return CMD_SUCCESS; | |
564 | } | |
565 | ||
0b2aa3a0 PJ |
566 | DEFUN (debug_bgp_as4_segment, |
567 | debug_bgp_as4_segment_cmd, | |
568 | "debug bgp as4 segment", | |
569 | DEBUG_STR | |
570 | BGP_STR | |
6e22b901 | 571 | "BGP AS4 actions\n" |
0b2aa3a0 PJ |
572 | "BGP AS4 aspath segment handling\n") |
573 | { | |
574 | if (vty->node == CONFIG_NODE) | |
575 | DEBUG_ON (as4, AS4_SEGMENT); | |
576 | else | |
577 | { | |
578 | TERM_DEBUG_ON (as4, AS4_SEGMENT); | |
579 | vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE); | |
580 | } | |
581 | return CMD_SUCCESS; | |
582 | } | |
583 | ||
584 | DEFUN (no_debug_bgp_as4_segment, | |
585 | no_debug_bgp_as4_segment_cmd, | |
586 | "no debug bgp as4 segment", | |
587 | NO_STR | |
588 | DEBUG_STR | |
589 | BGP_STR | |
6e22b901 | 590 | "BGP AS4 actions\n" |
0b2aa3a0 PJ |
591 | "BGP AS4 aspath segment handling\n") |
592 | { | |
593 | if (vty->node == CONFIG_NODE) | |
594 | DEBUG_OFF (as4, AS4_SEGMENT); | |
595 | else | |
596 | { | |
597 | TERM_DEBUG_OFF (as4, AS4_SEGMENT); | |
598 | vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE); | |
599 | } | |
600 | return CMD_SUCCESS; | |
601 | } | |
602 | ||
16286195 DS |
603 | /* debug bgp neighbor_events */ |
604 | DEFUN (debug_bgp_neighbor_events, | |
605 | debug_bgp_neighbor_events_cmd, | |
606 | "debug bgp neighbor-events", | |
718e3744 | 607 | DEBUG_STR |
608 | BGP_STR | |
16286195 | 609 | "BGP Neighbor Events\n") |
718e3744 | 610 | { |
91ba2c8b DS |
611 | bgp_debug_list_free(bgp_debug_neighbor_events_peers); |
612 | ||
718e3744 | 613 | if (vty->node == CONFIG_NODE) |
16286195 | 614 | DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS); |
718e3744 | 615 | else |
616 | { | |
16286195 DS |
617 | TERM_DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS); |
618 | vty_out (vty, "BGP neighbor-events debugging is on%s", VTY_NEWLINE); | |
718e3744 | 619 | } |
620 | return CMD_SUCCESS; | |
621 | } | |
622 | ||
16286195 DS |
623 | DEFUN (debug_bgp_neighbor_events_peer, |
624 | debug_bgp_neighbor_events_peer_cmd, | |
625 | "debug bgp neighbor-events (A.B.C.D|X:X::X:X|WORD)", | |
718e3744 | 626 | DEBUG_STR |
627 | BGP_STR | |
16286195 DS |
628 | "BGP Neighbor Events\n" |
629 | "BGP neighbor IP address to debug\n" | |
630 | "BGP IPv6 neighbor to debug\n" | |
631 | "BGP neighbor on interface to debug\n") | |
718e3744 | 632 | { |
ffd0c037 | 633 | const char *host = argv[0]; |
16286195 DS |
634 | |
635 | if (!bgp_debug_neighbor_events_peers) | |
636 | bgp_debug_neighbor_events_peers = list_new (); | |
637 | ||
167d390a | 638 | if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host, NULL)) |
16286195 | 639 | { |
167d390a | 640 | vty_out (vty, "BGP neighbor-events debugging is already enabled for %s%s", host, VTY_NEWLINE); |
16286195 DS |
641 | return CMD_SUCCESS; |
642 | } | |
643 | ||
167d390a | 644 | bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL); |
16286195 | 645 | |
718e3744 | 646 | if (vty->node == CONFIG_NODE) |
16286195 | 647 | DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS); |
718e3744 | 648 | else |
649 | { | |
16286195 | 650 | TERM_DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS); |
167d390a | 651 | vty_out (vty, "BGP neighbor-events debugging is on for %s%s", host, VTY_NEWLINE); |
718e3744 | 652 | } |
653 | return CMD_SUCCESS; | |
654 | } | |
655 | ||
16286195 DS |
656 | DEFUN (no_debug_bgp_neighbor_events, |
657 | no_debug_bgp_neighbor_events_cmd, | |
658 | "no debug bgp neighbor-events", | |
659 | NO_STR | |
718e3744 | 660 | DEBUG_STR |
661 | BGP_STR | |
16286195 | 662 | "Neighbor Events\n") |
718e3744 | 663 | { |
16286195 DS |
664 | bgp_debug_list_free(bgp_debug_neighbor_events_peers); |
665 | ||
718e3744 | 666 | if (vty->node == CONFIG_NODE) |
16286195 | 667 | DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS); |
718e3744 | 668 | else |
669 | { | |
16286195 DS |
670 | TERM_DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS); |
671 | vty_out (vty, "BGP neighbor-events debugging is off%s", VTY_NEWLINE); | |
718e3744 | 672 | } |
673 | return CMD_SUCCESS; | |
674 | } | |
675 | ||
16286195 DS |
676 | DEFUN (no_debug_bgp_neighbor_events_peer, |
677 | no_debug_bgp_neighbor_events_peer_cmd, | |
678 | "no debug bgp neighbor-events (A.B.C.D|X:X::X:X|WORD)", | |
718e3744 | 679 | NO_STR |
680 | DEBUG_STR | |
681 | BGP_STR | |
16286195 DS |
682 | "Neighbor Events\n" |
683 | "BGP neighbor IP address to debug\n" | |
684 | "BGP IPv6 neighbor to debug\n" | |
685 | "BGP neighbor on interface to debug\n") | |
718e3744 | 686 | { |
16286195 | 687 | int found_peer = 0; |
ffd0c037 | 688 | const char *host = argv[0]; |
16286195 DS |
689 | |
690 | if (bgp_debug_neighbor_events_peers && !list_isempty(bgp_debug_neighbor_events_peers)) | |
718e3744 | 691 | { |
167d390a | 692 | found_peer = bgp_debug_list_remove_entry(bgp_debug_neighbor_events_peers, host, NULL); |
16286195 DS |
693 | |
694 | if (list_isempty(bgp_debug_neighbor_events_peers)) | |
695 | { | |
696 | if (vty->node == CONFIG_NODE) | |
697 | DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS); | |
698 | else | |
699 | TERM_DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS); | |
700 | } | |
718e3744 | 701 | } |
16286195 DS |
702 | |
703 | if (found_peer) | |
167d390a | 704 | vty_out (vty, "BGP neighbor-events debugging is off for %s%s", host, VTY_NEWLINE); |
16286195 | 705 | else |
167d390a | 706 | vty_out (vty, "BGP neighbor-events debugging was not enabled for %s%s", host, VTY_NEWLINE); |
16286195 | 707 | |
718e3744 | 708 | return CMD_SUCCESS; |
709 | } | |
710 | ||
16286195 | 711 | /* debug bgp nht */ |
fb018d25 DS |
712 | DEFUN (debug_bgp_nht, |
713 | debug_bgp_nht_cmd, | |
714 | "debug bgp nht", | |
715 | DEBUG_STR | |
716 | BGP_STR | |
717 | "BGP nexthop tracking events\n") | |
718 | { | |
719 | if (vty->node == CONFIG_NODE) | |
720 | DEBUG_ON (nht, NHT); | |
721 | else | |
722 | { | |
723 | TERM_DEBUG_ON (nht, NHT); | |
724 | vty_out (vty, "BGP nexthop tracking debugging is on%s", VTY_NEWLINE); | |
725 | } | |
726 | return CMD_SUCCESS; | |
727 | } | |
728 | ||
729 | DEFUN (no_debug_bgp_nht, | |
730 | no_debug_bgp_nht_cmd, | |
731 | "no debug bgp nht", | |
732 | NO_STR | |
733 | DEBUG_STR | |
734 | BGP_STR | |
735 | "BGP nexthop tracking events\n") | |
736 | { | |
737 | if (vty->node == CONFIG_NODE) | |
738 | DEBUG_OFF (nht, NHT); | |
739 | else | |
740 | { | |
741 | TERM_DEBUG_OFF (nht, NHT); | |
742 | vty_out (vty, "BGP nexthop tracking debugging is off%s", VTY_NEWLINE); | |
743 | } | |
744 | return CMD_SUCCESS; | |
745 | } | |
746 | ||
16286195 DS |
747 | /* debug bgp keepalives */ |
748 | DEFUN (debug_bgp_keepalive, | |
749 | debug_bgp_keepalive_cmd, | |
750 | "debug bgp keepalives", | |
718e3744 | 751 | DEBUG_STR |
752 | BGP_STR | |
16286195 | 753 | "BGP keepalives\n") |
718e3744 | 754 | { |
91ba2c8b DS |
755 | bgp_debug_list_free(bgp_debug_keepalive_peers); |
756 | ||
718e3744 | 757 | if (vty->node == CONFIG_NODE) |
16286195 | 758 | DEBUG_ON (keepalive, KEEPALIVE); |
718e3744 | 759 | else |
760 | { | |
16286195 DS |
761 | TERM_DEBUG_ON (keepalive, KEEPALIVE); |
762 | vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE); | |
718e3744 | 763 | } |
764 | return CMD_SUCCESS; | |
765 | } | |
766 | ||
16286195 DS |
767 | DEFUN (debug_bgp_keepalive_peer, |
768 | debug_bgp_keepalive_peer_cmd, | |
769 | "debug bgp keepalives (A.B.C.D|X:X::X:X|WORD)", | |
718e3744 | 770 | DEBUG_STR |
771 | BGP_STR | |
16286195 DS |
772 | "BGP Neighbor Events\n" |
773 | "BGP neighbor IP address to debug\n" | |
774 | "BGP IPv6 neighbor to debug\n" | |
775 | "BGP neighbor on interface to debug\n") | |
718e3744 | 776 | { |
ffd0c037 | 777 | const char *host = argv[0]; |
718e3744 | 778 | |
16286195 DS |
779 | if (!bgp_debug_keepalive_peers) |
780 | bgp_debug_keepalive_peers = list_new (); | |
781 | ||
167d390a | 782 | if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL)) |
16286195 | 783 | { |
167d390a | 784 | vty_out (vty, "BGP keepalive debugging is already enabled for %s%s", host, VTY_NEWLINE); |
16286195 DS |
785 | return CMD_SUCCESS; |
786 | } | |
787 | ||
167d390a | 788 | bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL); |
718e3744 | 789 | |
718e3744 | 790 | if (vty->node == CONFIG_NODE) |
791 | DEBUG_ON (keepalive, KEEPALIVE); | |
792 | else | |
793 | { | |
794 | TERM_DEBUG_ON (keepalive, KEEPALIVE); | |
167d390a | 795 | vty_out (vty, "BGP keepalives debugging is on for %s%s", host, VTY_NEWLINE); |
718e3744 | 796 | } |
797 | return CMD_SUCCESS; | |
798 | } | |
799 | ||
800 | DEFUN (no_debug_bgp_keepalive, | |
801 | no_debug_bgp_keepalive_cmd, | |
802 | "no debug bgp keepalives", | |
803 | NO_STR | |
804 | DEBUG_STR | |
805 | BGP_STR | |
806 | "BGP keepalives\n") | |
807 | { | |
16286195 DS |
808 | bgp_debug_list_free(bgp_debug_keepalive_peers); |
809 | ||
718e3744 | 810 | if (vty->node == CONFIG_NODE) |
811 | DEBUG_OFF (keepalive, KEEPALIVE); | |
812 | else | |
813 | { | |
814 | TERM_DEBUG_OFF (keepalive, KEEPALIVE); | |
815 | vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE); | |
816 | } | |
817 | return CMD_SUCCESS; | |
818 | } | |
819 | ||
16286195 DS |
820 | DEFUN (no_debug_bgp_keepalive_peer, |
821 | no_debug_bgp_keepalive_peer_cmd, | |
822 | "no debug bgp keepalives (A.B.C.D|X:X::X:X|WORD)", | |
823 | NO_STR | |
824 | DEBUG_STR | |
718e3744 | 825 | BGP_STR |
16286195 DS |
826 | "BGP keepalives\n" |
827 | "BGP neighbor IP address to debug\n" | |
828 | "BGP IPv6 neighbor to debug\n" | |
829 | "BGP neighbor on interface to debug\n") | |
830 | { | |
831 | int found_peer = 0; | |
ffd0c037 | 832 | const char *host = argv[0]; |
718e3744 | 833 | |
16286195 DS |
834 | if (bgp_debug_keepalive_peers && !list_isempty(bgp_debug_keepalive_peers)) |
835 | { | |
167d390a | 836 | found_peer = bgp_debug_list_remove_entry(bgp_debug_keepalive_peers, host, NULL); |
16286195 DS |
837 | |
838 | if (list_isempty(bgp_debug_keepalive_peers)) | |
839 | { | |
840 | if (vty->node == CONFIG_NODE) | |
841 | DEBUG_OFF (keepalive, KEEPALIVE); | |
842 | else | |
843 | TERM_DEBUG_OFF (keepalive, KEEPALIVE); | |
844 | } | |
845 | } | |
846 | ||
847 | if (found_peer) | |
167d390a | 848 | vty_out (vty, "BGP keepalives debugging is off for %s%s", host, VTY_NEWLINE); |
16286195 | 849 | else |
167d390a | 850 | vty_out (vty, "BGP keepalives debugging was not enabled for %s%s", host, VTY_NEWLINE); |
16286195 DS |
851 | |
852 | return CMD_SUCCESS; | |
853 | } | |
854 | ||
9fbdd100 DS |
855 | /* debug bgp bestpath */ |
856 | DEFUN (debug_bgp_bestpath_prefix, | |
857 | debug_bgp_bestpath_prefix_cmd, | |
858 | "debug bgp bestpath (A.B.C.D/M|X:X::X:X/M)", | |
859 | DEBUG_STR | |
860 | BGP_STR | |
861 | "BGP bestpath\n" | |
862 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
863 | "IPv6 prefix <network>/<length>\n") | |
864 | ||
865 | { | |
866 | struct prefix *argv_p; | |
867 | int ret; | |
868 | ||
869 | argv_p = prefix_new(); | |
870 | ret = str2prefix (argv[0], argv_p); | |
871 | if (!ret) | |
872 | { | |
873 | prefix_free(argv_p); | |
874 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
875 | return CMD_WARNING; | |
876 | } | |
877 | ||
878 | ||
879 | if (!bgp_debug_bestpath_prefixes) | |
880 | bgp_debug_bestpath_prefixes = list_new (); | |
881 | ||
882 | if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL, argv_p)) | |
883 | { | |
884 | vty_out (vty, "BGP bestptah debugging is already enabled for %s%s", argv[0], VTY_NEWLINE); | |
885 | return CMD_SUCCESS; | |
886 | } | |
887 | ||
888 | bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, argv_p); | |
889 | ||
890 | if (vty->node == CONFIG_NODE) | |
891 | { | |
892 | DEBUG_ON (bestpath, BESTPATH); | |
893 | } | |
894 | else | |
895 | { | |
896 | TERM_DEBUG_ON (bestpath, BESTPATH); | |
897 | vty_out (vty, "BGP bestpath debugging is on for %s%s", argv[0], VTY_NEWLINE); | |
898 | } | |
899 | ||
900 | return CMD_SUCCESS; | |
901 | } | |
902 | ||
903 | DEFUN (no_debug_bgp_bestpath_prefix, | |
904 | no_debug_bgp_bestpath_prefix_cmd, | |
905 | "no debug bgp bestpath (A.B.C.D/M|X:X::X:X/M)", | |
906 | NO_STR | |
907 | DEBUG_STR | |
908 | BGP_STR | |
909 | "BGP bestpath\n" | |
910 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
911 | "IPv6 prefix <network>/<length>\n") | |
912 | ||
913 | { | |
914 | struct prefix *argv_p; | |
915 | int found_prefix = 0; | |
916 | int ret; | |
917 | ||
918 | argv_p = prefix_new(); | |
919 | ret = str2prefix (argv[0], argv_p); | |
920 | if (!ret) | |
921 | { | |
922 | prefix_free(argv_p); | |
923 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
924 | return CMD_WARNING; | |
925 | } | |
926 | ||
927 | if (bgp_debug_bestpath_prefixes && !list_isempty(bgp_debug_bestpath_prefixes)) | |
928 | { | |
929 | found_prefix = bgp_debug_list_remove_entry(bgp_debug_bestpath_prefixes, NULL, argv_p); | |
930 | ||
931 | if (list_isempty(bgp_debug_bestpath_prefixes)) | |
932 | { | |
933 | if (vty->node == CONFIG_NODE) | |
934 | { | |
935 | DEBUG_OFF (bestpath, BESTPATH); | |
936 | } | |
937 | else | |
938 | { | |
939 | TERM_DEBUG_OFF (bestpath, BESTPATH); | |
940 | vty_out (vty, "BGP bestpath debugging (per prefix) is off%s", VTY_NEWLINE); | |
941 | } | |
942 | } | |
943 | } | |
944 | ||
945 | if (found_prefix) | |
946 | vty_out (vty, "BGP bestpath debugging is off for %s%s", argv[0], VTY_NEWLINE); | |
947 | else | |
948 | vty_out (vty, "BGP bestpath debugging was not enabled for %s%s", argv[0], VTY_NEWLINE); | |
949 | ||
950 | return CMD_SUCCESS; | |
951 | } | |
952 | ||
953 | DEFUN (no_debug_bgp_bestpath, | |
954 | no_debug_bgp_bestpath_cmd, | |
955 | "no debug bgp bestpath", | |
956 | NO_STR | |
957 | DEBUG_STR | |
958 | BGP_STR | |
959 | "BGP bestpath\n") | |
960 | { | |
961 | bgp_debug_list_free(bgp_debug_bestpath_prefixes); | |
962 | ||
963 | if (vty->node == CONFIG_NODE) | |
964 | DEBUG_OFF (bestpath, BESTPATH); | |
965 | else | |
966 | { | |
967 | TERM_DEBUG_OFF (bestpath, BESTPATH); | |
968 | vty_out (vty, "BGP bestpath debugging is off%s", VTY_NEWLINE); | |
969 | } | |
970 | return CMD_SUCCESS; | |
971 | } | |
972 | ||
16286195 | 973 | /* debug bgp updates */ |
718e3744 | 974 | DEFUN (debug_bgp_update, |
975 | debug_bgp_update_cmd, | |
976 | "debug bgp updates", | |
977 | DEBUG_STR | |
978 | BGP_STR | |
979 | "BGP updates\n") | |
980 | { | |
91ba2c8b DS |
981 | bgp_debug_list_free(bgp_debug_update_in_peers); |
982 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
983 | bgp_debug_list_free(bgp_debug_update_prefixes); | |
984 | ||
718e3744 | 985 | if (vty->node == CONFIG_NODE) |
986 | { | |
987 | DEBUG_ON (update, UPDATE_IN); | |
988 | DEBUG_ON (update, UPDATE_OUT); | |
989 | } | |
990 | else | |
991 | { | |
992 | TERM_DEBUG_ON (update, UPDATE_IN); | |
993 | TERM_DEBUG_ON (update, UPDATE_OUT); | |
994 | vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE); | |
995 | } | |
996 | return CMD_SUCCESS; | |
997 | } | |
998 | ||
999 | DEFUN (debug_bgp_update_direct, | |
1000 | debug_bgp_update_direct_cmd, | |
1001 | "debug bgp updates (in|out)", | |
1002 | DEBUG_STR | |
1003 | BGP_STR | |
1004 | "BGP updates\n" | |
1005 | "Inbound updates\n" | |
1006 | "Outbound updates\n") | |
1007 | { | |
91ba2c8b DS |
1008 | |
1009 | if (strncmp ("i", argv[0], 1) == 0) | |
1010 | bgp_debug_list_free(bgp_debug_update_in_peers); | |
1011 | else | |
1012 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1013 | ||
718e3744 | 1014 | if (vty->node == CONFIG_NODE) |
1015 | { | |
1016 | if (strncmp ("i", argv[0], 1) == 0) | |
91ba2c8b | 1017 | DEBUG_ON (update, UPDATE_IN); |
718e3744 | 1018 | else |
91ba2c8b | 1019 | DEBUG_ON (update, UPDATE_OUT); |
718e3744 | 1020 | } |
1021 | else | |
1022 | { | |
1023 | if (strncmp ("i", argv[0], 1) == 0) | |
1024 | { | |
718e3744 | 1025 | TERM_DEBUG_ON (update, UPDATE_IN); |
1026 | vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE); | |
1027 | } | |
1028 | else | |
1029 | { | |
718e3744 | 1030 | TERM_DEBUG_ON (update, UPDATE_OUT); |
1031 | vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE); | |
1032 | } | |
1033 | } | |
1034 | return CMD_SUCCESS; | |
1035 | } | |
1036 | ||
16286195 DS |
1037 | DEFUN (debug_bgp_update_direct_peer, |
1038 | debug_bgp_update_direct_peer_cmd, | |
1039 | "debug bgp updates (in|out) (A.B.C.D|X:X::X:X|WORD)", | |
718e3744 | 1040 | DEBUG_STR |
1041 | BGP_STR | |
16286195 DS |
1042 | "BGP updates\n" |
1043 | "Inbound updates\n" | |
1044 | "Outbound updates\n" | |
1045 | "BGP neighbor IP address to debug\n" | |
1046 | "BGP IPv6 neighbor to debug\n" | |
1047 | "BGP neighbor on interface to debug\n") | |
718e3744 | 1048 | { |
ffd0c037 | 1049 | const char *host = argv[1]; |
16286195 DS |
1050 | int inbound; |
1051 | ||
16286195 DS |
1052 | if (!bgp_debug_update_in_peers) |
1053 | bgp_debug_update_in_peers = list_new (); | |
1054 | ||
1055 | if (!bgp_debug_update_out_peers) | |
1056 | bgp_debug_update_out_peers = list_new (); | |
1057 | ||
1058 | if (strncmp ("i", argv[0], 1) == 0) | |
1059 | inbound = 1; | |
1060 | else | |
1061 | inbound = 0; | |
1062 | ||
1063 | if (inbound) | |
1064 | { | |
167d390a | 1065 | if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, host, NULL)) |
16286195 | 1066 | { |
167d390a | 1067 | vty_out (vty, "BGP inbound update debugging is already enabled for %s%s", host, VTY_NEWLINE); |
16286195 DS |
1068 | return CMD_SUCCESS; |
1069 | } | |
1070 | } | |
1071 | ||
1072 | else | |
1073 | { | |
167d390a | 1074 | if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, NULL)) |
16286195 | 1075 | { |
167d390a | 1076 | vty_out (vty, "BGP outbound update debugging is already enabled for %s%s", host, VTY_NEWLINE); |
16286195 DS |
1077 | return CMD_SUCCESS; |
1078 | } | |
1079 | } | |
1080 | ||
1081 | if (inbound) | |
167d390a | 1082 | bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL); |
16286195 | 1083 | else |
3f9c7369 | 1084 | { |
167d390a | 1085 | struct peer *peer; |
3f9c7369 | 1086 | struct peer_af *paf; |
96885f16 | 1087 | int afidx; |
3f9c7369 | 1088 | |
167d390a DS |
1089 | bgp_debug_list_add_entry(bgp_debug_update_out_peers, host, NULL); |
1090 | peer = bgp_find_peer (vty, host); | |
1091 | ||
1092 | if (peer) | |
3f9c7369 | 1093 | { |
96885f16 | 1094 | for (afidx = BGP_AF_START; afidx < BGP_AF_MAX; afidx++) |
3f9c7369 | 1095 | { |
96885f16 | 1096 | paf = peer->peer_af_array[afidx]; |
1097 | if (paf != NULL) | |
167d390a | 1098 | { |
96885f16 | 1099 | if (PAF_SUBGRP (paf)) |
1100 | { | |
1101 | UPDGRP_PEER_DBG_EN(PAF_SUBGRP(paf)->update_group); | |
1102 | } | |
167d390a | 1103 | } |
3f9c7369 DS |
1104 | } |
1105 | } | |
1106 | } | |
16286195 | 1107 | |
718e3744 | 1108 | if (vty->node == CONFIG_NODE) |
1109 | { | |
16286195 | 1110 | if (inbound) |
91ba2c8b | 1111 | DEBUG_ON (update, UPDATE_IN); |
16286195 | 1112 | else |
91ba2c8b | 1113 | DEBUG_ON (update, UPDATE_OUT); |
718e3744 | 1114 | } |
1115 | else | |
1116 | { | |
16286195 DS |
1117 | if (inbound) |
1118 | { | |
16286195 DS |
1119 | TERM_DEBUG_ON (update, UPDATE_IN); |
1120 | vty_out (vty, "BGP updates debugging is on (inbound) for %s%s", argv[1], VTY_NEWLINE); | |
1121 | } | |
1122 | else | |
1123 | { | |
16286195 DS |
1124 | TERM_DEBUG_ON (update, UPDATE_OUT); |
1125 | vty_out (vty, "BGP updates debugging is on (outbound) for %s%s", argv[1], VTY_NEWLINE); | |
1126 | } | |
718e3744 | 1127 | } |
1128 | return CMD_SUCCESS; | |
1129 | } | |
1130 | ||
91ba2c8b DS |
1131 | DEFUN (no_debug_bgp_update_direct, |
1132 | no_debug_bgp_update_direct_cmd, | |
1133 | "no debug bgp updates (in|out)", | |
1134 | NO_STR | |
1135 | DEBUG_STR | |
1136 | BGP_STR | |
1137 | "BGP updates\n" | |
1138 | "Inbound updates\n" | |
1139 | "Outbound updates\n") | |
1140 | { | |
1141 | if (strncmp ("i", argv[0], 1) == 0) | |
1142 | { | |
1143 | bgp_debug_list_free(bgp_debug_update_in_peers); | |
1144 | ||
1145 | if (vty->node == CONFIG_NODE) | |
1146 | { | |
1147 | DEBUG_OFF (update, UPDATE_IN); | |
1148 | } | |
1149 | else | |
1150 | { | |
1151 | TERM_DEBUG_OFF (update, UPDATE_IN); | |
1152 | vty_out (vty, "BGP updates debugging is off (inbound)%s", VTY_NEWLINE); | |
1153 | } | |
1154 | } | |
1155 | else | |
1156 | { | |
1157 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1158 | ||
1159 | if (vty->node == CONFIG_NODE) | |
1160 | { | |
1161 | DEBUG_OFF (update, UPDATE_OUT); | |
1162 | } | |
1163 | else | |
1164 | { | |
1165 | TERM_DEBUG_OFF (update, UPDATE_OUT); | |
1166 | vty_out (vty, "BGP updates debugging is off (outbound)%s", VTY_NEWLINE); | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | return CMD_SUCCESS; | |
1171 | } | |
1172 | ||
16286195 DS |
1173 | DEFUN (no_debug_bgp_update_direct_peer, |
1174 | no_debug_bgp_update_direct_peer_cmd, | |
1175 | "no debug bgp updates (in|out) (A.B.C.D|X:X::X:X|WORD)", | |
1176 | NO_STR | |
1177 | DEBUG_STR | |
718e3744 | 1178 | BGP_STR |
16286195 DS |
1179 | "BGP updates\n" |
1180 | "Inbound updates\n" | |
1181 | "Outbound updates\n" | |
1182 | "BGP neighbor IP address to debug\n" | |
1183 | "BGP IPv6 neighbor to debug\n" | |
1184 | "BGP neighbor on interface to debug\n") | |
1185 | { | |
1186 | int inbound; | |
1187 | int found_peer = 0; | |
ffd0c037 | 1188 | const char *host = argv[1]; |
718e3744 | 1189 | |
16286195 DS |
1190 | if (strncmp ("i", argv[0], 1) == 0) |
1191 | inbound = 1; | |
1192 | else | |
1193 | inbound = 0; | |
1194 | ||
1195 | if (inbound && bgp_debug_update_in_peers && | |
1196 | !list_isempty(bgp_debug_update_in_peers)) | |
1197 | { | |
167d390a | 1198 | found_peer = bgp_debug_list_remove_entry(bgp_debug_update_in_peers, host, NULL); |
16286195 DS |
1199 | |
1200 | if (list_isempty(bgp_debug_update_in_peers)) | |
1201 | { | |
1202 | if (vty->node == CONFIG_NODE) | |
1203 | DEBUG_OFF (update, UPDATE_IN); | |
1204 | else | |
1205 | { | |
1206 | TERM_DEBUG_OFF (update, UPDATE_IN); | |
1207 | vty_out (vty, "BGP updates debugging (inbound) is off%s", VTY_NEWLINE); | |
1208 | } | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | if (!inbound && bgp_debug_update_out_peers && | |
1213 | !list_isempty(bgp_debug_update_out_peers)) | |
1214 | { | |
167d390a | 1215 | found_peer = bgp_debug_list_remove_entry(bgp_debug_update_out_peers, host, NULL); |
16286195 DS |
1216 | |
1217 | if (list_isempty(bgp_debug_update_out_peers)) | |
1218 | { | |
1219 | if (vty->node == CONFIG_NODE) | |
1220 | DEBUG_OFF (update, UPDATE_OUT); | |
1221 | else | |
1222 | { | |
1223 | TERM_DEBUG_OFF (update, UPDATE_OUT); | |
1224 | vty_out (vty, "BGP updates debugging (outbound) is off%s", VTY_NEWLINE); | |
1225 | } | |
1226 | } | |
3f9c7369 | 1227 | |
167d390a DS |
1228 | struct peer *peer; |
1229 | struct peer_af *paf; | |
96885f16 | 1230 | int afidx; |
167d390a | 1231 | peer = bgp_find_peer (vty, host); |
3f9c7369 | 1232 | |
167d390a DS |
1233 | if (peer) |
1234 | { | |
96885f16 | 1235 | for (afidx = BGP_AF_START; afidx < BGP_AF_MAX; afidx++) |
3f9c7369 | 1236 | { |
96885f16 | 1237 | paf = peer->peer_af_array[afidx]; |
1238 | if (paf != NULL) | |
3f9c7369 | 1239 | { |
96885f16 | 1240 | if (PAF_SUBGRP (paf)) |
1241 | { | |
1242 | UPDGRP_PEER_DBG_DIS(PAF_SUBGRP(paf)->update_group); | |
1243 | } | |
3f9c7369 DS |
1244 | } |
1245 | } | |
1246 | } | |
16286195 DS |
1247 | } |
1248 | ||
1249 | if (found_peer) | |
1250 | if (inbound) | |
167d390a | 1251 | vty_out (vty, "BGP updates debugging (inbound) is off for %s%s", host, VTY_NEWLINE); |
16286195 | 1252 | else |
167d390a | 1253 | vty_out (vty, "BGP updates debugging (outbound) is off for %s%s", host, VTY_NEWLINE); |
16286195 DS |
1254 | else |
1255 | if (inbound) | |
167d390a | 1256 | vty_out (vty, "BGP updates debugging (inbound) was not enabled for %s%s", host, VTY_NEWLINE); |
16286195 | 1257 | else |
167d390a | 1258 | vty_out (vty, "BGP updates debugging (outbound) was not enabled for %s%s", host, VTY_NEWLINE); |
16286195 DS |
1259 | |
1260 | return CMD_SUCCESS; | |
1261 | } | |
1262 | ||
1263 | DEFUN (debug_bgp_update_prefix, | |
1264 | debug_bgp_update_prefix_cmd, | |
1265 | "debug bgp updates prefix (A.B.C.D/M|X:X::X:X/M)", | |
718e3744 | 1266 | DEBUG_STR |
16286195 DS |
1267 | BGP_STR |
1268 | "BGP updates\n" | |
1269 | "Specify a prefix to debug\n" | |
1270 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
1271 | "IPv6 prefix <network>/<length>\n") | |
1272 | ||
718e3744 | 1273 | { |
16286195 DS |
1274 | struct prefix *argv_p; |
1275 | int ret; | |
1276 | ||
1277 | argv_p = prefix_new(); | |
1278 | ret = str2prefix (argv[0], argv_p); | |
1279 | if (!ret) | |
1280 | { | |
1281 | prefix_free(argv_p); | |
1282 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
1283 | return CMD_WARNING; | |
1284 | } | |
1285 | ||
1286 | ||
1287 | if (!bgp_debug_update_prefixes) | |
1288 | bgp_debug_update_prefixes = list_new (); | |
1289 | ||
1290 | if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) | |
1291 | { | |
1292 | vty_out (vty, "BGP updates debugging is already enabled for %s%s", argv[0], VTY_NEWLINE); | |
1293 | return CMD_SUCCESS; | |
1294 | } | |
1295 | ||
1296 | bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p); | |
1297 | ||
718e3744 | 1298 | if (vty->node == CONFIG_NODE) |
16286195 DS |
1299 | { |
1300 | DEBUG_ON (update, UPDATE_PREFIX); | |
1301 | } | |
718e3744 | 1302 | else |
1303 | { | |
16286195 DS |
1304 | TERM_DEBUG_ON (update, UPDATE_PREFIX); |
1305 | vty_out (vty, "BGP updates debugging is on for %s%s", argv[0], VTY_NEWLINE); | |
718e3744 | 1306 | } |
16286195 | 1307 | |
718e3744 | 1308 | return CMD_SUCCESS; |
1309 | } | |
1310 | ||
16286195 DS |
1311 | DEFUN (no_debug_bgp_update_prefix, |
1312 | no_debug_bgp_update_prefix_cmd, | |
1313 | "no debug bgp updates prefix (A.B.C.D/M|X:X::X:X/M)", | |
718e3744 | 1314 | NO_STR |
1315 | DEBUG_STR | |
16286195 DS |
1316 | BGP_STR |
1317 | "BGP updates\n" | |
1318 | "Specify a prefix to debug\n" | |
1319 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
1320 | "IPv6 prefix <network>/<length>\n") | |
1321 | ||
1322 | { | |
1323 | struct prefix *argv_p; | |
1324 | int found_prefix = 0; | |
1325 | int ret; | |
1326 | ||
1327 | argv_p = prefix_new(); | |
1328 | ret = str2prefix (argv[0], argv_p); | |
1329 | if (!ret) | |
1330 | { | |
1331 | prefix_free(argv_p); | |
1332 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
1333 | return CMD_WARNING; | |
1334 | } | |
1335 | ||
1336 | if (bgp_debug_update_prefixes && !list_isempty(bgp_debug_update_prefixes)) | |
1337 | { | |
1338 | found_prefix = bgp_debug_list_remove_entry(bgp_debug_update_prefixes, NULL, argv_p); | |
1339 | ||
1340 | if (list_isempty(bgp_debug_update_prefixes)) | |
1341 | { | |
1342 | if (vty->node == CONFIG_NODE) | |
1343 | { | |
1344 | DEBUG_OFF (update, UPDATE_PREFIX); | |
1345 | } | |
1346 | else | |
1347 | { | |
1348 | TERM_DEBUG_OFF (update, UPDATE_PREFIX); | |
1349 | vty_out (vty, "BGP updates debugging (per prefix) is off%s", VTY_NEWLINE); | |
1350 | } | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | if (found_prefix) | |
1355 | vty_out (vty, "BGP updates debugging is off for %s%s", argv[0], VTY_NEWLINE); | |
1356 | else | |
1357 | vty_out (vty, "BGP updates debugging was not enabled for %s%s", argv[0], VTY_NEWLINE); | |
1358 | ||
1359 | return CMD_SUCCESS; | |
1360 | } | |
1361 | ||
1362 | DEFUN (no_debug_bgp_update, | |
1363 | no_debug_bgp_update_cmd, | |
1364 | "no debug bgp updates", | |
1365 | NO_STR | |
1366 | DEBUG_STR | |
1367 | BGP_STR | |
1368 | "BGP updates\n") | |
718e3744 | 1369 | { |
16286195 DS |
1370 | bgp_debug_list_free(bgp_debug_update_in_peers); |
1371 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1372 | bgp_debug_list_free(bgp_debug_update_prefixes); | |
1373 | ||
3f9c7369 DS |
1374 | bgp_debug_clear_updgrp_update_dbg(vty->index); |
1375 | ||
718e3744 | 1376 | if (vty->node == CONFIG_NODE) |
16286195 DS |
1377 | { |
1378 | DEBUG_OFF (update, UPDATE_IN); | |
1379 | DEBUG_OFF (update, UPDATE_OUT); | |
1380 | DEBUG_OFF (update, UPDATE_PREFIX); | |
1381 | } | |
718e3744 | 1382 | else |
1383 | { | |
16286195 DS |
1384 | TERM_DEBUG_OFF (update, UPDATE_IN); |
1385 | TERM_DEBUG_OFF (update, UPDATE_OUT); | |
1386 | TERM_DEBUG_OFF (update, UPDATE_PREFIX); | |
1387 | vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE); | |
718e3744 | 1388 | } |
1389 | return CMD_SUCCESS; | |
1390 | } | |
1391 | ||
16286195 | 1392 | /* debug bgp zebra */ |
a39275d7 AS |
1393 | DEFUN (debug_bgp_zebra, |
1394 | debug_bgp_zebra_cmd, | |
1395 | "debug bgp zebra", | |
1396 | DEBUG_STR | |
1397 | BGP_STR | |
1398 | "BGP Zebra messages\n") | |
1399 | { | |
1400 | if (vty->node == CONFIG_NODE) | |
1401 | DEBUG_ON (zebra, ZEBRA); | |
1402 | else | |
1403 | { | |
1404 | TERM_DEBUG_ON (zebra, ZEBRA); | |
1405 | vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE); | |
1406 | } | |
1407 | return CMD_SUCCESS; | |
1408 | } | |
1409 | ||
16286195 DS |
1410 | DEFUN (debug_bgp_zebra_prefix, |
1411 | debug_bgp_zebra_prefix_cmd, | |
1412 | "debug bgp zebra prefix (A.B.C.D/M|X:X::X:X/M)", | |
1413 | DEBUG_STR | |
1414 | BGP_STR | |
1415 | "BGP Zebra messages\n" | |
1416 | "Specify a prefix to debug\n" | |
1417 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
1418 | "IPv6 prefix <network>/<length>\n") | |
1419 | ||
1420 | { | |
1421 | struct prefix *argv_p; | |
1422 | int ret; | |
1423 | ||
1424 | argv_p = prefix_new(); | |
1425 | ret = str2prefix (argv[0], argv_p); | |
1426 | if (!ret) | |
1427 | { | |
1428 | prefix_free(argv_p); | |
1429 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
1430 | return CMD_WARNING; | |
1431 | } | |
1432 | ||
1433 | if (!bgp_debug_zebra_prefixes) | |
1434 | bgp_debug_zebra_prefixes = list_new(); | |
1435 | ||
1436 | if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, argv_p)) | |
1437 | { | |
1438 | vty_out (vty, "BGP zebra debugging is already enabled for %s%s", argv[0], VTY_NEWLINE); | |
1439 | return CMD_SUCCESS; | |
1440 | } | |
1441 | ||
1442 | bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, argv_p); | |
1443 | ||
1444 | if (vty->node == CONFIG_NODE) | |
1445 | DEBUG_ON (zebra, ZEBRA); | |
1446 | else | |
1447 | { | |
1448 | TERM_DEBUG_ON (zebra, ZEBRA); | |
1449 | vty_out (vty, "BGP zebra debugging is on for %s%s", argv[0], VTY_NEWLINE); | |
1450 | } | |
1451 | ||
1452 | return CMD_SUCCESS; | |
1453 | } | |
1454 | ||
a39275d7 AS |
1455 | DEFUN (no_debug_bgp_zebra, |
1456 | no_debug_bgp_zebra_cmd, | |
1457 | "no debug bgp zebra", | |
1458 | NO_STR | |
1459 | DEBUG_STR | |
1460 | BGP_STR | |
1461 | "BGP Zebra messages\n") | |
1462 | { | |
16286195 DS |
1463 | bgp_debug_list_free(bgp_debug_zebra_prefixes); |
1464 | ||
a39275d7 AS |
1465 | if (vty->node == CONFIG_NODE) |
1466 | DEBUG_OFF (zebra, ZEBRA); | |
1467 | else | |
1468 | { | |
1469 | TERM_DEBUG_OFF (zebra, ZEBRA); | |
1470 | vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE); | |
1471 | } | |
1472 | return CMD_SUCCESS; | |
1473 | } | |
1474 | ||
16286195 DS |
1475 | DEFUN (no_debug_bgp_zebra_prefix, |
1476 | no_debug_bgp_zebra_prefix_cmd, | |
1477 | "no debug bgp zebra prefix (A.B.C.D/M|X:X::X:X/M)", | |
1478 | NO_STR | |
1479 | DEBUG_STR | |
a39275d7 | 1480 | BGP_STR |
16286195 DS |
1481 | "BGP Zebra messages\n" |
1482 | "Specify a prefix to debug\n" | |
1483 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
1484 | "IPv6 prefix <network>/<length>\n") | |
1485 | ||
1486 | { | |
1487 | struct prefix *argv_p; | |
1488 | int found_prefix = 0; | |
1489 | int ret; | |
1490 | ||
1491 | argv_p = prefix_new(); | |
1492 | ret = str2prefix (argv[0], argv_p); | |
1493 | if (!ret) | |
1494 | { | |
1495 | prefix_free(argv_p); | |
1496 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
1497 | return CMD_WARNING; | |
1498 | } | |
1499 | ||
1500 | if (bgp_debug_zebra_prefixes && !list_isempty(bgp_debug_zebra_prefixes)) | |
1501 | { | |
91ba2c8b | 1502 | found_prefix = bgp_debug_list_remove_entry(bgp_debug_zebra_prefixes, NULL, argv_p); |
16286195 DS |
1503 | |
1504 | if (list_isempty(bgp_debug_zebra_prefixes)) | |
1505 | { | |
1506 | if (vty->node == CONFIG_NODE) | |
1507 | DEBUG_OFF (zebra, ZEBRA); | |
1508 | else | |
1509 | { | |
1510 | TERM_DEBUG_OFF (zebra, ZEBRA); | |
1511 | vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE); | |
1512 | } | |
1513 | } | |
1514 | } | |
a39275d7 | 1515 | |
16286195 DS |
1516 | if (found_prefix) |
1517 | vty_out (vty, "BGP zebra debugging is off for %s%s", argv[0], VTY_NEWLINE); | |
1518 | else | |
1519 | vty_out (vty, "BGP zebra debugging was not enabled for %s%s", argv[0], VTY_NEWLINE); | |
1520 | ||
1521 | return CMD_SUCCESS; | |
1522 | } | |
1523 | ||
cebb7440 LB |
1524 | DEFUN (debug_bgp_allow_martians, |
1525 | debug_bgp_allow_martians_cmd, | |
1526 | "debug bgp allow-martians", | |
1527 | DEBUG_STR | |
1528 | BGP_STR | |
1529 | "BGP allow martian next hops\n") | |
1530 | { | |
1531 | if (vty->node == CONFIG_NODE) | |
1532 | DEBUG_ON (allow_martians, ALLOW_MARTIANS); | |
1533 | else | |
1534 | { | |
1535 | TERM_DEBUG_ON (allow_martians, ALLOW_MARTIANS); | |
1536 | vty_out (vty, "BGP allow_martian next hop debugging is on%s", VTY_NEWLINE); | |
1537 | } | |
1538 | return CMD_SUCCESS; | |
1539 | } | |
1540 | ||
1541 | DEFUN (no_debug_bgp_allow_martians, | |
1542 | no_debug_bgp_allow_martians_cmd, | |
1543 | "no debug bgp allow-martians", | |
1544 | NO_STR | |
1545 | DEBUG_STR | |
1546 | BGP_STR | |
1547 | "BGP allow martian next hops\n") | |
1548 | { | |
1549 | if (vty->node == CONFIG_NODE) | |
1550 | DEBUG_OFF (allow_martians, ALLOW_MARTIANS); | |
1551 | else | |
1552 | { | |
1553 | TERM_DEBUG_OFF (allow_martians, ALLOW_MARTIANS); | |
1554 | vty_out (vty, "BGP allow martian next hop debugging is off%s", VTY_NEWLINE); | |
1555 | } | |
1556 | return CMD_SUCCESS; | |
1557 | } | |
1558 | ||
1559 | ALIAS (no_debug_bgp_allow_martians, | |
1560 | undebug_bgp_allow_martians_cmd, | |
1561 | "undebug bgp allow-martians", | |
1562 | UNDEBUG_STR | |
1563 | BGP_STR | |
1564 | "BGP allow martian next hops\n") | |
1565 | ||
3f9c7369 DS |
1566 | /* debug bgp update-groups */ |
1567 | DEFUN (debug_bgp_update_groups, | |
1568 | debug_bgp_update_groups_cmd, | |
1569 | "debug bgp update-groups", | |
1570 | DEBUG_STR | |
1571 | BGP_STR | |
1572 | "BGP update-groups\n") | |
1573 | { | |
1574 | if (vty->node == CONFIG_NODE) | |
1575 | DEBUG_ON (update_groups, UPDATE_GROUPS); | |
1576 | else | |
1577 | { | |
1578 | TERM_DEBUG_ON (update_groups, UPDATE_GROUPS); | |
1579 | vty_out (vty, "BGP update-groups debugging is on%s", VTY_NEWLINE); | |
1580 | } | |
1581 | return CMD_SUCCESS; | |
1582 | } | |
1583 | ||
1584 | DEFUN (no_debug_bgp_update_groups, | |
1585 | no_debug_bgp_update_groups_cmd, | |
1586 | "no debug bgp update-groups", | |
1587 | NO_STR | |
1588 | DEBUG_STR | |
1589 | BGP_STR | |
1590 | "BGP update-groups\n") | |
1591 | { | |
1592 | if (vty->node == CONFIG_NODE) | |
1593 | DEBUG_OFF (update_groups, UPDATE_GROUPS); | |
1594 | else | |
1595 | { | |
1596 | TERM_DEBUG_OFF (update_groups, UPDATE_GROUPS); | |
1597 | vty_out (vty, "BGP update-groups debugging is off%s", VTY_NEWLINE); | |
1598 | } | |
1599 | return CMD_SUCCESS; | |
1600 | } | |
1601 | ||
16286195 DS |
1602 | DEFUN (no_debug_bgp, |
1603 | no_debug_bgp_cmd, | |
1604 | "no debug bgp", | |
718e3744 | 1605 | NO_STR |
1606 | DEBUG_STR | |
718e3744 | 1607 | BGP_STR) |
1608 | { | |
16286195 DS |
1609 | bgp_debug_list_free(bgp_debug_neighbor_events_peers); |
1610 | bgp_debug_list_free(bgp_debug_keepalive_peers); | |
1611 | bgp_debug_list_free(bgp_debug_update_in_peers); | |
1612 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1613 | bgp_debug_list_free(bgp_debug_update_prefixes); | |
9fbdd100 | 1614 | bgp_debug_list_free(bgp_debug_bestpath_prefixes); |
16286195 DS |
1615 | bgp_debug_list_free(bgp_debug_zebra_prefixes); |
1616 | ||
3f9c7369 DS |
1617 | bgp_debug_clear_updgrp_update_dbg(vty->index); |
1618 | ||
718e3744 | 1619 | TERM_DEBUG_OFF (keepalive, KEEPALIVE); |
1620 | TERM_DEBUG_OFF (update, UPDATE_IN); | |
1621 | TERM_DEBUG_OFF (update, UPDATE_OUT); | |
16286195 | 1622 | TERM_DEBUG_OFF (update, UPDATE_PREFIX); |
9fbdd100 | 1623 | TERM_DEBUG_OFF (bestpath, BESTPATH); |
0b2aa3a0 PJ |
1624 | TERM_DEBUG_OFF (as4, AS4); |
1625 | TERM_DEBUG_OFF (as4, AS4_SEGMENT); | |
16286195 | 1626 | TERM_DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS); |
a39275d7 | 1627 | TERM_DEBUG_OFF (zebra, ZEBRA); |
cebb7440 | 1628 | TERM_DEBUG_OFF (allow_martians, ALLOW_MARTIANS); |
718e3744 | 1629 | vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE); |
1630 | ||
1631 | return CMD_SUCCESS; | |
1632 | } | |
1633 | ||
718e3744 | 1634 | DEFUN (show_debugging_bgp, |
1635 | show_debugging_bgp_cmd, | |
1636 | "show debugging bgp", | |
1637 | SHOW_STR | |
1638 | DEBUG_STR | |
1639 | BGP_STR) | |
1640 | { | |
1641 | vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE); | |
1642 | ||
0b2aa3a0 PJ |
1643 | if (BGP_DEBUG (as4, AS4)) |
1644 | vty_out (vty, " BGP as4 debugging is on%s", VTY_NEWLINE); | |
16286195 | 1645 | |
0b2aa3a0 PJ |
1646 | if (BGP_DEBUG (as4, AS4_SEGMENT)) |
1647 | vty_out (vty, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE); | |
16286195 | 1648 | |
91ba2c8b DS |
1649 | if (BGP_DEBUG (bestpath, BESTPATH)) |
1650 | bgp_debug_list_print (vty, " BGP bestpath debugging is on", | |
1651 | bgp_debug_bestpath_prefixes); | |
16286195 DS |
1652 | |
1653 | if (BGP_DEBUG (keepalive, KEEPALIVE)) | |
1654 | bgp_debug_list_print (vty, " BGP keepalives debugging is on", | |
1655 | bgp_debug_keepalive_peers); | |
1656 | ||
91ba2c8b DS |
1657 | if (BGP_DEBUG (neighbor_events, NEIGHBOR_EVENTS)) |
1658 | bgp_debug_list_print (vty, " BGP neighbor-events debugging is on", | |
1659 | bgp_debug_neighbor_events_peers); | |
1660 | ||
fb018d25 DS |
1661 | if (BGP_DEBUG (nht, NHT)) |
1662 | vty_out (vty, " BGP next-hop tracking debugging is on%s", VTY_NEWLINE); | |
16286195 | 1663 | |
91ba2c8b DS |
1664 | if (BGP_DEBUG (update_groups, UPDATE_GROUPS)) |
1665 | vty_out (vty, " BGP update-groups debugging is on%s", VTY_NEWLINE); | |
1666 | ||
16286195 | 1667 | if (BGP_DEBUG (update, UPDATE_PREFIX)) |
91ba2c8b | 1668 | bgp_debug_list_print (vty, " BGP updates debugging is on", |
16286195 DS |
1669 | bgp_debug_update_prefixes); |
1670 | ||
1671 | if (BGP_DEBUG (update, UPDATE_IN)) | |
1672 | bgp_debug_list_print (vty, " BGP updates debugging is on (inbound)", | |
1673 | bgp_debug_update_in_peers); | |
1674 | ||
1675 | if (BGP_DEBUG (update, UPDATE_OUT)) | |
1676 | bgp_debug_list_print (vty, " BGP updates debugging is on (outbound)", | |
1677 | bgp_debug_update_out_peers); | |
1678 | ||
1679 | if (BGP_DEBUG (zebra, ZEBRA)) | |
1680 | bgp_debug_list_print (vty, " BGP zebra debugging is on", | |
1681 | bgp_debug_zebra_prefixes); | |
1682 | ||
cebb7440 LB |
1683 | if (BGP_DEBUG (allow_martians, ALLOW_MARTIANS)) |
1684 | vty_out (vty, " BGP allow martian next hop debugging is on%s", VTY_NEWLINE); | |
718e3744 | 1685 | vty_out (vty, "%s", VTY_NEWLINE); |
1686 | return CMD_SUCCESS; | |
1687 | } | |
1688 | ||
94f2b392 | 1689 | static int |
718e3744 | 1690 | bgp_config_write_debug (struct vty *vty) |
1691 | { | |
1692 | int write = 0; | |
1693 | ||
0b2aa3a0 PJ |
1694 | if (CONF_BGP_DEBUG (as4, AS4)) |
1695 | { | |
1696 | vty_out (vty, "debug bgp as4%s", VTY_NEWLINE); | |
1697 | write++; | |
1698 | } | |
1699 | ||
1700 | if (CONF_BGP_DEBUG (as4, AS4_SEGMENT)) | |
1701 | { | |
1702 | vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE); | |
1703 | write++; | |
1704 | } | |
1705 | ||
91ba2c8b | 1706 | if (CONF_BGP_DEBUG (bestpath, BESTPATH)) |
718e3744 | 1707 | { |
91ba2c8b DS |
1708 | write += bgp_debug_list_conf_print (vty, "debug bgp bestpath", |
1709 | bgp_debug_bestpath_prefixes); | |
718e3744 | 1710 | } |
1711 | ||
91ba2c8b | 1712 | if (CONF_BGP_DEBUG (keepalive, KEEPALIVE)) |
718e3744 | 1713 | { |
7ef817d9 | 1714 | write += bgp_debug_list_conf_print (vty, "debug bgp keepalives", |
91ba2c8b | 1715 | bgp_debug_keepalive_peers); |
718e3744 | 1716 | } |
91ba2c8b DS |
1717 | |
1718 | if (CONF_BGP_DEBUG (neighbor_events, NEIGHBOR_EVENTS)) | |
718e3744 | 1719 | { |
91ba2c8b DS |
1720 | write += bgp_debug_list_conf_print (vty, "debug bgp neighbor-events", |
1721 | bgp_debug_neighbor_events_peers); | |
718e3744 | 1722 | } |
91ba2c8b DS |
1723 | |
1724 | if (CONF_BGP_DEBUG (nht, NHT)) | |
718e3744 | 1725 | { |
91ba2c8b | 1726 | vty_out (vty, "debug bgp nht%s", VTY_NEWLINE); |
718e3744 | 1727 | write++; |
1728 | } | |
1729 | ||
91ba2c8b | 1730 | if (CONF_BGP_DEBUG (update_groups, UPDATE_GROUPS)) |
9fbdd100 | 1731 | { |
91ba2c8b | 1732 | vty_out (vty, "debug bgp update-groups%s", VTY_NEWLINE); |
9fbdd100 DS |
1733 | write++; |
1734 | } | |
1735 | ||
91ba2c8b | 1736 | if (CONF_BGP_DEBUG (update, UPDATE_PREFIX)) |
718e3744 | 1737 | { |
91ba2c8b DS |
1738 | write += bgp_debug_list_conf_print (vty, "debug bgp updates prefix", |
1739 | bgp_debug_update_prefixes); | |
718e3744 | 1740 | } |
1741 | ||
91ba2c8b | 1742 | if (CONF_BGP_DEBUG (update, UPDATE_IN)) |
a39275d7 | 1743 | { |
91ba2c8b DS |
1744 | write += bgp_debug_list_conf_print (vty, "debug bgp updates in", |
1745 | bgp_debug_update_in_peers); | |
a39275d7 AS |
1746 | } |
1747 | ||
91ba2c8b | 1748 | if (CONF_BGP_DEBUG (update, UPDATE_OUT)) |
fb018d25 | 1749 | { |
91ba2c8b DS |
1750 | write += bgp_debug_list_conf_print (vty, "debug bgp updates out", |
1751 | bgp_debug_update_out_peers); | |
fb018d25 DS |
1752 | } |
1753 | ||
91ba2c8b | 1754 | if (CONF_BGP_DEBUG (zebra, ZEBRA)) |
3f9c7369 | 1755 | { |
91ba2c8b DS |
1756 | if (!bgp_debug_zebra_prefixes || list_isempty(bgp_debug_zebra_prefixes)) |
1757 | { | |
1758 | vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE); | |
1759 | write++; | |
1760 | } | |
1761 | else | |
1762 | { | |
1763 | write += bgp_debug_list_conf_print (vty, "debug bgp zebra prefix", | |
1764 | bgp_debug_zebra_prefixes); | |
1765 | } | |
3f9c7369 DS |
1766 | } |
1767 | ||
cebb7440 LB |
1768 | if (CONF_BGP_DEBUG (allow_martians, ALLOW_MARTIANS)) |
1769 | { | |
1770 | vty_out (vty, "debug bgp allow-martians%s", VTY_NEWLINE); | |
1771 | write++; | |
1772 | } | |
1773 | ||
718e3744 | 1774 | return write; |
1775 | } | |
1776 | ||
7fc626de | 1777 | static struct cmd_node debug_node = |
718e3744 | 1778 | { |
1779 | DEBUG_NODE, | |
1780 | "", | |
1781 | 1 | |
1782 | }; | |
1783 | ||
1784 | void | |
94f2b392 | 1785 | bgp_debug_init (void) |
718e3744 | 1786 | { |
1787 | install_node (&debug_node, bgp_config_write_debug); | |
1788 | ||
1789 | install_element (ENABLE_NODE, &show_debugging_bgp_cmd); | |
1790 | ||
0b2aa3a0 PJ |
1791 | install_element (ENABLE_NODE, &debug_bgp_as4_cmd); |
1792 | install_element (CONFIG_NODE, &debug_bgp_as4_cmd); | |
1793 | install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd); | |
1794 | install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd); | |
1795 | ||
16286195 DS |
1796 | install_element (ENABLE_NODE, &debug_bgp_neighbor_events_cmd); |
1797 | install_element (CONFIG_NODE, &debug_bgp_neighbor_events_cmd); | |
fb018d25 DS |
1798 | install_element (ENABLE_NODE, &debug_bgp_nht_cmd); |
1799 | install_element (CONFIG_NODE, &debug_bgp_nht_cmd); | |
718e3744 | 1800 | install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd); |
1801 | install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd); | |
1802 | install_element (ENABLE_NODE, &debug_bgp_update_cmd); | |
1803 | install_element (CONFIG_NODE, &debug_bgp_update_cmd); | |
a39275d7 AS |
1804 | install_element (ENABLE_NODE, &debug_bgp_zebra_cmd); |
1805 | install_element (CONFIG_NODE, &debug_bgp_zebra_cmd); | |
cebb7440 LB |
1806 | install_element (ENABLE_NODE, &debug_bgp_allow_martians_cmd); |
1807 | install_element (CONFIG_NODE, &debug_bgp_allow_martians_cmd); | |
3f9c7369 DS |
1808 | install_element (ENABLE_NODE, &debug_bgp_update_groups_cmd); |
1809 | install_element (CONFIG_NODE, &debug_bgp_update_groups_cmd); | |
9fbdd100 DS |
1810 | install_element (ENABLE_NODE, &debug_bgp_bestpath_prefix_cmd); |
1811 | install_element (CONFIG_NODE, &debug_bgp_bestpath_prefix_cmd); | |
718e3744 | 1812 | |
91ba2c8b DS |
1813 | /* debug bgp updates (in|out) */ |
1814 | install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd); | |
1815 | install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd); | |
1816 | install_element (ENABLE_NODE, &no_debug_bgp_update_direct_cmd); | |
1817 | install_element (CONFIG_NODE, &no_debug_bgp_update_direct_cmd); | |
1818 | ||
1819 | /* debug bgp updates (in|out) A.B.C.D */ | |
16286195 DS |
1820 | install_element (ENABLE_NODE, &debug_bgp_update_direct_peer_cmd); |
1821 | install_element (CONFIG_NODE, &debug_bgp_update_direct_peer_cmd); | |
1822 | install_element (ENABLE_NODE, &no_debug_bgp_update_direct_peer_cmd); | |
1823 | install_element (CONFIG_NODE, &no_debug_bgp_update_direct_peer_cmd); | |
1824 | ||
91ba2c8b | 1825 | /* debug bgp updates prefix A.B.C.D/M */ |
16286195 DS |
1826 | install_element (ENABLE_NODE, &debug_bgp_update_prefix_cmd); |
1827 | install_element (CONFIG_NODE, &debug_bgp_update_prefix_cmd); | |
1828 | install_element (ENABLE_NODE, &no_debug_bgp_update_prefix_cmd); | |
1829 | install_element (CONFIG_NODE, &no_debug_bgp_update_prefix_cmd); | |
1830 | ||
91ba2c8b | 1831 | /* debug bgp zebra prefix A.B.C.D/M */ |
16286195 DS |
1832 | install_element (ENABLE_NODE, &debug_bgp_zebra_prefix_cmd); |
1833 | install_element (CONFIG_NODE, &debug_bgp_zebra_prefix_cmd); | |
1834 | install_element (ENABLE_NODE, &no_debug_bgp_zebra_prefix_cmd); | |
1835 | install_element (CONFIG_NODE, &no_debug_bgp_zebra_prefix_cmd); | |
1836 | ||
0b2aa3a0 | 1837 | install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd); |
0b2aa3a0 PJ |
1838 | install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd); |
1839 | install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd); | |
0b2aa3a0 PJ |
1840 | install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd); |
1841 | ||
91ba2c8b | 1842 | /* debug bgp neighbor-events A.B.C.D */ |
16286195 DS |
1843 | install_element (ENABLE_NODE, &debug_bgp_neighbor_events_peer_cmd); |
1844 | install_element (CONFIG_NODE, &debug_bgp_neighbor_events_peer_cmd); | |
1845 | install_element (ENABLE_NODE, &no_debug_bgp_neighbor_events_peer_cmd); | |
1846 | install_element (CONFIG_NODE, &no_debug_bgp_neighbor_events_peer_cmd); | |
1847 | ||
91ba2c8b | 1848 | /* debug bgp keepalive A.B.C.D */ |
16286195 DS |
1849 | install_element (ENABLE_NODE, &debug_bgp_keepalive_peer_cmd); |
1850 | install_element (CONFIG_NODE, &debug_bgp_keepalive_peer_cmd); | |
1851 | install_element (ENABLE_NODE, &no_debug_bgp_keepalive_peer_cmd); | |
1852 | install_element (CONFIG_NODE, &no_debug_bgp_keepalive_peer_cmd); | |
1853 | ||
1854 | install_element (ENABLE_NODE, &no_debug_bgp_neighbor_events_cmd); | |
1855 | install_element (CONFIG_NODE, &no_debug_bgp_neighbor_events_cmd); | |
fb018d25 | 1856 | install_element (ENABLE_NODE, &no_debug_bgp_nht_cmd); |
fb018d25 | 1857 | install_element (CONFIG_NODE, &no_debug_bgp_nht_cmd); |
718e3744 | 1858 | install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd); |
718e3744 | 1859 | install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd); |
1860 | install_element (ENABLE_NODE, &no_debug_bgp_update_cmd); | |
718e3744 | 1861 | install_element (CONFIG_NODE, &no_debug_bgp_update_cmd); |
a39275d7 | 1862 | install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd); |
a39275d7 | 1863 | install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd); |
cebb7440 LB |
1864 | install_element (ENABLE_NODE, &no_debug_bgp_allow_martians_cmd); |
1865 | install_element (ENABLE_NODE, &undebug_bgp_allow_martians_cmd); | |
1866 | install_element (CONFIG_NODE, &no_debug_bgp_allow_martians_cmd); | |
3f9c7369 DS |
1867 | install_element (ENABLE_NODE, &no_debug_bgp_update_groups_cmd); |
1868 | install_element (CONFIG_NODE, &no_debug_bgp_update_groups_cmd); | |
16286195 | 1869 | install_element (ENABLE_NODE, &no_debug_bgp_cmd); |
9fbdd100 DS |
1870 | install_element (ENABLE_NODE, &no_debug_bgp_bestpath_cmd); |
1871 | install_element (CONFIG_NODE, &no_debug_bgp_bestpath_cmd); | |
1872 | install_element (ENABLE_NODE, &no_debug_bgp_bestpath_prefix_cmd); | |
1873 | install_element (CONFIG_NODE, &no_debug_bgp_bestpath_prefix_cmd); | |
16286195 DS |
1874 | } |
1875 | ||
1876 | /* Return true if this prefix is on the per_prefix_list of prefixes to debug | |
1877 | * for BGP_DEBUG_TYPE | |
1878 | */ | |
1879 | static int | |
1880 | bgp_debug_per_prefix (struct prefix *p, unsigned long term_bgp_debug_type, | |
1881 | unsigned int BGP_DEBUG_TYPE, struct list *per_prefix_list) | |
1882 | { | |
1883 | struct bgp_debug_filter *filter; | |
1884 | struct listnode *node, *nnode; | |
1885 | ||
1886 | if (term_bgp_debug_type & BGP_DEBUG_TYPE) | |
1887 | { | |
1888 | /* We are debugging all prefixes so return true */ | |
1889 | if (!per_prefix_list || list_isempty(per_prefix_list)) | |
1890 | return 1; | |
1891 | ||
1892 | else | |
1893 | { | |
1894 | if (!p) | |
1895 | return 0; | |
1896 | ||
1897 | for (ALL_LIST_ELEMENTS (per_prefix_list, node, nnode, filter)) | |
1898 | if (filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p)) | |
1899 | return 1; | |
1900 | ||
1901 | return 0; | |
1902 | } | |
1903 | } | |
1904 | ||
1905 | return 0; | |
1906 | } | |
1907 | ||
1908 | /* Return true if this peer is on the per_peer_list of peers to debug | |
1909 | * for BGP_DEBUG_TYPE | |
1910 | */ | |
1911 | static int | |
167d390a | 1912 | bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type, |
16286195 DS |
1913 | unsigned int BGP_DEBUG_TYPE, struct list *per_peer_list) |
1914 | { | |
1915 | struct bgp_debug_filter *filter; | |
1916 | struct listnode *node, *nnode; | |
1917 | ||
1918 | if (term_bgp_debug_type & BGP_DEBUG_TYPE) | |
1919 | { | |
1920 | /* We are debugging all peers so return true */ | |
1921 | if (!per_peer_list || list_isempty(per_peer_list)) | |
1922 | return 1; | |
1923 | ||
1924 | else | |
1925 | { | |
167d390a | 1926 | if (!host) |
16286195 DS |
1927 | return 0; |
1928 | ||
1929 | for (ALL_LIST_ELEMENTS (per_peer_list, node, nnode, filter)) | |
167d390a | 1930 | if (strcmp (filter->host, host) == 0) |
16286195 DS |
1931 | return 1; |
1932 | ||
1933 | return 0; | |
1934 | } | |
1935 | } | |
1936 | ||
1937 | return 0; | |
1938 | } | |
1939 | ||
1940 | int | |
1941 | bgp_debug_neighbor_events (struct peer *peer) | |
1942 | { | |
167d390a DS |
1943 | char *host = NULL; |
1944 | ||
1945 | if (peer) | |
1946 | host = peer->host; | |
1947 | ||
1948 | return bgp_debug_per_peer (host, | |
16286195 DS |
1949 | term_bgp_debug_neighbor_events, |
1950 | BGP_DEBUG_NEIGHBOR_EVENTS, | |
1951 | bgp_debug_neighbor_events_peers); | |
1952 | } | |
1953 | ||
1954 | int | |
1955 | bgp_debug_keepalive (struct peer *peer) | |
1956 | { | |
167d390a DS |
1957 | char *host = NULL; |
1958 | ||
1959 | if (peer) | |
1960 | host = peer->host; | |
1961 | ||
1962 | return bgp_debug_per_peer (host, | |
16286195 DS |
1963 | term_bgp_debug_keepalive, |
1964 | BGP_DEBUG_KEEPALIVE, | |
1965 | bgp_debug_keepalive_peers); | |
1966 | } | |
1967 | ||
1968 | int | |
3f9c7369 DS |
1969 | bgp_debug_update (struct peer *peer, struct prefix *p, |
1970 | struct update_group *updgrp, unsigned int inbound) | |
16286195 | 1971 | { |
167d390a DS |
1972 | char *host = NULL; |
1973 | ||
1974 | if (peer) | |
1975 | host = peer->host; | |
1976 | ||
16286195 DS |
1977 | if (inbound) |
1978 | { | |
167d390a | 1979 | if (bgp_debug_per_peer (host, term_bgp_debug_update, BGP_DEBUG_UPDATE_IN, |
16286195 DS |
1980 | bgp_debug_update_in_peers)) |
1981 | return 1; | |
1982 | } | |
1983 | ||
1984 | /* outbound */ | |
1985 | else | |
1986 | { | |
167d390a | 1987 | if (bgp_debug_per_peer (host, term_bgp_debug_update, |
16286195 DS |
1988 | BGP_DEBUG_UPDATE_OUT, |
1989 | bgp_debug_update_out_peers)) | |
1990 | return 1; | |
3f9c7369 DS |
1991 | |
1992 | /* Check if update debugging implicitly enabled for the group. */ | |
1993 | if (updgrp && UPDGRP_DBG_ON(updgrp)) | |
1994 | return 1; | |
16286195 DS |
1995 | } |
1996 | ||
1997 | ||
1998 | if (BGP_DEBUG (update, UPDATE_PREFIX)) | |
1999 | { | |
2000 | if (bgp_debug_per_prefix (p, term_bgp_debug_update, | |
2001 | BGP_DEBUG_UPDATE_PREFIX, | |
2002 | bgp_debug_update_prefixes)) | |
2003 | return 1; | |
2004 | } | |
2005 | ||
2006 | return 0; | |
2007 | } | |
2008 | ||
9fbdd100 DS |
2009 | int |
2010 | bgp_debug_bestpath (struct prefix *p) | |
2011 | { | |
2012 | if (BGP_DEBUG (bestpath, BESTPATH)) | |
2013 | { | |
2014 | if (bgp_debug_per_prefix (p, term_bgp_debug_bestpath, | |
2015 | BGP_DEBUG_BESTPATH, | |
2016 | bgp_debug_bestpath_prefixes)) | |
2017 | return 1; | |
2018 | } | |
2019 | ||
2020 | return 0; | |
2021 | } | |
2022 | ||
16286195 DS |
2023 | int |
2024 | bgp_debug_zebra (struct prefix *p) | |
2025 | { | |
2026 | if (BGP_DEBUG (zebra, ZEBRA)) | |
2027 | { | |
2028 | if (bgp_debug_per_prefix (p, term_bgp_debug_zebra, BGP_DEBUG_ZEBRA, | |
2029 | bgp_debug_zebra_prefixes)) | |
2030 | return 1; | |
2031 | } | |
2032 | ||
2033 | return 0; | |
718e3744 | 2034 | } |