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