Add AsyncSSLSocket option to turn off transparent tls
authorDave Watson <davejwatson@fb.com>
Fri, 13 Jan 2017 18:32:13 +0000 (10:32 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 13 Jan 2017 18:33:00 +0000 (10:33 -0800)
Summary: Folly parts of D4383906.

Reviewed By: plapukhov

Differential Revision: D4387254

fbshipit-source-id: 3c039720c88c91b7292d60a85272dd1978510296

folly/io/async/AsyncSSLSocket.cpp
folly/io/async/AsyncSocket.cpp
folly/io/async/AsyncSocket.h

index cb4b96d2ba9c78b589eef77aceb83e51393f902e..4b9f31738daa91fefde2da90e41cab83dc52a0b9 100644 (file)
@@ -225,6 +225,7 @@ AsyncSSLSocket::AsyncSSLSocket(const shared_ptr<SSLContext>& ctx,
     ctx_(ctx),
     handshakeTimeout_(this, evb),
     connectionTimeout_(this, evb) {
+  noTransparentTls_ = true;
   init();
   if (server) {
     SSL_CTX_set_info_callback(ctx_->getSSLCtx(),
@@ -653,6 +654,7 @@ void AsyncSSLSocket::connect(ConnectCallback* callback,
   assert(!server_);
   assert(state_ == StateEnum::UNINIT);
   assert(sslState_ == STATE_UNINIT);
+  noTransparentTls_ = true;
   AsyncSSLSocketConnector *connector =
     new AsyncSSLSocketConnector(this, callback, timeout);
   AsyncSocket::connect(connector, address, timeout, options, bindAddr);
index bdae6326c5bbaae86ba943f7a6ac0885131d1e4d..6395ef5868695fd83bcf26bd6b566b930079cc14 100644 (file)
@@ -471,6 +471,12 @@ void AsyncSocket::connect(ConnectCallback* callback,
 }
 
 int AsyncSocket::socketConnect(const struct sockaddr* saddr, socklen_t len) {
+#if __linux__
+  if (noTransparentTls_) {
+    // Ignore return value, errors are ok
+    setsockopt(fd_, SOL_SOCKET, SO_NO_TRANSPARENT_TLS, nullptr, 0);
+  }
+#endif
   int rv = fsp::connect(fd_, saddr, len);
   if (rv < 0) {
     auto errnoCopy = errno;
index 8917a6d6f8a9dfb8caa0136eb53e565955cd12e0..e4f01a4d6d03292053287e0f95fe73d0cb8a4c35 100644 (file)
@@ -64,6 +64,10 @@ namespace folly {
  * responding and no further progress can be made sending the data.
  */
 
+#if defined __linux__ && !defined SO_NO_TRANSPARENT_TLS
+#define SO_NO_TRANSPARENT_TLS 200
+#endif
+
 #ifdef _MSC_VER
 // We do a dynamic_cast on this, in
 // AsyncTransportWrapper::getUnderlyingTransport so be safe and
@@ -562,6 +566,10 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
 #endif
   }
 
+  void disableTransparentTls() {
+    noTransparentTls_ = true;
+  }
+
   enum class StateEnum : uint8_t {
     UNINIT,
     CONNECTING,
@@ -949,6 +957,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
   bool tfoEnabled_{false};
   bool tfoAttempted_{false};
   bool tfoFinished_{false};
+  bool noTransparentTls_{false};
 
   std::unique_ptr<EvbChangeCallback> evbChangeCb_{nullptr};
 };