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