pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 506718daeb by Anonymous on Thu 14th Apr 2022 14:05
original post b462550ed3 by Anonymous on Thu 14th Apr 2022 13:48
Download diff
Show old version | new version | both versions

    
11
#!/usr/bin/ksh93
22
33
#
44
# Ethernet/tap forwarding via ssh
55
#
66
77
set -o xtrace
88
set -o errexit
99
set -o nounset
1010
1111
# list of commands our ssh session should execute
1212
typeset -a sshcmds=(
1313
	#
1414
	# cleanup:
1515
	#
1616
	# we need to clean up the bridge interface ourselves, if
1717
	# we do not do that we risk getting that any subsequent
1818
	# ifconfig/ip/etc command hangs
1919
	#
2020
	'(( trap_once=0 )) ;'
2121
	"netcleanup() { "
2222
		'(( trap_once++ > 0 )) && return 0 ;'
2323
		"set +o errexit ;"
2424
		"brctl delif br19 tap19 ;"
2525
		"brctl delif br19 eno1 ;"
2626
		"ifconfig tap19 down ;"
2727
		"ifconfig br19 down ;"
2828
		"brctl delbr br19 ;"
2929
		"exit 0 ;"
3030
	"} ;"
3131
	'trap netcleanup EXIT ;'
3232
	'trap netcleanup HUP ;'
3333
3434
	"set -o xtrace ;"
3535
	"set -o errexit ;"
3636
	"brctl addbr br19 ;"
3737
	"brctl addif br19 tap19 ;"
3838
	"brctl addif br19 eno1 ;"
3939
	"brctl show ;"
4040
	"ifconfig tap19 promisc ;"
4141
	"ifconfig tap19 up ;"
4242
	"ifconfig br19 up ;"
4343
4444
	"read dummy ;" # wait
4545
46-
	# this is nasty:
46+
	# this is tricky (and nasty):
47-
	# we have to tell sshd to quit, and then busy-wait
47+
	# we have to tell our session sshd instance to quit, and then
48-
	# until we get SIGHUP so our HUP trap handler
48+
	# busy-wait until we get SIGHUP from gthat sshd process back
49-
	# function gets called
49+
	# so our HUP trap handler function gets called
5050
	'kill -s INT ${PPID} ;'
51-
	'while true ; do sleep 1 ; done ;'
51+
	'while true ; do sleep 0.1 ; done ;'
5252
)
5353
5454
ssh \
5555
	-o ExitOnForwardFailure=yes \
5656
	-o PermitLocalCommand=yes \
5757
	-o LocalCommand="ifconfig tap19 up" \
5858
	-o Tunnel=ethernet -w 19:19 \
5959
	root@10.49.20.202 \
6060
	"${sshcmds[*]}"
6161
6262
# cleanup
6363
# ...
6464
6565
# EOF.
6666

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