mirror of
https://git.openwrt.org/project/luci.git
synced 2025-11-02 05:49:05 +08:00
luci-mod-status: amend luci-bwc.c to use conntrack tool
Fall through to /usr/sbin/conntrack tool if /proc/net/nf_conntrack or ip_conntrack is not available. /proc/net/nf_conntrack has been obsoleted in recent kernels (https://cateee.net/lkddb/web-lkddb/NF_CONNTRACK_PROCFS.html). This change enables luci-bwc to collect conntrack information via the /usr/sbin/conntrack tool (if installed) instead. Populates the /luci/admin/status/realtime/connections chart. Signed-off-by: James Fox <jpfox156@yahoo.com.au> [ format using tabs ] Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
@ -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;
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user