Browse Source

bgpd: increase TCP socket buffer size

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>
Vipin Kumar 7 years ago
parent
commit
3374bef041
2 changed files with 31 additions and 1 deletions
  1. 29 1
      bgpd/bgp_network.c
  2. 2 0
      bgpd/bgp_network.h

+ 29 - 1
bgpd/bgp_network.c

@@ -122,7 +122,29 @@ bgp_md5_set (struct peer *peer)
   
   return ret;
 }
-
+
+/* 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);

+ 2 - 0
bgpd/bgp_network.h

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