#!/bin/sh
# DF-2611 setup (root): create tap0, addresses, static ND entries, and the
# gateway route that makes the guest redirect transit traffic out tap0.
set -x
kldload if_tap
# keep tap0 alive in the background
if [ ! -f /tmp/tap_hold.pid ] || ! kill -0 $(cat /tmp/tap_hold.pid) 2>/dev/null; then
	( /root/poc/tap_rdr hold >/tmp/tap_hold.log 2>&1 & echo $! > /tmp/tap_hold.pid )
	sleep 1
fi
ifconfig tap0 up
sleep 1
ifconfig tap0 | head -5
# on-link prefix for the attacker + attacker static ND entry (so the
# redirect can be transmitted immediately) + gateway static ND entry
ifconfig tap0 inet6 2001:db8:1::1/64 alias
ndp -s tap0 fe80::42:1 02:00:00:00:00:01
ndp -s tap0 2001:db8:1::2 02:00:de:ad:be:ef
# gateway route for the off-link destination prefix
route delete -inet6 2001:db8:cafe::/64 2>/dev/null
route add -inet6 -net 2001:db8:cafe::/64 fe80::42:1 -ifp tap0
route -n get 2001:db8:cafe::1
# become a router
sysctl -w net.inet6.ip6.forwarding=1
sysctl -w net.inet6.icmp6.nd6_debug=1
ifconfig tap0
ndp -an | grep tap0
