]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: add flags fo nft_ctx_new
authorEric Leblond <eric@regit.org>
Mon, 4 Sep 2017 07:55:57 +0000 (09:55 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 4 Sep 2017 20:30:02 +0000 (22:30 +0200)
By adding flags to nft_ctx_new, we will have a minimum capabilities
of changing the way the nft_ctx is created.

For now, this patch uses a simple value that allow the user to specify
that he will handle netlink by himself.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/nftables.h
src/main.c

index 5035567a75fdc4cc6fda0f50a4f03cad72569683..3429e4c127983a3c6d2846b204fe70ea08103273 100644 (file)
@@ -49,8 +49,11 @@ struct nft_ctx {
        struct output_ctx       output;
        bool                    check;
        struct nft_cache        cache;
+       uint32_t                flags;
 };
 
+#define NFT_CTX_DEFAULT                0
+
 enum nftables_exit_codes {
        NFT_EXIT_SUCCESS        = 0,
        NFT_EXIT_FAILURE        = 1,
index fce9bfeca1005ab07e5b86e2df1438f4b2ca55c2..702ef30237b3bb26161074b4f0be155fa206e862 100644 (file)
@@ -281,7 +281,12 @@ static void nft_exit(void)
        mark_table_exit();
 }
 
-static struct nft_ctx *nft_ctx_new(void)
+static void nft_ctx_netlink_init(struct nft_ctx *ctx)
+{
+       ctx->nf_sock = netlink_open_sock();
+}
+
+static struct nft_ctx *nft_ctx_new(uint32_t flags)
 {
        struct nft_ctx *ctx;
 
@@ -292,6 +297,10 @@ static struct nft_ctx *nft_ctx_new(void)
        ctx->num_include_paths  = 1;
        ctx->parser_max_errors  = 10;
        init_list_head(&ctx->cache.list);
+       ctx->flags = flags;
+
+       if (flags == NFT_CTX_DEFAULT)
+               nft_ctx_netlink_init(ctx);
 
        return ctx;
 }
@@ -307,11 +316,6 @@ static void nft_ctx_free(const struct nft_ctx *ctx)
        nft_exit();
 }
 
-static void nft_ctx_netlink_init(struct nft_ctx *ctx)
-{
-       ctx->nf_sock = netlink_open_sock();
-}
-
 static int nft_run_cmd_from_buffer(struct nft_ctx *nft,
                                   char *buf, size_t buflen)
 {
@@ -367,9 +371,7 @@ int main(int argc, char * const *argv)
        struct parser_state state;
        int i, val, rc;
 
-       nft = nft_ctx_new();
-
-       nft_ctx_netlink_init(nft);
+       nft = nft_ctx_new(NFT_CTX_DEFAULT);
 
        while (1) {
                val = getopt_long(argc, argv, OPTSTRING, options, NULL);