X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Ffreifunk%2Froot%2Fusr%2Fsbin%2Fff_olsr_test_gw;fp=modules%2Ffreifunk%2Froot%2Fusr%2Fsbin%2Fff_olsr_test_gw;h=dda6a5ea791569e36f26f1b4753fe7503a59f8d3;hp=0000000000000000000000000000000000000000;hb=07790dad35cd637a736bfc27ca50d3e2fc4ecc1d;hpb=ab18c3ba1006db94df57c310da97b5ddb07991ad diff --git a/modules/freifunk/root/usr/sbin/ff_olsr_test_gw b/modules/freifunk/root/usr/sbin/ff_olsr_test_gw new file mode 100755 index 000000000..dda6a5ea7 --- /dev/null +++ b/modules/freifunk/root/usr/sbin/ff_olsr_test_gw @@ -0,0 +1,37 @@ +#!/usr/bin/lua +local STRICT = true -- Only delete metric 0 routes +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 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 +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