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