summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r--modules/luci-base/luasrc/model/network.lua168
-rw-r--r--modules/luci-base/luasrc/sys/iptparser.lua18
-rw-r--r--modules/luci-base/luasrc/util.lua19
-rw-r--r--modules/luci-base/luasrc/view/sysauth.htm8
4 files changed, 139 insertions, 74 deletions
diff --git a/modules/luci-base/luasrc/model/network.lua b/modules/luci-base/luasrc/model/network.lua
index 9cd7c87c0c..2d8336bf33 100644
--- a/modules/luci-base/luasrc/model/network.lua
+++ b/modules/luci-base/luasrc/model/network.lua
@@ -30,7 +30,7 @@ protocol = utl.class()
local _protocols = { }
-local _interfaces, _bridge, _switch, _tunnel
+local _interfaces, _bridge, _switch, _tunnel, _swtopo
local _ubusnetcache, _ubusdevcache, _ubuswificache
local _uci
@@ -193,7 +193,6 @@ function _iface_ignore(x)
return false
end
-
function init(cursor)
_uci = cursor or _uci or uci.cursor()
@@ -201,6 +200,7 @@ function init(cursor)
_bridge = { }
_switch = { }
_tunnel = { }
+ _swtopo = { }
_ubusnetcache = { }
_ubusdevcache = { }
@@ -210,7 +210,6 @@ function init(cursor)
local n, i
for n, i in ipairs(nxo.getifaddrs()) do
local name = i.name:match("[^:]+")
- local prnt = name:match("^([^%.]+)%.")
if _iface_virtual(name) then
_tunnel[name] = true
@@ -226,11 +225,6 @@ function init(cursor)
ip6addrs = { }
}
- if prnt then
- _switch[name] = true
- _switch[prnt] = true
- end
-
if i.family == "packet" then
_interfaces[name].flags = i.flags
_interfaces[name].stats = i.data
@@ -266,6 +260,79 @@ function init(cursor)
end
end
+ -- read switch topology
+ local boardinfo = jsc.parse(nfs.readfile("/etc/board.json") or "")
+ if type(boardinfo) == "table" and type(boardinfo.switch) == "table" then
+ local switch, layout
+ for switch, layout in pairs(boardinfo.switch) do
+ if type(layout) == "table" and type(layout.ports) == "table" then
+ local _, port
+ local ports = { }
+ local nports = { }
+ local netdevs = { }
+
+ for _, port in ipairs(layout.ports) do
+ if type(port) == "table" and
+ type(port.num) == "number" and
+ (type(port.role) == "string" or
+ type(port.device) == "string")
+ then
+ local spec = {
+ num = port.num,
+ role = port.role or "cpu",
+ index = port.index or port.num
+ }
+
+ if port.device then
+ spec.device = port.device
+ spec.tagged = port.need_tag
+ netdevs[tostring(port.num)] = port.device
+ end
+
+ ports[#ports+1] = spec
+
+ if port.role then
+ nports[port.role] = (nports[port.role] or 0) + 1
+ end
+ end
+ end
+
+ table.sort(ports, function(a, b)
+ if a.role ~= b.role then
+ return (a.role < b.role)
+ end
+
+ return (a.index < b.index)
+ end)
+
+ local pnum, role
+ for _, port in ipairs(ports) do
+ if port.role ~= role then
+ role = port.role
+ pnum = 1
+ end
+
+ if role == "cpu" then
+ port.label = "CPU (%s)" % port.device
+ elseif nports[role] > 1 then
+ port.label = "%s %d" %{ role:upper(), pnum }
+ pnum = pnum + 1
+ else
+ port.label = role:upper()
+ end
+
+ port.role = nil
+ port.index = nil
+ end
+
+ _swtopo[switch] = {
+ ports = ports,
+ netdevs = netdevs
+ }
+ end
+ end
+ end
+
return _M
end
@@ -474,41 +541,23 @@ function get_interface(self, i)
end
end
-local function swdev_from_board_json()
- local boardinfo = jsc.parse(nfs.readfile("/etc/board.json") or "")
- if type(boardinfo) == "table" and type(boardinfo.network) == "table" then
- local net, val
- for net, val in pairs(boardinfo.network) do
- if type(val) == "table" and type(val.ifname) == "string" and
- val.create_vlan == true
- then
- return val.ifname
- end
- end
- end
- return nil
-end
-
function get_interfaces(self)
local iface
local ifaces = { }
- local seen = { }
local nfs = { }
- local baseof = { }
-- find normal interfaces
_uci:foreach("network", "interface",
function(s)
for iface in utl.imatch(s.ifname) do
if not _iface_ignore(iface) and not _iface_virtual(iface) and not _wifi_iface(iface) then
- seen[iface] = true
nfs[iface] = interface(iface)
end
end
end)
for iface in utl.kspairs(_interfaces) do
- if not (seen[iface] or _iface_ignore(iface) or _iface_virtual(iface) or _wifi_iface(iface)) then
+ if not (nfs[iface] or _iface_ignore(iface) or _iface_virtual(iface) or _wifi_iface(iface)) then
nfs[iface] = interface(iface)
end
end
@@ -516,34 +565,32 @@ function get_interfaces(self)
-- find vlan interfaces
_uci:foreach("network", "switch_vlan",
function(s)
- if not s.device then
+ if type(s.ports) ~= "string" or
+ type(s.device) ~= "string" or
+ type(_swtopo[s.device]) ~= "table"
+ then
return
end
- local base = baseof[s.device]
- if not base then
- if not s.device:match("^eth%d") then
- local l
- for l in utl.execi("swconfig dev %q help 2>/dev/null" % s.device) do
- if not base then
- base = l:match("^%w+: (%w+)")
- end
+ local pnum, ptag
+ for pnum, ptag in s.ports:gmatch("(%d+)([tu]?)") do
+ local netdev = _swtopo[s.device].netdevs[pnum]
+ if netdev then
+ if not nfs[netdev] then
+ nfs[netdev] = interface(netdev)
end
- if not base or not base:match("^eth%d") then
- base = swdev_from_board_json() or "eth0"
+ _switch[netdev] = true
+
+ if ptag == "t" then
+ local vid = tonumber(s.vid or s.vlan)
+ if vid ~= nil and vid >= 0 and vid <= 4095 then
+ local iface = "%s.%d" %{ netdev, vid }
+ if not nfs[iface] then
+ nfs[iface] = interface(iface)
+ end
+ _switch[iface] = true
+ end
end
- else
- base = s.device
- end
- baseof[s.device] = base
- end
-
- local vid = tonumber(s.vid or s.vlan)
- if vid ~= nil and vid >= 0 and vid <= 4095 then
- local iface = "%s.%d" %{ base, vid }
- if not seen[iface] then
- seen[iface] = true
- nfs[iface] = interface(iface)
end
end
end)
@@ -685,6 +732,10 @@ function get_wan6dev(self)
return stat and interface(stat.l3_device or stat.device)
end
+function get_switch_topologies(self)
+ return _swtopo
+end
+
function network(name, proto)
if name then
@@ -1140,10 +1191,7 @@ end
function interface.shortname(self)
if self.wif then
- return "%s %q" %{
- self.wif:active_mode(),
- self.wif:active_ssid() or self.wif:active_bssid()
- }
+ return self.wif:shortname()
else
return self.ifname
end
@@ -1154,7 +1202,7 @@ function interface.get_i18n(self)
return "%s: %s %q" %{
lng.translate("Wireless Network"),
self.wif:active_mode(),
- self.wif:active_ssid() or self.wif:active_bssid()
+ self.wif:active_ssid() or self.wif:active_bssid() or self.wif:id()
}
else
return "%s: %q" %{ self:get_type_i18n(), self:name() }
@@ -1170,7 +1218,11 @@ function interface.get_type_i18n(self)
elseif x == "switch" then
return lng.translate("Ethernet Switch")
elseif x == "vlan" then
- return lng.translate("VLAN Interface")
+ if _switch[self.ifname] then
+ return lng.translate("Switch VLAN")
+ else
+ return lng.translate("Software VLAN")
+ end
elseif x == "tunnel" then
return lng.translate("Tunnel Interface")
else
@@ -1593,7 +1645,7 @@ end
function wifinet.shortname(self)
return "%s %q" %{
lng.translate(self:active_mode()),
- self:active_ssid() or self:active_bssid()
+ self:active_ssid() or self:active_bssid() or self:id()
}
end
@@ -1601,7 +1653,7 @@ function wifinet.get_i18n(self)
return "%s: %s %q (%s)" %{
lng.translate("Wireless Network"),
lng.translate(self:active_mode()),
- self:active_ssid() or self:active_bssid(),
+ self:active_ssid() or self:active_bssid() or self:id(),
self:ifname()
}
end
diff --git a/modules/luci-base/luasrc/sys/iptparser.lua b/modules/luci-base/luasrc/sys/iptparser.lua
index 64353956b0..a9dbc30826 100644
--- a/modules/luci-base/luasrc/sys/iptparser.lua
+++ b/modules/luci-base/luasrc/sys/iptparser.lua
@@ -39,15 +39,15 @@ function IptParser.__init__( self, family )
else
self._nulladdr = "::/0"
self._tables = { "filter", "mangle", "raw" }
- local ok, lines = pcall(io.lines, "/proc/net/ip6_tables_names")
- if ok and lines then
- local line
- for line in lines do
- if line == "nat" then
- self._tables = { "filter", "nat", "mangle", "raw" }
- end
- end
- end
+ local ok, lines = pcall(io.lines, "/proc/net/ip6_tables_names")
+ if ok and lines then
+ local line
+ for line in lines do
+ if line == "nat" then
+ self._tables = { "filter", "nat", "mangle", "raw" }
+ end
+ end
+ end
self._command = "ip6tables -t %s --line-numbers -nxvL"
end
diff --git a/modules/luci-base/luasrc/util.lua b/modules/luci-base/luasrc/util.lua
index 896e36b45f..0e7334be87 100644
--- a/modules/luci-base/luasrc/util.lua
+++ b/modules/luci-base/luasrc/util.lua
@@ -16,7 +16,7 @@ local _ubus_connection = nil
local getmetatable, setmetatable = getmetatable, setmetatable
local rawget, rawset, unpack = rawget, rawset, unpack
-local tostring, type, assert = tostring, type, assert
+local tostring, type, assert, error = tostring, type, assert, error
local ipairs, pairs, next, loadstring = ipairs, pairs, next, loadstring
local require, pcall, xpcall = require, pcall, xpcall
local collectgarbage, get_memory_limit = collectgarbage, get_memory_limit
@@ -27,14 +27,27 @@ module "luci.util"
-- Pythonic string formatting extension
--
getmetatable("").__mod = function(a, b)
+ local ok, res
+
if not b then
return a
elseif type(b) == "table" then
+ local k, _
for k, _ in pairs(b) do if type(b[k]) == "userdata" then b[k] = tostring(b[k]) end end
- return a:format(unpack(b))
+
+ ok, res = pcall(a.format, a, unpack(b))
+ if not ok then
+ error(res, 2)
+ end
+ return res
else
if type(b) == "userdata" then b = tostring(b) end
- return a:format(b)
+
+ ok, res = pcall(a.format, a, b)
+ if not ok then
+ error(res, 2)
+ end
+ return res
end
end
diff --git a/modules/luci-base/luasrc/view/sysauth.htm b/modules/luci-base/luasrc/view/sysauth.htm
index e207504911..f6b0f5706a 100644
--- a/modules/luci-base/luasrc/view/sysauth.htm
+++ b/modules/luci-base/luasrc/view/sysauth.htm
@@ -7,14 +7,14 @@
<%+header%>
<form method="post" action="<%=pcdata(luci.http.getenv("REQUEST_URI"))%>">
+ <%- if fuser then %>
+ <div class="errorbox"><%:Invalid username and/or password! Please try again.%></div>
+ <% end -%>
+
<div class="cbi-map">
<h2 name="content"><%:Authorization Required%></h2>
<div class="cbi-map-descr">
<%:Please enter your username and password.%>
- <%- if fuser then %>
- <div class="error"><%:Invalid username and/or password! Please try again.%></div>
- <br />
- <% end -%>
</div>
<fieldset class="cbi-section"><fieldset class="cbi-section-node">
<div class="cbi-value">