mirror of
https://github.com/clearml/dropbear
synced 2025-02-12 07:25:30 +00:00
separate client/server fastopen options
This commit is contained in:
parent
0e1dee828a
commit
2a431cab03
41
netio.c
41
netio.c
@ -70,7 +70,7 @@ static void connect_try_next(struct dropbear_progress_connection *c) {
|
|||||||
struct addrinfo *r;
|
struct addrinfo *r;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int fastopen = 0;
|
int fastopen = 0;
|
||||||
#ifdef DROPBEAR_TCP_FAST_OPEN
|
#ifdef DROPBEAR_CLIENT_TCP_FAST_OPEN
|
||||||
struct msghdr message;
|
struct msghdr message;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -91,14 +91,13 @@ static void connect_try_next(struct dropbear_progress_connection *c) {
|
|||||||
set_piggyback_ack(c->sock);
|
set_piggyback_ack(c->sock);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DROPBEAR_TCP_FAST_OPEN
|
#ifdef DROPBEAR_CLIENT_TCP_FAST_OPEN
|
||||||
fastopen = (c->writequeue != NULL);
|
fastopen = (c->writequeue != NULL);
|
||||||
|
|
||||||
memset(&message, 0x0, sizeof(message));
|
if (fastopen) {
|
||||||
message.msg_name = r->ai_addr;
|
memset(&message, 0x0, sizeof(message));
|
||||||
message.msg_namelen = r->ai_addrlen;
|
message.msg_name = r->ai_addr;
|
||||||
|
message.msg_namelen = r->ai_addrlen;
|
||||||
if (c->writequeue) {
|
|
||||||
/* 6 is arbitrary, enough to hold initial packets */
|
/* 6 is arbitrary, enough to hold initial packets */
|
||||||
int iovlen = 6; /* Linux msg_iovlen is a size_t */
|
int iovlen = 6; /* Linux msg_iovlen is a size_t */
|
||||||
struct iovec iov[6];
|
struct iovec iov[6];
|
||||||
@ -106,18 +105,22 @@ static void connect_try_next(struct dropbear_progress_connection *c) {
|
|||||||
message.msg_iov = iov;
|
message.msg_iov = iov;
|
||||||
message.msg_iovlen = iovlen;
|
message.msg_iovlen = iovlen;
|
||||||
res = sendmsg(c->sock, &message, MSG_FASTOPEN);
|
res = sendmsg(c->sock, &message, MSG_FASTOPEN);
|
||||||
if (res < 0 && errno != EINPROGRESS) {
|
/* Returns EINPROGRESS if FASTOPEN wasn't available */
|
||||||
m_free(c->errstring);
|
if (res < 0) {
|
||||||
c->errstring = m_strdup(strerror(errno));
|
if (errno != EINPROGRESS) {
|
||||||
/* Not entirely sure which kind of errors are normal - 2.6.32 seems to
|
m_free(c->errstring);
|
||||||
return EPIPE for any (nonblocking?) sendmsg(). just fall back */
|
c->errstring = m_strdup(strerror(errno));
|
||||||
TRACE(("sendmsg tcp_fastopen failed, falling back. %s", strerror(errno)));
|
/* Not entirely sure which kind of errors are normal - 2.6.32 seems to
|
||||||
/* No kernel MSG_FASTOPEN support. Fall back below */
|
return EPIPE for any (nonblocking?) sendmsg(). just fall back */
|
||||||
fastopen = 0;
|
TRACE(("sendmsg tcp_fastopen failed, falling back. %s", strerror(errno)));
|
||||||
/* Set to NULL to avoid trying again */
|
/* No kernel MSG_FASTOPEN support. Fall back below */
|
||||||
c->writequeue = NULL;
|
fastopen = 0;
|
||||||
|
/* Set to NULL to avoid trying again */
|
||||||
|
c->writequeue = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
packet_queue_consume(c->writequeue, res);
|
||||||
}
|
}
|
||||||
packet_queue_consume(c->writequeue, res);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -310,7 +313,7 @@ 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
|
#ifdef DROPBEAR_SERVER_TCP_FAST_OPEN
|
||||||
void set_listen_fast_open(int sock) {
|
void set_listen_fast_open(int sock) {
|
||||||
int qlen = MAX(MAX_UNAUTH_PER_IP, 5);
|
int qlen = MAX(MAX_UNAUTH_PER_IP, 5);
|
||||||
if (setsockopt(sock, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) != 0) {
|
if (setsockopt(sock, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) != 0) {
|
||||||
|
2
netio.h
2
netio.h
@ -48,7 +48,7 @@ void connect_set_writequeue(struct dropbear_progress_connection *c, struct Queue
|
|||||||
void packet_queue_to_iovec(struct Queue *queue, struct iovec *iov, unsigned int *iov_count);
|
void packet_queue_to_iovec(struct Queue *queue, struct iovec *iov, unsigned int *iov_count);
|
||||||
void packet_queue_consume(struct Queue *queue, ssize_t written);
|
void packet_queue_consume(struct Queue *queue, ssize_t written);
|
||||||
|
|
||||||
#ifdef DROPBEAR_TCP_FAST_OPEN
|
#ifdef DROPBEAR_SERVER_TCP_FAST_OPEN
|
||||||
/* Try for any Linux builds, will fall back if the kernel doesn't support it */
|
/* Try for any Linux builds, will fall back if the kernel doesn't support it */
|
||||||
void set_listen_fast_open(int sock);
|
void set_listen_fast_open(int sock);
|
||||||
/* Define values which may be supported by the kernel even if the libc is too old */
|
/* Define values which may be supported by the kernel even if the libc is too old */
|
||||||
|
@ -429,7 +429,7 @@ static size_t listensockets(int *socks, size_t sockcount, int *maxfd) {
|
|||||||
for (n = 0; n < (unsigned int)nsock; n++) {
|
for (n = 0; n < (unsigned int)nsock; n++) {
|
||||||
int sock = socks[sockpos + n];
|
int sock = socks[sockpos + n];
|
||||||
set_sock_priority(sock, DROPBEAR_PRIO_LOWDELAY);
|
set_sock_priority(sock, DROPBEAR_PRIO_LOWDELAY);
|
||||||
#ifdef DROPBEAR_TCP_FAST_OPEN
|
#ifdef DROPBEAR_SERVER_TCP_FAST_OPEN
|
||||||
set_listen_fast_open(sock);
|
set_listen_fast_open(sock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -262,9 +262,12 @@
|
|||||||
/* Use this string since some implementations might special-case it */
|
/* Use this string since some implementations might special-case it */
|
||||||
#define DROPBEAR_KEEPALIVE_STRING "keepalive@openssh.com"
|
#define DROPBEAR_KEEPALIVE_STRING "keepalive@openssh.com"
|
||||||
|
|
||||||
/* Linux will attempt TCP fast open, falling back if not supported by the kernel */
|
/* Linux will attempt TCP fast open, falling back if not supported by the kernel.
|
||||||
|
* Currently server is enabled but client is disabled by default until there
|
||||||
|
* is further compatibility testing */
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define DROPBEAR_TCP_FAST_OPEN 1
|
#define DROPBEAR_SERVER_TCP_FAST_OPEN
|
||||||
|
/* #define DROPBEAR_CLIENT_TCP_FAST_OPEN */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* no include guard for this file */
|
/* no include guard for this file */
|
||||||
|
Loading…
Reference in New Issue
Block a user