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