Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Luci mod status handle obsoleted /proc/net/nf conntrack #5699

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion modules/luci-base/ucode/sys.uc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export function conntrack_list(callback) {
etcpr.close();
}

const nfct = open('/proc/net/nf_conntrack', 'r');
let nfct = open('/proc/net/nf_conntrack', 'r');
if (! nfct) {
nfct = popen('/usr/sbin/conntrack -L -o extended', 'r');
}
let connt;

if (nfct) {
Expand Down
12 changes: 8 additions & 4 deletions modules/luci-lua-runtime/luasrc/sys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,14 @@ function net.host_hints(callback)
end

function net.conntrack(callback)
local ok, nfct = pcall(io.lines, "/proc/net/nf_conntrack")
if not ok or not nfct then
return nil
end
local ok, fd = pcall(io.open, "/proc/net/nf_conntrack")
if not ok or not fd then
ok, fd = pcall(io.popen, "/usr/sbin/conntrack -L -o extended", "r")
end
if not ok or not fd then
return nil
end
nfct = fd:lines()

local line, connt = nil, (not callback) and { }
for line in nfct do
Expand Down
18 changes: 14 additions & 4 deletions modules/luci-mod-status/src/luci-bwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,14 @@ static int run_daemon(void)
struct dirent *e;

struct stat s;
const char *ipc = stat("/proc/net/nf_conntrack", &s)
? "/proc/net/ip_conntrack" : "/proc/net/nf_conntrack";
char *ipc;
char *ipc_command;
if(! stat("/proc/net/nf_conntrack", &s))
ipc = "/proc/net/nf_conntrack";
else if(! stat("/proc/net/ip_conntrack", &s))
ipc = "/proc/net/ip_conntrack";
else if(! stat("/usr/sbin/conntrack" , &s))
ipc_command = "/usr/sbin/conntrack -L -o extended";

const struct {
const char *file;
Expand Down Expand Up @@ -535,7 +541,8 @@ static int run_daemon(void)
closedir(dir);
}

if ((info = fopen(ipc, "r")) != NULL)
if (((ipc != '\0') && ((info = fopen(ipc, "r")) != NULL)) ||
((ipc_command != '\0') && ((info=popen(ipc_command, "r")) != NULL)))
{
udp = 0;
tcp = 0;
Expand Down Expand Up @@ -575,7 +582,10 @@ static int run_daemon(void)
(uint16_t)(lf15 * 100));
}

fclose(info);
if (ipc != '\0')
fclose(info);
if (ipc_command != '\0')
pclose(info);
}

sleep(STEP_TIME);
Expand Down