Article View: muc.lists.freebsd.bugs
Article #824[Bug 301217] tun(4): make tunwrite_l3() packet entropy harvesting optional behind RANDOM_ENABLE_TUN
From: bugzilla-noreply
Date: Sat, 28 Nov 2026 09:27
Date: Sat, 28 Nov 2026 09:27
82 lines
5608 bytes
5608 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301217
Bug ID: 301217
Summary: tun(4): make tunwrite_l3() packet entropy harvesting
optional behind RANDOM_ENABLE_TUN
Product: Base System
Version: 16.0-CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: laamalif@proton.me
Commit a6bc59f20340 disabled ether_input() entropy harvesting behind
RANDOM_ENABLE_ETHER because packet-rate harvesting acquires the global
harvest_context.hc_mtx spinlock and stirs minimal entropy at a steep
packet-rate cost. In sys/net/if_tuntap.c (main 2534dcb233ad),
tunwrite_l3() still harvests every outbound L3 tunnel packet by default:
random_harvest_queue(m, sizeof(*m), RANDOM_NET_TUN);
Because RANDOM_NET_TUN remains enabled in almost_everything_mask in
sys/dev/random/random_harvestq.c (and in /etc/defaults/rc.conf
harvest_mask), every packet written to /dev/tun acquires the global
MTX_SPIN harvest lock with interrupts disabled and runs jenkins_hash()
over all 256 bytes of struct mbuf.
On FreeBSD 16.0-CURRENT amd64 GENERIC-NODEBUG (main 2534dcb233ad, Xeon
6975P-C, 8 vCPUs), injecting 50000 28-byte IPv4 UDP packets per thread
across 8 pinned threads on tun0..tun7 (million packets/sec total, 10
runs):
cc -O2 -Wall -Wextra -Werror -pthread -o tun_tx_bench tun_tx_bench.c
for i in $(jot 10); do sudo ./tun_tx_bench 8 50000; done
x base_tun8.txt
+ patched_tun8.txt
+--------------------------------------------------------------------------+
| x +|
| x + +|
| x +++|
|xx ++++|
||A |A||
+--------------------------------------------------------------------------+
N Min Max Median Avg Stddev
x 10 8.778 9.139 9.0165 8.9973 0.09908812
+ 10 27.602 28.392 28.154 28.0824 0.29064839
Difference at 95.0% confidence
19.0851 +/- 0.204019
212.12% +/- 3.13403%
(Student's t, pooled s = 0.217135)
Single-thread throughput (sudo cpuset -l 2 ./tun_tx_bench 1 100000,
N=10) rises from 4.656 Mpps to 5.291 Mpps (+13.63% +/- 0.64% at 95%
confidence), SIOCGIFDATA confirms all packets traverse tunwrite_l3(),
and debug GENERIC (INVARIANTS and WITNESS) runs cleanly. Without
RANDOM_ENABLE_TUN, user_immutable_mask masks off RANDOM_NET_TUN when
/etc/rc.d/random applies /etc/defaults/rc.conf harvest_mask="4607", so
mask_symbolic reports [NET_TUN] and fbt::random_harvest_queue_:entry is
0; built with options RANDOM_ENABLE_TUN, harvesting is active at boot
(56000 calls on ./tun_tx_bench 8 5000), drops to 0 when cleared in
harvest.mask, and resumes (56000 calls) when re-enabled.
Making tunnel packet entropy harvesting optional behind
RANDOM_ENABLE_TUN (documented in random(4), matching RANDOM_ENABLE_ETHER)
avoids per-packet entropy harvesting overhead when RANDOM_ENABLE_TUN is
not configured.
Source inspection shows the same tunwrite_l3() harvesting on stable/15
and stable/14; I have only runtime-tested 16.0-CURRENT amd64.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<bug-301217-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 301217] tun(4): make tunwrite_l3() packet entropy harvesting optional behind RANDOM_ENABLE_TUN Date: Sat, 28 Nov 2026 09:27:40 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301217-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="71992"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795858060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CdK9XLFodXKv8udSeidkvtNtmEx/koWcyGcOrZR0Z6A=; b=PUgy9HFpTrU/JKnyoSZPvZSIa4qUzffabQstJEMOxZ+2umIuSQurezrstRi/R9OdJF4mog 77RXxHVHQutJIef2Ksn7ZDHQdeQ09Jm7PX3e9JWdu5nWg9ZywtRXKW7ogdL1OtFFWS9bWN k1QBHaOSUbluE/zqYeX+8a7ex5z3sviQGAs4LGyyMuQMEXq80hyKTHPOE20YM05etRp9Jq Ktwl6Yba0FaKRWyAgvJ9FSyroR3MdG0NU/21mXH6Tnbjn0fuBWCYrJbxJmwtR9FJMO4sAu Ilt/h6voH/GvtJEZoq3ktzvBcgbdHnWeMg2K5wnCYEutAtUt2RVPyexJye7q9w== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes