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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20