diff --git a/contrib/package/freifunk-gwcheck/Makefile b/contrib/package/freifunk-gwcheck/Makefile
index c339d13..7d6c92f 100644
--- a/contrib/package/freifunk-gwcheck/Makefile
+++ b/contrib/package/freifunk-gwcheck/Makefile
@@ -15,7 +15,7 @@ define Package/freifunk-gwcheck
   CATEGORY:=LuCI
   SUBMENU:=9. Freifunk
   TITLE:=Freifunk gateway check script
-  DEPENDS:=firewall +ip +iptables-mod-ipopt +olsrd-mod-dyn-gw-plain
+  DEPENDS:=+firewall +ip +olsrd-mod-dyn-gw-plain
 endef
 
 define Package/freifunk-gwcheck/description
diff --git a/contrib/package/freifunk-gwcheck/files/etc/config/freifunk-gwcheck b/contrib/package/freifunk-gwcheck/files/etc/config/freifunk-gwcheck
index b174dd6..ff2b224 100644
--- a/contrib/package/freifunk-gwcheck/files/etc/config/freifunk-gwcheck
+++ b/contrib/package/freifunk-gwcheck/files/etc/config/freifunk-gwcheck
@@ -3,3 +3,8 @@ config 'gwcheck' 'hosts'
 	list 'host' 'vpn4.leipzig.freifunk.net'
 	list 'host' 'luci.subsignal.org'
 	list 'host' 'bbb-vpn.berlin.freifunk.net'
+
+# logging values err,info,debug
+config 'gwcheck' 'script'
+	option logging 'err'
+
diff --git a/contrib/package/freifunk-gwcheck/files/usr/sbin/ff_olsr_test_gw.sh b/contrib/package/freifunk-gwcheck/files/usr/sbin/ff_olsr_test_gw.sh
index 3965ea1..e2e5ddd 100755
--- a/contrib/package/freifunk-gwcheck/files/usr/sbin/ff_olsr_test_gw.sh
+++ b/contrib/package/freifunk-gwcheck/files/usr/sbin/ff_olsr_test_gw.sh
@@ -1,37 +1,89 @@
 #!/bin/sh
 # Copyright 2013 Manuel Munz <freifunk at somakoma dot de>
+# Copyright 2013 Patrick Grimm <patrick at lunatiki dot de>
 # Licensed under the GNU General Public License (GPL) v3
 # This script monitors the local internet gateway
 
+. /lib/functions.sh
 . /lib/functions/network.sh
 
+config_load freifunk-gwcheck
+local log
+config_get log script logging
+case $log in
+	err) log=1;;
+	info) log=2;;
+	debug) log=3;;
+	*) log=0;;
+esac
+
+logging() {
+	p=$1
+	msg=$2
+	if [ $p -le $log ]; then
+		case $p in
+			1) p="err";;
+			2) p="info";;
+			3) p="debug";;
+		esac
+		logger -p "$p" -t gw-check "$msg"
+	fi
+}
+
+
 # exit if dyngw_plain is not installed or enabled
 dgwlib=`uci show olsrd |grep dyn_gw_plain |awk {' FS="."; print $1"."$2 '}`
 if [ -n "$dgwlib" ]; then
 	if [ "$(uci -q get $dgwlib.ignore)" == 1 ]; then
+		logging 2 "dyngw disable"
 		exit 1
 	fi
 else
+	logging 2 "no config for dyngw"
 	exit 1
 fi
 
+local has_sgw
+has_sgw="$(uci -q -P /var/state get olsrd.@olsrd[0].SmartGateway)"
+local has_sgw_cnf
+has_sgw_cnf="$(uci -q get olsrd.@olsrd[0].SmartGateway)"
+
 #Exit if this script is already running
 pid="$(pidof ff_olsr_test_gw.sh)"
 if [ ${#pid} -gt 5 ]; then
-	logger -p debug -t gwcheck "Gateway check script is already running, exit now"
+	logging 3 "Gateway check script is already running, exit now"
 	exit 1
 fi
 
 # exit if there is no defaultroute with metric=0 in main or gw-check table.
 defroutemain="$(ip route show |grep default |grep -v metric)"
+logging 3 "defroutemain: $defroutemain"
 defroutegwcheck="$(ip route show table gw-check |grep default |grep -v metric)"
-if [ -z "$defroutegwcheck" -a -z "$defroutemain" ]; then
+logging 3 "defroutegwcheck: $defroutegwcheck"
+
+
+RtTable=$(uci show olsrd |grep RtTable= |awk {' FS="="; print $2'})
+if [ -n "$RtTable" ]; then
+	RtTableDefault=$(uci show olsrd |grep RtTableDefault |awk {' FS="="; print $2'})
+	if [ -n "$RtTableDefault" ]; then
+		defroutedefault="$(ip route show table default 2>/dev/null|grep default|grep -v metric)"
+		logging 3 "defroutedefault: $defroutedefault"
+		defrouteolsrdefault="$(ip route show table olsr-default 2>/dev/null|grep default|grep -v metric)"
+		logging 3 "defrouteolsrdefault: $defrouteolsrdefault"
+		defrouteolsrgwcheck="$(ip route show table gw-check-olsr 2>/dev/null|grep default|grep -v metric)"
+		logging 3 "defrouteolsrgwcheck: $defrouteolsrgwcheck"
+	fi
+fi
+
+if [ -z "$defroutegwcheck" -a -z "$defroutemain" -a -z "$defroutedefault" ]; then
+	logging 2 "no defroute"
 	exit 1
 fi
 
 # get and shuffle list of testservers
-testserver="$(uci -q get freifunk-gwcheck.hosts.host)"
-[ -z "$testserver" ] && echo "No testservers found, exit" && exit
+local testserver
+config_get testserver hosts host
+[ -z "$testserver" ] && logging 2 "No testservers found, exit" && exit
 
 testserver="$(for t in $testserver; do echo $t; done | awk 'BEGIN {
 	srand();
@@ -48,21 +100,96 @@ END {
 	}
 }')"
 
+resolve() {
+	echo "$(nslookup $1 2>/dev/null |grep 'Address' |grep -v '127.0.0.1' |awk '{ print $3 }')"
+}
+
+# check_internet table testserver1 testserver2
 check_internet() {
-	for t in $testserver; do
-		local test
-		test=$(wget -q http://$t/conntest.html -O -| grep "Internet_works")
-		if [ "$test" == "Internet_works" ]; then
-			echo 0
-			break
-		else
-			logger -p debug -t gw-check "Could not fetch http://$t/conntest.html"
+	local table=$1
+	local tserver=""
+	local testserver=""
+	local tips=""
+	local dips=""
+	local has_dns=""
+	local has_tserver=""
+	local ret=""
+	logging 3 "Internet over $table testing"
+	i=1
+	while [ $i -le $# ]; do
+		i=$((i+1))
+		eval 'server=$'$i
+		testserver="${testserver:+$testserver }$server"
+	done
+	get_dnsservers
+	for ip in $dns; do
+		ip="$(echo $ip | egrep '^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}$')"
+		if [ -n "$ip" ]; then
+			logging 3 "add name server rule for $ip table $table"
+			ip rule add pref 500 to $ip table $table 2>/dev/null
+			ip rule add pref 501 to $ip unreachable 2>/dev/null
+			dips="${dips:+$dips }$ip"
+			if [ -z $has_dns ] ; then
+				logging 3 "ping name server $ip table $table"
+				if ping -c 1 -w 2 -q $ip >/dev/null ; then
+					has_dns=1
+				fi
+			fi
 		fi
 	done
-}
 
-resolve() {
-	echo "$(nslookup $1 2>/dev/null |grep 'Address' |grep -v '127.0.0.1' |awk '{ print $3 }')"
+	if [ -n "$has_dns" ]; then
+		for host in $testserver; do
+			ips="$(resolve $host)"
+			for ip in $ips; do
+				ip="$(echo $ip | egrep '^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}$')"
+				if [ -n "$ip" ]; then
+					logging 3 "add test server rule for $ip table $table"
+					ip rule add pref 500 to $ip table $table 2>/dev/null
+					ip rule add pref 501 to $ip unreachable 2>/dev/null
+					tips="${tips:+$tips }$ip"
+					tserver="${tserver:+$tserver }$host"
+					if [ -z "$has_tserver" ]; then 
+						if ping -c 1 -w 2 -q $ip >/dev/null ; then
+							has_tserver=1
+						fi
+					fi
+				fi
+			done
+		done
+		if [ -z "$tserver" ]; then
+			logging 1 "Could not resolve ip for testserver from table $table"
+		fi
+	else
+		logging 1 "Could not ping dns server from table $table"
+	fi
+
+	if [ -n "$has_tserver" ]; then 
+		for t in $tserver; do
+			local test
+			test=$(wget -q http://$t/conntest.html -O -| grep "Internet_works")
+			if [ "$test" == "Internet_works" ]; then
+				logging 3 "Internet Works fetch http://$t/conntest.html via table $table"
+				ret=0
+				break
+			else
+				logging 2 "Could not fetch http://$t/conntest.html via table $table"
+			fi
+		done
+	fi
+
+	for ip in $dips; do
+		logging 3 "del name server rule for $ip table $table"
+		ip rule del pref 500 to $ip table $table 2>/dev/null
+		ip rule del pref 501 to $ip unreachable 2>/dev/null
+	done
+
+	for ip in $tips; do
+		logging 3 "del test server rule for $ip table $table"
+		ip rule del pref 500 to $ip table $table 2>/dev/null
+		ip rule del pref 501 to $ip unreachable 2>/dev/null
+	done
+	[ "$ret" == 0 ] && echo 0
 }
 
 get_dnsservers() {
@@ -72,49 +199,141 @@ get_dnsservers() {
 	if [ ! -x /bin/ubus ]; then
 		# ubus not present (versions before Attitude): fallback to get these from /var/state/network.
 		# We always assume that wan is the default route interface here
+		# this gets all dns servers for the interface which has the default route
 		dns="$(grep network.wan.resolv_dns /var/state/network | cut -d "=" -f 2)"
 	else
-		network_find_wan wan
-		network_get_dnsserver dns $wan
+		# this gets all dns servers for all interfaces
+		for i in $(ubus list network.interface.*) ; do 
+			local tmp
+			local 
+			tmp="$(ubus call "$i" status 2>/dev/null)"
+			[ -n "$tmp" ] || return 1
+		
+			json_set_namespace "network" __old_ns
+			json_load "$tmp"
+			# parse dns info
+			if json_is_a "dns_server" array; then
+				json_select "dns_server"
+				idx=1
+				list=""
+				while json_is_a "$idx" string; do
+					json_get_var tmp "$((idx++))"
+					list="${list:+$list }$tmp"
+				done
+				json_select ".."
+				if [ -n "$list" ]; then
+					dns="${dns:+$dns }$list"
+				fi
+			fi
+		done
 	fi
 }
 
-iw=$(check_internet)
+if [ -n "$defroutemain" ]; then
+	logging 3 "add default route main in gw-check"
+	ip route add $defroutemain table gw-check 2>/dev/null
+fi
+if [ -n "$defroutedefault" ]; then
+	logging 3 "add default route default in gw-check"
+	ip route add $defroutedefault table gw-check 2>/dev/null
+fi
+
+iw=$(check_internet "gw-check" "$testserver")
+
+if [ -n "$defroutemain" ]; then
+	logging 3 "del default route main in gw-check"
+	ip route del $defroutemain table gw-check 2>/dev/null
+fi
+if [ -n "$defroutedefault" ]; then
+	logging 3 "del default route default in gw-check"
+	ip route del $defroutedefault table gw-check 2>/dev/null
+fi
 
 if [ "$iw" == 0 ]; then
 	# Internet available again, restore default route and remove ip rules
+	logging 3 "Internet available again, restore default route and remove ip rules"
 	if [ -n "$defroutegwcheck" ]; then
-		ip route add $defroutegwcheck
-		ip route del $defroutegwcheck table gw-check
-		for host in $testserver; do
-			ips="$(resolve $host)"
-			for ip in $ips; do
-				[ -n "$(ip rule show | grep "to $ip lookup gw-check")" ] && ip rule del to $ip table gw-check
-			done
-		done
-		get_dnsservers
-		for d in $dns; do
-			[ -n "$(ip rule show | grep "to $d lookup gw-check")" ] && ip rule del to $d table gw-check
-		done
-		logger -p err -t gw-check "Internet is available again, default route restored ( $defroutegwcheck)"
+		if [ -z "$defroutemain" -a -z "$defroutedefault" ]; then
+			if [ -z "$RtTableDefault" ]; then
+				logging 3 "restore defaultroute in the main table"
+				ip route add $defroutegwcheck table main 2>/dev/null
+			else
+				logging 3 "restore defaultroute in the default table"
+				ip route add $defroutegwcheck table default 2>/dev/null
+			fi
+		elif [ -n "$defroutemain" ] ; then
+			logging 3 "default route found in main table"
+		elif [ -n "$defroutedefault" ] ; then
+			logging 3 "default route found in default table"
+		fi
+		ip route del $defroutegwcheck table gw-check 2>/dev/null
+		logging 2 "Internet is available again, default route restored ( $defroutegwcheck)"
 	fi
+	
+	if [ -n "$RtTableDefault" ]; then
+		if [ -n "$defrouteolsrdefault" ]; then
+			logging 3 "add defaultroute in the gw-check-olsr table"
+			ip route add $defrouteolsrdefault table gw-check-olsr 2>/dev/null
+		fi
+
+		iwolsr=$(check_internet gw-check-olsr $testserver)
 
+		if [ -n "$defrouteolsrdefault" ]; then
+			logging 3 "del defaultroute in the gw-check-olsr table"
+			ip route del $defrouteolsrdefault table gw-check-olsr 2>/dev/null
+		fi
+
+		if [ "$iwolsr" == 0 ]; then
+			# Internet available again, restore default route and remove ip rules
+			logging 2 "Internet over olsr-default available"
+			if [ -n "$defrouteolsrgwcheck" ]; then
+				logging 3 "add olsr-default route from gw-check-olsr"
+				ip route add $defrouteolsrgwcheck table olsr-default 2>/dev/null
+			fi
+			if [ -n "$defroutedefault" ]; then
+				logging 3 "add default route table main from default table"
+				ip route add $defroutedefault table main 2>/dev/null
+				logging 3 "del default route table default"
+				ip route del $defroutedefault table default 2>/dev/null
+			fi
+		else
+			logging 1 "Internet not available for olsr-default"
+			if [ -n "$defrouteolsrdefault" ]; then
+				if [ -n "$defrouteolsrgwcheck" ]; then
+					logging 3 "del default route in gw-check-olsr"
+					ip route del "$defrouteolsrgwcheck" table gw-check-olsr 2>/dev/null
+				fi
+				logging 3 "add default olsr route in gw-check-olsr"
+				ip route add $defrouteolsrdefault table gw-check-olsr 2>/dev/null
+				logging 3 "del olsr default route"
+				ip route del $defrouteolsrdefault table olsr-default 2>/dev/null
+			fi
+			if [ -n "$defroutemain" ]; then
+				logging 1 "Internet only for local available"
+				ip route add $defroutemain table default 2>/dev/null
+				logging 3 "do not enable olsr hna with defaultroute in the main table"
+				ip route del $defroutemain table main 2>/dev/null
+			fi
+		fi
+	fi
 else
 	# Check failed. Move default route to table gw-check and setup ip rules.
-	if [ -z "$(ip rule show | grep gw-check)" -a -n "$defroutemain" ]; then
-		ip route add $defroutemain table gw-check
-		ip route del $defroutemain
-		logger -p err -t gw-check "Internet is not available, default route deactivated ( $defroutemain)"
+	logging 1 "Internet not available"
+	if [ -n "$defroutemain" ]; then
+		logging 3 "save default route main in gw-check"
+		ip route add $defroutemain table gw-check 2>/dev/null
+		ip route del $defroutemain 2>/dev/null
 	fi
-	for host in $testserver; do
-		ips="$(resolve $host)"
-		for ip in $ips; do
-			[ -z "$(ip rule show | grep "to $ip lookup gw-check")" ] && ip rule add to $ip table gw-check
-		done
-	done
-	get_dnsservers
-	for d in $dns; do
-		[ -z "$(ip rule show | grep "to $d lookup gw-check")" ] && ip rule add to $d table gw-check
-	done
-	logger -p err -t gw-check "Check your internet connection!"
+	if [ -n "$defroutedefault" ]; then
+		logging 3 "save default route default in gw-check"
+		ip route add $defroutedefault table gw-check 2>/dev/null
+		ip route del $defroutedefault table default 2>/dev/null
+	fi
+	if [ -n "$defrouteolsrdefault" ]; then
+		logging 3 "save default route olsr-default in gw-check-olsr"
+		ip route add $defrouteolsrdefault table gw-check-olsr 2>/dev/null
+		ip route del $defrouteolsrdefault table olsr-default 2>/dev/null
+	fi
+	logging 1 "Check your internet connection!"
 fi
+
diff --git a/contrib/package/freifunk-gwcheck/root/etc/uci-defaults/freifunk-gwcheck b/contrib/package/freifunk-gwcheck/root/etc/uci-defaults/freifunk-gwcheck
index 33b1b99..0d2ebe3 100644
--- a/contrib/package/freifunk-gwcheck/root/etc/uci-defaults/freifunk-gwcheck
+++ b/contrib/package/freifunk-gwcheck/root/etc/uci-defaults/freifunk-gwcheck
@@ -2,6 +2,7 @@
 tables="/etc/iproute2/rt_tables"
 test -d /etc/iproute2/ || mkdir -p /etc/iproute2/
 grep -q "gw-check" $tables || echo "200 gw-check" >> $tables
+grep -q "gw-check-olsr" $tables || echo "201 gw-check-olsr" >> $tables
 test -f /etc/crontabs/root || touch /etc/crontabs/root
 grep -q "ff_olsr_test_gw.sh" /etc/crontabs/root || echo "* * * * *	/usr/sbin/ff_olsr_test_gw.sh" >> /etc/crontabs/root
 /etc/init.d/cron restart
