From: Joe Holden Date: Fri, 13 Jul 2018 15:44:39 +0000 (+0100) Subject: defaults: use a generic check_kmod() function X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=06fa692c80fb2beb69d23d0a2c5cf667aa12f4ad;p=oweals%2Ffirewall3.git defaults: use a generic check_kmod() function Rather than having functions for check_offloading() et al, replace it with a generic function. Signed-off-by: Joe Holden --- diff --git a/defaults.c b/defaults.c index f42eed6..44fe629 100644 --- a/defaults.c +++ b/defaults.c @@ -85,14 +85,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) { @@ -100,8 +103,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; } static void @@ -168,7 +171,7 @@ fw3_load_defaults(struct fw3_state *state, struct uci_package *p) check_any_reject_code(e, &defs->any_reject_code); - check_offloading(e, &defs->flow_offloading); + check_kmod(e, &defs->flow_offloading, "xt_FLOWOFFLOAD"); } }