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