luci-base: drop unused functions in luci.sys
Drop a number of redundant functions from luci.sys to shrink the code a bit: * luci.sys.net.arptable() - replaced by luci.ip.neighbors() * luci.sys.net.routes() - replaced by luci.ip.routes() * luci.sys.net.routes6() - replaced by luci.ip.routes6() * luci.sys.net.deviceinfo() - replaced by nixio.getaddrinfo() * luci.sys.net.pingtest() - no known user Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
854a5f68bb
commit
366707a681
1 changed files with 0 additions and 173 deletions
|
@ -117,40 +117,6 @@ end
|
|||
|
||||
net = {}
|
||||
|
||||
-- The following fields are defined for arp entry objects:
|
||||
-- { "IP address", "HW address", "HW type", "Flags", "Mask", "Device" }
|
||||
function net.arptable(callback)
|
||||
local arp = (not callback) and {} or nil
|
||||
local e, r, v
|
||||
if fs.access("/proc/net/arp") then
|
||||
for e in io.lines("/proc/net/arp") do
|
||||
local r = { }, v
|
||||
for v in e:gmatch("%S+") do
|
||||
r[#r+1] = v
|
||||
end
|
||||
|
||||
if r[1] ~= "IP" then
|
||||
local x = {
|
||||
["IP address"] = r[1],
|
||||
["HW type"] = r[2],
|
||||
["Flags"] = r[3],
|
||||
["HW address"] = r[4],
|
||||
["Mask"] = r[5],
|
||||
["Device"] = r[6]
|
||||
}
|
||||
|
||||
if callback then
|
||||
callback(x)
|
||||
else
|
||||
arp = arp or { }
|
||||
arp[#arp+1] = x
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return arp
|
||||
end
|
||||
|
||||
local function _nethints(what, callback)
|
||||
local _, k, e, mac, ip, name
|
||||
local cur = uci.cursor()
|
||||
|
@ -378,145 +344,6 @@ function net.devices()
|
|||
end
|
||||
|
||||
|
||||
function net.deviceinfo()
|
||||
local devs = {}
|
||||
for k, v in ipairs(nixio.getifaddrs()) do
|
||||
if v.family == "packet" then
|
||||
local d = v.data
|
||||
d[1] = d.rx_bytes
|
||||
d[2] = d.rx_packets
|
||||
d[3] = d.rx_errors
|
||||
d[4] = d.rx_dropped
|
||||
d[5] = 0
|
||||
d[6] = 0
|
||||
d[7] = 0
|
||||
d[8] = d.multicast
|
||||
d[9] = d.tx_bytes
|
||||
d[10] = d.tx_packets
|
||||
d[11] = d.tx_errors
|
||||
d[12] = d.tx_dropped
|
||||
d[13] = 0
|
||||
d[14] = d.collisions
|
||||
d[15] = 0
|
||||
d[16] = 0
|
||||
devs[v.name] = d
|
||||
end
|
||||
end
|
||||
return devs
|
||||
end
|
||||
|
||||
|
||||
-- The following fields are defined for route entry tables:
|
||||
-- { "dest", "gateway", "metric", "refcount", "usecount", "irtt",
|
||||
-- "flags", "device" }
|
||||
function net.routes(callback)
|
||||
local routes = { }
|
||||
|
||||
for line in io.lines("/proc/net/route") do
|
||||
|
||||
local dev, dst_ip, gateway, flags, refcnt, usecnt, metric,
|
||||
dst_mask, mtu, win, irtt = line:match(
|
||||
"([^%s]+)\t([A-F0-9]+)\t([A-F0-9]+)\t([A-F0-9]+)\t" ..
|
||||
"(%d+)\t(%d+)\t(%d+)\t([A-F0-9]+)\t(%d+)\t(%d+)\t(%d+)"
|
||||
)
|
||||
|
||||
if dev then
|
||||
gateway = luci.ip.Hex( gateway, 32, luci.ip.FAMILY_INET4 )
|
||||
dst_mask = luci.ip.Hex( dst_mask, 32, luci.ip.FAMILY_INET4 )
|
||||
dst_ip = luci.ip.Hex(
|
||||
dst_ip, dst_mask:prefix(dst_mask), luci.ip.FAMILY_INET4
|
||||
)
|
||||
|
||||
local rt = {
|
||||
dest = dst_ip,
|
||||
gateway = gateway,
|
||||
metric = tonumber(metric),
|
||||
refcount = tonumber(refcnt),
|
||||
usecount = tonumber(usecnt),
|
||||
mtu = tonumber(mtu),
|
||||
window = tonumber(window),
|
||||
irtt = tonumber(irtt),
|
||||
flags = tonumber(flags, 16),
|
||||
device = dev
|
||||
}
|
||||
|
||||
if callback then
|
||||
callback(rt)
|
||||
else
|
||||
routes[#routes+1] = rt
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return routes
|
||||
end
|
||||
|
||||
-- The following fields are defined for route entry tables:
|
||||
-- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
|
||||
-- "flags", "device" }
|
||||
function net.routes6(callback)
|
||||
if fs.access("/proc/net/ipv6_route", "r") then
|
||||
local routes = { }
|
||||
|
||||
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]+)"
|
||||
)
|
||||
|
||||
if dst_ip and dst_prefix and
|
||||
src_ip and src_prefix and
|
||||
nexthop and metric and
|
||||
refcnt and usecnt and
|
||||
flags and dev
|
||||
then
|
||||
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 )
|
||||
|
||||
local rt = {
|
||||
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,
|
||||
|
||||
-- lua number is too small for storing the metric
|
||||
-- add a metric_raw field with the original content
|
||||
metric_raw = metric
|
||||
}
|
||||
|
||||
if callback then
|
||||
callback(rt)
|
||||
else
|
||||
routes[#routes+1] = rt
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return routes
|
||||
end
|
||||
end
|
||||
|
||||
function net.pingtest(host)
|
||||
return os.execute("ping -c1 '"..host:gsub("'", '').."' >/dev/null 2>&1")
|
||||
end
|
||||
|
||||
|
||||
process = {}
|
||||
|
||||
function process.info(key)
|
||||
|
|
Loading…
Reference in a new issue