fix tls_bench DTLS mode failures#10606
Open
miyazakh wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes DTLS (-u) mode failures in examples/benchmark/tls_bench.c by correcting UDP socket setup, avoiding DTLS 1.3 method selection when not compiled in, and choosing a default DTLS payload size that fits within wolfSSL’s default MTU constraints.
Changes:
- Fix
SetupSocketAndListen()tobind()UDP sockets and only calllisten()for TCP. - Skip TLS 1.3 cipher suites during DTLS runs when
WOLFSSL_DTLS13is not enabled to preventwolfSSL_CTX_new()failures. - Reduce the default DTLS test packet size for non-embedded builds to fit within
WOLFSSL_MAX_MTU, and update the startup banner to reflect TLS vs DTLS mode.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10606
No scan targets match the changed files in this PR. Review skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix tls_bench DTLS (
-u) mode failuresSummary
Running
tls_bench -u(DTLS mode) failed immediately with the following errors:And after partial fixes, a third error appeared:
This PR fixes three independent bugs in
examples/benchmark/tls_bench.c.Bug 1:
SetupSocketAndListencalledlisten()on a UDP socketRoot cause
When DTLS mode is active,
SetupSocketAndListen()correctly created aSOCK_DGRAM(UDP) socket instead of a
SOCK_STREAM(TCP) socket. However,setsockopt(),bind(), andlisten()were all inside the TCP-onlyelsebranch, so:listen()was called unconditionally after the socket-type branch, which alwaysfails on a UDP socket (
EOPNOTSUPP), producingERROR: failed to listen.Fix
setsockopt(SO_REUSEADDR)andbind()outside the TCP-only block so theyapply to both TCP and UDP sockets.
listen()call with#ifdef WOLFSSL_DTLS if (!doDTLS)so it is onlycalled for TCP connections.
Bug 2:
wolfSSL_CTX_new()returned NULL for TLS 1.3 ciphers in DTLS mode (whenWOLFSSL_DTLS13is not compiled in)Root cause
When iterating over the default cipher list in DTLS mode, TLS 1.3 cipher suites
(names starting with
"TLS13") were encountered. The client/server setup codeattempted to use
wolfDTLSv1_3_client/server_method()inside an#ifdef WOLFSSL_DTLS13guard. WhenWOLFSSL_DTLS13is not compiled in, nomethod was assigned, leaving
ctx == NULL. The subsequent NULL check returnedMEMORY_E(-125), producing:Fix
Add an early-continue in the cipher iteration loop: when DTLS mode is active and
WOLFSSL_DTLS13is not compiled in, silently skip any TLS 1.3 cipher suite.Bug 3:
TEST_DTLS_PACKET_SIZEexceeded the default DTLS MTURoot cause
TEST_DTLS_PACKET_SIZEwas defined as 8092 bytes (referencingMAX_UDP_SIZEininternal.h). However, wolfSSL'sSendData()checks that the total DTLS recordsize fits within
MAX_MTU(default: 1400 bytes). Since 8092 bytes of payloadproduces a record far larger than 1400 bytes,
SendData()returnedDTLS_SIZE_ERROR(-439) on every write:MAX_UDP_SIZE(8092) is the maximum UDP datagram size wolfSSL is prepared toreceive, not the send-side MTU limit. The two constants serve different purposes
and were conflated.
Fix
Change
TEST_DTLS_PACKET_SIZEfor non-embedded builds from8092to1200,which fits within
MAX_MTU (1400) - MAX_MSG_EXTRA (~102). A comment documentsthe two compile-time options that allow larger packets:
WOLFSSL_DTLS_MTU+wolfSSL_dtls_set_mtu()— set a per-session MTUWOLFSSL_NO_DTLS_SIZE_CHECK— auto-fragment writes that exceed the MTUThe automatic fallback already present in tls_bench (
argTestPacketSizeisreduced to
TEST_DTLS_PACKET_SIZEwhen DTLS mode is detected and no-pflagis given) now produces a value that actually works with the default MTU.
Improvement: startup message now reflects the active protocol
The banner printed at the start of the run was always
"Running TLS Benchmarks...",even when DTLS mode (
-u) was selected. It now reads"Running DTLS Benchmarks..."when DTLS is active and
"Running TLS Benchmarks..."otherwise.Files changed
examples/benchmark/tls_bench.cTesting
Verified on Linux (x86-64) with a wolfSSL build that has
WOLFSSL_DTLSandWOLFSSL_DTLS13enabled.Checklist