luci-base: optimize luci.tools.webadmin.iface_get_network()

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
Jo-Philipp Wich 2015-01-23 15:26:33 +01:00
parent 671566d701
commit 40066a6799

View file

@ -83,23 +83,15 @@ function firewall_find_zone(name)
end end
function iface_get_network(iface) function iface_get_network(iface)
local devs = util.ubus("network.device", "status", { }) local link = ip.link(tostring(iface))
local _, net, subdev, dev, status if link.master then
iface = link.master
for dev, status in pairs(devs) do
if status["bridge-members"] then
for _, subdev in ipairs(status["bridge-members"]) do
if subdev == iface then
iface = dev
break
end
end
end
end end
local cur = uci.cursor() local cur = uci.cursor()
local dump = util.ubus("network.interface", "dump", { }) local dump = util.ubus("network.interface", "dump", { })
if dump then if dump then
local _, net
for _, net in ipairs(dump.interface) do for _, net in ipairs(dump.interface) do
if net.l3_device == iface or net.device == iface then if net.l3_device == iface or net.device == iface then
-- cross check with uci to filter out @name style aliases -- cross check with uci to filter out @name style aliases