require "luci.sys"
require "luci.tools.webadmin"
+local bit = require "bit"
local uci = luci.model.uci.cursor_state()
local ffzone = luci.tools.webadmin.firewall_find_zone("freifunk")
local routes6 = {}
-for i, route in ipairs(luci.sys.net.routes6()) do
+for i, route in ipairs(luci.sys.net.routes6() or {}) do
if route.dest:prefix() == 0 then
routes6[#routes6+1] = route
end
end
-v6 = r:section(Table, routes6)
+if #routes6 > 0 then
+ v6 = r:section(Table, routes6)
-net = v6:option(DummyValue, "iface", translate("network"))
-function net.cfgvalue(self, section)
- return luci.tools.webadmin.iface_get_network(routes[section].device)
- or routes6[section].device
-end
+ net = v6:option(DummyValue, "iface", translate("network"))
+ function net.cfgvalue(self, section)
+ return luci.tools.webadmin.iface_get_network(routes6[section].device)
+ or routes6[section].device
+ end
-target = v6:option(DummyValue, "target", translate("target"))
-function target.cfgvalue(self, section)
- return routes6[section].dest:string()
-end
+ target = v6:option(DummyValue, "target", translate("target"))
+ function target.cfgvalue(self, section)
+ return routes6[section].dest:string()
+ end
-gateway = v6:option(DummyValue, "gateway6", translate("gateway6"))
-function gateway.cfgvalue(self, section)
- return routes6[section].source:string()
-end
+ gateway = v6:option(DummyValue, "gateway6", translate("gateway6"))
+ function gateway.cfgvalue(self, section)
+ return routes6[section].source:string()
+ end
-metric = v6:option(DummyValue, "metric", translate("metric"))
-function metric.cfgvalue(self, section)
- return string.format("%X", routes6[section].metric)
+ metric = v6:option(DummyValue, "metric", translate("metric"))
+ function metric.cfgvalue(self, section)
+ local metr = routes6[section].metric
+ local lower = bit.band(metr, 0xffff)
+ local higher = bit.rshift(bit.band(metr, 0xffff0000), 16)
+ return "%04X%04X" % {higher, lower}
+ end
end
return f, m, r