libs/core: remove route enabled check in network model after netifd update in OpenWrt...
[project/luci.git] / libs / core / luasrc / model / network.lua
index d062164..c2c2e66 100644 (file)
@@ -38,7 +38,7 @@ module "luci.model.network"
 
 
 IFACE_PATTERNS_VIRTUAL  = { }
-IFACE_PATTERNS_IGNORE   = { "^wmaster%d", "^wifi%d", "^hwsim%d", "^imq%d", "^ifb%d", "^mon%.wlan%d", "^sit%d", "^lo$" }
+IFACE_PATTERNS_IGNORE   = { "^wmaster%d", "^wifi%d", "^hwsim%d", "^imq%d", "^ifb%d", "^mon%.wlan%d", "^sit%d", "^gre%d", "^lo$" }
 IFACE_PATTERNS_WIRELESS = { "^wlan%d", "^wl%d", "^ath%d", "^%w+%.network%d" }
 
 
@@ -585,6 +585,44 @@ function del_wifinet(self, net)
        return false
 end
 
+function get_status_by_route(self, addr, mask)
+       local _, object
+       for _, object in ipairs(_ubus:objects()) do
+               local net = object:match("^network%.interface%.(.+)")
+               if net then
+                       local s = _ubus:call(object, "status", {})
+                       if s and s.route then
+                               local rt
+                               for _, rt in ipairs(s.route) do
+                                       if rt.target == addr and rt.mask == mask then
+                                               return net, s
+                                       end
+                               end
+                       end
+               end
+       end
+end
+
+function get_wannet(self)
+       local net = self:get_status_by_route("0.0.0.0", 0)
+       return net and network(net)
+end
+
+function get_wandev(self)
+       local _, stat = self:get_status_by_route("0.0.0.0", 0)
+       return stat and interface(stat.l3_device or stat.device)
+end
+
+function get_wan6net(self)
+       local net = self:get_status_by_route("::", 0)
+       return net and network(net)
+end
+
+function get_wan6dev(self)
+       local _, stat = self:get_status_by_route("::", 0)
+       return stat and interface(stat.l3_device or stat.device)
+end
+
 
 function network(name, proto)
        if name then
@@ -782,9 +820,12 @@ function protocol.is_empty(self)
 
                _uci_real:foreach("wireless", "wifi-iface",
                        function(s)
-                               if s.network == self.sid then
-                                       rv = false
-                                       return false
+                               local n
+                               for n in utl.imatch(s.network) do
+                                       if n == self.sid then
+                                               rv = false
+                                               return false
+                                       end
                                end
                        end)