libs/core: allow ifaces to be part of multiple networks in luci.model.network

This commit is contained in:
Jo-Philipp Wich 2012-06-26 21:49:07 +00:00
parent 92f0643e2c
commit 699391a559

View file

@ -795,16 +795,10 @@ end
function protocol.add_interface(self, ifname) function protocol.add_interface(self, ifname)
ifname = _M:ifnameof(ifname) ifname = _M:ifnameof(ifname)
if ifname and not self:is_floating() then if ifname and not self:is_floating() then
-- remove the interface from all ifaces
_uci_real:foreach("network", "interface",
function(s)
_filter("network", s['.name'], "ifname", ifname)
end)
-- if its a wifi interface, change its network option -- if its a wifi interface, change its network option
local wif = _wifi_lookup(ifname) local wif = _wifi_lookup(ifname)
if wif then if wif then
_uci_real:set("wireless", wif, "network", self.sid) _append("wireless", wif, "network", self.sid)
-- add iface to our iface list -- add iface to our iface list
else else
@ -818,7 +812,7 @@ function protocol.del_interface(self, ifname)
if ifname and not self:is_floating() then if ifname and not self:is_floating() then
-- if its a wireless interface, clear its network option -- if its a wireless interface, clear its network option
local wif = _wifi_lookup(ifname) local wif = _wifi_lookup(ifname)
if wif then _uci_real:delete("wireless", wif, "network") end if wif then _filter("wireless", wif, "network", self.sid) end
-- remove the interface -- remove the interface
_filter("network", self.sid, "ifname", ifname) _filter("network", self.sid, "ifname", ifname)
@ -909,7 +903,12 @@ function protocol.contains_interface(self, ifname)
local wif = _wifi_lookup(ifname) local wif = _wifi_lookup(ifname)
if wif then if wif then
return (_uci_real:get("wireless", wif, "network") == self.sid) local n
for n in utl.imatch(_uci_real:get("wireless", wif, "network")) do
if n == self.sid then
return true
end
end
end end
end end
@ -1032,7 +1031,6 @@ function interface.ports(self)
for _, iface in ipairs(members) do for _, iface in ipairs(members) do
ifaces[#ifaces+1] = interface(iface) ifaces[#ifaces+1] = interface(iface)
end end
return ifaces
end end
end end
@ -1096,24 +1094,25 @@ function interface.rx_packets(self)
end end
function interface.get_network(self) function interface.get_network(self)
if not self.network then return self:get_networks()[1]
if self.dev and self.dev.network then end
self.network = _M:get_network(self.dev.network)
end
end
if not self.network then function interface.get_networks(self)
local net if not self.networks then
local nets = { }
local _, net
for _, net in ipairs(_M:get_networks()) do for _, net in ipairs(_M:get_networks()) do
if net:contains_interface(self.ifname) or if net:contains_interface(self.ifname) or
net:ifname() == self.ifname net:ifname() == self.ifname
then then
self.network = net nets[#nets+1] = net
return net
end end
end end
table.sort(nets, function(a, b) return a.sid < b.sid end)
self.networks = nets
return nets
else else
return self.network return self.networks
end end
end end
@ -1433,10 +1432,19 @@ function wifinet.adminlink(self)
end end
function wifinet.get_network(self) function wifinet.get_network(self)
local net = tostring(self.iwdata.network) return self:get_networks()[1]
if net and _uci_real:get("network", net) == "interface" then end
return network(net)
function wifinet.get_networks(self)
local nets = { }
local net
for net in utl.imatch(tostring(self.iwdata.network)) do
if _uci_real:get("network", net) == "interface" then
nets[#nets+1] = network(net)
end
end end
table.sort(nets, function(a, b) return a.sid < b.sid end)
return nets
end end
function wifinet.get_interface(self) function wifinet.get_interface(self)