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