From cd715b7e7fdd2aeb0fd80220d2df5187b291f87a Mon Sep 17 00:00:00 2001 From: Maxim Mikityanskiy Date: Wed, 9 Nov 2022 11:26:11 +0200 Subject: Add support for KTLS zerocopy sendfile on Linux TLS device offload allows to perform zerocopy sendfile transmissions. FreeBSD provides this feature by default, and Linux 5.19 introduced it as an opt-in. Zerocopy improves the TX rate significantly, but has a side effect: if the underlying file is changed while being transmitted, and a TCP retransmission happens, the receiver may get a TLS record containing both new and old data, which leads to an authentication failure and termination of connection. This effect is the reason Linux makes a copy on sendfile by default. This commit adds support for TLS zerocopy sendfile on Linux disabled by default to avoid any unlikely backward compatibility issues on Linux, although sacrificing consistency in OpenSSL's behavior on Linux and FreeBSD. A new option called KTLSTxZerocopySendfile is added to enable the new zerocopy behavior on Linux. This option should be used when the the application guarantees that the file is not modified during transmission, or it doesn't care about breaking the connection. The related documentation is also added in this commit. The unit test added doesn't test the actual functionality (it would require specific hardware and a non-local peer), but solely checks that it's possible to set the new option flag. Signed-off-by: Maxim Mikityanskiy Reviewed-by: Tariq Toukan Reviewed-by: Boris Pismenny Reviewed-by: Matt Caswell Reviewed-by: Todd Short Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/18650) --- crypto/bio/bss_sock.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'crypto/bio/bss_sock.c') diff --git a/crypto/bio/bss_sock.c b/crypto/bio/bss_sock.c index 69dfd37bfe..f64eb8c843 100644 --- a/crypto/bio/bss_sock.c +++ b/crypto/bio/bss_sock.c @@ -235,6 +235,11 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) BIO_clear_ktls_ctrl_msg_flag(b); ret = 0; break; + case BIO_CTRL_SET_KTLS_TX_ZEROCOPY_SENDFILE: + ret = ktls_enable_tx_zerocopy_sendfile(b->num); + if (ret) + BIO_set_ktls_zerocopy_sendfile_flag(b); + break; # endif case BIO_CTRL_EOF: ret = (b->flags & BIO_FLAGS_IN_EOF) != 0; -- cgit v1.2.3