Mercurial > dropbear
changeset 1023:a00303a7d247 fastopen
tcp fastopen for the server
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 15 Feb 2015 22:34:05 +0800 |
parents | 4121ca987e6a |
children | aac0095dc3b4 |
files | dbutil.c dbutil.h svr-main.c |
diffstat | 3 files changed, 28 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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,
--- 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; }