summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2015-02-15 22:34:05 +0800
committerMatt Johnston <matt@ucc.asn.au>2015-02-15 22:34:05 +0800
commit91494d868c4d28b0bbc41d8de0c618b1bd9ba1ba (patch)
tree80f90851d493f362b4f2c3e9fc66df13fe6d787f
parent21f2af66311b1488fb1539c28eb8cd32fd74cd65 (diff)
downloaddropbear-91494d868c4d28b0bbc41d8de0c618b1bd9ba1ba.tar.gz
tcp fastopen for the server
-rw-r--r--dbutil.c10
-rw-r--r--dbutil.h6
-rw-r--r--svr-main.c17
3 files changed, 28 insertions, 5 deletions
diff --git a/dbutil.c b/dbutil.c
index ec108bf..03244cb 100644
--- a/dbutil.c
+++ b/dbutil.c
@@ -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;
diff --git a/dbutil.h b/dbutil.h
index 9feec2d..eb630a7 100644
--- a/dbutil.h
+++ b/dbutil.h
@@ -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,
diff --git a/svr-main.c b/svr-main.c
index 284e02d..5234086 100644
--- a/svr-main.c
+++ b/svr-main.c
@@ -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;
}