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