ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/tunconfig
Revision: 1.1
Committed: 2004-05-09T16:11:45Z (20 years, 2 months ago) by gbeauche
Branch: MAIN
Log Message:
TUN/TAP support

File Contents

# Content
1 #!/bin/bash
2 ###########################################################################
3 # Configuration of the tunN devices for usage with Basilisk II.
4 # (derived MOL tunconfig script)
5 #
6 # This script should be named /usr/share/BasiliskII/tunconfig (unless
7 # the default name has been changed with the 'etherconfig' keyword).
8 #
9 # Usage: tunconfig iface up|down
10 #
11 # If the linux box is configured as a firewall, the rules below might
12 # need some adjustments.
13 #
14 ###########################################################################
15
16 SUDO=/usr/bin/sudo
17 IPTABLES=/sbin/iptables
18
19 #########################################################
20
21 TUN_DEV=$1
22 ACTION=$2
23
24 TUN_NUM=`echo $TUN_DEV | sed s/[^0-9]//g`
25 NET_NUM=`expr 40 + $TUN_NUM`
26 TUN_NET=172.20.$NET_NUM.0/24
27 TUN_HOST=172.20.$NET_NUM.1
28
29 #########################################################
30 # Misc Checks
31 #########################################################
32
33 [[ $# = 2 ]] || {
34 echo "Usage: tunconfig iface up|down"
35 exit 2
36 }
37
38 [[ "`id -u`" = "0" ]] && {
39 echo "---> $SUDO not necessary." 1>&2
40 SUDO=""
41 }
42
43 [[ -x $IPTABLES ]] && {
44 IPTABLES="$SUDO $IPTABLES"
45 } || {
46 echo "---> $IPTABLES not found." 1>&2
47 IPTABLES=/bin/true
48 }
49
50 $IPTABLES -L -n -t nat > /dev/null || exit 1
51
52 #########################################################
53 # Remove old (possibly stale) ruleset
54 #########################################################
55
56 {
57 $IPTABLES -t nat -D POSTROUTING -s $TUN_NET -d ! $TUN_NET -j MASQUERADE
58 } >& /dev/null
59
60 #########################################################
61 # Bring down interface
62 #########################################################
63
64 [[ "$ACTION" = down ]] && {
65 $SUDO /sbin/ifconfig $TUN_DEV down
66 }
67
68 #########################################################
69 # Configure interface
70 #########################################################
71
72 [[ "$ACTION" = up ]] && {
73 $SUDO /sbin/ifconfig $TUN_DEV $TUN_HOST
74
75 # masquerade the tun network
76 $IPTABLES -t nat -A POSTROUTING -s $TUN_NET -d ! $TUN_NET -j MASQUERADE
77 }
78
79 exit 0