From: Eric Leblond <eric@regit.org>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, Eric Leblond <eric@regit.org>
Subject: [nft PATCH v2 1/2] src: add flags fo nft_ctx_new
Date: Mon, 4 Sep 2017 09:55:57 +0200 [thread overview]
Message-ID: <20170904075558.10129-2-eric@regit.org> (raw)
In-Reply-To: <20170904075558.10129-1-eric@regit.org>
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>
---
include/nftables.h | 3 +++
src/main.c | 20 +++++++++++---------
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/include/nftables.h b/include/nftables.h
index 5035567..3429e4c 100644
--- a/include/nftables.h
+++ b/include/nftables.h
@@ -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,
diff --git a/src/main.c b/src/main.c
index fce9bfe..702ef30 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
--
2.14.1
next prev parent reply other threads:[~2017-09-04 7:56 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-03 22:03 [nft PATCH 0/2] libnftables preparation work Eric Leblond
2017-09-03 22:03 ` [nft PATCH 1/2] src: add flags fo nft_ctx_new Eric Leblond
2017-09-03 22:33 ` Pablo Neira Ayuso
2017-09-03 22:45 ` Pablo Neira Ayuso
2017-09-04 7:21 ` Eric Leblond
2017-09-03 22:03 ` [nft PATCH 2/2] src: get rid of printf Eric Leblond
2017-09-03 22:34 ` Pablo Neira Ayuso
2017-09-04 7:45 ` Eric Leblond
2017-09-04 7:55 ` [nft PATCH v2] libnftables preparation work Eric Leblond
2017-09-04 7:55 ` Eric Leblond [this message]
2017-09-04 20:43 ` [nft PATCH v2 1/2] src: add flags fo nft_ctx_new Pablo Neira Ayuso
2017-09-04 7:55 ` [nft PATCH v2 2/2] src: get rid of printf Eric Leblond
2017-09-04 20:43 ` Pablo Neira Ayuso
2017-09-04 20:53 ` Pablo Neira Ayuso
2017-09-04 21:23 ` Eric Leblond
2017-09-05 17:33 ` Pablo Neira Ayuso
2017-09-21 15:37 ` Phil Sutter
2017-09-21 15:43 ` Florian Westphal
2017-09-21 15:51 ` Pablo Neira Ayuso
2017-09-21 16:21 ` Phil Sutter
2017-09-21 17:05 ` Florian Westphal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170904075558.10129-2-eric@regit.org \
--to=eric@regit.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).