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