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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20