/[baselayout]/trunk/net.Linux/pppd.sh
Gentoo

Contents of /trunk/net.Linux/pppd.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2818 - (show annotations) (download) (as text)
Tue Aug 7 20:23:38 2007 UTC (6 years, 11 months ago) by uberlord
File MIME type: text/x-sh
File size: 5602 byte(s)
More pppd fixes
1 # Copyright 2005-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 pppd_depend() {
5 program /usr/sbin/pppd
6 after interface
7 before dhcp
8 provide ppp
9 }
10
11 is_ppp() {
12 [ -e /var/run/ppp-"${IFACE}".pid ]
13 }
14
15 requote() {
16 printf "'%s' " "$@"
17 }
18
19 pppd_pre_start() {
20 # Interface has to be called ppp
21 [ "${IFACE%%[0-9]*}" = "ppp" ] || return 0
22
23 if ${IN_BACKGROUND} ; then
24 local config=
25 eval config=\$config_${IFVAR}
26 # If no config for ppp then don't default to DHCP
27 if [ -z "${config}" ] ; then
28 eval config_${IFVAR}=null
29 fi
30 return 0
31 fi
32
33 local link= i= opts= unit="${IFACE#ppp}" mtu=
34
35 # PPP requires a link to communicate over - normally a serial port
36 # PPPoE communicates over Ethernet
37 # PPPoA communicates over ATM
38 # In all cases, the link needs to be available before we start PPP
39 eval link=\$link_${IFVAR}
40 [ -n "${link}" ] || return 0
41
42 case "${link}" in
43 /*)
44 if [ ! -e "${link}" ] ; then
45 eerror "${link} does not exist"
46 eerror "Please verify hardware or kernel module (driver)"
47 return 1
48 fi
49 ;;
50 esac
51
52 if [ -z "${unit}" ] ; then
53 eerror "PPP requires a unit - use net.ppp[0-9] instead of net.ppp"
54 return 1
55 fi
56
57 eval $(_get_array "pppd_${IFVAR}")
58 opts="$@"
59
60 local mtu= hasmtu=false hasmru=false hasmaxfail=false haspersist=false
61 local hasupdetach=false
62 for i in "$@" ; do
63 set -- ${i}
64 case "$1" in
65 unit|nodetach|linkname)
66 eerror "The option \"$1\" is not allowed in pppd_${IFVAR}"
67 return 1
68 ;;
69 mtu) hasmtu=true ;;
70 mru) hasmru=true ;;
71 maxfail) hasmaxfail=true ;;
72 persist) haspersist=true ;;
73 updetach) hasupdetach=true ;;
74 esac
75 done
76
77 # Might be set in conf.d/net
78 local username= password= passwordset=
79 eval username=\$username_${IFVAR}
80 eval password=\$password_${IFVAR}
81 eval passwordset=\$\{password_${IFVAR}-x\}
82 if [ -n "${username}" ] \
83 && [ -n "${password}" -o -z "${passwordset}" ] ; then
84 opts="${opts} plugin passwordfd.so passwordfd 0"
85 fi
86
87 if [ -n "${mtu}" ] ; then
88 ${hasmtu} || opts="${opts} mtu ${mtu}"
89 ${hasmru} || opts="${opts} mru ${mtu}"
90 fi
91 ${hasmaxfail} || opts="${opts} maxfail 0"
92 ${haspersist} || opts="${opts} persist"
93
94 # Set linkname because we need /var/run/ppp-${linkname}.pid
95 # This pidfile has the advantage of being there,
96 # even if ${IFACE} interface was never started
97 opts="linkname ${IFACE} ${opts}"
98
99 # Setup auth info
100 if [ -n "${username}" ] ; then
101 opts="user '${username}' remotename ${IFACE} ${opts}"
102 fi
103
104 # Load a custom interface configuration file if it exists
105 [ -f "/etc/ppp/options.${IFACE}" ] \
106 && opts="${opts} file /etc/ppp/options.${IFACE}"
107
108 # Set unit
109 opts="unit ${unit} ${opts}"
110
111 # Setup connect script
112 local chatopts="/usr/sbin/chat -e -E -v"
113 eval $(_get_array "phone_number_${IFVAR}")
114 [ -n "$1" ] && chatopts="${chatopts} -T '$1'"
115 [ -n "$2" ] && chatopts="${chatopts} -U '$2'"
116 eval $(_get_array "chat_${IFVAR}")
117 if [ $# != 0 ] ; then
118 opts="${opts} connect $(printf "\\'%s\\'" "${chatopts} $(printf "\\'\\\\'\\'%s\\'\\\'' " "$@")")"
119 fi
120
121 # Add plugins
122 local haspppoa=false haspppoe=false
123 eval $(_get_array "plugins_${IFVAR}")
124 for i in "$@" ; do
125 set -- ${i}
126 case "$1" in
127 passwordfd) continue;;
128 pppoa) shift; set -- "pppoatm" "$@" ;;
129 pppoe) shift; set -- "rp-pppoe" "$@" ;;
130 capi) shift; set -- "capiplugin" "$@" ;;
131 esac
132 case "$1" in
133 rp-pppoe) haspppoe=true ;;
134 pppoatm) haspppoa=true ;;
135 esac
136 if [ "$1" = "rp-pppoe" ] || [ "$1" = "pppoatm" -a "${link}" != "/dev/null" ] ; then
137 opts="${opts} connect true"
138 set -- "$@" "${link}"
139 fi
140 opts="${opts} plugin $1.so"
141 shift
142 opts="${opts} $@"
143 done
144
145 #Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi)
146 local insert_link_in_opts=1
147 if ${haspppoe} ; then
148 if [ ! -e /proc/net/pppoe ] ; then
149 # Load the PPPoE kernel module
150 if ! modprobe pppoe ; then
151 eerror "kernel does not support PPPoE"
152 return 1
153 fi
154 fi
155
156 # Ensure that the link exists and is up
157 ( IFACE="${link}" ; _exists true && _up ) || return 1
158 insert_link_in_opts=0
159 fi
160
161 if ${haspppoa} ; then
162 if [ ! -d /proc/net/atm ] ; then
163 # Load the PPPoA kernel module
164 if ! modprobe pppoatm ; then
165 eerror "kernel does not support PPPoATM"
166 return 1
167 fi
168 fi
169
170 if [ "${link}" != "/dev/null" ] ; then
171 insert_link_in_opts=0
172 else
173 ewarn "WARNING: An [itf.]vpi.vci ATM address was expected in link_${IFVAR}"
174 fi
175
176 fi
177 [ "${insert_link_in_opts}" = "0" ] || opts="${link} ${opts}"
178
179 ebegin "Starting pppd in ${IFACE}"
180 mark_service_inactive "${SVCNAME}"
181 if [ -n "${username}" ] \
182 && [ -n "${password}" -o -z "${passwordset}" ] ; then
183 printf "%s" "${password}" | \
184 eval start-stop-daemon --start --exec /usr/sbin/pppd \
185 --pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null
186 else
187 eval start-stop-daemon --start --exec /usr/sbin/pppd \
188 --pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null
189 fi
190
191 if ! eend $? "Failed to start PPP" ; then
192 mark_service_stopped "net.${IFACE}"
193 return 1
194 fi
195
196 if ${hasupdetach} ; then
197 _show_address
198 else
199 einfo "Backgrounding ..."
200 fi
201
202 # pppd will re-call us when we bring the interface up
203 exit 0
204 }
205
206 # Dummy function for users that still have config_ppp0="ppp"
207 pppd_start() {
208 return 0
209 }
210
211 pppd_stop() {
212 ${IN_BACKGROUND} && return 0
213 local pidfile="/var/run/ppp-${IFACE}.pid"
214
215 [ ! -s "${pidfile}" ] && return 0
216
217 # Give pppd at least 30 seconds do die, #147490
218 einfo "Stopping pppd on ${IFACE}"
219 start-stop-daemon --stop --quiet --exec /usr/sbin/pppd \
220 --pidfile "${pidfile}" --retry 30
221 eend $?
222 }
223
224 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20