diff options
author | Hannu Nyman <hannu.nyman@iki.fi> | 2019-01-02 18:04:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-02 18:04:53 +0200 |
commit | 8374aa2bad5dfe8ba0a79be3344fc9cd41ebc511 (patch) | |
tree | ffdb56be8d45f3719cb475f772cae46a170b153a /applications/luci-app-nft-qos | |
parent | 37dfd1b625d07091cd78c346d864413998ba9d5a (diff) | |
parent | 8269351cf4362492fa191758d2cec61b688ff683 (diff) |
Merge pull request #2413 from rosysong/nft-qos
luci-app-nft-qos: rework _action_rate function
Diffstat (limited to 'applications/luci-app-nft-qos')
-rw-r--r-- | applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua b/applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua index f7e399352f..637eb11736 100644 --- a/applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua +++ b/applications/luci-app-nft-qos/luasrc/controller/nft-qos.lua @@ -17,30 +17,29 @@ function index() end function _action_rate(rv, n) - local has_ipv6 = nixio.fs.access("/proc/net/ipv6_route") - if has_ipv6 then - local c = io.popen("nft list chain inet nft-qos-monitor " .. n .. " 2>/dev/null") - else - local c = io.popen("nft list chain ip nft-qos-monitor " .. n .. " 2>/dev/null") - end + local c = nixio.fs.access("/proc/net/ipv6_route") and + io.popen("nft list chain inet nft-qos-monitor " .. n .. " 2>/dev/null") or + io.popen("nft list chain ip nft-qos-monitor " .. n .. " 2>/dev/null") + if c then for l in c:lines() do - local _, i, p, b = l:match('^%s+ip ([^%s]+) ([^%s]+) counter packets (%d+) bytes (%d+)') + local _, i, p, b = l:match( + '^%s+ip ([^%s]+) ([^%s]+) counter packets (%d+) bytes (%d+)' + ) if i and p and b then -- handle expression - local r = { + rv[#rv + 1] = { rule = { - family = "inet", - table = "nft-qos-monitor", - chain = n, - handle = 0, - expr = { + family = "inet", + table = "nft-qos-monitor", + chain = n, + handle = 0, + expr = { { match = { right = i } }, { counter = { packets = p, bytes = b } } } } } - rv[#rv + 1] = r end end c:close() |