3 #check if dyngw_plain is installed and enabled, else exit
4 dyngwplainlib
=`uci show olsrd |grep dyn_gw_plain |awk {' FS="."; print $1"."$2 '}`
5 if [ -n "$dyngwplainlib" ]; then
6 if [ "$(uci -q get $dyngwplainlib.ignore)" == 1 ]; then
10 echo "dyngw_plain not found in olsrd config, exit"
15 # check if we have a defaultroute with metric=0 in one of these tables: main table and gw-check table.
17 defroutemain
="$(ip r s |grep default |grep -v metric)"
18 defroutegwcheck
="$(ip r s t gw-check |grep default |grep -v metric)"
19 if [ -z "$defroutegwcheck" -a -z "$defroutemain" ]; then
23 # get and shuffle list of testservers
24 testserver
="$(uci -q get freifunk-gwcheck.hosts.host)"
25 [ -z "$testserver" ] && echo "No testservers found, exit" && exit
27 testserver
="$(for t in $testserver; do echo $t; done | awk 'BEGIN {
35 for (i = 1; i <= NR; i++) {
36 n = int(rand() * (NR - i + 1)) + i;
43 for t
in $testserver; do
45 test=$
(wget
-q http
://$t/conntest.html
-O -|
grep "Internet_works")
46 if [ "$test" == "Internet_works" ]; then
50 logger
-t gw-check
"Could not get test file from http://$t/conntest.html"
57 if [ "$iw" == 0 ]; then
58 # check if we have a seperate routing table for our tests.
59 # If yes, move defaultroute to normal table and delete table gw-check
60 if [ -n "$defroutegwcheck" ]; then
61 ip r a
$defroutegwcheck
62 ip r d
$defroutegwcheck t gw-check
63 ip ru del fwmark
0x2 lookup gw-check
64 for host in $testserver; do
65 iptables
-t mangle
-D OUTPUT
-d $host -p tcp
--dport 80 -j MARK
--set-mark 0x2
67 logger
-t gw-check
"Internet is available again, restoring default route ( $defroutegwcheck)"
71 # Check failed. If we have a defaultroute with metric=0 and it is already in table gw-check then do nothing.
72 # If there is a defaultroute with metric=0 then remove it from the main routing table and add to table gw-check.
73 if [ -z "$(ip ru s | grep gw-check)" -a -n "$defroutemain" ]; then
74 ip rule add fwmark
0x2 lookup gw-check
75 for host in $testserver; do
76 iptables
-t mangle
-I OUTPUT
-d $host -p tcp
--dport 80 -j MARK
--set-mark 0x2
78 ip r a
$defroutemain table gw-check
80 logger
-t gw-check
"Internet is not available, deactivating the default route ( $defroutemain)"