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