summaryrefslogtreecommitdiffhomepage
path: root/modules/freifunk/root/usr
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-01-31 16:28:34 +0000
committerSteven Barth <steven@midlink.org>2009-01-31 16:28:34 +0000
commitce2da9198bd7d02815878bf04681ffe6c1dabb91 (patch)
treef3236a4d75fe4e29107499d25a0c7e8c2e85b7e0 /modules/freifunk/root/usr
parent56f5204e8f61c065023fc3a014355b4cacaa0772 (diff)
Fix ff_olsr_test_gw
Diffstat (limited to 'modules/freifunk/root/usr')
-rwxr-xr-xmodules/freifunk/root/usr/sbin/ff_olsr_test_gw52
1 files changed, 28 insertions, 24 deletions
diff --git a/modules/freifunk/root/usr/sbin/ff_olsr_test_gw b/modules/freifunk/root/usr/sbin/ff_olsr_test_gw
index dda6a5ea7..5c47b498d 100755
--- a/modules/freifunk/root/usr/sbin/ff_olsr_test_gw
+++ b/modules/freifunk/root/usr/sbin/ff_olsr_test_gw
@@ -4,34 +4,38 @@ local PINGCMD = "ping -q -I%s -c3 -w3 '%s' >/dev/null 2>&1"
local PINGTRG = {"google.de", "www.de.debian.org", "eu.kernel.org", "freifunk.net"}
local ROUTECMD = "route del default gw '%s' >/dev/null 2>&1"
local THRESHOLD = 3 -- Maximum number of failed tests before dropping the route
-
+
local sys = require "luci.sys"
local uci = require "luci.model.uci".cursor_state()
+local ucisec = "ff_olsr_test_gw"
local section = nil
-
+
uci:foreach("olsrd", "LoadPlugin", function(s)
- if s.library == "olsrd_dyn_gw_plain.so.0.4" and s.ignore ~= "1" then
- section = s[".name"]
- end
+ if s.library == "olsrd_dyn_gw_plain.so.0.4" and s.ignore ~= "1" then
+ section = s[".name"]
+ end
end)
-
+
local droute = sys.net.defaultroute()
if section and droute then -- dyn_gw is enabled and we have a defaultroute, test it
- local state = false
-
- for _, host in ipairs(PINGTRG) do
- state = state or (sys.call(PINGCMD % {droute.device, host}) == 0)
- end
-
- if not state and (not STRICT or tonumber(droute.metric) == 0) then
- local count = tonumber(uci:get("olsrd", section, "noinet_count"))
- if not THRESHOLD or (count and count > THRESHOLD) then
- sys.call(ROUTECMD % droute.gateway:string())
- else
- uci:set("olsrd", section, "noinet_count", (count or 0) + 1)
- end
- else
- uci:set("olsrd", section, "noinet_count", "0")
- end
- uci:save("olsrd")
-end \ No newline at end of file
+ local state = false
+
+ for _, host in ipairs(PINGTRG) do
+ state = state or (sys.call(PINGCMD % {droute.device, host}) == 0)
+ end
+
+ if not state and (not STRICT or tonumber(droute.metric) == 0) then
+ local count = tonumber(uci:get("olsrd", ucisec, "noinet_count"))
+ if not THRESHOLD or (count and count >= THRESHOLD) then
+ sys.call(ROUTECMD % droute.gateway:string())
+ else
+ if not count then
+ uci:set("olsrd", ucisec, "state")
+ end
+ uci:set("olsrd", ucisec, "noinet_count", (count or 0) + 1)
+ uci:save("olsrd")
+ end
+ else
+ uci:revert("olsrd", ucisec)
+ end
+end