http://www.apache.org/licenses/LICENSE-2.0
-$Id$
]]--
-m = Map("network", translate("Switch"), translate("The network ports on your router can be combined to several <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s in which computers can communicate directly with each other. <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network."))
+m = Map("network", translate("Switch"), translate("The network ports on this device can be combined to several <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s in which computers can communicate directly with each other. <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network."))
+
+local fs = require "nixio.fs"
+local switches = { }
m.uci:foreach("network", "switch",
function(x)
local max_vid = 16
local num_vlans = 16
local num_ports = 6
- local cpu_port = 5
+ local cpu_port = tonumber(fs.readfile("/proc/switch/eth0/cpuport") or 5)
local switch_title
local enable_vlan4k = false
s:option(Flag, has_vlan, translate("Enable VLAN functionality"))
end
- if enable_vlan4k then
- s:option(Flag, "enable_vlan4k", translate("Enable 4K VLANs"))
- end
-
if has_learn then
x = s:option(Flag, has_learn, translate("Enable learning and aging"))
x.default = x.enabled
end
end)
- m.uci:set("network", sid, "device", switch_name)
- m.uci:set("network", sid, "vlan", max_nr + 1)
+ m:set(sid, "device", switch_name)
+ m:set(sid, "vlan", max_nr + 1)
if has_vlan4k then
- m.uci:set("network", sid, has_vlan4k, max_id + 1)
+ m:set(sid, has_vlan4k, max_id + 1)
end
return sid
end
- local vid = s:option(Value, has_vlan4k or "vlan", "VLAN ID")
+ local vid = s:option(Value, has_vlan4k or "vlan", "VLAN ID", "<div id='portstatus-%s'></div>" % switch_name)
+ local mx_vid = has_vlan4k and 4094 or (num_vlans - 1)
vid.rmempty = false
vid.forcewrite = true
vid.vlan_used = { }
+ vid.datatype = "and(uinteger,range("..min_vid..","..mx_vid.."))"
-- Validate user provided VLAN ID, make sure its within the bounds
-- allowed by the switch.
end
end
- m.uci:set("network", section, "ports", table.concat(p, " "))
+ if enable_vlan4k then
+ m:set(sid, "enable_vlan4k", "1")
+ end
+
+ m:set(section, "ports", table.concat(p, " "))
return Value.write(self, section, value)
end
-- Build per-port off/untagged/tagged choice lists.
local pt
- local off = 1
for pt = 0, num_ports - 1 do
local title
if pt == cpu_port then
- off = 0
title = translate("CPU")
else
- title = translatef("Port %d", pt + off)
+ title = translatef("Port %d", pt)
end
local po = s:option(ListValue, tostring(pt), title)
port_opts[#port_opts+1] = po
end
+
+ switches[#switches+1] = switch_name
end
)
+-- Switch status template
+s = m:section(SimpleSection)
+s.template = "admin_network/switch_status"
+s.switches = switches
+
return m