From 18786c56a850476d152a50b612a5254fcc5e94c3 Mon Sep 17 00:00:00 2001 From: jpfox156 Date: Fri, 25 Feb 2022 23:25:58 +1000 Subject: [PATCH] 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 [ format using tabs ] Signed-off-by: Paul Donald --- modules/luci-mod-status/src/luci-bwc.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/luci-mod-status/src/luci-bwc.c b/modules/luci-mod-status/src/luci-bwc.c index b7682f9e21..4eef2d38d1 100644 --- a/modules/luci-mod-status/src/luci-bwc.c +++ b/modules/luci-mod-status/src/luci-bwc.c @@ -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); -- 2.30.2