]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: fix counter restoration
authorEric Leblond <eric@regit.org>
Sat, 8 Jun 2013 23:08:47 +0000 (01:08 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 12 Jun 2013 09:41:39 +0000 (11:41 +0200)
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>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/netlink_linearize.c
src/parser.y
src/scanner.l

index cfd669157768aca61099f2b7d3042f46a79626fa..accab9c2ebb080517d78e71a6e2e437c85819ffa 100644 (file)
@@ -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);
 }
 
index 12322209385f7edcdc358fd6120c6007d83fd53e..2923b598ebf7975245e2bb314853ab59db44a84a 100644 (file)
@@ -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
                        ;
index edecf7b69a5391fa26cf5e54f24ec75489a5be46..fe7b86c4bfdf128d852de0a0761964972300f78f 100644 (file)
@@ -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; }