This is an automated email from the ASF dual-hosted git repository.

maskit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new ede901897e Add QUICSupport as a NetVC service (#10596)
ede901897e is described below

commit ede901897ec45d0c23154c5d8e572785d36eeda6
Author: Masakazu Kitajo <[email protected]>
AuthorDate: Sat Oct 14 00:38:05 2023 +0900

    Add QUICSupport as a NetVC service (#10596)
    
    * Add QUICSupport as a NetVC service
    
    * Add QUICSupport.h,cc
    
    * Fix CMake build
---
 iocore/net/CMakeLists.txt                |  1 +
 iocore/net/I_NetVConnection.h            | 15 ++++++++
 iocore/net/Makefile.am                   |  3 +-
 iocore/net/P_QUICNetVConnection_quiche.h |  7 +++-
 iocore/net/QUICNetVConnection_quiche.cc  |  8 +++++
 iocore/net/QUICSupport.cc                | 59 ++++++++++++++++++++++++++++++++
 iocore/net/QUICSupport.h                 | 47 +++++++++++++++++++++++++
 iocore/net/SNIActionPerformer.cc         |  2 +-
 proxy/http3/Http09App.cc                 |  7 ++--
 proxy/http3/Http09App.h                  |  3 +-
 proxy/http3/Http3App.cc                  |  7 ++--
 proxy/http3/Http3App.h                   |  3 +-
 proxy/http3/Http3Session.cc              | 17 ++++-----
 proxy/http3/Http3SessionAccept.cc        | 16 ++++-----
 proxy/http3/Http3Transaction.cc          | 14 ++++----
 15 files changed, 173 insertions(+), 36 deletions(-)

diff --git a/iocore/net/CMakeLists.txt b/iocore/net/CMakeLists.txt
index 893ac0988d..2f7b3169c3 100644
--- a/iocore/net/CMakeLists.txt
+++ b/iocore/net/CMakeLists.txt
@@ -88,6 +88,7 @@ if(TS_USE_QUIC)
             QUICNetVConnection_quiche.cc
             QUICNextProtocolAccept_quiche.cc
             QUICPacketHandler_quiche.cc
+            QUICSupport.cc
     )
 
     target_link_libraries(inknet
diff --git a/iocore/net/I_NetVConnection.h b/iocore/net/I_NetVConnection.h
index 441545304f..f6ff424970 100644
--- a/iocore/net/I_NetVConnection.h
+++ b/iocore/net/I_NetVConnection.h
@@ -530,6 +530,7 @@ protected:
     TLS_SNI,
     TLS_SessionResumption,
     TLS_Tunnel,
+    QUIC,
     N_SERVICES,
   };
 
@@ -686,3 +687,17 @@ NetVConnection::_set_service(TLSTunnelSupport *instance)
 {
   this->_set_service(NetVConnection::Service::TLS_Tunnel, instance);
 }
+
+class QUICSupport;
+template <>
+inline QUICSupport *
+NetVConnection::get_service() const
+{
+  return static_cast<QUICSupport 
*>(this->_get_service(NetVConnection::Service::QUIC));
+}
+template <>
+inline void
+NetVConnection::_set_service(QUICSupport *instance)
+{
+  this->_set_service(NetVConnection::Service::QUIC, instance);
+}
diff --git a/iocore/net/Makefile.am b/iocore/net/Makefile.am
index ae46160436..cfa445cb63 100644
--- a/iocore/net/Makefile.am
+++ b/iocore/net/Makefile.am
@@ -263,7 +263,8 @@ libinknet_a_SOURCES += \
        QUICNetProcessor_quiche.cc \
        QUICNetVConnection_quiche.cc \
        QUICNextProtocolAccept_quiche.cc \
-       QUICPacketHandler_quiche.cc
+       QUICPacketHandler_quiche.cc \
+       QUICSupport.cc
 endif
 
 if BUILD_TESTS
diff --git a/iocore/net/P_QUICNetVConnection_quiche.h 
b/iocore/net/P_QUICNetVConnection_quiche.h
index d83d789a2f..ff55b31bcc 100644
--- a/iocore/net/P_QUICNetVConnection_quiche.h
+++ b/iocore/net/P_QUICNetVConnection_quiche.h
@@ -42,6 +42,7 @@
 #include "TLSSessionResumptionSupport.h"
 #include "TLSSNISupport.h"
 #include "TLSCertSwitchSupport.h"
+#include "QUICSupport.h"
 #include "tscore/ink_apidefs.h"
 #include "tscore/List.h"
 
@@ -65,7 +66,8 @@ class QUICNetVConnection : public UnixNetVConnection,
                            public TLSSNISupport,
                            public TLSSessionResumptionSupport,
                            public TLSCertSwitchSupport,
-                           public TLSBasicSupport
+                           public TLSBasicSupport,
+                           public QUICSupport
 {
   using super = UnixNetVConnection; ///< Parent type.
 
@@ -137,6 +139,9 @@ public:
   std::vector<QUICFrameType> interests() override;
   QUICConnectionErrorUPtr handle_frame(QUICEncryptionLevel level, const 
QUICFrame &frame) override;
 
+  // QUICSupport
+  QUICConnection *get_quic_connection() override;
+
   // QUICNetVConnection
   int in_closed_queue = 0;
 
diff --git a/iocore/net/QUICNetVConnection_quiche.cc 
b/iocore/net/QUICNetVConnection_quiche.cc
index 879ae47f59..a842a8b8c4 100644
--- a/iocore/net/QUICNetVConnection_quiche.cc
+++ b/iocore/net/QUICNetVConnection_quiche.cc
@@ -527,6 +527,7 @@ QUICNetVConnection::_bindSSLObject()
   TLSSessionResumptionSupport::bind(this->_ssl, this);
   TLSSNISupport::bind(this->_ssl, this);
   TLSCertSwitchSupport::bind(this->_ssl, this);
+  QUICSupport::bind(this->_ssl, this);
 }
 
 void
@@ -537,6 +538,7 @@ QUICNetVConnection::_unbindSSLObject()
   TLSSessionResumptionSupport::unbind(this->_ssl);
   TLSSNISupport::unbind(this->_ssl);
   TLSCertSwitchSupport::unbind(this->_ssl);
+  QUICSupport::unbind(this->_ssl);
 }
 
 void
@@ -734,6 +736,12 @@ QUICNetVConnection::support_sni() const
   return true;
 }
 
+QUICConnection *
+QUICNetVConnection::get_quic_connection()
+{
+  return static_cast<QUICConnection *>(this);
+}
+
 SSL *
 QUICNetVConnection::_get_ssl_object() const
 {
diff --git a/iocore/net/QUICSupport.cc b/iocore/net/QUICSupport.cc
new file mode 100644
index 0000000000..118359f16b
--- /dev/null
+++ b/iocore/net/QUICSupport.cc
@@ -0,0 +1,59 @@
+/** @file
+
+  TLSSBasicSupport.cc provides implementations for
+  QUICSupport methods
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include "QUICSupport.h"
+
+int QUICSupport::_ex_data_index = -1;
+
+void
+QUICSupport::initialize()
+{
+  ink_assert(_ex_data_index == -1);
+  if (_ex_data_index == -1) {
+    _ex_data_index = SSL_get_ex_new_index(0, (void *)"QUICSupport index", 
nullptr, nullptr, nullptr);
+  }
+}
+
+QUICSupport *
+QUICSupport::getInstance(SSL *ssl)
+{
+  return static_cast<QUICSupport *>(SSL_get_ex_data(ssl, _ex_data_index));
+}
+
+void
+QUICSupport::bind(SSL *ssl, QUICSupport *srs)
+{
+  SSL_set_ex_data(ssl, _ex_data_index, srs);
+}
+
+void
+QUICSupport::unbind(SSL *ssl)
+{
+  SSL_set_ex_data(ssl, _ex_data_index, nullptr);
+}
+
+void
+QUICSupport::clear()
+{
+}
diff --git a/iocore/net/QUICSupport.h b/iocore/net/QUICSupport.h
new file mode 100644
index 0000000000..c6c26044f1
--- /dev/null
+++ b/iocore/net/QUICSupport.h
@@ -0,0 +1,47 @@
+/** @file
+
+  QUICSupport
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include <openssl/ssl.h>
+
+#include "quic/QUICConnection.h"
+
+class QUICSupport
+{
+public:
+  virtual ~QUICSupport() = default;
+
+  static void initialize();
+  static QUICSupport *getInstance(SSL *ssl);
+  static void bind(SSL *ssl, QUICSupport *srs);
+  static void unbind(SSL *ssl);
+
+  virtual QUICConnection *get_quic_connection() = 0;
+
+protected:
+  void clear();
+
+private:
+  static int _ex_data_index;
+};
diff --git a/iocore/net/SNIActionPerformer.cc b/iocore/net/SNIActionPerformer.cc
index e2836b04a7..c1f8169fcf 100644
--- a/iocore/net/SNIActionPerformer.cc
+++ b/iocore/net/SNIActionPerformer.cc
@@ -41,7 +41,7 @@ ControlQUIC::SNIAction(SSL &ssl, const Context &ctx) const
   }
 
   // This action is only available for QUIC connections
-  if (dynamic_cast<QUICNetVConnection *>(SSLNetVCAccess(&ssl)) == nullptr) {
+  if (QUICSupport::getInstance(&ssl) == nullptr) {
     return SSL_TLSEXT_ERR_OK;
   }
 
diff --git a/proxy/http3/Http09App.cc b/proxy/http3/Http09App.cc
index b6dc02a9b2..5c1430d774 100644
--- a/proxy/http3/Http09App.cc
+++ b/proxy/http3/Http09App.cc
@@ -27,7 +27,7 @@
 
 #include "P_Net.h"
 #include "P_VConnection.h"
-#include "P_QUICNetVConnection.h"
+#include "QUICStreamManager.h"
 #include "QUICDebugNames.h"
 #include "QUICStreamVCAdapter.h"
 
@@ -37,8 +37,9 @@
 static constexpr char debug_tag[]   = "quic_simple_app";
 static constexpr char debug_tag_v[] = "v_quic_simple_app";
 
-Http09App::Http09App(QUICNetVConnection *client_vc, IpAllow::ACL 
&&session_acl, const HttpSessionAccept::Options &options)
-  : QUICApplication(client_vc)
+Http09App::Http09App(NetVConnection *client_vc, QUICConnection *qc, 
IpAllow::ACL &&session_acl,
+                     const HttpSessionAccept::Options &options)
+  : QUICApplication(qc)
 {
   this->_ssn                 = new Http09Session(client_vc);
   this->_ssn->acl            = std::move(session_acl);
diff --git a/proxy/http3/Http09App.h b/proxy/http3/Http09App.h
index 14ee8e647c..5490f4fdaa 100644
--- a/proxy/http3/Http09App.h
+++ b/proxy/http3/Http09App.h
@@ -30,7 +30,6 @@
 #include "QUICApplication.h"
 #include "QUICStreamVCAdapter.h"
 
-class QUICNetVConnection;
 class Http09Session;
 
 /**
@@ -42,7 +41,7 @@ class Http09Session;
 class Http09App : public QUICApplication
 {
 public:
-  Http09App(QUICNetVConnection *client_vc, IpAllow::ACL &&session_acl, const 
HttpSessionAccept::Options &options);
+  Http09App(NetVConnection *client_vc, QUICConnection *qc, IpAllow::ACL 
&&session_acl, const HttpSessionAccept::Options &options);
   ~Http09App();
 
   void on_new_stream(QUICStream &stream) override;
diff --git a/proxy/http3/Http3App.cc b/proxy/http3/Http3App.cc
index aadd7ed8f5..61ee8dcab8 100644
--- a/proxy/http3/Http3App.cc
+++ b/proxy/http3/Http3App.cc
@@ -29,7 +29,7 @@
 
 #include "P_Net.h"
 #include "P_VConnection.h"
-#include "P_QUICNetVConnection.h"
+#include "QUICStreamManager.h"
 #include "QUICStreamVCAdapter.h"
 
 #include "Http3.h"
@@ -43,8 +43,9 @@
 static constexpr char debug_tag[]   = "http3";
 static constexpr char debug_tag_v[] = "v_http3";
 
-Http3App::Http3App(QUICNetVConnection *client_vc, IpAllow::ACL &&session_acl, 
const HttpSessionAccept::Options &options)
-  : QUICApplication(client_vc)
+Http3App::Http3App(NetVConnection *client_vc, QUICConnection *qc, IpAllow::ACL 
&&session_acl,
+                   const HttpSessionAccept::Options &options)
+  : QUICApplication(qc)
 {
   this->_ssn                 = new Http3Session(client_vc);
   this->_ssn->acl            = std::move(session_acl);
diff --git a/proxy/http3/Http3App.h b/proxy/http3/Http3App.h
index 0374b85eb3..369d9eb9e1 100644
--- a/proxy/http3/Http3App.h
+++ b/proxy/http3/Http3App.h
@@ -38,7 +38,6 @@
 #include "Http3FrameGenerator.h"
 #include "Http3FrameHandler.h"
 
-class QUICNetVConnection;
 class Http3Session;
 
 /**
@@ -48,7 +47,7 @@ class Http3Session;
 class Http3App : public QUICApplication
 {
 public:
-  Http3App(QUICNetVConnection *client_vc, IpAllow::ACL &&session_acl, const 
HttpSessionAccept::Options &options);
+  Http3App(NetVConnection *client_vc, QUICConnection *qc, IpAllow::ACL 
&&session_acl, const HttpSessionAccept::Options &options);
   virtual ~Http3App();
 
   void on_new_stream(QUICStream &stream) override;
diff --git a/proxy/http3/Http3Session.cc b/proxy/http3/Http3Session.cc
index 10c9bdfec8..099e34d1cb 100644
--- a/proxy/http3/Http3Session.cc
+++ b/proxy/http3/Http3Session.cc
@@ -22,7 +22,7 @@
  */
 
 #include "Http3Session.h"
-#include "P_QUICNetVConnection.h"
+#include "QUICSupport.h"
 
 #include "Http3.h"
 
@@ -31,7 +31,7 @@
 //
 HQSession::HQSession(NetVConnection *vc) : ProxySession(vc)
 {
-  auto app_name = static_cast<QUICNetVConnection 
*>(vc)->negotiated_application_name();
+  auto app_name = 
vc->get_service<QUICSupport>()->get_quic_connection()->negotiated_application_name();
   memcpy(this->_protocol_string, app_name.data(), std::min(app_name.length(), 
sizeof(this->_protocol_string)));
   this->_protocol_string[app_name.length()] = '\0';
 }
@@ -69,7 +69,7 @@ HQSession::populate_protocol(std::string_view *result, int 
size) const
 {
   int retval = 0;
   if (size > retval) {
-    result[retval++] = static_cast<QUICNetVConnection 
*>(this->_vc)->negotiated_application_name();
+    result[retval++] = 
this->_vc->get_service<QUICSupport>()->get_quic_connection()->negotiated_application_name();
     if (size > retval) {
       retval += super::populate_protocol(result + retval, size - retval);
     }
@@ -127,7 +127,7 @@ HQSession::reenable(VIO *vio)
 void
 HQSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, 
IOBufferReader *reade)
 {
-  this->con_id = static_cast<QUICConnection 
*>(reinterpret_cast<QUICNetVConnection *>(new_vc))->connection_id();
+  this->con_id = 
new_vc->get_service<QUICSupport>()->get_quic_connection()->connection_id();
   this->_handle_if_ssl(new_vc);
 
   return;
@@ -170,10 +170,11 @@ HQSession::get_transact_count() const
 //
 Http3Session::Http3Session(NetVConnection *vc) : HQSession(vc)
 {
-  this->_local_qpack  = new QPACK(static_cast<QUICNetVConnection *>(vc), 
HTTP3_DEFAULT_MAX_FIELD_SECTION_SIZE,
-                                  HTTP3_DEFAULT_HEADER_TABLE_SIZE, 
HTTP3_DEFAULT_QPACK_BLOCKED_STREAMS);
-  this->_remote_qpack = new QPACK(static_cast<QUICNetVConnection *>(vc), 
HTTP3_DEFAULT_MAX_FIELD_SECTION_SIZE,
-                                  HTTP3_DEFAULT_HEADER_TABLE_SIZE, 
HTTP3_DEFAULT_QPACK_BLOCKED_STREAMS);
+  QUICConnection *qc = vc->get_service<QUICSupport>()->get_quic_connection();
+  this->_local_qpack =
+    new QPACK(qc, HTTP3_DEFAULT_MAX_FIELD_SECTION_SIZE, 
HTTP3_DEFAULT_HEADER_TABLE_SIZE, HTTP3_DEFAULT_QPACK_BLOCKED_STREAMS);
+  this->_remote_qpack =
+    new QPACK(qc, HTTP3_DEFAULT_MAX_FIELD_SECTION_SIZE, 
HTTP3_DEFAULT_HEADER_TABLE_SIZE, HTTP3_DEFAULT_QPACK_BLOCKED_STREAMS);
 }
 
 Http3Session::~Http3Session()
diff --git a/proxy/http3/Http3SessionAccept.cc 
b/proxy/http3/Http3SessionAccept.cc
index be3f2b90d2..efe6b2b1c4 100644
--- a/proxy/http3/Http3SessionAccept.cc
+++ b/proxy/http3/Http3SessionAccept.cc
@@ -22,11 +22,11 @@
  */
 
 #include "Http3SessionAccept.h"
-#include "P_QUICNetVConnection.h"
 
 #include "P_Net.h"
 #include "I_Machine.h"
 #include "IPAllow.h"
+#include "QUICSupport.h"
 
 #include "Http09App.h"
 #include "Http3App.h"
@@ -57,23 +57,23 @@ Http3SessionAccept::accept(NetVConnection *netvc, MIOBuffer 
*iobuf, IOBufferRead
 
   netvc->attributes = this->options.transport_type;
 
-  QUICNetVConnection *qvc = static_cast<QUICNetVConnection *>(netvc);
+  QUICConnection *qc = 
netvc->get_service<QUICSupport>()->get_quic_connection();
 
   if (is_debug_tag_set("http3")) {
     ip_port_text_buffer ipb;
 
-    Debug("http3", "[%s] accepted connection from %s transport type = %d", 
qvc->cids().data(),
+    Debug("http3", "[%s] accepted connection from %s transport type = %d", 
qc->cids().data(),
           ats_ip_nptop(client_ip, ipb, sizeof(ipb)), netvc->attributes);
   }
-  std::string_view alpn = qvc->negotiated_application_name();
+  std::string_view alpn = qc->negotiated_application_name();
 
   if (IP_PROTO_TAG_HTTP_QUIC.compare(alpn) == 0 || 
IP_PROTO_TAG_HTTP_QUIC_D29.compare(alpn) == 0) {
-    Debug("http3", "[%s] start HTTP/0.9 app (ALPN=%.*s)", qvc->cids().data(), 
static_cast<int>(alpn.length()), alpn.data());
-    new Http09App(qvc, std::move(session_acl), this->options);
+    Debug("http3", "[%s] start HTTP/0.9 app (ALPN=%.*s)", qc->cids().data(), 
static_cast<int>(alpn.length()), alpn.data());
+    new Http09App(netvc, qc, std::move(session_acl), this->options);
   } else if (IP_PROTO_TAG_HTTP_3.compare(alpn) == 0 || 
IP_PROTO_TAG_HTTP_3_D29.compare(alpn) == 0) {
-    Debug("http3", "[%s] start HTTP/3 app (ALPN=%.*s)", qvc->cids().data(), 
static_cast<int>(alpn.length()), alpn.data());
+    Debug("http3", "[%s] start HTTP/3 app (ALPN=%.*s)", qc->cids().data(), 
static_cast<int>(alpn.length()), alpn.data());
 
-    Http3App *app = new Http3App(qvc, std::move(session_acl), this->options);
+    Http3App *app = new Http3App(netvc, qc, std::move(session_acl), 
this->options);
     app->start();
   } else {
     ink_abort("Negotiated App Name is unknown");
diff --git a/proxy/http3/Http3Transaction.cc b/proxy/http3/Http3Transaction.cc
index 0fe825c2b5..885f622c29 100644
--- a/proxy/http3/Http3Transaction.cc
+++ b/proxy/http3/Http3Transaction.cc
@@ -22,7 +22,7 @@
  */
 
 #include "Http3Transaction.h"
-#include "P_QUICNetVConnection.h"
+#include "QUICSupport.h"
 
 #include "QUICDebugNames.h"
 
@@ -33,14 +33,14 @@
 #include "Http3DataFramer.h"
 #include "HttpSM.h"
 
-#define Http3TransDebug(fmt, ...)                                              
                                              \
-  Debug("http3_trans", "[%s] [%" PRIx32 "] " fmt,                              
                                              \
-        static_cast<QUICConnection *>(reinterpret_cast<QUICNetVConnection 
*>(this->_proxy_ssn->get_netvc()))->cids().data(), \
+#define NetVC2QUICCon(netvc) 
netvc->get_service<QUICSupport>()->get_quic_connection()
+
+#define Http3TransDebug(fmt, ...)                                              
                                \
+  Debug("http3_trans", "[%s] [%" PRIx32 "] " fmt, 
NetVC2QUICCon(this->_proxy_ssn->get_netvc())->cids().data(), \
         this->get_transaction_id(), ##__VA_ARGS__)
 
-#define Http3TransVDebug(fmt, ...)                                             
                                              \
-  Debug("v_http3_trans", "[%s] [%" PRIx32 "] " fmt,                            
                                              \
-        static_cast<QUICConnection *>(reinterpret_cast<QUICNetVConnection 
*>(this->_proxy_ssn->get_netvc()))->cids().data(), \
+#define Http3TransVDebug(fmt, ...)                                             
                                  \
+  Debug("v_http3_trans", "[%s] [%" PRIx32 "] " fmt, 
NetVC2QUICCon(this->_proxy_ssn->get_netvc())->cids().data(), \
         this->get_transaction_id(), ##__VA_ARGS__)
 
 // static void

Reply via email to