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