luci-base: sys.lua: fix parsing conntrack entries without timeout

Flow offloaded conntrack entries carry no timeout value and trip up the
record parsing routine. Adjust the code to properly deal with such entries.

Ref: https://forum.openwrt.org/t/offloading-breaks-connections-list/126423
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 531c0ecff2)
This commit is contained in:
Jo-Philipp Wich 2022-04-29 12:16:19 +02:00
parent 0473e99fab
commit a993714790

View file

@ -286,8 +286,14 @@ function net.conntrack(callback)
local line, connt = nil, (not callback) and { } local line, connt = nil, (not callback) and { }
for line in nfct do for line in nfct do
local fam, l3, l4, timeout, tuples = local fam, l3, l4, rest =
line:match("^(ipv[46]) +(%d+) +%S+ +(%d+) +(%d+) +(.+)$") line:match("^(ipv[46]) +(%d+) +%S+ +(%d+) +(.+)$")
local timeout, tuples = rest:match("^(%d+) +(.+)$")
if not tuples then
tuples = rest
end
if fam and l3 and l4 and timeout and not tuples:match("^TIME_WAIT ") then if fam and l3 and l4 and timeout and not tuples:match("^TIME_WAIT ") then
l4 = nixio.getprotobynumber(l4) l4 = nixio.getprotobynumber(l4)