summaryrefslogtreecommitdiffstats
path: root/init.d/tuntap
blob: 667acb917fcb5cff80c17e7fe3cc3a0416fbf3de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/sbin/runscript

OPENVPN=`which openvpn 2>/dev/null`
TUNCTL=`which tunctl 2>/dev/null`

if [ -x "$OPENVPN" ] ; then
	CREATETAP="$OPENVPN --mktun --dev"
else
	CREATETAP="$TUNCTL -t"
fi
	

start() {
	# verify tun/tap support in kernel
	if ! [ -e /dev/net/tun ] ; then
		modprobe tun 2>&1 >/dev/null && sleep 1
		if ! [ -e /dev/net/tun ] ; then
			eerror "Tun/Tap support is not present in kernel"
			return 1
		fi
	fi

	# verify if openvpn is present
	if [ -x "$OPENVPN" ] ; then
		MKTUNTAP="$OPENVPN --mktun --dev"
	elif [ -x "$TUNCTL" ] ; then
		MKTUNTAP="$TUNCTL -t"
	else
		eerror "Needs openvpn or tunctl to create Tun/Tap devices"
		return 1
	fi
	
	# create devices
	for iface in $DEVICES ; do
		ebegin "Creating Tun/Tap interface $iface"
		$MKTUNTAP  $iface >/dev/null
		eend $?
	done
}

stop() {
	ebegin "Destroying Tun/Tap interfaces"
	rmmod tun 2>/dev/null
	eend $?
}