pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 6d62140f by Anonymous on Thu 14th Apr 2022 14:40
original post a0b9b by Anonymous on Thu 14th Apr 2022 14:19
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
		"set +o errexit ;"
2323
		'(( 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
34+
	# tell NetworkManager NOT to touch the requested interface
3439
	"set -o xtrace ;"
3540
	"set -o errexit ;"
41+
3645
	"brctl addbr br19 ;"
46+
	"nonetmanage br19 ;"
3747
	"brctl addif br19 tap19 ;"
3848
	"brctl addif br19 eno1 ;"
3949
	"brctl show ;"
4050
	"ifconfig tap19 promisc ;"
4151
	"ifconfig tap19 up ;"
4252
	"ifconfig br19 up ;"
4353
4454
	"read dummy ;" # wait
4555
4656
	# this is tricky (and nasty):
4757
	# we have to tell our session sshd instance to quit, and then
4858
	# busy-wait until we get SIGHUP from gthat sshd process back
4959
	# so our HUP trap handler function gets called
5060
	'kill -s INT ${PPID} ;'
5161
	'while true ; do sleep 0.1 ; done ;'
5262
)
5363
5464
ssh \
5565
	-o ExitOnForwardFailure=yes \
5666
	-o PermitLocalCommand=yes \
5767
	-o LocalCommand="ifconfig tap19 up" \
5868
	-o Tunnel=ethernet -w 19:19 \
5969
	root@10.49.20.202 \
6070
	"${sshcmds[*]}"
6171
6272
# cleanup
6373
# ...
6474
6575
# EOF.
6676

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