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