#!/bin/sh - # # ls testinterfaces.sh | entr sh -c 'fsync testinterfaces.sh && sh testinterfaces.sh ue0 ue1' # testiface="$1" checkiface="$2" echo starting, test $1, check $2 # ifconfig -m to get caps getcaps() { ifconfig -m "$1" | awk '$1 ~ /^capabilities=/ { split($0, a, "<"); split(a[2], b, ">"); split(b[1], caps, ","); for (i in caps) print caps[i] }' } if ! testjail=$(jail -i -c persist=1 path=/ name=testjail vnet=new vnet.interface="$testiface"); then echo failed to start test jail exit 1 fi if ! checkjail=$(jail -i -c persist=1 path=/ name=checkjail vnet=new vnet.interface="$checkiface"); then echo failed to start check jail exit 1 fi cleanup() { jail -r "$testjail" jail -r "$checkjail" } trap cleanup EXIT run() { if [ x"$1" = x"check" ]; then jid="$checkjail" elif [ x"$1" = x"test" ]; then jid="$testjail" else echo Invalid: "$1" >&2 exit 1 fi shift jexec "$jid" "$@" } ifjail() { if [ x"$1" = x"check" ]; then iface="$checkiface" elif [ x"$1" = x"test" ]; then iface="$testiface" else echo Invalid: "$1" >&2 exit 1 fi j="$1" shift run "$j" ifconfig "$iface" "$@" } waitcarrier() { local i for i in test check; do while :; do if ifjail "$i" | grep 1000baseT >/dev/null; then break fi sleep .5 done done } hwvlantest() { run test ifconfig lo0 up run check ifconfig lo0 up for i in "vlanhwtag" "-vlanhwtag"; do ifjail test down ifjail check down ifjail test "$i" ifjail check -vlanhwtag ifjail test up ifjail check up sleep 2 run test ifconfig $testiface.42 create 172.30.5.5/24 run check ifconfig $checkiface.42 create 172.30.5.4/24 waitcarrier run check tcpdump -p -q -c 2 -n -i "$checkiface" vlan 42 and icmp & sleep 1 if ! run test ping -c 1 -t 2 172.30.5.4; then echo FAILED on "$i"!!!! exit 1 fi done } hwvlantest