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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2628 - (show annotations) (download) (as text)
Thu Apr 19 12:09:19 2007 UTC (7 years, 8 months ago) by uberlord
File MIME type: text/x-sh
File size: 5401 byte(s)
no need for the sed using printf
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 ${IN_BACKGROUND} && return 0
21
22 # Interface has to be called ppp
23 [ "${IFACE%%[0-9]*}" = "ppp" ] || return 0
24
25 local link= i= opts= unit="${IFACE#ppp}" mtu=
26
27 # 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 [ -n "${link}" ] || return 0
33
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 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 eval $(_get_array "pppd_${IFVAR}")
50 opts="$@"
51
52 local mtu= hasmtu=false hasmru=false hasmaxfail=false haspersits=false
53 local hasupdetach=false
54 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 mtu) hasmtu=true ;;
62 mru) hasmru=true ;;
63 maxfail) hasmaxfail=true ;;
64 persist) haspersist=true ;;
65 updetach) hasupdetach=true;
66 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 if [ -n "${mtu}" ] ; then
80 ${hasmtu} || opts="${opts} mtu ${mtu}"
81 ${hasmru} || opts="${opts} mru ${mtu}"
82 fi
83 ${hasmailfail} || opts="${opts} maxfail 0"
84 ${haspersist} || opts="${opts} persist"
85
86 # Set linkname because we need /var/run/ppp-${linkname}.pid
87 # This pidfile has the advantage of being there,
88 # even if ${IFACE} interface was never started
89 opts="linkname ${IFACE} ${opts}"
90
91 # Setup auth info
92 if [ -n "${username}" ] ; then
93 opts="user '${username}' remotename ${IFACE} ${opts}"
94 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 case "$1" in
119 passwordfd) continue;;
120 pppoa) shift; set -- "pppoatm" "$@" ;;
121 pppoe) shift; set -- "rp-pppoe" "$@" ;;
122 capi) shift; set -- "capiplugin" "$@" ;;
123 esac
124 case "$1" in
125 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 [ "${insert_link_in_opts}" = "0" ] || opts="${link} ${opts}"
170
171 ebegin "Starting pppd in ${IFACE}"
172 mark_service_inactive "${SVCNAME}"
173 if [ -n "${username}" ] \
174 && [ -n "${password}" -o -z "${passwordset}" ] ; then
175 printf "%s" "${password}" | \
176 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 if ! eend $? "Failed to start PPP" ; then
184 mark_service_starting "net.${IFACE}"
185 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 # Dummy function for users that still have config_ppp0="ppp"
199 pppd_start() {
200 return 0
201 }
202
203 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