]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_debug.c
Merge branch 'master' into docuser
[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",
389 community_str(attr->community, false));
390
391 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
392 snprintf(buf + strlen(buf), size - strlen(buf),
393 ", extcommunity %s", ecommunity_str(attr->ecommunity));
394
395 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)))
396 snprintf(buf + strlen(buf), size - strlen(buf),
397 ", atomic-aggregate");
398
399 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)))
400 snprintf(buf + strlen(buf), size - strlen(buf),
401 ", aggregated by %u %s", attr->aggregator_as,
402 inet_ntoa(attr->aggregator_addr));
403
404 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))
405 snprintf(buf + strlen(buf), size - strlen(buf),
406 ", originator %s", inet_ntoa(attr->originator_id));
407
408 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) {
409 int i;
410
411 snprintf(buf + strlen(buf), size - strlen(buf),
412 ", clusterlist");
413 for (i = 0; i < attr->cluster->length / 4; i++)
414 snprintf(buf + strlen(buf), size - strlen(buf), " %s",
415 inet_ntoa(attr->cluster->list[i]));
416 }
417
418 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
419 snprintf(buf + strlen(buf), size - strlen(buf), ", path %s",
420 aspath_print(attr->aspath));
421
422 if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))) {
423 if (attr->label_index != BGP_INVALID_LABEL_INDEX)
424 snprintf(buf + strlen(buf), size - strlen(buf),
425 ", label-index %u", attr->label_index);
426 }
427
428 if (strlen(buf) > 1)
429 return 1;
430 else
431 return 0;
432 }
433
434 const char *bgp_notify_code_str(char code)
435 {
436 return lookup_msg(bgp_notify_msg, code, "Unrecognized Error Code");
437 }
438
439 const char *bgp_notify_subcode_str(char code, char subcode)
440 {
441
442 switch (code) {
443 case BGP_NOTIFY_HEADER_ERR:
444 return lookup_msg(bgp_notify_head_msg, subcode,
445 "Unrecognized Error Subcode");
446 case BGP_NOTIFY_OPEN_ERR:
447 return lookup_msg(bgp_notify_open_msg, subcode,
448 "Unrecognized Error Subcode");
449 case BGP_NOTIFY_UPDATE_ERR:
450 return lookup_msg(bgp_notify_update_msg, subcode,
451 "Unrecognized Error Subcode");
452 case BGP_NOTIFY_HOLD_ERR:
453 break;
454 case BGP_NOTIFY_FSM_ERR:
455 break;
456 case BGP_NOTIFY_CEASE:
457 return lookup_msg(bgp_notify_cease_msg, subcode,
458 "Unrecognized Error Subcode");
459 case BGP_NOTIFY_CAPABILITY_ERR:
460 return lookup_msg(bgp_notify_capability_msg, subcode,
461 "Unrecognized Error Subcode");
462 }
463 return "";
464 }
465
466 /* extract notify admin reason if correctly present */
467 const char *bgp_notify_admin_message(char *buf, size_t bufsz, u_char *data,
468 size_t datalen)
469 {
470 if (!data || datalen < 1)
471 return NULL;
472
473 u_char len = data[0];
474 if (len > 128 || len > datalen - 1)
475 return NULL;
476
477 return zlog_sanitize(buf, bufsz, data + 1, len);
478 }
479
480 /* dump notify packet */
481 void bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
482 const char *direct)
483 {
484 const char *subcode_str;
485 const char *code_str;
486 const char *msg_str = NULL;
487 char msg_buf[1024];
488
489 if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)
490 || bgp_flag_check(peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) {
491 code_str = bgp_notify_code_str(bgp_notify->code);
492 subcode_str = bgp_notify_subcode_str(bgp_notify->code,
493 bgp_notify->subcode);
494
495 if (bgp_notify->code == BGP_NOTIFY_CEASE
496 && (bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
497 || bgp_notify->subcode
498 == BGP_NOTIFY_CEASE_ADMIN_RESET)) {
499 msg_str = bgp_notify_admin_message(
500 msg_buf, sizeof(msg_buf), bgp_notify->raw_data,
501 bgp_notify->length);
502 }
503
504 if (msg_str) {
505 zlog_info(
506 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
507 strcmp(direct, "received") == 0
508 ? "received from"
509 : "sent to",
510 peer->host, bgp_notify->code,
511 bgp_notify->subcode, code_str, subcode_str,
512 msg_str);
513 } else {
514 msg_str = bgp_notify->data ? bgp_notify->data : "";
515 zlog_info(
516 "%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
517 strcmp(direct, "received") == 0
518 ? "received from"
519 : "sent to",
520 peer->host, bgp_notify->code,
521 bgp_notify->subcode, code_str, subcode_str,
522 bgp_notify->length, msg_str);
523 }
524 }
525 }
526
527 static void bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp)
528 {
529 if (!bgp)
530 bgp = bgp_get_default();
531 update_group_walk(bgp, update_group_clear_update_dbg, NULL);
532 }
533
534
535 /* Debug option setting interface. */
536 unsigned long bgp_debug_option = 0;
537
538 int debug(unsigned int option)
539 {
540 return bgp_debug_option & option;
541 }
542
543 DEFUN (debug_bgp_as4,
544 debug_bgp_as4_cmd,
545 "debug bgp as4",
546 DEBUG_STR
547 BGP_STR
548 "BGP AS4 actions\n")
549 {
550 if (vty->node == CONFIG_NODE)
551 DEBUG_ON(as4, AS4);
552 else {
553 TERM_DEBUG_ON(as4, AS4);
554 vty_out(vty, "BGP as4 debugging is on\n");
555 }
556 return CMD_SUCCESS;
557 }
558
559 DEFUN (no_debug_bgp_as4,
560 no_debug_bgp_as4_cmd,
561 "no debug bgp as4",
562 NO_STR
563 DEBUG_STR
564 BGP_STR
565 "BGP AS4 actions\n")
566 {
567 if (vty->node == CONFIG_NODE)
568 DEBUG_OFF(as4, AS4);
569 else {
570 TERM_DEBUG_OFF(as4, AS4);
571 vty_out(vty, "BGP as4 debugging is off\n");
572 }
573 return CMD_SUCCESS;
574 }
575
576 DEFUN (debug_bgp_as4_segment,
577 debug_bgp_as4_segment_cmd,
578 "debug bgp as4 segment",
579 DEBUG_STR
580 BGP_STR
581 "BGP AS4 actions\n"
582 "BGP AS4 aspath segment handling\n")
583 {
584 if (vty->node == CONFIG_NODE)
585 DEBUG_ON(as4, AS4_SEGMENT);
586 else {
587 TERM_DEBUG_ON(as4, AS4_SEGMENT);
588 vty_out(vty, "BGP as4 segment debugging is on\n");
589 }
590 return CMD_SUCCESS;
591 }
592
593 DEFUN (no_debug_bgp_as4_segment,
594 no_debug_bgp_as4_segment_cmd,
595 "no debug bgp as4 segment",
596 NO_STR
597 DEBUG_STR
598 BGP_STR
599 "BGP AS4 actions\n"
600 "BGP AS4 aspath segment handling\n")
601 {
602 if (vty->node == CONFIG_NODE)
603 DEBUG_OFF(as4, AS4_SEGMENT);
604 else {
605 TERM_DEBUG_OFF(as4, AS4_SEGMENT);
606 vty_out(vty, "BGP as4 segment debugging is off\n");
607 }
608 return CMD_SUCCESS;
609 }
610
611 /* debug bgp neighbor_events */
612 DEFUN (debug_bgp_neighbor_events,
613 debug_bgp_neighbor_events_cmd,
614 "debug bgp neighbor-events",
615 DEBUG_STR
616 BGP_STR
617 "BGP Neighbor Events\n")
618 {
619 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
620
621 if (vty->node == CONFIG_NODE)
622 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
623 else {
624 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
625 vty_out(vty, "BGP neighbor-events debugging is on\n");
626 }
627 return CMD_SUCCESS;
628 }
629
630 DEFUN (debug_bgp_neighbor_events_peer,
631 debug_bgp_neighbor_events_peer_cmd,
632 "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
633 DEBUG_STR
634 BGP_STR
635 "BGP Neighbor Events\n"
636 "BGP neighbor IP address to debug\n"
637 "BGP IPv6 neighbor to debug\n"
638 "BGP neighbor on interface to debug\n")
639 {
640 int idx_peer = 3;
641 const char *host = argv[idx_peer]->arg;
642
643 if (!bgp_debug_neighbor_events_peers)
644 bgp_debug_neighbor_events_peers = list_new();
645
646 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host,
647 NULL)) {
648 vty_out(vty,
649 "BGP neighbor-events debugging is already enabled for %s\n",
650 host);
651 return CMD_SUCCESS;
652 }
653
654 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL);
655
656 if (vty->node == CONFIG_NODE)
657 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
658 else {
659 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
660 vty_out(vty, "BGP neighbor-events debugging is on for %s\n",
661 host);
662 }
663 return CMD_SUCCESS;
664 }
665
666 DEFUN (no_debug_bgp_neighbor_events,
667 no_debug_bgp_neighbor_events_cmd,
668 "no debug bgp neighbor-events",
669 NO_STR
670 DEBUG_STR
671 BGP_STR
672 "Neighbor Events\n")
673 {
674 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
675
676 if (vty->node == CONFIG_NODE)
677 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
678 else {
679 TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
680 vty_out(vty, "BGP neighbor-events debugging is off\n");
681 }
682 return CMD_SUCCESS;
683 }
684
685 DEFUN (no_debug_bgp_neighbor_events_peer,
686 no_debug_bgp_neighbor_events_peer_cmd,
687 "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
688 NO_STR
689 DEBUG_STR
690 BGP_STR
691 "Neighbor Events\n"
692 "BGP neighbor IP address to debug\n"
693 "BGP IPv6 neighbor to debug\n"
694 "BGP neighbor on interface to debug\n")
695 {
696 int idx_peer = 4;
697 int found_peer = 0;
698 const char *host = argv[idx_peer]->arg;
699
700 if (bgp_debug_neighbor_events_peers
701 && !list_isempty(bgp_debug_neighbor_events_peers)) {
702 found_peer = bgp_debug_list_remove_entry(
703 bgp_debug_neighbor_events_peers, host, NULL);
704
705 if (list_isempty(bgp_debug_neighbor_events_peers)) {
706 if (vty->node == CONFIG_NODE)
707 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
708 else
709 TERM_DEBUG_OFF(neighbor_events,
710 NEIGHBOR_EVENTS);
711 }
712 }
713
714 if (found_peer)
715 vty_out(vty, "BGP neighbor-events debugging is off for %s\n",
716 host);
717 else
718 vty_out(vty,
719 "BGP neighbor-events debugging was not enabled for %s\n",
720 host);
721
722 return CMD_SUCCESS;
723 }
724
725 /* debug bgp nht */
726 DEFUN (debug_bgp_nht,
727 debug_bgp_nht_cmd,
728 "debug bgp nht",
729 DEBUG_STR
730 BGP_STR
731 "BGP nexthop tracking events\n")
732 {
733 if (vty->node == CONFIG_NODE)
734 DEBUG_ON(nht, NHT);
735 else {
736 TERM_DEBUG_ON(nht, NHT);
737 vty_out(vty, "BGP nexthop tracking debugging is on\n");
738 }
739 return CMD_SUCCESS;
740 }
741
742 DEFUN (no_debug_bgp_nht,
743 no_debug_bgp_nht_cmd,
744 "no debug bgp nht",
745 NO_STR
746 DEBUG_STR
747 BGP_STR
748 "BGP nexthop tracking events\n")
749 {
750 if (vty->node == CONFIG_NODE)
751 DEBUG_OFF(nht, NHT);
752 else {
753 TERM_DEBUG_OFF(nht, NHT);
754 vty_out(vty, "BGP nexthop tracking debugging is off\n");
755 }
756 return CMD_SUCCESS;
757 }
758
759 /* debug bgp keepalives */
760 DEFUN (debug_bgp_keepalive,
761 debug_bgp_keepalive_cmd,
762 "debug bgp keepalives",
763 DEBUG_STR
764 BGP_STR
765 "BGP keepalives\n")
766 {
767 bgp_debug_list_free(bgp_debug_keepalive_peers);
768
769 if (vty->node == CONFIG_NODE)
770 DEBUG_ON(keepalive, KEEPALIVE);
771 else {
772 TERM_DEBUG_ON(keepalive, KEEPALIVE);
773 vty_out(vty, "BGP keepalives debugging is on\n");
774 }
775 return CMD_SUCCESS;
776 }
777
778 DEFUN (debug_bgp_keepalive_peer,
779 debug_bgp_keepalive_peer_cmd,
780 "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
781 DEBUG_STR
782 BGP_STR
783 "BGP Neighbor Events\n"
784 "BGP neighbor IP address to debug\n"
785 "BGP IPv6 neighbor to debug\n"
786 "BGP neighbor on interface to debug\n")
787 {
788 int idx_peer = 3;
789 const char *host = argv[idx_peer]->arg;
790
791 if (!bgp_debug_keepalive_peers)
792 bgp_debug_keepalive_peers = list_new();
793
794 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL)) {
795 vty_out(vty,
796 "BGP keepalive debugging is already enabled for %s\n",
797 host);
798 return CMD_SUCCESS;
799 }
800
801 bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL);
802
803 if (vty->node == CONFIG_NODE)
804 DEBUG_ON(keepalive, KEEPALIVE);
805 else {
806 TERM_DEBUG_ON(keepalive, KEEPALIVE);
807 vty_out(vty, "BGP keepalives debugging is on for %s\n", host);
808 }
809 return CMD_SUCCESS;
810 }
811
812 DEFUN (no_debug_bgp_keepalive,
813 no_debug_bgp_keepalive_cmd,
814 "no debug bgp keepalives",
815 NO_STR
816 DEBUG_STR
817 BGP_STR
818 "BGP keepalives\n")
819 {
820 bgp_debug_list_free(bgp_debug_keepalive_peers);
821
822 if (vty->node == CONFIG_NODE)
823 DEBUG_OFF(keepalive, KEEPALIVE);
824 else {
825 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
826 vty_out(vty, "BGP keepalives debugging is off\n");
827 }
828 return CMD_SUCCESS;
829 }
830
831 DEFUN (no_debug_bgp_keepalive_peer,
832 no_debug_bgp_keepalive_peer_cmd,
833 "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
834 NO_STR
835 DEBUG_STR
836 BGP_STR
837 "BGP keepalives\n"
838 "BGP neighbor IP address to debug\n"
839 "BGP IPv6 neighbor to debug\n"
840 "BGP neighbor on interface to debug\n")
841 {
842 int idx_peer = 4;
843 int found_peer = 0;
844 const char *host = argv[idx_peer]->arg;
845
846 if (bgp_debug_keepalive_peers
847 && !list_isempty(bgp_debug_keepalive_peers)) {
848 found_peer = bgp_debug_list_remove_entry(
849 bgp_debug_keepalive_peers, host, NULL);
850
851 if (list_isempty(bgp_debug_keepalive_peers)) {
852 if (vty->node == CONFIG_NODE)
853 DEBUG_OFF(keepalive, KEEPALIVE);
854 else
855 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
856 }
857 }
858
859 if (found_peer)
860 vty_out(vty, "BGP keepalives debugging is off for %s\n", host);
861 else
862 vty_out(vty,
863 "BGP keepalives debugging was not enabled for %s\n",
864 host);
865
866 return CMD_SUCCESS;
867 }
868
869 /* debug bgp bestpath */
870 DEFUN (debug_bgp_bestpath_prefix,
871 debug_bgp_bestpath_prefix_cmd,
872 "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
873 DEBUG_STR
874 BGP_STR
875 "BGP bestpath\n"
876 "IPv4 prefix\n"
877 "IPv6 prefix\n")
878 {
879 struct prefix *argv_p;
880 int idx_ipv4_ipv6_prefixlen = 3;
881
882 argv_p = prefix_new();
883 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
884 apply_mask(argv_p);
885
886 if (!bgp_debug_bestpath_prefixes)
887 bgp_debug_bestpath_prefixes = list_new();
888
889 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL,
890 argv_p)) {
891 vty_out(vty,
892 "BGP bestpath debugging is already enabled for %s\n",
893 argv[idx_ipv4_ipv6_prefixlen]->arg);
894 return CMD_SUCCESS;
895 }
896
897 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, argv_p);
898
899 if (vty->node == CONFIG_NODE) {
900 DEBUG_ON(bestpath, BESTPATH);
901 } else {
902 TERM_DEBUG_ON(bestpath, BESTPATH);
903 vty_out(vty, "BGP bestpath debugging is on for %s\n",
904 argv[idx_ipv4_ipv6_prefixlen]->arg);
905 }
906
907 return CMD_SUCCESS;
908 }
909
910 DEFUN (no_debug_bgp_bestpath_prefix,
911 no_debug_bgp_bestpath_prefix_cmd,
912 "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>",
913 NO_STR
914 DEBUG_STR
915 BGP_STR
916 "BGP bestpath\n"
917 "IPv4 prefix\n"
918 "IPv6 prefix\n")
919 {
920 int idx_ipv4_ipv6_prefixlen = 4;
921 struct prefix *argv_p;
922 int found_prefix = 0;
923
924 argv_p = prefix_new();
925 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
926 apply_mask(argv_p);
927
928 if (bgp_debug_bestpath_prefixes
929 && !list_isempty(bgp_debug_bestpath_prefixes)) {
930 found_prefix = bgp_debug_list_remove_entry(
931 bgp_debug_bestpath_prefixes, NULL, argv_p);
932
933 if (list_isempty(bgp_debug_bestpath_prefixes)) {
934 if (vty->node == CONFIG_NODE) {
935 DEBUG_OFF(bestpath, BESTPATH);
936 } else {
937 TERM_DEBUG_OFF(bestpath, BESTPATH);
938 vty_out(vty,
939 "BGP bestpath debugging (per prefix) is off\n");
940 }
941 }
942 }
943
944 if (found_prefix)
945 vty_out(vty, "BGP bestpath debugging is off for %s\n",
946 argv[idx_ipv4_ipv6_prefixlen]->arg);
947 else
948 vty_out(vty, "BGP bestpath debugging was not enabled for %s\n",
949 argv[idx_ipv4_ipv6_prefixlen]->arg);
950
951 return CMD_SUCCESS;
952 }
953
954 DEFUN (no_debug_bgp_bestpath,
955 no_debug_bgp_bestpath_cmd,
956 "no debug bgp bestpath",
957 NO_STR
958 DEBUG_STR
959 BGP_STR
960 "BGP bestpath\n")
961 {
962 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
963
964 if (vty->node == CONFIG_NODE)
965 DEBUG_OFF(bestpath, BESTPATH);
966 else {
967 TERM_DEBUG_OFF(bestpath, BESTPATH);
968 vty_out(vty, "BGP bestpath debugging is off\n");
969 }
970 return CMD_SUCCESS;
971 }
972
973 /* debug bgp updates */
974 DEFUN (debug_bgp_update,
975 debug_bgp_update_cmd,
976 "debug bgp updates",
977 DEBUG_STR
978 BGP_STR
979 "BGP updates\n")
980 {
981 bgp_debug_list_free(bgp_debug_update_in_peers);
982 bgp_debug_list_free(bgp_debug_update_out_peers);
983 bgp_debug_list_free(bgp_debug_update_prefixes);
984
985 if (vty->node == CONFIG_NODE) {
986 DEBUG_ON(update, UPDATE_IN);
987 DEBUG_ON(update, UPDATE_OUT);
988 } else {
989 TERM_DEBUG_ON(update, UPDATE_IN);
990 TERM_DEBUG_ON(update, UPDATE_OUT);
991 vty_out(vty, "BGP updates debugging is on\n");
992 }
993 return CMD_SUCCESS;
994 }
995
996 DEFUN (debug_bgp_update_direct,
997 debug_bgp_update_direct_cmd,
998 "debug bgp updates <in|out>",
999 DEBUG_STR
1000 BGP_STR
1001 "BGP updates\n"
1002 "Inbound updates\n"
1003 "Outbound updates\n")
1004 {
1005 int idx_in_out = 3;
1006
1007 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1008 bgp_debug_list_free(bgp_debug_update_in_peers);
1009 else
1010 bgp_debug_list_free(bgp_debug_update_out_peers);
1011
1012 if (vty->node == CONFIG_NODE) {
1013 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1014 DEBUG_ON(update, UPDATE_IN);
1015 else
1016 DEBUG_ON(update, UPDATE_OUT);
1017 } else {
1018 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
1019 TERM_DEBUG_ON(update, UPDATE_IN);
1020 vty_out(vty, "BGP updates debugging is on (inbound)\n");
1021 } else {
1022 TERM_DEBUG_ON(update, UPDATE_OUT);
1023 vty_out(vty,
1024 "BGP updates debugging is on (outbound)\n");
1025 }
1026 }
1027 return CMD_SUCCESS;
1028 }
1029
1030 DEFUN (debug_bgp_update_direct_peer,
1031 debug_bgp_update_direct_peer_cmd,
1032 "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1033 DEBUG_STR
1034 BGP_STR
1035 "BGP updates\n"
1036 "Inbound updates\n"
1037 "Outbound updates\n"
1038 "BGP neighbor IP address to debug\n"
1039 "BGP IPv6 neighbor to debug\n"
1040 "BGP neighbor on interface to debug\n")
1041 {
1042 int idx_in_out = 3;
1043 int idx_peer = 4;
1044 const char *host = argv[idx_peer]->arg;
1045 int inbound;
1046
1047 if (!bgp_debug_update_in_peers)
1048 bgp_debug_update_in_peers = list_new();
1049
1050 if (!bgp_debug_update_out_peers)
1051 bgp_debug_update_out_peers = list_new();
1052
1053 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1054 inbound = 1;
1055 else
1056 inbound = 0;
1057
1058 if (inbound) {
1059 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, host,
1060 NULL)) {
1061 vty_out(vty,
1062 "BGP inbound update debugging is already enabled for %s\n",
1063 host);
1064 return CMD_SUCCESS;
1065 }
1066 }
1067
1068 else {
1069 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host,
1070 NULL)) {
1071 vty_out(vty,
1072 "BGP outbound update debugging is already enabled for %s\n",
1073 host);
1074 return CMD_SUCCESS;
1075 }
1076 }
1077
1078 if (inbound)
1079 bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL);
1080 else {
1081 struct peer *peer;
1082 struct peer_af *paf;
1083 int afidx;
1084
1085 bgp_debug_list_add_entry(bgp_debug_update_out_peers, host,
1086 NULL);
1087 peer = bgp_find_peer(vty, host);
1088
1089 if (peer) {
1090 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
1091 afidx++) {
1092 paf = peer->peer_af_array[afidx];
1093 if (paf != NULL) {
1094 if (PAF_SUBGRP(paf)) {
1095 UPDGRP_PEER_DBG_EN(
1096 PAF_SUBGRP(paf)
1097 ->update_group);
1098 }
1099 }
1100 }
1101 }
1102 }
1103
1104 if (vty->node == CONFIG_NODE) {
1105 if (inbound)
1106 DEBUG_ON(update, UPDATE_IN);
1107 else
1108 DEBUG_ON(update, UPDATE_OUT);
1109 } else {
1110 if (inbound) {
1111 TERM_DEBUG_ON(update, UPDATE_IN);
1112 vty_out(vty,
1113 "BGP updates debugging is on (inbound) for %s\n",
1114 argv[idx_peer]->arg);
1115 } else {
1116 TERM_DEBUG_ON(update, UPDATE_OUT);
1117 vty_out(vty,
1118 "BGP updates debugging is on (outbound) for %s\n",
1119 argv[idx_peer]->arg);
1120 }
1121 }
1122 return CMD_SUCCESS;
1123 }
1124
1125 DEFUN (no_debug_bgp_update_direct,
1126 no_debug_bgp_update_direct_cmd,
1127 "no debug bgp updates <in|out>",
1128 NO_STR
1129 DEBUG_STR
1130 BGP_STR
1131 "BGP updates\n"
1132 "Inbound updates\n"
1133 "Outbound updates\n")
1134 {
1135 int idx_in_out = 4;
1136 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
1137 bgp_debug_list_free(bgp_debug_update_in_peers);
1138
1139 if (vty->node == CONFIG_NODE) {
1140 DEBUG_OFF(update, UPDATE_IN);
1141 } else {
1142 TERM_DEBUG_OFF(update, UPDATE_IN);
1143 vty_out(vty,
1144 "BGP updates debugging is off (inbound)\n");
1145 }
1146 } else {
1147 bgp_debug_list_free(bgp_debug_update_out_peers);
1148
1149 if (vty->node == CONFIG_NODE) {
1150 DEBUG_OFF(update, UPDATE_OUT);
1151 } else {
1152 TERM_DEBUG_OFF(update, UPDATE_OUT);
1153 vty_out(vty,
1154 "BGP updates debugging is off (outbound)\n");
1155 }
1156 }
1157
1158 return CMD_SUCCESS;
1159 }
1160
1161 DEFUN (no_debug_bgp_update_direct_peer,
1162 no_debug_bgp_update_direct_peer_cmd,
1163 "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
1164 NO_STR
1165 DEBUG_STR
1166 BGP_STR
1167 "BGP updates\n"
1168 "Inbound updates\n"
1169 "Outbound updates\n"
1170 "BGP neighbor IP address to debug\n"
1171 "BGP IPv6 neighbor to debug\n"
1172 "BGP neighbor on interface to debug\n")
1173 {
1174 int idx_in_out = 4;
1175 int idx_peer = 5;
1176 int inbound;
1177 int found_peer = 0;
1178 const char *host = argv[idx_peer]->arg;
1179
1180 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
1181 inbound = 1;
1182 else
1183 inbound = 0;
1184
1185 if (inbound && bgp_debug_update_in_peers
1186 && !list_isempty(bgp_debug_update_in_peers)) {
1187 found_peer = bgp_debug_list_remove_entry(
1188 bgp_debug_update_in_peers, host, NULL);
1189
1190 if (list_isempty(bgp_debug_update_in_peers)) {
1191 if (vty->node == CONFIG_NODE)
1192 DEBUG_OFF(update, UPDATE_IN);
1193 else {
1194 TERM_DEBUG_OFF(update, UPDATE_IN);
1195 vty_out(vty,
1196 "BGP updates debugging (inbound) is off\n");
1197 }
1198 }
1199 }
1200
1201 if (!inbound && bgp_debug_update_out_peers
1202 && !list_isempty(bgp_debug_update_out_peers)) {
1203 found_peer = bgp_debug_list_remove_entry(
1204 bgp_debug_update_out_peers, host, NULL);
1205
1206 if (list_isempty(bgp_debug_update_out_peers)) {
1207 if (vty->node == CONFIG_NODE)
1208 DEBUG_OFF(update, UPDATE_OUT);
1209 else {
1210 TERM_DEBUG_OFF(update, UPDATE_OUT);
1211 vty_out(vty,
1212 "BGP updates debugging (outbound) is off\n");
1213 }
1214 }
1215
1216 struct peer *peer;
1217 struct peer_af *paf;
1218 int afidx;
1219 peer = bgp_find_peer(vty, host);
1220
1221 if (peer) {
1222 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
1223 afidx++) {
1224 paf = peer->peer_af_array[afidx];
1225 if (paf != NULL) {
1226 if (PAF_SUBGRP(paf)) {
1227 UPDGRP_PEER_DBG_DIS(
1228 PAF_SUBGRP(paf)
1229 ->update_group);
1230 }
1231 }
1232 }
1233 }
1234 }
1235
1236 if (found_peer)
1237 if (inbound)
1238 vty_out(vty,
1239 "BGP updates debugging (inbound) is off for %s\n",
1240 host);
1241 else
1242 vty_out(vty,
1243 "BGP updates debugging (outbound) is off for %s\n",
1244 host);
1245 else if (inbound)
1246 vty_out(vty,
1247 "BGP updates debugging (inbound) was not enabled for %s\n",
1248 host);
1249 else
1250 vty_out(vty,
1251 "BGP updates debugging (outbound) was not enabled for %s\n",
1252 host);
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 DEFUN (debug_bgp_update_prefix,
1258 debug_bgp_update_prefix_cmd,
1259 "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1260 DEBUG_STR
1261 BGP_STR
1262 "BGP updates\n"
1263 "Specify a prefix to debug\n"
1264 "IPv4 prefix\n"
1265 "IPv6 prefix\n")
1266 {
1267 int idx_ipv4_ipv6_prefixlen = 4;
1268 struct prefix *argv_p;
1269
1270 argv_p = prefix_new();
1271 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
1272 apply_mask(argv_p);
1273
1274 if (!bgp_debug_update_prefixes)
1275 bgp_debug_update_prefixes = list_new();
1276
1277 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) {
1278 vty_out(vty,
1279 "BGP updates debugging is already enabled for %s\n",
1280 argv[idx_ipv4_ipv6_prefixlen]->arg);
1281 return CMD_SUCCESS;
1282 }
1283
1284 bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p);
1285
1286 if (vty->node == CONFIG_NODE) {
1287 DEBUG_ON(update, UPDATE_PREFIX);
1288 } else {
1289 TERM_DEBUG_ON(update, UPDATE_PREFIX);
1290 vty_out(vty, "BGP updates debugging is on for %s\n",
1291 argv[idx_ipv4_ipv6_prefixlen]->arg);
1292 }
1293
1294 return CMD_SUCCESS;
1295 }
1296
1297 DEFUN (no_debug_bgp_update_prefix,
1298 no_debug_bgp_update_prefix_cmd,
1299 "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>",
1300 NO_STR
1301 DEBUG_STR
1302 BGP_STR
1303 "BGP updates\n"
1304 "Specify a prefix to debug\n"
1305 "IPv4 prefix\n"
1306 "IPv6 prefix\n")
1307 {
1308 int idx_ipv4_ipv6_prefixlen = 5;
1309 struct prefix *argv_p;
1310 int found_prefix = 0;
1311
1312 argv_p = prefix_new();
1313 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
1314 apply_mask(argv_p);
1315
1316 if (bgp_debug_update_prefixes
1317 && !list_isempty(bgp_debug_update_prefixes)) {
1318 found_prefix = bgp_debug_list_remove_entry(
1319 bgp_debug_update_prefixes, NULL, argv_p);
1320
1321 if (list_isempty(bgp_debug_update_prefixes)) {
1322 if (vty->node == CONFIG_NODE) {
1323 DEBUG_OFF(update, UPDATE_PREFIX);
1324 } else {
1325 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1326 vty_out(vty,
1327 "BGP updates debugging (per prefix) is off\n");
1328 }
1329 }
1330 }
1331
1332 if (found_prefix)
1333 vty_out(vty, "BGP updates debugging is off for %s\n",
1334 argv[idx_ipv4_ipv6_prefixlen]->arg);
1335 else
1336 vty_out(vty, "BGP updates debugging was not enabled for %s\n",
1337 argv[idx_ipv4_ipv6_prefixlen]->arg);
1338
1339 return CMD_SUCCESS;
1340 }
1341
1342 DEFUN (no_debug_bgp_update,
1343 no_debug_bgp_update_cmd,
1344 "no debug bgp updates",
1345 NO_STR
1346 DEBUG_STR
1347 BGP_STR
1348 "BGP updates\n")
1349 {
1350 struct listnode *ln;
1351 struct bgp *bgp;
1352
1353 bgp_debug_list_free(bgp_debug_update_in_peers);
1354 bgp_debug_list_free(bgp_debug_update_out_peers);
1355 bgp_debug_list_free(bgp_debug_update_prefixes);
1356
1357 for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
1358 bgp_debug_clear_updgrp_update_dbg(bgp);
1359
1360 if (vty->node == CONFIG_NODE) {
1361 DEBUG_OFF(update, UPDATE_IN);
1362 DEBUG_OFF(update, UPDATE_OUT);
1363 DEBUG_OFF(update, UPDATE_PREFIX);
1364 } else {
1365 TERM_DEBUG_OFF(update, UPDATE_IN);
1366 TERM_DEBUG_OFF(update, UPDATE_OUT);
1367 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1368 vty_out(vty, "BGP updates debugging is off\n");
1369 }
1370 return CMD_SUCCESS;
1371 }
1372
1373 /* debug bgp zebra */
1374 DEFUN (debug_bgp_zebra,
1375 debug_bgp_zebra_cmd,
1376 "debug bgp zebra",
1377 DEBUG_STR
1378 BGP_STR
1379 "BGP Zebra messages\n")
1380 {
1381 if (vty->node == CONFIG_NODE)
1382 DEBUG_ON(zebra, ZEBRA);
1383 else {
1384 TERM_DEBUG_ON(zebra, ZEBRA);
1385 vty_out(vty, "BGP zebra debugging is on\n");
1386 }
1387 return CMD_SUCCESS;
1388 }
1389
1390 DEFUN (debug_bgp_zebra_prefix,
1391 debug_bgp_zebra_prefix_cmd,
1392 "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1393 DEBUG_STR
1394 BGP_STR
1395 "BGP Zebra messages\n"
1396 "Specify a prefix to debug\n"
1397 "IPv4 prefix\n"
1398 "IPv6 prefix\n")
1399 {
1400 int idx_ipv4_ipv6_prefixlen = 4;
1401 struct prefix *argv_p;
1402
1403 argv_p = prefix_new();
1404 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
1405 apply_mask(argv_p);
1406
1407 if (!bgp_debug_zebra_prefixes)
1408 bgp_debug_zebra_prefixes = list_new();
1409
1410 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, argv_p)) {
1411 vty_out(vty, "BGP zebra debugging is already enabled for %s\n",
1412 argv[idx_ipv4_ipv6_prefixlen]->arg);
1413 return CMD_SUCCESS;
1414 }
1415
1416 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, argv_p);
1417
1418 if (vty->node == CONFIG_NODE)
1419 DEBUG_ON(zebra, ZEBRA);
1420 else {
1421 TERM_DEBUG_ON(zebra, ZEBRA);
1422 vty_out(vty, "BGP zebra debugging is on for %s\n",
1423 argv[idx_ipv4_ipv6_prefixlen]->arg);
1424 }
1425
1426 return CMD_SUCCESS;
1427 }
1428
1429 DEFUN (no_debug_bgp_zebra,
1430 no_debug_bgp_zebra_cmd,
1431 "no debug bgp zebra",
1432 NO_STR
1433 DEBUG_STR
1434 BGP_STR
1435 "BGP Zebra messages\n")
1436 {
1437 bgp_debug_list_free(bgp_debug_zebra_prefixes);
1438
1439 if (vty->node == CONFIG_NODE)
1440 DEBUG_OFF(zebra, ZEBRA);
1441 else {
1442 TERM_DEBUG_OFF(zebra, ZEBRA);
1443 vty_out(vty, "BGP zebra debugging is off\n");
1444 }
1445 return CMD_SUCCESS;
1446 }
1447
1448 DEFUN (no_debug_bgp_zebra_prefix,
1449 no_debug_bgp_zebra_prefix_cmd,
1450 "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>",
1451 NO_STR
1452 DEBUG_STR
1453 BGP_STR
1454 "BGP Zebra messages\n"
1455 "Specify a prefix to debug\n"
1456 "IPv4 prefix\n"
1457 "IPv6 prefix\n")
1458 {
1459 int idx_ipv4_ipv6_prefixlen = 5;
1460 struct prefix *argv_p;
1461 int found_prefix = 0;
1462
1463 argv_p = prefix_new();
1464 (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p);
1465 apply_mask(argv_p);
1466
1467 if (bgp_debug_zebra_prefixes
1468 && !list_isempty(bgp_debug_zebra_prefixes)) {
1469 found_prefix = bgp_debug_list_remove_entry(
1470 bgp_debug_zebra_prefixes, NULL, argv_p);
1471
1472 if (list_isempty(bgp_debug_zebra_prefixes)) {
1473 if (vty->node == CONFIG_NODE)
1474 DEBUG_OFF(zebra, ZEBRA);
1475 else {
1476 TERM_DEBUG_OFF(zebra, ZEBRA);
1477 vty_out(vty, "BGP zebra debugging is off\n");
1478 }
1479 }
1480 }
1481
1482 if (found_prefix)
1483 vty_out(vty, "BGP zebra debugging is off for %s\n",
1484 argv[idx_ipv4_ipv6_prefixlen]->arg);
1485 else
1486 vty_out(vty, "BGP zebra debugging was not enabled for %s\n",
1487 argv[idx_ipv4_ipv6_prefixlen]->arg);
1488
1489 return CMD_SUCCESS;
1490 }
1491
1492 DEFUN (debug_bgp_allow_martians,
1493 debug_bgp_allow_martians_cmd,
1494 "debug bgp allow-martians",
1495 DEBUG_STR
1496 BGP_STR
1497 "BGP allow martian next hops\n")
1498 {
1499 if (vty->node == CONFIG_NODE)
1500 DEBUG_ON(allow_martians, ALLOW_MARTIANS);
1501 else {
1502 TERM_DEBUG_ON(allow_martians, ALLOW_MARTIANS);
1503 vty_out(vty, "BGP allow_martian next hop debugging is on\n");
1504 }
1505 return CMD_SUCCESS;
1506 }
1507
1508 DEFUN (no_debug_bgp_allow_martians,
1509 no_debug_bgp_allow_martians_cmd,
1510 "no debug bgp allow-martians",
1511 NO_STR
1512 DEBUG_STR
1513 BGP_STR
1514 "BGP allow martian next hops\n")
1515 {
1516 if (vty->node == CONFIG_NODE)
1517 DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
1518 else {
1519 TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
1520 vty_out(vty, "BGP allow martian next hop debugging is off\n");
1521 }
1522 return CMD_SUCCESS;
1523 }
1524
1525
1526 /* debug bgp update-groups */
1527 DEFUN (debug_bgp_update_groups,
1528 debug_bgp_update_groups_cmd,
1529 "debug bgp update-groups",
1530 DEBUG_STR
1531 BGP_STR
1532 "BGP update-groups\n")
1533 {
1534 if (vty->node == CONFIG_NODE)
1535 DEBUG_ON(update_groups, UPDATE_GROUPS);
1536 else {
1537 TERM_DEBUG_ON(update_groups, UPDATE_GROUPS);
1538 vty_out(vty, "BGP update-groups debugging is on\n");
1539 }
1540 return CMD_SUCCESS;
1541 }
1542
1543 DEFUN (no_debug_bgp_update_groups,
1544 no_debug_bgp_update_groups_cmd,
1545 "no debug bgp update-groups",
1546 NO_STR
1547 DEBUG_STR
1548 BGP_STR
1549 "BGP update-groups\n")
1550 {
1551 if (vty->node == CONFIG_NODE)
1552 DEBUG_OFF(update_groups, UPDATE_GROUPS);
1553 else {
1554 TERM_DEBUG_OFF(update_groups, UPDATE_GROUPS);
1555 vty_out(vty, "BGP update-groups debugging is off\n");
1556 }
1557 return CMD_SUCCESS;
1558 }
1559
1560 DEFUN (no_debug_bgp,
1561 no_debug_bgp_cmd,
1562 "no debug bgp",
1563 NO_STR
1564 DEBUG_STR
1565 BGP_STR)
1566 {
1567 struct bgp *bgp;
1568 struct listnode *ln;
1569
1570 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
1571 bgp_debug_list_free(bgp_debug_keepalive_peers);
1572 bgp_debug_list_free(bgp_debug_update_in_peers);
1573 bgp_debug_list_free(bgp_debug_update_out_peers);
1574 bgp_debug_list_free(bgp_debug_update_prefixes);
1575 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
1576 bgp_debug_list_free(bgp_debug_zebra_prefixes);
1577
1578 for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
1579 bgp_debug_clear_updgrp_update_dbg(bgp);
1580
1581 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
1582 TERM_DEBUG_OFF(update, UPDATE_IN);
1583 TERM_DEBUG_OFF(update, UPDATE_OUT);
1584 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
1585 TERM_DEBUG_OFF(bestpath, BESTPATH);
1586 TERM_DEBUG_OFF(as4, AS4);
1587 TERM_DEBUG_OFF(as4, AS4_SEGMENT);
1588 TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
1589 TERM_DEBUG_OFF(zebra, ZEBRA);
1590 TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
1591 TERM_DEBUG_OFF(nht, NHT);
1592 vty_out(vty, "All possible debugging has been turned off\n");
1593
1594 return CMD_SUCCESS;
1595 }
1596
1597 DEFUN_NOSH (show_debugging_bgp,
1598 show_debugging_bgp_cmd,
1599 "show debugging [bgp]",
1600 SHOW_STR
1601 DEBUG_STR
1602 BGP_STR)
1603 {
1604 vty_out(vty, "BGP debugging status:\n");
1605
1606 if (BGP_DEBUG(as4, AS4))
1607 vty_out(vty, " BGP as4 debugging is on\n");
1608
1609 if (BGP_DEBUG(as4, AS4_SEGMENT))
1610 vty_out(vty, " BGP as4 aspath segment debugging is on\n");
1611
1612 if (BGP_DEBUG(bestpath, BESTPATH))
1613 bgp_debug_list_print(vty, " BGP bestpath debugging is on",
1614 bgp_debug_bestpath_prefixes);
1615
1616 if (BGP_DEBUG(keepalive, KEEPALIVE))
1617 bgp_debug_list_print(vty, " BGP keepalives debugging is on",
1618 bgp_debug_keepalive_peers);
1619
1620 if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS))
1621 bgp_debug_list_print(vty,
1622 " BGP neighbor-events debugging is on",
1623 bgp_debug_neighbor_events_peers);
1624
1625 if (BGP_DEBUG(nht, NHT))
1626 vty_out(vty, " BGP next-hop tracking debugging is on\n");
1627
1628 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
1629 vty_out(vty, " BGP update-groups debugging is on\n");
1630
1631 if (BGP_DEBUG(update, UPDATE_PREFIX))
1632 bgp_debug_list_print(vty, " BGP updates debugging is on",
1633 bgp_debug_update_prefixes);
1634
1635 if (BGP_DEBUG(update, UPDATE_IN))
1636 bgp_debug_list_print(vty,
1637 " BGP updates debugging is on (inbound)",
1638 bgp_debug_update_in_peers);
1639
1640 if (BGP_DEBUG(update, UPDATE_OUT))
1641 bgp_debug_list_print(vty,
1642 " BGP updates debugging is on (outbound)",
1643 bgp_debug_update_out_peers);
1644
1645 if (BGP_DEBUG(zebra, ZEBRA))
1646 bgp_debug_list_print(vty, " BGP zebra debugging is on",
1647 bgp_debug_zebra_prefixes);
1648
1649 if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS))
1650 vty_out(vty, " BGP allow martian next hop debugging is on\n");
1651 vty_out(vty, "\n");
1652 return CMD_SUCCESS;
1653 }
1654
1655 /* return count of number of debug flags set */
1656 int bgp_debug_count(void)
1657 {
1658 int ret = 0;
1659 if (BGP_DEBUG(as4, AS4))
1660 ret++;
1661
1662 if (BGP_DEBUG(as4, AS4_SEGMENT))
1663 ret++;
1664
1665 if (BGP_DEBUG(bestpath, BESTPATH))
1666 ret++;
1667
1668 if (BGP_DEBUG(keepalive, KEEPALIVE))
1669 ret++;
1670
1671 if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS))
1672 ret++;
1673
1674 if (BGP_DEBUG(nht, NHT))
1675 ret++;
1676
1677 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
1678 ret++;
1679
1680 if (BGP_DEBUG(update, UPDATE_PREFIX))
1681 ret++;
1682
1683 if (BGP_DEBUG(update, UPDATE_IN))
1684 ret++;
1685
1686 if (BGP_DEBUG(update, UPDATE_OUT))
1687 ret++;
1688
1689 if (BGP_DEBUG(zebra, ZEBRA))
1690 ret++;
1691
1692 if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS))
1693 ret++;
1694
1695 return ret;
1696 }
1697
1698 static int bgp_config_write_debug(struct vty *vty)
1699 {
1700 int write = 0;
1701
1702 if (CONF_BGP_DEBUG(as4, AS4)) {
1703 vty_out(vty, "debug bgp as4\n");
1704 write++;
1705 }
1706
1707 if (CONF_BGP_DEBUG(as4, AS4_SEGMENT)) {
1708 vty_out(vty, "debug bgp as4 segment\n");
1709 write++;
1710 }
1711
1712 if (CONF_BGP_DEBUG(bestpath, BESTPATH)) {
1713 write += bgp_debug_list_conf_print(vty, "debug bgp bestpath",
1714 bgp_debug_bestpath_prefixes);
1715 }
1716
1717 if (CONF_BGP_DEBUG(keepalive, KEEPALIVE)) {
1718 write += bgp_debug_list_conf_print(vty, "debug bgp keepalives",
1719 bgp_debug_keepalive_peers);
1720 }
1721
1722 if (CONF_BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)) {
1723 write += bgp_debug_list_conf_print(
1724 vty, "debug bgp neighbor-events",
1725 bgp_debug_neighbor_events_peers);
1726 }
1727
1728 if (CONF_BGP_DEBUG(nht, NHT)) {
1729 vty_out(vty, "debug bgp nht\n");
1730 write++;
1731 }
1732
1733 if (CONF_BGP_DEBUG(update_groups, UPDATE_GROUPS)) {
1734 vty_out(vty, "debug bgp update-groups\n");
1735 write++;
1736 }
1737
1738 if (CONF_BGP_DEBUG(update, UPDATE_PREFIX)) {
1739 write += bgp_debug_list_conf_print(vty,
1740 "debug bgp updates prefix",
1741 bgp_debug_update_prefixes);
1742 }
1743
1744 if (CONF_BGP_DEBUG(update, UPDATE_IN)) {
1745 write += bgp_debug_list_conf_print(vty, "debug bgp updates in",
1746 bgp_debug_update_in_peers);
1747 }
1748
1749 if (CONF_BGP_DEBUG(update, UPDATE_OUT)) {
1750 write += bgp_debug_list_conf_print(vty, "debug bgp updates out",
1751 bgp_debug_update_out_peers);
1752 }
1753
1754 if (CONF_BGP_DEBUG(zebra, ZEBRA)) {
1755 if (!bgp_debug_zebra_prefixes
1756 || list_isempty(bgp_debug_zebra_prefixes)) {
1757 vty_out(vty, "debug bgp zebra\n");
1758 write++;
1759 } else {
1760 write += bgp_debug_list_conf_print(
1761 vty, "debug bgp zebra prefix",
1762 bgp_debug_zebra_prefixes);
1763 }
1764 }
1765
1766 if (CONF_BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) {
1767 vty_out(vty, "debug bgp allow-martians\n");
1768 write++;
1769 }
1770
1771 return write;
1772 }
1773
1774 static struct cmd_node debug_node = {DEBUG_NODE, "", 1};
1775
1776 void bgp_debug_init(void)
1777 {
1778 install_node(&debug_node, bgp_config_write_debug);
1779
1780 install_element(ENABLE_NODE, &show_debugging_bgp_cmd);
1781
1782 install_element(ENABLE_NODE, &debug_bgp_as4_cmd);
1783 install_element(CONFIG_NODE, &debug_bgp_as4_cmd);
1784 install_element(ENABLE_NODE, &debug_bgp_as4_segment_cmd);
1785 install_element(CONFIG_NODE, &debug_bgp_as4_segment_cmd);
1786
1787 install_element(ENABLE_NODE, &debug_bgp_neighbor_events_cmd);
1788 install_element(CONFIG_NODE, &debug_bgp_neighbor_events_cmd);
1789 install_element(ENABLE_NODE, &debug_bgp_nht_cmd);
1790 install_element(CONFIG_NODE, &debug_bgp_nht_cmd);
1791 install_element(ENABLE_NODE, &debug_bgp_keepalive_cmd);
1792 install_element(CONFIG_NODE, &debug_bgp_keepalive_cmd);
1793 install_element(ENABLE_NODE, &debug_bgp_update_cmd);
1794 install_element(CONFIG_NODE, &debug_bgp_update_cmd);
1795 install_element(ENABLE_NODE, &debug_bgp_zebra_cmd);
1796 install_element(CONFIG_NODE, &debug_bgp_zebra_cmd);
1797 install_element(ENABLE_NODE, &debug_bgp_allow_martians_cmd);
1798 install_element(CONFIG_NODE, &debug_bgp_allow_martians_cmd);
1799 install_element(ENABLE_NODE, &debug_bgp_update_groups_cmd);
1800 install_element(CONFIG_NODE, &debug_bgp_update_groups_cmd);
1801 install_element(ENABLE_NODE, &debug_bgp_bestpath_prefix_cmd);
1802 install_element(CONFIG_NODE, &debug_bgp_bestpath_prefix_cmd);
1803
1804 /* debug bgp updates (in|out) */
1805 install_element(ENABLE_NODE, &debug_bgp_update_direct_cmd);
1806 install_element(CONFIG_NODE, &debug_bgp_update_direct_cmd);
1807 install_element(ENABLE_NODE, &no_debug_bgp_update_direct_cmd);
1808 install_element(CONFIG_NODE, &no_debug_bgp_update_direct_cmd);
1809
1810 /* debug bgp updates (in|out) A.B.C.D */
1811 install_element(ENABLE_NODE, &debug_bgp_update_direct_peer_cmd);
1812 install_element(CONFIG_NODE, &debug_bgp_update_direct_peer_cmd);
1813 install_element(ENABLE_NODE, &no_debug_bgp_update_direct_peer_cmd);
1814 install_element(CONFIG_NODE, &no_debug_bgp_update_direct_peer_cmd);
1815
1816 /* debug bgp updates prefix A.B.C.D/M */
1817 install_element(ENABLE_NODE, &debug_bgp_update_prefix_cmd);
1818 install_element(CONFIG_NODE, &debug_bgp_update_prefix_cmd);
1819 install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_cmd);
1820 install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_cmd);
1821
1822 /* debug bgp zebra prefix A.B.C.D/M */
1823 install_element(ENABLE_NODE, &debug_bgp_zebra_prefix_cmd);
1824 install_element(CONFIG_NODE, &debug_bgp_zebra_prefix_cmd);
1825 install_element(ENABLE_NODE, &no_debug_bgp_zebra_prefix_cmd);
1826 install_element(CONFIG_NODE, &no_debug_bgp_zebra_prefix_cmd);
1827
1828 install_element(ENABLE_NODE, &no_debug_bgp_as4_cmd);
1829 install_element(CONFIG_NODE, &no_debug_bgp_as4_cmd);
1830 install_element(ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
1831 install_element(CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
1832
1833 /* debug bgp neighbor-events A.B.C.D */
1834 install_element(ENABLE_NODE, &debug_bgp_neighbor_events_peer_cmd);
1835 install_element(CONFIG_NODE, &debug_bgp_neighbor_events_peer_cmd);
1836 install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
1837 install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
1838
1839 /* debug bgp keepalive A.B.C.D */
1840 install_element(ENABLE_NODE, &debug_bgp_keepalive_peer_cmd);
1841 install_element(CONFIG_NODE, &debug_bgp_keepalive_peer_cmd);
1842 install_element(ENABLE_NODE, &no_debug_bgp_keepalive_peer_cmd);
1843 install_element(CONFIG_NODE, &no_debug_bgp_keepalive_peer_cmd);
1844
1845 install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_cmd);
1846 install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_cmd);
1847 install_element(ENABLE_NODE, &no_debug_bgp_nht_cmd);
1848 install_element(CONFIG_NODE, &no_debug_bgp_nht_cmd);
1849 install_element(ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
1850 install_element(CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
1851 install_element(ENABLE_NODE, &no_debug_bgp_update_cmd);
1852 install_element(CONFIG_NODE, &no_debug_bgp_update_cmd);
1853 install_element(ENABLE_NODE, &no_debug_bgp_zebra_cmd);
1854 install_element(CONFIG_NODE, &no_debug_bgp_zebra_cmd);
1855 install_element(ENABLE_NODE, &no_debug_bgp_allow_martians_cmd);
1856 install_element(CONFIG_NODE, &no_debug_bgp_allow_martians_cmd);
1857 install_element(ENABLE_NODE, &no_debug_bgp_update_groups_cmd);
1858 install_element(CONFIG_NODE, &no_debug_bgp_update_groups_cmd);
1859 install_element(ENABLE_NODE, &no_debug_bgp_cmd);
1860 install_element(ENABLE_NODE, &no_debug_bgp_bestpath_cmd);
1861 install_element(CONFIG_NODE, &no_debug_bgp_bestpath_cmd);
1862 install_element(ENABLE_NODE, &no_debug_bgp_bestpath_prefix_cmd);
1863 install_element(CONFIG_NODE, &no_debug_bgp_bestpath_prefix_cmd);
1864 }
1865
1866 /* Return true if this prefix is on the per_prefix_list of prefixes to debug
1867 * for BGP_DEBUG_TYPE
1868 */
1869 static int bgp_debug_per_prefix(struct prefix *p,
1870 unsigned long term_bgp_debug_type,
1871 unsigned int BGP_DEBUG_TYPE,
1872 struct list *per_prefix_list)
1873 {
1874 struct bgp_debug_filter *filter;
1875 struct listnode *node, *nnode;
1876
1877 if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
1878 /* We are debugging all prefixes so return true */
1879 if (!per_prefix_list || list_isempty(per_prefix_list))
1880 return 1;
1881
1882 else {
1883 if (!p)
1884 return 0;
1885
1886 for (ALL_LIST_ELEMENTS(per_prefix_list, node, nnode,
1887 filter))
1888 if (filter->p->prefixlen == p->prefixlen
1889 && prefix_match(filter->p, p))
1890 return 1;
1891
1892 return 0;
1893 }
1894 }
1895
1896 return 0;
1897 }
1898
1899 /* Return true if this peer is on the per_peer_list of peers to debug
1900 * for BGP_DEBUG_TYPE
1901 */
1902 static int bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type,
1903 unsigned int BGP_DEBUG_TYPE,
1904 struct list *per_peer_list)
1905 {
1906 struct bgp_debug_filter *filter;
1907 struct listnode *node, *nnode;
1908
1909 if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
1910 /* We are debugging all peers so return true */
1911 if (!per_peer_list || list_isempty(per_peer_list))
1912 return 1;
1913
1914 else {
1915 if (!host)
1916 return 0;
1917
1918 for (ALL_LIST_ELEMENTS(per_peer_list, node, nnode,
1919 filter))
1920 if (strcmp(filter->host, host) == 0)
1921 return 1;
1922
1923 return 0;
1924 }
1925 }
1926
1927 return 0;
1928 }
1929
1930 int bgp_debug_neighbor_events(struct peer *peer)
1931 {
1932 char *host = NULL;
1933
1934 if (peer)
1935 host = peer->host;
1936
1937 return bgp_debug_per_peer(host, term_bgp_debug_neighbor_events,
1938 BGP_DEBUG_NEIGHBOR_EVENTS,
1939 bgp_debug_neighbor_events_peers);
1940 }
1941
1942 int bgp_debug_keepalive(struct peer *peer)
1943 {
1944 char *host = NULL;
1945
1946 if (peer)
1947 host = peer->host;
1948
1949 return bgp_debug_per_peer(host, term_bgp_debug_keepalive,
1950 BGP_DEBUG_KEEPALIVE,
1951 bgp_debug_keepalive_peers);
1952 }
1953
1954 int bgp_debug_update(struct peer *peer, struct prefix *p,
1955 struct update_group *updgrp, unsigned int inbound)
1956 {
1957 char *host = NULL;
1958
1959 if (peer)
1960 host = peer->host;
1961
1962 if (inbound) {
1963 if (bgp_debug_per_peer(host, term_bgp_debug_update,
1964 BGP_DEBUG_UPDATE_IN,
1965 bgp_debug_update_in_peers))
1966 return 1;
1967 }
1968
1969 /* outbound */
1970 else {
1971 if (bgp_debug_per_peer(host, term_bgp_debug_update,
1972 BGP_DEBUG_UPDATE_OUT,
1973 bgp_debug_update_out_peers))
1974 return 1;
1975
1976 /* Check if update debugging implicitly enabled for the group.
1977 */
1978 if (updgrp && UPDGRP_DBG_ON(updgrp))
1979 return 1;
1980 }
1981
1982
1983 if (BGP_DEBUG(update, UPDATE_PREFIX)) {
1984 if (bgp_debug_per_prefix(p, term_bgp_debug_update,
1985 BGP_DEBUG_UPDATE_PREFIX,
1986 bgp_debug_update_prefixes))
1987 return 1;
1988 }
1989
1990 return 0;
1991 }
1992
1993 int bgp_debug_bestpath(struct prefix *p)
1994 {
1995 if (BGP_DEBUG(bestpath, BESTPATH)) {
1996 if (bgp_debug_per_prefix(p, term_bgp_debug_bestpath,
1997 BGP_DEBUG_BESTPATH,
1998 bgp_debug_bestpath_prefixes))
1999 return 1;
2000 }
2001
2002 return 0;
2003 }
2004
2005 int bgp_debug_zebra(struct prefix *p)
2006 {
2007 if (BGP_DEBUG(zebra, ZEBRA)) {
2008 if (bgp_debug_per_prefix(p, term_bgp_debug_zebra,
2009 BGP_DEBUG_ZEBRA,
2010 bgp_debug_zebra_prefixes))
2011 return 1;
2012 }
2013
2014 return 0;
2015 }
2016
2017 const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi,
2018 struct prefix_rd *prd,
2019 union prefixconstptr pu,
2020 mpls_label_t *label, u_int32_t num_labels,
2021 int addpath_valid, u_int32_t addpath_id,
2022 char *str, int size)
2023 {
2024 char rd_buf[RD_ADDRSTRLEN];
2025 char pfx_buf[PREFIX_STRLEN];
2026 char tag_buf[30];
2027 /* ' with addpath ID ' 17
2028 * max strlen of uint32 + 10
2029 * +/- (just in case) + 1
2030 * null terminator + 1
2031 * ============================ 29 */
2032 char pathid_buf[30];
2033
2034 if (size < BGP_PRD_PATH_STRLEN)
2035 return NULL;
2036
2037 /* Note: Path-id is created by default, but only included in update
2038 * sometimes. */
2039 pathid_buf[0] = '\0';
2040 if (addpath_valid)
2041 snprintf(pathid_buf, sizeof(pathid_buf), " with addpath ID %u",
2042 addpath_id);
2043
2044 tag_buf[0] = '\0';
2045 if (bgp_labeled_safi(safi) && num_labels) {
2046
2047 if (safi == SAFI_EVPN) {
2048 char tag_buf2[20];
2049
2050 bgp_evpn_label2str(label, num_labels, tag_buf2, 20);
2051 sprintf(tag_buf, " label %s", tag_buf2);
2052 } else {
2053 u_int32_t label_value;
2054
2055 label_value = decode_label(label);
2056 sprintf(tag_buf, " label %u", label_value);
2057 }
2058 }
2059
2060 if (prd)
2061 snprintf(str, size, "RD %s %s%s%s %s %s",
2062 prefix_rd2str(prd, rd_buf, sizeof(rd_buf)),
2063 prefix2str(pu, pfx_buf, sizeof(pfx_buf)), tag_buf,
2064 pathid_buf, afi2str(afi), safi2str(safi));
2065 else
2066 snprintf(str, size, "%s%s%s %s %s",
2067 prefix2str(pu, pfx_buf, sizeof(pfx_buf)), tag_buf,
2068 pathid_buf, afi2str(afi), safi2str(safi));
2069
2070 return str;
2071 }