From: Eric Leblond <eric@regit.org>
To: netfilter-devel@vger.kernel.org
Cc: Eric Leblond <eric@regit.org>
Subject: [nftables PATCH 2/2] counter: fix restoration
Date: Sun, 9 Jun 2013 01:08:47 +0200 [thread overview]
Message-ID: <1370732927-23322-3-git-send-email-eric@regit.org> (raw)
In-Reply-To: <1370732927-23322-1-git-send-email-eric@regit.org>
It was not possible to restore a ruleset countaining counter. The
packets and bytes fields were not known from the parser but they
were in the output of the list command.
This patch fixes the issue by restoring correctly the counters if
they are present in the command.
Signed-off-by: Eric Leblond <eric@regit.org>
---
src/netlink_linearize.c | 4 ++++
src/parser.y | 28 +++++++++++++++++++++++++---
src/scanner.l | 2 ++
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index cfd6691..accab9c 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -440,6 +440,10 @@ static void netlink_gen_counter_stmt(struct netlink_linearize_ctx *ctx,
struct nfnl_nft_expr *nle;
nle = alloc_nft_expr(nfnl_nft_counter_init);
+ if (stmt->counter.packets)
+ nfnl_nft_counter_set_packets(nle, stmt->counter.packets);
+ if (stmt->counter.bytes)
+ nfnl_nft_counter_set_bytes(nle, stmt->counter.bytes);
nfnl_nft_rule_add_expr(ctx->nlr, nle);
}
diff --git a/src/parser.y b/src/parser.y
index 1232220..2923b59 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -300,6 +300,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
%token PROTO_DST "proto-dst"
%token COUNTER "counter"
+%token PACKETS "packets"
+%token BYTES "bytes"
%token LOG "log"
%token PREFIX "prefix"
@@ -356,8 +358,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
%destructor { stmt_list_free($$); xfree($$); } stmt_list
%type <stmt> stmt match_stmt verdict_stmt
%destructor { stmt_free($$); } stmt match_stmt verdict_stmt
-%type <stmt> counter_stmt
-%destructor { stmt_free($$); } counter_stmt
+%type <stmt> counter_stmt counter_stmt_alloc
+%destructor { stmt_free($$); } counter_stmt counter_stmt_alloc
%type <stmt> meta_stmt
%destructor { stmt_free($$); } meta_stmt
%type <stmt> log_stmt log_stmt_alloc
@@ -892,12 +894,32 @@ verdict_stmt : verdict_expr
}
;
-counter_stmt : COUNTER
+counter_stmt : counter_stmt_alloc
+ | counter_stmt_alloc counter_args
+
+counter_stmt_alloc : COUNTER
{
$$ = counter_stmt_alloc(&@$);
}
;
+counter_args : counter_arg
+ {
+ $<stmt>$ = $<stmt>0;
+ }
+ | counter_args counter_arg
+ ;
+
+counter_arg : PACKETS NUM
+ {
+ $<stmt>0->counter.packets = $2;
+ }
+ | BYTES NUM
+ {
+ $<stmt>0->counter.bytes = $2;
+ }
+ ;
+
log_stmt : log_stmt_alloc
| log_stmt_alloc log_args
;
diff --git a/src/scanner.l b/src/scanner.l
index edecf7b..fe7b86c 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -250,6 +250,8 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr})
"rename" { return RENAME; }
"counter" { return COUNTER; }
+"packets" { return PACKETS; }
+"bytes" { return BYTES; }
"log" { return LOG; }
"prefix" { return PREFIX; }
--
1.7.10.4
next prev parent reply other threads:[~2013-06-08 23:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-08 23:08 [nftables PATCH 0/2] work on restoration Eric Leblond
2013-06-08 23:08 ` [nftables PATCH 1/2] rule: display hook info Eric Leblond
2013-06-12 9:43 ` Pablo Neira Ayuso
2013-06-08 23:08 ` Eric Leblond [this message]
2013-06-12 9:43 ` [nftables PATCH 2/2] counter: fix restoration 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=1370732927-23322-3-git-send-email-eric@regit.org \
--to=eric@regit.org \
--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).