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