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