Skip to content

Commit b6515d9

Browse files
committed
Move things out of the NetVC, subtract early data
1 parent 9300fc0 commit b6515d9

File tree

9 files changed

+66
-57
lines changed

9 files changed

+66
-57
lines changed

doc/admin-guide/logging/formatting.en.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,8 @@ cqql Client Request Client request header and content length combined,
455455
in bytes.
456456
cqqtl Client Request Same as cqql_, but for the first transaction on a
457457
TLS connection, also includes TLS handshake bytes
458-
received from the client. Since the TLS handshake
459-
only occurs once per connection, the handshake bytes
460-
are only attributed to the first transaction to
461-
prevent double-counting.
458+
received from the client. Note that this metrics
459+
may not always be 100% accurate.
462460
csscl Cached Origin Response Content body length from cached origin response.
463461
csshl Cached Origin Response Header length from cached origin response.
464462
cssql Cached Origin Response Content and header length from cached origin
@@ -476,10 +474,8 @@ psql Proxy Response Content body and header length combined of the
476474
|TS| response to client.
477475
psqtl Proxy Response Same as psql_, but for the first transaction on a
478476
TLS connection, also includes TLS handshake bytes
479-
sent to the client. Since the TLS handshake only
480-
occurs once per connection, the handshake bytes are
481-
only attributed to the first transaction to prevent
482-
double-counting.
477+
sent to the client. Note that this metric may not
478+
always be 100% accurate.
483479
sscl Origin Response Content body length of the origin server response
484480
to |TS|.
485481
sshl Origin Response Header length of the origin server response.

include/iocore/net/NetVConnection.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,6 @@ class NetVConnection : public VConnection, public PluginUserArgs<TS_USER_ARGS_VC
322322
return 0;
323323
}
324324

325-
/** Capture handshake byte statistics. */
326-
virtual bool
327-
capture_handshake_bytes(uint64_t &bytes_in, uint64_t &bytes_out)
328-
{
329-
bytes_in = 0;
330-
bytes_out = 0;
331-
return false;
332-
}
333-
334325
/** Structure holding user options. */
335326
NetVCOptions options;
336327

include/iocore/net/TLSBasicSupport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class TLSBasicSupport
5151
std::string_view get_tls_group() const;
5252
ink_hrtime get_tls_handshake_begin_time() const;
5353
ink_hrtime get_tls_handshake_end_time() const;
54+
bool get_tls_handshake_bytes(uint64_t &bytes_in, uint64_t &bytes_out);
55+
5456
/**
5557
* Returns a certificate that need to be verified.
5658
*
@@ -103,4 +105,6 @@ class TLSBasicSupport
103105

104106
ink_hrtime _tls_handshake_begin_time = 0;
105107
ink_hrtime _tls_handshake_end_time = 0;
108+
uint64_t _tls_handshake_bytes_in = 0;
109+
uint64_t _tls_handshake_bytes_out = 0;
106110
};

include/proxy/http/HttpUserAgent.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "proxy/ProxyTransaction.h"
3232
#include "records/RecHttp.h"
3333
#include "iocore/net/TLSBasicSupport.h"
34+
#include "iocore/net/TLSEarlyDataSupport.h"
3435
#include "iocore/net/TLSSessionResumptionSupport.h"
3536
#include "tscore/ink_assert.h"
3637

@@ -59,6 +60,7 @@ struct ClientConnectionInfo {
5960
// TLS handshake bytes (rx = received from client, tx = sent to client)
6061
uint64_t tls_handshake_bytes_rx{0};
6162
uint64_t tls_handshake_bytes_tx{0};
63+
size_t tls_early_data_len{0};
6264
};
6365

6466
class HttpUserAgent
@@ -105,6 +107,8 @@ class HttpUserAgent
105107

106108
uint64_t get_client_tls_handshake_bytes_tx() const;
107109

110+
size_t get_client_tls_early_data_len() const;
111+
108112
private:
109113
HttpVCTableEntry *m_entry{nullptr};
110114
IOBufferReader *m_raw_buffer_reader{nullptr};
@@ -194,7 +198,11 @@ HttpUserAgent::set_txn(ProxyTransaction *txn, TransactionMilestones &milestones)
194198
milestones[TS_MILESTONE_TLS_HANDSHAKE_START] = tbs->get_tls_handshake_begin_time();
195199
milestones[TS_MILESTONE_TLS_HANDSHAKE_END] = tbs->get_tls_handshake_end_time();
196200
}
197-
netvc->capture_handshake_bytes(m_conn_info.tls_handshake_bytes_rx, m_conn_info.tls_handshake_bytes_tx);
201+
tbs->get_tls_handshake_bytes(m_conn_info.tls_handshake_bytes_rx, m_conn_info.tls_handshake_bytes_tx);
202+
}
203+
204+
if (auto eds = netvc->get_service<TLSEarlyDataSupport>()) {
205+
m_conn_info.tls_early_data_len = eds->get_early_data_len();
198206
}
199207

200208
if (auto as = netvc->get_service<ALPNSupport>()) {
@@ -322,6 +330,12 @@ HttpUserAgent::get_client_tls_handshake_bytes_tx() const
322330
return m_conn_info.tls_handshake_bytes_tx;
323331
}
324332

333+
inline size_t
334+
HttpUserAgent::get_client_tls_early_data_len() const
335+
{
336+
return m_conn_info.tls_early_data_len;
337+
}
338+
325339
inline void
326340
HttpUserAgent::save_transaction_info()
327341
{

src/iocore/net/P_SSLNetVConnection.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ class SSLNetVConnection : public UnixNetVConnection,
309309
EThread *getThreadForTLSEvents() override;
310310
Ptr<ProxyMutex> getMutexForTLSEvents() override;
311311

312-
bool capture_handshake_bytes(uint64_t &bytes_in, uint64_t &bytes_out) override;
313-
314312
protected:
315313
// UnixNetVConnection
316314
bool _isReadyToTransferData() const override;
@@ -378,10 +376,6 @@ class SSLNetVConnection : public UnixNetVConnection,
378376
*/
379377
char *_getCoalescedHandShakeBuffer(int64_t total_chain_size);
380378

381-
// TLS handshake byte tracking (bytes read/written during handshake only)
382-
uint64_t _tls_handshake_bytes_in = 0;
383-
uint64_t _tls_handshake_bytes_out = 0;
384-
385379
enum SSLHandshakeStatus sslHandshakeStatus = SSLHandshakeStatus::SSL_HANDSHAKE_ONGOING;
386380
bool sslClientRenegotiationAbort = false;
387381
bool first_ssl_connect = true;

src/iocore/net/SSLNetVConnection.cc

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,6 @@ SSLNetVConnection::clear()
978978
sslLastWriteTime = 0;
979979
sslTotalBytesSent = 0;
980980
sslClientRenegotiationAbort = false;
981-
_tls_handshake_bytes_in = 0;
982-
_tls_handshake_bytes_out = 0;
983981
hookOpRequested = SslVConnOp::SSL_HOOK_OP_DEFAULT;
984982

985983
free_handshake_buffers();
@@ -2485,31 +2483,3 @@ SSLNetVConnection::_ssl_read_buffer(void *buf, int64_t nbytes, int64_t &nread)
24852483

24862484
return ssl_error;
24872485
}
2488-
2489-
bool
2490-
SSLNetVConnection::capture_handshake_bytes(uint64_t &bytes_in, uint64_t &bytes_out)
2491-
{
2492-
if (_tls_handshake_bytes_in > 0 || _tls_handshake_bytes_out > 0) {
2493-
bytes_in = _tls_handshake_bytes_in;
2494-
bytes_out = _tls_handshake_bytes_out;
2495-
2496-
return false;
2497-
}
2498-
2499-
// If no SSL object, nothing to capture
2500-
if (this->ssl == nullptr) {
2501-
bytes_in = 0;
2502-
bytes_out = 0;
2503-
2504-
return false;
2505-
}
2506-
2507-
// Capture bytes from BIO statistics
2508-
BIO *rbio = SSL_get_rbio(this->ssl);
2509-
BIO *wbio = SSL_get_wbio(this->ssl);
2510-
2511-
bytes_in = _tls_handshake_bytes_in = rbio ? BIO_number_read(rbio) : 0;
2512-
bytes_out = _tls_handshake_bytes_out = wbio ? BIO_number_written(wbio) : 0;
2513-
2514-
return true;
2515-
}

src/iocore/net/SSLUtils.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,11 @@ ssl_callback_info(const SSL *ssl, int where, int ret)
10791079
Metrics::Counter::increment(it->second);
10801080
}
10811081

1082-
// Capture TLS handshake byte statistics
10831082
if (netvc && netvc->get_context() == NET_VCONNECTION_IN) {
10841083
uint64_t bytes_in = 0, bytes_out = 0;
1084+
auto tbs = TLSBasicSupport::getInstance(const_cast<SSL *>(ssl));
10851085

1086-
if (netvc->capture_handshake_bytes(bytes_in, bytes_out)) {
1086+
if (tbs && tbs->get_tls_handshake_bytes(bytes_in, bytes_out)) {
10871087
Metrics::Counter::increment(ssl_rsb.tls_handshake_bytes_in_total, bytes_in);
10881088
Metrics::Counter::increment(ssl_rsb.tls_handshake_bytes_out_total, bytes_out);
10891089
}

src/iocore/net/TLSBasicSupport.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,36 @@ TLSBasicSupport::clear()
7272
{
7373
this->_tls_handshake_begin_time = 0;
7474
this->_tls_handshake_end_time = 0;
75+
this->_tls_handshake_bytes_in = 0;
76+
this->_tls_handshake_bytes_out = 0;
77+
}
78+
79+
bool
80+
TLSBasicSupport::get_tls_handshake_bytes(uint64_t &bytes_in, uint64_t &bytes_out)
81+
{
82+
if (_tls_handshake_bytes_in > 0 || _tls_handshake_bytes_out > 0) {
83+
bytes_in = _tls_handshake_bytes_in;
84+
bytes_out = _tls_handshake_bytes_out;
85+
return false;
86+
}
87+
88+
SSL *ssl = this->_get_ssl_object();
89+
if (ssl == nullptr) {
90+
bytes_in = 0;
91+
bytes_out = 0;
92+
return false;
93+
}
94+
95+
BIO *rbio = SSL_get_rbio(ssl);
96+
BIO *wbio = SSL_get_wbio(ssl);
97+
98+
uint64_t bio_in = rbio ? BIO_number_read(rbio) : 0;
99+
uint64_t bio_out = wbio ? BIO_number_written(wbio) : 0;
100+
101+
bytes_in = _tls_handshake_bytes_in = bio_in;
102+
bytes_out = _tls_handshake_bytes_out = bio_out;
103+
104+
return true;
75105
}
76106

77107
TLSHandle

src/proxy/logging/LogAccess.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,9 @@ LogAccess::marshal_client_req_squid_len(char *buf)
20982098

20992099
/*-------------------------------------------------------------------------
21002100
Client request squid length plus TLS handshake bytes received for TLS connections.
2101+
For TLS 1.3 early data (0-RTT), we subtract the early data length from the
2102+
handshake bytes to avoid double-counting since the early data bytes are
2103+
already included in client_request_body_bytes.
21012104
-------------------------------------------------------------------------*/
21022105
int
21032106
LogAccess::marshal_client_req_squid_len_tls(char *buf)
@@ -2110,7 +2113,14 @@ LogAccess::marshal_client_req_squid_len_tls(char *buf)
21102113
}
21112114

21122115
if (!m_http_sm->get_user_agent().get_client_tcp_reused()) {
2113-
val += m_http_sm->get_user_agent().get_client_tls_handshake_bytes_rx();
2116+
uint64_t handshake_rx = m_http_sm->get_user_agent().get_client_tls_handshake_bytes_rx();
2117+
size_t early_data_len = m_http_sm->get_user_agent().get_client_tls_early_data_len();
2118+
2119+
if (early_data_len > 0 && handshake_rx > early_data_len) {
2120+
handshake_rx -= early_data_len;
2121+
}
2122+
2123+
val += handshake_rx;
21142124
}
21152125
marshal_int(buf, val);
21162126
}

0 commit comments

Comments
 (0)