summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-11-21 20:13:53 +0000
committerJo-Philipp Wich <jow@openwrt.org>2012-11-21 20:13:53 +0000
commit06c8c28bab9975149f94397f3b7027712c0ba424 (patch)
treed83d4cc191888378774c091d7a1b01422c59eeb1
parent7399e07593f79334ae5342faf5c9f0687caf6c2d (diff)
libs/core: introduce get_status_by_address() in luci.model.network
-rw-r--r--libs/core/luasrc/model/network.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/core/luasrc/model/network.lua b/libs/core/luasrc/model/network.lua
index cc572298c..56f1751f8 100644
--- a/libs/core/luasrc/model/network.lua
+++ b/libs/core/luasrc/model/network.lua
@@ -623,6 +623,32 @@ function get_status_by_route(self, addr, mask)
end
end
+function get_status_by_address(self, addr)
+ 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['ipv4-address'] then
+ local a
+ for _, a in ipairs(s['ipv4-address']) do
+ if a.address == addr then
+ return net, s
+ end
+ end
+ end
+ if s and s['ipv6-address'] then
+ local a
+ for _, a in ipairs(s['ipv6-address']) do
+ if a.address == addr 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)