Don't fail if we do not have v6 support
[project/luci.git] / libs / sys / luasrc / sys.lua
index 948da5b..e92adc1 100644 (file)
@@ -320,7 +320,11 @@ end
 --                       "flags", "device" }
 function net.defaultroute6()
        local route = nil
-       for _, r in pairs(net.routes6()) do
+       local routes6 = net.routes6()
+       if not routes6 then
+               return nil
+       end
+       for _, r in pairs(routes6) do
                if r.dest:prefix() == 0 and (not route or route.metric > r.metric) then
                        route = r
                end
@@ -417,6 +421,10 @@ end
 function net.routes6()
        local routes = { }
 
+       if not luci.fs.access("/proc/net/ipv6_route", "r") then
+               return nil
+       end
+
        for line in io.lines("/proc/net/ipv6_route") do
 
                local dst_ip, dst_prefix, src_ip, src_prefix, nexthop,