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