]>
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" | |
81cf0de5 CS |
45 | #include "bgpd/bgp_evpn_private.h" |
46 | #include "bgpd/bgp_vty.h" | |
268e1b9b | 47 | #include "bgpd/bgp_flowspec.h" |
718e3744 | 48 | |
0b2aa3a0 | 49 | unsigned long conf_bgp_debug_as4; |
16286195 | 50 | unsigned long conf_bgp_debug_neighbor_events; |
718e3744 | 51 | unsigned long conf_bgp_debug_events; |
52 | unsigned long conf_bgp_debug_packet; | |
53 | unsigned long conf_bgp_debug_filter; | |
54 | unsigned long conf_bgp_debug_keepalive; | |
55 | unsigned long conf_bgp_debug_update; | |
9fbdd100 | 56 | unsigned long conf_bgp_debug_bestpath; |
a39275d7 | 57 | unsigned long conf_bgp_debug_zebra; |
cebb7440 | 58 | unsigned long conf_bgp_debug_allow_martians; |
fb018d25 | 59 | unsigned long conf_bgp_debug_nht; |
3f9c7369 | 60 | unsigned long conf_bgp_debug_update_groups; |
ddb5b488 | 61 | unsigned long conf_bgp_debug_vpn; |
268e1b9b | 62 | unsigned long conf_bgp_debug_flowspec; |
955bfd98 | 63 | unsigned long conf_bgp_debug_labelpool; |
1a80fc0f | 64 | unsigned long conf_bgp_debug_pbr; |
718e3744 | 65 | |
0b2aa3a0 | 66 | unsigned long term_bgp_debug_as4; |
16286195 | 67 | unsigned long term_bgp_debug_neighbor_events; |
718e3744 | 68 | unsigned long term_bgp_debug_events; |
69 | unsigned long term_bgp_debug_packet; | |
70 | unsigned long term_bgp_debug_filter; | |
71 | unsigned long term_bgp_debug_keepalive; | |
72 | unsigned long term_bgp_debug_update; | |
9fbdd100 | 73 | unsigned long term_bgp_debug_bestpath; |
a39275d7 | 74 | unsigned long term_bgp_debug_zebra; |
cebb7440 | 75 | unsigned long term_bgp_debug_allow_martians; |
fb018d25 | 76 | unsigned long term_bgp_debug_nht; |
3f9c7369 | 77 | unsigned long term_bgp_debug_update_groups; |
ddb5b488 | 78 | unsigned long term_bgp_debug_vpn; |
268e1b9b | 79 | unsigned long term_bgp_debug_flowspec; |
955bfd98 | 80 | unsigned long term_bgp_debug_labelpool; |
1a80fc0f | 81 | unsigned long term_bgp_debug_pbr; |
718e3744 | 82 | |
16286195 DS |
83 | struct list *bgp_debug_neighbor_events_peers = NULL; |
84 | struct list *bgp_debug_keepalive_peers = NULL; | |
85 | struct list *bgp_debug_update_out_peers = NULL; | |
86 | struct list *bgp_debug_update_in_peers = NULL; | |
87 | struct list *bgp_debug_update_prefixes = NULL; | |
9fbdd100 | 88 | struct list *bgp_debug_bestpath_prefixes = NULL; |
16286195 DS |
89 | struct list *bgp_debug_zebra_prefixes = NULL; |
90 | ||
718e3744 | 91 | /* messages for BGP-4 status */ |
d62a17ae | 92 | const struct message bgp_status_msg[] = {{Idle, "Idle"}, |
93 | {Connect, "Connect"}, | |
94 | {Active, "Active"}, | |
95 | {OpenSent, "OpenSent"}, | |
96 | {OpenConfirm, "OpenConfirm"}, | |
97 | {Established, "Established"}, | |
98 | {Clearing, "Clearing"}, | |
99 | {Deleted, "Deleted"}, | |
100 | {0}}; | |
718e3744 | 101 | |
102 | /* BGP message type string. */ | |
d62a17ae | 103 | const char *bgp_type_str[] = {NULL, "OPEN", "UPDATE", |
104 | "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH", | |
105 | "CAPABILITY"}; | |
718e3744 | 106 | |
107 | /* message for BGP-4 Notify */ | |
d62a17ae | 108 | static const struct message bgp_notify_msg[] = { |
109 | {BGP_NOTIFY_HEADER_ERR, "Message Header Error"}, | |
110 | {BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"}, | |
111 | {BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"}, | |
112 | {BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"}, | |
113 | {BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"}, | |
114 | {BGP_NOTIFY_CEASE, "Cease"}, | |
115 | {BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"}, | |
116 | {0}}; | |
117 | ||
118 | static const struct message bgp_notify_head_msg[] = { | |
119 | {BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"}, | |
120 | {BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"}, | |
121 | {BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}, | |
122 | {0}}; | |
123 | ||
124 | static const struct message bgp_notify_open_msg[] = { | |
125 | {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, | |
126 | {BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number"}, | |
127 | {BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"}, | |
128 | {BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"}, | |
129 | {BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"}, | |
130 | {BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"}, | |
131 | {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"}, | |
132 | {BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"}, | |
133 | {0}}; | |
134 | ||
135 | static const struct message bgp_notify_update_msg[] = { | |
136 | {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, | |
137 | {BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"}, | |
138 | {BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"}, | |
139 | {BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"}, | |
140 | {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"}, | |
141 | {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"}, | |
142 | {BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"}, | |
143 | {BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"}, | |
144 | {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"}, | |
145 | {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"}, | |
146 | {BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"}, | |
147 | {BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"}, | |
148 | {0}}; | |
149 | ||
150 | static const struct message bgp_notify_cease_msg[] = { | |
151 | {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, | |
152 | {BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"}, | |
153 | {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"}, | |
154 | {BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"}, | |
155 | {BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"}, | |
156 | {BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"}, | |
157 | {BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"}, | |
158 | {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, | |
159 | "/Connection collision resolution"}, | |
160 | {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"}, | |
161 | {0}}; | |
162 | ||
163 | static const struct message bgp_notify_capability_msg[] = { | |
164 | {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"}, | |
165 | {BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value"}, | |
166 | {BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"}, | |
167 | {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"}, | |
168 | {0}}; | |
718e3744 | 169 | |
170 | /* Origin strings. */ | |
d62a17ae | 171 | const char *bgp_origin_str[] = {"i", "e", "?"}; |
172 | const char *bgp_origin_long_str[] = {"IGP", "EGP", "incomplete"}; | |
718e3744 | 173 | |
81cf0de5 CS |
174 | static int bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, |
175 | struct prefix *p); | |
16286195 | 176 | /* Given a string return a pointer the corresponding peer structure */ |
d62a17ae | 177 | static struct peer *bgp_find_peer(struct vty *vty, const char *peer_str) |
16286195 | 178 | { |
d62a17ae | 179 | struct bgp *bgp = VTY_GET_CONTEXT(bgp); |
180 | int ret; | |
181 | union sockunion su; | |
182 | struct peer *peer; | |
183 | ||
184 | if (!bgp) { | |
185 | return NULL; | |
186 | } | |
187 | ret = str2sockunion(peer_str, &su); | |
188 | ||
189 | /* 'swpX' string */ | |
190 | if (ret < 0) { | |
191 | peer = peer_lookup_by_conf_if(bgp, peer_str); | |
192 | ||
193 | if (!peer) | |
194 | peer = peer_lookup_by_hostname(bgp, peer_str); | |
195 | ||
196 | return peer; | |
197 | } else | |
198 | return peer_lookup(bgp, &su); | |
16286195 DS |
199 | } |
200 | ||
d62a17ae | 201 | static void bgp_debug_list_free(struct list *list) |
16286195 | 202 | { |
d62a17ae | 203 | struct bgp_debug_filter *filter; |
204 | struct listnode *node, *nnode; | |
16286195 | 205 | |
d62a17ae | 206 | if (list) |
207 | for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { | |
208 | listnode_delete(list, filter); | |
16286195 | 209 | |
d62a17ae | 210 | if (filter->p) |
211 | prefix_free(filter->p); | |
16286195 | 212 | |
d62a17ae | 213 | if (filter->host) |
214 | XFREE(MTYPE_BGP_DEBUG_STR, filter->host); | |
16286195 | 215 | |
d62a17ae | 216 | XFREE(MTYPE_BGP_DEBUG_FILTER, filter); |
217 | } | |
16286195 DS |
218 | } |
219 | ||
29a643ca QY |
220 | /* |
221 | * Print the desc along with a list of peers/prefixes this debug is | |
222 | * enabled for | |
223 | */ | |
d62a17ae | 224 | static void bgp_debug_list_print(struct vty *vty, const char *desc, |
29a643ca | 225 | struct list *list) |
d62a17ae | 226 | { |
227 | struct bgp_debug_filter *filter; | |
228 | struct listnode *node, *nnode; | |
81cf0de5 | 229 | char buf[PREFIX2STR_BUFFER]; |
d62a17ae | 230 | |
231 | vty_out(vty, "%s", desc); | |
232 | ||
233 | if (list && !list_isempty(list)) { | |
234 | vty_out(vty, " for"); | |
235 | for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { | |
236 | if (filter->host) | |
237 | vty_out(vty, " %s", filter->host); | |
238 | ||
29a643ca QY |
239 | if (filter->p && filter->p->family == AF_EVPN) |
240 | bgp_debug_print_evpn_prefix(vty, "", filter->p); | |
241 | else if (filter->p) { | |
242 | prefix2str(filter->p, buf, sizeof(buf)); | |
243 | vty_out(vty, " %s", buf); | |
81cf0de5 | 244 | } |
d62a17ae | 245 | } |
246 | } | |
247 | ||
248 | vty_out(vty, "\n"); | |
16286195 DS |
249 | } |
250 | ||
29a643ca QY |
251 | /* |
252 | * Print the command to enable the debug for each peer/prefix this debug is | |
91ba2c8b DS |
253 | * enabled for |
254 | */ | |
d62a17ae | 255 | static int bgp_debug_list_conf_print(struct vty *vty, const char *desc, |
29a643ca | 256 | struct list *list) |
d62a17ae | 257 | { |
258 | struct bgp_debug_filter *filter; | |
259 | struct listnode *node, *nnode; | |
81cf0de5 | 260 | char buf[PREFIX2STR_BUFFER]; |
d62a17ae | 261 | int write = 0; |
262 | ||
263 | if (list && !list_isempty(list)) { | |
264 | for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { | |
265 | if (filter->host) { | |
266 | vty_out(vty, "%s %s\n", desc, filter->host); | |
267 | write++; | |
268 | } | |
269 | ||
29a643ca QY |
270 | if (filter->p && filter->p->family == AF_EVPN) { |
271 | bgp_debug_print_evpn_prefix(vty, desc, | |
272 | filter->p); | |
273 | write++; | |
274 | } else if (filter->p) { | |
275 | prefix2str(filter->p, buf, sizeof(buf)); | |
276 | vty_out(vty, "%s %s\n", desc, buf); | |
277 | write++; | |
d62a17ae | 278 | } |
279 | } | |
280 | } | |
281 | ||
282 | if (!write) { | |
283 | vty_out(vty, "%s\n", desc); | |
284 | write++; | |
285 | } | |
286 | ||
287 | return write; | |
91ba2c8b DS |
288 | } |
289 | ||
d62a17ae | 290 | static void bgp_debug_list_add_entry(struct list *list, const char *host, |
291 | const struct prefix *p) | |
16286195 | 292 | { |
d62a17ae | 293 | struct bgp_debug_filter *filter; |
294 | ||
295 | filter = XCALLOC(MTYPE_BGP_DEBUG_FILTER, | |
296 | sizeof(struct bgp_debug_filter)); | |
297 | ||
298 | if (host) { | |
299 | filter->host = XSTRDUP(MTYPE_BGP_DEBUG_STR, host); | |
300 | filter->p = NULL; | |
301 | } else if (p) { | |
302 | filter->host = NULL; | |
303 | filter->p = prefix_new(); | |
304 | prefix_copy(filter->p, p); | |
305 | } | |
306 | ||
307 | listnode_add(list, filter); | |
16286195 DS |
308 | } |
309 | ||
d62a17ae | 310 | static int bgp_debug_list_remove_entry(struct list *list, const char *host, |
311 | struct prefix *p) | |
312 | { | |
313 | struct bgp_debug_filter *filter; | |
314 | struct listnode *node, *nnode; | |
315 | ||
316 | for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { | |
317 | if (host && strcmp(filter->host, host) == 0) { | |
318 | listnode_delete(list, filter); | |
319 | XFREE(MTYPE_BGP_DEBUG_STR, filter->host); | |
320 | XFREE(MTYPE_BGP_DEBUG_FILTER, filter); | |
321 | return 1; | |
322 | } else if (p && filter->p->prefixlen == p->prefixlen | |
323 | && prefix_match(filter->p, p)) { | |
324 | listnode_delete(list, filter); | |
325 | prefix_free(filter->p); | |
326 | XFREE(MTYPE_BGP_DEBUG_FILTER, filter); | |
327 | return 1; | |
328 | } | |
329 | } | |
330 | ||
331 | return 0; | |
16286195 DS |
332 | } |
333 | ||
d62a17ae | 334 | static int bgp_debug_list_has_entry(struct list *list, const char *host, |
335 | const struct prefix *p) | |
336 | { | |
337 | struct bgp_debug_filter *filter; | |
338 | struct listnode *node, *nnode; | |
339 | ||
340 | for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { | |
341 | if (host) { | |
342 | if (strcmp(filter->host, host) == 0) { | |
343 | return 1; | |
344 | } | |
345 | } else if (p) { | |
346 | if (filter->p->prefixlen == p->prefixlen | |
347 | && prefix_match(filter->p, p)) { | |
348 | return 1; | |
349 | } | |
350 | } | |
351 | } | |
352 | ||
353 | return 0; | |
16286195 DS |
354 | } |
355 | ||
d62a17ae | 356 | int bgp_debug_peer_updout_enabled(char *host) |
3f9c7369 | 357 | { |
d62a17ae | 358 | return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, |
359 | NULL)); | |
3f9c7369 DS |
360 | } |
361 | ||
718e3744 | 362 | /* Dump attribute. */ |
d62a17ae | 363 | int bgp_dump_attr(struct attr *attr, char *buf, size_t size) |
718e3744 | 364 | { |
d62a17ae | 365 | char addrbuf[BUFSIZ]; |
718e3744 | 366 | |
d62a17ae | 367 | if (!attr) |
368 | return 0; | |
369 | ||
370 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) | |
371 | snprintf(buf, size, "nexthop %s", inet_ntoa(attr->nexthop)); | |
372 | ||
373 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN))) | |
374 | snprintf(buf + strlen(buf), size - strlen(buf), ", origin %s", | |
375 | bgp_origin_str[attr->origin]); | |
376 | ||
377 | /* Add MP case. */ | |
378 | if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL | |
379 | || attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) | |
380 | snprintf(buf + strlen(buf), size - strlen(buf), | |
381 | ", mp_nexthop %s", | |
382 | inet_ntop(AF_INET6, &attr->mp_nexthop_global, addrbuf, | |
383 | BUFSIZ)); | |
384 | ||
385 | if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) | |
386 | snprintf(buf + strlen(buf), size - strlen(buf), "(%s)", | |
387 | inet_ntop(AF_INET6, &attr->mp_nexthop_local, addrbuf, | |
388 | BUFSIZ)); | |
389 | ||
390 | if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) | |
391 | snprintf(buf, size, "nexthop %s", inet_ntoa(attr->nexthop)); | |
392 | ||
393 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))) | |
394 | snprintf(buf + strlen(buf), size - strlen(buf), | |
395 | ", localpref %u", attr->local_pref); | |
396 | ||
397 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))) | |
398 | snprintf(buf + strlen(buf), size - strlen(buf), ", metric %u", | |
399 | attr->med); | |
400 | ||
401 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES))) | |
402 | snprintf(buf + strlen(buf), size - strlen(buf), | |
a4d82a8a PZ |
403 | ", community %s", |
404 | community_str(attr->community, false)); | |
d62a17ae | 405 | |
406 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) | |
407 | snprintf(buf + strlen(buf), size - strlen(buf), | |
408 | ", extcommunity %s", ecommunity_str(attr->ecommunity)); | |
409 | ||
410 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))) | |
411 | snprintf(buf + strlen(buf), size - strlen(buf), | |
412 | ", atomic-aggregate"); | |
413 | ||
414 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))) | |
415 | snprintf(buf + strlen(buf), size - strlen(buf), | |
416 | ", aggregated by %u %s", attr->aggregator_as, | |
417 | inet_ntoa(attr->aggregator_addr)); | |
418 | ||
419 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))) | |
420 | snprintf(buf + strlen(buf), size - strlen(buf), | |
421 | ", originator %s", inet_ntoa(attr->originator_id)); | |
422 | ||
423 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) { | |
424 | int i; | |
425 | ||
426 | snprintf(buf + strlen(buf), size - strlen(buf), | |
427 | ", clusterlist"); | |
428 | for (i = 0; i < attr->cluster->length / 4; i++) | |
429 | snprintf(buf + strlen(buf), size - strlen(buf), " %s", | |
430 | inet_ntoa(attr->cluster->list[i])); | |
431 | } | |
432 | ||
7fd077aa | 433 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL))) |
052ea98b | 434 | snprintf(buf + strlen(buf), size - strlen(buf), |
435 | ", pmsi tnltype %u", attr->pmsi_tnl_type); | |
7fd077aa | 436 | |
d62a17ae | 437 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH))) |
438 | snprintf(buf + strlen(buf), size - strlen(buf), ", path %s", | |
439 | aspath_print(attr->aspath)); | |
440 | ||
441 | if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))) { | |
442 | if (attr->label_index != BGP_INVALID_LABEL_INDEX) | |
443 | snprintf(buf + strlen(buf), size - strlen(buf), | |
444 | ", label-index %u", attr->label_index); | |
445 | } | |
446 | ||
447 | if (strlen(buf) > 1) | |
448 | return 1; | |
449 | else | |
450 | return 0; | |
3a8c7ba1 | 451 | } |
718e3744 | 452 | |
d62a17ae | 453 | const char *bgp_notify_code_str(char code) |
3a8c7ba1 | 454 | { |
d62a17ae | 455 | return lookup_msg(bgp_notify_msg, code, "Unrecognized Error Code"); |
456 | } | |
718e3744 | 457 | |
d62a17ae | 458 | const char *bgp_notify_subcode_str(char code, char subcode) |
459 | { | |
460 | ||
461 | switch (code) { | |
462 | case BGP_NOTIFY_HEADER_ERR: | |
463 | return lookup_msg(bgp_notify_head_msg, subcode, | |
464 | "Unrecognized Error Subcode"); | |
465 | case BGP_NOTIFY_OPEN_ERR: | |
466 | return lookup_msg(bgp_notify_open_msg, subcode, | |
467 | "Unrecognized Error Subcode"); | |
468 | case BGP_NOTIFY_UPDATE_ERR: | |
469 | return lookup_msg(bgp_notify_update_msg, subcode, | |
470 | "Unrecognized Error Subcode"); | |
471 | case BGP_NOTIFY_HOLD_ERR: | |
472 | break; | |
473 | case BGP_NOTIFY_FSM_ERR: | |
474 | break; | |
475 | case BGP_NOTIFY_CEASE: | |
476 | return lookup_msg(bgp_notify_cease_msg, subcode, | |
477 | "Unrecognized Error Subcode"); | |
478 | case BGP_NOTIFY_CAPABILITY_ERR: | |
479 | return lookup_msg(bgp_notify_capability_msg, subcode, | |
480 | "Unrecognized Error Subcode"); | |
481 | } | |
482 | return ""; | |
3a8c7ba1 DW |
483 | } |
484 | ||
38de8d02 | 485 | /* extract notify admin reason if correctly present */ |
d7c0a89a | 486 | const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data, |
d62a17ae | 487 | size_t datalen) |
38de8d02 | 488 | { |
d62a17ae | 489 | if (!data || datalen < 1) |
490 | return NULL; | |
38de8d02 | 491 | |
d7c0a89a | 492 | uint8_t len = data[0]; |
d62a17ae | 493 | if (len > 128 || len > datalen - 1) |
494 | return NULL; | |
38de8d02 | 495 | |
d62a17ae | 496 | return zlog_sanitize(buf, bufsz, data + 1, len); |
38de8d02 DL |
497 | } |
498 | ||
3a8c7ba1 | 499 | /* dump notify packet */ |
d62a17ae | 500 | void bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, |
501 | const char *direct) | |
502 | { | |
503 | const char *subcode_str; | |
504 | const char *code_str; | |
505 | const char *msg_str = NULL; | |
506 | char msg_buf[1024]; | |
507 | ||
508 | if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS) | |
509 | || bgp_flag_check(peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) { | |
510 | code_str = bgp_notify_code_str(bgp_notify->code); | |
511 | subcode_str = bgp_notify_subcode_str(bgp_notify->code, | |
512 | bgp_notify->subcode); | |
513 | ||
514 | if (bgp_notify->code == BGP_NOTIFY_CEASE | |
515 | && (bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN | |
516 | || bgp_notify->subcode | |
517 | == BGP_NOTIFY_CEASE_ADMIN_RESET)) { | |
518 | msg_str = bgp_notify_admin_message( | |
519 | msg_buf, sizeof(msg_buf), bgp_notify->raw_data, | |
520 | bgp_notify->length); | |
521 | } | |
522 | ||
523 | if (msg_str) { | |
524 | zlog_info( | |
525 | "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"", | |
526 | strcmp(direct, "received") == 0 | |
527 | ? "received from" | |
528 | : "sent to", | |
529 | peer->host, bgp_notify->code, | |
530 | bgp_notify->subcode, code_str, subcode_str, | |
531 | msg_str); | |
532 | } else { | |
533 | msg_str = bgp_notify->data ? bgp_notify->data : ""; | |
534 | zlog_info( | |
535 | "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s", | |
536 | strcmp(direct, "received") == 0 | |
537 | ? "received from" | |
538 | : "sent to", | |
539 | peer->host, bgp_notify->code, | |
540 | bgp_notify->subcode, code_str, subcode_str, | |
541 | bgp_notify->length, msg_str); | |
542 | } | |
543 | } | |
718e3744 | 544 | } |
6b0655a2 | 545 | |
d62a17ae | 546 | static void bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp) |
3f9c7369 | 547 | { |
d62a17ae | 548 | if (!bgp) |
549 | bgp = bgp_get_default(); | |
550 | update_group_walk(bgp, update_group_clear_update_dbg, NULL); | |
3f9c7369 DS |
551 | } |
552 | ||
81cf0de5 CS |
553 | static int bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, |
554 | struct prefix *p) | |
555 | { | |
556 | char evpn_desc[PREFIX2STR_BUFFER + INET_ADDRSTRLEN]; | |
557 | char buf[PREFIX2STR_BUFFER]; | |
558 | char buf2[ETHER_ADDR_STRLEN]; | |
559 | ||
560 | if (p->u.prefix_evpn.route_type == BGP_EVPN_MAC_IP_ROUTE) { | |
561 | if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)p)) { | |
562 | sprintf(evpn_desc, "l2vpn evpn type macip mac %s", | |
563 | prefix_mac2str( | |
564 | &p->u.prefix_evpn.macip_addr.mac, | |
565 | buf2, sizeof(buf2))); | |
566 | } else { | |
567 | uint8_t family = is_evpn_prefix_ipaddr_v4( | |
568 | (struct prefix_evpn *)p) ? | |
569 | AF_INET : AF_INET6; | |
570 | sprintf(evpn_desc, "l2vpn evpn type macip mac %s ip %s", | |
571 | prefix_mac2str( | |
572 | &p->u.prefix_evpn.macip_addr.mac, | |
573 | buf2, sizeof(buf2)), | |
574 | inet_ntop(family, | |
575 | &p->u.prefix_evpn.macip_addr.ip.ip.addr, | |
576 | buf, PREFIX2STR_BUFFER)); | |
577 | } | |
578 | } else if (p->u.prefix_evpn.route_type == BGP_EVPN_IMET_ROUTE) { | |
579 | sprintf(evpn_desc, "l2vpn evpn type multicast ip %s", | |
580 | inet_ntoa(p->u.prefix_evpn.imet_addr.ip.ipaddr_v4)); | |
581 | } else if (p->u.prefix_evpn.route_type == BGP_EVPN_IP_PREFIX_ROUTE) { | |
582 | uint8_t family = is_evpn_prefix_ipaddr_v4( | |
583 | (struct prefix_evpn *)p) ? AF_INET | |
584 | : AF_INET6; | |
585 | sprintf(evpn_desc, "l2vpn evpn type prefix ip %s/%d", | |
586 | inet_ntop(family, | |
587 | &p->u.prefix_evpn.prefix_addr.ip.ip.addr, buf, | |
588 | PREFIX2STR_BUFFER), | |
589 | p->u.prefix_evpn.prefix_addr.ip_prefix_length); | |
590 | } | |
591 | ||
592 | vty_out(vty, "%s %s\n", desc, evpn_desc); | |
593 | ||
594 | return 0; | |
595 | } | |
596 | ||
597 | static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv, | |
598 | int argc, struct prefix **argv_pp) | |
599 | { | |
600 | struct prefix *argv_p; | |
601 | struct ethaddr mac; | |
602 | struct ipaddr ip; | |
603 | int evpn_type; | |
604 | int type_idx = 0; | |
605 | int mac_idx = 0; | |
606 | int ip_idx = 0; | |
607 | ||
608 | argv_p = *argv_pp; | |
609 | ||
610 | if (argv_find(argv, argc, "type", &type_idx) == 0) | |
611 | return CMD_WARNING; | |
612 | ||
613 | if (strncmp(argv[type_idx + 1]->arg, "ma", 2) == 0) | |
614 | evpn_type = BGP_EVPN_MAC_IP_ROUTE; | |
615 | else if (strncmp(argv[type_idx + 1]->arg, "mu", 2) == 0) | |
616 | evpn_type = BGP_EVPN_IMET_ROUTE; | |
617 | else if (strncmp(argv[type_idx + 1]->arg, "pr", 2) == 0) | |
618 | evpn_type = BGP_EVPN_IP_PREFIX_ROUTE; | |
619 | else | |
620 | evpn_type = 0; | |
621 | ||
622 | if (evpn_type == BGP_EVPN_MAC_IP_ROUTE) { | |
623 | memset(&ip, 0, sizeof(struct ipaddr)); | |
624 | /* get the ip if specified */ | |
625 | if (argv_find(argv, argc, "ip", &ip_idx)) { | |
626 | if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) { | |
627 | vty_out(vty, "%% Malformed IP address\n"); | |
628 | return CMD_WARNING; | |
629 | } | |
630 | } | |
631 | argv_find(argv, argc, "mac", &mac_idx); | |
632 | if (!prefix_str2mac(argv[mac_idx + 1]->arg, &mac)) { | |
633 | vty_out(vty, "%% Malformed MAC address\n"); | |
634 | return CMD_WARNING; | |
635 | } | |
636 | ||
637 | build_evpn_type2_prefix((struct prefix_evpn *)argv_p, | |
638 | &mac, &ip); | |
639 | } else if (evpn_type == BGP_EVPN_IMET_ROUTE) { | |
640 | memset(&ip, 0, sizeof(struct ipaddr)); | |
641 | /* get the ip if specified */ | |
642 | if (argv_find(argv, argc, "ip", &ip_idx)) { | |
643 | if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) { | |
644 | vty_out(vty, "%% Malformed IP address\n"); | |
645 | return CMD_WARNING; | |
646 | } | |
647 | } | |
648 | build_evpn_type3_prefix((struct prefix_evpn *)argv_p, | |
649 | ip.ipaddr_v4); | |
650 | } else if (evpn_type == BGP_EVPN_IP_PREFIX_ROUTE) { | |
651 | struct prefix ip_prefix; | |
652 | ||
653 | memset(&ip_prefix, 0, sizeof(struct prefix)); | |
654 | if (argv_find(argv, argc, "ip", &ip_idx)) { | |
655 | (void)str2prefix(argv[ip_idx + 1]->arg, &ip_prefix); | |
656 | apply_mask(&ip_prefix); | |
657 | } | |
658 | build_type5_prefix_from_ip_prefix( | |
659 | (struct prefix_evpn *)argv_p, | |
660 | &ip_prefix); | |
661 | } | |
662 | ||
663 | return CMD_SUCCESS; | |
664 | } | |
3f9c7369 | 665 | |
718e3744 | 666 | /* Debug option setting interface. */ |
667 | unsigned long bgp_debug_option = 0; | |
668 | ||
d62a17ae | 669 | int debug(unsigned int option) |
718e3744 | 670 | { |
d62a17ae | 671 | return bgp_debug_option & option; |
718e3744 | 672 | } |
673 | ||
0b2aa3a0 PJ |
674 | DEFUN (debug_bgp_as4, |
675 | debug_bgp_as4_cmd, | |
676 | "debug bgp as4", | |
677 | DEBUG_STR | |
678 | BGP_STR | |
679 | "BGP AS4 actions\n") | |
680 | { | |
d62a17ae | 681 | if (vty->node == CONFIG_NODE) |
682 | DEBUG_ON(as4, AS4); | |
683 | else { | |
684 | TERM_DEBUG_ON(as4, AS4); | |
685 | vty_out(vty, "BGP as4 debugging is on\n"); | |
686 | } | |
687 | return CMD_SUCCESS; | |
0b2aa3a0 PJ |
688 | } |
689 | ||
690 | DEFUN (no_debug_bgp_as4, | |
691 | no_debug_bgp_as4_cmd, | |
692 | "no debug bgp as4", | |
693 | NO_STR | |
694 | DEBUG_STR | |
695 | BGP_STR | |
696 | "BGP AS4 actions\n") | |
697 | { | |
d62a17ae | 698 | if (vty->node == CONFIG_NODE) |
699 | DEBUG_OFF(as4, AS4); | |
700 | else { | |
701 | TERM_DEBUG_OFF(as4, AS4); | |
702 | vty_out(vty, "BGP as4 debugging is off\n"); | |
703 | } | |
704 | return CMD_SUCCESS; | |
0b2aa3a0 PJ |
705 | } |
706 | ||
0b2aa3a0 PJ |
707 | DEFUN (debug_bgp_as4_segment, |
708 | debug_bgp_as4_segment_cmd, | |
709 | "debug bgp as4 segment", | |
710 | DEBUG_STR | |
711 | BGP_STR | |
6e22b901 | 712 | "BGP AS4 actions\n" |
0b2aa3a0 PJ |
713 | "BGP AS4 aspath segment handling\n") |
714 | { | |
d62a17ae | 715 | if (vty->node == CONFIG_NODE) |
716 | DEBUG_ON(as4, AS4_SEGMENT); | |
717 | else { | |
718 | TERM_DEBUG_ON(as4, AS4_SEGMENT); | |
719 | vty_out(vty, "BGP as4 segment debugging is on\n"); | |
720 | } | |
721 | return CMD_SUCCESS; | |
0b2aa3a0 PJ |
722 | } |
723 | ||
724 | DEFUN (no_debug_bgp_as4_segment, | |
725 | no_debug_bgp_as4_segment_cmd, | |
726 | "no debug bgp as4 segment", | |
727 | NO_STR | |
728 | DEBUG_STR | |
729 | BGP_STR | |
6e22b901 | 730 | "BGP AS4 actions\n" |
0b2aa3a0 PJ |
731 | "BGP AS4 aspath segment handling\n") |
732 | { | |
d62a17ae | 733 | if (vty->node == CONFIG_NODE) |
734 | DEBUG_OFF(as4, AS4_SEGMENT); | |
735 | else { | |
736 | TERM_DEBUG_OFF(as4, AS4_SEGMENT); | |
737 | vty_out(vty, "BGP as4 segment debugging is off\n"); | |
738 | } | |
739 | return CMD_SUCCESS; | |
0b2aa3a0 PJ |
740 | } |
741 | ||
16286195 DS |
742 | /* debug bgp neighbor_events */ |
743 | DEFUN (debug_bgp_neighbor_events, | |
744 | debug_bgp_neighbor_events_cmd, | |
745 | "debug bgp neighbor-events", | |
718e3744 | 746 | DEBUG_STR |
747 | BGP_STR | |
16286195 | 748 | "BGP Neighbor Events\n") |
718e3744 | 749 | { |
d62a17ae | 750 | bgp_debug_list_free(bgp_debug_neighbor_events_peers); |
751 | ||
752 | if (vty->node == CONFIG_NODE) | |
753 | DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS); | |
754 | else { | |
755 | TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS); | |
756 | vty_out(vty, "BGP neighbor-events debugging is on\n"); | |
757 | } | |
758 | return CMD_SUCCESS; | |
718e3744 | 759 | } |
760 | ||
16286195 DS |
761 | DEFUN (debug_bgp_neighbor_events_peer, |
762 | debug_bgp_neighbor_events_peer_cmd, | |
6147e2c6 | 763 | "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>", |
718e3744 | 764 | DEBUG_STR |
765 | BGP_STR | |
16286195 DS |
766 | "BGP Neighbor Events\n" |
767 | "BGP neighbor IP address to debug\n" | |
768 | "BGP IPv6 neighbor to debug\n" | |
769 | "BGP neighbor on interface to debug\n") | |
718e3744 | 770 | { |
d62a17ae | 771 | int idx_peer = 3; |
772 | const char *host = argv[idx_peer]->arg; | |
773 | ||
774 | if (!bgp_debug_neighbor_events_peers) | |
775 | bgp_debug_neighbor_events_peers = list_new(); | |
776 | ||
777 | if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host, | |
778 | NULL)) { | |
779 | vty_out(vty, | |
780 | "BGP neighbor-events debugging is already enabled for %s\n", | |
781 | host); | |
782 | return CMD_SUCCESS; | |
783 | } | |
784 | ||
785 | bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL); | |
786 | ||
787 | if (vty->node == CONFIG_NODE) | |
788 | DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS); | |
789 | else { | |
790 | TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS); | |
791 | vty_out(vty, "BGP neighbor-events debugging is on for %s\n", | |
792 | host); | |
793 | } | |
794 | return CMD_SUCCESS; | |
718e3744 | 795 | } |
796 | ||
16286195 DS |
797 | DEFUN (no_debug_bgp_neighbor_events, |
798 | no_debug_bgp_neighbor_events_cmd, | |
799 | "no debug bgp neighbor-events", | |
800 | NO_STR | |
718e3744 | 801 | DEBUG_STR |
802 | BGP_STR | |
16286195 | 803 | "Neighbor Events\n") |
718e3744 | 804 | { |
d62a17ae | 805 | bgp_debug_list_free(bgp_debug_neighbor_events_peers); |
806 | ||
807 | if (vty->node == CONFIG_NODE) | |
808 | DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS); | |
809 | else { | |
810 | TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS); | |
811 | vty_out(vty, "BGP neighbor-events debugging is off\n"); | |
812 | } | |
813 | return CMD_SUCCESS; | |
718e3744 | 814 | } |
815 | ||
16286195 DS |
816 | DEFUN (no_debug_bgp_neighbor_events_peer, |
817 | no_debug_bgp_neighbor_events_peer_cmd, | |
6147e2c6 | 818 | "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>", |
718e3744 | 819 | NO_STR |
820 | DEBUG_STR | |
821 | BGP_STR | |
16286195 DS |
822 | "Neighbor Events\n" |
823 | "BGP neighbor IP address to debug\n" | |
824 | "BGP IPv6 neighbor to debug\n" | |
825 | "BGP neighbor on interface to debug\n") | |
718e3744 | 826 | { |
d62a17ae | 827 | int idx_peer = 4; |
828 | int found_peer = 0; | |
829 | const char *host = argv[idx_peer]->arg; | |
830 | ||
831 | if (bgp_debug_neighbor_events_peers | |
832 | && !list_isempty(bgp_debug_neighbor_events_peers)) { | |
833 | found_peer = bgp_debug_list_remove_entry( | |
834 | bgp_debug_neighbor_events_peers, host, NULL); | |
835 | ||
836 | if (list_isempty(bgp_debug_neighbor_events_peers)) { | |
837 | if (vty->node == CONFIG_NODE) | |
838 | DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS); | |
839 | else | |
840 | TERM_DEBUG_OFF(neighbor_events, | |
841 | NEIGHBOR_EVENTS); | |
842 | } | |
843 | } | |
844 | ||
845 | if (found_peer) | |
846 | vty_out(vty, "BGP neighbor-events debugging is off for %s\n", | |
847 | host); | |
848 | else | |
849 | vty_out(vty, | |
850 | "BGP neighbor-events debugging was not enabled for %s\n", | |
851 | host); | |
852 | ||
853 | return CMD_SUCCESS; | |
718e3744 | 854 | } |
855 | ||
16286195 | 856 | /* debug bgp nht */ |
fb018d25 DS |
857 | DEFUN (debug_bgp_nht, |
858 | debug_bgp_nht_cmd, | |
859 | "debug bgp nht", | |
860 | DEBUG_STR | |
861 | BGP_STR | |
862 | "BGP nexthop tracking events\n") | |
863 | { | |
d62a17ae | 864 | if (vty->node == CONFIG_NODE) |
865 | DEBUG_ON(nht, NHT); | |
866 | else { | |
867 | TERM_DEBUG_ON(nht, NHT); | |
868 | vty_out(vty, "BGP nexthop tracking debugging is on\n"); | |
869 | } | |
870 | return CMD_SUCCESS; | |
fb018d25 DS |
871 | } |
872 | ||
873 | DEFUN (no_debug_bgp_nht, | |
874 | no_debug_bgp_nht_cmd, | |
875 | "no debug bgp nht", | |
876 | NO_STR | |
877 | DEBUG_STR | |
878 | BGP_STR | |
879 | "BGP nexthop tracking events\n") | |
880 | { | |
d62a17ae | 881 | if (vty->node == CONFIG_NODE) |
882 | DEBUG_OFF(nht, NHT); | |
883 | else { | |
884 | TERM_DEBUG_OFF(nht, NHT); | |
885 | vty_out(vty, "BGP nexthop tracking debugging is off\n"); | |
886 | } | |
887 | return CMD_SUCCESS; | |
fb018d25 DS |
888 | } |
889 | ||
16286195 DS |
890 | /* debug bgp keepalives */ |
891 | DEFUN (debug_bgp_keepalive, | |
892 | debug_bgp_keepalive_cmd, | |
893 | "debug bgp keepalives", | |
718e3744 | 894 | DEBUG_STR |
895 | BGP_STR | |
16286195 | 896 | "BGP keepalives\n") |
718e3744 | 897 | { |
d62a17ae | 898 | bgp_debug_list_free(bgp_debug_keepalive_peers); |
899 | ||
900 | if (vty->node == CONFIG_NODE) | |
901 | DEBUG_ON(keepalive, KEEPALIVE); | |
902 | else { | |
903 | TERM_DEBUG_ON(keepalive, KEEPALIVE); | |
904 | vty_out(vty, "BGP keepalives debugging is on\n"); | |
905 | } | |
906 | return CMD_SUCCESS; | |
718e3744 | 907 | } |
908 | ||
16286195 DS |
909 | DEFUN (debug_bgp_keepalive_peer, |
910 | debug_bgp_keepalive_peer_cmd, | |
6147e2c6 | 911 | "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>", |
718e3744 | 912 | DEBUG_STR |
913 | BGP_STR | |
16286195 DS |
914 | "BGP Neighbor Events\n" |
915 | "BGP neighbor IP address to debug\n" | |
916 | "BGP IPv6 neighbor to debug\n" | |
917 | "BGP neighbor on interface to debug\n") | |
718e3744 | 918 | { |
d62a17ae | 919 | int idx_peer = 3; |
920 | const char *host = argv[idx_peer]->arg; | |
921 | ||
922 | if (!bgp_debug_keepalive_peers) | |
923 | bgp_debug_keepalive_peers = list_new(); | |
924 | ||
925 | if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL)) { | |
926 | vty_out(vty, | |
927 | "BGP keepalive debugging is already enabled for %s\n", | |
928 | host); | |
929 | return CMD_SUCCESS; | |
930 | } | |
931 | ||
932 | bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL); | |
933 | ||
934 | if (vty->node == CONFIG_NODE) | |
935 | DEBUG_ON(keepalive, KEEPALIVE); | |
936 | else { | |
937 | TERM_DEBUG_ON(keepalive, KEEPALIVE); | |
938 | vty_out(vty, "BGP keepalives debugging is on for %s\n", host); | |
939 | } | |
940 | return CMD_SUCCESS; | |
718e3744 | 941 | } |
942 | ||
943 | DEFUN (no_debug_bgp_keepalive, | |
944 | no_debug_bgp_keepalive_cmd, | |
945 | "no debug bgp keepalives", | |
946 | NO_STR | |
947 | DEBUG_STR | |
948 | BGP_STR | |
949 | "BGP keepalives\n") | |
950 | { | |
d62a17ae | 951 | bgp_debug_list_free(bgp_debug_keepalive_peers); |
952 | ||
953 | if (vty->node == CONFIG_NODE) | |
954 | DEBUG_OFF(keepalive, KEEPALIVE); | |
955 | else { | |
956 | TERM_DEBUG_OFF(keepalive, KEEPALIVE); | |
957 | vty_out(vty, "BGP keepalives debugging is off\n"); | |
958 | } | |
959 | return CMD_SUCCESS; | |
718e3744 | 960 | } |
961 | ||
16286195 DS |
962 | DEFUN (no_debug_bgp_keepalive_peer, |
963 | no_debug_bgp_keepalive_peer_cmd, | |
6147e2c6 | 964 | "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>", |
16286195 DS |
965 | NO_STR |
966 | DEBUG_STR | |
718e3744 | 967 | BGP_STR |
16286195 DS |
968 | "BGP keepalives\n" |
969 | "BGP neighbor IP address to debug\n" | |
970 | "BGP IPv6 neighbor to debug\n" | |
971 | "BGP neighbor on interface to debug\n") | |
972 | { | |
d62a17ae | 973 | int idx_peer = 4; |
974 | int found_peer = 0; | |
975 | const char *host = argv[idx_peer]->arg; | |
976 | ||
977 | if (bgp_debug_keepalive_peers | |
978 | && !list_isempty(bgp_debug_keepalive_peers)) { | |
979 | found_peer = bgp_debug_list_remove_entry( | |
980 | bgp_debug_keepalive_peers, host, NULL); | |
981 | ||
982 | if (list_isempty(bgp_debug_keepalive_peers)) { | |
983 | if (vty->node == CONFIG_NODE) | |
984 | DEBUG_OFF(keepalive, KEEPALIVE); | |
985 | else | |
986 | TERM_DEBUG_OFF(keepalive, KEEPALIVE); | |
987 | } | |
988 | } | |
989 | ||
990 | if (found_peer) | |
991 | vty_out(vty, "BGP keepalives debugging is off for %s\n", host); | |
992 | else | |
993 | vty_out(vty, | |
994 | "BGP keepalives debugging was not enabled for %s\n", | |
995 | host); | |
996 | ||
997 | return CMD_SUCCESS; | |
16286195 DS |
998 | } |
999 | ||
9fbdd100 | 1000 | /* debug bgp bestpath */ |
ffd71765 | 1001 | DEFUN (debug_bgp_bestpath_prefix, |
9fbdd100 | 1002 | debug_bgp_bestpath_prefix_cmd, |
ffd71765 | 1003 | "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>", |
9fbdd100 DS |
1004 | DEBUG_STR |
1005 | BGP_STR | |
1006 | "BGP bestpath\n" | |
0c7b1b01 QY |
1007 | "IPv4 prefix\n" |
1008 | "IPv6 prefix\n") | |
9fbdd100 | 1009 | { |
0be4b77c DW |
1010 | struct prefix *argv_p; |
1011 | int idx_ipv4_ipv6_prefixlen = 3; | |
1012 | ||
1013 | argv_p = prefix_new(); | |
ffd71765 | 1014 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); |
0be4b77c DW |
1015 | apply_mask(argv_p); |
1016 | ||
d62a17ae | 1017 | if (!bgp_debug_bestpath_prefixes) |
1018 | bgp_debug_bestpath_prefixes = list_new(); | |
1019 | ||
1020 | if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL, | |
ffd71765 | 1021 | argv_p)) { |
d62a17ae | 1022 | vty_out(vty, |
1023 | "BGP bestpath debugging is already enabled for %s\n", | |
ffd71765 | 1024 | argv[idx_ipv4_ipv6_prefixlen]->arg); |
d62a17ae | 1025 | return CMD_SUCCESS; |
1026 | } | |
1027 | ||
ffd71765 | 1028 | bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, argv_p); |
d62a17ae | 1029 | |
1030 | if (vty->node == CONFIG_NODE) { | |
1031 | DEBUG_ON(bestpath, BESTPATH); | |
1032 | } else { | |
1033 | TERM_DEBUG_ON(bestpath, BESTPATH); | |
1034 | vty_out(vty, "BGP bestpath debugging is on for %s\n", | |
ffd71765 | 1035 | argv[idx_ipv4_ipv6_prefixlen]->arg); |
d62a17ae | 1036 | } |
1037 | ||
1038 | return CMD_SUCCESS; | |
9fbdd100 DS |
1039 | } |
1040 | ||
1041 | DEFUN (no_debug_bgp_bestpath_prefix, | |
1042 | no_debug_bgp_bestpath_prefix_cmd, | |
6147e2c6 | 1043 | "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>", |
9fbdd100 DS |
1044 | NO_STR |
1045 | DEBUG_STR | |
1046 | BGP_STR | |
1047 | "BGP bestpath\n" | |
0c7b1b01 QY |
1048 | "IPv4 prefix\n" |
1049 | "IPv6 prefix\n") | |
9fbdd100 | 1050 | { |
d62a17ae | 1051 | int idx_ipv4_ipv6_prefixlen = 4; |
1052 | struct prefix *argv_p; | |
1053 | int found_prefix = 0; | |
d62a17ae | 1054 | |
1055 | argv_p = prefix_new(); | |
ffd71765 | 1056 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); |
0be4b77c | 1057 | apply_mask(argv_p); |
d62a17ae | 1058 | |
1059 | if (bgp_debug_bestpath_prefixes | |
1060 | && !list_isempty(bgp_debug_bestpath_prefixes)) { | |
1061 | found_prefix = bgp_debug_list_remove_entry( | |
1062 | bgp_debug_bestpath_prefixes, NULL, argv_p); | |
1063 | ||
1064 | if (list_isempty(bgp_debug_bestpath_prefixes)) { | |
1065 | if (vty->node == CONFIG_NODE) { | |
1066 | DEBUG_OFF(bestpath, BESTPATH); | |
1067 | } else { | |
1068 | TERM_DEBUG_OFF(bestpath, BESTPATH); | |
1069 | vty_out(vty, | |
1070 | "BGP bestpath debugging (per prefix) is off\n"); | |
1071 | } | |
1072 | } | |
1073 | } | |
1074 | ||
1075 | if (found_prefix) | |
1076 | vty_out(vty, "BGP bestpath debugging is off for %s\n", | |
1077 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1078 | else | |
1079 | vty_out(vty, "BGP bestpath debugging was not enabled for %s\n", | |
1080 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1081 | ||
1082 | return CMD_SUCCESS; | |
9fbdd100 DS |
1083 | } |
1084 | ||
1085 | DEFUN (no_debug_bgp_bestpath, | |
1086 | no_debug_bgp_bestpath_cmd, | |
1087 | "no debug bgp bestpath", | |
1088 | NO_STR | |
1089 | DEBUG_STR | |
1090 | BGP_STR | |
1091 | "BGP bestpath\n") | |
1092 | { | |
d62a17ae | 1093 | bgp_debug_list_free(bgp_debug_bestpath_prefixes); |
1094 | ||
1095 | if (vty->node == CONFIG_NODE) | |
1096 | DEBUG_OFF(bestpath, BESTPATH); | |
1097 | else { | |
1098 | TERM_DEBUG_OFF(bestpath, BESTPATH); | |
1099 | vty_out(vty, "BGP bestpath debugging is off\n"); | |
1100 | } | |
1101 | return CMD_SUCCESS; | |
9fbdd100 DS |
1102 | } |
1103 | ||
16286195 | 1104 | /* debug bgp updates */ |
718e3744 | 1105 | DEFUN (debug_bgp_update, |
1106 | debug_bgp_update_cmd, | |
1107 | "debug bgp updates", | |
1108 | DEBUG_STR | |
1109 | BGP_STR | |
1110 | "BGP updates\n") | |
1111 | { | |
d62a17ae | 1112 | bgp_debug_list_free(bgp_debug_update_in_peers); |
1113 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1114 | bgp_debug_list_free(bgp_debug_update_prefixes); | |
1115 | ||
1116 | if (vty->node == CONFIG_NODE) { | |
1117 | DEBUG_ON(update, UPDATE_IN); | |
1118 | DEBUG_ON(update, UPDATE_OUT); | |
1119 | } else { | |
1120 | TERM_DEBUG_ON(update, UPDATE_IN); | |
1121 | TERM_DEBUG_ON(update, UPDATE_OUT); | |
1122 | vty_out(vty, "BGP updates debugging is on\n"); | |
1123 | } | |
1124 | return CMD_SUCCESS; | |
718e3744 | 1125 | } |
1126 | ||
1127 | DEFUN (debug_bgp_update_direct, | |
1128 | debug_bgp_update_direct_cmd, | |
6147e2c6 | 1129 | "debug bgp updates <in|out>", |
718e3744 | 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 = 3; |
1137 | ||
1138 | if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) | |
1139 | bgp_debug_list_free(bgp_debug_update_in_peers); | |
1140 | else | |
1141 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1142 | ||
1143 | if (vty->node == CONFIG_NODE) { | |
1144 | if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) | |
1145 | DEBUG_ON(update, UPDATE_IN); | |
1146 | else | |
1147 | DEBUG_ON(update, UPDATE_OUT); | |
1148 | } else { | |
1149 | if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) { | |
1150 | TERM_DEBUG_ON(update, UPDATE_IN); | |
1151 | vty_out(vty, "BGP updates debugging is on (inbound)\n"); | |
1152 | } else { | |
1153 | TERM_DEBUG_ON(update, UPDATE_OUT); | |
1154 | vty_out(vty, | |
1155 | "BGP updates debugging is on (outbound)\n"); | |
1156 | } | |
1157 | } | |
1158 | return CMD_SUCCESS; | |
718e3744 | 1159 | } |
1160 | ||
16286195 DS |
1161 | DEFUN (debug_bgp_update_direct_peer, |
1162 | debug_bgp_update_direct_peer_cmd, | |
6147e2c6 | 1163 | "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>", |
718e3744 | 1164 | DEBUG_STR |
1165 | BGP_STR | |
16286195 DS |
1166 | "BGP updates\n" |
1167 | "Inbound updates\n" | |
1168 | "Outbound updates\n" | |
1169 | "BGP neighbor IP address to debug\n" | |
1170 | "BGP IPv6 neighbor to debug\n" | |
1171 | "BGP neighbor on interface to debug\n") | |
718e3744 | 1172 | { |
d62a17ae | 1173 | int idx_in_out = 3; |
1174 | int idx_peer = 4; | |
1175 | const char *host = argv[idx_peer]->arg; | |
1176 | int inbound; | |
1177 | ||
1178 | if (!bgp_debug_update_in_peers) | |
1179 | bgp_debug_update_in_peers = list_new(); | |
1180 | ||
1181 | if (!bgp_debug_update_out_peers) | |
1182 | bgp_debug_update_out_peers = list_new(); | |
1183 | ||
1184 | if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) | |
1185 | inbound = 1; | |
1186 | else | |
1187 | inbound = 0; | |
1188 | ||
1189 | if (inbound) { | |
1190 | if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, host, | |
1191 | NULL)) { | |
1192 | vty_out(vty, | |
1193 | "BGP inbound update debugging is already enabled for %s\n", | |
1194 | host); | |
1195 | return CMD_SUCCESS; | |
1196 | } | |
1197 | } | |
1198 | ||
1199 | else { | |
1200 | if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, | |
1201 | NULL)) { | |
1202 | vty_out(vty, | |
1203 | "BGP outbound update debugging is already enabled for %s\n", | |
1204 | host); | |
1205 | return CMD_SUCCESS; | |
1206 | } | |
1207 | } | |
1208 | ||
1209 | if (inbound) | |
1210 | bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL); | |
1211 | else { | |
1212 | struct peer *peer; | |
1213 | struct peer_af *paf; | |
1214 | int afidx; | |
1215 | ||
1216 | bgp_debug_list_add_entry(bgp_debug_update_out_peers, host, | |
1217 | NULL); | |
1218 | peer = bgp_find_peer(vty, host); | |
1219 | ||
1220 | if (peer) { | |
1221 | for (afidx = BGP_AF_START; afidx < BGP_AF_MAX; | |
1222 | afidx++) { | |
1223 | paf = peer->peer_af_array[afidx]; | |
1224 | if (paf != NULL) { | |
1225 | if (PAF_SUBGRP(paf)) { | |
1226 | UPDGRP_PEER_DBG_EN( | |
1227 | PAF_SUBGRP(paf) | |
1228 | ->update_group); | |
1229 | } | |
1230 | } | |
1231 | } | |
1232 | } | |
1233 | } | |
1234 | ||
1235 | if (vty->node == CONFIG_NODE) { | |
1236 | if (inbound) | |
1237 | DEBUG_ON(update, UPDATE_IN); | |
1238 | else | |
1239 | DEBUG_ON(update, UPDATE_OUT); | |
1240 | } else { | |
1241 | if (inbound) { | |
1242 | TERM_DEBUG_ON(update, UPDATE_IN); | |
1243 | vty_out(vty, | |
1244 | "BGP updates debugging is on (inbound) for %s\n", | |
1245 | argv[idx_peer]->arg); | |
1246 | } else { | |
1247 | TERM_DEBUG_ON(update, UPDATE_OUT); | |
1248 | vty_out(vty, | |
1249 | "BGP updates debugging is on (outbound) for %s\n", | |
1250 | argv[idx_peer]->arg); | |
1251 | } | |
1252 | } | |
1253 | return CMD_SUCCESS; | |
718e3744 | 1254 | } |
1255 | ||
91ba2c8b DS |
1256 | DEFUN (no_debug_bgp_update_direct, |
1257 | no_debug_bgp_update_direct_cmd, | |
6147e2c6 | 1258 | "no debug bgp updates <in|out>", |
91ba2c8b DS |
1259 | NO_STR |
1260 | DEBUG_STR | |
1261 | BGP_STR | |
1262 | "BGP updates\n" | |
1263 | "Inbound updates\n" | |
1264 | "Outbound updates\n") | |
1265 | { | |
d62a17ae | 1266 | int idx_in_out = 4; |
1267 | if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) { | |
1268 | bgp_debug_list_free(bgp_debug_update_in_peers); | |
1269 | ||
1270 | if (vty->node == CONFIG_NODE) { | |
1271 | DEBUG_OFF(update, UPDATE_IN); | |
1272 | } else { | |
1273 | TERM_DEBUG_OFF(update, UPDATE_IN); | |
1274 | vty_out(vty, | |
1275 | "BGP updates debugging is off (inbound)\n"); | |
1276 | } | |
1277 | } else { | |
1278 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1279 | ||
1280 | if (vty->node == CONFIG_NODE) { | |
1281 | DEBUG_OFF(update, UPDATE_OUT); | |
1282 | } else { | |
1283 | TERM_DEBUG_OFF(update, UPDATE_OUT); | |
1284 | vty_out(vty, | |
1285 | "BGP updates debugging is off (outbound)\n"); | |
1286 | } | |
1287 | } | |
1288 | ||
1289 | return CMD_SUCCESS; | |
91ba2c8b DS |
1290 | } |
1291 | ||
16286195 DS |
1292 | DEFUN (no_debug_bgp_update_direct_peer, |
1293 | no_debug_bgp_update_direct_peer_cmd, | |
6147e2c6 | 1294 | "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>", |
16286195 DS |
1295 | NO_STR |
1296 | DEBUG_STR | |
718e3744 | 1297 | BGP_STR |
16286195 DS |
1298 | "BGP updates\n" |
1299 | "Inbound updates\n" | |
1300 | "Outbound updates\n" | |
1301 | "BGP neighbor IP address to debug\n" | |
1302 | "BGP IPv6 neighbor to debug\n" | |
1303 | "BGP neighbor on interface to debug\n") | |
1304 | { | |
d62a17ae | 1305 | int idx_in_out = 4; |
1306 | int idx_peer = 5; | |
1307 | int inbound; | |
1308 | int found_peer = 0; | |
1309 | const char *host = argv[idx_peer]->arg; | |
1310 | ||
1311 | if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) | |
1312 | inbound = 1; | |
1313 | else | |
1314 | inbound = 0; | |
1315 | ||
1316 | if (inbound && bgp_debug_update_in_peers | |
1317 | && !list_isempty(bgp_debug_update_in_peers)) { | |
1318 | found_peer = bgp_debug_list_remove_entry( | |
1319 | bgp_debug_update_in_peers, host, NULL); | |
1320 | ||
1321 | if (list_isempty(bgp_debug_update_in_peers)) { | |
1322 | if (vty->node == CONFIG_NODE) | |
1323 | DEBUG_OFF(update, UPDATE_IN); | |
1324 | else { | |
1325 | TERM_DEBUG_OFF(update, UPDATE_IN); | |
1326 | vty_out(vty, | |
1327 | "BGP updates debugging (inbound) is off\n"); | |
1328 | } | |
1329 | } | |
1330 | } | |
1331 | ||
1332 | if (!inbound && bgp_debug_update_out_peers | |
1333 | && !list_isempty(bgp_debug_update_out_peers)) { | |
1334 | found_peer = bgp_debug_list_remove_entry( | |
1335 | bgp_debug_update_out_peers, host, NULL); | |
1336 | ||
1337 | if (list_isempty(bgp_debug_update_out_peers)) { | |
1338 | if (vty->node == CONFIG_NODE) | |
1339 | DEBUG_OFF(update, UPDATE_OUT); | |
1340 | else { | |
1341 | TERM_DEBUG_OFF(update, UPDATE_OUT); | |
1342 | vty_out(vty, | |
1343 | "BGP updates debugging (outbound) is off\n"); | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | struct peer *peer; | |
1348 | struct peer_af *paf; | |
1349 | int afidx; | |
1350 | peer = bgp_find_peer(vty, host); | |
1351 | ||
1352 | if (peer) { | |
1353 | for (afidx = BGP_AF_START; afidx < BGP_AF_MAX; | |
1354 | afidx++) { | |
1355 | paf = peer->peer_af_array[afidx]; | |
1356 | if (paf != NULL) { | |
1357 | if (PAF_SUBGRP(paf)) { | |
1358 | UPDGRP_PEER_DBG_DIS( | |
1359 | PAF_SUBGRP(paf) | |
1360 | ->update_group); | |
1361 | } | |
1362 | } | |
1363 | } | |
1364 | } | |
1365 | } | |
1366 | ||
1367 | if (found_peer) | |
1368 | if (inbound) | |
1369 | vty_out(vty, | |
1370 | "BGP updates debugging (inbound) is off for %s\n", | |
1371 | host); | |
1372 | else | |
1373 | vty_out(vty, | |
1374 | "BGP updates debugging (outbound) is off for %s\n", | |
1375 | host); | |
1376 | else if (inbound) | |
1377 | vty_out(vty, | |
1378 | "BGP updates debugging (inbound) was not enabled for %s\n", | |
1379 | host); | |
1380 | else | |
1381 | vty_out(vty, | |
1382 | "BGP updates debugging (outbound) was not enabled for %s\n", | |
1383 | host); | |
1384 | ||
1385 | return CMD_SUCCESS; | |
16286195 DS |
1386 | } |
1387 | ||
81cf0de5 CS |
1388 | #ifndef VTYSH_EXTRACT_PL |
1389 | #include "bgpd/bgp_debug_clippy.c" | |
1390 | #endif | |
1391 | ||
1392 | DEFPY (debug_bgp_update_prefix_afi_safi, | |
1393 | debug_bgp_update_prefix_afi_safi_cmd, | |
1394 | "debug bgp updates prefix <l2vpn>$afi <evpn>$safi type <macip mac WORD [ip WORD]|multicast ip WORD |prefix ip WORD>", | |
1395 | DEBUG_STR | |
1396 | BGP_STR | |
1397 | "BGP updates\n" | |
1398 | "Specify a prefix to debug\n" | |
1399 | "l2vpn\n" | |
1400 | "evpn\n" | |
1401 | "Specify EVPN Route type\n" | |
1402 | "MAC-IP (Type-2) route\n" | |
1403 | "MAC\n" | |
1404 | "MAC address (e.g., 00:e0:ec:20:12:62)\n" | |
1405 | "IP\n" | |
1406 | "IP address (IPv4 or IPv6)\n" | |
1407 | "Multicast (Type-3) route\n" | |
1408 | "IP\n" | |
1409 | "IP address (IPv4 or IPv6)\n" | |
1410 | "Prefix (Type-5) route\n" | |
1411 | "IP\n" | |
1412 | "Prefix route\n") | |
1413 | { | |
1414 | int idx_ipv4_ipv6_prefixlen = 4; | |
1415 | struct prefix *argv_p; | |
1416 | int ret = CMD_SUCCESS; | |
1417 | afi_t afiz; | |
1418 | safi_t safiz; | |
1419 | ||
1420 | argv_p = prefix_new(); | |
1421 | ||
1422 | afiz = bgp_vty_afi_from_str(afi); | |
1423 | safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST; | |
1424 | ||
1425 | /* check for evpn route type */ | |
1426 | if (afiz == AFI_L2VPN && safiz == SAFI_EVPN) { | |
1427 | ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p); | |
1428 | if (ret != CMD_SUCCESS) | |
360f9703 | 1429 | goto cleanup; |
81cf0de5 CS |
1430 | } else { |
1431 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); | |
1432 | apply_mask(argv_p); | |
1433 | } | |
1434 | ||
1435 | if (!bgp_debug_update_prefixes) | |
1436 | bgp_debug_update_prefixes = list_new(); | |
1437 | ||
1438 | if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) { | |
1439 | vty_out(vty, | |
1440 | "BGP updates debugging is already enabled for %s\n", | |
1441 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
360f9703 | 1442 | goto cleanup; |
81cf0de5 CS |
1443 | } |
1444 | ||
1445 | bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p); | |
1446 | ||
1447 | if (vty->node == CONFIG_NODE) { | |
1448 | DEBUG_ON(update, UPDATE_PREFIX); | |
1449 | } else { | |
1450 | TERM_DEBUG_ON(update, UPDATE_PREFIX); | |
1451 | vty_out(vty, "BGP updates debugging is on for %s\n", | |
1452 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1453 | } | |
1454 | ||
360f9703 A |
1455 | cleanup: |
1456 | prefix_free(argv_p); | |
1457 | ||
1458 | return ret; | |
81cf0de5 CS |
1459 | } |
1460 | ||
1461 | DEFPY (no_debug_bgp_update_prefix_afi_safi, | |
1462 | no_debug_bgp_update_prefix_afi_safi_cmd, | |
1463 | "no debug bgp updates prefix <l2vpn>$afi <evpn>$safi type <macip mac WORD [ip WORD]|multicast ip WORD |prefix ip WORD>", | |
1464 | NO_STR | |
1465 | DEBUG_STR | |
1466 | BGP_STR | |
1467 | "BGP updates\n" | |
1468 | "Specify a prefix to debug\n" | |
1469 | "l2vpn\n" | |
1470 | "evpn\n" | |
1471 | "Specify EVPN Route type\n" | |
1472 | "MAC-IP (Type-2) route\n" | |
1473 | "MAC\n" | |
1474 | "MAC address (e.g., 00:e0:ec:20:12:62)\n" | |
1475 | "IP\n" | |
1476 | "IP address (IPv4 or IPv6)\n" | |
1477 | "Multicast (Type-3) route\n" | |
1478 | "IP\n" | |
1479 | "IP address (IPv4 or IPv6)\n" | |
1480 | "Prefix (Type-5) route\n" | |
1481 | "IP\n" | |
1482 | "Prefix route\n") | |
1483 | { | |
1484 | int idx_ipv4_ipv6_prefixlen = 5; | |
1485 | struct prefix *argv_p; | |
1486 | int found_prefix = 0; | |
1487 | int ret = CMD_SUCCESS; | |
1488 | afi_t afiz; | |
1489 | safi_t safiz; | |
1490 | ||
1491 | argv_p = prefix_new(); | |
1492 | ||
1493 | afiz = bgp_vty_afi_from_str(afi); | |
1494 | safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST; | |
1495 | ||
1496 | /* check for evpn route type */ | |
1497 | if (afiz == AFI_L2VPN && safiz == SAFI_EVPN) { | |
1498 | ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p); | |
1499 | if (ret != CMD_SUCCESS) | |
360f9703 | 1500 | goto cleanup; |
81cf0de5 CS |
1501 | } else { |
1502 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); | |
1503 | apply_mask(argv_p); | |
1504 | } | |
1505 | ||
1506 | if (bgp_debug_update_prefixes | |
1507 | && !list_isempty(bgp_debug_update_prefixes)) { | |
1508 | found_prefix = bgp_debug_list_remove_entry( | |
1509 | bgp_debug_update_prefixes, NULL, argv_p); | |
1510 | ||
1511 | if (list_isempty(bgp_debug_update_prefixes)) { | |
1512 | if (vty->node == CONFIG_NODE) { | |
1513 | DEBUG_OFF(update, UPDATE_PREFIX); | |
1514 | } else { | |
1515 | TERM_DEBUG_OFF(update, UPDATE_PREFIX); | |
1516 | vty_out(vty, | |
1517 | "BGP updates debugging (per prefix) is off\n"); | |
1518 | } | |
1519 | } | |
1520 | } | |
1521 | ||
1522 | if (found_prefix) | |
1523 | vty_out(vty, "BGP updates debugging is off for %s\n", | |
1524 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1525 | else | |
1526 | vty_out(vty, "BGP updates debugging was not enabled for %s\n", | |
1527 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1528 | ||
360f9703 A |
1529 | cleanup: |
1530 | prefix_free(argv_p); | |
1531 | ||
1532 | return ret; | |
81cf0de5 CS |
1533 | } |
1534 | ||
1535 | ||
16286195 DS |
1536 | DEFUN (debug_bgp_update_prefix, |
1537 | debug_bgp_update_prefix_cmd, | |
6147e2c6 | 1538 | "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>", |
718e3744 | 1539 | DEBUG_STR |
16286195 DS |
1540 | BGP_STR |
1541 | "BGP updates\n" | |
1542 | "Specify a prefix to debug\n" | |
0c7b1b01 QY |
1543 | "IPv4 prefix\n" |
1544 | "IPv6 prefix\n") | |
718e3744 | 1545 | { |
d62a17ae | 1546 | int idx_ipv4_ipv6_prefixlen = 4; |
1547 | struct prefix *argv_p; | |
d62a17ae | 1548 | |
1549 | argv_p = prefix_new(); | |
ffd71765 | 1550 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); |
0be4b77c | 1551 | apply_mask(argv_p); |
d62a17ae | 1552 | |
1553 | if (!bgp_debug_update_prefixes) | |
1554 | bgp_debug_update_prefixes = list_new(); | |
1555 | ||
1556 | if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) { | |
1557 | vty_out(vty, | |
1558 | "BGP updates debugging is already enabled for %s\n", | |
1559 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1560 | return CMD_SUCCESS; | |
1561 | } | |
1562 | ||
1563 | bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p); | |
1564 | ||
1565 | if (vty->node == CONFIG_NODE) { | |
1566 | DEBUG_ON(update, UPDATE_PREFIX); | |
1567 | } else { | |
1568 | TERM_DEBUG_ON(update, UPDATE_PREFIX); | |
1569 | vty_out(vty, "BGP updates debugging is on for %s\n", | |
1570 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1571 | } | |
1572 | ||
1573 | return CMD_SUCCESS; | |
718e3744 | 1574 | } |
1575 | ||
16286195 DS |
1576 | DEFUN (no_debug_bgp_update_prefix, |
1577 | no_debug_bgp_update_prefix_cmd, | |
6147e2c6 | 1578 | "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>", |
718e3744 | 1579 | NO_STR |
1580 | DEBUG_STR | |
16286195 DS |
1581 | BGP_STR |
1582 | "BGP updates\n" | |
1583 | "Specify a prefix to debug\n" | |
0c7b1b01 QY |
1584 | "IPv4 prefix\n" |
1585 | "IPv6 prefix\n") | |
16286195 | 1586 | { |
d62a17ae | 1587 | int idx_ipv4_ipv6_prefixlen = 5; |
1588 | struct prefix *argv_p; | |
1589 | int found_prefix = 0; | |
d62a17ae | 1590 | |
1591 | argv_p = prefix_new(); | |
ffd71765 | 1592 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); |
0be4b77c | 1593 | apply_mask(argv_p); |
d62a17ae | 1594 | |
1595 | if (bgp_debug_update_prefixes | |
1596 | && !list_isempty(bgp_debug_update_prefixes)) { | |
1597 | found_prefix = bgp_debug_list_remove_entry( | |
1598 | bgp_debug_update_prefixes, NULL, argv_p); | |
1599 | ||
1600 | if (list_isempty(bgp_debug_update_prefixes)) { | |
1601 | if (vty->node == CONFIG_NODE) { | |
1602 | DEBUG_OFF(update, UPDATE_PREFIX); | |
1603 | } else { | |
1604 | TERM_DEBUG_OFF(update, UPDATE_PREFIX); | |
1605 | vty_out(vty, | |
1606 | "BGP updates debugging (per prefix) is off\n"); | |
1607 | } | |
1608 | } | |
1609 | } | |
1610 | ||
1611 | if (found_prefix) | |
1612 | vty_out(vty, "BGP updates debugging is off for %s\n", | |
1613 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1614 | else | |
1615 | vty_out(vty, "BGP updates debugging was not enabled for %s\n", | |
1616 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1617 | ||
1618 | return CMD_SUCCESS; | |
16286195 DS |
1619 | } |
1620 | ||
1621 | DEFUN (no_debug_bgp_update, | |
1622 | no_debug_bgp_update_cmd, | |
1623 | "no debug bgp updates", | |
1624 | NO_STR | |
1625 | DEBUG_STR | |
1626 | BGP_STR | |
1627 | "BGP updates\n") | |
718e3744 | 1628 | { |
87f42c2c QY |
1629 | struct listnode *ln; |
1630 | struct bgp *bgp; | |
1631 | ||
d62a17ae | 1632 | bgp_debug_list_free(bgp_debug_update_in_peers); |
1633 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
1634 | bgp_debug_list_free(bgp_debug_update_prefixes); | |
1635 | ||
87f42c2c QY |
1636 | for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp)) |
1637 | bgp_debug_clear_updgrp_update_dbg(bgp); | |
d62a17ae | 1638 | |
1639 | if (vty->node == CONFIG_NODE) { | |
1640 | DEBUG_OFF(update, UPDATE_IN); | |
1641 | DEBUG_OFF(update, UPDATE_OUT); | |
1642 | DEBUG_OFF(update, UPDATE_PREFIX); | |
1643 | } else { | |
1644 | TERM_DEBUG_OFF(update, UPDATE_IN); | |
1645 | TERM_DEBUG_OFF(update, UPDATE_OUT); | |
1646 | TERM_DEBUG_OFF(update, UPDATE_PREFIX); | |
1647 | vty_out(vty, "BGP updates debugging is off\n"); | |
1648 | } | |
1649 | return CMD_SUCCESS; | |
718e3744 | 1650 | } |
1651 | ||
16286195 | 1652 | /* debug bgp zebra */ |
a39275d7 AS |
1653 | DEFUN (debug_bgp_zebra, |
1654 | debug_bgp_zebra_cmd, | |
1655 | "debug bgp zebra", | |
1656 | DEBUG_STR | |
1657 | BGP_STR | |
1658 | "BGP Zebra messages\n") | |
1659 | { | |
d62a17ae | 1660 | if (vty->node == CONFIG_NODE) |
1661 | DEBUG_ON(zebra, ZEBRA); | |
1662 | else { | |
1663 | TERM_DEBUG_ON(zebra, ZEBRA); | |
1664 | vty_out(vty, "BGP zebra debugging is on\n"); | |
1665 | } | |
1666 | return CMD_SUCCESS; | |
a39275d7 AS |
1667 | } |
1668 | ||
16286195 DS |
1669 | DEFUN (debug_bgp_zebra_prefix, |
1670 | debug_bgp_zebra_prefix_cmd, | |
6147e2c6 | 1671 | "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>", |
16286195 DS |
1672 | DEBUG_STR |
1673 | BGP_STR | |
1674 | "BGP Zebra messages\n" | |
1675 | "Specify a prefix to debug\n" | |
0c7b1b01 QY |
1676 | "IPv4 prefix\n" |
1677 | "IPv6 prefix\n") | |
16286195 | 1678 | { |
d62a17ae | 1679 | int idx_ipv4_ipv6_prefixlen = 4; |
1680 | struct prefix *argv_p; | |
d62a17ae | 1681 | |
1682 | argv_p = prefix_new(); | |
ffd71765 | 1683 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); |
0be4b77c | 1684 | apply_mask(argv_p); |
d62a17ae | 1685 | |
1686 | if (!bgp_debug_zebra_prefixes) | |
1687 | bgp_debug_zebra_prefixes = list_new(); | |
1688 | ||
1689 | if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, argv_p)) { | |
1690 | vty_out(vty, "BGP zebra debugging is already enabled for %s\n", | |
1691 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1692 | return CMD_SUCCESS; | |
1693 | } | |
1694 | ||
1695 | bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, argv_p); | |
1696 | ||
1697 | if (vty->node == CONFIG_NODE) | |
1698 | DEBUG_ON(zebra, ZEBRA); | |
1699 | else { | |
1700 | TERM_DEBUG_ON(zebra, ZEBRA); | |
1701 | vty_out(vty, "BGP zebra debugging is on for %s\n", | |
1702 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1703 | } | |
1704 | ||
1705 | return CMD_SUCCESS; | |
16286195 DS |
1706 | } |
1707 | ||
a39275d7 AS |
1708 | DEFUN (no_debug_bgp_zebra, |
1709 | no_debug_bgp_zebra_cmd, | |
1710 | "no debug bgp zebra", | |
1711 | NO_STR | |
1712 | DEBUG_STR | |
1713 | BGP_STR | |
1714 | "BGP Zebra messages\n") | |
1715 | { | |
d62a17ae | 1716 | bgp_debug_list_free(bgp_debug_zebra_prefixes); |
1717 | ||
1718 | if (vty->node == CONFIG_NODE) | |
1719 | DEBUG_OFF(zebra, ZEBRA); | |
1720 | else { | |
1721 | TERM_DEBUG_OFF(zebra, ZEBRA); | |
1722 | vty_out(vty, "BGP zebra debugging is off\n"); | |
1723 | } | |
1724 | return CMD_SUCCESS; | |
a39275d7 AS |
1725 | } |
1726 | ||
16286195 DS |
1727 | DEFUN (no_debug_bgp_zebra_prefix, |
1728 | no_debug_bgp_zebra_prefix_cmd, | |
6147e2c6 | 1729 | "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>", |
16286195 DS |
1730 | NO_STR |
1731 | DEBUG_STR | |
a39275d7 | 1732 | BGP_STR |
16286195 DS |
1733 | "BGP Zebra messages\n" |
1734 | "Specify a prefix to debug\n" | |
0c7b1b01 QY |
1735 | "IPv4 prefix\n" |
1736 | "IPv6 prefix\n") | |
16286195 | 1737 | { |
d62a17ae | 1738 | int idx_ipv4_ipv6_prefixlen = 5; |
1739 | struct prefix *argv_p; | |
1740 | int found_prefix = 0; | |
d62a17ae | 1741 | |
1742 | argv_p = prefix_new(); | |
ffd71765 | 1743 | (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); |
0be4b77c | 1744 | apply_mask(argv_p); |
d62a17ae | 1745 | |
1746 | if (bgp_debug_zebra_prefixes | |
1747 | && !list_isempty(bgp_debug_zebra_prefixes)) { | |
1748 | found_prefix = bgp_debug_list_remove_entry( | |
1749 | bgp_debug_zebra_prefixes, NULL, argv_p); | |
1750 | ||
1751 | if (list_isempty(bgp_debug_zebra_prefixes)) { | |
1752 | if (vty->node == CONFIG_NODE) | |
1753 | DEBUG_OFF(zebra, ZEBRA); | |
1754 | else { | |
1755 | TERM_DEBUG_OFF(zebra, ZEBRA); | |
1756 | vty_out(vty, "BGP zebra debugging is off\n"); | |
1757 | } | |
1758 | } | |
1759 | } | |
1760 | ||
1761 | if (found_prefix) | |
1762 | vty_out(vty, "BGP zebra debugging is off for %s\n", | |
1763 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1764 | else | |
1765 | vty_out(vty, "BGP zebra debugging was not enabled for %s\n", | |
1766 | argv[idx_ipv4_ipv6_prefixlen]->arg); | |
1767 | ||
1768 | return CMD_SUCCESS; | |
16286195 DS |
1769 | } |
1770 | ||
cebb7440 LB |
1771 | DEFUN (debug_bgp_allow_martians, |
1772 | debug_bgp_allow_martians_cmd, | |
1773 | "debug bgp allow-martians", | |
1774 | DEBUG_STR | |
1775 | BGP_STR | |
1776 | "BGP allow martian next hops\n") | |
1777 | { | |
d62a17ae | 1778 | if (vty->node == CONFIG_NODE) |
1779 | DEBUG_ON(allow_martians, ALLOW_MARTIANS); | |
1780 | else { | |
1781 | TERM_DEBUG_ON(allow_martians, ALLOW_MARTIANS); | |
1782 | vty_out(vty, "BGP allow_martian next hop debugging is on\n"); | |
1783 | } | |
1784 | return CMD_SUCCESS; | |
cebb7440 LB |
1785 | } |
1786 | ||
1787 | DEFUN (no_debug_bgp_allow_martians, | |
1788 | no_debug_bgp_allow_martians_cmd, | |
1789 | "no debug bgp allow-martians", | |
1790 | NO_STR | |
1791 | DEBUG_STR | |
1792 | BGP_STR | |
1793 | "BGP allow martian next hops\n") | |
1794 | { | |
d62a17ae | 1795 | if (vty->node == CONFIG_NODE) |
1796 | DEBUG_OFF(allow_martians, ALLOW_MARTIANS); | |
1797 | else { | |
1798 | TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS); | |
1799 | vty_out(vty, "BGP allow martian next hop debugging is off\n"); | |
1800 | } | |
1801 | return CMD_SUCCESS; | |
cebb7440 LB |
1802 | } |
1803 | ||
cebb7440 | 1804 | |
3f9c7369 DS |
1805 | /* debug bgp update-groups */ |
1806 | DEFUN (debug_bgp_update_groups, | |
1807 | debug_bgp_update_groups_cmd, | |
1808 | "debug bgp update-groups", | |
1809 | DEBUG_STR | |
1810 | BGP_STR | |
1811 | "BGP update-groups\n") | |
1812 | { | |
d62a17ae | 1813 | if (vty->node == CONFIG_NODE) |
1814 | DEBUG_ON(update_groups, UPDATE_GROUPS); | |
1815 | else { | |
1816 | TERM_DEBUG_ON(update_groups, UPDATE_GROUPS); | |
1817 | vty_out(vty, "BGP update-groups debugging is on\n"); | |
1818 | } | |
1819 | return CMD_SUCCESS; | |
3f9c7369 DS |
1820 | } |
1821 | ||
1822 | DEFUN (no_debug_bgp_update_groups, | |
1823 | no_debug_bgp_update_groups_cmd, | |
1824 | "no debug bgp update-groups", | |
1825 | NO_STR | |
1826 | DEBUG_STR | |
1827 | BGP_STR | |
1828 | "BGP update-groups\n") | |
1829 | { | |
d62a17ae | 1830 | if (vty->node == CONFIG_NODE) |
1831 | DEBUG_OFF(update_groups, UPDATE_GROUPS); | |
1832 | else { | |
1833 | TERM_DEBUG_OFF(update_groups, UPDATE_GROUPS); | |
1834 | vty_out(vty, "BGP update-groups debugging is off\n"); | |
1835 | } | |
1836 | return CMD_SUCCESS; | |
3f9c7369 DS |
1837 | } |
1838 | ||
ddb5b488 PZ |
1839 | DEFUN (debug_bgp_vpn, |
1840 | debug_bgp_vpn_cmd, | |
1841 | "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>", | |
1842 | DEBUG_STR | |
1843 | BGP_STR | |
1844 | "VPN routes\n" | |
1845 | "leaked from vrf to vpn\n" | |
1846 | "leaked to vrf from vpn\n" | |
1847 | "route-map updates\n" | |
1848 | "labels\n") | |
1849 | { | |
1850 | int idx = 3; | |
1851 | ||
1852 | if (argv_find(argv, argc, "leak-from-vrf", &idx)) { | |
1853 | if (vty->node == CONFIG_NODE) | |
1854 | DEBUG_ON(vpn, VPN_LEAK_FROM_VRF); | |
1855 | else | |
1856 | TERM_DEBUG_ON(vpn, VPN_LEAK_FROM_VRF); | |
1857 | } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) { | |
1858 | if (vty->node == CONFIG_NODE) | |
1859 | DEBUG_ON(vpn, VPN_LEAK_TO_VRF); | |
1860 | else | |
1861 | TERM_DEBUG_ON(vpn, VPN_LEAK_TO_VRF); | |
1862 | } else if (argv_find(argv, argc, "rmap-event", &idx)) { | |
1863 | if (vty->node == CONFIG_NODE) | |
1864 | DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT); | |
1865 | else | |
1866 | TERM_DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT); | |
1867 | } else if (argv_find(argv, argc, "label", &idx)) { | |
1868 | if (vty->node == CONFIG_NODE) | |
1869 | DEBUG_ON(vpn, VPN_LEAK_LABEL); | |
1870 | else | |
1871 | TERM_DEBUG_ON(vpn, VPN_LEAK_LABEL); | |
1872 | } else { | |
1873 | vty_out(vty, "%% unknown debug bgp vpn keyword\n"); | |
1874 | return CMD_WARNING_CONFIG_FAILED; | |
1875 | } | |
1876 | ||
1877 | if (vty->node != CONFIG_NODE) | |
1878 | vty_out(vty, "enabled debug bgp vpn %s\n", argv[idx]->text); | |
1879 | ||
1880 | return CMD_SUCCESS; | |
1881 | } | |
1882 | ||
1883 | DEFUN (no_debug_bgp_vpn, | |
1884 | no_debug_bgp_vpn_cmd, | |
1885 | "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>", | |
1886 | NO_STR | |
1887 | DEBUG_STR | |
1888 | BGP_STR | |
1889 | "VPN routes\n" | |
1890 | "leaked from vrf to vpn\n" | |
1891 | "leaked to vrf from vpn\n" | |
1892 | "route-map updates\n" | |
1893 | "labels\n") | |
1894 | { | |
1895 | int idx = 4; | |
1896 | ||
1897 | if (argv_find(argv, argc, "leak-from-vrf", &idx)) { | |
1898 | if (vty->node == CONFIG_NODE) | |
1899 | DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF); | |
1900 | else | |
1901 | TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF); | |
1902 | ||
1903 | } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) { | |
1904 | if (vty->node == CONFIG_NODE) | |
1905 | DEBUG_OFF(vpn, VPN_LEAK_TO_VRF); | |
1906 | else | |
1907 | TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF); | |
1908 | } else if (argv_find(argv, argc, "rmap-event", &idx)) { | |
1909 | if (vty->node == CONFIG_NODE) | |
1910 | DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT); | |
1911 | else | |
1912 | TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT); | |
1913 | } else if (argv_find(argv, argc, "label", &idx)) { | |
1914 | if (vty->node == CONFIG_NODE) | |
1915 | DEBUG_OFF(vpn, VPN_LEAK_LABEL); | |
1916 | else | |
1917 | TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL); | |
1918 | } else { | |
1919 | vty_out(vty, "%% unknown debug bgp vpn keyword\n"); | |
1920 | return CMD_WARNING_CONFIG_FAILED; | |
1921 | } | |
1922 | ||
1923 | if (vty->node != CONFIG_NODE) | |
1924 | vty_out(vty, "disabled debug bgp vpn %s\n", argv[idx]->text); | |
1a80fc0f PG |
1925 | return CMD_SUCCESS; |
1926 | } | |
ddb5b488 | 1927 | |
1a80fc0f PG |
1928 | /* debug bgp pbr */ |
1929 | DEFUN (debug_bgp_pbr, | |
1930 | debug_bgp_pbr_cmd, | |
e9d0aa99 | 1931 | "debug bgp pbr [error]", |
1a80fc0f PG |
1932 | DEBUG_STR |
1933 | BGP_STR | |
e9d0aa99 PG |
1934 | "BGP policy based routing\n" |
1935 | "BGP PBR error\n") | |
1a80fc0f | 1936 | { |
e9d0aa99 PG |
1937 | int idx = 3; |
1938 | ||
1939 | if (argv_find(argv, argc, "error", &idx)) { | |
1940 | if (vty->node == CONFIG_NODE) | |
1941 | DEBUG_ON(pbr, PBR_ERROR); | |
1942 | else { | |
1943 | TERM_DEBUG_ON(pbr, PBR_ERROR); | |
1944 | vty_out(vty, "BGP policy based routing error is on\n"); | |
1945 | } | |
1946 | return CMD_SUCCESS; | |
1947 | } | |
1a80fc0f PG |
1948 | if (vty->node == CONFIG_NODE) |
1949 | DEBUG_ON(pbr, PBR); | |
1950 | else { | |
1951 | TERM_DEBUG_ON(pbr, PBR); | |
1952 | vty_out(vty, "BGP policy based routing is on\n"); | |
1953 | } | |
1954 | return CMD_SUCCESS; | |
1955 | } | |
1956 | ||
1957 | DEFUN (no_debug_bgp_pbr, | |
1958 | no_debug_bgp_pbr_cmd, | |
e9d0aa99 | 1959 | "no debug bgp pbr [error]", |
1a80fc0f PG |
1960 | NO_STR |
1961 | DEBUG_STR | |
1962 | BGP_STR | |
e9d0aa99 PG |
1963 | "BGP policy based routing\n" |
1964 | "BGP PBR Error\n") | |
1a80fc0f | 1965 | { |
e9d0aa99 PG |
1966 | int idx = 3; |
1967 | ||
1968 | if (argv_find(argv, argc, "error", &idx)) { | |
1969 | if (vty->node == CONFIG_NODE) | |
1970 | DEBUG_OFF(pbr, PBR_ERROR); | |
1971 | else { | |
1972 | TERM_DEBUG_OFF(pbr, PBR_ERROR); | |
1973 | vty_out(vty, "BGP policy based routing error is off\n"); | |
1974 | } | |
1975 | return CMD_SUCCESS; | |
1976 | } | |
1a80fc0f PG |
1977 | if (vty->node == CONFIG_NODE) |
1978 | DEBUG_OFF(pbr, PBR); | |
1979 | else { | |
1980 | TERM_DEBUG_OFF(pbr, PBR); | |
1981 | vty_out(vty, "BGP policy based routing is off\n"); | |
1982 | } | |
ddb5b488 PZ |
1983 | return CMD_SUCCESS; |
1984 | } | |
1985 | ||
955bfd98 PZ |
1986 | DEFUN (debug_bgp_labelpool, |
1987 | debug_bgp_labelpool_cmd, | |
1988 | "debug bgp labelpool", | |
1989 | DEBUG_STR | |
1990 | BGP_STR | |
1991 | "label pool\n") | |
1992 | { | |
1993 | if (vty->node == CONFIG_NODE) | |
1994 | DEBUG_ON(labelpool, LABELPOOL); | |
1995 | else | |
1996 | TERM_DEBUG_ON(labelpool, LABELPOOL); | |
1997 | ||
1998 | if (vty->node != CONFIG_NODE) | |
1999 | vty_out(vty, "enabled debug bgp labelpool\n"); | |
2000 | ||
2001 | return CMD_SUCCESS; | |
2002 | } | |
2003 | ||
2004 | DEFUN (no_debug_bgp_labelpool, | |
2005 | no_debug_bgp_labelpool_cmd, | |
2006 | "no debug bgp labelpool", | |
2007 | NO_STR | |
2008 | DEBUG_STR | |
2009 | BGP_STR | |
2010 | "label pool\n") | |
2011 | { | |
2012 | if (vty->node == CONFIG_NODE) | |
2013 | DEBUG_OFF(labelpool, LABELPOOL); | |
2014 | else | |
2015 | TERM_DEBUG_OFF(labelpool, LABELPOOL); | |
2016 | ||
2017 | ||
2018 | if (vty->node != CONFIG_NODE) | |
2019 | vty_out(vty, "disabled debug bgp labelpool\n"); | |
2020 | ||
2021 | return CMD_SUCCESS; | |
2022 | } | |
2023 | ||
16286195 DS |
2024 | DEFUN (no_debug_bgp, |
2025 | no_debug_bgp_cmd, | |
2026 | "no debug bgp", | |
718e3744 | 2027 | NO_STR |
2028 | DEBUG_STR | |
718e3744 | 2029 | BGP_STR) |
2030 | { | |
87f42c2c QY |
2031 | struct bgp *bgp; |
2032 | struct listnode *ln; | |
2033 | ||
d62a17ae | 2034 | bgp_debug_list_free(bgp_debug_neighbor_events_peers); |
2035 | bgp_debug_list_free(bgp_debug_keepalive_peers); | |
2036 | bgp_debug_list_free(bgp_debug_update_in_peers); | |
2037 | bgp_debug_list_free(bgp_debug_update_out_peers); | |
2038 | bgp_debug_list_free(bgp_debug_update_prefixes); | |
2039 | bgp_debug_list_free(bgp_debug_bestpath_prefixes); | |
2040 | bgp_debug_list_free(bgp_debug_zebra_prefixes); | |
2041 | ||
87f42c2c QY |
2042 | for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp)) |
2043 | bgp_debug_clear_updgrp_update_dbg(bgp); | |
d62a17ae | 2044 | |
2045 | TERM_DEBUG_OFF(keepalive, KEEPALIVE); | |
2046 | TERM_DEBUG_OFF(update, UPDATE_IN); | |
2047 | TERM_DEBUG_OFF(update, UPDATE_OUT); | |
2048 | TERM_DEBUG_OFF(update, UPDATE_PREFIX); | |
2049 | TERM_DEBUG_OFF(bestpath, BESTPATH); | |
2050 | TERM_DEBUG_OFF(as4, AS4); | |
2051 | TERM_DEBUG_OFF(as4, AS4_SEGMENT); | |
2052 | TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS); | |
2053 | TERM_DEBUG_OFF(zebra, ZEBRA); | |
2054 | TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS); | |
c33b83b3 | 2055 | TERM_DEBUG_OFF(nht, NHT); |
ddb5b488 PZ |
2056 | TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF); |
2057 | TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF); | |
2058 | TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT); | |
2059 | TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL); | |
268e1b9b | 2060 | TERM_DEBUG_OFF(flowspec, FLOWSPEC); |
955bfd98 | 2061 | TERM_DEBUG_OFF(labelpool, LABELPOOL); |
1a80fc0f | 2062 | TERM_DEBUG_OFF(pbr, PBR); |
e9d0aa99 | 2063 | TERM_DEBUG_OFF(pbr, PBR_ERROR); |
d62a17ae | 2064 | vty_out(vty, "All possible debugging has been turned off\n"); |
2065 | ||
2066 | return CMD_SUCCESS; | |
718e3744 | 2067 | } |
2068 | ||
87f6dc50 DS |
2069 | DEFUN_NOSH (show_debugging_bgp, |
2070 | show_debugging_bgp_cmd, | |
2071 | "show debugging [bgp]", | |
2072 | SHOW_STR | |
2073 | DEBUG_STR | |
2074 | BGP_STR) | |
718e3744 | 2075 | { |
d62a17ae | 2076 | vty_out(vty, "BGP debugging status:\n"); |
718e3744 | 2077 | |
d62a17ae | 2078 | if (BGP_DEBUG(as4, AS4)) |
2079 | vty_out(vty, " BGP as4 debugging is on\n"); | |
16286195 | 2080 | |
d62a17ae | 2081 | if (BGP_DEBUG(as4, AS4_SEGMENT)) |
2082 | vty_out(vty, " BGP as4 aspath segment debugging is on\n"); | |
16286195 | 2083 | |
d62a17ae | 2084 | if (BGP_DEBUG(bestpath, BESTPATH)) |
2085 | bgp_debug_list_print(vty, " BGP bestpath debugging is on", | |
29a643ca | 2086 | bgp_debug_bestpath_prefixes); |
16286195 | 2087 | |
d62a17ae | 2088 | if (BGP_DEBUG(keepalive, KEEPALIVE)) |
2089 | bgp_debug_list_print(vty, " BGP keepalives debugging is on", | |
29a643ca | 2090 | bgp_debug_keepalive_peers); |
16286195 | 2091 | |
d62a17ae | 2092 | if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)) |
2093 | bgp_debug_list_print(vty, | |
2094 | " BGP neighbor-events debugging is on", | |
29a643ca | 2095 | bgp_debug_neighbor_events_peers); |
91ba2c8b | 2096 | |
d62a17ae | 2097 | if (BGP_DEBUG(nht, NHT)) |
2098 | vty_out(vty, " BGP next-hop tracking debugging is on\n"); | |
16286195 | 2099 | |
d62a17ae | 2100 | if (BGP_DEBUG(update_groups, UPDATE_GROUPS)) |
2101 | vty_out(vty, " BGP update-groups debugging is on\n"); | |
91ba2c8b | 2102 | |
d62a17ae | 2103 | if (BGP_DEBUG(update, UPDATE_PREFIX)) |
2104 | bgp_debug_list_print(vty, " BGP updates debugging is on", | |
29a643ca | 2105 | bgp_debug_update_prefixes); |
16286195 | 2106 | |
d62a17ae | 2107 | if (BGP_DEBUG(update, UPDATE_IN)) |
2108 | bgp_debug_list_print(vty, | |
2109 | " BGP updates debugging is on (inbound)", | |
29a643ca | 2110 | bgp_debug_update_in_peers); |
16286195 | 2111 | |
d62a17ae | 2112 | if (BGP_DEBUG(update, UPDATE_OUT)) |
2113 | bgp_debug_list_print(vty, | |
2114 | " BGP updates debugging is on (outbound)", | |
29a643ca | 2115 | bgp_debug_update_out_peers); |
16286195 | 2116 | |
d62a17ae | 2117 | if (BGP_DEBUG(zebra, ZEBRA)) |
2118 | bgp_debug_list_print(vty, " BGP zebra debugging is on", | |
29a643ca | 2119 | bgp_debug_zebra_prefixes); |
16286195 | 2120 | |
d62a17ae | 2121 | if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) |
2122 | vty_out(vty, " BGP allow martian next hop debugging is on\n"); | |
ddb5b488 PZ |
2123 | |
2124 | if (BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF)) | |
2125 | vty_out(vty, | |
2126 | " BGP route leak from vrf to vpn debugging is on\n"); | |
2127 | if (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF)) | |
2128 | vty_out(vty, | |
2129 | " BGP route leak to vrf from vpn debugging is on\n"); | |
2130 | if (BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT)) | |
2131 | vty_out(vty, " BGP vpn route-map event debugging is on\n"); | |
2132 | if (BGP_DEBUG(vpn, VPN_LEAK_LABEL)) | |
2133 | vty_out(vty, " BGP vpn label event debugging is on\n"); | |
268e1b9b PG |
2134 | if (BGP_DEBUG(flowspec, FLOWSPEC)) |
2135 | vty_out(vty, " BGP flowspec debugging is on\n"); | |
955bfd98 PZ |
2136 | if (BGP_DEBUG(labelpool, LABELPOOL)) |
2137 | vty_out(vty, " BGP labelpool debugging is on\n"); | |
ddb5b488 | 2138 | |
1a80fc0f PG |
2139 | if (BGP_DEBUG(pbr, PBR)) |
2140 | vty_out(vty, " BGP policy based routing debugging is on\n"); | |
e9d0aa99 PG |
2141 | if (BGP_DEBUG(pbr, PBR_ERROR)) |
2142 | vty_out(vty, " BGP policy based routing error debugging is on\n"); | |
1a80fc0f | 2143 | |
d62a17ae | 2144 | vty_out(vty, "\n"); |
2145 | return CMD_SUCCESS; | |
718e3744 | 2146 | } |
2147 | ||
90dcf2d7 | 2148 | /* return count of number of debug flags set */ |
d62a17ae | 2149 | int bgp_debug_count(void) |
90dcf2d7 | 2150 | { |
d62a17ae | 2151 | int ret = 0; |
2152 | if (BGP_DEBUG(as4, AS4)) | |
2153 | ret++; | |
90dcf2d7 | 2154 | |
d62a17ae | 2155 | if (BGP_DEBUG(as4, AS4_SEGMENT)) |
2156 | ret++; | |
90dcf2d7 | 2157 | |
d62a17ae | 2158 | if (BGP_DEBUG(bestpath, BESTPATH)) |
2159 | ret++; | |
90dcf2d7 | 2160 | |
d62a17ae | 2161 | if (BGP_DEBUG(keepalive, KEEPALIVE)) |
2162 | ret++; | |
90dcf2d7 | 2163 | |
d62a17ae | 2164 | if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)) |
2165 | ret++; | |
90dcf2d7 | 2166 | |
d62a17ae | 2167 | if (BGP_DEBUG(nht, NHT)) |
2168 | ret++; | |
90dcf2d7 | 2169 | |
d62a17ae | 2170 | if (BGP_DEBUG(update_groups, UPDATE_GROUPS)) |
2171 | ret++; | |
90dcf2d7 | 2172 | |
d62a17ae | 2173 | if (BGP_DEBUG(update, UPDATE_PREFIX)) |
2174 | ret++; | |
90dcf2d7 | 2175 | |
d62a17ae | 2176 | if (BGP_DEBUG(update, UPDATE_IN)) |
2177 | ret++; | |
90dcf2d7 | 2178 | |
d62a17ae | 2179 | if (BGP_DEBUG(update, UPDATE_OUT)) |
2180 | ret++; | |
90dcf2d7 | 2181 | |
d62a17ae | 2182 | if (BGP_DEBUG(zebra, ZEBRA)) |
2183 | ret++; | |
90dcf2d7 | 2184 | |
d62a17ae | 2185 | if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) |
2186 | ret++; | |
90dcf2d7 | 2187 | |
ddb5b488 PZ |
2188 | if (BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF)) |
2189 | ret++; | |
2190 | if (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF)) | |
2191 | ret++; | |
2192 | if (BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT)) | |
2193 | ret++; | |
2194 | if (BGP_DEBUG(vpn, VPN_LEAK_LABEL)) | |
2195 | ret++; | |
268e1b9b PG |
2196 | if (BGP_DEBUG(flowspec, FLOWSPEC)) |
2197 | ret++; | |
955bfd98 PZ |
2198 | if (BGP_DEBUG(labelpool, LABELPOOL)) |
2199 | ret++; | |
ddb5b488 | 2200 | |
1a80fc0f PG |
2201 | if (BGP_DEBUG(pbr, PBR)) |
2202 | ret++; | |
e9d0aa99 PG |
2203 | if (BGP_DEBUG(pbr, PBR_ERROR)) |
2204 | ret++; | |
1a80fc0f | 2205 | |
d62a17ae | 2206 | return ret; |
90dcf2d7 LB |
2207 | } |
2208 | ||
d62a17ae | 2209 | static int bgp_config_write_debug(struct vty *vty) |
718e3744 | 2210 | { |
d62a17ae | 2211 | int write = 0; |
718e3744 | 2212 | |
d62a17ae | 2213 | if (CONF_BGP_DEBUG(as4, AS4)) { |
2214 | vty_out(vty, "debug bgp as4\n"); | |
2215 | write++; | |
2216 | } | |
718e3744 | 2217 | |
d62a17ae | 2218 | if (CONF_BGP_DEBUG(as4, AS4_SEGMENT)) { |
2219 | vty_out(vty, "debug bgp as4 segment\n"); | |
2220 | write++; | |
2221 | } | |
16286195 | 2222 | |
d62a17ae | 2223 | if (CONF_BGP_DEBUG(bestpath, BESTPATH)) { |
2224 | write += bgp_debug_list_conf_print(vty, "debug bgp bestpath", | |
29a643ca | 2225 | bgp_debug_bestpath_prefixes); |
d62a17ae | 2226 | } |
2227 | ||
2228 | if (CONF_BGP_DEBUG(keepalive, KEEPALIVE)) { | |
2229 | write += bgp_debug_list_conf_print(vty, "debug bgp keepalives", | |
29a643ca | 2230 | bgp_debug_keepalive_peers); |
d62a17ae | 2231 | } |
2232 | ||
2233 | if (CONF_BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)) { | |
2234 | write += bgp_debug_list_conf_print( | |
2235 | vty, "debug bgp neighbor-events", | |
29a643ca | 2236 | bgp_debug_neighbor_events_peers); |
d62a17ae | 2237 | } |
2238 | ||
2239 | if (CONF_BGP_DEBUG(nht, NHT)) { | |
2240 | vty_out(vty, "debug bgp nht\n"); | |
2241 | write++; | |
2242 | } | |
2243 | ||
2244 | if (CONF_BGP_DEBUG(update_groups, UPDATE_GROUPS)) { | |
2245 | vty_out(vty, "debug bgp update-groups\n"); | |
2246 | write++; | |
2247 | } | |
2248 | ||
2249 | if (CONF_BGP_DEBUG(update, UPDATE_PREFIX)) { | |
2250 | write += bgp_debug_list_conf_print(vty, | |
2251 | "debug bgp updates prefix", | |
29a643ca | 2252 | bgp_debug_update_prefixes); |
d62a17ae | 2253 | } |
2254 | ||
2255 | if (CONF_BGP_DEBUG(update, UPDATE_IN)) { | |
2256 | write += bgp_debug_list_conf_print(vty, "debug bgp updates in", | |
29a643ca | 2257 | bgp_debug_update_in_peers); |
d62a17ae | 2258 | } |
2259 | ||
2260 | if (CONF_BGP_DEBUG(update, UPDATE_OUT)) { | |
2261 | write += bgp_debug_list_conf_print(vty, "debug bgp updates out", | |
29a643ca | 2262 | bgp_debug_update_out_peers); |
d62a17ae | 2263 | } |
16286195 | 2264 | |
d62a17ae | 2265 | if (CONF_BGP_DEBUG(zebra, ZEBRA)) { |
2266 | if (!bgp_debug_zebra_prefixes | |
2267 | || list_isempty(bgp_debug_zebra_prefixes)) { | |
2268 | vty_out(vty, "debug bgp zebra\n"); | |
2269 | write++; | |
2270 | } else { | |
2271 | write += bgp_debug_list_conf_print( | |
2272 | vty, "debug bgp zebra prefix", | |
29a643ca | 2273 | bgp_debug_zebra_prefixes); |
d62a17ae | 2274 | } |
2275 | } | |
16286195 | 2276 | |
d62a17ae | 2277 | if (CONF_BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) { |
2278 | vty_out(vty, "debug bgp allow-martians\n"); | |
2279 | write++; | |
2280 | } | |
16286195 | 2281 | |
ddb5b488 PZ |
2282 | if (CONF_BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF)) { |
2283 | vty_out(vty, "debug bgp vpn leak-from-vrf\n"); | |
2284 | write++; | |
2285 | } | |
2286 | if (CONF_BGP_DEBUG(vpn, VPN_LEAK_TO_VRF)) { | |
2287 | vty_out(vty, "debug bgp vpn leak-to-vrf\n"); | |
2288 | write++; | |
2289 | } | |
2290 | if (CONF_BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT)) { | |
2291 | vty_out(vty, "debug bgp vpn rmap-event\n"); | |
2292 | write++; | |
2293 | } | |
2294 | if (CONF_BGP_DEBUG(vpn, VPN_LEAK_LABEL)) { | |
2295 | vty_out(vty, "debug bgp vpn label\n"); | |
2296 | write++; | |
2297 | } | |
268e1b9b PG |
2298 | if (CONF_BGP_DEBUG(flowspec, FLOWSPEC)) { |
2299 | vty_out(vty, "debug bgp flowspec\n"); | |
2300 | write++; | |
2301 | } | |
955bfd98 PZ |
2302 | if (CONF_BGP_DEBUG(labelpool, LABELPOOL)) { |
2303 | vty_out(vty, "debug bgp labelpool\n"); | |
2304 | write++; | |
2305 | } | |
ddb5b488 | 2306 | |
1a80fc0f PG |
2307 | if (CONF_BGP_DEBUG(pbr, PBR)) { |
2308 | vty_out(vty, "debug bgp pbr\n"); | |
2309 | write++; | |
e9d0aa99 PG |
2310 | } |
2311 | if (CONF_BGP_DEBUG(pbr, PBR_ERROR)) { | |
2312 | vty_out(vty, "debug bgp pbr error\n"); | |
2313 | write++; | |
1a80fc0f | 2314 | } |
d62a17ae | 2315 | return write; |
2316 | } | |
16286195 | 2317 | |
d62a17ae | 2318 | static struct cmd_node debug_node = {DEBUG_NODE, "", 1}; |
2319 | ||
2320 | void bgp_debug_init(void) | |
2321 | { | |
2322 | install_node(&debug_node, bgp_config_write_debug); | |
2323 | ||
2324 | install_element(ENABLE_NODE, &show_debugging_bgp_cmd); | |
2325 | ||
2326 | install_element(ENABLE_NODE, &debug_bgp_as4_cmd); | |
2327 | install_element(CONFIG_NODE, &debug_bgp_as4_cmd); | |
2328 | install_element(ENABLE_NODE, &debug_bgp_as4_segment_cmd); | |
2329 | install_element(CONFIG_NODE, &debug_bgp_as4_segment_cmd); | |
2330 | ||
2331 | install_element(ENABLE_NODE, &debug_bgp_neighbor_events_cmd); | |
2332 | install_element(CONFIG_NODE, &debug_bgp_neighbor_events_cmd); | |
2333 | install_element(ENABLE_NODE, &debug_bgp_nht_cmd); | |
2334 | install_element(CONFIG_NODE, &debug_bgp_nht_cmd); | |
2335 | install_element(ENABLE_NODE, &debug_bgp_keepalive_cmd); | |
2336 | install_element(CONFIG_NODE, &debug_bgp_keepalive_cmd); | |
2337 | install_element(ENABLE_NODE, &debug_bgp_update_cmd); | |
2338 | install_element(CONFIG_NODE, &debug_bgp_update_cmd); | |
2339 | install_element(ENABLE_NODE, &debug_bgp_zebra_cmd); | |
2340 | install_element(CONFIG_NODE, &debug_bgp_zebra_cmd); | |
2341 | install_element(ENABLE_NODE, &debug_bgp_allow_martians_cmd); | |
2342 | install_element(CONFIG_NODE, &debug_bgp_allow_martians_cmd); | |
2343 | install_element(ENABLE_NODE, &debug_bgp_update_groups_cmd); | |
2344 | install_element(CONFIG_NODE, &debug_bgp_update_groups_cmd); | |
2345 | install_element(ENABLE_NODE, &debug_bgp_bestpath_prefix_cmd); | |
2346 | install_element(CONFIG_NODE, &debug_bgp_bestpath_prefix_cmd); | |
2347 | ||
2348 | /* debug bgp updates (in|out) */ | |
2349 | install_element(ENABLE_NODE, &debug_bgp_update_direct_cmd); | |
2350 | install_element(CONFIG_NODE, &debug_bgp_update_direct_cmd); | |
2351 | install_element(ENABLE_NODE, &no_debug_bgp_update_direct_cmd); | |
2352 | install_element(CONFIG_NODE, &no_debug_bgp_update_direct_cmd); | |
2353 | ||
2354 | /* debug bgp updates (in|out) A.B.C.D */ | |
2355 | install_element(ENABLE_NODE, &debug_bgp_update_direct_peer_cmd); | |
2356 | install_element(CONFIG_NODE, &debug_bgp_update_direct_peer_cmd); | |
2357 | install_element(ENABLE_NODE, &no_debug_bgp_update_direct_peer_cmd); | |
2358 | install_element(CONFIG_NODE, &no_debug_bgp_update_direct_peer_cmd); | |
2359 | ||
2360 | /* debug bgp updates prefix A.B.C.D/M */ | |
2361 | install_element(ENABLE_NODE, &debug_bgp_update_prefix_cmd); | |
2362 | install_element(CONFIG_NODE, &debug_bgp_update_prefix_cmd); | |
2363 | install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_cmd); | |
2364 | install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_cmd); | |
81cf0de5 CS |
2365 | install_element(ENABLE_NODE, &debug_bgp_update_prefix_afi_safi_cmd); |
2366 | install_element(CONFIG_NODE, &debug_bgp_update_prefix_afi_safi_cmd); | |
2367 | install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd); | |
2368 | install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd); | |
d62a17ae | 2369 | |
2370 | /* debug bgp zebra prefix A.B.C.D/M */ | |
2371 | install_element(ENABLE_NODE, &debug_bgp_zebra_prefix_cmd); | |
2372 | install_element(CONFIG_NODE, &debug_bgp_zebra_prefix_cmd); | |
2373 | install_element(ENABLE_NODE, &no_debug_bgp_zebra_prefix_cmd); | |
2374 | install_element(CONFIG_NODE, &no_debug_bgp_zebra_prefix_cmd); | |
2375 | ||
2376 | install_element(ENABLE_NODE, &no_debug_bgp_as4_cmd); | |
2377 | install_element(CONFIG_NODE, &no_debug_bgp_as4_cmd); | |
2378 | install_element(ENABLE_NODE, &no_debug_bgp_as4_segment_cmd); | |
2379 | install_element(CONFIG_NODE, &no_debug_bgp_as4_segment_cmd); | |
2380 | ||
2381 | /* debug bgp neighbor-events A.B.C.D */ | |
2382 | install_element(ENABLE_NODE, &debug_bgp_neighbor_events_peer_cmd); | |
2383 | install_element(CONFIG_NODE, &debug_bgp_neighbor_events_peer_cmd); | |
2384 | install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_peer_cmd); | |
2385 | install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_peer_cmd); | |
2386 | ||
2387 | /* debug bgp keepalive A.B.C.D */ | |
2388 | install_element(ENABLE_NODE, &debug_bgp_keepalive_peer_cmd); | |
2389 | install_element(CONFIG_NODE, &debug_bgp_keepalive_peer_cmd); | |
2390 | install_element(ENABLE_NODE, &no_debug_bgp_keepalive_peer_cmd); | |
2391 | install_element(CONFIG_NODE, &no_debug_bgp_keepalive_peer_cmd); | |
2392 | ||
2393 | install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_cmd); | |
2394 | install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_cmd); | |
2395 | install_element(ENABLE_NODE, &no_debug_bgp_nht_cmd); | |
2396 | install_element(CONFIG_NODE, &no_debug_bgp_nht_cmd); | |
2397 | install_element(ENABLE_NODE, &no_debug_bgp_keepalive_cmd); | |
2398 | install_element(CONFIG_NODE, &no_debug_bgp_keepalive_cmd); | |
2399 | install_element(ENABLE_NODE, &no_debug_bgp_update_cmd); | |
2400 | install_element(CONFIG_NODE, &no_debug_bgp_update_cmd); | |
2401 | install_element(ENABLE_NODE, &no_debug_bgp_zebra_cmd); | |
2402 | install_element(CONFIG_NODE, &no_debug_bgp_zebra_cmd); | |
2403 | install_element(ENABLE_NODE, &no_debug_bgp_allow_martians_cmd); | |
2404 | install_element(CONFIG_NODE, &no_debug_bgp_allow_martians_cmd); | |
2405 | install_element(ENABLE_NODE, &no_debug_bgp_update_groups_cmd); | |
2406 | install_element(CONFIG_NODE, &no_debug_bgp_update_groups_cmd); | |
2407 | install_element(ENABLE_NODE, &no_debug_bgp_cmd); | |
2408 | install_element(ENABLE_NODE, &no_debug_bgp_bestpath_cmd); | |
2409 | install_element(CONFIG_NODE, &no_debug_bgp_bestpath_cmd); | |
2410 | install_element(ENABLE_NODE, &no_debug_bgp_bestpath_prefix_cmd); | |
2411 | install_element(CONFIG_NODE, &no_debug_bgp_bestpath_prefix_cmd); | |
ddb5b488 PZ |
2412 | |
2413 | install_element(ENABLE_NODE, &debug_bgp_vpn_cmd); | |
2414 | install_element(CONFIG_NODE, &debug_bgp_vpn_cmd); | |
2415 | install_element(ENABLE_NODE, &no_debug_bgp_vpn_cmd); | |
2416 | install_element(CONFIG_NODE, &no_debug_bgp_vpn_cmd); | |
955bfd98 PZ |
2417 | |
2418 | install_element(ENABLE_NODE, &debug_bgp_labelpool_cmd); | |
2419 | install_element(CONFIG_NODE, &debug_bgp_labelpool_cmd); | |
2420 | install_element(ENABLE_NODE, &no_debug_bgp_labelpool_cmd); | |
2421 | install_element(CONFIG_NODE, &no_debug_bgp_labelpool_cmd); | |
1a80fc0f PG |
2422 | |
2423 | /* debug bgp pbr */ | |
2424 | install_element(ENABLE_NODE, &debug_bgp_pbr_cmd); | |
2425 | install_element(CONFIG_NODE, &debug_bgp_pbr_cmd); | |
2426 | install_element(ENABLE_NODE, &no_debug_bgp_pbr_cmd); | |
2427 | install_element(CONFIG_NODE, &no_debug_bgp_pbr_cmd); | |
2428 | ||
d62a17ae | 2429 | } |
16286195 | 2430 | |
d62a17ae | 2431 | /* Return true if this prefix is on the per_prefix_list of prefixes to debug |
2432 | * for BGP_DEBUG_TYPE | |
2433 | */ | |
2434 | static int bgp_debug_per_prefix(struct prefix *p, | |
2435 | unsigned long term_bgp_debug_type, | |
2436 | unsigned int BGP_DEBUG_TYPE, | |
2437 | struct list *per_prefix_list) | |
2438 | { | |
2439 | struct bgp_debug_filter *filter; | |
2440 | struct listnode *node, *nnode; | |
2441 | ||
2442 | if (term_bgp_debug_type & BGP_DEBUG_TYPE) { | |
2443 | /* We are debugging all prefixes so return true */ | |
2444 | if (!per_prefix_list || list_isempty(per_prefix_list)) | |
2445 | return 1; | |
2446 | ||
2447 | else { | |
2448 | if (!p) | |
2449 | return 0; | |
2450 | ||
2451 | for (ALL_LIST_ELEMENTS(per_prefix_list, node, nnode, | |
2452 | filter)) | |
2453 | if (filter->p->prefixlen == p->prefixlen | |
2454 | && prefix_match(filter->p, p)) | |
2455 | return 1; | |
2456 | ||
2457 | return 0; | |
2458 | } | |
2459 | } | |
2460 | ||
2461 | return 0; | |
16286195 DS |
2462 | } |
2463 | ||
2464 | /* Return true if this peer is on the per_peer_list of peers to debug | |
2465 | * for BGP_DEBUG_TYPE | |
2466 | */ | |
d62a17ae | 2467 | static int bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type, |
2468 | unsigned int BGP_DEBUG_TYPE, | |
2469 | struct list *per_peer_list) | |
16286195 | 2470 | { |
d62a17ae | 2471 | struct bgp_debug_filter *filter; |
2472 | struct listnode *node, *nnode; | |
16286195 | 2473 | |
d62a17ae | 2474 | if (term_bgp_debug_type & BGP_DEBUG_TYPE) { |
2475 | /* We are debugging all peers so return true */ | |
2476 | if (!per_peer_list || list_isempty(per_peer_list)) | |
2477 | return 1; | |
16286195 | 2478 | |
d62a17ae | 2479 | else { |
2480 | if (!host) | |
2481 | return 0; | |
16286195 | 2482 | |
d62a17ae | 2483 | for (ALL_LIST_ELEMENTS(per_peer_list, node, nnode, |
2484 | filter)) | |
2485 | if (strcmp(filter->host, host) == 0) | |
2486 | return 1; | |
16286195 | 2487 | |
d62a17ae | 2488 | return 0; |
2489 | } | |
2490 | } | |
16286195 | 2491 | |
d62a17ae | 2492 | return 0; |
16286195 DS |
2493 | } |
2494 | ||
d62a17ae | 2495 | int bgp_debug_neighbor_events(struct peer *peer) |
16286195 | 2496 | { |
d62a17ae | 2497 | char *host = NULL; |
167d390a | 2498 | |
d62a17ae | 2499 | if (peer) |
2500 | host = peer->host; | |
167d390a | 2501 | |
d62a17ae | 2502 | return bgp_debug_per_peer(host, term_bgp_debug_neighbor_events, |
2503 | BGP_DEBUG_NEIGHBOR_EVENTS, | |
2504 | bgp_debug_neighbor_events_peers); | |
16286195 DS |
2505 | } |
2506 | ||
d62a17ae | 2507 | int bgp_debug_keepalive(struct peer *peer) |
16286195 | 2508 | { |
d62a17ae | 2509 | char *host = NULL; |
167d390a | 2510 | |
d62a17ae | 2511 | if (peer) |
2512 | host = peer->host; | |
167d390a | 2513 | |
d62a17ae | 2514 | return bgp_debug_per_peer(host, term_bgp_debug_keepalive, |
2515 | BGP_DEBUG_KEEPALIVE, | |
2516 | bgp_debug_keepalive_peers); | |
16286195 DS |
2517 | } |
2518 | ||
d62a17ae | 2519 | int bgp_debug_update(struct peer *peer, struct prefix *p, |
2520 | struct update_group *updgrp, unsigned int inbound) | |
16286195 | 2521 | { |
d62a17ae | 2522 | char *host = NULL; |
2523 | ||
2524 | if (peer) | |
2525 | host = peer->host; | |
2526 | ||
2527 | if (inbound) { | |
2528 | if (bgp_debug_per_peer(host, term_bgp_debug_update, | |
2529 | BGP_DEBUG_UPDATE_IN, | |
2530 | bgp_debug_update_in_peers)) | |
2531 | return 1; | |
2532 | } | |
2533 | ||
2534 | /* outbound */ | |
2535 | else { | |
2536 | if (bgp_debug_per_peer(host, term_bgp_debug_update, | |
2537 | BGP_DEBUG_UPDATE_OUT, | |
2538 | bgp_debug_update_out_peers)) | |
2539 | return 1; | |
2540 | ||
2541 | /* Check if update debugging implicitly enabled for the group. | |
2542 | */ | |
2543 | if (updgrp && UPDGRP_DBG_ON(updgrp)) | |
2544 | return 1; | |
2545 | } | |
2546 | ||
2547 | ||
2548 | if (BGP_DEBUG(update, UPDATE_PREFIX)) { | |
2549 | if (bgp_debug_per_prefix(p, term_bgp_debug_update, | |
2550 | BGP_DEBUG_UPDATE_PREFIX, | |
2551 | bgp_debug_update_prefixes)) | |
2552 | return 1; | |
2553 | } | |
2554 | ||
2555 | return 0; | |
16286195 DS |
2556 | } |
2557 | ||
d62a17ae | 2558 | int bgp_debug_bestpath(struct prefix *p) |
9fbdd100 | 2559 | { |
d62a17ae | 2560 | if (BGP_DEBUG(bestpath, BESTPATH)) { |
2561 | if (bgp_debug_per_prefix(p, term_bgp_debug_bestpath, | |
2562 | BGP_DEBUG_BESTPATH, | |
2563 | bgp_debug_bestpath_prefixes)) | |
2564 | return 1; | |
2565 | } | |
2566 | ||
2567 | return 0; | |
9fbdd100 DS |
2568 | } |
2569 | ||
d62a17ae | 2570 | int bgp_debug_zebra(struct prefix *p) |
16286195 | 2571 | { |
d62a17ae | 2572 | if (BGP_DEBUG(zebra, ZEBRA)) { |
2573 | if (bgp_debug_per_prefix(p, term_bgp_debug_zebra, | |
2574 | BGP_DEBUG_ZEBRA, | |
2575 | bgp_debug_zebra_prefixes)) | |
2576 | return 1; | |
2577 | } | |
2578 | ||
2579 | return 0; | |
718e3744 | 2580 | } |
906ad49b | 2581 | |
d62a17ae | 2582 | const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi, |
2583 | struct prefix_rd *prd, | |
2584 | union prefixconstptr pu, | |
d7c0a89a QY |
2585 | mpls_label_t *label, uint32_t num_labels, |
2586 | int addpath_valid, uint32_t addpath_id, | |
b57ba6d2 | 2587 | char *str, int size) |
d62a17ae | 2588 | { |
2589 | char rd_buf[RD_ADDRSTRLEN]; | |
2590 | char pfx_buf[PREFIX_STRLEN]; | |
2591 | char tag_buf[30]; | |
2592 | /* ' with addpath ID ' 17 | |
2593 | * max strlen of uint32 + 10 | |
2594 | * +/- (just in case) + 1 | |
2595 | * null terminator + 1 | |
2596 | * ============================ 29 */ | |
2597 | char pathid_buf[30]; | |
2598 | ||
2599 | if (size < BGP_PRD_PATH_STRLEN) | |
2600 | return NULL; | |
2601 | ||
2602 | /* Note: Path-id is created by default, but only included in update | |
2603 | * sometimes. */ | |
2604 | pathid_buf[0] = '\0'; | |
2605 | if (addpath_valid) | |
2606 | snprintf(pathid_buf, sizeof(pathid_buf), " with addpath ID %u", | |
2607 | addpath_id); | |
2608 | ||
2609 | tag_buf[0] = '\0'; | |
b57ba6d2 | 2610 | if (bgp_labeled_safi(safi) && num_labels) { |
d62a17ae | 2611 | |
b57ba6d2 MK |
2612 | if (safi == SAFI_EVPN) { |
2613 | char tag_buf2[20]; | |
2614 | ||
2615 | bgp_evpn_label2str(label, num_labels, tag_buf2, 20); | |
2616 | sprintf(tag_buf, " label %s", tag_buf2); | |
2617 | } else { | |
d7c0a89a | 2618 | uint32_t label_value; |
b57ba6d2 MK |
2619 | |
2620 | label_value = decode_label(label); | |
2621 | sprintf(tag_buf, " label %u", label_value); | |
2622 | } | |
d62a17ae | 2623 | } |
2624 | ||
2625 | if (prd) | |
e1af3f16 | 2626 | snprintf(str, size, "RD %s %s%s%s %s %s", |
d62a17ae | 2627 | prefix_rd2str(prd, rd_buf, sizeof(rd_buf)), |
2628 | prefix2str(pu, pfx_buf, sizeof(pfx_buf)), tag_buf, | |
e1af3f16 | 2629 | pathid_buf, afi2str(afi), safi2str(safi)); |
268e1b9b PG |
2630 | else if (safi == SAFI_FLOWSPEC) { |
2631 | char return_string[BGP_FLOWSPEC_NLRI_STRING_MAX]; | |
2632 | const struct prefix_fs *fs = pu.fs; | |
2633 | ||
2634 | bgp_fs_nlri_get_string((unsigned char *)fs->prefix.ptr, | |
2635 | fs->prefix.prefixlen, | |
2636 | return_string, | |
d33fc23b | 2637 | NLRI_STRING_FORMAT_DEBUG, NULL); |
268e1b9b PG |
2638 | snprintf(str, size, "FS %s Match{%s}", afi2str(afi), |
2639 | return_string); | |
2640 | } else | |
e1af3f16 | 2641 | snprintf(str, size, "%s%s%s %s %s", |
d62a17ae | 2642 | prefix2str(pu, pfx_buf, sizeof(pfx_buf)), tag_buf, |
e1af3f16 | 2643 | pathid_buf, afi2str(afi), safi2str(safi)); |
d62a17ae | 2644 | |
2645 | return str; | |
906ad49b | 2646 | } |