pastebin - collaborative debugging tool
rovema.kpaste.net RSS

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

    
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() { "
22-
		'(( trap_once++ > 0 )) && return 0 ;'
2322
		"set +o errexit ;"
23+
		'(( trap_once++ > 0 )) && return 0 ;'
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
4646
	# this is tricky (and nasty):
4747
	# we have to tell our session sshd instance to quit, and then
4848
	# busy-wait until we get SIGHUP from gthat sshd process back
4949
	# so our HUP trap handler function gets called
5050
	'kill -s INT ${PPID} ;'
5151
	'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