]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: increase TCP socket buffer size
authorVipin Kumar <vipin@cumulusnetworks.com>
Thu, 9 Jan 2014 00:31:22 +0000 (00:31 +0000)
committerDavid Lamparter <equinox@opensourcerouting.org>
Thu, 15 May 2014 18:34:53 +0000 (20:34 +0200)
BGP does not respond fairly in high scale.  As the number of BGP peers
and prefixes increase, triggers like interface flaps which lead to BGP
peer flaps, cause blockage in bgp_write.

BGP does handle the cases of TCP socket buffer full by queuing a write
event back, there is no functional issue there as such. Still,
increasing the peer socket buffer size should help reduce event queueing
in BGP.

Signed-off-by: Vipin Kumar <vipin@cumulusnetworks.com>
Reviewed-by: Pradosh Mohapatra <pmohapat@cumulusnetworks.com>
Reviewed-by: Dinesh Dutt <ddutt@cumulusnetworks.com>
[DL: patch split, this is item 3.]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgp_network.c
bgpd/bgp_network.h

index bcaaba759b894b5460b3dd560ebd153f6e46e72f..d86db3c8ac48cfd41066f60577e0675a39a81cf2 100644 (file)
@@ -122,7 +122,29 @@ bgp_md5_set (struct peer *peer)
   
   return ret;
 }
-\f
+
+/* Update BGP socket send buffer size */
+static void
+bgp_update_sock_send_buffer_size (int fd)
+{
+  int size = BGP_SOCKET_SNDBUF_SIZE;
+  int optval;
+  socklen_t optlen = sizeof(optval);
+
+  if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optval, &optlen) < 0)
+    {
+      zlog_err("getsockopt of SO_SNDBUF failed %s\n", safe_strerror(errno));
+      return;
+    }
+  if (optval < size)
+    {
+      if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) < 0)
+        {
+          zlog_err("Couldn't increase send buffer: %s\n", safe_strerror(errno));
+        }
+    }
+}
+
 /* Accept bgp connection. */
 static int
 bgp_accept (struct thread *thread)
@@ -153,6 +175,9 @@ bgp_accept (struct thread *thread)
     }
   set_nonblocking (bgp_sock);
 
+  /* Set socket send buffer size */
+  bgp_update_sock_send_buffer_size(bgp_sock);
+
   if (BGP_DEBUG (events, EVENTS))
     zlog_debug ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
   
@@ -308,6 +333,9 @@ bgp_connect (struct peer *peer)
 
   set_nonblocking (peer->fd);
 
+  /* Set socket send buffer size */
+  bgp_update_sock_send_buffer_size(peer->fd);
+
   /* If we can get socket for the peer, adjest TTL and make connection. */
   if (peer->sort == BGP_PEER_EBGP) {
     sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
index 5bf2e5ff178b4f3f87a60137c1dedd8b51028f02..127684306b5fe3dc807b5fed1c43c0e9e50e2c6d 100644 (file)
@@ -21,6 +21,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #ifndef _QUAGGA_BGP_NETWORK_H
 #define _QUAGGA_BGP_NETWORK_H
 
+#define BGP_SOCKET_SNDBUF_SIZE 65536
+
 extern int bgp_socket (unsigned short, const char *);
 extern void bgp_close (void);
 extern int bgp_connect (struct peer *);