]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: libnftnl: run single-initcalls only once
authorFlorian Westphal <fw@strlen.de>
Fri, 16 Aug 2019 14:42:34 +0000 (16:42 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 19 Aug 2019 08:32:17 +0000 (10:32 +0200)
Signed-off-by: Florian Westphal <fw@strlen.de>
src/libnftables.c

index a693c0c6907562b75acc0ea149b5fc2c2807a64c..b169dd2f2afec1b1885ed7accab578c6a8be3fb7 100644 (file)
@@ -90,11 +90,6 @@ static void nft_init(struct nft_ctx *ctx)
        realm_table_rt_init(ctx);
        devgroup_table_init(ctx);
        ct_label_table_init(ctx);
-
-       gmp_init();
-#ifdef HAVE_LIBXTABLES
-       xt_init();
-#endif
 }
 
 static void nft_exit(struct nft_ctx *ctx)
@@ -142,8 +137,17 @@ static void nft_ctx_netlink_init(struct nft_ctx *ctx)
 EXPORT_SYMBOL(nft_ctx_new);
 struct nft_ctx *nft_ctx_new(uint32_t flags)
 {
+       static bool init_once;
        struct nft_ctx *ctx;
 
+       if (!init_once) {
+               init_once = true;
+               gmp_init();
+#ifdef HAVE_LIBXTABLES
+               xt_init();
+#endif
+       }
+
        ctx = xzalloc(sizeof(struct nft_ctx));
        nft_init(ctx);