]> git.puffer.fish Git - mirror/frr.git/commitdiff
Save the last message from a peer that caused us to send a NOTIFICATION
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 00:40:39 +0000 (17:40 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 00:40:39 +0000 (17:40 -0700)
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
bgpd/bgp_packet.c
bgpd/bgp_vty.c
bgpd/bgpd.h

index ecb96dce066efed6c1c77fe04d91eae132e42fd5..6afbe7d76c989d7a7c54bd71a64ea6661d43970f 100644 (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;
 }
index bc18e7bd7d9ab133f8916edfdda1cae72a33c9ad..6927ffc7e7cf12bfdbe0fef38dc55bf2ead53b9f 100644 (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))
     {
index ef22c45f13d502319e6604e56d554693b110d813..40e3d2abeadbf9a8ce6017d52d4bebb26ebceb8b 100644 (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)