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