tcp fastopen for the server

--HG--
branch : fastopen
This commit is contained in:
Matt Johnston 2015-02-15 22:34:05 +08:00
parent 9abcc7b909
commit 28f61c8b3a
3 changed files with 28 additions and 5 deletions

View File

@ -221,6 +221,16 @@ void set_sock_nodelay(int sock) {
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); 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) { void set_sock_priority(int sock, enum dropbear_prio prio) {
int iptos_val = 0, so_prio_val = 0, rc; int iptos_val = 0, so_prio_val = 0, rc;

View File

@ -75,6 +75,12 @@ void getaddrstring(struct sockaddr_storage* addr,
char **ret_host, char **ret_port, int host_lookup); char **ret_host, char **ret_port, int host_lookup);
void set_sock_nodelay(int sock); void set_sock_nodelay(int sock);
void set_sock_priority(int sock, enum dropbear_prio prio); 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 dropbear_listen(const char* address, const char* port,
int *socks, unsigned int sockcount, char **errstring, int *maxfd); int *socks, unsigned int sockcount, char **errstring, int *maxfd);
int spawn_command(void(*exec_fn)(void *user_data), void *exec_data, int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,

View File

@ -138,7 +138,6 @@ void main_noinetd() {
} }
for (i = 0; i < listensockcount; i++) { for (i = 0; i < listensockcount; i++) {
set_sock_priority(listensocks[i], DROPBEAR_PRIO_LOWDELAY);
FD_SET(listensocks[i], &fds); FD_SET(listensocks[i], &fds);
} }
@ -403,9 +402,9 @@ static void commonsetup() {
} }
/* Set up listening sockets for all the requested ports */ /* Set up listening sockets for all the requested ports */
static size_t listensockets(int *sock, size_t sockcount, int *maxfd) { static size_t listensockets(int *socks, size_t sockcount, int *maxfd) {
unsigned int i; unsigned int i, n;
char* errstring = NULL; char* errstring = NULL;
size_t sockpos = 0; size_t sockpos = 0;
int nsock; 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])) 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, sockcount - sockpos,
&errstring, maxfd); &errstring, maxfd);
@ -427,6 +426,14 @@ static size_t listensockets(int *sock, size_t sockcount, int *maxfd) {
continue; 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; sockpos += nsock;
} }