#!/bin/sh
# DF-3310 setup: wg0 <-> wg1 as peers over lo0 with RFC 7748 6.1 keys
# (kernel does all DH; keys are fixed, trusted pairs).  ping -f gives the
# continuous wg_send() traffic that holds so_lock SHARED / reads so_so4.
ROOT=$(dirname "$0")
P0=77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a   # Alice priv
PUB0=8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a # Alice pub
P1=5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb   # Bob priv
PUB1=de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f # Bob pub

ifconfig wg0 destroy 2>/dev/null
ifconfig wg1 destroy 2>/dev/null
ifconfig wg0 create
ifconfig wg1 create
$ROOT/wgtool set wg0 $P0 40001
$ROOT/wgtool set wg1 $P1 40002
$ROOT/wgtool peer wg0 $PUB1 127.0.0.1 40002 24 1
$ROOT/wgtool peer wg1 $PUB0 127.0.0.1 40001 24 1
ifconfig wg0 10.7.0.1/24 up
ifconfig wg1 10.7.0.2/24 up
sleep 8
if ping -c 2 10.7.0.2 >/dev/null 2>&1; then
	echo "TUNNEL_UP"
else
	echo "TUNNEL_DOWN"
fi
