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