modules/admin-full: rewrite interface state json backend to only utilize network model
This commit is contained in:
parent
9b18001b9f
commit
2dae492a36
1 changed files with 52 additions and 37 deletions
|
@ -207,47 +207,62 @@ function iface_status()
|
||||||
local iface
|
local iface
|
||||||
for iface in path[#path]:gmatch("[%w%.%-_]+") do
|
for iface in path[#path]:gmatch("[%w%.%-_]+") do
|
||||||
local net = netm:get_network(iface)
|
local net = netm:get_network(iface)
|
||||||
if net then
|
local device = net and net:get_interface()
|
||||||
local info
|
if device then
|
||||||
local dev = net:ifname()
|
local device = net:get_interface()
|
||||||
local data = {
|
local data = {
|
||||||
id = iface,
|
id = iface,
|
||||||
proto = net:proto(),
|
proto = net:proto(),
|
||||||
uptime = net:uptime(),
|
uptime = net:uptime(),
|
||||||
gwaddr = net:gwaddr(),
|
gwaddr = net:gwaddr(),
|
||||||
dnsaddrs = net:dnsaddrs()
|
dnsaddrs = net:dnsaddrs(),
|
||||||
|
name = device:shortname(),
|
||||||
|
type = device:type(),
|
||||||
|
ifname = device:name(),
|
||||||
|
macaddr = device:mac(),
|
||||||
|
is_up = device:is_up(),
|
||||||
|
rx_bytes = device:rx_bytes(),
|
||||||
|
tx_bytes = device:tx_bytes(),
|
||||||
|
rx_packets = device:rx_packets(),
|
||||||
|
tx_packets = device:tx_packets(),
|
||||||
|
|
||||||
|
ipaddrs = { },
|
||||||
|
ip6addrs = { },
|
||||||
|
subdevices = { }
|
||||||
}
|
}
|
||||||
for _, info in ipairs(nixio.getifaddrs()) do
|
|
||||||
local name = info.name:match("[^:]+")
|
local _, a
|
||||||
if name == dev then
|
for _, a in ipairs(device:ipaddrs()) do
|
||||||
if info.family == "packet" then
|
data.ipaddrs[#data.ipaddrs+1] = {
|
||||||
data.flags = info.flags
|
addr = a:host():string(),
|
||||||
data.stats = info.data
|
netmask = a:mask():string(),
|
||||||
data.macaddr = info.addr
|
prefix = a:prefix()
|
||||||
data.ifname = name
|
}
|
||||||
elseif info.family == "inet" then
|
end
|
||||||
data.ipaddrs = data.ipaddrs or { }
|
for _, a in ipairs(device:ip6addrs()) do
|
||||||
data.ipaddrs[#data.ipaddrs+1] = {
|
data.ip6addrs[#data.ip6addrs+1] = {
|
||||||
addr = info.addr,
|
addr = a:host():string(),
|
||||||
broadaddr = info.broadaddr,
|
netmask = a:mask():string(),
|
||||||
dstaddr = info.dstaddr,
|
prefix = a:prefix()
|
||||||
netmask = info.netmask,
|
}
|
||||||
prefix = info.prefix
|
|
||||||
}
|
|
||||||
elseif info.family == "inet6" then
|
|
||||||
data.ip6addrs = data.ip6addrs or { }
|
|
||||||
data.ip6addrs[#data.ip6addrs+1] = {
|
|
||||||
addr = info.addr,
|
|
||||||
netmask = info.netmask,
|
|
||||||
prefix = info.prefix
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if next(data) then
|
for _, device in ipairs(net:get_interfaces()) do
|
||||||
rv[#rv+1] = data
|
data.subdevices[#data.subdevices+1] = {
|
||||||
|
name = device:shortname(),
|
||||||
|
type = device:type(),
|
||||||
|
ifname = device:name(),
|
||||||
|
macaddr = device:mac(),
|
||||||
|
macaddr = device:mac(),
|
||||||
|
is_up = device:is_up(),
|
||||||
|
rx_bytes = device:rx_bytes(),
|
||||||
|
tx_bytes = device:tx_bytes(),
|
||||||
|
rx_packets = device:rx_packets(),
|
||||||
|
tx_packets = device:tx_packets(),
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rv[#rv+1] = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue