]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix TCP with Fast Open requested but unsupported 5454/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 23 Jun 2017 08:35:03 +0000 (10:35 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 23 Jun 2017 08:35:03 +0000 (10:35 +0200)
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.

pdns/dnsdist-lua.cc
pdns/dnsdist-tcp.cc

index 8b4b094c1f8a054cd925119e4389d8486f18ba0a..50c0b3537d72b6567756017a54107c378eca6f38 100644 (file)
@@ -437,7 +437,14 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                        }
 
                        if(vars.count("tcpFastOpen")) {
-                         ret->tcpFastOpen=boost::get<bool>(vars["tcpFastOpen"]);
+                         bool fastOpen = boost::get<bool>(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<string>(vars["address"]));
+#endif
+                         }
                        }
 
                        if(vars.count("name")) {
index 95e3ac204511a13169f33c3d2062e474c5ecfc79..02fafc634ba0fa8f34900fbfa00a41601ec3c0cb 100644 (file)
@@ -61,9 +61,13 @@ static int setupTCPDownstream(shared_ptr<DownstreamState> 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) {