From d6661008e2ded929a77e729ebbf20aa177d59f67 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 19 May 2015 17:40:39 -0700 Subject: [PATCH] Save the last message from a peer that caused us to send a NOTIFICATION Signed-off-by: Daniel Walton --- bgpd/bgp_packet.c | 23 +++++++++++++++++++++++ bgpd/bgp_vty.c | 29 +++++++++++++++++++++++++---- bgpd/bgpd.h | 12 +++++++----- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index ecb96dce06..6afbe7d76c 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -2529,11 +2529,15 @@ bgp_read (struct thread *thread) struct peer *peer; bgp_size_t size; char notify_data_length[2]; + u_int32_t notify_out; /* Yes first of all get peer pointer. */ peer = THREAD_ARG (thread); peer->t_read = NULL; + /* Note notify_out so we can check later to see if we sent another one */ + notify_out = peer->notify_out; + /* For non-blocking IO check. */ if (peer->status == Connect) { @@ -2669,11 +2673,30 @@ bgp_read (struct thread *thread) break; } + /* If reading this packet caused us to send a NOTIFICATION then store a copy + * of the packet for troubleshooting purposes + */ + if (notify_out < peer->notify_out) + { + memcpy(peer->last_reset_cause, peer->ibuf->data, peer->packet_size); + peer->last_reset_cause_size = peer->packet_size; + notify_out = peer->notify_out; + } + /* Clear input buffer. */ peer->packet_size = 0; if (peer->ibuf) stream_reset (peer->ibuf); done: + /* If reading this packet caused us to send a NOTIFICATION then store a copy + * of the packet for troubleshooting purposes + */ + if (notify_out < peer->notify_out) + { + memcpy(peer->last_reset_cause, peer->ibuf->data, peer->packet_size); + peer->last_reset_cause_size = peer->packet_size; + } + return 0; } diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index bc18e7bd7d..6927ffc7e7 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -7840,6 +7840,8 @@ bgp_show_peer (struct vty *vty, struct peer *p) char timebuf[BGP_UPTIME_LEN]; afi_t afi; safi_t safi; + u_int16_t i; + u_char *msg; bgp = p->bgp; @@ -8116,12 +8118,31 @@ bgp_show_peer (struct vty *vty, struct peer *p) p->established, p->dropped, VTY_NEWLINE); - if (! p->dropped) + if (! p->last_reset) vty_out (vty, " Last reset never%s", VTY_NEWLINE); else - vty_out (vty, " Last reset %s, due to %s%s", - peer_uptime (p->resettime, timebuf, BGP_UPTIME_LEN), - peer_down_str[(int) p->last_reset], VTY_NEWLINE); + { + vty_out (vty, " Last reset %s, due to %s%s", + peer_uptime (p->resettime, timebuf, BGP_UPTIME_LEN), + peer_down_str[(int) p->last_reset], VTY_NEWLINE); + + if (p->last_reset_cause_size) + { + msg = p->last_reset_cause; + vty_out(vty, " Message received that caused BGP to send a NOTIFICATION:%s ", VTY_NEWLINE); + for (i = 1; i <= p->last_reset_cause_size; i++) + { + vty_out(vty, "%02X", *msg++); + + if (i != p->last_reset_cause_size) + if (i % 16 == 0) + vty_out(vty, "%s ", VTY_NEWLINE); + else if (i % 4 == 0) + vty_out(vty, " "); + } + vty_out(vty, "%s", VTY_NEWLINE); + } + } if (CHECK_FLAG (p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) { diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index ef22c45f13..40e3d2abea 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -299,6 +299,11 @@ typedef enum BGP_PEER_CONFED, } bgp_peer_sort_t; +/* BGP message header and packet size. */ +#define BGP_MARKER_SIZE 16 +#define BGP_HEADER_SIZE 19 +#define BGP_MAX_PACKET_SIZE 4096 + /* BGP neighbor structure. */ struct peer { @@ -598,6 +603,8 @@ struct peer #define PEER_DOWN_PASSIVE_CHANGE 20 /* neighbor passive command */ #define PEER_DOWN_MULTIHOP_CHANGE 21 /* neighbor multihop command */ #define PEER_DOWN_NSF_CLOSE_SESSION 22 /* NSF tcp session close */ +unsigned long last_reset_cause_size; +u_char last_reset_cause[BGP_MAX_PACKET_SIZE]; /* The kind of route-map Flags.*/ u_char rmap_type; @@ -637,11 +644,6 @@ struct bgp_nlri /* Default BGP port number. */ #define BGP_PORT_DEFAULT 179 -/* BGP message header and packet size. */ -#define BGP_MARKER_SIZE 16 -#define BGP_HEADER_SIZE 19 -#define BGP_MAX_PACKET_SIZE 4096 - /* BGP minimum message size. */ #define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10) #define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4) -- 2.39.5