X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fcore%2Fluasrc%2Fmodel%2Fnetwork.lua;h=68ad04fae09e99837a4baeef44ef6e5fa867d2d4;hb=b818354c9420fe8a9bc811352c4a1f21474a2b23;hp=30e75b9e4c4d69dc48e007dd7bad7cf3a9bf4b89;hpb=9d83aafb789a5c4ffdefcc3e336354485e80fc38;p=project%2Fluci.git diff --git a/libs/core/luasrc/model/network.lua b/libs/core/luasrc/model/network.lua index 30e75b9e4..68ad04fae 100644 --- a/libs/core/luasrc/model/network.lua +++ b/libs/core/luasrc/model/network.lua @@ -155,7 +155,7 @@ function _iface_ignore(x) x:match("^wmaster%d") or x:match("^wifi%d") or x:match("^hwsim%d") or x:match("^imq%d") or x:match("^mon.wlan%d") or x:match("^6in4-%w") or x:match("^6to4-%w") or x:match("^3g-%w") or x:match("^ppp-%w") or - x:match("^pppoe-%w") or x:match("^pppoa-%w") or x == "lo" + x:match("^pppoe-%w") or x:match("^pppoa-%w") or x == "sit0" or x == "lo" ) end @@ -242,10 +242,19 @@ function has_ipv6(self) end function add_network(self, n, options) - if n and #n > 0 and n:match("^[a-zA-Z0-9_]+$") and not self:get_network(n) then + local oldnet = self:get_network(n) + if n and #n > 0 and n:match("^[a-zA-Z0-9_]+$") and not oldnet then if uci_r:section("network", "interface", n, options) then return network(n) end + elseif oldnet and oldnet:is_empty() then + if options then + local k, v + for k, v in pairs(options) do + oldnet:set(k, v) + end + end + return oldnet end end @@ -482,10 +491,11 @@ function network.ifname(self) return p .. "-" .. self.sid else local num = { } - local dev = self:_get("ifname") or - uci_r:get("network", self.sid, "ifname") + local dev = uci_r:get("network", self.sid, "ifname") or + uci_s:get("network", self.sid, "ifname") - dev = dev and dev:match("%S+") + dev = (type(dev) == "table") and dev[1] or dev + dev = (dev ~= nil) and dev:match("%S+") if not dev then uci_r:foreach("wireless", "wifi-iface", @@ -507,10 +517,18 @@ function network.ifname(self) end function network.device(self) - local dev = self:_get("device") + local dev = uci_r:get("network", self.sid, "device") or + uci_s:get("network", self.sid, "device") + + dev = (type(dev) == "table") and dev[1] or dev + if not dev or dev:match("[^%w%-%.%s]") then - dev = uci_r:get("network", self.sid, "ifname") + dev = uci_r:get("network", self.sid, "ifname") or + uci_s:get("network", self.sid, "ifname") + + dev = (type(dev) == "table") and dev[1] or dev end + return dev end @@ -834,7 +852,9 @@ function interface.get_network(self) if not self.network then local net for _, net in ipairs(_M:get_networks()) do - if net:contains_interface(self.ifname) then + if net:contains_interface(self.ifname) or + net:ifname() == self.ifname + then self.network = net return net end @@ -936,21 +956,22 @@ wifinet = utl.class() function wifinet.__init__(self, net, data) self.sid = net - local dev = uci_s:get("wireless", self.sid, "ifname") - if not dev then - local num = { } - uci_r:foreach("wireless", "wifi-iface", - function(s) - if s.device then - num[s.device] = num[s.device] and num[s.device] + 1 or 1 - if s['.name'] == self.sid then - dev = "%s.network%d" %{ s.device, num[s.device] } - return false - end + local num = { } + local netid + uci_r:foreach("wireless", "wifi-iface", + function(s) + if s.device then + num[s.device] = num[s.device] and num[s.device] + 1 or 1 + if s['.name'] == self.sid then + netid = "%s.network%d" %{ s.device, num[s.device] } + return false end - end) - end + end + end) + + local dev = uci_s:get("wireless", self.sid, "ifname") or netid + self.netid = netid self.wdev = dev self.iwinfo = dev and sys.wifi.getiwinfo(dev) or { } self.iwdata = data or uci_s:get_all("wireless", self.sid) or @@ -1006,7 +1027,7 @@ end function wifinet.active_mode(self) local m = _stror(self.iwinfo.mode, self.iwdata.mode) or "ap" - if m == "ap" then m = "AP" + if m == "ap" then m = "Master" elseif m == "sta" then m = "Client" elseif m == "adhoc" then m = "Ad-Hoc" elseif m == "mesh" then m = "Mesh" @@ -1108,8 +1129,7 @@ function wifinet.get_i18n(self) end function wifinet.adminlink(self) - return dsp.build_url("admin", "network", "wireless", - self.iwdata.device, self.wdev) + return dsp.build_url("admin", "network", "wireless", self.netid) end function wifinet.get_network(self)