+ -- 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
+ return
+ end
+
+ local sid = TypedSection.create(self, section)
+
+ local max_nr = 0
+ local max_id = 0
+
+ m.uci:foreach("network", "switch_vlan",
+ function(s)
+ if s.device == switch_name then
+ local nr = tonumber(s.vlan)
+ local id = has_vlan4k and tonumber(s[has_vlan4k])
+ if nr ~= nil and nr > max_nr then max_nr = nr end
+ if id ~= nil and id > max_id then max_id = id end
+ end
+ end)
+
+ m:set(sid, "device", switch_name)
+ m:set(sid, "vlan", max_nr + 1)
+
+ if has_vlan4k then
+ m:set(sid, has_vlan4k, max_id + 1)
+ end
+
+ return sid
+ end
+
+