libs/core: fixes for network model
This commit is contained in:
parent
17f2921341
commit
3fb80187f8
1 changed files with 11 additions and 8 deletions
|
@ -32,7 +32,7 @@ module "luci.model.network"
|
||||||
|
|
||||||
|
|
||||||
local ub = uct.bind("network")
|
local ub = uct.bind("network")
|
||||||
local ifs, brs
|
local ifs, brs, sws
|
||||||
|
|
||||||
function init(cursor)
|
function init(cursor)
|
||||||
if cursor then
|
if cursor then
|
||||||
|
@ -42,11 +42,13 @@ function init(cursor)
|
||||||
|
|
||||||
ifs = { }
|
ifs = { }
|
||||||
brs = { }
|
brs = { }
|
||||||
|
sws = { }
|
||||||
|
|
||||||
-- read interface information
|
-- read interface information
|
||||||
local n, i
|
local n, i
|
||||||
for n, i in ipairs(nxo.getifaddrs()) do
|
for n, i in ipairs(nxo.getifaddrs()) do
|
||||||
local name = i.name:match("[^:]+")
|
local name = i.name:match("[^:]+")
|
||||||
|
local prnt = name:match("^([^%.]+)%.")
|
||||||
|
|
||||||
if not _M:ignore_interface(name) then
|
if not _M:ignore_interface(name) then
|
||||||
ifs[name] = ifs[name] or {
|
ifs[name] = ifs[name] or {
|
||||||
|
@ -58,6 +60,11 @@ function init(cursor)
|
||||||
ip6addrs = { }
|
ip6addrs = { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if prnt then
|
||||||
|
sws[name] = true
|
||||||
|
sws[prnt] = true
|
||||||
|
end
|
||||||
|
|
||||||
if i.family == "packet" then
|
if i.family == "packet" then
|
||||||
ifs[name].flags = i.flags
|
ifs[name].flags = i.flags
|
||||||
ifs[name].stats = i.data
|
ifs[name].stats = i.data
|
||||||
|
@ -229,9 +236,7 @@ end
|
||||||
function network.get_interfaces(self)
|
function network.get_interfaces(self)
|
||||||
local ifaces = { }
|
local ifaces = { }
|
||||||
local iface
|
local iface
|
||||||
for _, iface in ub:list(
|
for _, iface in ipairs(ub:list(self:ifname())) do
|
||||||
(self:ifname() or '') .. ' ' .. (self:device() or '')
|
|
||||||
) do
|
|
||||||
iface = iface:match("[^:]+")
|
iface = iface:match("[^:]+")
|
||||||
if ifs[iface] then
|
if ifs[iface] then
|
||||||
ifaces[#ifaces+1] = interface(iface)
|
ifaces[#ifaces+1] = interface(iface)
|
||||||
|
@ -242,9 +247,7 @@ end
|
||||||
|
|
||||||
function network.contains_interface(self, iface)
|
function network.contains_interface(self, iface)
|
||||||
local i
|
local i
|
||||||
local ifaces = ub:list(
|
local ifaces = ub:list(self:ifname())
|
||||||
(self:ifname() or '') .. ' ' .. (self:device() or '')
|
|
||||||
)
|
|
||||||
|
|
||||||
if type(iface) ~= "string" then
|
if type(iface) ~= "string" then
|
||||||
iface = iface:name()
|
iface = iface:name()
|
||||||
|
@ -290,7 +293,7 @@ function interface.type(self)
|
||||||
return "wifi"
|
return "wifi"
|
||||||
elseif brs[self.ifname] then
|
elseif brs[self.ifname] then
|
||||||
return "bridge"
|
return "bridge"
|
||||||
elseif self.ifname:match("%.") then
|
elseif sws[self.ifname] or self.ifname:match("%.") then
|
||||||
return "switch"
|
return "switch"
|
||||||
else
|
else
|
||||||
return "ethernet"
|
return "ethernet"
|
||||||
|
|
Loading…
Reference in a new issue