libs/sys: optimize luci.sys.net.defaultroute6()
This commit is contained in:
parent
223963e419
commit
98a6885834
1 changed files with 15 additions and 12 deletions
|
@ -302,17 +302,14 @@ end
|
||||||
-- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
|
-- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
|
||||||
-- "flags", "device" }
|
-- "flags", "device" }
|
||||||
function net.defaultroute6()
|
function net.defaultroute6()
|
||||||
local route = nil
|
local route
|
||||||
local routes6 = net.routes6()
|
|
||||||
if routes6 then
|
net.routes6(function(rt)
|
||||||
for _, r in pairs(routes6) do
|
if rt.dest:prefix() == 0 and (not route or route.metric > rt.metric) then
|
||||||
if r.dest:prefix() == 0 and
|
route = rt
|
||||||
(not route or route.metric > r.metric)
|
|
||||||
then
|
|
||||||
route = r
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
|
|
||||||
return route
|
return route
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -426,7 +423,7 @@ end
|
||||||
-- The following fields are defined for route entry tables:
|
-- The following fields are defined for route entry tables:
|
||||||
-- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
|
-- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
|
||||||
-- "flags", "device" }
|
-- "flags", "device" }
|
||||||
function net.routes6()
|
function net.routes6(callback)
|
||||||
if luci.fs.access("/proc/net/ipv6_route", "r") then
|
if luci.fs.access("/proc/net/ipv6_route", "r") then
|
||||||
local routes = { }
|
local routes = { }
|
||||||
|
|
||||||
|
@ -451,7 +448,7 @@ function net.routes6()
|
||||||
|
|
||||||
nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false )
|
nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false )
|
||||||
|
|
||||||
routes[#routes+1] = {
|
local rt = {
|
||||||
source = src_ip,
|
source = src_ip,
|
||||||
dest = dst_ip,
|
dest = dst_ip,
|
||||||
nexthop = nexthop,
|
nexthop = nexthop,
|
||||||
|
@ -461,6 +458,12 @@ function net.routes6()
|
||||||
flags = tonumber(flags, 16),
|
flags = tonumber(flags, 16),
|
||||||
device = dev
|
device = dev
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if callback then
|
||||||
|
callback(rt)
|
||||||
|
else
|
||||||
|
routes[#routes+1] = rt
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return routes
|
return routes
|
||||||
|
|
Loading…
Reference in a new issue