]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_debug.c
'show ip bgp x.x.x.x' should display swpX when link-local peering
[mirror_frr.git] / bgpd / bgp_debug.c
CommitLineData
718e3744 1/* BGP-4, BGP-4+ packet debug routine
2 Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
5e4fa164 23#include <lib/version.h>
718e3744 24#include "prefix.h"
25#include "linklist.h"
26#include "stream.h"
27#include "command.h"
28#include "str.h"
29#include "log.h"
30#include "sockunion.h"
16286195 31#include "memory.h"
3f9c7369 32#include "queue.h"
718e3744 33
34#include "bgpd/bgpd.h"
35#include "bgpd/bgp_aspath.h"
36#include "bgpd/bgp_route.h"
37#include "bgpd/bgp_attr.h"
38#include "bgpd/bgp_debug.h"
39#include "bgpd/bgp_community.h"
3f9c7369 40#include "bgpd/bgp_updgrp.h"
718e3744 41
0b2aa3a0 42unsigned long conf_bgp_debug_as4;
16286195 43unsigned long conf_bgp_debug_neighbor_events;
718e3744 44unsigned long conf_bgp_debug_events;
45unsigned long conf_bgp_debug_packet;
46unsigned long conf_bgp_debug_filter;
47unsigned long conf_bgp_debug_keepalive;
48unsigned long conf_bgp_debug_update;
9fbdd100 49unsigned long conf_bgp_debug_bestpath;
a39275d7 50unsigned long conf_bgp_debug_zebra;
fb018d25 51unsigned long conf_bgp_debug_nht;
3f9c7369 52unsigned long conf_bgp_debug_update_groups;
718e3744 53
0b2aa3a0 54unsigned long term_bgp_debug_as4;
16286195 55unsigned long term_bgp_debug_neighbor_events;
718e3744 56unsigned long term_bgp_debug_events;
57unsigned long term_bgp_debug_packet;
58unsigned long term_bgp_debug_filter;
59unsigned long term_bgp_debug_keepalive;
60unsigned long term_bgp_debug_update;
9fbdd100 61unsigned long term_bgp_debug_bestpath;
a39275d7 62unsigned long term_bgp_debug_zebra;
fb018d25 63unsigned long term_bgp_debug_nht;
3f9c7369 64unsigned long term_bgp_debug_update_groups;
718e3744 65
16286195
DS
66struct list *bgp_debug_neighbor_events_peers = NULL;
67struct list *bgp_debug_keepalive_peers = NULL;
68struct list *bgp_debug_update_out_peers = NULL;
69struct list *bgp_debug_update_in_peers = NULL;
70struct list *bgp_debug_update_prefixes = NULL;
9fbdd100 71struct list *bgp_debug_bestpath_prefixes = NULL;
16286195
DS
72struct list *bgp_debug_zebra_prefixes = NULL;
73
718e3744 74/* messages for BGP-4 status */
b2d933f8 75const struct message bgp_status_msg[] =
718e3744 76{
718e3744 77 { Idle, "Idle" },
78 { Connect, "Connect" },
79 { Active, "Active" },
80 { OpenSent, "OpenSent" },
81 { OpenConfirm, "OpenConfirm" },
82 { Established, "Established" },
ca058a30
PJ
83 { Clearing, "Clearing" },
84 { Deleted, "Deleted" },
718e3744 85};
b2d933f8 86const int bgp_status_msg_max = BGP_STATUS_MAX;
718e3744 87
88/* BGP message type string. */
fd79ac91 89const char *bgp_type_str[] =
718e3744 90{
91 NULL,
92 "OPEN",
93 "UPDATE",
94 "NOTIFICATION",
95 "KEEPALIVE",
96 "ROUTE-REFRESH",
97 "CAPABILITY"
98};
99
100/* message for BGP-4 Notify */
b2d933f8 101static const struct message bgp_notify_msg[] =
718e3744 102{
718e3744 103 { BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
104 { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
105 { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
106 { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
16286195 107 { BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"},
718e3744 108 { BGP_NOTIFY_CEASE, "Cease"},
109 { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
110};
b2d933f8 111static const int bgp_notify_msg_max = BGP_NOTIFY_MAX;
718e3744 112
b2d933f8 113static const struct message bgp_notify_head_msg[] =
718e3744 114{
3950fda5 115 { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
116 { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
117 { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}
718e3744 118};
b2d933f8 119static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
718e3744 120
b2d933f8 121static const struct message bgp_notify_open_msg[] =
718e3744 122{
4b4e07d2 123 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 124 { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number" },
125 { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
126 { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
127 { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
128 { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
129 { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
130 { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
718e3744 131};
b2d933f8 132static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
718e3744 133
b2d933f8 134static const struct message bgp_notify_update_msg[] =
718e3744 135{
4b4e07d2 136 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 137 { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
138 { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
139 { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
140 { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
141 { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
142 { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
143 { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
144 { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
145 { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
146 { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
147 { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
718e3744 148};
b2d933f8 149static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
718e3744 150
b2d933f8 151static const struct message bgp_notify_cease_msg[] =
718e3744 152{
4b4e07d2 153 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 154 { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
155 { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
156 { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
157 { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
158 { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
159 { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
160 { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
161 { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
718e3744 162};
b2d933f8 163static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
718e3744 164
b2d933f8 165static const struct message bgp_notify_capability_msg[] =
718e3744 166{
4b4e07d2 167 { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
3950fda5 168 { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
169 { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
170 { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
718e3744 171};
b2d933f8 172static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
718e3744 173
174/* Origin strings. */
fd79ac91 175const char *bgp_origin_str[] = {"i","e","?"};
176const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
718e3744 177
16286195
DS
178
179/* Given a string return a pointer the corresponding peer structure */
180static struct peer *
181bgp_find_peer (struct vty *vty, const char *peer_str)
182{
183 int ret;
184 union sockunion su;
185 struct bgp *bgp;
186
187 bgp = vty->index;
188 ret = str2sockunion (peer_str, &su);
189
190 /* 'swpX' string */
191 if (ret < 0)
192 return peer_lookup_by_conf_if (bgp, peer_str);
193 else
194 return peer_lookup (bgp, &su);
195}
196
197static void
198bgp_debug_list_free(struct list *list)
199{
200 struct bgp_debug_filter *filter;
201 struct listnode *node, *nnode;
202
203 if (list)
204 for (ALL_LIST_ELEMENTS (list, node, nnode, filter))
205 {
206 listnode_delete (list, filter);
207
208 if (filter->p)
209 prefix_free(filter->p);
210
211 if (filter->peer)
212 peer_unlock (filter->peer);
213
214 XFREE (MTYPE_BGP_DEBUG_FILTER, filter);
215 }
216}
217
218/* Print the desc along with a list of peers/prefixes this debug is
219 * enabled for */
220static void
221bgp_debug_list_print (struct vty *vty, const char *desc, struct list *list)
222{
223 struct bgp_debug_filter *filter;
224 struct listnode *node, *nnode;
225 char buf[INET6_ADDRSTRLEN];
226
227 vty_out (vty, "%s", desc);
228
229 if (list && !list_isempty(list))
230 {
231 vty_out (vty, " for");
232 for (ALL_LIST_ELEMENTS (list, node, nnode, filter))
233 {
234 if (filter->peer)
235 vty_out (vty, " %s", filter->peer->host);
236
237 if (filter->p)
238 vty_out (vty, " %s/%d",
239 inet_ntop (filter->p->family, &filter->p->u.prefix, buf, INET6_ADDRSTRLEN),
240 filter->p->prefixlen);
241 }
242 }
243
244 vty_out (vty, "%s", VTY_NEWLINE);
245}
246
247static void
248bgp_debug_list_add_entry(struct list *list, struct peer *peer, struct prefix *p)
249{
250 struct bgp_debug_filter *filter;
251
252 filter = XCALLOC (MTYPE_BGP_DEBUG_FILTER, sizeof (struct bgp_debug_filter));
253
254 if (peer)
255 {
256 peer_lock (peer);
257 filter->peer = peer;
258 filter->p = NULL;
259 }
260 else if (p)
261 {
262 filter->peer = NULL;
263 filter->p = p;
264 }
265
266 listnode_add(list, filter);
267}
268
269static int
270bgp_debug_list_remove_entry(struct list *list, struct peer *peer, struct prefix *p)
271{
272 struct bgp_debug_filter *filter;
273 struct listnode *node, *nnode;
274
275 for (ALL_LIST_ELEMENTS (list, node, nnode, filter))
276 {
277 if (peer && filter->peer == peer)
278 {
279 listnode_delete (list, filter);
280 peer_unlock (filter->peer);
281 XFREE (MTYPE_BGP_DEBUG_FILTER, filter);
282 return 1;
283 }
284 else if (p && filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p))
285 {
286 listnode_delete (list, filter);
287 prefix_free (filter->p);
288 XFREE (MTYPE_BGP_DEBUG_FILTER, filter);
289 return 1;
290 }
291 }
292
293 return 0;
294}
295
296static int
297bgp_debug_list_has_entry(struct list *list, struct peer *peer, struct prefix *p)
298{
299 struct bgp_debug_filter *filter;
300 struct listnode *node, *nnode;
301
302 for (ALL_LIST_ELEMENTS (list, node, nnode, filter))
303 {
304 if (peer)
305 {
306 if (filter->peer == peer)
307 {
308 return 1;
309 }
310 }
311 else if (p)
312 {
313 if (filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p))
314 {
315 return 1;
316 }
317 }
318 }
319
320 return 0;
321}
322
3f9c7369
DS
323int
324bgp_debug_peer_updout_enabled(struct peer *peer)
325{
326 return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, peer, NULL));
327}
328
718e3744 329/* Dump attribute. */
e01f9cbb 330int
718e3744 331bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
332{
718e3744 333 if (! attr)
e01f9cbb 334 return 0;
718e3744 335
e01f9cbb 336 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
337 snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
338
339 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
340 snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
341 bgp_origin_str[attr->origin]);
718e3744 342
343#ifdef HAVE_IPV6
fb982c25
PJ
344 if (attr->extra)
345 {
346 char addrbuf[BUFSIZ];
347
348 /* Add MP case. */
801a9bcc
DS
349 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL
350 || attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
fb982c25
PJ
351 snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
352 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
353 addrbuf, BUFSIZ));
354
801a9bcc 355 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
fb982c25
PJ
356 snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
357 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
358 addrbuf, BUFSIZ));
359 }
718e3744 360#endif /* HAVE_IPV6 */
361
e01f9cbb 362 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
ddc943de 363 snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u",
718e3744 364 attr->local_pref);
365
e01f9cbb 366 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
ddc943de 367 snprintf (buf + strlen (buf), size - strlen (buf), ", metric %u",
718e3744 368 attr->med);
369
e01f9cbb 370 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)))
718e3744 371 snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
372 community_str (attr->community));
373
e01f9cbb 374 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
718e3744 375 snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
376
e01f9cbb 377 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
aea339f7 378 snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s",
fb982c25
PJ
379 attr->extra->aggregator_as,
380 inet_ntoa (attr->extra->aggregator_addr));
718e3744 381
e01f9cbb 382 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
718e3744 383 snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
fb982c25 384 inet_ntoa (attr->extra->originator_id));
718e3744 385
e01f9cbb 386 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
718e3744 387 {
388 int i;
389
e01f9cbb 390 snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
fb982c25 391 for (i = 0; i < attr->extra->cluster->length / 4; i++)
e01f9cbb 392 snprintf (buf + strlen (buf), size - strlen (buf), " %s",
fb982c25 393 inet_ntoa (attr->extra->cluster->list[i]));
718e3744 394 }
395
e01f9cbb 396 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
718e3744 397 snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
398 aspath_print (attr->aspath));
e01f9cbb 399
400 if (strlen (buf) > 1)
401 return 1;
402 else
403 return 0;
718e3744 404}
405
406/* dump notify packet */
407void
fd79ac91 408bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
409 const char *direct)
718e3744 410{
fd79ac91 411 const char *subcode_str;
1e0ce7ca 412 const char *code_str;
718e3744 413
414 subcode_str = "";
1e0ce7ca
LR
415 code_str = LOOKUP_DEF (bgp_notify_msg, bgp_notify->code,
416 "Unrecognized Error Code");
718e3744 417
1e0ce7ca 418 switch (bgp_notify->code)
718e3744 419 {
420 case BGP_NOTIFY_HEADER_ERR:
1e0ce7ca
LR
421 subcode_str = LOOKUP_DEF (bgp_notify_head_msg, bgp_notify->subcode,
422 "Unrecognized Error Subcode");
718e3744 423 break;
424 case BGP_NOTIFY_OPEN_ERR:
1e0ce7ca
LR
425 subcode_str = LOOKUP_DEF (bgp_notify_open_msg, bgp_notify->subcode,
426 "Unrecognized Error Subcode");
718e3744 427 break;
428 case BGP_NOTIFY_UPDATE_ERR:
1e0ce7ca
LR
429 subcode_str = LOOKUP_DEF (bgp_notify_update_msg, bgp_notify->subcode,
430 "Unrecognized Error Subcode");
718e3744 431 break;
432 case BGP_NOTIFY_HOLD_ERR:
718e3744 433 break;
434 case BGP_NOTIFY_FSM_ERR:
718e3744 435 break;
436 case BGP_NOTIFY_CEASE:
1e0ce7ca
LR
437 subcode_str = LOOKUP_DEF (bgp_notify_cease_msg, bgp_notify->subcode,
438 "Unrecognized Error Subcode");
718e3744 439 break;
440 case BGP_NOTIFY_CAPABILITY_ERR:
1e0ce7ca
LR
441 subcode_str = LOOKUP_DEF (bgp_notify_capability_msg, bgp_notify->subcode,
442 "Unrecognized Error Subcode");
718e3744 443 break;
444 }
3950fda5 445
16286195 446 if (BGP_DEBUG (neighbor_events, NEIGHBOR_EVENTS) || bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
3950fda5 447 zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
448 strcmp (direct, "received") == 0 ? "received from" : "sent to",
449 peer->host, bgp_notify->code, bgp_notify->subcode,
1e0ce7ca 450 code_str, subcode_str, bgp_notify->length,
3950fda5 451 bgp_notify->data ? bgp_notify->data : "");
718e3744 452}
6b0655a2 453
3f9c7369
DS
454static void
455bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp)
456{
457 if (!bgp)
458 bgp = bgp_get_default();
459 update_group_walk (bgp, update_group_clear_update_dbg, NULL);
460}
461
462
718e3744 463/* Debug option setting interface. */
464unsigned long bgp_debug_option = 0;
465
466int
467debug (unsigned int option)
468{
469 return bgp_debug_option & option;
470}
471
0b2aa3a0
PJ
472DEFUN (debug_bgp_as4,
473 debug_bgp_as4_cmd,
474 "debug bgp as4",
475 DEBUG_STR
476 BGP_STR
477 "BGP AS4 actions\n")
478{
479 if (vty->node == CONFIG_NODE)
480 DEBUG_ON (as4, AS4);
481 else
482 {
483 TERM_DEBUG_ON (as4, AS4);
484 vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
485 }
486 return CMD_SUCCESS;
487}
488
489DEFUN (no_debug_bgp_as4,
490 no_debug_bgp_as4_cmd,
491 "no debug bgp as4",
492 NO_STR
493 DEBUG_STR
494 BGP_STR
495 "BGP AS4 actions\n")
496{
497 if (vty->node == CONFIG_NODE)
498 DEBUG_OFF (as4, AS4);
499 else
500 {
501 TERM_DEBUG_OFF (as4, AS4);
502 vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
503 }
504 return CMD_SUCCESS;
505}
506
0b2aa3a0
PJ
507DEFUN (debug_bgp_as4_segment,
508 debug_bgp_as4_segment_cmd,
509 "debug bgp as4 segment",
510 DEBUG_STR
511 BGP_STR
6e22b901 512 "BGP AS4 actions\n"
0b2aa3a0
PJ
513 "BGP AS4 aspath segment handling\n")
514{
515 if (vty->node == CONFIG_NODE)
516 DEBUG_ON (as4, AS4_SEGMENT);
517 else
518 {
519 TERM_DEBUG_ON (as4, AS4_SEGMENT);
520 vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
521 }
522 return CMD_SUCCESS;
523}
524
525DEFUN (no_debug_bgp_as4_segment,
526 no_debug_bgp_as4_segment_cmd,
527 "no debug bgp as4 segment",
528 NO_STR
529 DEBUG_STR
530 BGP_STR
6e22b901 531 "BGP AS4 actions\n"
0b2aa3a0
PJ
532 "BGP AS4 aspath segment handling\n")
533{
534 if (vty->node == CONFIG_NODE)
535 DEBUG_OFF (as4, AS4_SEGMENT);
536 else
537 {
538 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
539 vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
540 }
541 return CMD_SUCCESS;
542}
543
16286195
DS
544/* debug bgp neighbor_events */
545DEFUN (debug_bgp_neighbor_events,
546 debug_bgp_neighbor_events_cmd,
547 "debug bgp neighbor-events",
718e3744 548 DEBUG_STR
549 BGP_STR
16286195 550 "BGP Neighbor Events\n")
718e3744 551{
552 if (vty->node == CONFIG_NODE)
16286195 553 DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS);
718e3744 554 else
555 {
16286195
DS
556 TERM_DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS);
557 vty_out (vty, "BGP neighbor-events debugging is on%s", VTY_NEWLINE);
718e3744 558 }
559 return CMD_SUCCESS;
560}
561
16286195
DS
562DEFUN (debug_bgp_neighbor_events_peer,
563 debug_bgp_neighbor_events_peer_cmd,
564 "debug bgp neighbor-events (A.B.C.D|X:X::X:X|WORD)",
718e3744 565 DEBUG_STR
566 BGP_STR
16286195
DS
567 "BGP Neighbor Events\n"
568 "BGP neighbor IP address to debug\n"
569 "BGP IPv6 neighbor to debug\n"
570 "BGP neighbor on interface to debug\n")
718e3744 571{
16286195
DS
572 struct peer *peer;
573
574 peer = bgp_find_peer (vty, argv[0]);
575 if (!peer)
576 {
577 vty_out (vty, "%s is not a configured peer%s", argv[0], VTY_NEWLINE);
578 return CMD_WARNING;
579 }
580
581 if (!bgp_debug_neighbor_events_peers)
582 bgp_debug_neighbor_events_peers = list_new ();
583
584 if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, peer, NULL))
585 {
586 vty_out (vty, "BGP neighbor-events debugging is already enabled for %s%s", peer->host, VTY_NEWLINE);
587 return CMD_SUCCESS;
588 }
589
590 bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, peer, NULL);
591
718e3744 592 if (vty->node == CONFIG_NODE)
16286195 593 DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS);
718e3744 594 else
595 {
16286195
DS
596 TERM_DEBUG_ON (neighbor_events, NEIGHBOR_EVENTS);
597 vty_out (vty, "BGP neighbor-events debugging is on for %s%s", argv[0], VTY_NEWLINE);
718e3744 598 }
599 return CMD_SUCCESS;
600}
601
16286195
DS
602DEFUN (no_debug_bgp_neighbor_events,
603 no_debug_bgp_neighbor_events_cmd,
604 "no debug bgp neighbor-events",
605 NO_STR
718e3744 606 DEBUG_STR
607 BGP_STR
16286195 608 "Neighbor Events\n")
718e3744 609{
16286195
DS
610 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
611
718e3744 612 if (vty->node == CONFIG_NODE)
16286195 613 DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS);
718e3744 614 else
615 {
16286195
DS
616 TERM_DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS);
617 vty_out (vty, "BGP neighbor-events debugging is off%s", VTY_NEWLINE);
718e3744 618 }
619 return CMD_SUCCESS;
620}
621
16286195
DS
622DEFUN (no_debug_bgp_neighbor_events_peer,
623 no_debug_bgp_neighbor_events_peer_cmd,
624 "no debug bgp neighbor-events (A.B.C.D|X:X::X:X|WORD)",
718e3744 625 NO_STR
626 DEBUG_STR
627 BGP_STR
16286195
DS
628 "Neighbor Events\n"
629 "BGP neighbor IP address to debug\n"
630 "BGP IPv6 neighbor to debug\n"
631 "BGP neighbor on interface to debug\n")
718e3744 632{
16286195
DS
633 int found_peer = 0;
634 struct peer *peer;
635
636 peer = bgp_find_peer (vty, argv[0]);
637 if (!peer)
638 {
639 vty_out (vty, "%s is not a configured peer%s", argv[0], VTY_NEWLINE);
640 return CMD_WARNING;
641 }
642
643 if (bgp_debug_neighbor_events_peers && !list_isempty(bgp_debug_neighbor_events_peers))
718e3744 644 {
16286195
DS
645 found_peer = bgp_debug_list_remove_entry(bgp_debug_neighbor_events_peers, peer, NULL);
646
647 if (list_isempty(bgp_debug_neighbor_events_peers))
648 {
649 if (vty->node == CONFIG_NODE)
650 DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS);
651 else
652 TERM_DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS);
653 }
718e3744 654 }
16286195
DS
655
656 if (found_peer)
657 vty_out (vty, "BGP neighbor-events debugging is off for %s%s", argv[0], VTY_NEWLINE);
658 else
659 vty_out (vty, "BGP neighbor-events debugging was not enabled for %s%s", argv[0], VTY_NEWLINE);
660
718e3744 661 return CMD_SUCCESS;
662}
663
16286195 664/* debug bgp nht */
fb018d25
DS
665DEFUN (debug_bgp_nht,
666 debug_bgp_nht_cmd,
667 "debug bgp nht",
668 DEBUG_STR
669 BGP_STR
670 "BGP nexthop tracking events\n")
671{
672 if (vty->node == CONFIG_NODE)
673 DEBUG_ON (nht, NHT);
674 else
675 {
676 TERM_DEBUG_ON (nht, NHT);
677 vty_out (vty, "BGP nexthop tracking debugging is on%s", VTY_NEWLINE);
678 }
679 return CMD_SUCCESS;
680}
681
682DEFUN (no_debug_bgp_nht,
683 no_debug_bgp_nht_cmd,
684 "no debug bgp nht",
685 NO_STR
686 DEBUG_STR
687 BGP_STR
688 "BGP nexthop tracking events\n")
689{
690 if (vty->node == CONFIG_NODE)
691 DEBUG_OFF (nht, NHT);
692 else
693 {
694 TERM_DEBUG_OFF (nht, NHT);
695 vty_out (vty, "BGP nexthop tracking debugging is off%s", VTY_NEWLINE);
696 }
697 return CMD_SUCCESS;
698}
699
16286195
DS
700/* debug bgp keepalives */
701DEFUN (debug_bgp_keepalive,
702 debug_bgp_keepalive_cmd,
703 "debug bgp keepalives",
718e3744 704 DEBUG_STR
705 BGP_STR
16286195 706 "BGP keepalives\n")
718e3744 707{
708 if (vty->node == CONFIG_NODE)
16286195 709 DEBUG_ON (keepalive, KEEPALIVE);
718e3744 710 else
711 {
16286195
DS
712 TERM_DEBUG_ON (keepalive, KEEPALIVE);
713 vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
718e3744 714 }
715 return CMD_SUCCESS;
716}
717
16286195
DS
718DEFUN (debug_bgp_keepalive_peer,
719 debug_bgp_keepalive_peer_cmd,
720 "debug bgp keepalives (A.B.C.D|X:X::X:X|WORD)",
718e3744 721 DEBUG_STR
722 BGP_STR
16286195
DS
723 "BGP Neighbor Events\n"
724 "BGP neighbor IP address to debug\n"
725 "BGP IPv6 neighbor to debug\n"
726 "BGP neighbor on interface to debug\n")
718e3744 727{
16286195
DS
728 struct peer *peer;
729
730 peer = bgp_find_peer (vty, argv[0]);
731 if (!peer)
718e3744 732 {
16286195
DS
733 vty_out (vty, "%s is not a configured peer%s", argv[0], VTY_NEWLINE);
734 return CMD_WARNING;
718e3744 735 }
718e3744 736
16286195
DS
737 if (!bgp_debug_keepalive_peers)
738 bgp_debug_keepalive_peers = list_new ();
739
740 if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, peer, NULL))
741 {
742 vty_out (vty, "BGP keepalive debugging is already enabled for %s%s", peer->host, VTY_NEWLINE);
743 return CMD_SUCCESS;
744 }
745
746 bgp_debug_list_add_entry(bgp_debug_keepalive_peers, peer, NULL);
718e3744 747
718e3744 748 if (vty->node == CONFIG_NODE)
749 DEBUG_ON (keepalive, KEEPALIVE);
750 else
751 {
752 TERM_DEBUG_ON (keepalive, KEEPALIVE);
16286195 753 vty_out (vty, "BGP keepalives debugging is on for %s%s", argv[0], VTY_NEWLINE);
718e3744 754 }
755 return CMD_SUCCESS;
756}
757
758DEFUN (no_debug_bgp_keepalive,
759 no_debug_bgp_keepalive_cmd,
760 "no debug bgp keepalives",
761 NO_STR
762 DEBUG_STR
763 BGP_STR
764 "BGP keepalives\n")
765{
16286195
DS
766 bgp_debug_list_free(bgp_debug_keepalive_peers);
767
718e3744 768 if (vty->node == CONFIG_NODE)
769 DEBUG_OFF (keepalive, KEEPALIVE);
770 else
771 {
772 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
773 vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
774 }
775 return CMD_SUCCESS;
776}
777
16286195
DS
778DEFUN (no_debug_bgp_keepalive_peer,
779 no_debug_bgp_keepalive_peer_cmd,
780 "no debug bgp keepalives (A.B.C.D|X:X::X:X|WORD)",
781 NO_STR
782 DEBUG_STR
718e3744 783 BGP_STR
16286195
DS
784 "BGP keepalives\n"
785 "BGP neighbor IP address to debug\n"
786 "BGP IPv6 neighbor to debug\n"
787 "BGP neighbor on interface to debug\n")
788{
789 int found_peer = 0;
790 struct peer *peer;
791
792 peer = bgp_find_peer (vty, argv[0]);
793 if (!peer)
794 {
795 vty_out (vty, "%s is not a configured peer%s", argv[0], VTY_NEWLINE);
796 return CMD_WARNING;
797 }
718e3744 798
16286195
DS
799 if (bgp_debug_keepalive_peers && !list_isempty(bgp_debug_keepalive_peers))
800 {
801 found_peer = bgp_debug_list_remove_entry(bgp_debug_keepalive_peers, peer, NULL);
802
803 if (list_isempty(bgp_debug_keepalive_peers))
804 {
805 if (vty->node == CONFIG_NODE)
806 DEBUG_OFF (keepalive, KEEPALIVE);
807 else
808 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
809 }
810 }
811
812 if (found_peer)
813 vty_out (vty, "BGP keepalives debugging is off for %s%s", argv[0], VTY_NEWLINE);
814 else
815 vty_out (vty, "BGP keepalives debugging was not enabled for %s%s", argv[0], VTY_NEWLINE);
816
817 return CMD_SUCCESS;
818}
819
9fbdd100
DS
820/* debug bgp bestpath */
821DEFUN (debug_bgp_bestpath_prefix,
822 debug_bgp_bestpath_prefix_cmd,
823 "debug bgp bestpath (A.B.C.D/M|X:X::X:X/M)",
824 DEBUG_STR
825 BGP_STR
826 "BGP bestpath\n"
827 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
828 "IPv6 prefix <network>/<length>\n")
829
830{
831 struct prefix *argv_p;
832 int ret;
833
834 argv_p = prefix_new();
835 ret = str2prefix (argv[0], argv_p);
836 if (!ret)
837 {
838 prefix_free(argv_p);
839 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
840 return CMD_WARNING;
841 }
842
843
844 if (!bgp_debug_bestpath_prefixes)
845 bgp_debug_bestpath_prefixes = list_new ();
846
847 if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL, argv_p))
848 {
849 vty_out (vty, "BGP bestptah debugging is already enabled for %s%s", argv[0], VTY_NEWLINE);
850 return CMD_SUCCESS;
851 }
852
853 bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, argv_p);
854
855 if (vty->node == CONFIG_NODE)
856 {
857 DEBUG_ON (bestpath, BESTPATH);
858 }
859 else
860 {
861 TERM_DEBUG_ON (bestpath, BESTPATH);
862 vty_out (vty, "BGP bestpath debugging is on for %s%s", argv[0], VTY_NEWLINE);
863 }
864
865 return CMD_SUCCESS;
866}
867
868DEFUN (no_debug_bgp_bestpath_prefix,
869 no_debug_bgp_bestpath_prefix_cmd,
870 "no debug bgp bestpath (A.B.C.D/M|X:X::X:X/M)",
871 NO_STR
872 DEBUG_STR
873 BGP_STR
874 "BGP bestpath\n"
875 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
876 "IPv6 prefix <network>/<length>\n")
877
878{
879 struct prefix *argv_p;
880 int found_prefix = 0;
881 int ret;
882
883 argv_p = prefix_new();
884 ret = str2prefix (argv[0], argv_p);
885 if (!ret)
886 {
887 prefix_free(argv_p);
888 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
889 return CMD_WARNING;
890 }
891
892 if (bgp_debug_bestpath_prefixes && !list_isempty(bgp_debug_bestpath_prefixes))
893 {
894 found_prefix = bgp_debug_list_remove_entry(bgp_debug_bestpath_prefixes, NULL, argv_p);
895
896 if (list_isempty(bgp_debug_bestpath_prefixes))
897 {
898 if (vty->node == CONFIG_NODE)
899 {
900 DEBUG_OFF (bestpath, BESTPATH);
901 }
902 else
903 {
904 TERM_DEBUG_OFF (bestpath, BESTPATH);
905 vty_out (vty, "BGP bestpath debugging (per prefix) is off%s", VTY_NEWLINE);
906 }
907 }
908 }
909
910 if (found_prefix)
911 vty_out (vty, "BGP bestpath debugging is off for %s%s", argv[0], VTY_NEWLINE);
912 else
913 vty_out (vty, "BGP bestpath debugging was not enabled for %s%s", argv[0], VTY_NEWLINE);
914
915 return CMD_SUCCESS;
916}
917
918DEFUN (no_debug_bgp_bestpath,
919 no_debug_bgp_bestpath_cmd,
920 "no debug bgp bestpath",
921 NO_STR
922 DEBUG_STR
923 BGP_STR
924 "BGP bestpath\n")
925{
926 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
927
928 if (vty->node == CONFIG_NODE)
929 DEBUG_OFF (bestpath, BESTPATH);
930 else
931 {
932 TERM_DEBUG_OFF (bestpath, BESTPATH);
933 vty_out (vty, "BGP bestpath debugging is off%s", VTY_NEWLINE);
934 }
935 return CMD_SUCCESS;
936}
937
938
939
16286195 940/* debug bgp updates */
718e3744 941DEFUN (debug_bgp_update,
942 debug_bgp_update_cmd,
943 "debug bgp updates",
944 DEBUG_STR
945 BGP_STR
946 "BGP updates\n")
947{
948 if (vty->node == CONFIG_NODE)
949 {
950 DEBUG_ON (update, UPDATE_IN);
951 DEBUG_ON (update, UPDATE_OUT);
952 }
953 else
954 {
955 TERM_DEBUG_ON (update, UPDATE_IN);
956 TERM_DEBUG_ON (update, UPDATE_OUT);
957 vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
958 }
959 return CMD_SUCCESS;
960}
961
962DEFUN (debug_bgp_update_direct,
963 debug_bgp_update_direct_cmd,
964 "debug bgp updates (in|out)",
965 DEBUG_STR
966 BGP_STR
967 "BGP updates\n"
968 "Inbound updates\n"
969 "Outbound updates\n")
970{
971 if (vty->node == CONFIG_NODE)
972 {
973 if (strncmp ("i", argv[0], 1) == 0)
974 {
975 DEBUG_OFF (update, UPDATE_OUT);
976 DEBUG_ON (update, UPDATE_IN);
977 }
978 else
979 {
980 DEBUG_OFF (update, UPDATE_IN);
981 DEBUG_ON (update, UPDATE_OUT);
982 }
983 }
984 else
985 {
986 if (strncmp ("i", argv[0], 1) == 0)
987 {
988 TERM_DEBUG_OFF (update, UPDATE_OUT);
989 TERM_DEBUG_ON (update, UPDATE_IN);
990 vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
991 }
992 else
993 {
994 TERM_DEBUG_OFF (update, UPDATE_IN);
995 TERM_DEBUG_ON (update, UPDATE_OUT);
996 vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
997 }
998 }
999 return CMD_SUCCESS;
1000}
1001
16286195
DS
1002DEFUN (debug_bgp_update_direct_peer,
1003 debug_bgp_update_direct_peer_cmd,
1004 "debug bgp updates (in|out) (A.B.C.D|X:X::X:X|WORD)",
718e3744 1005 DEBUG_STR
1006 BGP_STR
16286195
DS
1007 "BGP updates\n"
1008 "Inbound updates\n"
1009 "Outbound updates\n"
1010 "BGP neighbor IP address to debug\n"
1011 "BGP IPv6 neighbor to debug\n"
1012 "BGP neighbor on interface to debug\n")
718e3744 1013{
16286195
DS
1014 struct peer *peer;
1015 int inbound;
1016
1017 peer = bgp_find_peer (vty, argv[1]);
1018 if (!peer)
1019 {
1020 vty_out (vty, "%s is not a configured peer%s", argv[1], VTY_NEWLINE);
1021 return CMD_WARNING;
1022 }
1023
1024
1025 if (!bgp_debug_update_in_peers)
1026 bgp_debug_update_in_peers = list_new ();
1027
1028 if (!bgp_debug_update_out_peers)
1029 bgp_debug_update_out_peers = list_new ();
1030
1031 if (strncmp ("i", argv[0], 1) == 0)
1032 inbound = 1;
1033 else
1034 inbound = 0;
1035
1036 if (inbound)
1037 {
1038 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, peer, NULL))
1039 {
1040 vty_out (vty, "BGP inbound update debugging is already enabled for %s%s", peer->host, VTY_NEWLINE);
1041 return CMD_SUCCESS;
1042 }
1043 }
1044
1045 else
1046 {
1047 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, peer, NULL))
1048 {
1049 vty_out (vty, "BGP outbound update debugging is already enabled for %s%s", peer->host, VTY_NEWLINE);
1050 return CMD_SUCCESS;
1051 }
1052 }
1053
1054 if (inbound)
1055 bgp_debug_list_add_entry(bgp_debug_update_in_peers, peer, NULL);
1056 else
3f9c7369
DS
1057 {
1058 struct peer_af *paf;
1059 int af;
1060
1061 bgp_debug_list_add_entry(bgp_debug_update_out_peers, peer, NULL);
1062 PEERAF_FOREACH (peer, paf, af)
1063 {
1064 if (PAF_SUBGRP (paf))
1065 {
1066 UPDGRP_PEER_DBG_EN(PAF_SUBGRP(paf)->update_group);
1067 }
1068 }
1069 }
16286195 1070
718e3744 1071 if (vty->node == CONFIG_NODE)
1072 {
16286195
DS
1073 if (inbound)
1074 {
1075 DEBUG_OFF (update, UPDATE_OUT);
1076 DEBUG_ON (update, UPDATE_IN);
1077 }
1078 else
1079 {
1080 DEBUG_OFF (update, UPDATE_IN);
1081 DEBUG_ON (update, UPDATE_OUT);
1082 }
718e3744 1083 }
1084 else
1085 {
16286195
DS
1086 if (inbound)
1087 {
1088 TERM_DEBUG_OFF (update, UPDATE_OUT);
1089 TERM_DEBUG_ON (update, UPDATE_IN);
1090 vty_out (vty, "BGP updates debugging is on (inbound) for %s%s", argv[1], VTY_NEWLINE);
1091 }
1092 else
1093 {
1094 TERM_DEBUG_OFF (update, UPDATE_IN);
1095 TERM_DEBUG_ON (update, UPDATE_OUT);
1096 vty_out (vty, "BGP updates debugging is on (outbound) for %s%s", argv[1], VTY_NEWLINE);
1097 }
718e3744 1098 }
1099 return CMD_SUCCESS;
1100}
1101
16286195
DS
1102DEFUN (no_debug_bgp_update_direct_peer,
1103 no_debug_bgp_update_direct_peer_cmd,
1104 "no debug bgp updates (in|out) (A.B.C.D|X:X::X:X|WORD)",
1105 NO_STR
1106 DEBUG_STR
718e3744 1107 BGP_STR
16286195
DS
1108 "BGP updates\n"
1109 "Inbound updates\n"
1110 "Outbound updates\n"
1111 "BGP neighbor IP address to debug\n"
1112 "BGP IPv6 neighbor to debug\n"
1113 "BGP neighbor on interface to debug\n")
1114{
1115 int inbound;
1116 int found_peer = 0;
1117 struct peer *peer;
1118
1119 peer = bgp_find_peer (vty, argv[1]);
1120 if (!peer)
1121 {
1122 vty_out (vty, "%s is not a configured peer%s", argv[1], VTY_NEWLINE);
1123 return CMD_WARNING;
1124 }
718e3744 1125
16286195
DS
1126 if (strncmp ("i", argv[0], 1) == 0)
1127 inbound = 1;
1128 else
1129 inbound = 0;
1130
1131 if (inbound && bgp_debug_update_in_peers &&
1132 !list_isempty(bgp_debug_update_in_peers))
1133 {
1134 found_peer = bgp_debug_list_remove_entry(bgp_debug_update_in_peers, peer, NULL);
1135
1136 if (list_isempty(bgp_debug_update_in_peers))
1137 {
1138 if (vty->node == CONFIG_NODE)
1139 DEBUG_OFF (update, UPDATE_IN);
1140 else
1141 {
1142 TERM_DEBUG_OFF (update, UPDATE_IN);
1143 vty_out (vty, "BGP updates debugging (inbound) is off%s", VTY_NEWLINE);
1144 }
1145 }
1146 }
1147
1148 if (!inbound && bgp_debug_update_out_peers &&
1149 !list_isempty(bgp_debug_update_out_peers))
1150 {
1151 found_peer = bgp_debug_list_remove_entry(bgp_debug_update_out_peers, peer, NULL);
1152
1153 if (list_isempty(bgp_debug_update_out_peers))
1154 {
1155 if (vty->node == CONFIG_NODE)
1156 DEBUG_OFF (update, UPDATE_OUT);
1157 else
1158 {
1159 TERM_DEBUG_OFF (update, UPDATE_OUT);
1160 vty_out (vty, "BGP updates debugging (outbound) is off%s", VTY_NEWLINE);
1161 }
1162 }
3f9c7369
DS
1163
1164 if (found_peer)
1165 {
1166 struct peer_af *paf;
1167 int af;
1168
1169 PEERAF_FOREACH (peer, paf, af)
1170 {
1171 if (PAF_SUBGRP (paf))
1172 {
1173 UPDGRP_PEER_DBG_DIS(PAF_SUBGRP(paf)->update_group);
1174 }
1175 }
1176 }
16286195
DS
1177 }
1178
1179 if (found_peer)
1180 if (inbound)
1181 vty_out (vty, "BGP updates debugging (inbound) is off for %s%s", argv[1], VTY_NEWLINE);
1182 else
1183 vty_out (vty, "BGP updates debugging (outbound) is off for %s%s", argv[1], VTY_NEWLINE);
1184 else
1185 if (inbound)
1186 vty_out (vty, "BGP updates debugging (inbound) was not enabled for %s%s", argv[1], VTY_NEWLINE);
1187 else
1188 vty_out (vty, "BGP updates debugging (outbound) was not enabled for %s%s", argv[1], VTY_NEWLINE);
1189
1190 return CMD_SUCCESS;
1191}
1192
1193DEFUN (debug_bgp_update_prefix,
1194 debug_bgp_update_prefix_cmd,
1195 "debug bgp updates prefix (A.B.C.D/M|X:X::X:X/M)",
718e3744 1196 DEBUG_STR
16286195
DS
1197 BGP_STR
1198 "BGP updates\n"
1199 "Specify a prefix to debug\n"
1200 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1201 "IPv6 prefix <network>/<length>\n")
1202
718e3744 1203{
16286195
DS
1204 struct prefix *argv_p;
1205 int ret;
1206
1207 argv_p = prefix_new();
1208 ret = str2prefix (argv[0], argv_p);
1209 if (!ret)
1210 {
1211 prefix_free(argv_p);
1212 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1213 return CMD_WARNING;
1214 }
1215
1216
1217 if (!bgp_debug_update_prefixes)
1218 bgp_debug_update_prefixes = list_new ();
1219
1220 if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p))
1221 {
1222 vty_out (vty, "BGP updates debugging is already enabled for %s%s", argv[0], VTY_NEWLINE);
1223 return CMD_SUCCESS;
1224 }
1225
1226 bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p);
1227
718e3744 1228 if (vty->node == CONFIG_NODE)
16286195
DS
1229 {
1230 DEBUG_ON (update, UPDATE_PREFIX);
1231 }
718e3744 1232 else
1233 {
16286195
DS
1234 TERM_DEBUG_ON (update, UPDATE_PREFIX);
1235 vty_out (vty, "BGP updates debugging is on for %s%s", argv[0], VTY_NEWLINE);
718e3744 1236 }
16286195 1237
718e3744 1238 return CMD_SUCCESS;
1239}
1240
16286195
DS
1241DEFUN (no_debug_bgp_update_prefix,
1242 no_debug_bgp_update_prefix_cmd,
1243 "no debug bgp updates prefix (A.B.C.D/M|X:X::X:X/M)",
718e3744 1244 NO_STR
1245 DEBUG_STR
16286195
DS
1246 BGP_STR
1247 "BGP updates\n"
1248 "Specify a prefix to debug\n"
1249 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1250 "IPv6 prefix <network>/<length>\n")
1251
1252{
1253 struct prefix *argv_p;
1254 int found_prefix = 0;
1255 int ret;
1256
1257 argv_p = prefix_new();
1258 ret = str2prefix (argv[0], argv_p);
1259 if (!ret)
1260 {
1261 prefix_free(argv_p);
1262 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1263 return CMD_WARNING;
1264 }
1265
1266 if (bgp_debug_update_prefixes && !list_isempty(bgp_debug_update_prefixes))
1267 {
1268 found_prefix = bgp_debug_list_remove_entry(bgp_debug_update_prefixes, NULL, argv_p);
1269
1270 if (list_isempty(bgp_debug_update_prefixes))
1271 {
1272 if (vty->node == CONFIG_NODE)
1273 {
1274 DEBUG_OFF (update, UPDATE_PREFIX);
1275 }
1276 else
1277 {
1278 TERM_DEBUG_OFF (update, UPDATE_PREFIX);
1279 vty_out (vty, "BGP updates debugging (per prefix) is off%s", VTY_NEWLINE);
1280 }
1281 }
1282 }
1283
1284 if (found_prefix)
1285 vty_out (vty, "BGP updates debugging is off for %s%s", argv[0], VTY_NEWLINE);
1286 else
1287 vty_out (vty, "BGP updates debugging was not enabled for %s%s", argv[0], VTY_NEWLINE);
1288
1289 return CMD_SUCCESS;
1290}
1291
1292DEFUN (no_debug_bgp_update,
1293 no_debug_bgp_update_cmd,
1294 "no debug bgp updates",
1295 NO_STR
1296 DEBUG_STR
1297 BGP_STR
1298 "BGP updates\n")
718e3744 1299{
16286195
DS
1300 bgp_debug_list_free(bgp_debug_update_in_peers);
1301 bgp_debug_list_free(bgp_debug_update_out_peers);
1302 bgp_debug_list_free(bgp_debug_update_prefixes);
1303
3f9c7369
DS
1304 bgp_debug_clear_updgrp_update_dbg(vty->index);
1305
718e3744 1306 if (vty->node == CONFIG_NODE)
16286195
DS
1307 {
1308 DEBUG_OFF (update, UPDATE_IN);
1309 DEBUG_OFF (update, UPDATE_OUT);
1310 DEBUG_OFF (update, UPDATE_PREFIX);
1311 }
718e3744 1312 else
1313 {
16286195
DS
1314 TERM_DEBUG_OFF (update, UPDATE_IN);
1315 TERM_DEBUG_OFF (update, UPDATE_OUT);
1316 TERM_DEBUG_OFF (update, UPDATE_PREFIX);
1317 vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
718e3744 1318 }
1319 return CMD_SUCCESS;
1320}
1321
16286195 1322/* debug bgp zebra */
a39275d7
AS
1323DEFUN (debug_bgp_zebra,
1324 debug_bgp_zebra_cmd,
1325 "debug bgp zebra",
1326 DEBUG_STR
1327 BGP_STR
1328 "BGP Zebra messages\n")
1329{
1330 if (vty->node == CONFIG_NODE)
1331 DEBUG_ON (zebra, ZEBRA);
1332 else
1333 {
1334 TERM_DEBUG_ON (zebra, ZEBRA);
1335 vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
1336 }
1337 return CMD_SUCCESS;
1338}
1339
16286195
DS
1340DEFUN (debug_bgp_zebra_prefix,
1341 debug_bgp_zebra_prefix_cmd,
1342 "debug bgp zebra prefix (A.B.C.D/M|X:X::X:X/M)",
1343 DEBUG_STR
1344 BGP_STR
1345 "BGP Zebra messages\n"
1346 "Specify a prefix to debug\n"
1347 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1348 "IPv6 prefix <network>/<length>\n")
1349
1350{
1351 struct prefix *argv_p;
1352 int ret;
1353
1354 argv_p = prefix_new();
1355 ret = str2prefix (argv[0], argv_p);
1356 if (!ret)
1357 {
1358 prefix_free(argv_p);
1359 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1360 return CMD_WARNING;
1361 }
1362
1363 if (!bgp_debug_zebra_prefixes)
1364 bgp_debug_zebra_prefixes = list_new();
1365
1366 if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, argv_p))
1367 {
1368 vty_out (vty, "BGP zebra debugging is already enabled for %s%s", argv[0], VTY_NEWLINE);
1369 return CMD_SUCCESS;
1370 }
1371
1372 bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, argv_p);
1373
1374 if (vty->node == CONFIG_NODE)
1375 DEBUG_ON (zebra, ZEBRA);
1376 else
1377 {
1378 TERM_DEBUG_ON (zebra, ZEBRA);
1379 vty_out (vty, "BGP zebra debugging is on for %s%s", argv[0], VTY_NEWLINE);
1380 }
1381
1382 return CMD_SUCCESS;
1383}
1384
a39275d7
AS
1385DEFUN (no_debug_bgp_zebra,
1386 no_debug_bgp_zebra_cmd,
1387 "no debug bgp zebra",
1388 NO_STR
1389 DEBUG_STR
1390 BGP_STR
1391 "BGP Zebra messages\n")
1392{
16286195
DS
1393 bgp_debug_list_free(bgp_debug_zebra_prefixes);
1394
a39275d7
AS
1395 if (vty->node == CONFIG_NODE)
1396 DEBUG_OFF (zebra, ZEBRA);
1397 else
1398 {
1399 TERM_DEBUG_OFF (zebra, ZEBRA);
1400 vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
1401 }
1402 return CMD_SUCCESS;
1403}
1404
16286195
DS
1405DEFUN (no_debug_bgp_zebra_prefix,
1406 no_debug_bgp_zebra_prefix_cmd,
1407 "no debug bgp zebra prefix (A.B.C.D/M|X:X::X:X/M)",
1408 NO_STR
1409 DEBUG_STR
a39275d7 1410 BGP_STR
16286195
DS
1411 "BGP Zebra messages\n"
1412 "Specify a prefix to debug\n"
1413 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1414 "IPv6 prefix <network>/<length>\n")
1415
1416{
1417 struct prefix *argv_p;
1418 int found_prefix = 0;
1419 int ret;
1420
1421 argv_p = prefix_new();
1422 ret = str2prefix (argv[0], argv_p);
1423 if (!ret)
1424 {
1425 prefix_free(argv_p);
1426 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1427 return CMD_WARNING;
1428 }
1429
1430 if (bgp_debug_zebra_prefixes && !list_isempty(bgp_debug_zebra_prefixes))
1431 {
1432 found_prefix = bgp_debug_list_remove_entry(bgp_debug_neighbor_events_peers, NULL, argv_p);
1433
1434 if (list_isempty(bgp_debug_zebra_prefixes))
1435 {
1436 if (vty->node == CONFIG_NODE)
1437 DEBUG_OFF (zebra, ZEBRA);
1438 else
1439 {
1440 TERM_DEBUG_OFF (zebra, ZEBRA);
1441 vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
1442 }
1443 }
1444 }
a39275d7 1445
16286195
DS
1446 if (found_prefix)
1447 vty_out (vty, "BGP zebra debugging is off for %s%s", argv[0], VTY_NEWLINE);
1448 else
1449 vty_out (vty, "BGP zebra debugging was not enabled for %s%s", argv[0], VTY_NEWLINE);
1450
1451 return CMD_SUCCESS;
1452}
1453
3f9c7369
DS
1454/* debug bgp update-groups */
1455DEFUN (debug_bgp_update_groups,
1456 debug_bgp_update_groups_cmd,
1457 "debug bgp update-groups",
1458 DEBUG_STR
1459 BGP_STR
1460 "BGP update-groups\n")
1461{
1462 if (vty->node == CONFIG_NODE)
1463 DEBUG_ON (update_groups, UPDATE_GROUPS);
1464 else
1465 {
1466 TERM_DEBUG_ON (update_groups, UPDATE_GROUPS);
1467 vty_out (vty, "BGP update-groups debugging is on%s", VTY_NEWLINE);
1468 }
1469 return CMD_SUCCESS;
1470}
1471
1472DEFUN (no_debug_bgp_update_groups,
1473 no_debug_bgp_update_groups_cmd,
1474 "no debug bgp update-groups",
1475 NO_STR
1476 DEBUG_STR
1477 BGP_STR
1478 "BGP update-groups\n")
1479{
1480 if (vty->node == CONFIG_NODE)
1481 DEBUG_OFF (update_groups, UPDATE_GROUPS);
1482 else
1483 {
1484 TERM_DEBUG_OFF (update_groups, UPDATE_GROUPS);
1485 vty_out (vty, "BGP update-groups debugging is off%s", VTY_NEWLINE);
1486 }
1487 return CMD_SUCCESS;
1488}
1489
16286195
DS
1490DEFUN (no_debug_bgp,
1491 no_debug_bgp_cmd,
1492 "no debug bgp",
718e3744 1493 NO_STR
1494 DEBUG_STR
718e3744 1495 BGP_STR)
1496{
16286195
DS
1497 bgp_debug_list_free(bgp_debug_neighbor_events_peers);
1498 bgp_debug_list_free(bgp_debug_keepalive_peers);
1499 bgp_debug_list_free(bgp_debug_update_in_peers);
1500 bgp_debug_list_free(bgp_debug_update_out_peers);
1501 bgp_debug_list_free(bgp_debug_update_prefixes);
9fbdd100 1502 bgp_debug_list_free(bgp_debug_bestpath_prefixes);
16286195
DS
1503 bgp_debug_list_free(bgp_debug_zebra_prefixes);
1504
3f9c7369
DS
1505 bgp_debug_clear_updgrp_update_dbg(vty->index);
1506
718e3744 1507 TERM_DEBUG_OFF (keepalive, KEEPALIVE);
1508 TERM_DEBUG_OFF (update, UPDATE_IN);
1509 TERM_DEBUG_OFF (update, UPDATE_OUT);
16286195 1510 TERM_DEBUG_OFF (update, UPDATE_PREFIX);
9fbdd100 1511 TERM_DEBUG_OFF (bestpath, BESTPATH);
0b2aa3a0
PJ
1512 TERM_DEBUG_OFF (as4, AS4);
1513 TERM_DEBUG_OFF (as4, AS4_SEGMENT);
16286195 1514 TERM_DEBUG_OFF (neighbor_events, NEIGHBOR_EVENTS);
a39275d7 1515 TERM_DEBUG_OFF (zebra, ZEBRA);
718e3744 1516 vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
1517
1518 return CMD_SUCCESS;
1519}
1520
718e3744 1521DEFUN (show_debugging_bgp,
1522 show_debugging_bgp_cmd,
1523 "show debugging bgp",
1524 SHOW_STR
1525 DEBUG_STR
1526 BGP_STR)
1527{
1528 vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
1529
0b2aa3a0
PJ
1530 if (BGP_DEBUG (as4, AS4))
1531 vty_out (vty, " BGP as4 debugging is on%s", VTY_NEWLINE);
16286195 1532
0b2aa3a0
PJ
1533 if (BGP_DEBUG (as4, AS4_SEGMENT))
1534 vty_out (vty, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE);
16286195
DS
1535
1536 if (BGP_DEBUG (neighbor_events, NEIGHBOR_EVENTS))
1537 bgp_debug_list_print (vty, " BGP neighbor-events debugging is on",
1538 bgp_debug_neighbor_events_peers);
1539
1540 if (BGP_DEBUG (keepalive, KEEPALIVE))
1541 bgp_debug_list_print (vty, " BGP keepalives debugging is on",
1542 bgp_debug_keepalive_peers);
1543
fb018d25
DS
1544 if (BGP_DEBUG (nht, NHT))
1545 vty_out (vty, " BGP next-hop tracking debugging is on%s", VTY_NEWLINE);
16286195
DS
1546
1547 if (BGP_DEBUG (update, UPDATE_PREFIX))
1548 bgp_debug_list_print (vty, " BGP updates debugging is on for",
1549 bgp_debug_update_prefixes);
1550
1551 if (BGP_DEBUG (update, UPDATE_IN))
1552 bgp_debug_list_print (vty, " BGP updates debugging is on (inbound)",
1553 bgp_debug_update_in_peers);
1554
1555 if (BGP_DEBUG (update, UPDATE_OUT))
1556 bgp_debug_list_print (vty, " BGP updates debugging is on (outbound)",
1557 bgp_debug_update_out_peers);
1558
9fbdd100
DS
1559 if (BGP_DEBUG (bestpath, BESTPATH))
1560 bgp_debug_list_print (vty, " BGP bestpath debugging is on for",
1561 bgp_debug_bestpath_prefixes);
1562
16286195
DS
1563 if (BGP_DEBUG (zebra, ZEBRA))
1564 bgp_debug_list_print (vty, " BGP zebra debugging is on",
1565 bgp_debug_zebra_prefixes);
1566
3f9c7369
DS
1567 if (BGP_DEBUG (update_groups, UPDATE_GROUPS))
1568 vty_out (vty, " BGP update-groups debugging is on%s", VTY_NEWLINE);
1569
718e3744 1570 vty_out (vty, "%s", VTY_NEWLINE);
1571 return CMD_SUCCESS;
1572}
1573
94f2b392 1574static int
718e3744 1575bgp_config_write_debug (struct vty *vty)
1576{
1577 int write = 0;
1578
0b2aa3a0
PJ
1579 if (CONF_BGP_DEBUG (as4, AS4))
1580 {
1581 vty_out (vty, "debug bgp as4%s", VTY_NEWLINE);
1582 write++;
1583 }
1584
1585 if (CONF_BGP_DEBUG (as4, AS4_SEGMENT))
1586 {
1587 vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE);
1588 write++;
1589 }
1590
718e3744 1591 if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
1592 {
1593 vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
1594 write++;
1595 }
1596
1597 if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
1598 {
1599 vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
1600 write++;
1601 }
1602 else if (CONF_BGP_DEBUG (update, UPDATE_IN))
1603 {
1604 vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
1605 write++;
1606 }
1607 else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
1608 {
1609 vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
1610 write++;
1611 }
1612
9fbdd100
DS
1613 if (CONF_BGP_DEBUG (bestpath, BESTPATH))
1614 {
1615 vty_out (vty, "debug bgp bestpath%s", VTY_NEWLINE);
1616 write++;
1617 }
1618
16286195 1619 if (CONF_BGP_DEBUG (neighbor_events, NEIGHBOR_EVENTS))
718e3744 1620 {
16286195 1621 vty_out (vty, "debug bgp neighbor-events%s", VTY_NEWLINE);
718e3744 1622 write++;
1623 }
1624
a39275d7
AS
1625 if (CONF_BGP_DEBUG (zebra, ZEBRA))
1626 {
1627 vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
1628 write++;
1629 }
1630
fb018d25
DS
1631 if (CONF_BGP_DEBUG (nht, NHT))
1632 {
1633 vty_out (vty, "debug bgp nht%s", VTY_NEWLINE);
1634 write++;
1635 }
1636
3f9c7369
DS
1637 if (CONF_BGP_DEBUG (update_groups, UPDATE_GROUPS))
1638 {
1639 vty_out (vty, "debug bgp update-groups%s", VTY_NEWLINE);
1640 write++;
1641 }
1642
718e3744 1643 return write;
1644}
1645
7fc626de 1646static struct cmd_node debug_node =
718e3744 1647{
1648 DEBUG_NODE,
1649 "",
1650 1
1651};
1652
1653void
94f2b392 1654bgp_debug_init (void)
718e3744 1655{
1656 install_node (&debug_node, bgp_config_write_debug);
1657
1658 install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
1659
0b2aa3a0
PJ
1660 install_element (ENABLE_NODE, &debug_bgp_as4_cmd);
1661 install_element (CONFIG_NODE, &debug_bgp_as4_cmd);
1662 install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd);
1663 install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd);
1664
16286195
DS
1665 install_element (ENABLE_NODE, &debug_bgp_neighbor_events_cmd);
1666 install_element (CONFIG_NODE, &debug_bgp_neighbor_events_cmd);
fb018d25
DS
1667 install_element (ENABLE_NODE, &debug_bgp_nht_cmd);
1668 install_element (CONFIG_NODE, &debug_bgp_nht_cmd);
718e3744 1669 install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
1670 install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
1671 install_element (ENABLE_NODE, &debug_bgp_update_cmd);
1672 install_element (CONFIG_NODE, &debug_bgp_update_cmd);
1673 install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
1674 install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
a39275d7
AS
1675 install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
1676 install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
3f9c7369
DS
1677 install_element (ENABLE_NODE, &debug_bgp_update_groups_cmd);
1678 install_element (CONFIG_NODE, &debug_bgp_update_groups_cmd);
9fbdd100
DS
1679 install_element (ENABLE_NODE, &debug_bgp_bestpath_prefix_cmd);
1680 install_element (CONFIG_NODE, &debug_bgp_bestpath_prefix_cmd);
718e3744 1681
16286195
DS
1682 /* deb bgp updates [in|out] A.B.C.D */
1683 install_element (ENABLE_NODE, &debug_bgp_update_direct_peer_cmd);
1684 install_element (CONFIG_NODE, &debug_bgp_update_direct_peer_cmd);
1685 install_element (ENABLE_NODE, &no_debug_bgp_update_direct_peer_cmd);
1686 install_element (CONFIG_NODE, &no_debug_bgp_update_direct_peer_cmd);
1687
1688 /* deb bgp updates prefix A.B.C.D/M */
1689 install_element (ENABLE_NODE, &debug_bgp_update_prefix_cmd);
1690 install_element (CONFIG_NODE, &debug_bgp_update_prefix_cmd);
1691 install_element (ENABLE_NODE, &no_debug_bgp_update_prefix_cmd);
1692 install_element (CONFIG_NODE, &no_debug_bgp_update_prefix_cmd);
1693
1694 /* deb bgp zebra prefix A.B.C.D/M */
1695 install_element (ENABLE_NODE, &debug_bgp_zebra_prefix_cmd);
1696 install_element (CONFIG_NODE, &debug_bgp_zebra_prefix_cmd);
1697 install_element (ENABLE_NODE, &no_debug_bgp_zebra_prefix_cmd);
1698 install_element (CONFIG_NODE, &no_debug_bgp_zebra_prefix_cmd);
1699
0b2aa3a0 1700 install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd);
0b2aa3a0
PJ
1701 install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd);
1702 install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
0b2aa3a0
PJ
1703 install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
1704
16286195
DS
1705 /* deb bgp neighbor-events A.B.C.D */
1706 install_element (ENABLE_NODE, &debug_bgp_neighbor_events_peer_cmd);
1707 install_element (CONFIG_NODE, &debug_bgp_neighbor_events_peer_cmd);
1708 install_element (ENABLE_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
1709 install_element (CONFIG_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
1710
1711 /* deb bgp keepalive A.B.C.D */
1712 install_element (ENABLE_NODE, &debug_bgp_keepalive_peer_cmd);
1713 install_element (CONFIG_NODE, &debug_bgp_keepalive_peer_cmd);
1714 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_peer_cmd);
1715 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_peer_cmd);
1716
1717 install_element (ENABLE_NODE, &no_debug_bgp_neighbor_events_cmd);
1718 install_element (CONFIG_NODE, &no_debug_bgp_neighbor_events_cmd);
fb018d25 1719 install_element (ENABLE_NODE, &no_debug_bgp_nht_cmd);
fb018d25 1720 install_element (CONFIG_NODE, &no_debug_bgp_nht_cmd);
718e3744 1721 install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
718e3744 1722 install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
1723 install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
718e3744 1724 install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
a39275d7 1725 install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
a39275d7 1726 install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
3f9c7369
DS
1727 install_element (ENABLE_NODE, &no_debug_bgp_update_groups_cmd);
1728 install_element (CONFIG_NODE, &no_debug_bgp_update_groups_cmd);
16286195 1729 install_element (ENABLE_NODE, &no_debug_bgp_cmd);
9fbdd100
DS
1730 install_element (ENABLE_NODE, &no_debug_bgp_bestpath_cmd);
1731 install_element (CONFIG_NODE, &no_debug_bgp_bestpath_cmd);
1732 install_element (ENABLE_NODE, &no_debug_bgp_bestpath_prefix_cmd);
1733 install_element (CONFIG_NODE, &no_debug_bgp_bestpath_prefix_cmd);
16286195
DS
1734}
1735
1736/* Return true if this prefix is on the per_prefix_list of prefixes to debug
1737 * for BGP_DEBUG_TYPE
1738 */
1739static int
1740bgp_debug_per_prefix (struct prefix *p, unsigned long term_bgp_debug_type,
1741 unsigned int BGP_DEBUG_TYPE, struct list *per_prefix_list)
1742{
1743 struct bgp_debug_filter *filter;
1744 struct listnode *node, *nnode;
1745
1746 if (term_bgp_debug_type & BGP_DEBUG_TYPE)
1747 {
1748 /* We are debugging all prefixes so return true */
1749 if (!per_prefix_list || list_isempty(per_prefix_list))
1750 return 1;
1751
1752 else
1753 {
1754 if (!p)
1755 return 0;
1756
1757 for (ALL_LIST_ELEMENTS (per_prefix_list, node, nnode, filter))
1758 if (filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p))
1759 return 1;
1760
1761 return 0;
1762 }
1763 }
1764
1765 return 0;
1766}
1767
1768/* Return true if this peer is on the per_peer_list of peers to debug
1769 * for BGP_DEBUG_TYPE
1770 */
1771static int
1772bgp_debug_per_peer(struct peer *peer, unsigned long term_bgp_debug_type,
1773 unsigned int BGP_DEBUG_TYPE, struct list *per_peer_list)
1774{
1775 struct bgp_debug_filter *filter;
1776 struct listnode *node, *nnode;
1777
1778 if (term_bgp_debug_type & BGP_DEBUG_TYPE)
1779 {
1780 /* We are debugging all peers so return true */
1781 if (!per_peer_list || list_isempty(per_peer_list))
1782 return 1;
1783
1784 else
1785 {
1786 if (!peer)
1787 return 0;
1788
1789 for (ALL_LIST_ELEMENTS (per_peer_list, node, nnode, filter))
1790 if (filter->peer == peer)
1791 return 1;
1792
1793 return 0;
1794 }
1795 }
1796
1797 return 0;
1798}
1799
1800int
1801bgp_debug_neighbor_events (struct peer *peer)
1802{
1803 return bgp_debug_per_peer (peer,
1804 term_bgp_debug_neighbor_events,
1805 BGP_DEBUG_NEIGHBOR_EVENTS,
1806 bgp_debug_neighbor_events_peers);
1807}
1808
1809int
1810bgp_debug_keepalive (struct peer *peer)
1811{
1812 return bgp_debug_per_peer (peer,
1813 term_bgp_debug_keepalive,
1814 BGP_DEBUG_KEEPALIVE,
1815 bgp_debug_keepalive_peers);
1816}
1817
1818int
3f9c7369
DS
1819bgp_debug_update (struct peer *peer, struct prefix *p,
1820 struct update_group *updgrp, unsigned int inbound)
16286195
DS
1821{
1822 if (inbound)
1823 {
1824 if (bgp_debug_per_peer (peer, term_bgp_debug_update, BGP_DEBUG_UPDATE_IN,
1825 bgp_debug_update_in_peers))
1826 return 1;
1827 }
1828
1829 /* outbound */
1830 else
1831 {
1832 if (bgp_debug_per_peer (peer, term_bgp_debug_update,
1833 BGP_DEBUG_UPDATE_OUT,
1834 bgp_debug_update_out_peers))
1835 return 1;
3f9c7369
DS
1836
1837 /* Check if update debugging implicitly enabled for the group. */
1838 if (updgrp && UPDGRP_DBG_ON(updgrp))
1839 return 1;
16286195
DS
1840 }
1841
1842
1843 if (BGP_DEBUG (update, UPDATE_PREFIX))
1844 {
1845 if (bgp_debug_per_prefix (p, term_bgp_debug_update,
1846 BGP_DEBUG_UPDATE_PREFIX,
1847 bgp_debug_update_prefixes))
1848 return 1;
1849 }
1850
1851 return 0;
1852}
1853
9fbdd100
DS
1854int
1855bgp_debug_bestpath (struct prefix *p)
1856{
1857 if (BGP_DEBUG (bestpath, BESTPATH))
1858 {
1859 if (bgp_debug_per_prefix (p, term_bgp_debug_bestpath,
1860 BGP_DEBUG_BESTPATH,
1861 bgp_debug_bestpath_prefixes))
1862 return 1;
1863 }
1864
1865 return 0;
1866}
1867
16286195
DS
1868int
1869bgp_debug_zebra (struct prefix *p)
1870{
1871 if (BGP_DEBUG (zebra, ZEBRA))
1872 {
1873 if (bgp_debug_per_prefix (p, term_bgp_debug_zebra, BGP_DEBUG_ZEBRA,
1874 bgp_debug_zebra_prefixes))
1875 return 1;
1876 }
1877
1878 return 0;
718e3744 1879}