#!/usr/bin/ksh93 # # Ethernet/tap forwarding via ssh # set -o xtrace set -o errexit set -o nounset # list of commands our ssh session should execute typeset -a sshcmds=( # # cleanup: # # we need to clean up the bridge interface ourselves, if # we do not do that we risk getting that any subsequent # ifconfig/ip/etc command hangs # '(( trap_once=0 )) ;' "netcleanup() { " '(( trap_once++ > 0 )) && return 0 ;' "set +o errexit ;" "brctl delif br19 tap19 ;" "brctl delif br19 eno1 ;" "ifconfig tap19 down ;" "ifconfig br19 down ;" "brctl delbr br19 ;" "} ;" 'trap netcleanup EXIT ;' 'trap netcleanup HUP ;' "set -o xtrace ;" "set -o errexit ;" "brctl addbr br19 ;" "brctl addif br19 tap19 ;" "brctl addif br19 eno1 ;" "brctl show ;" "ifconfig tap19 promisc ;" "ifconfig tap19 up ;" "ifconfig br19 up ;" "read dummy ;" # dummy wait 'kill -s HUP -${PPID} ;' ) ssh \ -o ExitOnForwardFailure=yes \ -o PermitLocalCommand=yes \ -o LocalCommand="ifconfig tap19 up" \ -o Tunnel=ethernet -w 19:19 \ root@10.49.20.202 \ "${sshcmds[*]}" # cleanup # ... # EOF.