diff options
author | Kristian Evensen <kristian.evensen@gmail.com> | 2018-09-09 17:27:28 +0200 |
---|---|---|
committer | Kristian Evensen <kristian.evensen@gmail.com> | 2018-09-19 11:01:38 +0200 |
commit | a13748d4145edd3edc70e462714a115f7c99470e (patch) | |
tree | 502f6c45b52c8da9d6e1e4642c3547996f9a2be2 /modules/luci-base | |
parent | fb27334aef63cef39a93b63e185f047a91d9f33a (diff) |
luci-base: Show multiple upstream interface
Several devices have multiple upstream interfaces, for example a fixed
and a mobile broadband connection. Currently, only one upstream
interface is shown per address family in Luci. So in my example, one of
the interfaces would not appear on the Status-page.
This PR introduces support for showing multiple upstream interfaces on
the Status-page. The code is not very complicated. get_status_by_route()
has been extended to return a list of all routes, and
get_wannet()/get_wan6net() now returns all upstream interfaces.
I could not find any other (active) users of these three functions than
calls triggered from the Status-page, so changing the default behavior
should be fine. get_wandev()/get_wan6dev() called get_status_by_route(),
but I could not find any place where those functions were called. I
removed the dev-functions instead of keeping the old
get_status_by_route().
On the status page, the wan/wan6-variables have been replaced with
arrays. When populating the html, we now iterate through these arrays
and create one element for each interface.
I have tested the code with different interface types, v4, v6, as well as
disconnecting and connecting interfaces. The status is updated and the
correct interfaces (or sometimes none at all) are shown.
Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com>
Diffstat (limited to 'modules/luci-base')
-rw-r--r-- | modules/luci-base/luasrc/model/network.lua | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/modules/luci-base/luasrc/model/network.lua b/modules/luci-base/luasrc/model/network.lua index cce559aab..7f7397032 100644 --- a/modules/luci-base/luasrc/model/network.lua +++ b/modules/luci-base/luasrc/model/network.lua @@ -813,6 +813,7 @@ function del_wifinet(self, net) end function get_status_by_route(self, addr, mask) + local route_statuses = { } local _, object for _, object in ipairs(utl.ubus()) do local net = object:match("^network%.interface%.(.+)") @@ -822,12 +823,14 @@ function get_status_by_route(self, addr, mask) local rt for _, rt in ipairs(s.route) do if not rt.table and rt.target == addr and rt.mask == mask then - return net, s + route_statuses[net] = s end end end end end + + return route_statuses end function get_status_by_address(self, addr) @@ -856,24 +859,28 @@ function get_status_by_address(self, addr) end end -function get_wannet(self) - local net, stat = self:get_status_by_route("0.0.0.0", 0) - return net and network(net, stat.proto) -end +function get_wan_networks(self) + local k, v + local wan_nets = { } + local route_statuses = self:get_status_by_route("0.0.0.0", 0) -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 + for k, v in pairs(route_statuses) do + wan_nets[#wan_nets+1] = network(k, v.proto) + end -function get_wan6net(self) - local net, stat = self:get_status_by_route("::", 0) - return net and network(net, stat.proto) + return wan_nets end -function get_wan6dev(self) - local _, stat = self:get_status_by_route("::", 0) - return stat and interface(stat.l3_device or stat.device) +function get_wan6_networks(self) + local k, v + local wan6_nets = { } + local route_statuses = self:get_status_by_route("::", 0) + + for k, v in pairs(route_statuses) do + wan6_nets[#wan6_nets+1] = network(k, v.proto) + end + + return wan6_nets end function get_switch_topologies(self) |