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