modules/admin-full: whitesapce cleanup in routes.lua
libs/sys: code changes in routes6() and defaultroute6()
This commit is contained in:
parent
cd8e12d72a
commit
46bb17c2d2
2 changed files with 52 additions and 50 deletions
|
@ -319,14 +319,15 @@ 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 = nil
|
||||||
local routes6 = net.routes6()
|
local routes6 = net.routes6()
|
||||||
if not routes6 then
|
if routes6 then
|
||||||
return nil
|
for _, r in pairs(routes6) do
|
||||||
end
|
if r.dest:prefix() == 0 and
|
||||||
for _, r in pairs(routes6) do
|
(not route or route.metric > r.metric)
|
||||||
if r.dest:prefix() == 0 and (not route or route.metric > r.metric) then
|
then
|
||||||
route = r
|
route = r
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return route
|
return route
|
||||||
|
@ -419,46 +420,44 @@ end
|
||||||
-- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
|
-- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
|
||||||
-- "flags", "device" }
|
-- "flags", "device" }
|
||||||
function net.routes6()
|
function net.routes6()
|
||||||
local routes = { }
|
if luci.fs.access("/proc/net/ipv6_route", "r") then
|
||||||
|
local routes = { }
|
||||||
|
|
||||||
if not luci.fs.access("/proc/net/ipv6_route", "r") then
|
for line in io.lines("/proc/net/ipv6_route") do
|
||||||
return nil
|
|
||||||
|
local dst_ip, dst_prefix, src_ip, src_prefix, nexthop,
|
||||||
|
metric, refcnt, usecnt, flags, dev = line:match(
|
||||||
|
"([a-f0-9]+) ([a-f0-9]+) " ..
|
||||||
|
"([a-f0-9]+) ([a-f0-9]+) " ..
|
||||||
|
"([a-f0-9]+) ([a-f0-9]+) " ..
|
||||||
|
"([a-f0-9]+) ([a-f0-9]+) " ..
|
||||||
|
"([a-f0-9]+) +([^%s]+)"
|
||||||
|
)
|
||||||
|
|
||||||
|
src_ip = luci.ip.Hex(
|
||||||
|
src_ip, tonumber(src_prefix, 16), luci.ip.FAMILY_INET6, false
|
||||||
|
)
|
||||||
|
|
||||||
|
dst_ip = luci.ip.Hex(
|
||||||
|
dst_ip, tonumber(dst_prefix, 16), luci.ip.FAMILY_INET6, false
|
||||||
|
)
|
||||||
|
|
||||||
|
nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false )
|
||||||
|
|
||||||
|
routes[#routes+1] = {
|
||||||
|
source = src_ip,
|
||||||
|
dest = dst_ip,
|
||||||
|
nexthop = nexthop,
|
||||||
|
metric = tonumber(metric, 16),
|
||||||
|
refcount = tonumber(refcnt, 16),
|
||||||
|
usecount = tonumber(usecnt, 16),
|
||||||
|
flags = tonumber(flags, 16),
|
||||||
|
device = dev
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return routes
|
||||||
end
|
end
|
||||||
|
|
||||||
for line in io.lines("/proc/net/ipv6_route") do
|
|
||||||
|
|
||||||
local dst_ip, dst_prefix, src_ip, src_prefix, nexthop,
|
|
||||||
metric, refcnt, usecnt, flags, dev = line:match(
|
|
||||||
"([a-f0-9]+) ([a-f0-9]+) " ..
|
|
||||||
"([a-f0-9]+) ([a-f0-9]+) " ..
|
|
||||||
"([a-f0-9]+) ([a-f0-9]+) " ..
|
|
||||||
"([a-f0-9]+) ([a-f0-9]+) " ..
|
|
||||||
"([a-f0-9]+) +([^%s]+)"
|
|
||||||
)
|
|
||||||
|
|
||||||
src_ip = luci.ip.Hex(
|
|
||||||
src_ip, tonumber(src_prefix, 16), luci.ip.FAMILY_INET6, false
|
|
||||||
)
|
|
||||||
|
|
||||||
dst_ip = luci.ip.Hex(
|
|
||||||
dst_ip, tonumber(dst_prefix, 16), luci.ip.FAMILY_INET6, false
|
|
||||||
)
|
|
||||||
|
|
||||||
nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false )
|
|
||||||
|
|
||||||
routes[#routes+1] = {
|
|
||||||
source = src_ip,
|
|
||||||
dest = dst_ip,
|
|
||||||
nexthop = nexthop,
|
|
||||||
metric = tonumber(metric, 16),
|
|
||||||
refcount = tonumber(refcnt, 16),
|
|
||||||
usecount = tonumber(usecnt, 16),
|
|
||||||
flags = tonumber(flags, 16),
|
|
||||||
device = dev
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
return routes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Tests whether the given host responds to ping probes.
|
--- Tests whether the given host responds to ping probes.
|
||||||
|
|
|
@ -42,7 +42,10 @@ if not arg or not arg[1] then
|
||||||
return routes[section].gateway:string()
|
return routes[section].gateway:string()
|
||||||
end
|
end
|
||||||
|
|
||||||
metric = v:option(DummyValue, "Metric", translate("metric"))
|
metric = v:option(DummyValue, "metric", translate("metric"))
|
||||||
|
function metric.cfgvalue(self, section)
|
||||||
|
return routes[section].metric
|
||||||
|
end
|
||||||
|
|
||||||
if routes6 then
|
if routes6 then
|
||||||
v = m:section(Table, routes6, translate("a_n_routes_kernel6"))
|
v = m:section(Table, routes6, translate("a_n_routes_kernel6"))
|
||||||
|
@ -63,10 +66,10 @@ if not arg or not arg[1] then
|
||||||
return routes6[section].source:string()
|
return routes6[section].source:string()
|
||||||
end
|
end
|
||||||
|
|
||||||
metric = v:option(DummyValue, "Metric", translate("metric"))
|
metric = v:option(DummyValue, "metric", translate("metric"))
|
||||||
function metric.cfgvalue(self, section)
|
function metric.cfgvalue(self, section)
|
||||||
return string.format( "%08X", routes6[section].metric )
|
return string.format( "%08X", routes6[section].metric )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue