Skip to content

Commit

Permalink
netfilter: nf_tables: Extend nft_expr_ops::dump callback parameters
Browse files Browse the repository at this point in the history
Add a 'reset' flag just like with nft_object_ops::dump. This will be
useful to reset "anonymous stateful objects", e.g. simple rule counters.

No functional change intended.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Phil Sutter authored and ummakynes committed Nov 15, 2022
1 parent 7394c2d commit 7d34aa3
Show file tree
Hide file tree
Showing 45 changed files with 110 additions and 62 deletions.
3 changes: 2 additions & 1 deletion include/net/netfilter/nf_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ struct nft_expr_ops {
void (*destroy_clone)(const struct nft_ctx *ctx,
const struct nft_expr *expr);
int (*dump)(struct sk_buff *skb,
const struct nft_expr *expr);
const struct nft_expr *expr,
bool reset);
int (*validate)(const struct nft_ctx *ctx,
const struct nft_expr *expr,
const struct nft_data **data);
Expand Down
2 changes: 1 addition & 1 deletion include/net/netfilter/nft_fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nft_fib_is_loopback(const struct sk_buff *skb, const struct net_device *in)
return skb->pkt_type == PACKET_LOOPBACK || in->flags & IFF_LOOPBACK;
}

int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr);
int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr, bool reset);
int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
const struct nlattr * const tb[]);
int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
Expand Down
4 changes: 2 additions & 2 deletions include/net/netfilter/nft_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ int nft_meta_set_init(const struct nft_ctx *ctx,
const struct nlattr * const tb[]);

int nft_meta_get_dump(struct sk_buff *skb,
const struct nft_expr *expr);
const struct nft_expr *expr, bool reset);

int nft_meta_set_dump(struct sk_buff *skb,
const struct nft_expr *expr);
const struct nft_expr *expr, bool reset);

void nft_meta_get_eval(const struct nft_expr *expr,
struct nft_regs *regs,
Expand Down
3 changes: 2 additions & 1 deletion include/net/netfilter/nft_reject.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ int nft_reject_init(const struct nft_ctx *ctx,
const struct nft_expr *expr,
const struct nlattr * const tb[]);

int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr);
int nft_reject_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset);

int nft_reject_icmp_code(u8 code);
int nft_reject_icmpv6_code(u8 code);
Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/netfilter/nft_dup_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static int nft_dup_ipv4_init(const struct nft_ctx *ctx,
return err;
}

static int nft_dup_ipv4_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_dup_ipv4_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_dup_ipv4 *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/ipv6/netfilter/nft_dup_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ static int nft_dup_ipv6_init(const struct nft_ctx *ctx,
return err;
}

static int nft_dup_ipv6_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_dup_ipv6_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_dup_ipv6 *priv = nft_expr_priv(expr);

Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2769,7 +2769,7 @@ static int nf_tables_fill_expr_info(struct sk_buff *skb,
NFTA_EXPR_DATA);
if (data == NULL)
goto nla_put_failure;
if (expr->ops->dump(skb, expr) < 0)
if (expr->ops->dump(skb, expr, false) < 0)
goto nla_put_failure;
nla_nest_end(skb, data);
}
Expand Down
6 changes: 4 additions & 2 deletions net/netfilter/nft_bitwise.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ static int nft_bitwise_dump_shift(struct sk_buff *skb,
return 0;
}

static int nft_bitwise_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_bitwise_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_bitwise *priv = nft_expr_priv(expr);
int err = 0;
Expand Down Expand Up @@ -393,7 +394,8 @@ static int nft_bitwise_fast_init(const struct nft_ctx *ctx,
}

static int
nft_bitwise_fast_dump(struct sk_buff *skb, const struct nft_expr *expr)
nft_bitwise_fast_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_bitwise_fast_expr *priv = nft_expr_priv(expr);
struct nft_data data;
Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_byteorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ static int nft_byteorder_init(const struct nft_ctx *ctx,
priv->len);
}

static int nft_byteorder_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_byteorder_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_byteorder *priv = nft_expr_priv(expr);

Expand Down
9 changes: 6 additions & 3 deletions net/netfilter/nft_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ static int nft_cmp_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
return 0;
}

static int nft_cmp_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_cmp_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_cmp_expr *priv = nft_expr_priv(expr);

Expand Down Expand Up @@ -253,7 +254,8 @@ static int nft_cmp_fast_offload(struct nft_offload_ctx *ctx,
return __nft_cmp_offload(ctx, flow, &cmp);
}

static int nft_cmp_fast_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_cmp_fast_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_cmp_fast_expr *priv = nft_expr_priv(expr);
enum nft_cmp_ops op = priv->inv ? NFT_CMP_NEQ : NFT_CMP_EQ;
Expand Down Expand Up @@ -347,7 +349,8 @@ static int nft_cmp16_fast_offload(struct nft_offload_ctx *ctx,
return __nft_cmp_offload(ctx, flow, &cmp);
}

static int nft_cmp16_fast_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_cmp16_fast_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_cmp16_fast_expr *priv = nft_expr_priv(expr);
enum nft_cmp_ops op = priv->inv ? NFT_CMP_NEQ : NFT_CMP_EQ;
Expand Down
9 changes: 6 additions & 3 deletions net/netfilter/nft_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ static int nft_extension_dump_info(struct sk_buff *skb, int attr,
return 0;
}

static int nft_target_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_target_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct xt_target *target = expr->ops->data;
void *info = nft_expr_priv(expr);
Expand Down Expand Up @@ -572,12 +573,14 @@ static int __nft_match_dump(struct sk_buff *skb, const struct nft_expr *expr,
return -1;
}

static int nft_match_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_match_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
return __nft_match_dump(skb, expr, nft_expr_priv(expr));
}

static int nft_match_large_dump(struct sk_buff *skb, const struct nft_expr *e)
static int nft_match_large_dump(struct sk_buff *skb,
const struct nft_expr *e, bool reset)
{
struct nft_xt_match_priv *priv = nft_expr_priv(e);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_connlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ static void nft_connlimit_eval(const struct nft_expr *expr,
nft_connlimit_do_eval(priv, regs, pkt, NULL);
}

static int nft_connlimit_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_connlimit_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_connlimit *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ void nft_counter_eval(const struct nft_expr *expr, struct nft_regs *regs,
nft_counter_do_eval(priv, regs, pkt);
}

static int nft_counter_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_counter_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_counter_percpu_priv *priv = nft_expr_priv(expr);

Expand Down
6 changes: 4 additions & 2 deletions net/netfilter/nft_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ static void nft_ct_set_destroy(const struct nft_ctx *ctx,
nf_ct_netns_put(ctx->net, ctx->family);
}

static int nft_ct_get_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_ct_get_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_ct *priv = nft_expr_priv(expr);

Expand Down Expand Up @@ -703,7 +704,8 @@ static bool nft_ct_get_reduce(struct nft_regs_track *track,
return nft_expr_reduce_bitwise(track, expr);
}

static int nft_ct_set_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_ct_set_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_ct *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_dup_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ static int nft_dup_netdev_init(const struct nft_ctx *ctx,
sizeof(int));
}

static int nft_dup_netdev_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_dup_netdev_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_dup_netdev *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_dynset.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ static void nft_dynset_destroy(const struct nft_ctx *ctx,
nf_tables_destroy_set(ctx, priv->set);
}

static int nft_dynset_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_dynset_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_dynset *priv = nft_expr_priv(expr);
u32 flags = priv->invert ? NFT_DYNSET_F_INV : 0;
Expand Down
9 changes: 6 additions & 3 deletions net/netfilter/nft_exthdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ static int nft_exthdr_dump_common(struct sk_buff *skb, const struct nft_exthdr *
return -1;
}

static int nft_exthdr_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_exthdr_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_exthdr *priv = nft_expr_priv(expr);

Expand All @@ -586,7 +587,8 @@ static int nft_exthdr_dump(struct sk_buff *skb, const struct nft_expr *expr)
return nft_exthdr_dump_common(skb, priv);
}

static int nft_exthdr_dump_set(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_exthdr_dump_set(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_exthdr *priv = nft_expr_priv(expr);

Expand All @@ -596,7 +598,8 @@ static int nft_exthdr_dump_set(struct sk_buff *skb, const struct nft_expr *expr)
return nft_exthdr_dump_common(skb, priv);
}

static int nft_exthdr_dump_strip(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_exthdr_dump_strip(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_exthdr *priv = nft_expr_priv(expr);

Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/nft_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
}
EXPORT_SYMBOL_GPL(nft_fib_init);

int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr)
int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr, bool reset)
{
const struct nft_fib *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_flow_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ static void nft_flow_offload_destroy(const struct nft_ctx *ctx,
nf_ct_netns_put(ctx->net, ctx->family);
}

static int nft_flow_offload_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_flow_offload_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_flow_offload *priv = nft_expr_priv(expr);

Expand Down
6 changes: 4 additions & 2 deletions net/netfilter/nft_fwd_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ static int nft_fwd_netdev_init(const struct nft_ctx *ctx,
sizeof(int));
}

static int nft_fwd_netdev_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_fwd_netdev_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_fwd_netdev *priv = nft_expr_priv(expr);

Expand Down Expand Up @@ -186,7 +187,8 @@ static int nft_fwd_neigh_init(const struct nft_ctx *ctx,
addr_len);
}

static int nft_fwd_neigh_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_fwd_neigh_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_fwd_neigh *priv = nft_expr_priv(expr);

Expand Down
4 changes: 2 additions & 2 deletions net/netfilter/nft_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int nft_symhash_init(const struct nft_ctx *ctx,
}

static int nft_jhash_dump(struct sk_buff *skb,
const struct nft_expr *expr)
const struct nft_expr *expr, bool reset)
{
const struct nft_jhash *priv = nft_expr_priv(expr);

Expand Down Expand Up @@ -176,7 +176,7 @@ static bool nft_jhash_reduce(struct nft_regs_track *track,
}

static int nft_symhash_dump(struct sk_buff *skb,
const struct nft_expr *expr)
const struct nft_expr *expr, bool reset)
{
const struct nft_symhash *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_immediate.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ static void nft_immediate_destroy(const struct nft_ctx *ctx,
}
}

static int nft_immediate_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_immediate_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_immediate_expr *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_inner.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ static int nft_inner_init(const struct nft_ctx *ctx,
return 0;
}

static int nft_inner_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_inner_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_inner *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_last.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ static void nft_last_eval(const struct nft_expr *expr,
WRITE_ONCE(last->set, 1);
}

static int nft_last_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_last_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_last_priv *priv = nft_expr_priv(expr);
struct nft_last *last = priv->last;
Expand Down
5 changes: 3 additions & 2 deletions net/netfilter/nft_limit.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ static int nft_limit_pkts_init(const struct nft_ctx *ctx,
return 0;
}

static int nft_limit_pkts_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_limit_pkts_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_limit_priv_pkts *priv = nft_expr_priv(expr);

Expand Down Expand Up @@ -251,7 +252,7 @@ static int nft_limit_bytes_init(const struct nft_ctx *ctx,
}

static int nft_limit_bytes_dump(struct sk_buff *skb,
const struct nft_expr *expr)
const struct nft_expr *expr, bool reset)
{
const struct nft_limit_priv *priv = nft_expr_priv(expr);

Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ static void nft_log_destroy(const struct nft_ctx *ctx,
nf_logger_put(ctx->family, li->type);
}

static int nft_log_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_log_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_log *priv = nft_expr_priv(expr);
const struct nf_loginfo *li = &priv->loginfo;
Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ static void nft_lookup_destroy(const struct nft_ctx *ctx,
nf_tables_destroy_set(ctx, priv->set);
}

static int nft_lookup_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_lookup_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_lookup *priv = nft_expr_priv(expr);
u32 flags = priv->invert ? NFT_LOOKUP_F_INV : 0;
Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_masq.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ static int nft_masq_init(const struct nft_ctx *ctx,
return nf_ct_netns_get(ctx->net, ctx->family);
}

static int nft_masq_dump(struct sk_buff *skb, const struct nft_expr *expr)
static int nft_masq_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_masq *priv = nft_expr_priv(expr);

Expand Down
Loading

0 comments on commit 7d34aa3

Please sign in to comment.