X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fcore%2Fluasrc%2Fmodel%2Fnetwork.lua;h=28237e49a80abf8fa941b1dd30b0e94524e8ea03;hb=ea294f0b645a04db24a7dc75057cec48f6493bd7;hp=101bba38d89135dc0cbb6265054bb573f20f4f1e;hpb=2b7ba80b8a441356f3b1b3a51cc120843c6c1b68;p=project%2Fluci.git diff --git a/libs/core/luasrc/model/network.lua b/libs/core/luasrc/model/network.lua index 101bba38d..28237e49a 100644 --- a/libs/core/luasrc/model/network.lua +++ b/libs/core/luasrc/model/network.lua @@ -102,7 +102,7 @@ function _set(c, s, o, v) if type(v) == "boolean" then v = v and "1" or "0" end return uci_r:set(c, s, o, v) else - return uci_r:del(c, s, o, v) + return uci_r:delete(c, s, o) end end @@ -154,14 +154,14 @@ function _iface_ignore(x) return ( 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("^3g-%w") or x:match("^ppp-%w") or x:match("^pppoe-%w") or - x:match("^pppoa-%w") or x == "lo" + 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 == "sit0" or x == "lo" ) end function init(cursor) - uci_r = cursor or uci.cursor() + uci_r = cursor or uci_r or uci.cursor() uci_s = uci_r:substate() ifs = { } @@ -275,26 +275,14 @@ end function del_network(self, n) local r = uci_r:delete("network", n) if r then - uci_r:foreach("network", "alias", - function(s) - if s.interface == n then - uci_r:delete("network", s['.name']) - end - end) + uci_r:delete_all("network", "alias", + function(s) return (s.interface == n) end) - uci_r:foreach("network", "route", - function(s) - if s.interface == n then - uci_r:delete("network", s['.name']) - end - end) + uci_r:delete_all("network", "route", + function(s) return (s.interface == n) end) - uci_r:foreach("network", "route6", - function(s) - if s.interface == n then - uci_r:delete("network", s['.name']) - end - end) + uci_r:delete_all("network", "route6", + function(s) return (s.interface == n) end) uci_r:foreach("wireless", "wifi-iface", function(s) @@ -302,8 +290,6 @@ function del_network(self, n) uci_r:delete("wireless", s['.name'], "network") end end) - - uci_r:delete("network", n) end return r end @@ -372,14 +358,30 @@ end function get_interfaces(self) local iface local ifaces = { } + local seen = { } + local nfs = { } -- find normal interfaces + uci_r:foreach("network", "interface", + function(s) + for iface in utl.imatch(s.ifname) do + if not _iface_ignore(iface) and not _wifi_iface(iface) then + seen[iface] = true + nfs[iface] = interface(iface) + end + end + end) + for iface in utl.kspairs(ifs) do - if not _iface_ignore(iface) and not _wifi_iface(iface) then - ifaces[#ifaces+1] = interface(iface) + if not (seen[iface] or _iface_ignore(iface) or _wifi_iface(iface)) then + nfs[iface] = interface(iface) end end + for iface in utl.kspairs(nfs) do + ifaces[#ifaces+1] = nfs[iface] + end + -- find wifi interfaces local num = { } local wfs = { } @@ -479,6 +481,7 @@ function network.ifname(self) elseif self:is_virtual() then return p .. "-" .. self.sid else + local num = { } local dev = self:_get("ifname") or uci_r:get("network", self.sid, "ifname") @@ -523,6 +526,15 @@ function network.name(self) return self.sid end +function network.uptime(self) + local cnt = tonumber(uci_s:get("network", self.sid, "connect_time")) + if cnt ~= nil then + return nxo.sysinfo().uptime - cnt + else + return 0 + end +end + function network.is_bridge(self) return (self:type() == "bridge") end @@ -530,7 +542,7 @@ end function network.is_virtual(self) local p = self:proto() return ( - p == "3g" or p == "6in4" or p == "ppp" or + p == "3g" or p == "6in4" or p == "6to4" or p == "ppp" or p == "pppoe" or p == "pppoa" ) end @@ -609,7 +621,7 @@ function network.get_interfaces(self) ifaces = { interface(ifn) } else local nfs = { } - for ifn in self:_get("ifname"):gmatch("%S+") do + for ifn in utl.imatch(self:get("ifname")) do ifn = ifn:match("[^:]+") nfs[ifn] = interface(ifn) end @@ -651,7 +663,7 @@ function network.contains_interface(self, ifname) ifn = self:proto() .. "-" .. self.sid return ifname == ifn else - for ifn in self:_get("ifname"):gmatch("%S+") do + for ifn in utl.imatch(self:get("ifname")) do ifn = ifn:match("[^:]+") if ifn == ifname then return true @@ -686,7 +698,7 @@ function interface.name(self) end function interface.mac(self) - return self.dev and self.dev or "00:00:00:00:00:00" + return self.dev and self.dev.macaddr or "00:00:00:00:00:00" end function interface.ipaddrs(self) @@ -974,7 +986,11 @@ function wifinet.name(self) end function wifinet.ifname(self) - return self.iwinfo.ifname or self.wdev + local ifname = self.iwinfo.ifname + if not ifname or ifname:match("^wifi%d") or ifname:match("^radio%d") then + ifname = self.wdev + end + return ifname end function wifinet.get_device(self)