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