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