We use the simpler (Linux only) implementation where you just set the
TCP_FASTOPEN_CONNECT socket option. The alternative method of using
sendmsg + MSG_FASTOPEN requires more complicated userspace changes.
---
generator/states-connect.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/generator/states-connect.c b/generator/states-connect.c
index 07d4e234e..00d771d3a 100644
--- a/generator/states-connect.c
+++ b/generator/states-connect.c
@@ -63,6 +63,23 @@ disable_sigpipe (int sock)
#endif
}
+/* Set TCP fastopen (TFO) on connect if supported, but don't fail. */
+static void
+set_tcp_fastopen (struct nbd_handle *h, int family, int sock)
+{
+#ifdef TCP_FASTOPEN_CONNECT
+ const int flag = 1;
+
+ if (!h->fastopen) return;
+ if (family != AF_INET && family != AF_INET6) return;
+
+ if (setsockopt (sock, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
+ &flag, sizeof flag) == -1)
+ debug (h, "ignoring error trying to request TCP fastopen: %s",
+ strerror (errno));
+#endif /* TCP_FASTOPEN_CONNECT */
+}
+
STATE_MACHINE {
CONNECT.START:
sa_family_t family;
@@ -84,6 +101,7 @@ CONNECT.START:
disable_nagle (fd);
disable_sigpipe (fd);
+ set_tcp_fastopen (h, family, fd);
r = connect (fd, (struct sockaddr *)&h->connaddr, h->connaddrlen);
if (r == 0 || (r == -1 && errno == EINPROGRESS))
@@ -197,6 +215,7 @@ CONNECT_TCP.CONNECT:
disable_nagle (fd);
disable_sigpipe (fd);
+ set_tcp_fastopen (h, h->rp->ai_family, fd);
if (connect (fd, h->rp->ai_addr, h->rp->ai_addrlen) == -1) {
if (errno != EINPROGRESS) {
--
2.46.0