/[vps]/baselayout-vserver/trunk/net-scripts/net.modules.d/tuntap
Gentoo

Contents of /baselayout-vserver/trunk/net-scripts/net.modules.d/tuntap

Parent Directory Parent Directory | Revision Log Revision Log


Revision 236 - (show annotations) (download)
Tue Feb 14 13:00:44 2006 UTC (8 years, 10 months ago) by phreak
File size: 2255 byte(s)
Merging r1881
1 #!/bin/bash
2 # Copyright (c) 2004-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # Fix any potential localisation problems
8 # Note that LC_ALL trumps LC_anything_else according to locale(7)
9 tunctl() {
10 LC_ALL=C /usr/bin/tunctl "$@"
11 }
12
13 # void tuntap_depend(void)
14 #
15 # Sets up the dependancies for the module
16 tuntap_depend() {
17 before interface macchanger
18 functions interface_exists interface_type
19 variables tunctl
20 }
21
22 # bool tuntap_check_installed(void)
23 #
24 # Returns 1 if tuntap is installed, otherwise 0
25 tuntap_check_installed() {
26 [[ -x /usr/bin/tunctl ]] && return 0
27 ${1:-false} && eerror "For TunTap support, emerge sys-apps/usermode-utilities"
28 return 1
29 }
30
31 # bool tuntap_check_kernel(void)
32 #
33 # Checks to see if the tun is present - if not try and load it
34 # Returns 1 if there is a problem
35 tuntap_check_kernel() {
36 [[ -a /dev/net/tun ]] && return 0
37 /sbin/modprobe tun && sleep 1
38 [[ -a /dev/net/tun ]] && return 0
39 eerror "TUN/TAP support is not present in this kernel"
40 return 1
41 }
42
43 # bool tuntap_exists(char *interface)
44 #
45 # Returns 0 if the tun/tap interface exists, otherwise 1
46 tuntap_exists() {
47 tunctl -d "$1" &>/dev/null
48 }
49
50 # bool tuntap_pre_start(char *iface)
51 #
52 # Create the device, give it the right perms
53 tuntap_pre_start() {
54 local iface="$1" opts ifvar=$( bash_variable "$1" )
55 local itype=$( interface_type "${iface}" )
56
57 # Check that we are a valid tun/tap interface
58 # NOTE - the name can be anything as we define it
59 # but for simplicity in the config we require either
60 # tun or tap
61 [[ ${itype} != "tun" && ${itype} != "tap" ]] && return 0
62
63 tuntap_check_kernel || return 1
64
65 # Get our options
66 opts="tunctl_${ifvar}"
67
68 ebegin "Creating Tun/Tap interface ${iface}"
69 tunctl ${!opts} -t "${iface}" >/dev/null
70 eend "$?" || return 1
71
72 return 0
73 }
74
75 # bool tuntap_stop(char *iface)
76 #
77 # Removes the device
78 tuntap_stop() {
79 local iface="$1"
80
81 tuntap_check_installed || return 0
82 interface_exists "${iface}" || return 0
83
84 # tunctl doesn't always error on on tun/tap
85 # interfaces (mainly aliases, etc)
86 if tuntap_exists "${iface}" ; then
87 interface_exists "${iface}" \
88 || einfo "Destroyed Tun/Tap interface ${iface}"
89 fi
90
91 return 0
92 }
93
94 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20