Copilot commented on code in PR #13908:
URL: https://github.com/apache/trafficserver/pull/13908#discussion_r4548603645
##########
src/iocore/net/QUICNetVConnection.cc:
##########
@@ -574,6 +574,7 @@ QUICNetVConnection::load_buffer_and_write(int64_t /*
towrite ATS_UNUSED */, MIOB
void
QUICNetVConnection::_bindSSLObject()
{
+ NetVCAttach(this->_ssl, this);
TLSBasicSupport::bind(this->_ssl, this);
Review Comment:
The PR description says the fix ‘reaches the connection through
TLSSNISupport::getInstance()’, but the implementation also changes behavior by
attaching the `NetVConnection` to the `SSL` ex_data via `NetVCAttach()` (and
then using `NetVCAccess()` in actions/callbacks). Please update the PR
description to reflect this (or adjust code/description so they match) since
this is an important behavioral/mechanism change for QUIC.
##########
src/iocore/net/SNIActionPerformer.cc:
##########
@@ -182,16 +182,21 @@ TunnelDestination::TunnelDestination(const
std::string_view &dest, SNIRoutingTyp
int
TunnelDestination::SNIAction(SSL &ssl, const Context &ctx) const
{
- auto snis = TLSSNISupport::getInstance(&ssl);
auto tuns = TLSTunnelSupport::getInstance(&ssl);
auto alpns = ALPNSupport::getInstance(&ssl);
- auto ssl_netvc = SSLNetVCAccess(&ssl);
+ auto ssl_netvc = dynamic_cast<SSLNetVConnection *>(NetVCAccess(&ssl));
Review Comment:
`dynamic_cast` in SNI actions runs on the handshake path. If this path is
latency-sensitive, consider avoiding repeated RTTI casts by providing a cheaper
discriminator (e.g., a virtual `asSSLNetVConnection()` on `NetVConnection`, or
storing a dedicated ex_data pointer for `SSLNetVConnection` only where
applicable). This is optional, but could reduce per-handshake overhead.
##########
src/iocore/net/unit_tests/test_SNIActionPerformer.cc:
##########
@@ -0,0 +1,599 @@
+/** @file
+
+ Catch based unit tests for the SNI actions that act on the connection.
+
+ @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.
+ */
+
+#ifndef LIBINKNET_UNIT_TEST_DIR
+#error please set LIBINKNET_UNIT_TEST_DIR
+#endif
+
+#define _STR(s) #s
+#define _XSTR(s) _STR(s)
+
+#include "../SNIActionPerformer.h"
+#include "../P_SSLNetVConnection.h"
+#include "../P_SSLUtils.h"
+#include "../P_UnixNetVConnection.h"
+#include "iocore/net/TLSALPNSupport.h"
+#include "iocore/net/TLSSNISupport.h"
+#include "iocore/net/TLSTunnelSupport.h"
+#include "proxy/IPAllow.h"
+#include "records/RecHttp.h"
+#include "tscore/ink_inet.h"
+
+#if TS_USE_QUIC == 1
+#include "../P_QUICNetVConnection.h"
+#endif
+
+#if TS_USE_QUIC == 1 && TS_HAS_OPENSSL_QUIC
+#include "iocore/net/quic/QUICConfig.h"
+#include "iocore/net/quic/QUICGlobals.h"
+#endif
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <openssl/err.h>
+#include <openssl/ssl.h>
+
+#include <algorithm>
+#include <initializer_list>
+#include <iterator>
+#include <memory>
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#if TS_USE_QUIC == 1
+// The look-alike connections below model QUICNetVConnection, so
QUICNetVConnection must keep this shape.
+static_assert(std::is_convertible_v<QUICNetVConnection *, TLSSNISupport *>);
+static_assert(std::is_convertible_v<QUICNetVConnection *, NetVConnection *>);
+static_assert(!std::is_base_of_v<SSLNetVConnection, QUICNetVConnection>);
+#endif
+
+namespace
+{
+IpEndpoint
+make_endpoint(const char *ip)
+{
+ IpEndpoint ep;
+
+ REQUIRE(ats_ip_pton(ip, &ep) == 0);
+ return ep;
+}
+
+// A connection that attaches itself and binds TLSSNISupport and ALPNSupport
but is not an
+// SSLNetVConnection, the way QUICNetVConnection is.
+class NonSSLNetVConnection : public UnixNetVConnection, public ALPNSupport,
public TLSSNISupport
+{
+public:
+ void
+ set_peer(const char *ip)
+ {
+ IpEndpoint ep = make_endpoint(ip);
+
+ set_remote_addr(&ep.sa);
+ got_remote_addr = true;
+ }
+
+ void
+ bind_to(SSL *ssl)
+ {
+ NetVCAttach(ssl, this);
+ ALPNSupport::bind(ssl, this);
+ TLSSNISupport::bind(ssl, this);
+ }
+
+protected:
+ in_port_t
+ _get_local_port() override
+ {
+ return 443;
+ }
+};
+
+// The same, but also binding TLSTunnelSupport, so nothing but the connection
type stops a tunnel.
+class NonSSLTunnelNetVConnection : public NonSSLNetVConnection, public
TLSTunnelSupport
+{
+public:
+ void
+ bind_to(SSL *ssl)
+ {
+ NonSSLNetVConnection::bind_to(ssl);
+ TLSTunnelSupport::bind(ssl, this);
+ }
+};
+
+class PeerSSLNetVConnection : public SSLNetVConnection
+{
+public:
+ void
+ set_peer(const char *ip)
+ {
+ IpEndpoint ep = make_endpoint(ip);
+
+ set_remote_addr(&ep.sa);
+ got_remote_addr = true;
+ }
+
+ // What _bindSSLObject() binds for the slots the actions read.
+ void
+ bind_to(SSL *ssl)
+ {
+ this->ssl = ssl;
+ NetVCAttach(ssl, this);
+ ALPNSupport::bind(ssl, this);
+ TLSSNISupport::bind(ssl, this);
+ TLSTunnelSupport::bind(ssl, this);
+ }
+
+ // The SSL object belongs to the test.
+ ~PeerSSLNetVConnection() override { this->ssl = nullptr; }
+};
+
+struct SSLDeleter {
+ void
+ operator()(SSL *ssl) const
+ {
+ SSL_free(ssl);
+ }
+};
+
+struct SSLCtxDeleter {
+ void
+ operator()(SSL_CTX *ctx) const
+ {
+ SSL_CTX_free(ctx);
+ }
+};
+
+// Declare the connection before this, so the connection outlives the SSL
object that points at it.
+class SSLObject
+{
+public:
+ SSLObject()
+ {
+ // The support classes reserve their ex_data slots here, and they assert
on a second call.
+ [[maybe_unused]] static bool const initialized = (SSLInitializeLibrary(),
true);
+
+ _ctx.reset(SSL_CTX_new(TLS_server_method()));
+ REQUIRE(_ctx != nullptr);
+ _ssl.reset(SSL_new(_ctx.get()));
+ REQUIRE(_ssl != nullptr);
+ }
+
+ SSL *
+ get() const
+ {
+ return _ssl.get();
+ }
+
+ SSL &
+ operator*() const
+ {
+ return *_ssl;
+ }
+
+private:
+ std::unique_ptr<SSL_CTX, SSLCtxDeleter> _ctx;
+ std::unique_ptr<SSL, SSLDeleter> _ssl;
+};
+
+// IpAllow::subjects is process-wide; set it for one test and put it back
afterwards.
+class ScopedAclSubjects
+{
+public:
+ ScopedAclSubjects(std::initializer_list<uint8_t> subjects)
+ {
+ REQUIRE(subjects.size() <= IpAllow::Subject::MAX_SUBJECTS);
+ std::copy(std::begin(IpAllow::subjects), std::end(IpAllow::subjects),
std::begin(_saved));
+ std::fill(std::begin(IpAllow::subjects), std::end(IpAllow::subjects),
IpAllow::Subject::MAX_SUBJECTS);
+ std::copy(subjects.begin(), subjects.end(), std::begin(IpAllow::subjects));
+ }
+
+ ~ScopedAclSubjects() { std::copy(std::begin(_saved), std::end(_saved),
std::begin(IpAllow::subjects)); }
Review Comment:
`IpAllow::subjects` is process-global. If the test runner enables parallel
execution, these tests can race each other and become flaky. Consider
serializing access (e.g., a static mutex + lock_guard inside
`ScopedAclSubjects`) or marking these tests to run non-parallel so the global
mutation is protected.
##########
src/iocore/net/unit_tests/test_SNIActionPerformer.cc:
##########
@@ -0,0 +1,599 @@
+/** @file
+
+ Catch based unit tests for the SNI actions that act on the connection.
+
+ @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.
+ */
+
+#ifndef LIBINKNET_UNIT_TEST_DIR
+#error please set LIBINKNET_UNIT_TEST_DIR
+#endif
+
+#define _STR(s) #s
+#define _XSTR(s) _STR(s)
+
+#include "../SNIActionPerformer.h"
+#include "../P_SSLNetVConnection.h"
+#include "../P_SSLUtils.h"
+#include "../P_UnixNetVConnection.h"
+#include "iocore/net/TLSALPNSupport.h"
+#include "iocore/net/TLSSNISupport.h"
+#include "iocore/net/TLSTunnelSupport.h"
+#include "proxy/IPAllow.h"
+#include "records/RecHttp.h"
+#include "tscore/ink_inet.h"
+
+#if TS_USE_QUIC == 1
+#include "../P_QUICNetVConnection.h"
+#endif
+
+#if TS_USE_QUIC == 1 && TS_HAS_OPENSSL_QUIC
+#include "iocore/net/quic/QUICConfig.h"
+#include "iocore/net/quic/QUICGlobals.h"
+#endif
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <openssl/err.h>
+#include <openssl/ssl.h>
+
+#include <algorithm>
+#include <initializer_list>
+#include <iterator>
+#include <memory>
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#if TS_USE_QUIC == 1
+// The look-alike connections below model QUICNetVConnection, so
QUICNetVConnection must keep this shape.
+static_assert(std::is_convertible_v<QUICNetVConnection *, TLSSNISupport *>);
+static_assert(std::is_convertible_v<QUICNetVConnection *, NetVConnection *>);
+static_assert(!std::is_base_of_v<SSLNetVConnection, QUICNetVConnection>);
+#endif
+
+namespace
+{
+IpEndpoint
+make_endpoint(const char *ip)
+{
+ IpEndpoint ep;
+
+ REQUIRE(ats_ip_pton(ip, &ep) == 0);
+ return ep;
+}
+
+// A connection that attaches itself and binds TLSSNISupport and ALPNSupport
but is not an
+// SSLNetVConnection, the way QUICNetVConnection is.
+class NonSSLNetVConnection : public UnixNetVConnection, public ALPNSupport,
public TLSSNISupport
+{
+public:
+ void
+ set_peer(const char *ip)
+ {
+ IpEndpoint ep = make_endpoint(ip);
+
+ set_remote_addr(&ep.sa);
+ got_remote_addr = true;
+ }
+
+ void
+ bind_to(SSL *ssl)
+ {
+ NetVCAttach(ssl, this);
+ ALPNSupport::bind(ssl, this);
+ TLSSNISupport::bind(ssl, this);
+ }
+
+protected:
+ in_port_t
+ _get_local_port() override
+ {
+ return 443;
+ }
+};
+
+// The same, but also binding TLSTunnelSupport, so nothing but the connection
type stops a tunnel.
+class NonSSLTunnelNetVConnection : public NonSSLNetVConnection, public
TLSTunnelSupport
+{
+public:
+ void
+ bind_to(SSL *ssl)
+ {
+ NonSSLNetVConnection::bind_to(ssl);
+ TLSTunnelSupport::bind(ssl, this);
+ }
+};
+
+class PeerSSLNetVConnection : public SSLNetVConnection
+{
+public:
+ void
+ set_peer(const char *ip)
+ {
+ IpEndpoint ep = make_endpoint(ip);
+
+ set_remote_addr(&ep.sa);
+ got_remote_addr = true;
+ }
+
+ // What _bindSSLObject() binds for the slots the actions read.
+ void
+ bind_to(SSL *ssl)
+ {
+ this->ssl = ssl;
+ NetVCAttach(ssl, this);
+ ALPNSupport::bind(ssl, this);
+ TLSSNISupport::bind(ssl, this);
+ TLSTunnelSupport::bind(ssl, this);
+ }
Review Comment:
The comment says this matches what `_bindSSLObject()` binds, but this test
helper does not bind everything `_bindSSLObject()` typically binds (e.g.,
`TLSBasicSupport`, `TLSEventSupport`). Either update the comment to be precise
about which slots are required for these tests, or bind the same supports as
production to keep the test double accurate over time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]