libs/core: various interface handling fixes in network model
This commit is contained in:
parent
63639d6076
commit
e2a1ffb59d
1 changed files with 61 additions and 29 deletions
|
@ -674,6 +674,10 @@ function network.is_virtual(self)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function network.is_floating(self)
|
||||||
|
return (self:is_virtual() and self:proto() ~= "pppoe")
|
||||||
|
end
|
||||||
|
|
||||||
function network.is_empty(self)
|
function network.is_empty(self)
|
||||||
if self:is_virtual() then
|
if self:is_virtual() then
|
||||||
return false
|
return false
|
||||||
|
@ -697,7 +701,7 @@ function network.is_empty(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function network.add_interface(self, ifname)
|
function network.add_interface(self, ifname)
|
||||||
if not self:is_virtual() then
|
if not self:is_floating() then
|
||||||
if type(ifname) ~= "string" then
|
if type(ifname) ~= "string" then
|
||||||
ifname = ifname:name()
|
ifname = ifname:name()
|
||||||
else
|
else
|
||||||
|
@ -723,7 +727,7 @@ function network.add_interface(self, ifname)
|
||||||
end
|
end
|
||||||
|
|
||||||
function network.del_interface(self, ifname)
|
function network.del_interface(self, ifname)
|
||||||
if not self:is_virtual() then
|
if not self:is_floating() then
|
||||||
if utl.instanceof(ifname, interface) then
|
if utl.instanceof(ifname, interface) then
|
||||||
ifname = ifname:name()
|
ifname = ifname:name()
|
||||||
else
|
else
|
||||||
|
@ -739,40 +743,67 @@ function network.del_interface(self, ifname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function network.get_interfaces(self)
|
function network.get_interface(self)
|
||||||
local ifaces = { }
|
|
||||||
|
|
||||||
local ifn
|
|
||||||
if self:is_virtual() then
|
if self:is_virtual() then
|
||||||
ifn = self:proto() .. "-" .. self.sid
|
return interface(self:proto() .. "-" .. self.sid)
|
||||||
ifaces = { interface(ifn) }
|
elseif self:is_bridge() then
|
||||||
|
return interface("br-" .. self.sid)
|
||||||
else
|
else
|
||||||
local nfs = { }
|
local ifn = nil
|
||||||
for ifn in utl.imatch(self:get("ifname")) do
|
|
||||||
ifn = ifn:match("[^:]+")
|
|
||||||
nfs[ifn] = interface(ifn)
|
|
||||||
end
|
|
||||||
|
|
||||||
for ifn in utl.kspairs(nfs) do
|
|
||||||
ifaces[#ifaces+1] = nfs[ifn]
|
|
||||||
end
|
|
||||||
|
|
||||||
local num = { }
|
local num = { }
|
||||||
local wfs = { }
|
for ifn in utl.imatch(uci_s:get("network", self.sid, "ifname")) do
|
||||||
uci_r:foreach("wireless", "wifi-iface",
|
ifn = ifn:match("^[^:/]+")
|
||||||
|
return ifn and interface(ifn)
|
||||||
|
end
|
||||||
|
ifn = nil
|
||||||
|
uci_s:foreach("wireless", "wifi-iface",
|
||||||
function(s)
|
function(s)
|
||||||
if s.device then
|
if s.device then
|
||||||
num[s.device] = num[s.device] and num[s.device] + 1 or 1
|
num[s.device] = num[s.device] and num[s.device] + 1 or 1
|
||||||
if s.network == self.sid then
|
if s.network == self.sid then
|
||||||
ifn = "%s.network%d" %{ s.device, num[s.device] }
|
ifn = s.ifname or "%s.network%d" %{ s.device, num[s.device] }
|
||||||
wfs[ifn] = interface(ifn)
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
return ifn and interface(ifn)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for ifn in utl.kspairs(wfs) do
|
function network.get_interfaces(self)
|
||||||
ifaces[#ifaces+1] = wfs[ifn]
|
local ifaces = { }
|
||||||
end
|
|
||||||
|
local ifn
|
||||||
|
local nfs = { }
|
||||||
|
for ifn in utl.imatch(self:get("ifname")) do
|
||||||
|
ifn = ifn:match("^[^:/]+")
|
||||||
|
nfs[ifn] = interface(ifn)
|
||||||
|
end
|
||||||
|
|
||||||
|
for ifn in utl.kspairs(nfs) do
|
||||||
|
ifaces[#ifaces+1] = nfs[ifn]
|
||||||
|
end
|
||||||
|
|
||||||
|
local num = { }
|
||||||
|
local wfs = { }
|
||||||
|
uci_r:foreach("wireless", "wifi-iface",
|
||||||
|
function(s)
|
||||||
|
if s.device then
|
||||||
|
num[s.device] = num[s.device] and num[s.device] + 1 or 1
|
||||||
|
if s.network == self.sid then
|
||||||
|
ifn = "%s.network%d" %{ s.device, num[s.device] }
|
||||||
|
wfs[ifn] = interface(ifn)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
for ifn in utl.kspairs(wfs) do
|
||||||
|
ifaces[#ifaces+1] = wfs[ifn]
|
||||||
|
|
||||||
|
-- only bridges may cover more than one interface
|
||||||
|
--if not self:is_bridge() then
|
||||||
|
-- break
|
||||||
|
--end
|
||||||
end
|
end
|
||||||
|
|
||||||
return ifaces
|
return ifaces
|
||||||
|
@ -785,11 +816,12 @@ function network.contains_interface(self, ifname)
|
||||||
ifname = ifname:match("[^%s:]+")
|
ifname = ifname:match("[^%s:]+")
|
||||||
end
|
end
|
||||||
|
|
||||||
local ifn
|
if self:is_virtual() and self:proto() .. "-" .. self.sid == ifname then
|
||||||
if self:is_virtual() then
|
return true
|
||||||
ifn = self:proto() .. "-" .. self.sid
|
elseif self:is_bridge() and "br-" .. self.sid == ifname then
|
||||||
return ifname == ifn
|
return true
|
||||||
else
|
else
|
||||||
|
local ifn
|
||||||
for ifn in utl.imatch(self:get("ifname")) do
|
for ifn in utl.imatch(self:get("ifname")) do
|
||||||
ifn = ifn:match("[^:]+")
|
ifn = ifn:match("[^:]+")
|
||||||
if ifn == ifname then
|
if ifn == ifname then
|
||||||
|
|
Loading…
Reference in a new issue