ktls-stream
Stream abstraction for implementing Linux kernel TLS (kTLS) offload.
Overview
This crate is built on top of ktls-core and provides higher-level Stream abstraction that can be used as a drop-in replacement of TcpStream (or UnixStream, etc) after setting up kTLS offload.
Usage
Setting up kTLS offload generally involves these steps:
use TcpStream;
// Step 0 (Optional): You may probe kernel TLS compatibility in advance
let compatibilities = probe.expect;
// Step 1: Creates a `TcpStream` (or something else like `UnixStream`).
let stream = connect.await.expect;
// Step 2: Configures TLS User Level Protocol (ULP) on the socket.
if let Err = setup_ulp
// Step 3: Performs TLS handshake using your preferred TLS library over the socket.
// (omitted here) and extracts the crypto materials after handshake completion.
let = handshake.await.expect;
// Step 4: Creates a `Stream` using the configured socket and crypto materials.
let mut stream = new
.expect;
// Now you can use the `Stream` as a drop-in replacement of the original `TcpStream`.
// (omitted here)
Please check ktls-tests for more examples.
Kernel Compatibility
We perform daily CI tests against the following kernel versions:
| Ver. | Min. Ver. |
|---|---|
| mainline | - |
| stable | - |
| 6.12.x (LTS) | 6.12.0 |
| 6.6.x (LTS) | 6.6.0 |
| 6.1.x (LTS) | 6.1.28 |
| 5.15.x (LTS) | 5.15.25 |
| 5.10.x (LTS) | 5.10.102 |
| 5.4.x (LTS) | 5.4.181 |
-
For LTS versions, we test against the latest patch.
-
Have simply tested the minimum applicable kernel version, and listed above.
We recommend using the latest Linux kernel, at least 6.6 LTS, for better support of kTLS.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.