summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-06-26 22:19:27 +0000
committerJo-Philipp Wich <jow@openwrt.org>2012-06-26 22:19:27 +0000
commit0f3175ad42baa9c80606026d6a203cf9444b647b (patch)
tree3b76cb5ff0900a170806f107fb004e2784742e83
parentc0451d8a72ac139efd85638ddc95a9935664b2ec (diff)
libs/core: implement get_wandev(), get_wan6dev(), get_wannet() and get_wan6net() in luci.model.network
-rw-r--r--libs/core/luasrc/model/network.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/libs/core/luasrc/model/network.lua b/libs/core/luasrc/model/network.lua
index 1764a3d41..a0ff58124 100644
--- a/libs/core/luasrc/model/network.lua
+++ b/libs/core/luasrc/model/network.lua
@@ -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