From: "Pablo M. Bermudo Garay" <pablombg@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: "Pablo M. Bermudo Garay" <pablombg@gmail.com>
Subject: [PATCH nft 2/2] src: add --check option flag
Date: Fri, 23 Jun 2017 18:38:25 +0200 [thread overview]
Message-ID: <20170623163825.2066-2-pablombg@gmail.com> (raw)
In-Reply-To: <20170623163825.2066-1-pablombg@gmail.com>
Sometimes it can be useful to test if a command is valid without
applying any change to the rule-set. This commit adds a new option
flag (-c | --check) that performs a dry run execution of the commands.
Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
doc/nft.xml | 11 +++++++++++
include/nftables.h | 1 +
src/main.c | 14 ++++++++++++--
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/doc/nft.xml b/doc/nft.xml
index e9ccd63..970acb5 100644
--- a/doc/nft.xml
+++ b/doc/nft.xml
@@ -52,6 +52,9 @@ vi:ts=4 sw=4
<option>-s | --stateless</option>
</arg>
<arg choice="opt">
+ <option>-c | --check</option>
+ </arg>
+ <arg choice="opt">
<option>[-I | --includepath]</option>
<replaceable>directory</replaceable>
</arg>
@@ -130,6 +133,14 @@ vi:ts=4 sw=4
</listitem>
</varlistentry>
<varlistentry>
+ <term><option>-c, --check</option></term>
+ <listitem>
+ <para>
+ Check commands validity without actually applying the changes.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>-N</option></term>
<listitem>
<para>
diff --git a/include/nftables.h b/include/nftables.h
index dbd4637..26fd344 100644
--- a/include/nftables.h
+++ b/include/nftables.h
@@ -33,6 +33,7 @@ struct output_ctx {
struct nft_ctx {
struct output_ctx output;
+ bool check;
};
extern unsigned int max_errors;
diff --git a/src/main.c b/src/main.c
index 16a01f3..849b3bf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,6 +40,7 @@ static unsigned int num_include_paths = 1;
enum opt_vals {
OPT_HELP = 'h',
OPT_VERSION = 'v',
+ OPT_CHECK = 'c',
OPT_FILE = 'f',
OPT_INTERACTIVE = 'i',
OPT_INCLUDEPATH = 'I',
@@ -51,7 +52,7 @@ enum opt_vals {
OPT_INVALID = '?',
};
-#define OPTSTRING "hvf:iI:vnsNa"
+#define OPTSTRING "hvcf:iI:vnsNa"
static const struct option options[] = {
{
@@ -63,6 +64,10 @@ static const struct option options[] = {
.val = OPT_VERSION,
},
{
+ .name = "check",
+ .val = OPT_CHECK,
+ },
+ {
.name = "file",
.val = OPT_FILE,
.has_arg = 1,
@@ -113,6 +118,7 @@ static void show_help(const char *name)
" -h, --help Show this help\n"
" -v, --version Show version information\n"
"\n"
+" -c --check Check commands validity without actually applying the changes.\n"
" -f, --file <filename> Read input from <filename>\n"
" -i, --interactive Read input from interactive CLI\n"
"\n"
@@ -202,7 +208,8 @@ static int nft_netlink(struct parser_state *state, struct list_head *msgs,
if (ret < 0)
goto out;
}
- mnl_batch_end(batch);
+ if (!nft->check)
+ mnl_batch_end(batch);
if (!mnl_batch_ready(batch))
goto out;
@@ -278,6 +285,9 @@ int main(int argc, char * const *argv)
printf("%s v%s (%s)\n",
PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME);
exit(NFT_EXIT_SUCCESS);
+ case OPT_CHECK:
+ nft.check = true;
+ break;
case OPT_FILE:
filename = optarg;
break;
--
2.11.0
next prev parent reply other threads:[~2017-06-23 16:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-23 16:38 [PATCH nft 1/2] src: add new generic context structure nft_ctx Pablo M. Bermudo Garay
2017-06-23 16:38 ` Pablo M. Bermudo Garay [this message]
2017-06-26 17:00 ` [PATCH nft 2/2] src: add --check option flag Pablo Neira Ayuso
2017-06-26 17:00 ` [PATCH nft 1/2] src: add new generic context structure nft_ctx Pablo Neira Ayuso
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=20170623163825.2066-2-pablombg@gmail.com \
--to=pablombg@gmail.com \
--cc=netfilter-devel@vger.kernel.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).