From 736d9f20bfe3d96f6a484356c1e99ccff1907b62 Mon Sep 17 00:00:00 2001 From: Sara Dickinson Date: Sun, 13 Dec 2015 17:44:31 +0000 Subject: [PATCH 1/2] Enable TCP FastOpen by default and add support for OSX implementation of TFO. --- configure.ac | 46 ++++++++++++++++++++++++---------------------- src/stub.c | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/configure.ac b/configure.ac index 4a6ff889..1159f2bc 100644 --- a/configure.ac +++ b/configure.ac @@ -160,29 +160,31 @@ case "$enable_debug_sec" in ;; esac -AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--enable-tcp-fastopen], [Enable TCP Fast Open])) -case "$enable_tcp_fastopen" in - yes) - AC_CHECK_DECL([MSG_FASTOPEN], [], [AC_MSG_ERROR([TCP Fast Open is not available: please rerun without --enable-tcp-fastopen])], [AC_INCLUDES_DEFAULT -#include - ]) - AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.]) - ;; - no|*) - ;; -esac - -# Not yet enabled by default as crash found when TCP fails. -# AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)), -# enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes) -# if test "x$enable_tcp_fastopen" = xno; then -# AC_MSG_WARN([TCP Fast Open is disabled]) -# else -# AC_CHECK_DECL([MSG_FASTOPEN], [AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])], -# [AC_MSG_WARN([TCP Fast Open is not available.])], [AC_INCLUDES_DEFAULT +# AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--enable-tcp-fastopen], [Enable TCP Fast Open])) +# case "$enable_tcp_fastopen" in +# yes) +# AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [], [AC_MSG_ERROR([TCP Fast Open is not available: please rerun without --enable-tcp-fastopen])], [AC_INCLUDES_DEFAULT # #include -# ]) -# fi +# ]) +# AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.]) +# ;; +# no|*) +# ;; +# esac + +AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)), + enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes) +if test "x$enable_tcp_fastopen" = xno; then + AC_MSG_WARN([TCP Fast Open is disabled]) +else + my_have_linux_tfo=1 + AC_CHECK_DECL([MSG_FASTOPEN], [AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])], + my_have_linux_tfo=0, [#include ]) + if test my_have_linux_tfo=0; then + AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_DEFINE_UNQUOTED([USE_OSX_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])], + [AC_MSG_WARN([TCP Fast Open is not available, continuing without])], [#include ]) + fi +fi AC_ARG_ENABLE(native-stub-dnssec, AC_HELP_STRING([--disable-native-stub-dnssec], [Disable native stub DNSSEC support])) case "$enable_native_stub_dnssec" in diff --git a/src/stub.c b/src/stub.c index b9da8d17..ec13de7e 100644 --- a/src/stub.c +++ b/src/stub.c @@ -357,6 +357,22 @@ tcp_connect(getdns_upstream *upstream, getdns_transport_list_t transport) if (transport == GETDNS_TRANSPORT_TCP || transport == GETDNS_TRANSPORT_STARTTLS) return fd; +#elif USE_OSX_TCP_FASTOPEN + sa_endpoints_t endpoints; + endpoints.sae_srcif = 0; + endpoints.sae_srcaddr = NULL; + endpoints.sae_srcaddrlen = 0; + endpoints.sae_dstaddr = (struct sockaddr *)&upstream->addr; + endpoints.sae_dstaddrlen = upstream->addr_len; + if (connectx(fd, &endpoints, SAE_ASSOCID_ANY, + CONNECT_DATA_IDEMPOTENT | CONNECT_RESUME_ON_READ_WRITE, + NULL, 0, NULL, NULL) == -1) { + if (errno != EINPROGRESS) { + close(fd); + return -1; + } + } + return fd; #endif if (connect(fd, (struct sockaddr *)&upstream->addr, upstream->addr_len) == -1) { From 438870785af586b2fa91ed10efd2030d128faf46 Mon Sep 17 00:00:00 2001 From: Sara Dickinson Date: Tue, 15 Dec 2015 18:11:45 +0000 Subject: [PATCH 2/2] Improve config check for TFO --- configure.ac | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index 1159f2bc..46dac344 100644 --- a/configure.ac +++ b/configure.ac @@ -160,30 +160,21 @@ case "$enable_debug_sec" in ;; esac -# AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--enable-tcp-fastopen], [Enable TCP Fast Open])) -# case "$enable_tcp_fastopen" in -# yes) -# AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [], [AC_MSG_ERROR([TCP Fast Open is not available: please rerun without --enable-tcp-fastopen])], [AC_INCLUDES_DEFAULT -# #include -# ]) -# AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.]) -# ;; -# no|*) -# ;; -# esac - AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)), enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes) if test "x$enable_tcp_fastopen" = xno; then AC_MSG_WARN([TCP Fast Open is disabled]) else - my_have_linux_tfo=1 - AC_CHECK_DECL([MSG_FASTOPEN], [AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])], - my_have_linux_tfo=0, [#include ]) - if test my_have_linux_tfo=0; then - AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_DEFINE_UNQUOTED([USE_OSX_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])], - [AC_MSG_WARN([TCP Fast Open is not available, continuing without])], [#include ]) - fi + case `uname` in + Linux) AC_CHECK_DECL([MSG_FASTOPEN], [AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])], + [AC_MSG_WARN([TCP Fast Open is not available, continuing without])], [#include ]) + ;; + Darwin) AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_DEFINE_UNQUOTED([USE_OSX_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])], + [AC_MSG_WARN([TCP Fast Open is not available, continuing without])], [#include ]) + ;; + *) AC_MSG_WARN([TCP Fast Open is not available, continuing without]) + ;; + esac fi AC_ARG_ENABLE(native-stub-dnssec, AC_HELP_STRING([--disable-native-stub-dnssec], [Disable native stub DNSSEC support]))