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",
local has_learn = nil
local has_vlan4k = nil
local has_jumbo3 = nil
+ local has_mirror = nil
local min_vid = 0
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 num_ports = cpu_port + 1
local switch_title
local enable_vlan4k = false
elseif line:match(": enable_learning") then
has_learn = "enable_learning"
+ elseif line:match(": enable_mirror_rx") then
+ has_mirror = "enable_mirror_rx"
+
elseif line:match(": max_length") then
has_jumbo3 = "max_length"
end
x.rmempty = true
end
+ -- Does this switch support port mirroring?
+ if has_mirror then
+ s:option(Flag, "enable_mirror_rx", translate("Enable mirroring of incoming packets"))
+ s:option(Flag, "enable_mirror_tx", translate("Enable mirroring of outgoing packets"))
+
+ local sp = s:option(ListValue, "mirror_source_port", translate("Mirror source port"))
+ local mp = s:option(ListValue, "mirror_monitor_port", translate("Mirror monitor port"))
+
+ local pt
+ for pt = 0, num_ports - 1 do
+ local name
+
+ name = (pt == cpu_port) and translate("CPU") or translatef("Port %d", pt)
+
+ sp:value(pt, name)
+ mp:value(pt, name)
+ end
+ end
-- VLAN table
s = m:section(TypedSection, "switch_vlan",
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)
+ local mx_vid = has_vlan4k and 4094 or (num_vlans - 1)
vid.rmempty = false
vid.forcewrite = true