#!/bin/sh
# pfilrace.sh -- drive the DF-3453 race:
#   feeder keeps softclock inside pfil walks (via ip_mroute tbf drain);
#   this loop toggles pfil hook B -> COW swap -> netmsg_service_sync (netisr
#   threads only) -> pfil_list_free() while the softclock walk is in flight.
#
# usage: pfilrace.sh <max_seconds>   (run as root on the guest)
MAX=${1:-300}
START=$(date +%s)
i=0
echo "pfilrace: toggling for up to ${MAX}s"
while true; do
    NOW=$(date +%s)
    [ $((NOW - START)) -gt $MAX ] && break
    sysctl -w net.prhook_toggle=1 >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "pfilrace: sysctl toggle failed at iter $i (guest alive?)"
        break
    fi
    i=$((i + 1))
    [ $((i % 10)) -eq 0 ] && echo "pfilrace: $i toggles ($(date +%T))"
    sleep 0.05
done 2>&1 | tee /tmp/pfilrace_toggle.log
echo "pfilrace: finished after $i toggles, guest still up (no panic)"
