]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/rc.d/rc.connectioncheck
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[people/teissler/ipfire-2.x.git] / src / rc.d / rc.connectioncheck
1 #!/bin/bash
2 #
3 # $Id: rc.connectioncheck,v 1.4.2.22 2005/07/07 20:11:58 franck78 Exp $
4 #
5
6 eval $(/usr/local/bin/readhash CONFIG_ROOT/ppp/settings)
7
8 # MAXRETRIES is now a count before rc.red clear and if reconnection fail, eventually switching to a backup profil
9 MAXCONFIGURE=160
10 if [ ! $HOLDOFF ]; then
11 HOLDOFF=30
12 fi
13
14 # Debugging. Comment it out to stop logging
15 DEBUG="yes"
16 msg() {
17 if [ "z$DEBUG" != "z" ] ; then
18 /usr/bin/logger -t red "Connectioncheck: $*"
19 fi
20 /bin/echo "$*"
21 }
22
23 if [ -s "CONFIG_ROOT/red/keepconnected" ]; then
24 ATTEMPTS=$(/bin/cat CONFIG_ROOT/red/keepconnected)
25 else
26 echo "0" > CONFIG_ROOT/red/keepconnected
27 fi
28
29 case "$1" in
30 start)
31 # waiting pppd start or sync timout set at 90 s when available in driver
32 #rc.eciadsl/eci-load2 timout after 60s and 5 eci-load2 maximum attempts are done in rc.eciadsl.
33 #So just wait 5 s after 'rc.red start' end where pppd should have been started
34 TIMETOSTART=0
35 while ( ! /bin/ps ax | /bin/grep -q [p]ppd ); do
36 if [ ! -e "CONFIG_ROOT/red/keepconnected" ]; then
37 # user pressed disconnect in gui
38 exit 0
39 fi
40 RCREDSTART=`/bin/ps ax | /bin/grep '[r]c.red start'`
41 if [ "$TIMETOSTART" -eq 1 ]; then
42 msg "fail before pppd start : no sync, trying again"
43 /etc/rc.d/rc.red stop
44 /etc/rc.d/rc.red clear
45 /etc/rc.d/rc.red start
46 exit
47 fi
48 # give 5 s more at pppd to be visible with ps ax after 'rc.red start' end
49 if [ "$RCREDSTART" = '' ]; then
50 TIMETOSTART=1
51 fi
52 /bin/sleep 5
53 done
54
55 #watching if an IP is received in $MAXCONFIGURE time to avoid some pppoa waiting forever even after LCP timeout
56 COUNT=0
57 while [ "$COUNT" -le "$MAXCONFIGURE" ]; do
58 if [ ! -e "CONFIG_ROOT/red/keepconnected" ]; then
59 # user pressed disconnect in gui
60 exit 0
61 fi
62 if [ -e "CONFIG_ROOT/red/active" ]; then
63 # connected in time so exit
64 echo "0" > CONFIG_ROOT/red/keepconnected
65 exit 0
66 fi
67 if [ -e "CONFIG_ROOT/red/dial-on-demand" ]; then
68 # Don't count time when dial-on-demand is not really connected
69 if ( ! /sbin/ifconfig | /bin/grep -q addr:10.64.64.64 ); then
70 (( COUNT += 5 ))
71 fi
72 else
73 (( COUNT += 5 ))
74 fi
75 if ( ! /bin/ps ax | /bin/grep -q [p]ppd ); then
76 #pppd exit, so don't need to wait MAXCONFIGURE
77 break
78 fi
79 /bin/sleep 5
80 done
81 msg "RED fail to connect"
82 RCREDSTART=`/bin/ps ax | /bin/grep '[r]c.red start' | /usr/bin/cut -f1 -d ' '`
83 if [ "$RCREDSTART" != '' ]; then
84 /bin/kill "$RCREDSTART"
85 fi
86 # this attempt to connect fail, so retry
87
88 #Don't erase keepconnected because it is used to watch user actions
89 /bin/touch CONFIG_ROOT/red/redial
90 /etc/rc.d/rc.red stop
91 while ( /bin/ps ax | /bin/grep -q [p]ppd ); do
92 msg "waiting pppd exit"
93 /bin/sleep 2
94 done
95 /bin/sleep $HOLDOFF
96 if [ ! -e "CONFIG_ROOT/red/keepconnected" ]; then
97 # user pressed disconnect in gui
98 exit 0
99 fi
100 (( ATTEMPTS += 1 ))
101 msg "Restarting $ATTEMPTS/$MAXRETRIES"
102 if [ "$ATTEMPTS" -ge "$MAXRETRIES" ]; then
103 echo "0" > CONFIG_ROOT/red/keepconnected
104 msg "Clearing RED interface"
105 /etc/rc.d/rc.red clear
106 if [ "$BACKUPPROFILE" != '' ]; then
107 /bin/rm -f CONFIG_ROOT/ppp/settings
108 /bin/cp "CONFIG_ROOT/ppp/settings-$BACKUPPROFILE" CONFIG_ROOT/ppp/settings
109 fi
110 else
111 echo $ATTEMPTS > CONFIG_ROOT/red/keepconnected
112 fi
113 /etc/rc.d/rc.red start
114 ;;
115 reconnect)
116 while ( /bin/ps ax | /bin/grep -q [p]ppd ); do
117 /bin/sleep 2
118 done
119 if [ "$PROTOCOL" = RFC1483 ]; then
120 # remove bridged/routed user-space programs
121 if [ "$TYPE" = eciadsl ]; then
122 /etc/rc.d/rc.eciadsl stop
123 fi
124 if [ "$TYPE" = alcatelusb ]; then
125 /etc/rc.d/rc.alcatelusb stop
126 fi
127 fi
128 msg "will connect again"
129 /etc/rc.d/rc.red start
130 ;;
131 *)
132 /bin/echo "Usage: $0 {start|reconnect}"
133 exit 1
134 ;;
135 esac