[OpenWrt-Devel] [PATCH firewall3] defaults: use a generic check_kmod() function

Joe Holden jwh at corp.connectbit.io
Fri Jul 13 11:44:39 EDT 2018


From: Joe Holden <jwh at zorins.co.uk>

Rather than having functions for check_offloading() et al, replace it with a
generic function.

Signed-off-by: Joe Holden <jwh at zorins.co.uk>
---
 defaults.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/defaults.c b/defaults.c
index 11fbf0d..46c2a45 100644
--- a/defaults.c
+++ b/defaults.c
@@ -83,14 +83,17 @@ check_policy(struct uci_element *e, enum fw3_flag *pol, const char *name)
 }
 
 static void
-check_offloading(struct uci_element *e, bool *offloading)
+check_kmod(struct uci_element *e, bool *module, const char *name)
 {
 	FILE *f;
+	char buf[128];
 
-	if (!*offloading)
+	if (!*module)
 		return;
 
-	f = fopen("/sys/module/xt_FLOWOFFLOAD/refcnt", "r");
+	snprintf(buf, sizeof(buf), "/sys/module/%s/refcnt", name);
+
+	f = fopen(buf, "r");
 
 	if (f)
 	{
@@ -98,8 +101,8 @@ check_offloading(struct uci_element *e, bool *offloading)
 		return;
 	}
 
-	warn_elem(e, "enables offloading but missing kernel support, disabling");
-	*offloading = false;
+	warn_elem(e, sprintf("requires module %s but missing kernel support, disabling", name));
+	*module = false;
 }
 
 void
@@ -138,7 +141,7 @@ fw3_load_defaults(struct fw3_state *state, struct uci_package *p)
 		check_policy(e, &defs->policy_output, "output");
 		check_policy(e, &defs->policy_forward, "forward");
 
-		check_offloading(e, &defs->flow_offloading);
+		check_kmod(e, &defs->flow_offloading, "xt_FLOWOFFLOAD");
 	}
 }
 
-- 
2.18.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list