Save the last message from a peer that caused us to send a NOTIFICATION

Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2015-05-19 17:40:39 -07:00
parent 80e0ad24f9
commit d6661008e2
3 changed files with 55 additions and 9 deletions

View File

@ -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;
}

View File

@ -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))
{

View File

@ -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)