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