# HG changeset patch # User Matt Johnston # Date 1424010845 -28800 # Node ID a00303a7d2473ce6d36fc34b04296d170fbd58c3 # Parent 4121ca987e6a137e1f83a3100a68632f5f353fe6 tcp fastopen for the server diff -r 4121ca987e6a -r a00303a7d247 dbutil.c --- a/dbutil.c Sat Feb 14 09:56:11 2015 +0800 +++ b/dbutil.c Sun Feb 15 22:34:05 2015 +0800 @@ -221,6 +221,16 @@ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); } +#ifdef DROPBEAR_TCP_FAST_OPEN +void set_listen_fast_open(int sock) { + int qlen = MAX(MAX_UNAUTH_PER_IP, 5); + if (setsockopt(sock, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) != 0) { + TRACE(("set_listen_fast_open failed for socket %d: %s", sock, strerror(errno))) + } +} + +#endif + void set_sock_priority(int sock, enum dropbear_prio prio) { int iptos_val = 0, so_prio_val = 0, rc; diff -r 4121ca987e6a -r a00303a7d247 dbutil.h --- a/dbutil.h Sat Feb 14 09:56:11 2015 +0800 +++ b/dbutil.h Sun Feb 15 22:34:05 2015 +0800 @@ -75,6 +75,12 @@ char **ret_host, char **ret_port, int host_lookup); void set_sock_nodelay(int sock); void set_sock_priority(int sock, enum dropbear_prio prio); + +#ifdef __linux__ +#define DROPBEAR_TCP_FAST_OPEN +void set_listen_fast_open(int sock); +#endif + int dropbear_listen(const char* address, const char* port, int *socks, unsigned int sockcount, char **errstring, int *maxfd); int spawn_command(void(*exec_fn)(void *user_data), void *exec_data, diff -r 4121ca987e6a -r a00303a7d247 svr-main.c --- a/svr-main.c Sat Feb 14 09:56:11 2015 +0800 +++ b/svr-main.c Sun Feb 15 22:34:05 2015 +0800 @@ -138,7 +138,6 @@ } for (i = 0; i < listensockcount; i++) { - set_sock_priority(listensocks[i], DROPBEAR_PRIO_LOWDELAY); FD_SET(listensocks[i], &fds); } @@ -403,9 +402,9 @@ } /* Set up listening sockets for all the requested ports */ -static size_t listensockets(int *sock, size_t sockcount, int *maxfd) { - - unsigned int i; +static size_t listensockets(int *socks, size_t sockcount, int *maxfd) { + + unsigned int i, n; char* errstring = NULL; size_t sockpos = 0; int nsock; @@ -416,7 +415,7 @@ TRACE(("listening on '%s:%s'", svr_opts.addresses[i], svr_opts.ports[i])) - nsock = dropbear_listen(svr_opts.addresses[i], svr_opts.ports[i], &sock[sockpos], + nsock = dropbear_listen(svr_opts.addresses[i], svr_opts.ports[i], &socks[sockpos], sockcount - sockpos, &errstring, maxfd); @@ -427,6 +426,14 @@ continue; } + for (n = 0; n < (unsigned int)nsock; n++) { + int sock = socks[sockpos + n]; + set_sock_priority(sock, DROPBEAR_PRIO_LOWDELAY); +#ifdef DROPBEAR_TCP_FAST_OPEN + set_listen_fast_open(sock); +#endif + } + sockpos += nsock; }