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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Sep 3 16:10:27 2005 UTC (8 years, 10 months ago) by hollow
File size: 2652 byte(s)
import initial baselayout sources (1.12.0_pre8)
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 # char* tuntap_provides(void)
14 #
15 # Returns a string to change module definition for starting up
16 tuntap_provides() {
17 echo "tuntap"
18 }
19
20 # void tuntap_depend(void)
21 #
22 # Sets up the dependancies for the module
23 tuntap_depend() {
24 after interface
25 before dhcp
26 }
27
28 # bool tuntap_check_installed(void)
29 #
30 # Returns 1 if tuntap is installed, otherwise 0
31 tuntap_check_installed() {
32 [[ -x /usr/bin/tunctl ]] && return 0
33 ${1:-false} && eerror "For TunTap support, emerge sys-apps/usermode-utilities"
34 return 1
35 }
36
37 # bool tuntap_check_depends(void)
38 #
39 # Checks to see if we have the needed functions
40 tuntap_check_depends() {
41 local f
42
43 for f in interface_exists interface_type; do
44 [[ $( type -t "${f}" ) == "function" ]] && continue
45 eerror "tuntap: missing required function ${f}\n"
46 return 1
47 done
48
49 return 0
50 }
51
52 # bool tuntap_check_kernel(void)
53 #
54 # Checks to see if the tun is present - if not try and load it
55 # Returns 1 if there is a problem
56 tuntap_check_kernel() {
57 [[ -a /dev/net/tun ]] && return 0
58 /sbin/modprobe tun && sleep 1
59 [[ -a /dev/net/tun ]] && return 0
60 eerror "TUN/TAP support is not present in this kernel"
61 return 1
62 }
63
64 # char* tuntap_get_vars(char *interface)
65 #
66 # Returns a string spaced with possible user set
67 # configuration variables
68 tuntap_get_vars() {
69 echo "tunctl_$1"
70 }
71
72 # bool tuntap_pre_start(char *iface)
73 #
74 # Create the device, give it the right perms
75 tuntap_pre_start() {
76 local iface="$1" opts ifvar=$( bash_variable "$1" )
77 local itype=$( interface_type "${iface}" )
78
79 # Check that we are a valid tun/tap interface
80 # NOTE - the name can be anything as we define it
81 # but for simplicity in the config we require either
82 # tun or tap
83 [[ ${itype} != "tun" && ${itype} != "tap" ]] && return 0
84
85 tuntap_check_kernel || return 1
86
87 # Get our options
88 eval opts=\"\$\{tunctl_${ifvar}\}\"
89
90 ebegin "Creating Tun/Tap interface ${iface}"
91 tunctl ${opts} -t "${iface}"
92 eend "$?" || return 1
93
94 return 0
95 }
96
97 # bool tuntap_stop(char *iface)
98 #
99 # Removes the device
100 tuntap_stop() {
101 local iface="$1"
102
103 tuntap_check_installed || return 0
104 interface_exists "${iface}" || return 0
105
106 # tunctl doesn't always error on on tun/tap
107 # interfaces (mainly aliases, etc)
108 if tunctl -d "${iface}" &>/dev/null ; then
109 interface_exists "${iface}" \
110 || einfo "Destroyed Tun/Tap interface ${iface}"
111 fi
112
113 return 0
114 }
115
116 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20