Difference between
modified post b462550ed3 by Anonymous on Thu 14th Apr 2022 13:48
original post fad4 by Anonymous on Thu 14th Apr 2022 13:32
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 | 22 | '(( trap_once++ > 0 )) && return 0 ;' | |
| 23 | 23 | "set +o errexit ;" | |
| 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 | + | "exit 0 ;" | |
| 29 | 30 | "} ;" | |
| 30 | 31 | 'trap netcleanup EXIT ;' | |
| 31 | 32 | 'trap netcleanup HUP ;' | |
| 32 | 33 | ||
| 33 | 34 | "set -o xtrace ;" | |
| 34 | 35 | "set -o errexit ;" | |
| 35 | 36 | "brctl addbr br19 ;" | |
| 36 | 37 | "brctl addif br19 tap19 ;" | |
| 37 | 38 | "brctl addif br19 eno1 ;" | |
| 38 | 39 | "brctl show ;" | |
| 39 | 40 | "ifconfig tap19 promisc ;" | |
| 40 | 41 | "ifconfig tap19 up ;" | |
| 41 | 42 | "ifconfig br19 up ;" | |
| 42 | 43 | ||
| 43 | - | "read dummy ;" # dummy wait | |
| 44 | + | "read dummy ;" # wait | |
| 44 | 45 | ||
| 45 | - | 'kill -s HUP -${PPID} ;' | |
| 46 | + | # this is nasty: | |
| 47 | + | # we have to tell sshd to quit, and then busy-wait | |
| 46 | 52 | ) | |
| 47 | 53 | ||
| 48 | 54 | ssh \ | |
| 49 | 55 | -o ExitOnForwardFailure=yes \ | |
| 50 | 56 | -o PermitLocalCommand=yes \ | |
| 51 | 57 | -o LocalCommand="ifconfig tap19 up" \ | |
| 52 | 58 | -o Tunnel=ethernet -w 19:19 \ | |
| 53 | 59 | root@10.49.20.202 \ | |
| 54 | 60 | "${sshcmds[*]}" | |
| 55 | 61 | ||
| 56 | 62 | # cleanup | |
| 57 | 63 | # ... | |
| 58 | 64 | ||
| 59 | 65 | # EOF. | |
| 60 | 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