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