Mercurial > dropbear
comparison netio.c @ 1084:2265d7ebfdeb
separate client/server fastopen options
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 29 May 2015 23:19:11 +0800 |
parents | b3b772646974 |
children | bb3a03feb31f |
comparison
equal
deleted
inserted
replaced
1083:8e0280986710 | 1084:2265d7ebfdeb |
---|---|
68 | 68 |
69 static void connect_try_next(struct dropbear_progress_connection *c) { | 69 static void connect_try_next(struct dropbear_progress_connection *c) { |
70 struct addrinfo *r; | 70 struct addrinfo *r; |
71 int res = 0; | 71 int res = 0; |
72 int fastopen = 0; | 72 int fastopen = 0; |
73 #ifdef DROPBEAR_TCP_FAST_OPEN | 73 #ifdef DROPBEAR_CLIENT_TCP_FAST_OPEN |
74 struct msghdr message; | 74 struct msghdr message; |
75 #endif | 75 #endif |
76 | 76 |
77 for (r = c->res_iter; r; r = r->ai_next) | 77 for (r = c->res_iter; r; r = r->ai_next) |
78 { | 78 { |
89 | 89 |
90 #if defined(__linux__) && defined(TCP_DEFER_ACCEPT) | 90 #if defined(__linux__) && defined(TCP_DEFER_ACCEPT) |
91 set_piggyback_ack(c->sock); | 91 set_piggyback_ack(c->sock); |
92 #endif | 92 #endif |
93 | 93 |
94 #ifdef DROPBEAR_TCP_FAST_OPEN | 94 #ifdef DROPBEAR_CLIENT_TCP_FAST_OPEN |
95 fastopen = (c->writequeue != NULL); | 95 fastopen = (c->writequeue != NULL); |
96 | 96 |
97 memset(&message, 0x0, sizeof(message)); | 97 if (fastopen) { |
98 message.msg_name = r->ai_addr; | 98 memset(&message, 0x0, sizeof(message)); |
99 message.msg_namelen = r->ai_addrlen; | 99 message.msg_name = r->ai_addr; |
100 | 100 message.msg_namelen = r->ai_addrlen; |
101 if (c->writequeue) { | |
102 /* 6 is arbitrary, enough to hold initial packets */ | 101 /* 6 is arbitrary, enough to hold initial packets */ |
103 int iovlen = 6; /* Linux msg_iovlen is a size_t */ | 102 int iovlen = 6; /* Linux msg_iovlen is a size_t */ |
104 struct iovec iov[6]; | 103 struct iovec iov[6]; |
105 packet_queue_to_iovec(c->writequeue, iov, &iovlen); | 104 packet_queue_to_iovec(c->writequeue, iov, &iovlen); |
106 message.msg_iov = iov; | 105 message.msg_iov = iov; |
107 message.msg_iovlen = iovlen; | 106 message.msg_iovlen = iovlen; |
108 res = sendmsg(c->sock, &message, MSG_FASTOPEN); | 107 res = sendmsg(c->sock, &message, MSG_FASTOPEN); |
109 if (res < 0 && errno != EINPROGRESS) { | 108 /* Returns EINPROGRESS if FASTOPEN wasn't available */ |
110 m_free(c->errstring); | 109 if (res < 0) { |
111 c->errstring = m_strdup(strerror(errno)); | 110 if (errno != EINPROGRESS) { |
112 /* Not entirely sure which kind of errors are normal - 2.6.32 seems to | 111 m_free(c->errstring); |
113 return EPIPE for any (nonblocking?) sendmsg(). just fall back */ | 112 c->errstring = m_strdup(strerror(errno)); |
114 TRACE(("sendmsg tcp_fastopen failed, falling back. %s", strerror(errno))); | 113 /* Not entirely sure which kind of errors are normal - 2.6.32 seems to |
115 /* No kernel MSG_FASTOPEN support. Fall back below */ | 114 return EPIPE for any (nonblocking?) sendmsg(). just fall back */ |
116 fastopen = 0; | 115 TRACE(("sendmsg tcp_fastopen failed, falling back. %s", strerror(errno))); |
117 /* Set to NULL to avoid trying again */ | 116 /* No kernel MSG_FASTOPEN support. Fall back below */ |
118 c->writequeue = NULL; | 117 fastopen = 0; |
118 /* Set to NULL to avoid trying again */ | |
119 c->writequeue = NULL; | |
120 } | |
121 } else { | |
122 packet_queue_consume(c->writequeue, res); | |
119 } | 123 } |
120 packet_queue_consume(c->writequeue, res); | |
121 } | 124 } |
122 #endif | 125 #endif |
123 | 126 |
124 /* Normal connect(), used as fallback for TCP fastopen too */ | 127 /* Normal connect(), used as fallback for TCP fastopen too */ |
125 if (!fastopen) { | 128 if (!fastopen) { |
308 /* disable nagle */ | 311 /* disable nagle */ |
309 val = 1; | 312 val = 1; |
310 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); | 313 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); |
311 } | 314 } |
312 | 315 |
313 #ifdef DROPBEAR_TCP_FAST_OPEN | 316 #ifdef DROPBEAR_SERVER_TCP_FAST_OPEN |
314 void set_listen_fast_open(int sock) { | 317 void set_listen_fast_open(int sock) { |
315 int qlen = MAX(MAX_UNAUTH_PER_IP, 5); | 318 int qlen = MAX(MAX_UNAUTH_PER_IP, 5); |
316 if (setsockopt(sock, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) != 0) { | 319 if (setsockopt(sock, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) != 0) { |
317 TRACE(("set_listen_fast_open failed for socket %d: %s", sock, strerror(errno))) | 320 TRACE(("set_listen_fast_open failed for socket %d: %s", sock, strerror(errno))) |
318 } | 321 } |