pastebin - collaborative debugging tool
rovema.kpaste.net RSS


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)

  1. #!/usr/bin/ksh93
  2.  
  3. #
  4. # Ethernet/tap forwarding via ssh
  5. #
  6.  
  7. set -o xtrace
  8. set -o errexit
  9. set -o nounset
  10.  
  11. # list of commands our ssh session should execute
  12. typeset -a sshcmds=(
  13.         #
  14.         # cleanup:
  15.         #
  16.         # we need to clean up the bridge interface ourselves, if
  17.         # we do not do that we risk getting that any subsequent
  18.         # ifconfig/ip/etc command hangs
  19.         #
  20.         '(( trap_once=0 )) ;'
  21.         "netcleanup() { "
  22.                 '(( trap_once++ > 0 )) && return 0 ;'
  23.                 "set +o errexit ;"
  24.                 "brctl delif br19 tap19 ;"
  25.                 "brctl delif br19 eno1 ;"
  26.                 "ifconfig tap19 down ;"
  27.                 "ifconfig br19 down ;"
  28.                 "brctl delbr br19 ;"
  29.                 "exit 0 ;"
  30.         "} ;"
  31.         'trap netcleanup EXIT ;'
  32.         'trap netcleanup HUP ;'
  33.  
  34.         "set -o xtrace ;"
  35.         "set -o errexit ;"
  36.         "brctl addbr br19 ;"
  37.         "brctl addif br19 tap19 ;"
  38.         "brctl addif br19 eno1 ;"
  39.         "brctl show ;"
  40.         "ifconfig tap19 promisc ;"
  41.         "ifconfig tap19 up ;"
  42.         "ifconfig br19 up ;"
  43.  
  44.         "read dummy ;" # wait
  45.  
  46.         # this is tricky (and nasty):
  47.         # we have to tell our session sshd instance to quit, and then
  48.         # busy-wait until we get SIGHUP from gthat sshd process back
  49.         # so our HUP trap handler function gets called
  50.         'kill -s INT ${PPID} ;'
  51.         'while true ; do sleep 0.1 ; done ;'
  52. )
  53.  
  54. ssh \
  55.         -o ExitOnForwardFailure=yes \
  56.         -o PermitLocalCommand=yes \
  57.         -o LocalCommand="ifconfig tap19 up" \
  58.         -o Tunnel=ethernet -w 19:19 \
  59.         root@10.49.20.202 \
  60.         "${sshcmds[*]}"
  61.  
  62. # cleanup
  63. # ...
  64.  
  65. # EOF.

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at