Files
tailscale/kernel/linux/scripts/probe.sh
T
Brad Fitzpatrick ff6f9e8409 kernel/linux/{src/compat,scripts}: add feature-probe compat layer for 6.8 and 7.0
The fork tracks the newest upstream WireGuard (7.4-rc1), but has to build
on distro kernels. Our first target is the natlab Ubuntu 24.04 guest
(6.8.0-106-generic) and the dev host is on 7.0.

Rather than LINUX_VERSION_CODE checks, which lie on heavily backported
kernels such as RHEL's, scripts/probe.sh compile-tests each
src/compat/probes/HAVE_*.c against the target kernel's build directory
(in parallel, about one second in total) and writes
src/compat/generated/autoconf.h. Kbuild force-includes src/compat/compat.h,
which shims whatever is missing: udp_get_len_short, the struct sock
udp_tunnel APIs, the ipcb_flags xmit arguments, the blake2s_ctx API,
WQ_PERCPU, netif_threaded_enable, rtnl_newlink_params, sockaddr_inet, the
kmalloc_obj family and timer_container_of.

Three spots in device.c can't be shimmed from a header (the lltx bit, the
old rtnl newlink signature, and pernet exit_rtnl) and get small #ifdefs
marked TSWG_COMPAT. device.c also always sets ndo_get_stats64 to
dev_get_tstats64, since older kernels don't fold tstats in
dev_get_stats(). That is equivalent on new kernels.

tswg.ko now builds against both 6.8.0-106-generic and 7.0.0-1009-aws.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I0ed279318b4f623688d1f178a9b8fbcc0b585219
2026-11-06 21:01:41 +00:00

51 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# probe.sh compiles each src/compat/probes/HAVE_*.c against the kernel build
# directory KDIR and writes a header defining the HAVE_* macros whose probes
# compiled. It only rewrites the output file when its contents change, so
# that unchanged probe results don't force a rebuild.
#
# usage: probe.sh KDIR OUTPUT_HEADER
set -eu
if [ $# -ne 2 ]; then
echo "usage: $0 KDIR OUTPUT_HEADER" >&2
exit 2
fi
kdir=$1
out=$2
top=$(cd "$(dirname "$0")/.." && pwd)
probes=$top/src/compat/probes
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
cp "$probes"/HAVE_*.c "$tmp"/
printf 'obj-m :=\nccflags-y := -Werror\n' > "$tmp/Kbuild"
# Unset MAKEFLAGS so a parent make's jobserver and flags don't leak into the
# per-probe builds.
for c in "$tmp"/HAVE_*.c; do
basename "$c" .c
done | MAKEFLAGS= xargs -P "$(nproc)" -I{} sh -c \
'make -s -C "$1" M="$2" "$3.o" >"$2/$3.log" 2>&1 || true' \
sh "$kdir" "$tmp" {}
{
echo "/* Generated by scripts/probe.sh for $kdir. Do not edit. */"
for c in "$tmp"/HAVE_*.c; do
name=$(basename "$c" .c)
if [ -f "$tmp/$name.o" ]; then
echo "#define $name 1"
else
echo "/* #undef $name */"
fi
done
} > "$tmp/autoconf.h"
mkdir -p "$(dirname "$out")"
if ! cmp -s "$tmp/autoconf.h" "$out"; then
cp "$tmp/autoconf.h" "$out"
fi