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