nf_tables misc updates
Subsystems (2)
Pablo Neira Ayuso
maintainercover nf_tables misc updates
Hi,
This patchset contains misc updates for nf_tables:
1) Remove unnecessary rcu read-size lock when updating chain counters. from the nft_do_chain() path.
2) Replace BUG_ON by WARN_ON_ONCE in nft_payload on buggy payload base.
3) Consolidate verdict tracing in nft_do_chain().
4) Replace WARN_ON() by WARN_ON_ONCE() in nft_do_chain() for unknown verdicts.
5) Make counters a built-in expression (IIRC, already suggested by Florian).
Pablo Neira Ayuso (5):
netfilter: nf_tables: remove rcu read-size lock
netfilter: nft_payload: WARN_ON_ONCE instead of BUG
netfilter: nf_tables: consolidate rule verdict trace call
netfilter: nf_tables: replace WARN_ON by WARN_ON_ONCE for unknown verdicts
netfilter: nf_tables: make counter support built-in
include/net/netfilter/nf_tables_core.h | 4 ++ net/netfilter/Kconfig | 6 --- net/netfilter/Makefile | 3 +- net/netfilter/nf_tables_core.c | 46 +++++++++++++++----- net/netfilter/nft_counter.c | 59 +++++++------------------- net/netfilter/nft_payload.c | 6 ++- 6 files changed, 61 insertions(+), 63 deletions(-)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 1/5 netfilter: nf_tables: remove rcu read-size lock
Chain stats are updated from the Netfilter hook path which already run under rcu read-size lock section.
--- net/netfilter/nf_tables_core.c | 2 -- 1 file changed, 2 deletions(-)
net/netfilter/nf_tables_core.c +0 -2
@@ -110,7 +110,6 @@ static noinline void nft_update_chain_stats(const struct nft_chain *chain, base_chain =nft_base_chain (chain); -rcu_read_lock (); pstats =READ_ONCE (base_chain->stats);if (pstats) {local_bh_disable ();
@@ -121,7 +120,6 @@ static noinline void nft_update_chain_stats(const struct nft_chain *chain,u64_stats_update_end (&stats->syncp);local_bh_enable (); } -rcu_read_unlock (); }struct nft_jumpstack {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/5 netfilter: nft_payload: WARN_ON_ONCE instead of BUG
In reply to Pablo Neira AyusoBUG() is too harsh for unknown payload base, use WARN_ON_ONCE() instead.
--- net/netfilter/nft_payload.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nft_payload.c +4 -2
@@ -157,7 +157,8 @@ void nft_payload_eval(const struct nft_expr *expr, goto err;break ;default : -BUG (); +WARN_ON_ONCE (1 ); + goto err; } offset += priv->offset;
@@ -664,7 +665,8 @@ static void nft_payload_set_eval(const struct nft_expr *expr, goto err;break ;default : -BUG (); +WARN_ON_ONCE (1 ); + goto err; } csum_offset = offset + priv->csum_offset;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/5 netfilter: nf_tables: consolidate rule verdict trace call
In reply to Pablo Neira AyusoAdd function to consolidate verdict tracing.
--- net/netfilter/nf_tables_core.c | 39 ++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-)
net/netfilter/nf_tables_core.c +32 -7
@@ -67,6 +67,36 @@ static void nft_cmp_fast_eval(const struct nft_expr *expr, regs->verdict.code =NFT_BREAK ; } +static noinline void __nft_trace_verdict(struct nft_traceinfo *info, +const struct nft_chain *chain, +const struct nft_regs *regs) +{ +enum nft_trace_types type; + +switch (regs->verdict.code) { +case NFT_CONTINUE : +case NFT_RETURN : + type =NFT_TRACETYPE_RETURN ; +break ; +default : + type =NFT_TRACETYPE_RULE ; +break ; + } + +__nft_trace_packet (info, chain, type); +} + +static inline void nft_trace_verdict (struct nft_traceinfo *info, +const struct nft_chain *chain, +const struct nft_rule *rule, +const struct nft_regs *regs) +{ +if (static_branch_unlikely (&nft_trace_enabled)) { + info->rule = rule; +__nft_trace_verdict (info, chain, regs); + } +} +static bool nft_payload_fast_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt)
@@ -205,13 +235,13 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)break ; } +nft_trace_verdict (&info, chain, rule, ®s); +switch (regs.verdict.code &NF_VERDICT_MASK ) {case NF_ACCEPT :case NF_DROP :case NF_QUEUE :case NF_STOLEN : -nft_trace_packet (&info, chain, rule, -NFT_TRACETYPE_RULE );return regs.verdict.code; }
@@ -224,15 +254,10 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv) stackptr++; fallthrough;case NFT_GOTO : -nft_trace_packet (&info, chain, rule, -NFT_TRACETYPE_RULE ); - chain = regs.verdict.chain; goto do_chain;case NFT_CONTINUE :case NFT_RETURN : -nft_trace_packet (&info, chain, rule, -NFT_TRACETYPE_RETURN );break ;default :WARN_ON (1 );
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/5 netfilter: nf_tables: replace WARN_ON by WARN_ON_ONCE for unknown verdicts
In reply to Pablo Neira AyusoBug might trigger warning for each packet, call WARN_ON_ONCE instead.
--- net/netfilter/nf_tables_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_core.c +1 -1
@@ -260,7 +260,7 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)case NFT_RETURN :break ;default : -WARN_ON (1 ); +WARN_ON_ONCE (1 ); }if (stackptr >0 ) {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/5 netfilter: nf_tables: make counter support built-in
In reply to Pablo Neira AyusoMake counter support built-in to allow for direct call in case of CONFIG_RETPOLINE.
--- include/net/netfilter/nf_tables_core.h | 4 ++ net/netfilter/Kconfig | 6 --- net/netfilter/Makefile | 3 +- net/netfilter/nf_tables_core.c | 3 ++ net/netfilter/nft_counter.c | 59 +++++++------------------- 5 files changed, 24 insertions(+), 51 deletions(-)
include/net/netfilter/nf_tables_core.h +4 -0
@@ -7,6 +7,7 @@extern struct nft_expr_type nft_imm_type;extern struct nft_expr_type nft_cmp_type; +extern struct nft_expr_type nft_counter_type;extern struct nft_expr_type nft_lookup_type;extern struct nft_expr_type nft_bitwise_type;extern struct nft_expr_type nft_byteorder_type;
@@ -21,6 +22,7 @@ extern struct nft_expr_type nft_last_type;#ifdef CONFIG_NETWORK_SECMARK extern struct nft_object_type nft_secmark_obj_type;#endif +extern struct nft_object_type nft_counter_obj_type;int nf_tables_core_module_init (void );void nf_tables_core_module_exit (void );
@@ -143,4 +145,6 @@ void nft_dynset_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt);void nft_rt_get_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt); +void nft_counter_eval (const struct nft_expr *expr,struct nft_regs *regs, +const struct nft_pktinfo *pkt);#endif /* _NET_NF_TABLES_CORE_H */
net/netfilter/Kconfig +0 -6
@@ -515,12 +515,6 @@ config NFT_FLOW_OFFLOAD This option adds the "flow_offload" expression that you can use to choose what flows are placed into the hardware. -config NFT_COUNTER - tristate "Netfilter nf_tables counter module" - help - This option adds the "counter" expression that you can use to - include packet and byte counters in a rule. - config NFT_CONNLIMIT tristate "Netfilter nf_tables connlimit module" depends on NF_CONNTRACK
net/netfilter/Makefile +1 -2
@@ -75,7 +75,7 @@ nf_tables-objs := nf_tables_core.o nf_tables_api.o nft_chain_filter.o \ nf_tables_trace.o nft_immediate.o nft_cmp.o nft_range.o \ nft_bitwise.o nft_byteorder.o nft_payload.o nft_lookup.o \ nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o nft_last.o \ - nft_chain_route.o nf_tables_offload.o \ + nft_counter.o nft_chain_route.o nf_tables_offload.o \ nft_set_hash.o nft_set_bitmap.o nft_set_rbtree.o \ nft_set_pipapo.o
@@ -100,7 +100,6 @@ obj-$(CONFIG_NFT_REJECT) += nft_reject.o obj-$(CONFIG_NFT_REJECT_INET) += nft_reject_inet.o obj-$(CONFIG_NFT_REJECT_NETDEV) += nft_reject_netdev.o obj-$(CONFIG_NFT_TUNNEL) += nft_tunnel.o -obj-$(CONFIG_NFT_COUNTER) += nft_counter.o obj-$(CONFIG_NFT_LOG) += nft_log.o obj-$(CONFIG_NFT_MASQ) += nft_masq.o obj-$(CONFIG_NFT_REDIR) += nft_redir.o
net/netfilter/nf_tables_core.c +3 -0
@@ -169,6 +169,7 @@ static void expr_call_ops_eval(const struct nft_expr *expr,X (e, nft_payload_eval);X (e, nft_cmp_eval); +X (e, nft_counter_eval);X (e, nft_meta_get_eval);X (e, nft_lookup_eval);X (e, nft_range_eval);
@@ -292,12 +293,14 @@ static struct nft_expr_type *nft_basic_types[] = { &nft_rt_type, &nft_exthdr_type, &nft_last_type, + &nft_counter_type, };static struct nft_object_type *nft_basic_objects[] = { #ifdef CONFIG_NETWORK_SECMARK &nft_secmark_obj_type, #endif + &nft_counter_obj_type, };int __init nf_tables_core_module_init (void )
net/netfilter/nft_counter.c +16 -43
103 lines not on this page · raw message
Signature · 1 line
2.30.2