2 local STRICT = true -- Only delete metric 0 routes
3 local PINGCMD = "ping -q -I%s -c3 -w3 '%s' >/dev/null 2>&1"
4 local PINGTRG = {"google.de", "www.de.debian.org", "eu.kernel.org", "freifunk.net"}
5 local ROUTECMD = "route del default gw '%s' >/dev/null 2>&1"
6 local THRESHOLD = 3 -- Maximum number of failed tests before dropping the route
8 local sys = require "luci.sys"
9 local uci = require "luci.model.uci".cursor_state()
10 local ucisec = "ff_olsr_test_gw"
13 uci:foreach("olsrd", "LoadPlugin", function(s)
14 if s.library == "olsrd_dyn_gw_plain.so.0.4" and s.ignore ~= "1" then
19 local droute = sys.net.defaultroute()
20 if section and droute then -- dyn_gw is enabled and we have a defaultroute, test it
23 for _, host in ipairs(PINGTRG) do
24 state = state or (sys.call(PINGCMD % {droute.device, host}) == 0)
27 if not state and (not STRICT or tonumber(droute.metric) == 0) then
28 local count = tonumber(uci:get("olsrd", ucisec, "noinet_count"))
29 if not THRESHOLD or (count and count >= THRESHOLD) then
30 sys.call(ROUTECMD % droute.gateway:string())
33 uci:set("olsrd", ucisec, "state")
35 uci:set("olsrd", ucisec, "noinet_count", (count or 0) + 1)
39 uci:revert("olsrd", ucisec)