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