From: Remi Gacogne Date: Fri, 23 Jun 2017 08:35:03 +0000 (+0200) Subject: dnsdist: Fix TCP with Fast Open requested but unsupported X-Git-Tag: rec-4.1.0-alpha1~48^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F5454%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Fix TCP with Fast Open requested but unsupported If `tcpFastOpen` is set on a backend, we used to skip the `connect()` call regardless of `MSG_FASTOPEN` availability. We then tried to call `sendmsg()` (without `MSG_FASTOPEN`) on an unconnected TCP socket, which failed. --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 8b4b094c1f..50c0b3537d 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -437,7 +437,14 @@ vector> setupLua(bool client, const std::string& confi } if(vars.count("tcpFastOpen")) { - ret->tcpFastOpen=boost::get(vars["tcpFastOpen"]); + bool fastOpen = boost::get(vars["tcpFastOpen"]); + if (fastOpen) { +#ifdef MSG_FASTOPEN + ret->tcpFastOpen=true; +#else + warnlog("TCP Fast Open has been configured on downstream server %s but is not supported", boost::get(vars["address"])); +#endif + } } if(vars.count("name")) { diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 95e3ac2045..02fafc634b 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -61,9 +61,13 @@ static int setupTCPDownstream(shared_ptr ds, uint16_t& downstre SBind(sock, ds->sourceAddr); } setNonBlocking(sock); +#ifdef MSG_FASTOPEN if (!ds->tcpFastOpen) { SConnectWithTimeout(sock, ds->remote, ds->tcpConnectTimeout); } +#else + SConnectWithTimeout(sock, ds->remote, ds->tcpConnectTimeout); +#endif /* MSG_FASTOPEN */ return sock; } catch(const std::runtime_error& e) {