Skip to content

Commit 310d7d4

Browse files
committed
Add kTLS options and SSL_sendfile
1 parent 9f29412 commit 310d7d4

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

openssl-sys/src/handwritten/ssl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ extern "C" {
674674
num: size_t,
675675
written: *mut size_t,
676676
) -> c_int;
677+
#[cfg(ossl300)]
678+
pub fn SSL_sendfile(ssl: *mut SSL, fd: c_int, offset: off_t, size: size_t, flags: c_int) -> ssize_t;
677679
#[cfg(any(ossl111, libressl340))]
678680
pub fn SSL_write_early_data(
679681
s: *mut SSL,

openssl-sys/src/ssl.rs

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ cfg_if! {
7373
}
7474

7575
pub const SSL_OP_LEGACY_SERVER_CONNECT: ssl_op_type!() = 0x00000004;
76+
#[cfg(ossl300)]
77+
pub const SSL_OP_ENABLE_KTLS: ssl_op_type!() = 0x00000008;
7678
cfg_if! {
7779
if #[cfg(libressl261)] {
7880
pub const SSL_OP_TLSEXT_PADDING: ssl_op_type!() = 0x0;
@@ -169,6 +171,9 @@ cfg_if! {
169171
}
170172
}
171173

174+
#[cfg(ossl320)]
175+
pub const SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE: ssl_op_type!() = 0x400000000;
176+
172177
cfg_if! {
173178
if #[cfg(ossl300)] {
174179
pub const SSL_OP_ALL: ssl_op_type!() = SSL_OP_CRYPTOPRO_TLSEXT_BUG

openssl/src/ssl/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,26 @@ bitflags! {
281281
/// [`SslOptions::CIPHER_SERVER_PREFERENCE`]: struct.SslOptions.html#associatedconstant.CIPHER_SERVER_PREFERENCE
282282
#[cfg(ossl111)]
283283
const PRIORITIZE_CHACHA = ffi::SSL_OP_PRIORITIZE_CHACHA as SslOptionsRepr;
284+
285+
/// Enable the use of kernel TLS.
286+
///
287+
/// In order to benefit from kernel TLS OpenSSL must have been compiled with support for it,
288+
/// and it must be supported by the negotiated ciphersuites and extensions.
289+
/// The specific ciphersuites and extensions that are supported may vary by platform and kernel version.
290+
///
291+
/// Requires OpenSSL 3.0.0 or newer.
292+
#[cfg(ossl300)]
293+
const ENABLE_KTLS = ffi::SSL_OP_ENABLE_KTLS as SslOptionsRepr;
294+
295+
/// With this option, sendfile() will use the zerocopy mode, which gives a performance boost when used with KTLS hardware offload.
296+
/// Note that invalid TLS records might be transmitted if the file is changed while being sent.
297+
///
298+
/// Requires enable [`SslOptions::ENABLE_KTLS`].
299+
/// Requires OpenSSL 3.2.0 or newer.
300+
///
301+
/// [`SslOptions::ENABLE_KTLS`]: struct.SslOptions.html#associatedconstant.ENABLE_KTLS
302+
#[cfg(ossl320)]
303+
const ENABLE_KTLS_ZEROCOPY_SENDFILE = ffi::SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE as SslOptionsRepr;
284304
}
285305
}
286306

0 commit comments

Comments
 (0)