Optimized conntrack (thanks to Joe Burpee)
authorSteven Barth <steven@midlink.org>
Sun, 30 Nov 2008 17:22:48 +0000 (17:22 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 30 Nov 2008 17:22:48 +0000 (17:22 +0000)
libs/sys/luasrc/sys.lua
modules/admin-full/luasrc/model/cbi/admin_network/conntrack.lua

index 2b9d9a3c5f81f9132e0c4a6fbcede235c0c9bdab..948da5b1e3562393199aae63f8b3ab8135e4c2a6 100644 (file)
@@ -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
index aa7f7c21ca64f50a8349d50ae3cad6ac67c4f0c4..f1c90d695853c83447b33274ec39be1ad130c98c 100644 (file)
@@ -22,7 +22,7 @@ t:option(DummyValue, "IP address", translate("ipaddress"))
 t:option(DummyValue, "HW address", translate("macaddress"))
 t:option(DummyValue, "Device", translate("interface"))
 
-t = f:section(Table, luci.sys.net.conntrack(), translate("a_n_conntrack"))
+t = f:section(Table, luci.sys.net.conntrack() or {}, translate("a_n_conntrack"))
 l3 = t:option(DummyValue, "layer3", translate("network"))
 function l3.cfgvalue(self, ...)
        return DummyValue.cfgvalue(self, ...):upper()