blob: 88dd15ca58c1285b83c3ca0bd7973949b9f8a797
1 | #!/bin/sh |
2 | # ../scripts/pppoe-connect. Generated from pppoe-connect.in by configure. |
3 | #*********************************************************************** |
4 | # |
5 | # pppoe-connect |
6 | # |
7 | # Shell script to connect to a PPPoE provider |
8 | # |
9 | # Copyright (C) 2000 Roaring Penguin Software Inc. |
10 | # |
11 | # $Id$ |
12 | # |
13 | # This file may be distributed under the terms of the GNU General |
14 | # Public License. |
15 | # |
16 | # LIC: GPL |
17 | # |
18 | # Usage: pppoe-connect [config_file] |
19 | # pppoe-connect interface user [config_file] |
20 | # Second form overrides USER and ETH from config file. |
21 | # If config_file is omitted, defaults to /etc//ppp/pppoe.conf |
22 | # |
23 | #*********************************************************************** |
24 | |
25 | # From AUTOCONF |
26 | prefix=/usr |
27 | exec_prefix=${prefix} |
28 | localstatedir=/var |
29 | |
30 | # Paths to programs |
31 | IFCONFIG=/sbin/ifconfig |
32 | PPPD=pppd |
33 | SETSID=/usr/bin/setsid |
34 | PPPOE=${exec_prefix}/sbin/pppoe |
35 | LOGGER="/usr/bin/logger -t `basename $0`" |
36 | |
37 | # Set to "C" locale so we can parse messages from commands |
38 | LANG=C |
39 | export LANG |
40 | |
41 | # Must be root |
42 | if test "`/usr/bin/id -u`" != 0 ; then |
43 | echo "$0: You must be root to run this script" >& 2 |
44 | exit 1 |
45 | fi |
46 | |
47 | if test "$SETSID" != "" -a ! -x "$SETSID"; then |
48 | SETSID="" |
49 | fi |
50 | |
51 | CONFIG=/etc//ppp/pppoe.conf |
52 | USER="" |
53 | ETH="" |
54 | |
55 | # Sort out command-line arguments |
56 | case "$#" in |
57 | 1) |
58 | CONFIG="$1" |
59 | ;; |
60 | 3) |
61 | CONFIG="$3" |
62 | ;; |
63 | esac |
64 | |
65 | if test ! -f "$CONFIG" -o ! -r "$CONFIG" ; then |
66 | echo "$0: Cannot read configuration file '$CONFIG'" >& 2 |
67 | exit 1 |
68 | fi |
69 | export CONFIG |
70 | . $CONFIG |
71 | |
72 | PPPOE_PIDFILE="$PIDFILE.pppoe" |
73 | PPPD_PIDFILE="$PIDFILE.pppd" |
74 | |
75 | # Check for command-line overriding of ETH and USER |
76 | case "$#" in |
77 | 2|3) |
78 | ETH="$1" |
79 | USER="$2" |
80 | ;; |
81 | esac |
82 | |
83 | # Check that config file is sane |
84 | if test "$USER" = "" ; then |
85 | echo "$0: Check '$CONFIG' -- no setting for USER" >& 2 |
86 | exit 1 |
87 | fi |
88 | if test "$ETH" = "" ; then |
89 | echo "$0: Check '$CONFIG' -- no setting for ETH" >& 2 |
90 | exit 1 |
91 | fi |
92 | |
93 | PPPD_PID=0 |
94 | |
95 | # Catch common error |
96 | if test "$DEBUG" = "1" ; then |
97 | echo "*** If you want to use DEBUG, invoke pppoe-start, not pppoe-connect." |
98 | exit 1 |
99 | fi |
100 | |
101 | if test "$DEBUG" != "" ; then |
102 | if test "$LINUX_PLUGIN" != "" ; then |
103 | echo "Cannot use DEBUG mode and LINUX_PLUGIN at the same time." |
104 | echo "Kernel-mode PPPoE is experimental and unsupported." |
105 | exit 1 |
106 | fi |
107 | echo "* The following section identifies your Ethernet interface" >> $DEBUG |
108 | echo "* and user name. Some ISP's need 'username'; others" >> $DEBUG |
109 | echo "* need 'username@isp.com'. Try both" >> $DEBUG |
110 | echo "ETH=$ETH; USER=$USER" >> $DEBUG |
111 | echo "---------------------------------------------" >> $DEBUG |
112 | fi |
113 | |
114 | # MTU of Ethernet card attached to modem MUST be 1500. This apparently |
115 | # fails on some *BSD's, so we'll only do it under Linux |
116 | |
117 | if test `uname -s` = Linux ; then |
118 | $IFCONFIG $ETH up mtu 1500 |
119 | # For 2.4 kernels. Will fail on 2.2.x, but who cares? |
120 | modprobe ppp_generic > /dev/null 2>&1 |
121 | modprobe ppp_async > /dev/null 2>&1 |
122 | modprobe ppp_synctty > /dev/null 2>&1 |
123 | if test -n "$LINUX_PLUGIN" ; then |
124 | modprobe pppox > /dev/null 2>&1 |
125 | modprobe pppoe > /dev/null 2>&1 |
126 | fi |
127 | fi |
128 | |
129 | if test "$SYNCHRONOUS" = "yes" ; then |
130 | PPPOE_SYNC=-s |
131 | PPPD_SYNC=sync |
132 | # Increase the chances of it working on Linux... |
133 | if test `uname -s` = Linux ; then |
134 | modprobe n_hdlc > /dev/null 2>&1 |
135 | fi |
136 | else |
137 | PPPOE_SYNC="" |
138 | PPPD_SYNC="" |
139 | fi |
140 | |
141 | if test -n "$ACNAME" ; then |
142 | ACNAME="-C $ACNAME" |
143 | fi |
144 | |
145 | if test -n "$SERVICENAME" ; then |
146 | SERVICENAMEOPT="-S $SERVICENAME" |
147 | else |
148 | SERVICENAMEOPT="" |
149 | fi |
150 | |
151 | if test "$CLAMPMSS" = "no" ; then |
152 | CLAMPMSS="" |
153 | else |
154 | CLAMPMSS="-m $CLAMPMSS" |
155 | fi |
156 | |
157 | # If DNSTYPE is SERVER, we must use "usepeerdns" option to pppd. |
158 | if test "$DNSTYPE" = "SERVER" ; then |
159 | PEERDNS=yes |
160 | USEPEERDNS=yes |
161 | fi |
162 | |
163 | if test "$PEERDNS" = "yes" ; then |
164 | PEERDNS="usepeerdns" |
165 | else |
166 | PEERDNS="" |
167 | fi |
168 | |
169 | # Backward config file compatibility -- PEERDNS used to be USEPEERDNS |
170 | if test "$USEPEERDNS" = "yes" ; then |
171 | PEERDNS="usepeerdns" |
172 | fi |
173 | if test "$USEPEERDNS" = "no" ; then |
174 | PEERDNS="" |
175 | fi |
176 | |
177 | |
178 | # Backward config file compatibility |
179 | if test "$DEMAND" = "" ; then |
180 | DEMAND=no |
181 | fi |
182 | |
183 | if test "$DEMAND" = "no" ; then |
184 | DEMAND="" |
185 | else |
186 | DEMAND="demand persist idle $DEMAND 10.112.112.112:10.112.112.113 ipcp-accept-remote ipcp-accept-local connect true noipdefault ktune" |
187 | fi |
188 | |
189 | case "$FIREWALL" in |
190 | STANDALONE) |
191 | . /etc/ppp/firewall-standalone |
192 | ;; |
193 | MASQUERADE) |
194 | . /etc/ppp/firewall-masq |
195 | ;; |
196 | esac |
197 | |
198 | # If we're using kernel-mode PPPoE on Linux... |
199 | if test "$LINUX_PLUGIN" != "" ; then |
200 | PLUGIN_OPTS="plugin $LINUX_PLUGIN nic-$ETH" |
201 | if test -n "$SERVICENAME" ; then |
202 | PLUGIN_OPTS="$PLUGIN_OPTS rp_pppoe_service $SERVICENAME" |
203 | fi |
204 | modprobe pppoe > /dev/null 2>&1 |
205 | fi |
206 | |
207 | if test "$DEFAULTROUTE" != "no" ; then |
208 | DEFAULTROUTE="defaultroute" |
209 | else |
210 | DEFAULTROUTE="" |
211 | fi |
212 | |
213 | # Standard PPP options we always use |
214 | PPP_STD_OPTIONS="$PLUGIN_OPTS noipdefault noauth default-asyncmap $DEFAULTROUTE hide-password nodetach $PEERDNS mtu 1492 mru 1492 noaccomp nodeflate nopcomp novj novjccomp user $USER lcp-echo-interval $LCP_INTERVAL lcp-echo-failure $LCP_FAILURE $PPPD_EXTRA" |
215 | |
216 | # Jigger DNS if required... |
217 | if test "$DNSTYPE" = "SERVER" ; then |
218 | # Sorry, dude... |
219 | rm -f /etc/resolv.conf |
220 | ln -s /etc/ppp/resolv.conf /etc/resolv.conf |
221 | elif test "$DNSTYPE" = "SPECIFY" ; then |
222 | # Sorry, dude... |
223 | rm -f /etc/resolv.conf |
224 | echo "nameserver $DNS1" > /etc/resolv.conf |
225 | if test -n "$DNS2" ; then |
226 | echo "nameserver $DNS2" >> /etc/resolv.conf |
227 | fi |
228 | fi |
229 | |
230 | # PPPoE invocation |
231 | PPPOE_CMD="$PPPOE -p $PPPOE_PIDFILE -I $ETH -T $PPPOE_TIMEOUT -U $PPPOE_SYNC $CLAMPMSS $ACNAME $SERVICENAMEOPT $PPPOE_EXTRA" |
232 | if test "$DEBUG" != "" ; then |
233 | if test "$DEMAND" != "" ; then |
234 | echo "(Turning off DEMAND for debugging purposes)" |
235 | DEMAND="" |
236 | fi |
237 | echo "* The following section shows the pppd command we will invoke" >> $DEBUG |
238 | echo "pppd invocation" >> $DEBUG |
239 | echo "$SETSID $PPPD pty '$PPPOE_CMD' $PPP_STD_OPTIONS $PPPD_SYNC debug" >> $DEBUG |
240 | echo "---------------------------------------------" >> $DEBUG |
241 | $SETSID $PPPD pty "$PPPOE_CMD -D $DEBUG-0" \ |
242 | $PPP_STD_OPTIONS \ |
243 | $PPPD_SYNC \ |
244 | debug >> $DEBUG 2>&1 |
245 | echo "---------------------------------------------" >> $DEBUG |
246 | echo "* The following section is an extract from your log." >> $DEBUG |
247 | echo "* Look for error messages from pppd, such as" >> $DEBUG |
248 | echo "* a lack of kernel support for PPP, authentication failure" >> $DEBUG |
249 | echo "* etc." >> $DEBUG |
250 | if test -f "/var/log/messages" ; then |
251 | echo "Extract from /var/log/messages" >> $DEBUG |
252 | grep 'ppp' /var/log/messages | tail -150 >> $DEBUG |
253 | elif test -f "/var/adm/messages"; then |
254 | echo "Extract from /var/adm/messages" >> $DEBUG |
255 | grep 'ppp' /var/adm/messages | tail -150 >> $DEBUG |
256 | else |
257 | echo "Can't find messages file (looked for /var/{log,adm}/messages" >> $DEBUG |
258 | fi |
259 | date >> $DEBUG |
260 | echo "---------------------------------------------" >> $DEBUG |
261 | echo "* The following section is a dump of the packets" >> $DEBUG |
262 | echo "* sent and received by rp-pppoe. If you don't see" >> $DEBUG |
263 | echo "* any output, it's an Ethernet driver problem. If you only" >> $DEBUG |
264 | echo "* see three PADI packets and nothing else, check your cables" >> $DEBUG |
265 | echo "* and modem. Make sure the modem lights flash when you try" >> $DEBUG |
266 | echo "* to connect. Check that your Ethernet card is in" >> $DEBUG |
267 | echo "* half-duplex, 10Mb/s mode. If all else fails," >> $DEBUG |
268 | echo "* try using pppoe-sniff." >> $DEBUG |
269 | echo "rp-pppoe debugging dump" >> $DEBUG |
270 | cat $DEBUG-0 >> $DEBUG |
271 | rm -f $DEBUG-0 |
272 | for i in 1 2 3 4 5 6 7 8 9 10 ; do |
273 | echo "" |
274 | echo "" |
275 | echo "" |
276 | done |
277 | echo "*** Finished debugging run. Please review the file" |
278 | echo "*** '$DEBUG' and try to" |
279 | echo "*** figure out what is going on." |
280 | echo "***" |
281 | echo "*** Unfortunately, we can NO LONGER accept debugging" |
282 | echo "*** output for analysis. Please do not send this to" |
283 | echo "*** Roaring Penguin; it is too time-consuming for" |
284 | echo "*** us to deal with all the analyses we have been sent." |
285 | exit 0 |
286 | fi |
287 | |
288 | echo $$ > $PIDFILE |
289 | |
290 | while [ true ] ; do |
291 | if test "$OVERRIDE_PPPD_COMMAND" != "" ; then |
292 | $SETSID $OVERRIDE_PPPD_COMMAND & |
293 | echo "$!" > $PPPD_PIDFILE |
294 | elif test "$LINUX_PLUGIN" != "" ; then |
295 | $SETSID $PPPD $PPP_STD_OPTIONS $DEMAND & |
296 | echo "$!" > $PPPD_PIDFILE |
297 | else |
298 | $SETSID $PPPD pty "$PPPOE_CMD" \ |
299 | $PPP_STD_OPTIONS \ |
300 | $DEMAND \ |
301 | $PPPD_SYNC & |
302 | echo "$!" > $PPPD_PIDFILE |
303 | fi |
304 | wait |
305 | |
306 | if test "$RETRY_ON_FAILURE" = "no" ; then |
307 | exit |
308 | fi |
309 | |
310 | # Run /etc/ppp/pppoe-lost if it exists |
311 | test -x /etc/ppp/pppoe-lost && /etc/ppp/pppoe-lost |
312 | |
313 | # Re-establish the connection |
314 | $LOGGER -p daemon.notice \ |
315 | "PPPoE connection lost; attempting re-connection." |
316 | |
317 | # Wait a bit in case a problem causes tons of log messages :-) |
318 | sleep 5 |
319 | done |
320 |