libs/core: ignore sit0 in network model
[project/luci.git] / libs / core / luasrc / model / network.lua
index 7882c81..28237e4 100644 (file)
@@ -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
 
@@ -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
@@ -495,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")
 
@@ -539,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
@@ -990,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)