diff options
author | Matt Johnston <matt@ucc.asn.au> | 2015-02-15 22:34:05 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2015-02-15 22:34:05 +0800 |
commit | 91494d868c4d28b0bbc41d8de0c618b1bd9ba1ba (patch) | |
tree | 80f90851d493f362b4f2c3e9fc66df13fe6d787f | |
parent | 21f2af66311b1488fb1539c28eb8cd32fd74cd65 (diff) | |
download | dropbear-91494d868c4d28b0bbc41d8de0c618b1bd9ba1ba.tar.gz |
tcp fastopen for the server
-rw-r--r-- | dbutil.c | 10 | ||||
-rw-r--r-- | dbutil.h | 6 | ||||
-rw-r--r-- | svr-main.c | 17 |
3 files changed, 28 insertions, 5 deletions
@@ -221,6 +221,16 @@ void set_sock_nodelay(int sock) { 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; @@ -75,6 +75,12 @@ void getaddrstring(struct sockaddr_storage* addr, 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, @@ -138,7 +138,6 @@ void main_noinetd() { } for (i = 0; i < listensockcount; i++) { - set_sock_priority(listensocks[i], DROPBEAR_PRIO_LOWDELAY); FD_SET(listensocks[i], &fds); } @@ -403,9 +402,9 @@ static void commonsetup() { } /* 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 @@ static size_t listensockets(int *sock, size_t sockcount, int *maxfd) { 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 @@ static size_t listensockets(int *sock, size_t sockcount, int *maxfd) { 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; } |