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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20