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