#!/bin/sh
# run.sh — DF-0741 trigger
#
# Sets up a gre-mobile tunnel (gre0, g_src=g_dst=127.0.0.1) and injects
# short IPPROTO_MOBILE packets via raw socket.  On the unpatched kernel
# this panics the guest within ~1s ("vm_fault: fault on stack guard"
# from memmove/bcopy called by gre_mobile_input).  On a kernel with the
# fix.diff applied the trigger exits 0 and the guest stays up.
#
# MUST run as root (raw socket + ifconfig gre create + tunnel setup).
#
# Capture the panic from the serial console (dfbsd-qemu/boot.log), not
# ssh, because ssh dies with the kernel.

set -e
cd "$(dirname "$0")"

# 1. Create the gre-mobile tunnel.
ifconfig gre create 2>/dev/null || true
ifconfig gre0 tunnel 127.0.0.1 127.0.0.1
ifconfig gre0 -link0          # clears IFF_LINK0  =>  g_proto = IPPROTO_MOBILE
ifconfig gre0 up

# 2. Inject short IPPROTO_MOBILE packets.
./trigger 127.0.0.1 127.0.0.1
echo "TRIGGER_DONE rc=$?"

# 3. If we get here, the guest is still up = the fix is in place.
#    On the unpatched kernel we never reach this line; check
#    dfbsd-qemu/boot.log for the panic signature.
