From c21cab05f8c188b52aa2b9832420d726e60aef87 Mon Sep 17 00:00:00 2001 From: SDD Date: Sat, 17 Oct 2026 14:15:17 +0300 Subject: [PATCH] harness: net-setup.sh -- recreate the tap+bridge the harness needs (they do not survive a reboot) --- harness/net-setup.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 harness/net-setup.sh diff --git a/harness/net-setup.sh b/harness/net-setup.sh new file mode 100755 index 0000000..1e85876 --- /dev/null +++ b/harness/net-setup.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# net-setup.sh -- create the tap + bridge the VT1200 harness needs on the host. +# +# Idempotent: safe to re-run, and NEEDS re-running after a reboot, because both +# the tap and the bridge are runtime kernel state and do not survive one. +# +# ./harness/net-setup.sh +# +# The tap is owned by your user, which is what lets MAME attach to it with no +# sudo and no capabilities of its own. The bridge gets an address so the host +# can serve BOOTP and TFTP to the terminal. +# +# IMPORTANT: both interfaces will still show DOWN until MAME opens the tap. A +# tap has carrier only while a process holds it open, and a bridge whose only +# port has no carrier reports down. That is correct, not a failure. + +set -euo pipefail + +UID_="$(id -u)" +USER_="$(id -un)" +TAP="tap-mess-${UID_}-0" # MAME's own naming: taptun.cpp, "tap-mess-%d-0" +BRIDGE="vt1200" +ADDR="192.168.99.1/24" + +if ! sudo -n true 2>/dev/null; then + echo "net-setup: needs passwordless sudo (or run these by hand):" >&2 + echo " ip tuntap add dev $TAP mode tap user $USER_" >&2 + echo " ip link add dev $BRIDGE type bridge" >&2 + exit 1 +fi + +if ip link show "$TAP" >/dev/null 2>&1; then + echo "net-setup: $TAP exists, leaving it" +else + sudo -n ip tuntap add dev "$TAP" mode tap user "$USER_" + echo "net-setup: created $TAP (owned by $USER_)" +fi + +if ip link show "$BRIDGE" >/dev/null 2>&1; then + echo "net-setup: $BRIDGE exists, leaving it" +else + sudo -n ip link add dev "$BRIDGE" type bridge + echo "net-setup: created $BRIDGE" +fi + +sudo -n ip link set "$TAP" master "$BRIDGE" +sudo -n ip link set "$TAP" up +sudo -n ip link set "$BRIDGE" up +# single-member bridge: no STP, so it forwards immediately instead of after ~30s +sudo -n ip link set "$BRIDGE" type bridge stp_state 0 +sudo -n ip addr replace "$ADDR" dev "$BRIDGE" + +echo +echo "host side now:" +ip -brief addr show "$BRIDGE" | sed 's/^/ /' +ip -brief link show "$TAP" | sed 's/^/ /' +echo +echo "reminder: both read DOWN until MAME holds the tap. Then run, in another shell:" +echo " sudo python3 -u harness/serve.py 192.168.99.1 --bootp" +echo " ./run.sh net"