|
|
96192c |
From 0db42cc2d2647ec61441e29445c9f6e0f8946613 Mon Sep 17 00:00:00 2001
|
|
|
96192c |
From: Phil Sutter <psutter@redhat.com>
|
|
|
96192c |
Date: Thu, 13 Jan 2022 20:37:56 +0100
|
|
|
96192c |
Subject: [PATCH] src: support for restoring element counters
|
|
|
96192c |
|
|
|
96192c |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2039594
|
|
|
96192c |
Upstream Status: nftables commit 1fe6089ddd87e
|
|
|
96192c |
|
|
|
96192c |
commit 1fe6089ddd87ee7869d24c0f8849951220cc9b85
|
|
|
96192c |
Author: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
96192c |
Date: Wed Mar 11 13:00:01 2020 +0100
|
|
|
96192c |
|
|
|
96192c |
src: support for restoring element counters
|
|
|
96192c |
|
|
|
96192c |
This patch allows you to restore counters in dynamic sets:
|
|
|
96192c |
|
|
|
96192c |
table ip test {
|
|
|
96192c |
set test {
|
|
|
96192c |
type ipv4_addr
|
|
|
96192c |
size 65535
|
|
|
96192c |
flags dynamic,timeout
|
|
|
96192c |
timeout 30d
|
|
|
96192c |
gc-interval 1d
|
|
|
96192c |
elements = { 192.168.10.13 expires 19d23h52m27s576ms counter packets 51 bytes 17265 }
|
|
|
96192c |
}
|
|
|
96192c |
chain output {
|
|
|
96192c |
type filter hook output priority 0;
|
|
|
96192c |
update @test { ip saddr }
|
|
|
96192c |
}
|
|
|
96192c |
}
|
|
|
96192c |
|
|
|
96192c |
You can also add counters to elements from the control place, ie.
|
|
|
96192c |
|
|
|
96192c |
table ip test {
|
|
|
96192c |
set test {
|
|
|
96192c |
type ipv4_addr
|
|
|
96192c |
size 65535
|
|
|
96192c |
elements = { 192.168.2.1 counter packets 75 bytes 19043 }
|
|
|
96192c |
}
|
|
|
96192c |
|
|
|
96192c |
chain output {
|
|
|
96192c |
type filter hook output priority filter; policy accept;
|
|
|
96192c |
ip daddr @test
|
|
|
96192c |
}
|
|
|
96192c |
}
|
|
|
96192c |
|
|
|
96192c |
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
96192c |
---
|
|
|
96192c |
include/netlink.h | 1 +
|
|
|
96192c |
src/netlink.c | 3 +++
|
|
|
96192c |
src/netlink_linearize.c | 2 +-
|
|
|
96192c |
src/parser_bison.y | 36 +++++++++++++++++++++++++++++++++++-
|
|
|
96192c |
4 files changed, 40 insertions(+), 2 deletions(-)
|
|
|
96192c |
|
|
|
96192c |
diff --git a/include/netlink.h b/include/netlink.h
|
|
|
96192c |
index 88d12ba..059092e 100644
|
|
|
96192c |
--- a/include/netlink.h
|
|
|
96192c |
+++ b/include/netlink.h
|
|
|
96192c |
@@ -97,6 +97,7 @@ extern void netlink_gen_data(const struct expr *expr,
|
|
|
96192c |
extern void netlink_gen_raw_data(const mpz_t value, enum byteorder byteorder,
|
|
|
96192c |
unsigned int len,
|
|
|
96192c |
struct nft_data_linearize *data);
|
|
|
96192c |
+extern struct nftnl_expr *netlink_gen_stmt_stateful(const struct stmt *stmt);
|
|
|
96192c |
|
|
|
96192c |
extern struct expr *netlink_alloc_value(const struct location *loc,
|
|
|
96192c |
const struct nft_data_delinearize *nld);
|
|
|
96192c |
diff --git a/src/netlink.c b/src/netlink.c
|
|
|
96192c |
index 64e51e5..825c2cc 100644
|
|
|
96192c |
--- a/src/netlink.c
|
|
|
96192c |
+++ b/src/netlink.c
|
|
|
96192c |
@@ -136,6 +136,9 @@ static struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
|
|
|
96192c |
if (elem->expiration)
|
|
|
96192c |
nftnl_set_elem_set_u64(nlse, NFTNL_SET_ELEM_EXPIRATION,
|
|
|
96192c |
elem->expiration);
|
|
|
96192c |
+ if (elem->stmt)
|
|
|
96192c |
+ nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_EXPR,
|
|
|
96192c |
+ netlink_gen_stmt_stateful(elem->stmt), 0);
|
|
|
96192c |
if (elem->comment || expr->elem_flags) {
|
|
|
96192c |
udbuf = nftnl_udata_buf_alloc(NFT_USERDATA_MAXLEN);
|
|
|
96192c |
if (!udbuf)
|
|
|
96192c |
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
|
|
|
96192c |
index f5c6116..3fa1339 100644
|
|
|
96192c |
--- a/src/netlink_linearize.c
|
|
|
96192c |
+++ b/src/netlink_linearize.c
|
|
|
96192c |
@@ -838,7 +838,7 @@ static struct nftnl_expr *netlink_gen_quota_stmt(const struct stmt *stmt)
|
|
|
96192c |
return nle;
|
|
|
96192c |
}
|
|
|
96192c |
|
|
|
96192c |
-static struct nftnl_expr *netlink_gen_stmt_stateful(const struct stmt *stmt)
|
|
|
96192c |
+struct nftnl_expr *netlink_gen_stmt_stateful(const struct stmt *stmt)
|
|
|
96192c |
{
|
|
|
96192c |
switch (stmt->ops->type) {
|
|
|
96192c |
case STMT_CONNLIMIT:
|
|
|
96192c |
diff --git a/src/parser_bison.y b/src/parser_bison.y
|
|
|
96192c |
index d38ec30..2cdf8ec 100644
|
|
|
96192c |
--- a/src/parser_bison.y
|
|
|
96192c |
+++ b/src/parser_bison.y
|
|
|
96192c |
@@ -3654,7 +3654,7 @@ meter_key_expr_alloc : concat_expr
|
|
|
96192c |
;
|
|
|
96192c |
|
|
|
96192c |
set_elem_expr : set_elem_expr_alloc
|
|
|
96192c |
- | set_elem_expr_alloc set_elem_options
|
|
|
96192c |
+ | set_elem_expr_alloc set_elem_expr_options
|
|
|
96192c |
;
|
|
|
96192c |
|
|
|
96192c |
set_elem_expr_alloc : set_lhs_expr
|
|
|
96192c |
@@ -3684,6 +3684,40 @@ set_elem_option : TIMEOUT time_spec
|
|
|
96192c |
}
|
|
|
96192c |
;
|
|
|
96192c |
|
|
|
96192c |
+set_elem_expr_options : set_elem_expr_option
|
|
|
96192c |
+ {
|
|
|
96192c |
+ $<expr>$ = $<expr>0;
|
|
|
96192c |
+ }
|
|
|
96192c |
+ | set_elem_expr_options set_elem_expr_option
|
|
|
96192c |
+ ;
|
|
|
96192c |
+
|
|
|
96192c |
+set_elem_expr_option : TIMEOUT time_spec
|
|
|
96192c |
+ {
|
|
|
96192c |
+ $<expr>0->timeout = $2;
|
|
|
96192c |
+ }
|
|
|
96192c |
+ | EXPIRES time_spec
|
|
|
96192c |
+ {
|
|
|
96192c |
+ $<expr>0->expiration = $2;
|
|
|
96192c |
+ }
|
|
|
96192c |
+ | COUNTER
|
|
|
96192c |
+ {
|
|
|
96192c |
+ $<expr>0->stmt = counter_stmt_alloc(&@$);
|
|
|
96192c |
+ }
|
|
|
96192c |
+ | COUNTER PACKETS NUM BYTES NUM
|
|
|
96192c |
+ {
|
|
|
96192c |
+ struct stmt *stmt;
|
|
|
96192c |
+
|
|
|
96192c |
+ stmt = counter_stmt_alloc(&@$);
|
|
|
96192c |
+ stmt->counter.packets = $3;
|
|
|
96192c |
+ stmt->counter.bytes = $5;
|
|
|
96192c |
+ $<expr>0->stmt = stmt;
|
|
|
96192c |
+ }
|
|
|
96192c |
+ | comment_spec
|
|
|
96192c |
+ {
|
|
|
96192c |
+ $<expr>0->comment = $1;
|
|
|
96192c |
+ }
|
|
|
96192c |
+ ;
|
|
|
96192c |
+
|
|
|
96192c |
set_lhs_expr : concat_rhs_expr
|
|
|
96192c |
| wildcard_expr
|
|
|
96192c |
;
|
|
|
96192c |
--
|
|
|
96192c |
2.31.1
|
|
|
96192c |
|