[quagga-dev 13569] [PATCH 11/22] Save the last message from a peer that caused us to send a NOTIFICATION

Donald Sharp sharpd at cumulusnetworks.com
Tue Nov 10 01:21:51 GMT 2015


From: dwalton at cumulusnetworks.com

Signed-off-by: Daniel Walton <dwalton at cumulusnetworks.com>
---
 bgpd/bgp_packet.c |   23 +++++++++++++++++++++++
 bgpd/bgp_vty.c    |   31 +++++++++++++++++++++++++++----
 bgpd/bgpd.h       |   12 +++++++-----
 3 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 87c9fc5..8ccbc8a 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -2495,11 +2495,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)
     {
@@ -2636,11 +2640,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 40f97ea..92887e3 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -7760,6 +7760,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;
 
@@ -8036,12 +8038,33 @@ 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 e0d6e97..06e48b4 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
 {
@@ -599,6 +604,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;
@@ -638,11 +645,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)
-- 
1.7.10.4





More information about the Quagga-dev mailing list