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