summaryrefslogtreecommitdiffhomepage
path: root/libs/sys/luasrc
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-11-30 17:22:48 +0000
committerSteven Barth <steven@midlink.org>2008-11-30 17:22:48 +0000
commit5734545388e6661c3e9040c53262bc3ba54fa81e (patch)
treef1142411f707c2e93dabb7e430eafefe280975c0 /libs/sys/luasrc
parentc63a170cde44e891adedc9c589d05da46eecd674 (diff)
Optimized conntrack (thanks to Joe Burpee)
Diffstat (limited to 'libs/sys/luasrc')
-rw-r--r--libs/sys/luasrc/sys.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua
index 2b9d9a3c5..948da5b1e 100644
--- a/libs/sys/luasrc/sys.lua
+++ b/libs/sys/luasrc/sys.lua
@@ -266,19 +266,21 @@ end
-- @return Table with the currently tracked IP connections
function net.conntrack()
local connt = {}
- if luci.fs.access("/proc/net/nf_conntrack") then
+ if luci.fs.access("/proc/net/nf_conntrack", "r") then
for line in io.lines("/proc/net/nf_conntrack") do
+ line = line:match "^(.-( [^ =]+=).-)%2"
local entry, flags = _parse_mixed_record(line, " +")
entry.layer3 = flags[1]
- entry.layer4 = flags[2]
+ entry.layer4 = flags[3]
for i=1, #entry do
entry[i] = nil
end
connt[#connt+1] = entry
end
- elseif luci.fs.access("/proc/net/ip_conntrack") then
+ elseif luci.fs.access("/proc/net/ip_conntrack", "r") then
for line in io.lines("/proc/net/ip_conntrack") do
+ line = line:match "^(.-( [^ =]+=).-)%2"
local entry, flags = _parse_mixed_record(line, " +")
entry.layer3 = "ipv4"
entry.layer4 = flags[1]
@@ -757,7 +759,7 @@ function _parse_mixed_record(cnt, delimiter)
for i, l in pairs(luci.util.split(luci.util.trim(cnt), "\n")) do
for j, f in pairs(luci.util.split(luci.util.trim(l), delimiter, nil, true)) do
- local k, x, v = f:match('([^%s][^:=]+) *([:=]*) *"*([^\n"]*)"*')
+ local k, x, v = f:match('([^%s][^:=]*) *([:=]*) *"*([^\n"]*)"*')
if k then
if x == "" then