libs/core: ignore sit0 in network model
[project/luci.git] / libs / core / luasrc / model / network.lua
index bb98f82..28237e4 100644 (file)
@@ -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,8 +154,8 @@ 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
 
@@ -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
@@ -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)