[luci] Patch for sys.lua

Joe Burpee jeb at burkby.com
So Nov 30 15:09:29 CET 2008


A couple of minor changes for "Active Connections":

- net.conntrack: Display source/destination for initial packet
  direction, instead of (possibly masqueraded) reverse direction
  (reply).

- _parse_mixed_record: Include single-character keywords/fields, which
  were being discarded.

Joe


Index: libs/sys/luasrc/sys.lua
===================================================================
--- libs/sys/luasrc/sys.lua	(revision 3844)
+++ libs/sys/luasrc/sys.lua	(working copy)
@@ -268,9 +268,10 @@
 	local connt = {}
 	if luci.fs.access("/proc/net/nf_conntrack") 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
@@ -279,6 +280,7 @@
 		end
 	elseif luci.fs.access("/proc/net/ip_conntrack") 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 @@
 
 	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