Netfilter updates for net-next
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi David,
The following patchset contains Netfilter updates for your net-next tree, they are:
1) Remove obsolete nf_log tracing from nf_tables, from Florian Westphal.
2) Add support for map lookups to numgen, random and hash expressions, from Laura Garcia.
3) Allow to register nat hooks for iptables and nftables at the same time. Patchset from Florian Westpha.
4) Timeout support for rbtree sets.
5) ip6_rpfilter works needs interface for link-local addresses, from Vincent Bernat.
6) Add nf_ct_hook and nf_nat_hook structures and use them.
7) Do not drop packets on packets raceing to insert conntrack entries into hashes, this is particularly a problem in nfqueue setups.
8) Address fallout from xt_osf separation to nf_osf, patches from Florian Westphal and Fernando Mancera.
9) Remove reference to struct nft_af_info, which doesn't exist anymore. From Taehee Yoo.
This batch comes with is a conflict between 25fd386e0bc0 ("netfilter:
core: add missing __rcu annotation") in your tree and 2c205dd3981f ("netfilter: add struct nf_nat_hook and use it") coming in this batch. This conflict can be solved by leaving the __rcu tag on __netfilter_net_init() - added by 25fd386e0bc0 - and remove all code related to nf_nat_decode_session_hook - which is gone after 2c205dd3981f, as described by:
net/netfilter/core.c +0 -0
@@@ -611,7 -580,13 +611,8 @@@ const struct nf_conntrack_zone nf_ct_zoEXPORT_SYMBOL_GPL (nf_ct_zone_dflt);#endif /* CONFIG_NF_CONNTRACK */ - static void __net_init __netfilter_net_init(struct nf_hook_entries **e, int max) -#ifdef CONFIG_NF_NAT_NEEDED -void (*nf_nat_decode_session_hook)(struct sk_buff *, struct flowi *); -EXPORT_SYMBOL (nf_nat_decode_session_hook); -#endif - + static void __net_init +__netfilter_net_init (struct nf_hook_entries __rcu **e,int max) {int h;
I can also merge your net-next tree into nf-next, solve the conflict and resend the pull request if you prefer so.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks.
----------------------------------------------------------------
The following changes since commit 289e1f4e9e4a09c73a1c0152bb93855ea351ccda:
net: ipv4: ipconfig: fix unused variable (2018-05-13 20:27:25 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to 0c6bca747111dee19aa48c8f73d77fc85fcb8dd0:
netfilter: nf_tables: remove nft_af_info. (2018-05-23 12:16:25 +0200)
----------------------------------------------------------------
Fernando Fernandez Mancera (1):
netfilter: make NF_OSF non-visible symbol
Florian Westphal (9):
netfilter: fix fallout from xt/nf osf separation
netfilter: nf_tables: remove old nf_log based tracing
netfilter: nf_nat: move common nat code to nat core
netfilter: xtables: allow table definitions not backed by hook_ops
netfilter: nf_tables: allow chain type to override hook register
netfilter: core: export raw versions of add/delete hook functions
netfilter: nf_nat: add nat hook register functions to nf_nat
netfilter: nf_nat: add nat type hooks to nat core
netfilter: lift one-nat-hook-only restriction
Laura Garcia Liebana (2):
netfilter: nft_numgen: add map lookups for numgen random operations
netfilter: nft_hash: add map lookups for hashing operations
Pablo Neira Ayuso (4):
netfilter: nft_set_rbtree: add timeout support
netfilter: add struct nf_ct_hook and use it
netfilter: add struct nf_nat_hook and use it
netfilter: nfnetlink_queue: resolve clash for unconfirmed conntracks
Taehee Yoo (1):
netfilter: nf_tables: remove nft_af_info.
Vincent Bernat (1):
netfilter: ip6t_rpfilter: provide input interface for route lookup
include/linux/netfilter.h | 34 +++- include/linux/netfilter/nf_osf.h | 6 + include/net/netfilter/nf_nat.h | 4 + include/net/netfilter/nf_nat_core.h | 11 +- include/net/netfilter/nf_nat_l3proto.h | 52 +----- include/net/netfilter/nf_tables.h | 8 +- include/net/netns/nftables.h | 2 - include/uapi/linux/netfilter/nf_osf.h | 8 +- include/uapi/linux/netfilter/nf_tables.h | 4 + net/ipv4/netfilter/ip_tables.c | 5 +- net/ipv4/netfilter/iptable_nat.c | 85 ++++----- net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 135 ++++++-------- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 52 ++---- net/ipv6/netfilter/ip6_tables.c | 5 +- net/ipv6/netfilter/ip6t_rpfilter.c | 2 + net/ipv6/netfilter/ip6table_nat.c | 84 ++++----- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 129 ++++++-------- net/ipv6/netfilter/nft_chain_nat_ipv6.c | 48 ++--- net/netfilter/Kconfig | 2 +- net/netfilter/core.c | 102 +++++++---- net/netfilter/nf_conntrack_core.c | 91 +++++++++- net/netfilter/nf_conntrack_netlink.c | 10 +- net/netfilter/nf_internals.h | 5 + net/netfilter/nf_nat_core.c | 294 ++++++++++++++++++++++++++++--- net/netfilter/nf_tables_api.c | 87 ++------- net/netfilter/nf_tables_core.c | 29 +-- net/netfilter/nfnetlink_queue.c | 28 ++- net/netfilter/nft_hash.c | 131 +++++++++++++- net/netfilter/nft_numgen.c | 76 +++++++- net/netfilter/nft_set_rbtree.c | 75 +++++++- 30 files changed, 1033 insertions(+), 571 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/18 netfilter: fix fallout from xt/nf osf separation
From: Florian Westphal <[email protected]>
Stephen Rothwell says:
today's linux-next build (x86_64 allmodconfig) produced this warning:
./usr/include/linux/netfilter/nf_osf.h:25: found __[us]{8,16,32,64} type without #include <linux/types.h>
Fix that up and also move kernel-private struct out of uapi (it was not exposed in any released kernel version).
tested via allmodconfig build + make headers_check.
--- include/linux/netfilter/nf_osf.h | 6 ++++++ include/uapi/linux/netfilter/nf_osf.h | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/netfilter/nf_osf.h +6 -0
@@ -21,6 +21,12 @@ enum osf_fmatch_states { FMATCH_OPT_WRONG, }; +struct nf_osf_finger { +struct rcu_head rcu_head; +struct list_head finger_entry; +struct nf_osf_user_finger finger; +}; + bool nf_osf_match(const struct sk_buff *skb, u_int8_t family, int hooknum, struct net_device *in, struct net_device *out, const struct nf_osf_info *info, struct net *net,
include/uapi/linux/netfilter/nf_osf.h +2 -6
@@ -1,6 +1,8 @@#ifndef _NF_OSF_H#define _NF_OSF_H +#include <linux/types.h> +#define MAXGENRELEN 32#define NF_OSF_GENRE (1 << 0)
@@ -57,12 +59,6 @@ struct nf_osf_user_finger {struct nf_osf_opt opt[MAX_IPOPTLEN ]; }; -struct nf_osf_finger { -struct rcu_head rcu_head; -struct list_head finger_entry; -struct nf_osf_user_finger finger; -}; -struct nf_osf_nlmsg {struct nf_osf_user_finger f;struct iphdr ip;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/18 netfilter: nf_tables: remove old nf_log based tracing
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
nfnetlink tracing is available since nft 0.6 (June 2016). Remove old nf_log based tracing to avoid rule counter in main loop.
--- net/netfilter/nf_tables_core.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-)
net/netfilter/nf_tables_core.c +7 -22
@@ -41,7 +41,7 @@ static const struct nf_loginfo trace_loginfo = { static noinline void __nft_trace_packet(struct nft_traceinfo *info,const struct nft_chain *chain, -int rulenum,enum nft_trace_types type) +enum nft_trace_types type) {const struct nft_pktinfo *pkt = info->pkt;
@@ -52,22 +52,16 @@ static noinline void __nft_trace_packet(struct nft_traceinfo *info, info->type = type;nft_trace_notify (info); - -nf_log_trace (nft_net (pkt),nft_pf (pkt),nft_hook (pkt), pkt->skb, -nft_in (pkt),nft_out (pkt), &trace_loginfo, -"TRACE: %s:%s:%s:%u " , - chain->table->name, chain->name, comments[type], rulenum); }static inline void nft_trace_packet (struct nft_traceinfo *info,const struct nft_chain *chain,const struct nft_rule *rule, -int rulenum,enum nft_trace_types type) {if (static_branch_unlikely (&nft_trace_enabled)) { info->rule = rule; -__nft_trace_packet (info, chain, rulenum, type); +__nft_trace_packet (info, chain, type); } }
@@ -133,7 +127,6 @@ static noinline void nft_update_chain_stats(const struct nft_chain *chain,struct nft_jumpstack {const struct nft_chain *chain;const struct nft_rule *rule; -int rulenum; };unsigned int
@@ -146,7 +139,6 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)struct nft_regs regs;unsigned int stackptr =0 ;struct nft_jumpstack jumpstack[NFT_JUMP_STACK_SIZE ]; -int rulenum;unsigned int gencursor =nft_genmask_cur (net);struct nft_traceinfo info;
@@ -154,7 +146,6 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)if (static_branch_unlikely (&nft_trace_enabled))nft_trace_init (&info, pkt, ®s.verdict, basechain); do_chain: - rulenum =0 ; rule = list_entry(&chain->rules, struct nft_rule, list); next_rule: regs.verdict.code =NFT_CONTINUE ;
@@ -164,8 +155,6 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)if (unlikely (rule->genmask & gencursor))continue ; - rulenum++; -nft_rule_for_each_expr (expr, last, rule) {if (expr->ops == &nft_cmp_fast_ops)nft_cmp_fast_eval (expr, ®s);
@@ -183,7 +172,7 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)continue ;case NFT_CONTINUE :nft_trace_packet (&info, chain, rule, - rulenum,NFT_TRACETYPE_RULE ); +NFT_TRACETYPE_RULE );continue ; }break ;
@@ -195,7 +184,7 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)case NF_QUEUE :case NF_STOLEN :nft_trace_packet (&info, chain, rule, - rulenum,NFT_TRACETYPE_RULE ); +NFT_TRACETYPE_RULE );return regs.verdict.code; }
@@ -204,21 +193,19 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)BUG_ON (stackptr >=NFT_JUMP_STACK_SIZE ); jumpstack[stackptr].chain = chain; jumpstack[stackptr].rule = rule; - jumpstack[stackptr].rulenum = rulenum; stackptr++;/* fall through */ case NFT_GOTO :nft_trace_packet (&info, chain, rule, - rulenum,NFT_TRACETYPE_RULE ); +NFT_TRACETYPE_RULE ); chain = regs.verdict.chain; goto do_chain;case NFT_CONTINUE : - rulenum++;/* fall through */ case NFT_RETURN :nft_trace_packet (&info, chain, rule, - rulenum,NFT_TRACETYPE_RETURN ); +NFT_TRACETYPE_RETURN );break ;default :WARN_ON (1 );
@@ -228,12 +215,10 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv) stackptr--; chain = jumpstack[stackptr].chain; rule = jumpstack[stackptr].rule; - rulenum = jumpstack[stackptr].rulenum; goto next_rule; } -nft_trace_packet (&info, basechain,NULL ,-1 , -NFT_TRACETYPE_POLICY ); +nft_trace_packet (&info, basechain,NULL ,NFT_TRACETYPE_POLICY );if (static_branch_unlikely (&nft_counters_enabled))nft_update_chain_stats (basechain, pkt);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/18 netfilter: nft_numgen: add map lookups for numgen random operations
In reply to Pablo Neira AyusoFrom: Laura Garcia Liebana <[email protected]>
This patch uses the map lookup already included to be applied for random number generation.
--- net/netfilter/nft_numgen.c | 76 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-)
net/netfilter/nft_numgen.c +72 -4
@@ -166,18 +166,43 @@ struct nft_ng_random { enum nft_registers dreg:8;u32 modulus;u32 offset; +struct nft_set *map; }; +static u32 nft_ng_random_gen (struct nft_ng_random *priv) +{ +struct rnd_state *state =this_cpu_ptr (&nft_numgen_prandom_state); + +return reciprocal_scale (prandom_u32_state (state), priv->modulus) + + priv->offset; +} +static void nft_ng_random_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt) {struct nft_ng_random *priv =nft_expr_priv (expr); -struct rnd_state *state =this_cpu_ptr (&nft_numgen_prandom_state); -u32 val; - val =reciprocal_scale (prandom_u32_state (state), priv->modulus); - regs->data[priv->dreg] = val + priv->offset; + regs->data[priv->dreg] =nft_ng_random_gen (priv); +} + +static void nft_ng_random_map_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) +{ +struct nft_ng_random *priv =nft_expr_priv (expr); +const struct nft_set *map = priv->map; +const struct nft_set_ext *ext; +u32 result; +bool found; + + result =nft_ng_random_gen (priv); + found = map->ops->lookup (nft_net (pkt), map, &result, &ext); +if (!found) +return ; + +nft_data_copy (®s->data[priv->dreg], +nft_set_ext_data (ext), map->dlen); } static int nft_ng_random_init(const struct nft_ctx *ctx,
@@ -204,6 +229,23 @@ static int nft_ng_random_init(const struct nft_ctx *ctx, NFT_DATA_VALUE, sizeof(u32)); } +static int nft_ng_random_map_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]) +{ +struct nft_ng_random *priv =nft_expr_priv (expr); +u8 genmask =nft_genmask_next (ctx->net); + +nft_ng_random_init (ctx, expr, tb); + priv->map =nft_set_lookup_global (ctx->net, ctx->table, + tb[NFTA_NG_SET_NAME ], + tb[NFTA_NG_SET_ID ], genmask); +if (IS_ERR (priv->map)) +return PTR_ERR (priv->map); + +return 0 ; +} +static int nft_ng_random_dump (struct sk_buff *skb,const struct nft_expr *expr) {const struct nft_ng_random *priv =nft_expr_priv (expr);
@@ -212,6 +254,22 @@ static int nft_ng_random_dump(struct sk_buff *skb, const struct nft_expr *expr) priv->offset); } +static int nft_ng_random_map_dump (struct sk_buff *skb, +const struct nft_expr *expr) +{ +const struct nft_ng_random *priv =nft_expr_priv (expr); + +if (nft_ng_dump (skb, priv->dreg, priv->modulus, +NFT_NG_RANDOM , priv->offset) || +nla_put_string (skb,NFTA_NG_SET_NAME , priv->map->name)) + goto nla_put_failure; + +return 0 ; + +nla_put_failure: +return -1 ; +} +static struct nft_expr_type nft_ng_type;static const struct nft_expr_ops nft_ng_inc_ops = { .type = &nft_ng_type,
@@ -237,6 +295,14 @@ static const struct nft_expr_ops nft_ng_random_ops = { .dump = nft_ng_random_dump, }; +static const struct nft_expr_ops nft_ng_random_map_ops = { + .type = &nft_ng_type, + .size =NFT_EXPR_SIZE (sizeof (struct nft_ng_random )), + .eval = nft_ng_random_map_eval, + .init = nft_ng_random_map_init, + .dump = nft_ng_random_map_dump, +}; +static const struct nft_expr_ops *nft_ng_select_ops (const struct nft_ctx *ctx,const struct nlattr *const tb[]) {
@@ -255,6 +321,8 @@ nft_ng_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])return &nft_ng_inc_map_ops;return &nft_ng_inc_ops;case NFT_NG_RANDOM : +if (tb[NFTA_NG_SET_NAME ]) +return &nft_ng_random_map_ops;return &nft_ng_random_ops; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/18 netfilter: nft_hash: add map lookups for hashing operations
In reply to Pablo Neira AyusoFrom: Laura Garcia Liebana <[email protected]>
This patch creates new attributes to accept a map as argument and then perform the lookup with the generated hash accordingly.
Both current hash functions are supported: Jenkins and Symmetric Hash.
--- include/uapi/linux/netfilter/nf_tables.h | 4 + net/netfilter/nft_hash.c | 131 ++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 1 deletion(-)
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -856,6 +856,8 @@ enum nft_hash_types {* @NFTA_HASH_SEED: seed value (NLA_U32) * @NFTA_HASH_OFFSET: add this offset value to hash result (NLA_U32) * @NFTA_HASH_TYPE: hash operation (NLA_U32: nft_hash_types) +* @NFTA_HASH_SET_NAME: name of the map to lookup (NLA_STRING) +* @NFTA_HASH_SET_ID: id of the map (NLA_U32) */ enum nft_hash_attributes {NFTA_HASH_UNSPEC ,
@@ -866,6 +868,8 @@ enum nft_hash_attributes {NFTA_HASH_SEED ,NFTA_HASH_OFFSET ,NFTA_HASH_TYPE , +NFTA_HASH_SET_NAME , +NFTA_HASH_SET_ID , __NFTA_HASH_MAX, };#define NFTA_HASH_MAX (__NFTA_HASH_MAX - 1)
net/netfilter/nft_hash.c +130 -1
206 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/18 netfilter: nf_nat: move common nat code to nat core
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Copy-pasted, both l3 helpers almost use same code here. Split out the common part into an 'inet' helper.
--- include/net/netfilter/nf_nat_core.h | 7 ++++ net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 55 +------------------------ net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 48 +--------------------- net/netfilter/nf_nat_core.c | 70 ++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 99 deletions(-)
include/net/netfilter/nf_nat_core.h +7 -0
@@ -11,6 +11,13 @@unsigned int nf_nat_packet (struct nf_conn *ct,enum ip_conntrack_info ctinfo,unsigned int hooknum,struct sk_buff *skb); +unsigned int +nf_nat_inet_fn (void *priv,struct sk_buff *skb, +const struct nf_hook_state *state, +unsigned int (*do_chain)(void *priv, +struct sk_buff *skb, +const struct nf_hook_state *state)); +int nf_xfrm_me_harder (struct net *net,struct sk_buff *skb,unsigned int family); static inline int nf_nat_initialized(struct nf_conn *ct,
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +2 -53
74 lines not on this page · raw message
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +2 -46
68 lines not on this page · raw message
net/netfilter/nf_nat_core.c +70 -0
76 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/18 netfilter: xtables: allow table definitions not backed by hook_ops
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The ip(6)tables nat table is currently receiving skbs from the netfilter core, after a followup patch skbs will be coming from the netfilter nat core instead, so the table is no longer backed by normal hook_ops.
--- net/ipv4/netfilter/ip_tables.c | 5 ++++- net/ipv6/netfilter/ip6_tables.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ip_tables.c +4 -1
@@ -1782,6 +1782,8 @@ int ipt_register_table(struct net *net, const struct xt_table *table,/* set res now, will see skbs right after nf_register_net_hooks */ WRITE_ONCE (*res, new_table); +if (!ops) +return 0 ; ret =nf_register_net_hooks (net, ops,hweight32 (table->valid_hooks));if (ret !=0 ) {
@@ -1799,7 +1801,8 @@ int ipt_register_table(struct net *net, const struct xt_table *table,void ipt_unregister_table (struct net *net,struct xt_table *table,const struct nf_hook_ops *ops) { -nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +if (ops) +nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks));__ipt_unregister_table (net, table); }
net/ipv6/netfilter/ip6_tables.c +4 -1
@@ -1792,6 +1792,8 @@ int ip6t_register_table(struct net *net, const struct xt_table *table,/* set res now, will see skbs right after nf_register_net_hooks */ WRITE_ONCE (*res, new_table); +if (!ops) +return 0 ; ret =nf_register_net_hooks (net, ops,hweight32 (table->valid_hooks));if (ret !=0 ) {
@@ -1809,7 +1811,8 @@ int ip6t_register_table(struct net *net, const struct xt_table *table,void ip6t_unregister_table (struct net *net,struct xt_table *table,const struct nf_hook_ops *ops) { -nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +if (ops) +nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks));__ip6t_unregister_table (net, table); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/18 netfilter: nf_tables: allow chain type to override hook register
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Will be used in followup patch when nat types no longer
use nf_register_net_hook() but will instead register with the nat core.
--- include/net/netfilter/nf_tables.h | 8 ++++---- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 19 +++++++++++++------ net/ipv6/netfilter/nft_chain_nat_ipv6.c | 20 ++++++++++++++------ net/netfilter/nf_tables_api.c | 23 ++++++++++++++++------- 4 files changed, 47 insertions(+), 23 deletions(-)
include/net/netfilter/nf_tables.h +4 -4
@@ -880,8 +880,8 @@ enum nft_chain_types {* @owner: module owner * @hook_mask: mask of valid hooks * @hooks: array of hook functions -* @init: chain initialization function -* @free: chain release function +* @ops_register: base chain register function +* @ops_unregister: base chain unregister function */ struct nft_chain_type {const char *name;
@@ -890,8 +890,8 @@ struct nft_chain_type {struct module *owner;unsigned int hook_mask;nf_hookfn *hooks[NF_MAX_HOOKS ]; -int (*init)(struct nft_ctx *ctx); -void (*free)(struct nft_ctx *ctx); +int (*ops_register)(struct net *net,const struct nf_hook_ops *ops); +void (*ops_unregister)(struct net *net,const struct nf_hook_ops *ops); }; int nft_chain_validate_dependency(const struct nft_chain *chain,
net/ipv4/netfilter/nft_chain_nat_ipv4.c +13 -6
@@ -66,14 +66,21 @@ static unsigned int nft_nat_ipv4_local_fn(void *priv,return nf_nat_ipv4_local_fn (priv, skb, state, nft_nat_do_chain); } -static int nft_nat_ipv4_init (struct nft_ctx *ctx) +static int nft_nat_ipv4_reg (struct net *net,const struct nf_hook_ops *ops) { -return nf_ct_netns_get (ctx->net, ctx->family); +int ret =nf_register_net_hook (net, ops); +if (ret ==0 ) { + ret =nf_ct_netns_get (net,NFPROTO_IPV4 ); +if (ret) +nf_unregister_net_hook (net, ops); + } +return ret; } -static void nft_nat_ipv4_free (struct nft_ctx *ctx) +static void nft_nat_ipv4_unreg (struct net *net,const struct nf_hook_ops *ops) { -nf_ct_netns_put (ctx->net, ctx->family); +nf_unregister_net_hook (net, ops); +nf_ct_netns_put (net,NFPROTO_IPV4 ); }static const struct nft_chain_type nft_chain_nat_ipv4 = {
@@ -91,8 +98,8 @@ static const struct nft_chain_type nft_chain_nat_ipv4 = { [NF_INET_LOCAL_OUT] = nft_nat_ipv4_local_fn, [NF_INET_LOCAL_IN] = nft_nat_ipv4_fn, }, - .init = nft_nat_ipv4_init, - .free = nft_nat_ipv4_free, + .ops_register = nft_nat_ipv4_reg, + .ops_unregister = nft_nat_ipv4_unreg, };static int __init nft_chain_nat_init (void )
net/ipv6/netfilter/nft_chain_nat_ipv6.c +14 -6
@@ -64,14 +64,22 @@ static unsigned int nft_nat_ipv6_local_fn(void *priv,return nf_nat_ipv6_local_fn (priv, skb, state, nft_nat_do_chain); } -static int nft_nat_ipv6_init (struct nft_ctx *ctx) +static int nft_nat_ipv6_reg (struct net *net,const struct nf_hook_ops *ops) { -return nf_ct_netns_get (ctx->net, ctx->family); +int ret =nf_register_net_hook (net, ops); +if (ret ==0 ) { + ret =nf_ct_netns_get (net,NFPROTO_IPV6 ); +if (ret) +nf_unregister_net_hook (net, ops); + } + +return ret; } -static void nft_nat_ipv6_free (struct nft_ctx *ctx) +static void nft_nat_ipv6_unreg (struct net *net,const struct nf_hook_ops *ops) { -nf_ct_netns_put (ctx->net, ctx->family); +nf_unregister_net_hook (net, ops); +nf_ct_netns_put (net,NFPROTO_IPV6 ); }static const struct nft_chain_type nft_chain_nat_ipv6 = {
@@ -89,8 +97,8 @@ static const struct nft_chain_type nft_chain_nat_ipv6 = { [NF_INET_LOCAL_OUT] = nft_nat_ipv6_local_fn, [NF_INET_LOCAL_IN] = nft_nat_ipv6_fn, }, - .init = nft_nat_ipv6_init, - .free = nft_nat_ipv6_free, + .ops_register = nft_nat_ipv6_reg, + .ops_unregister = nft_nat_ipv6_unreg, };static int __init nft_chain_nat_ipv6_init (void )
net/netfilter/nf_tables_api.c +16 -7
@@ -129,6 +129,7 @@ static int nf_tables_register_hook(struct net *net,const struct nft_table *table, struct nft_chain *chain) { + const struct nft_base_chain *basechain;struct nf_hook_ops *ops;int ret;
@@ -136,7 +137,12 @@ static int nf_tables_register_hook(struct net *net, !nft_is_base_chain(chain))return 0 ; - ops = &nft_base_chain (chain)->ops; + basechain =nft_base_chain (chain); + ops = &basechain->ops; + +if (basechain->type->ops_register) +return basechain->type->ops_register (net, ops); + ret =nf_register_net_hook (net, ops);if (ret == -EBUSY &&nf_tables_allow_nat_conflict (net, ops)) { ops->nat_hook = false;
@@ -151,11 +157,19 @@ static void nf_tables_unregister_hook(struct net *net,const struct nft_table *table, struct nft_chain *chain) { + const struct nft_base_chain *basechain; +const struct nf_hook_ops *ops; +if (table->flags &NFT_TABLE_F_DORMANT || !nft_is_base_chain (chain))return ; + basechain =nft_base_chain (chain); + ops = &basechain->ops; + +if (basechain->type->ops_unregister) +return basechain->type->ops_unregister (net, ops); - nf_unregister_net_hook(net, &nft_base_chain(chain)->ops); +nf_unregister_net_hook (net, ops); }static int nft_trans_table_add (struct nft_ctx *ctx,int msg_type)
@@ -1262,8 +1276,6 @@ static void nf_tables_chain_destroy(struct nft_ctx *ctx)if (nft_is_base_chain (chain)) {struct nft_base_chain *basechain =nft_base_chain (chain); -if (basechain->type->free) - basechain->type->free (ctx);module_put (basechain->type->owner);free_percpu (basechain->stats);if (basechain->stats)
@@ -1396,9 +1408,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, } basechain->type = hook.type; -if (basechain->type->init) - basechain->type->init (ctx); - chain = &basechain->chain; ops = &basechain->ops;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/18 netfilter: core: export raw versions of add/delete hook functions
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This will allow the nat core to reuse the nf_hook infrastructure to maintain nat lookup functions.
The raw versions don't assume a particular hook location, the functions get added/deleted from the hook blob that is passed to the functions.
--- net/netfilter/core.c | 75 +++++++++++++++++++++++++++++++------------- net/netfilter/nf_internals.h | 5 +++ 2 files changed, 59 insertions(+), 21 deletions(-)
net/netfilter/core.c +54 -21
@@ -186,9 +186,31 @@ static void hooks_validate(const struct nf_hook_entries *hooks)#endif } +int nf_hook_entries_insert_raw (struct nf_hook_entries __rcu **pp, +const struct nf_hook_ops *reg) +{ +struct nf_hook_entries *new_hooks; +struct nf_hook_entries *p; + + p =rcu_dereference_raw (*pp); + new_hooks =nf_hook_entries_grow (p, reg); +if (IS_ERR (new_hooks)) +return PTR_ERR (new_hooks); + +hooks_validate (new_hooks); + +rcu_assign_pointer (*pp, new_hooks); + +BUG_ON (p == new_hooks); +nf_hook_entries_free (p); +return 0 ; +} +EXPORT_SYMBOL_GPL (nf_hook_entries_insert_raw); +/* * __nf_hook_entries_try_shrink - try to shrink hook array * +* @old -- current hook blob at @pp * @pp -- location of hook blob * * Hook unregistration must always succeed, so to-be-removed hooks
@@ -201,14 +223,14 @@ static void hooks_validate(const struct nf_hook_entries *hooks)* * Returns address to free, or NULL. */ -static void *__nf_hook_entries_try_shrink (struct nf_hook_entries __rcu **pp) +static void *__nf_hook_entries_try_shrink (struct nf_hook_entries *old, +struct nf_hook_entries __rcu **pp) { -struct nf_hook_entries *old, *new =NULL ;unsigned int i, j, skip =0 , hook_entries; +struct nf_hook_entries *new =NULL ;struct nf_hook_ops **orig_ops;struct nf_hook_ops **new_ops; - old =nf_entry_dereference (*pp);if (WARN_ON_ONCE (!old))return NULL ;
@@ -347,11 +369,10 @@ static int __nf_register_net_hook(struct net *net, int pf,* This cannot fail, hook unregistration must always succeed. * Therefore replace the to-be-removed hook with a dummy hook. */ -static void nf_remove_net_hook (struct nf_hook_entries *old, -const struct nf_hook_ops *unreg,int pf) +static bool nf_remove_net_hook (struct nf_hook_entries *old, +const struct nf_hook_ops *unreg) {struct nf_hook_ops **orig_ops; -bool found = false;unsigned int i; orig_ops =nf_hook_entries_get_hook_ops (old);
@@ -360,21 +381,10 @@ static void nf_remove_net_hook(struct nf_hook_entries *old,continue ;WRITE_ONCE (old->hooks[i].hook, accept_all);WRITE_ONCE (orig_ops[i], &dummy_ops); - found = true; -break ; +return true; } -if (found) { -#ifdef CONFIG_NETFILTER_INGRESS -if (pf ==NFPROTO_NETDEV && unreg->hooknum ==NF_NETDEV_INGRESS ) -net_dec_ingress_queue (); -#endif -#ifdef HAVE_JUMP_LABEL -static_key_slow_dec (&nf_hooks_needed[pf][unreg->hooknum]); -#endif - }else { -WARN_ONCE (1 ,"hook not found, pf %d num %d" , pf, unreg->hooknum); - } +return false; } static void __nf_unregister_net_hook(struct net *net, int pf,
@@ -395,9 +405,19 @@ static void __nf_unregister_net_hook(struct net *net, int pf,return ; } -nf_remove_net_hook (p, reg, pf); +if (nf_remove_net_hook (p, reg)) { +#ifdef CONFIG_NETFILTER_INGRESS +if (pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_INGRESS ) +net_dec_ingress_queue (); +#endif +#ifdef HAVE_JUMP_LABEL +static_key_slow_dec (&nf_hooks_needed[pf][reg->hooknum]); +#endif + }else { +WARN_ONCE (1 ,"hook not found, pf %d num %d" , pf, reg->hooknum); + } - p =__nf_hook_entries_try_shrink (pp); + p =__nf_hook_entries_try_shrink (p, pp);mutex_unlock (&nf_hook_mutex);if (!p)return ;
@@ -417,6 +437,19 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg) }EXPORT_SYMBOL (nf_unregister_net_hook); +void nf_hook_entries_delete_raw (struct nf_hook_entries __rcu **pp, +const struct nf_hook_ops *reg) +{ +struct nf_hook_entries *p; + + p =rcu_dereference_raw (*pp); +if (nf_remove_net_hook (p, reg)) { + p =__nf_hook_entries_try_shrink (p, pp); +nf_hook_entries_free (p); + } +} +EXPORT_SYMBOL_GPL (nf_hook_entries_delete_raw); +int nf_register_net_hook (struct net *net,const struct nf_hook_ops *reg) {int err;
net/netfilter/nf_internals.h +5 -0
@@ -15,4 +15,9 @@ void nf_queue_nf_hook_drop(struct net *net);/* nf_log.c */ int __init netfilter_log_init (void ); +/* core.c */ +void nf_hook_entries_delete_raw (struct nf_hook_entries __rcu **pp, +const struct nf_hook_ops *reg); +int nf_hook_entries_insert_raw (struct nf_hook_entries __rcu **pp, +const struct nf_hook_ops *reg);#endif
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/18 netfilter: nf_nat: add nat hook register functions to nf_nat
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This adds the infrastructure to register nat hooks with the nat core instead of the netfilter core.
nat hooks are used to configure nat bindings. Such hooks are registered from ip(6)table_nat or by the nftables core when a nat chain is added.
After next patch, nat hooks will be registered with nf_nat instead of netfilter core. This allows to use many nat lookup functions at the same time while doing the real packet rewrite (nat transformation) in one place.
This change doesn't convert the intended users yet to ease review.
--- include/net/netfilter/nf_nat.h | 4 ++ net/netfilter/nf_nat_core.c | 157 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+)
include/net/netfilter/nf_nat.h +4 -0
@@ -75,4 +75,8 @@ static inline bool nf_nat_oif_changed(unsigned int hooknum, #endif } +int nf_nat_register_fn (struct net *net,const struct nf_hook_ops *ops, +const struct nf_hook_ops *nat_ops,unsigned int ops_count); +void nf_nat_unregister_fn (struct net *net,const struct nf_hook_ops *ops, +unsigned int ops_count);#endif
net/netfilter/nf_nat_core.c +157 -0
192 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/18 netfilter: nf_nat: add nat type hooks to nat core
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Currently the packet rewrite and instantiation of nat NULL bindings happens from the protocol specific nat backend.
Invocation occurs either via ip(6)table_nat or the nf_tables nat chain type.
Invocation looks like this (simplified):NF_HOOK()
|
`---iptable_nat
|
`---> nf_nat_l3proto_ipv4 -> nf_nat_packet
|
new packet? pass skb though iptables nat chain
|
`---> iptable_nat: ipt_do_tableIn nft case, this looks the same (nft_chain_nat_ipv4 instead of iptable_nat).
This is a problem for two reasons:
1. Can't use iptables nat and nf_tables nat at the same time, as the first user adds a nat binding (nf_nat_l3proto_ipv4 adds a NULL binding if do_table() did not find a matching nat rule so we can detect post-nat tuple collisions).
2. If you use e.g. nft_masq, snat, redir, etc. uses must also register an empty base chain so that the nat core gets called fro NF_HOOK() to do the reverse translation, which is neither obvious nor user friendly.
After this change, the base hook gets registered not from iptable_nat or nftables nat hooks, but from the l3 nat core.
iptables/nft nat base hooks get registered with the nat core instead:
NF_HOOK()
|
`---> nf_nat_l3proto_ipv4 -> nf_nat_packet
|
new packet? pass skb through iptables/nftables nat chains
|
+-> iptables_nat: ipt_do_table
+-> nft nat chain x
`-> nft nat chain yThe nat core deals with null bindings and reverse translation. When no mapping exists, it calls the registered nat lookup hooks until one creates a new mapping.
If both iptables and nftables nat hooks exist, the first matching one is used (i.e., higher priority wins).
Also, nft users do not need to create empty nat hooks anymore, nat core always registers the base hooks that take care of reverse/reply translation.
--- include/net/netfilter/nf_nat_core.h | 5 +- include/net/netfilter/nf_nat_l3proto.h | 52 ++----------------- net/ipv4/netfilter/iptable_nat.c | 85 ++++++++++++++++---------------- net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 82 ++++++++++++++++++++---------- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 51 +++---------------- net/ipv6/netfilter/ip6table_nat.c | 84 +++++++++++++++---------------- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 83 ++++++++++++++++++++----------- net/ipv6/netfilter/nft_chain_nat_ipv6.c | 48 +++--------------- net/netfilter/nf_nat_core.c | 31 +++++++----- 9 files changed, 232 insertions(+), 289 deletions(-)
include/net/netfilter/nf_nat_core.h +1 -4
@@ -13,10 +13,7 @@ unsigned int nf_nat_packet(struct nf_conn *ct, enum ip_conntrack_info ctinfo,unsigned int nf_nat_inet_fn (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state, -unsigned int (*do_chain)(void *priv, -struct sk_buff *skb, -const struct nf_hook_state *state)); +const struct nf_hook_state *state);int nf_xfrm_me_harder (struct net *net,struct sk_buff *skb,unsigned int family);
include/net/netfilter/nf_nat_l3proto.h +4 -48
62 lines not on this page · raw message
net/ipv4/netfilter/iptable_nat.c +43 -42
126 lines not on this page · raw message
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +55 -27
137 lines not on this page · raw message
net/ipv4/netfilter/nft_chain_nat_ipv4.c +8 -43
75 lines not on this page · raw message
net/ipv6/netfilter/ip6table_nat.c +42 -42
125 lines not on this page · raw message
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +55 -28
137 lines not on this page · raw message
net/ipv6/netfilter/nft_chain_nat_ipv6.c +6 -42
66 lines not on this page · raw message
net/netfilter/nf_nat_core.c +18 -13
@@ -533,10 +533,7 @@ EXPORT_SYMBOL_GPL(nf_nat_packet);unsigned int nf_nat_inet_fn (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state, -unsigned int (*do_chain)(void *priv, -struct sk_buff *skb, -const struct nf_hook_state *state)) +const struct nf_hook_state *state) {struct nf_conn *ct;enum ip_conntrack_info ctinfo;
@@ -564,15 +561,23 @@ nf_nat_inet_fn(void *priv, struct sk_buff *skb,* or local packets. */ if (!nf_nat_initialized (ct, maniptype)) { +struct nf_nat_lookup_hook_priv *lpriv = priv; +struct nf_hook_entries *e =rcu_dereference (lpriv->entries);unsigned int ret; - - ret =do_chain (priv, skb, state); -if (ret !=NF_ACCEPT ) -return ret; - -if (nf_nat_initialized (ct,HOOK2MANIP (state->hook))) -break ; - +int i; + +if (!e) + goto null_bind; + +for (i =0 ; i < e->num_hook_entries; i++) { + ret = e->hooks[i].hook (e->hooks[i].priv, skb, + state); +if (ret !=NF_ACCEPT ) +return ret; +if (nf_nat_initialized (ct, maniptype)) + goto do_nat; + } +null_bind: ret =nf_nat_alloc_null_binding (ct, state->hook);if (ret !=NF_ACCEPT )return ret;
@@ -592,7 +597,7 @@ nf_nat_inet_fn(void *priv, struct sk_buff *skb,if (nf_nat_oif_changed (state->hook, ctinfo, nat, state->out)) goto oif_changed; } - +do_nat:return nf_nat_packet (ct, ctinfo, state->hook, skb); oif_changed:
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/18 netfilter: lift one-nat-hook-only restriction
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This reverts commit f92b40a8b2645
("netfilter: core: only allow one nat hook per hook point"), this limitation is no longer needed. The nat core now invokes these functions and makes sure that hook evaluation stops after a mapping is created and a null binding is created otherwise.
--- include/linux/netfilter.h | 1 - net/netfilter/core.c | 5 ---- net/netfilter/nf_tables_api.c | 66 ++----------------------------------------- 3 files changed, 2 insertions(+), 70 deletions(-)
include/linux/netfilter.h +0 -1
@@ -67,7 +67,6 @@ struct nf_hook_ops {struct net_device *dev;void *priv;u_int8_t pf; -bool nat_hook;unsigned int hooknum;/* Hooks are ordered in ascending priority. */ int priority;
net/netfilter/core.c +0 -5
@@ -138,11 +138,6 @@ nf_hook_entries_grow(const struct nf_hook_entries *old,continue ; } -if (reg->nat_hook && orig_ops[i]->nat_hook) { -kvfree (new); -return ERR_PTR (-EBUSY ); - } -if (inserted || reg->priority > orig_ops[i]->priority) { new_ops[nhooks] = (void *)orig_ops[i]; new->hooks[nhooks] = old->hooks[i];
net/netfilter/nf_tables_api.c +2 -64
89 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 12/18 netfilter: make NF_OSF non-visible symbol
In reply to Pablo Neira AyusoFrom: Fernando Fernandez Mancera <[email protected]>
--- net/netfilter/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/Kconfig +1 -1
@@ -445,7 +445,7 @@ config NETFILTER_SYNPROXY endif # NF_CONNTRACK config NF_OSF - tristate 'Passive OS fingerprint infrastructure' + tristate config NF_TABLES select NETFILTER_NETLINK
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 13/18 netfilter: nft_set_rbtree: add timeout support
In reply to Pablo Neira AyusoAdd garbage collection logic to expire elements stored in the rb-tree representation.
--- net/netfilter/nft_set_rbtree.c | 75 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-)
net/netfilter/nft_set_rbtree.c +72 -3
@@ -22,6 +22,7 @@ struct nft_rbtree {struct rb_root root;rwlock_t lock;seqcount_t count; +struct delayed_work gc_work; };struct nft_rbtree_elem {
@@ -265,6 +266,7 @@ static void nft_rbtree_activate(const struct net *net,struct nft_rbtree_elem *rbe = elem->priv;nft_set_elem_change_active (net, set, &rbe->ext); +nft_set_elem_clear_busy (&rbe->ext); } static bool nft_rbtree_flush(const struct net *net,
@@ -272,8 +274,12 @@ static bool nft_rbtree_flush(const struct net *net, {struct nft_rbtree_elem *rbe = priv; -nft_set_elem_change_active (net, set, &rbe->ext); -return true; +if (!nft_set_elem_mark_busy (&rbe->ext) || + !nft_is_active (net, &rbe->ext)) { +nft_set_elem_change_active (net, set, &rbe->ext); +return true; + } +return false; } static void *nft_rbtree_deactivate(const struct net *net,
@@ -347,6 +353,62 @@ static void nft_rbtree_walk(const struct nft_ctx *ctx,read_unlock_bh (&priv->lock); } +static void nft_rbtree_gc (struct work_struct *work) +{ +struct nft_set_gc_batch *gcb =NULL ; +struct rb_node *node, *prev =NULL ; +struct nft_rbtree_elem *rbe; +struct nft_rbtree *priv; +struct nft_set *set; +int i; + + priv = container_of(work, struct nft_rbtree, gc_work.work); + set =nft_set_container_of (priv); + +write_lock_bh (&priv->lock); +write_seqcount_begin (&priv->count); +for (node =rb_first (&priv->root); node !=NULL ; node =rb_next (node)) { + rbe = rb_entry(node, struct nft_rbtree_elem, node); + +if (nft_rbtree_interval_end (rbe)) { + prev = node; +continue ; + } +if (!nft_set_elem_expired (&rbe->ext)) +continue ; +if (nft_set_elem_mark_busy (&rbe->ext)) +continue ; + + gcb =nft_set_gc_batch_check (set, gcb,GFP_ATOMIC ); +if (!gcb) + goto out; + +atomic_dec (&set->nelems); +nft_set_gc_batch_add (gcb, rbe); + +if (prev) { + rbe = rb_entry(prev, struct nft_rbtree_elem, node); +atomic_dec (&set->nelems); +nft_set_gc_batch_add (gcb, rbe); + } + node =rb_next (node); + } +out: +if (gcb) { +for (i =0 ; i < gcb->head.cnt; i++) { + rbe = gcb->elems[i]; +rb_erase (&rbe->node, &priv->root); + } + } +write_seqcount_end (&priv->count); +write_unlock_bh (&priv->lock); + +nft_set_gc_batch_complete (gcb); + +queue_delayed_work (system_power_efficient_wq, &priv->gc_work, +nft_set_gc_interval (set)); +} +static unsigned int nft_rbtree_privsize (const struct nlattr *const nla[],const struct nft_set_desc *desc) {
@@ -362,6 +424,12 @@ static int nft_rbtree_init(const struct nft_set *set,rwlock_init (&priv->lock);seqcount_init (&priv->count); priv->root =RB_ROOT ; + +INIT_DEFERRABLE_WORK (&priv->gc_work, nft_rbtree_gc); +if (set->flags &NFT_SET_TIMEOUT ) +queue_delayed_work (system_power_efficient_wq, &priv->gc_work, +nft_set_gc_interval (set)); +return 0 ; }
@@ -371,6 +439,7 @@ static void nft_rbtree_destroy(const struct nft_set *set)struct nft_rbtree_elem *rbe;struct rb_node *node; +cancel_delayed_work_sync (&priv->gc_work);while ((node = priv->root.rb_node) !=NULL ) {rb_erase (node, &priv->root); rbe = rb_entry(node, struct nft_rbtree_elem, node);
@@ -395,7 +464,7 @@ static bool nft_rbtree_estimate(const struct nft_set_desc *desc, u32 features,static struct nft_set_type nft_rbtree_type__read_mostly = { .owner =THIS_MODULE , - .features =NFT_SET_INTERVAL |NFT_SET_MAP |NFT_SET_OBJECT , + .features =NFT_SET_INTERVAL |NFT_SET_MAP |NFT_SET_OBJECT |NFT_SET_TIMEOUT , .ops = { .privsize = nft_rbtree_privsize, .elemsize = offsetof(struct nft_rbtree_elem , ext),
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 14/18 netfilter: ip6t_rpfilter: provide input interface for route lookup
In reply to Pablo Neira AyusoFrom: Vincent Bernat <[email protected]>
In commit 47b7e7f82802, this bit was removed at the same time the RT6_LOOKUP_F_IFACE flag was removed. However, it is needed when link-local addresses are used, which is a very common case: when packets are routed, neighbor solicitations are done using link-local addresses. For example, the following neighbor solicitation is not matched by "-m rpfilter":
IP6 fe80::5254:33ff:fe00:1 > ff02::1:ff00:3: ICMP6, neighbor
solicitation, who has 2001:db8::5254:33ff:fe00:3, length 32Commit 47b7e7f82802 doesn't quite explain why we shouldn't use RT6_LOOKUP_F_IFACE in the rpfilter case. I suppose the interface check later in the function would make it redundant. However, the remaining of the routing code is using RT6_LOOKUP_F_IFACE when there is no source address (which matches rpfilter's case with a non-unicast destination, like with neighbor solicitation).
--- net/ipv6/netfilter/ip6t_rpfilter.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/netfilter/ip6t_rpfilter.c +2 -0
@@ -48,6 +48,8 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb, } fl6.flowi6_mark = flags &XT_RPFILTER_VALID_MARK ? skb->mark :0 ; +if ((flags &XT_RPFILTER_LOOSE ) ==0 ) + fl6.flowi6_oif = dev->ifindex; rt = (void *)ip6_route_lookup (net, &fl6, skb, lookup_flags);if (rt->dst.error)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 15/18 netfilter: add struct nf_ct_hook and use it
In reply to Pablo Neira AyusoMove the nf_ct_destroy indirection to the struct nf_ct_hook.
--- include/linux/netfilter.h | 7 ++++++- net/netfilter/core.c | 14 +++++++------- net/netfilter/nf_conntrack_core.c | 9 ++++++--- 3 files changed, 19 insertions(+), 11 deletions(-)
include/linux/netfilter.h +6 -1
@@ -373,13 +373,18 @@ nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)extern void (*ip_ct_attach)(struct sk_buff *,const struct sk_buff *)__rcu ;void nf_ct_attach (struct sk_buff *,const struct sk_buff *); -extern void (*nf_ct_destroy)(struct nf_conntrack *)__rcu ;#else static inline void nf_ct_attach (struct sk_buff *new,struct sk_buff *skb) {}#endif struct nf_conn ;enum ip_conntrack_info ; + +struct nf_ct_hook { +void (*destroy)(struct nf_conntrack *); +}; +extern struct nf_ct_hook __rcu *nf_ct_hook; +struct nlattr ;struct nfnl_ct_hook {
net/netfilter/core.c +7 -7
@@ -563,6 +563,9 @@ EXPORT_SYMBOL(skb_make_writable);struct nfnl_ct_hook __rcu *nfnl_ct_hook__read_mostly ;EXPORT_SYMBOL_GPL (nfnl_ct_hook); +struct nf_ct_hook __rcu *nf_ct_hook__read_mostly ; +EXPORT_SYMBOL_GPL (nf_ct_hook); +#if IS_ENABLED (CONFIG_NF_CONNTRACK )/* This does not belong here, but locally generated errors need it if connection tracking in use: without this, connection may not be in hash table, and hence
@@ -585,17 +588,14 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) }EXPORT_SYMBOL (nf_ct_attach); -void (*nf_ct_destroy)(struct nf_conntrack *)__rcu __read_mostly ; -EXPORT_SYMBOL (nf_ct_destroy); -void nf_conntrack_destroy (struct nf_conntrack *nfct) { -void (*destroy)(struct nf_conntrack *); +struct nf_ct_hook *ct_hook;rcu_read_lock (); - destroy =rcu_dereference (nf_ct_destroy); -BUG_ON (destroy ==NULL ); -destroy (nfct); + ct_hook =rcu_dereference (nf_ct_hook); +BUG_ON (ct_hook ==NULL ); + ct_hook->destroy (nfct);rcu_read_unlock (); }EXPORT_SYMBOL (nf_conntrack_destroy);
net/netfilter/nf_conntrack_core.c +6 -3
@@ -1813,8 +1813,7 @@ void nf_conntrack_cleanup_start(void)void nf_conntrack_cleanup_end (void ) { -RCU_INIT_POINTER (nf_ct_destroy,NULL ); - +RCU_INIT_POINTER (nf_ct_hook,NULL );cancel_delayed_work_sync (&conntrack_gc_work.dwork);nf_ct_free_hashtable (nf_conntrack_hash, nf_conntrack_htable_size);
@@ -2131,11 +2130,15 @@ int nf_conntrack_init_start(void)return ret; } +static struct nf_ct_hook nf_conntrack_hook = { + .destroy = destroy_conntrack, +}; +void nf_conntrack_init_end (void ) {/* For use by REJECT target */ RCU_INIT_POINTER (ip_ct_attach, nf_conntrack_attach); -RCU_INIT_POINTER (nf_ct_destroy, destroy_conntrack); +RCU_INIT_POINTER (nf_ct_hook, &nf_conntrack_hook); }/*
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 16/18 netfilter: add struct nf_nat_hook and use it
In reply to Pablo Neira AyusoMove decode_session() and parse_nat_setup_hook() indirections to struct nf_nat_hook structure.
--- include/linux/netfilter.h | 21 ++++++++++++++++----- include/net/netfilter/nf_nat_core.h | 7 ------- net/netfilter/core.c | 8 +++----- net/netfilter/nf_conntrack_core.c | 5 ----- net/netfilter/nf_conntrack_netlink.c | 10 +++++----- net/netfilter/nf_nat_core.c | 23 ++++++++++++----------- 6 files changed, 36 insertions(+), 38 deletions(-)
include/linux/netfilter.h +16 -5
@@ -320,18 +320,29 @@ int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,int nf_reroute (struct sk_buff *skb,struct nf_queue_entry *entry);#include <net/flow.h> -extern void (*nf_nat_decode_session_hook)(struct sk_buff *,struct flowi *); + +struct nf_conn ; +enum nf_nat_manip_type ; +struct nlattr ; + +struct nf_nat_hook { +int (*parse_nat_setup)(struct nf_conn *ct,enum nf_nat_manip_type manip, +const struct nlattr *attr); +void (*decode_session)(struct sk_buff *skb,struct flowi *fl); +}; + +extern struct nf_nat_hook __rcu *nf_nat_hook;static inline void nf_nat_decode_session (struct sk_buff *skb,struct flowi *fl,u_int8_t family) {#ifdef CONFIG_NF_NAT_NEEDED -void (*decodefn)(struct sk_buff *,struct flowi *); +struct nf_nat_hook *nat_hook;rcu_read_lock (); - decodefn =rcu_dereference (nf_nat_decode_session_hook); -if (decodefn) -decodefn (skb, fl); + nat_hook =rcu_dereference (nf_nat_hook); +if (nat_hook->decode_session) + nat_hook->decode_session (skb, fl);rcu_read_unlock ();#endif }
include/net/netfilter/nf_nat_core.h +0 -7
@@ -26,11 +26,4 @@ static inline int nf_nat_initialized(struct nf_conn *ct, return ct->status & IPS_DST_NAT_DONE; } -struct nlattr ; - -extern int -(*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct, -enum nf_nat_manip_type manip, -const struct nlattr *attr); -#endif /* _NF_NAT_CORE_H */
net/netfilter/core.c +3 -5
@@ -574,6 +574,9 @@ void (*ip_ct_attach)(struct sk_buff *, const struct sk_buff *)__rcu __read_mostly ;EXPORT_SYMBOL (ip_ct_attach); +struct nf_nat_hook __rcu *nf_nat_hook__read_mostly ; +EXPORT_SYMBOL_GPL (nf_nat_hook); +void nf_ct_attach (struct sk_buff *new,const struct sk_buff *skb) {void (*attach)(struct sk_buff *,const struct sk_buff *);
@@ -608,11 +611,6 @@ const struct nf_conntrack_zone nf_ct_zone_dflt = {EXPORT_SYMBOL_GPL (nf_ct_zone_dflt);#endif /* CONFIG_NF_CONNTRACK */ -#ifdef CONFIG_NF_NAT_NEEDED -void (*nf_nat_decode_session_hook)(struct sk_buff *,struct flowi *); -EXPORT_SYMBOL (nf_nat_decode_session_hook); -#endif -static void __net_init __netfilter_net_init (struct nf_hook_entries **e,int max) {int h;
net/netfilter/nf_conntrack_core.c +0 -5
@@ -58,11 +58,6 @@#include "nf_internals.h" -int (*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct, -enum nf_nat_manip_type manip, -const struct nlattr *attr)__read_mostly ; -EXPORT_SYMBOL_GPL (nfnetlink_parse_nat_setup_hook); - __cacheline_aligned_in_smp spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS];EXPORT_SYMBOL_GPL (nf_conntrack_locks);
net/netfilter/nf_conntrack_netlink.c +5 -5
@@ -1431,11 +1431,11 @@ ctnetlink_parse_nat_setup(struct nf_conn *ct,enum nf_nat_manip_type manip, const struct nlattr *attr) { - typeof(nfnetlink_parse_nat_setup_hook) parse_nat_setup; + struct nf_nat_hook *nat_hook;int err; - parse_nat_setup =rcu_dereference (nfnetlink_parse_nat_setup_hook); -if (!parse_nat_setup) { + nat_hook =rcu_dereference (nf_nat_hook); +if (!nat_hook) {#ifdef CONFIG_MODULES rcu_read_unlock ();nfnl_unlock (NFNL_SUBSYS_CTNETLINK );
@@ -1446,13 +1446,13 @@ ctnetlink_parse_nat_setup(struct nf_conn *ct, }nfnl_lock (NFNL_SUBSYS_CTNETLINK );rcu_read_lock (); -if (nfnetlink_parse_nat_setup_hook) +if (nat_hook->parse_nat_setup)return -EAGAIN ;#endif return -EOPNOTSUPP ; } - err =parse_nat_setup (ct, manip, attr); + err = nat_hook->parse_nat_setup (ct, manip, attr);if (err == -EAGAIN ) {#ifdef CONFIG_MODULES rcu_read_unlock ();
net/netfilter/nf_nat_core.c +12 -11
@@ -1026,6 +1026,13 @@ static struct pernet_operations nat_net_ops = { .size = sizeof(struct nat_net), }; +struct nf_nat_hook nat_hook = { + .parse_nat_setup = nfnetlink_parse_nat_setup, +#ifdef CONFIG_XFRM + .decode_session = __nf_nat_decode_session, +#endif +}; +static int __init nf_nat_init (void ) {int ret, i;
@@ -1057,13 +1064,9 @@ static int __init nf_nat_init(void)nf_ct_helper_expectfn_register (&follow_master_nat); -BUG_ON (nfnetlink_parse_nat_setup_hook !=NULL ); -RCU_INIT_POINTER (nfnetlink_parse_nat_setup_hook, - nfnetlink_parse_nat_setup); -#ifdef CONFIG_XFRM -BUG_ON (nf_nat_decode_session_hook !=NULL ); -RCU_INIT_POINTER (nf_nat_decode_session_hook, __nf_nat_decode_session); -#endif +WARN_ON (nf_nat_hook !=NULL ); +RCU_INIT_POINTER (nf_nat_hook, &nat_hook); +return 0 ; }
@@ -1076,10 +1079,8 @@ static void __exit nf_nat_cleanup(void)nf_ct_extend_unregister (&nat_extend);nf_ct_helper_expectfn_unregister (&follow_master_nat); -RCU_INIT_POINTER (nfnetlink_parse_nat_setup_hook,NULL ); -#ifdef CONFIG_XFRM -RCU_INIT_POINTER (nf_nat_decode_session_hook,NULL ); -#endif +RCU_INIT_POINTER (nf_nat_hook,NULL ); +synchronize_rcu ();for (i =0 ; i <NFPROTO_NUMPROTO ; i++)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 17/18 netfilter: nfnetlink_queue: resolve clash for unconfirmed conntracks
In reply to Pablo Neira AyusoIn nfqueue, two consecutive skbuffs may race to create the conntrack entry. Hence, the one that loses the race gets dropped due to clash in the insertion into the hashes from the nf_conntrack_confirm() path.
This patch adds a new nf_conntrack_update() function which searches for possible clashes and resolve them. NAT mangling for the packet losing race is corrected by using the conntrack information that won race.
In order to avoid direct module dependencies with conntrack and NAT, the nf_ct_hook and nf_nat_hook structures are used for this purpose.
--- include/linux/netfilter.h | 5 +++ net/netfilter/nf_conntrack_core.c | 77 +++++++++++++++++++++++++++++++++++++++ net/netfilter/nf_nat_core.c | 41 +++++++++++++-------- net/netfilter/nfnetlink_queue.c | 28 ++++++++++++-- 4 files changed, 132 insertions(+), 19 deletions(-)
include/linux/netfilter.h +5 -0
@@ -324,11 +324,15 @@ int nf_reroute(struct sk_buff *skb, struct nf_queue_entry *entry);struct nf_conn ;enum nf_nat_manip_type ;struct nlattr ; +enum ip_conntrack_dir ;struct nf_nat_hook {int (*parse_nat_setup)(struct nf_conn *ct,enum nf_nat_manip_type manip,const struct nlattr *attr);void (*decode_session)(struct sk_buff *skb,struct flowi *fl); +unsigned int (*manip_pkt)(struct sk_buff *skb,struct nf_conn *ct, +enum nf_nat_manip_type mtype, +enum ip_conntrack_dir dir); };extern struct nf_nat_hook __rcu *nf_nat_hook;
@@ -392,6 +396,7 @@ struct nf_conn;enum ip_conntrack_info ;struct nf_ct_hook { +int (*update)(struct net *net,struct sk_buff *skb);void (*destroy)(struct nf_conntrack *); };extern struct nf_ct_hook __rcu *nf_ct_hook;
net/netfilter/nf_conntrack_core.c +77 -0
89 lines not on this page · raw message
net/netfilter/nf_nat_core.c +26 -15
68 lines not on this page · raw message
net/netfilter/nfnetlink_queue.c +24 -4
@@ -227,6 +227,25 @@ find_dequeue_entry(struct nfqnl_instance *queue, unsigned int id)return entry; } +static void nfqnl_reinject (struct nf_queue_entry *entry,unsigned int verdict) +{ +struct nf_ct_hook *ct_hook; +int err; + +if (verdict ==NF_ACCEPT || + verdict ==NF_STOP ) { +rcu_read_lock (); + ct_hook =rcu_dereference (nf_ct_hook); +if (ct_hook) { + err = ct_hook->update (entry->state.net, entry->skb); +if (err <0 ) + verdict =NF_DROP ; + } +rcu_read_unlock (); + } +nf_reinject (entry, verdict); +} +static void nfqnl_flush (struct nfqnl_instance *queue,nfqnl_cmpfn cmpfn,unsigned long data) {
@@ -237,7 +256,7 @@ nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn, unsigned long data)if (!cmpfn ||cmpfn (entry, data)) {list_del (&entry->list); queue->queue_total--; -nf_reinject (entry,NF_DROP ); +nfqnl_reinject (entry,NF_DROP ); } }spin_unlock_bh (&queue->lock);
@@ -686,7 +705,7 @@ __nfqnl_enqueue_packet(struct net *net, struct nfqnl_instance *queue, err_out_unlock:spin_unlock_bh (&queue->lock);if (failopen) -nf_reinject (entry,NF_ACCEPT ); +nfqnl_reinject (entry,NF_ACCEPT ); err_out:return err; }
@@ -1085,7 +1104,8 @@ static int nfqnl_recv_verdict_batch(struct net *net, struct sock *ctnl,list_for_each_entry_safe (entry, tmp, &batch_list, list) {if (nfqa[NFQA_MARK ]) entry->skb->mark =ntohl (nla_get_be32 (nfqa[NFQA_MARK ])); -nf_reinject (entry, verdict); + +nfqnl_reinject (entry, verdict); }return 0 ; }
@@ -1208,7 +1228,7 @@ static int nfqnl_recv_verdict(struct net *net, struct sock *ctnl,if (nfqa[NFQA_MARK ]) entry->skb->mark =ntohl (nla_get_be32 (nfqa[NFQA_MARK ])); -nf_reinject (entry, verdict); +nfqnl_reinject (entry, verdict);return 0 ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 18/18 netfilter: nf_tables: remove nft_af_info.
In reply to Pablo Neira AyusoFrom: Taehee Yoo <[email protected]>
The struct nft_af_info was removed.
--- include/net/netns/nftables.h | 2 -- 1 file changed, 2 deletions(-)
include/net/netns/nftables.h +0 -2
@@ -4,8 +4,6 @@#include <linux/list.h> -struct nft_af_info ; -struct netns_nftables {struct list_head tables;struct list_head commit_list;
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 23 May 2018 20:42:36 +0200
Quoted 2 lines
The following patchset contains Netfilter updates for your net-next tree, they are:
...
Quoted 12 lines
This batch comes with is a conflict between
25fd386e0bc0("netfilter:
core: add missing__rcuannotation") in your tree and2c205dd3981f("netfilter: add structnf_nat_hookand use it") coming in this batch. This conflict can be solved by leaving the__rcutag on__netfilter_net_init()- added by25fd386e0bc0- and remove all code related tonf_nat_decode_session_hook- which is gone after2c205dd3981f, as described by:net/netfilter/core.c +0
-0
...
Quoted 6 lines
I can also merge your net-next tree into nf-next, solve the conflict and resend the pull request if you prefer so.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks for the merge conflict resolution guide.
Pulled, thanks.