]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/ppp/ip-up
Fix pingtest at ip-up
[people/pmueller/ipfire-2.x.git] / src / ppp / ip-up
index 80fb49f49e1c2a5176860545535f03db5cd403af..ec4fc82b5f9d1c10978e8c20d00298518a2a15d6 100644 (file)
@@ -43,20 +43,36 @@ fi
 echo -n "$1" > /var/ipfire/red/iface
 echo -n "$4" > /var/ipfire/red/local-ipaddress
 echo -n "$5" > /var/ipfire/red/remote-ipaddress
+
 grep -v "gateway" /etc/hosts > /tmp/hosts
+echo "$5 gateway" >> /tmp/hosts
+touch /var/ipfire/red/active
+mv /tmp/hosts /etc/hosts
+
+#Start pingtest in background and store the pid
+ping -c 2 $5 > /tmp/gatewayping &
+PINGPID=$!
+
+run_subdir ${rc_base}/init.d/networking/red.up/
+
+[ -e "/var/ipfire/ppp/nobeeps" ] || /etc/rc.d/init.d/beep up
+
+#Make sure that pingtest has enough time
+sleep 3
 
-TEST=`ping -c 2 $5 2>/dev/null | tail -2 | head -1 | cut -d"," -f2`;
+#Kill the pingtest
+kill $PINGPID >/dev/null 2>&1
+
+#Check if gateway has answerd to ping, if not replace with ping.ipfire.org
+TEST=`cat /tmp/gatewayping | tail -2 | head -1 | cut -d"," -f2`;
 
 if [ "$TEST" == " 2 packets received" ]; then
-       echo "$5 gateway" >> /tmp/hosts
+       echo Ping gateway
 else
+       echo Ping ipfire
        FIRE=`nslookup ping.ipfire.org | tail -2  | head -1 | cut -d" " -f2`;
+       grep -v "gateway" /etc/hosts > /tmp/hosts
        echo "$FIRE gateway" >> /tmp/hosts
+       mv /tmp/hosts /etc/hosts
 fi
-
-mv /tmp/hosts /etc/hosts
-touch /var/ipfire/red/active
-
-run_subdir ${rc_base}/init.d/networking/red.up/
-
-[ -e "/var/ipfire/ppp/nobeeps" ] || /etc/rc.d/init.d/beep up
+rm -f /tmp/gatewayping