- #!/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 ;"
- "exit 0 ;"
- "} ;"
- '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 ;" # wait
- # this is tricky (and nasty):
- # we have to tell our session sshd instance to quit, and then
- # busy-wait until we get SIGHUP from gthat sshd process back
- # so our HUP trap handler function gets called
- 'kill -s INT ${PPID} ;'
- 'while true ; do sleep 0.1 ; done ;'
- )
- 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.
ssh tuntap #017
Posted by Anonymous on Thu 14th Apr 2022 14:05
raw | new post
view followups (newest first): ssh tuntap #017 by Anonymous
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.