From: Vipin Kumar Date: Thu, 9 Jan 2014 00:31:22 +0000 (+0000) Subject: bgpd: increase TCP socket buffer size X-Git-Tag: frr-2.0-rc1~1594 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=3374bef0412ac11815779f54321cbc4bf96da909;p=mirror%2Ffrr.git 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 Reviewed-by: Pradosh Mohapatra Reviewed-by: Dinesh Dutt [DL: patch split, this is item 3.] Signed-off-by: David Lamparter --- diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index bcaaba759b..d86db3c8ac 100644 --- a/bgpd/bgp_network.c +++ b/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); diff --git a/bgpd/bgp_network.h b/bgpd/bgp_network.h index 5bf2e5ff17..127684306b 100644 --- a/bgpd/bgp_network.h +++ b/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 *);