diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-10 13:49:24 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-10 13:49:24 +0000 |
commit | 98a688583433396afc6e491b9a2e28d2e38e484e (patch) | |
tree | 2b38704b8f34399dcc3169927c0f2c0ed85c9c2f | |
parent | 223963e419e7dc0e660301050e6b42ee2a0002cb (diff) |
libs/sys: optimize luci.sys.net.defaultroute6()
-rw-r--r-- | libs/sys/luasrc/sys.lua | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index d6cc6346b..68ddd8a0c 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -302,17 +302,14 @@ end -- { "source", "dest", "nexthop", "metric", "refcount", "usecount", -- "flags", "device" } function net.defaultroute6() - local route = nil - local routes6 = net.routes6() - if routes6 then - for _, r in pairs(routes6) do - if r.dest:prefix() == 0 and - (not route or route.metric > r.metric) - then - route = r - end + local route + + net.routes6(function(rt) + if rt.dest:prefix() == 0 and (not route or route.metric > rt.metric) then + route = rt end - end + end) + return route end @@ -426,7 +423,7 @@ end -- The following fields are defined for route entry tables: -- { "source", "dest", "nexthop", "metric", "refcount", "usecount", -- "flags", "device" } -function net.routes6() +function net.routes6(callback) if luci.fs.access("/proc/net/ipv6_route", "r") then local routes = { } @@ -451,7 +448,7 @@ function net.routes6() nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false ) - routes[#routes+1] = { + local rt = { source = src_ip, dest = dst_ip, nexthop = nexthop, @@ -461,6 +458,12 @@ function net.routes6() flags = tonumber(flags, 16), device = dev } + + if callback then + callback(rt) + else + routes[#routes+1] = rt + end end return routes |