diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-05-07 08:54:23 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-05-07 08:55:22 +0200 |
commit | 6b7afabcdd270a5215a225553dda08e0cd1c5e40 (patch) | |
tree | d0fb5013b7f4de44d8c671142185571fb3adc68c | |
parent | 8648f7e8cea31de61030377ab16aed72f2371a2f (diff) |
luci-mod-admin-network: fix VLAN "add" button for empty switches
Fixes OpenWrt FS#2270.
Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2270
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | modules/luci-mod-network/luasrc/model/cbi/admin_network/vlan.lua | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/modules/luci-mod-network/luasrc/model/cbi/admin_network/vlan.lua b/modules/luci-mod-network/luasrc/model/cbi/admin_network/vlan.lua index d79b3c470..edeb193ef 100644 --- a/modules/luci-mod-network/luasrc/model/cbi/admin_network/vlan.lua +++ b/modules/luci-mod-network/luasrc/model/cbi/admin_network/vlan.lua @@ -42,6 +42,8 @@ local update_interfaces = function(old_ifname, new_ifname) end end +local vlan_already_created + m.uci:foreach("network", "switch", function(x) local sid = x['.name'] @@ -200,8 +202,29 @@ m.uci:foreach("network", "switch", -- When creating a new vlan, preset it with the highest found vid + 1. s.create = function(self, section, origin) - -- Filter by switch - if m:get(origin, "device") ~= switch_name then + -- VLAN has already been created for another switch + if vlan_already_created then + return + + -- VLAN add button was pressed in an empty VLAN section so only + -- accept the create event if our switch is without existing VLANs + elseif origin == "" then + local is_empty_switch = true + + m.uci:foreach("network", "switch_vlan", + function(s) + if s.device == switch_name then + is_empty_switch = false + return false + end + end) + + if not is_empty_switch then + return + end + + -- VLAN was created for another switch + elseif m:get(origin, "device") ~= switch_name then return end @@ -227,6 +250,8 @@ m.uci:foreach("network", "switch", m:set(sid, has_vlan4k, max_id + 1) end + vlan_already_created = true + return sid end |