Netfilter/IPVS updates for net-next
Subsystems (7)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi David,
The following patchset contains Netfilter/IPVS updates for your net-next tree:
1) Introduce a hashtable to speed up object lookups, from Florian Westphal.
2) Make direct calls to built-in extension, also from Florian.
3) Call helper before confirming the conntrack as it used to be originally, from Florian.
4) Call request_module() to autoload br_netfilter when physdev is used to relax the dependency, also from Florian.
5) Allow to insert rules at a given position ID that is internal to the batch, from Phil Sutter.
6) Several patches to replace conntrack indirections by direct calls, and to reduce modularization, from Florian. This also includes several follow up patches to deal with minor fallout from this rework.
7) Use RCU from conntrack gre helper, from Florian.
8) GRE conntrack module becomes built-in into nf_conntrack, from Florian.
9) Replace nf_ct_invert_tuplepr() by calls to nf_ct_invert_tuple(), from Florian.
10) Unify sysctl handling at the core of nf_conntrack, from Florian.
11) Provide modparam to register conntrack hooks.
12) Allow to match on the interface kind string, from wenxu.
13) Remove several exported symbols, not required anymore now after a bit of de-modulatization work has been done, from Florian.
14) Remove built-in map support in the hash extension, this can be done with the existing userspace infrastructure, from laura.
15) Remove indirection to calculate checksums in IPVS, from Matteo Croce.
16) Use call wrappers for indirection in IPVS, also from Matteo.
17) Remove superfluous __percpu parameter in nft_counter, patch from Luc Van Oostenryck.
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 435f3f267780321a1aff41bdade257722328ead5:
Merge branch 'tcp_openreq_child' (2019-01-17 22:19:05 -0800)
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 83f529281d7aa42b10c2c5cb64fcbd2c7cab4409:
netfilter: ipv4: remove useless export_symbol (2019-01-28 11:32:58 +0100)
----------------------------------------------------------------
Cong Wang (1):
netfilter: conntrack: fix error path in nf_conntrack_pernet_init()
Florian Westphal (25):
netfilter: nf_tables: prepare nft_object for lookups via hashtable
netfilter: nf_tables: handle nft_object lookups via rhltable
netfilter: nf_tables: add direct calls for all builtin expressions
netfilter: conntrack: remove helper hook again
netfilter: physdev: relax br_netfilter dependency
netfilter: conntrack: handle builtin l4proto packet functions via direct calls
netfilter: conntrack: handle icmp pkt_to_tuple helper via direct calls
netfilter: conntrack: gre: convert rwlock to rcu
netfilter: conntrack: gre: switch module to be built-in
netfilter: conntrack: remove net_id
netfilter: conntrack: remove pkt_to_tuple callback
netfilter: conntrack: remove invert_tuple callback
netfilter: conntrack: remove module owner field
netfilter: conntrack: remove remaining l4proto indirect packet calls
netfilter: conntrack: remove pernet l4 proto register interface
netfilter: conntrack: avoid unneeded nf_conntrack_l4proto lookups
netfilter: conntrack: unify sysctl handling
netfilter: conntrack: remove sysctl registration helpers
netfilter: conntrack: remove l4proto init and get_net callbacks
netfilter: conntrack: remove l4proto destroy hook
netfilter: conntrack: remove nf_ct_l4proto_find_get
netfilter: nat: un-export nf_nat_used_tuple
netfilter: conntrack: fix IPV6=n builds
netfilter: conntrack: fix bogus port values for other l4 protocols
netfilter: ipv4: remove useless export_symbol
Laura Garcia Liebana (1):
Revert "netfilter: nft_hash: add map lookups for hashing operations"
Luc Van Oostenryck (1):
netfilter: nft_counter: remove wrong __percpu of nft_counter_resest()'s arg
Matteo Croce (2):
ipvs: avoid indirect calls when calculating checksums
ipvs: use indirect call wrappers
Pablo Neira Ayuso (1):
netfilter: nf_conntrack: provide modparam to always register conntrack hooks
Phil Sutter (1):
netfilter: nf_tables: Support RULE_ID reference in new rule
wenxu (1):
netfilter: nft_meta: Add NFT_META_I/OIFKIND meta type
include/linux/netfilter/nf_conntrack_proto_gre.h | 17 +- include/linux/netfilter_ipv4.h | 6 - include/net/ip_vs.h | 3 - include/net/netfilter/br_netfilter.h | 1 - include/net/netfilter/ipv4/nf_conntrack_ipv4.h | 3 + include/net/netfilter/nf_conntrack.h | 2 - include/net/netfilter/nf_conntrack_core.h | 5 +- include/net/netfilter/nf_conntrack_l4proto.h | 122 +++--- include/net/netfilter/nf_nat.h | 4 - include/net/netfilter/nf_tables.h | 26 +- include/net/netfilter/nf_tables_core.h | 16 + include/net/netns/conntrack.h | 30 +- include/uapi/linux/netfilter/nf_tables.h | 10 +- net/bridge/br_netfilter_hooks.c | 5 - net/ipv4/netfilter.c | 18 - net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 2 +- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 2 +- net/netfilter/Kconfig | 2 +- net/netfilter/Makefile | 3 +- net/netfilter/ipvs/ip_vs_core.c | 49 ++- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 2 - net/netfilter/ipvs/ip_vs_proto_sctp.c | 8 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 15 +- net/netfilter/ipvs/ip_vs_proto_udp.c | 15 +- net/netfilter/nf_conntrack_core.c | 210 +++++---- net/netfilter/nf_conntrack_expect.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 14 +- net/netfilter/nf_conntrack_pptp.c | 2 +- net/netfilter/nf_conntrack_proto.c | 514 ++++------------------- net/netfilter/nf_conntrack_proto_dccp.c | 134 +----- net/netfilter/nf_conntrack_proto_generic.c | 85 +--- net/netfilter/nf_conntrack_proto_gre.c | 196 ++------- net/netfilter/nf_conntrack_proto_icmp.c | 67 +-- net/netfilter/nf_conntrack_proto_icmpv6.c | 69 +-- net/netfilter/nf_conntrack_proto_sctp.c | 128 +----- net/netfilter/nf_conntrack_proto_tcp.c | 160 +------ net/netfilter/nf_conntrack_proto_udp.c | 80 +--- net/netfilter/nf_conntrack_standalone.c | 427 ++++++++++++++++++- net/netfilter/nf_flow_table_core.c | 2 +- net/netfilter/nf_nat_core.c | 15 +- net/netfilter/nf_tables_api.c | 137 +++++- net/netfilter/nf_tables_core.c | 25 +- net/netfilter/nfnetlink_cttimeout.c | 19 +- net/netfilter/nft_bitwise.c | 5 +- net/netfilter/nft_byteorder.c | 6 +- net/netfilter/nft_cmp.c | 6 +- net/netfilter/nft_counter.c | 2 +- net/netfilter/nft_ct.c | 4 +- net/netfilter/nft_dynset.c | 5 +- net/netfilter/nft_hash.c | 121 ------ net/netfilter/nft_immediate.c | 6 +- net/netfilter/nft_meta.c | 12 + net/netfilter/nft_objref.c | 5 +- net/netfilter/nft_payload.c | 6 +- net/netfilter/nft_quota.c | 2 +- net/netfilter/nft_range.c | 5 +- net/netfilter/nft_rt.c | 6 +- net/netfilter/utils.c | 19 + net/netfilter/xt_CT.c | 2 +- net/netfilter/xt_physdev.c | 9 +- net/openvswitch/conntrack.c | 2 +- 61 files changed, 1178 insertions(+), 1697 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/33 netfilter: nf_tables: prepare nft_object for lookups via hashtable
From: Florian Westphal <[email protected]>
Add a 'key' structure for object, so we can look them up by name + table combination (the name can be the same in each table).
--- include/net/netfilter/nf_tables.h | 19 ++++++++++++++----- net/netfilter/nf_tables_api.c | 27 ++++++++++++++++----------- net/netfilter/nft_objref.c | 2 +- net/netfilter/nft_quota.c | 2 +- 4 files changed, 32 insertions(+), 18 deletions(-)
include/net/netfilter/nf_tables.h +14 -5
@@ -1012,11 +1012,21 @@ int nft_verdict_dump(struct sk_buff *skb, int type, const struct nft_verdict *v);/** +* struct nft_object_hash_key - key to lookup nft_object +* +* @name: name of the stateful object to look up +* @table: table the object belongs to +*/ +struct nft_object_hash_key { +const char *name; +const struct nft_table *table; +}; + +/** * struct nft_object - nf_tables stateful object * * @list: table stateful object list node -* @table: table this object belongs to -* @name: name of this stateful object +* @key: keys that identify this object * @genmask: generation mask * @use: number of references to this stateful object * @handle: unique object handle
@@ -1025,8 +1035,7 @@ int nft_verdict_dump(struct sk_buff *skb, int type,*/ struct nft_object {struct list_head list; -char *name; -struct nft_table *table; +struct nft_object_hash_key key;u32 genmask:2 , use:30 ;u64 handle;
@@ -1047,7 +1056,7 @@ struct nft_object *nft_obj_lookup(const struct nft_table *table, const struct nlattr *nla, u32 objtype, u8 genmask); -void nft_obj_notify (struct net *net,struct nft_table *table, +void nft_obj_notify (struct net *net,const struct nft_table *table,struct nft_object *obj,u32 portid,u32 seq,int event,int family,int report,gfp_t gfp);
net/netfilter/nf_tables_api.c +16 -11
@@ -3853,7 +3853,7 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,if (nft_set_ext_exists (ext,NFT_SET_EXT_OBJREF ) &&nla_put_string (skb,NFTA_SET_ELEM_OBJREF , - (*nft_set_ext_obj (ext))->name) <0 ) + (*nft_set_ext_obj (ext))->key.name) <0 ) goto nla_put_failure; if (nft_set_ext_exists(ext, NFT_SET_EXT_FLAGS) &&
@@ -4826,7 +4826,7 @@ struct nft_object *nft_obj_lookup(const struct nft_table *table,struct nft_object *obj;list_for_each_entry_rcu (obj, &table->objects, list) { -if (!nla_strcmp (nla, obj->name) && +if (!nla_strcmp (nla, obj->key.name) && objtype == obj->ops->type->type &&nft_active_genmask (obj, genmask))return obj;
@@ -5014,11 +5014,11 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk, err =PTR_ERR (obj); goto err1; } - obj->table = table; + obj->key.table = table; obj->handle =nf_tables_alloc_handle (table); - obj->name =nla_strdup (nla[NFTA_OBJ_NAME ],GFP_KERNEL ); -if (!obj->name) { + obj->key.name =nla_strdup (nla[NFTA_OBJ_NAME ],GFP_KERNEL ); +if (!obj->key.name) { err = -ENOMEM ; goto err2; }
@@ -5031,7 +5031,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk, table->use++;return 0 ; err3: -kfree (obj->name); +kfree (obj->key.name); err2:if (obj->ops->destroy) obj->ops->destroy (&ctx, obj);
@@ -5060,7 +5060,7 @@ static int nf_tables_fill_obj_info(struct sk_buff *skb, struct net *net, nfmsg->res_id =htons (net->nft.base_seq &0xffff ); if (nla_put_string(skb, NFTA_OBJ_TABLE, table->name) || - nla_put_string(skb, NFTA_OBJ_NAME, obj->name) || + nla_put_string(skb, NFTA_OBJ_NAME, obj->key.name) || nla_put_be32(skb, NFTA_OBJ_TYPE, htonl(obj->ops->type->type)) || nla_put_be32(skb, NFTA_OBJ_USE, htonl(obj->use)) || nft_object_dump(skb, NFTA_OBJ_DATA, obj, reset) ||
@@ -5246,7 +5246,7 @@ static void nft_obj_destroy(const struct nft_ctx *ctx, struct nft_object *obj) obj->ops->destroy (ctx, obj);module_put (obj->ops->type->owner); -kfree (obj->name); +kfree (obj->key.name);kfree (obj); }
@@ -5297,7 +5297,7 @@ static int nf_tables_delobj(struct net *net, struct sock *nlsk,return nft_delobj (&ctx, obj); } -void nft_obj_notify (struct net *net,struct nft_table *table, +void nft_obj_notify (struct net *net,const struct nft_table *table,struct nft_object *obj,u32 portid,u32 seq,int event,int family,int report,gfp_t gfp) {
@@ -6404,6 +6404,11 @@ static void nf_tables_commit_chain(struct net *net, struct nft_chain *chain)nf_tables_commit_chain_free_rules_old (g0); } +static void nft_obj_del (struct nft_object *obj) +{ +list_del_rcu (&obj->list); +} +static void nft_chain_del (struct nft_chain *chain) {struct nft_table *table = chain->table;
@@ -6580,7 +6585,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_trans_destroy (trans);break ;case NFT_MSG_DELOBJ : -list_del_rcu (&nft_trans_obj (trans)->list); +nft_obj_del (nft_trans_obj (trans));nf_tables_obj_notify (&trans->ctx,nft_trans_obj (trans),NFT_MSG_DELOBJ );break ;
@@ -7330,7 +7335,7 @@ static void __nft_release_tables(struct net *net)nft_set_destroy (set); }list_for_each_entry_safe (obj, ne, &table->objects, list) { -list_del (&obj->list); +nft_obj_del (obj); table->use--;nft_obj_destroy (&ctx, obj); }
net/netfilter/nft_objref.c +1 -1
@@ -53,7 +53,7 @@ static int nft_objref_dump(struct sk_buff *skb, const struct nft_expr *expr) {const struct nft_object *obj =nft_objref_priv (expr); -if (nla_put_string (skb,NFTA_OBJREF_IMM_NAME , obj->name) || +if (nla_put_string (skb,NFTA_OBJREF_IMM_NAME , obj->key.name) ||nla_put_be32 (skb,NFTA_OBJREF_IMM_TYPE ,htonl (obj->ops->type->type))) goto nla_put_failure;
net/netfilter/nft_quota.c +1 -1
@@ -61,7 +61,7 @@ static void nft_quota_obj_eval(struct nft_object *obj,if (overquota && !test_and_set_bit (NFT_QUOTA_DEPLETED_BIT , &priv->flags)) -nft_obj_notify (nft_net (pkt), obj->table, obj,0 ,0 , +nft_obj_notify (nft_net (pkt), obj->key.table, obj,0 ,0 ,NFT_MSG_NEWOBJ ,nft_pf (pkt),0 ,GFP_ATOMIC ); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/33 netfilter: nf_tables: handle nft_object lookups via rhltable
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Instead of linear search, use rhlist interface to look up the objects. This fixes rulesets with thousands of named objects (quota, counters and the like).
We only use a single table for this and consider the address of the table we're doing the lookup in as a part of the key.
This reduces restore time of a sample ruleset with ~20k named counters from 37 seconds to 0.8 seconds.
--- include/net/netfilter/nf_tables.h | 7 ++- net/netfilter/nf_tables_api.c | 103 +++++++++++++++++++++++++++++++++----- net/netfilter/nft_objref.c | 3 +- 3 files changed, 98 insertions(+), 15 deletions(-)
include/net/netfilter/nf_tables.h +5 -2
@@ -1027,14 +1027,16 @@ struct nft_object_hash_key {* * @list: table stateful object list node * @key: keys that identify this object +* @rhlhead: nft_objname_ht node * @genmask: generation mask * @use: number of references to this stateful object * @handle: unique object handle * @ops: object operations -* @data: object data, layout depends on type +* @data: object data, layout depends on type */ struct nft_object {struct list_head list; +struct rhlist_head rhlhead;struct nft_object_hash_key key;u32 genmask:2 , use:30 ;
@@ -1052,7 +1054,8 @@ static inline void *nft_obj_data(const struct nft_object *obj)#define nft_expr_obj (expr) *((struct nft_object **)nft_expr_priv(expr)) -struct nft_object *nft_obj_lookup (const struct nft_table *table, +struct nft_object *nft_obj_lookup (const struct net *net, +const struct nft_table *table,const struct nlattr *nla,u32 objtype,u8 genmask);
net/netfilter/nf_tables_api.c +91 -12
206 lines not on this page · raw message
net/netfilter/nft_objref.c +2 -1
@@ -38,7 +38,8 @@ static int nft_objref_init(const struct nft_ctx *ctx,return -EINVAL ; objtype =ntohl (nla_get_be32 (tb[NFTA_OBJREF_IMM_TYPE ])); - obj =nft_obj_lookup (ctx->table, tb[NFTA_OBJREF_IMM_NAME ], objtype, + obj =nft_obj_lookup (ctx->net, ctx->table, + tb[NFTA_OBJREF_IMM_NAME ], objtype, genmask);if (IS_ERR (obj))return -ENOENT ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/33 netfilter: nf_tables: add direct calls for all builtin expressions
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
With CONFIG_RETPOLINE its faster to add an if (ptr == &foo_func) check and and use direct calls for all the built-in expressions.
~15% improvement in pathological cases.
checkpatch doesn't like the X macro due to the embedded return statement, but the macro has a very limited scope so I don't think its a problem.
I would like to avoid bugs of the form
If (e->ops->eval == (unsigned long)nft_foo_eval)
nft_bar_eval();
and open-coded if ()/else if()/else cascade, thus the macro.
--- include/net/netfilter/nf_tables_core.h | 16 ++++++++++++++++ net/netfilter/nf_tables_core.c | 25 ++++++++++++++++++------- net/netfilter/nft_bitwise.c | 5 ++--- net/netfilter/nft_byteorder.c | 6 +++--- net/netfilter/nft_cmp.c | 6 +++--- net/netfilter/nft_dynset.c | 5 ++--- net/netfilter/nft_immediate.c | 6 +++--- net/netfilter/nft_payload.c | 6 +++--- net/netfilter/nft_range.c | 5 ++--- net/netfilter/nft_rt.c | 6 +++--- 10 files changed, 55 insertions(+), 31 deletions(-)
include/net/netfilter/nf_tables_core.h +16 -0
@@ -80,6 +80,22 @@ struct nft_regs;struct nft_pktinfo ;void nft_meta_get_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt); +void nft_cmp_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt);void nft_lookup_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt); +void nft_payload_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt); +void nft_immediate_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt); +void nft_bitwise_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt); +void nft_range_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt); +void nft_byteorder_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt); +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);#endif /* _NET_NF_TABLES_CORE_H */
net/netfilter/nf_tables_core.c +18 -7
@@ -124,14 +124,25 @@ static void expr_call_ops_eval(const struct nft_expr *expr,struct nft_regs *regs, struct nft_pktinfo *pkt) { +#ifdef CONFIG_RETPOLINE unsigned long e = (unsigned long)expr->ops->eval; - -if (e == (unsigned long )nft_meta_get_eval) -nft_meta_get_eval (expr, regs, pkt); -else if (e == (unsigned long )nft_lookup_eval) -nft_lookup_eval (expr, regs, pkt); -else - expr->ops->eval (expr, regs, pkt); +#define X (e, fun) \ + do { if ((e) == (unsigned long)(fun)) \ + return fun(expr, regs, pkt); } while (0) + +X (e, nft_payload_eval); +X (e, nft_cmp_eval); +X (e, nft_meta_get_eval); +X (e, nft_lookup_eval); +X (e, nft_range_eval); +X (e, nft_immediate_eval); +X (e, nft_byteorder_eval); +X (e, nft_dynset_eval); +X (e, nft_rt_get_eval); +X (e, nft_bitwise_eval); +#undef X +#endif /* CONFIG_RETPOLINE */ + expr->ops->eval (expr, regs, pkt); }unsigned int
net/netfilter/nft_bitwise.c +2 -3
@@ -25,9 +25,8 @@ struct nft_bitwise {struct nft_data xor; }; -static void nft_bitwise_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +void nft_bitwise_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt) {const struct nft_bitwise *priv =nft_expr_priv (expr);const u32 *src = ®s->data[priv->sreg];
net/netfilter/nft_byteorder.c +3 -3
@@ -26,9 +26,9 @@ struct nft_byteorder {u8 size; }; -static void nft_byteorder_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +void nft_byteorder_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) {const struct nft_byteorder *priv =nft_expr_priv (expr);u32 *src = ®s->data[priv->sreg];
net/netfilter/nft_cmp.c +3 -3
@@ -24,9 +24,9 @@ struct nft_cmp_expr { enum nft_cmp_ops op:8; }; -static void nft_cmp_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +void nft_cmp_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) {const struct nft_cmp_expr *priv =nft_expr_priv (expr);int d;
net/netfilter/nft_dynset.c +2 -3
@@ -62,9 +62,8 @@ static void *nft_dynset_new(struct nft_set *set, const struct nft_expr *expr,return NULL ; } -static void nft_dynset_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +void nft_dynset_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt) {const struct nft_dynset *priv =nft_expr_priv (expr);struct nft_set *set = priv->set;
net/netfilter/nft_immediate.c +3 -3
@@ -17,9 +17,9 @@#include <net/netfilter/nf_tables_core.h> #include <net/netfilter/nf_tables.h> -static void nft_immediate_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +void nft_immediate_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) {const struct nft_immediate_expr *priv =nft_expr_priv (expr);
net/netfilter/nft_payload.c +3 -3
@@ -70,9 +70,9 @@ nft_payload_copy_vlan(u32 *d, const struct sk_buff *skb, u8 offset, u8 len)return skb_copy_bits (skb, offset + mac_off, dst_u8, len) ==0 ; } -static void nft_payload_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +void nft_payload_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) {const struct nft_payload *priv =nft_expr_priv (expr);const struct sk_buff *skb = pkt->skb;
net/netfilter/nft_range.c +2 -3
@@ -23,9 +23,8 @@ struct nft_range_expr { enum nft_range_ops op:8; }; -static void nft_range_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +void nft_range_eval (const struct nft_expr *expr, +struct nft_regs *regs,const struct nft_pktinfo *pkt) {const struct nft_range_expr *priv =nft_expr_priv (expr);int d1, d2;
net/netfilter/nft_rt.c +3 -3
@@ -53,9 +53,9 @@ static u16 get_tcpmss(const struct nft_pktinfo *pkt, const struct dst_entry *skbreturn mtu - minlen; } -static void nft_rt_get_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) {const struct nft_rt *priv =nft_expr_priv (expr);const struct sk_buff *skb = pkt->skb;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/33 netfilter: conntrack: remove helper hook again
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
place them into the confirm one.
Old:
hook (300): ipv4/6_help() first call helper, then seqadj. hook (INT_MAX): confirm
Now:
hook (INT_MAX): confirm, first call helper, then seqadj, then confirm
Not having the extra call is noticeable in bechmarks.
--- net/netfilter/nf_conntrack_proto.c | 142 ++++++++++--------------------------- 1 file changed, 36 insertions(+), 106 deletions(-)
net/netfilter/nf_conntrack_proto.c +36 -106
@@ -364,55 +364,55 @@ void nf_ct_l4proto_pernet_unregister(struct net *net, }EXPORT_SYMBOL_GPL (nf_ct_l4proto_pernet_unregister); -static unsigned int ipv4_helper (void *priv, -struct sk_buff *skb, -const struct nf_hook_state *state) +static unsigned int nf_confirm (struct sk_buff *skb, +unsigned int protoff, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo) { -struct nf_conn *ct; -enum ip_conntrack_info ctinfo;const struct nf_conn_help *help; -const struct nf_conntrack_helper *helper; - -/* This is where we call the helper: as the packet goes out. */ - ct =nf_ct_get (skb, &ctinfo); -if (!ct || ctinfo ==IP_CT_RELATED_REPLY ) -return NF_ACCEPT ; help =nfct_help (ct); -if (!help) -return NF_ACCEPT ; +if (help) { +const struct nf_conntrack_helper *helper; +int ret; + +/* rcu_read_lock()ed by nf_hook_thresh */ + helper =rcu_dereference (help->helper); +if (helper) { + ret = helper->help (skb, + protoff, + ct, ctinfo); +if (ret !=NF_ACCEPT ) +return ret; + } + } -/* rcu_read_lock()ed by nf_hook_thresh */ - helper =rcu_dereference (help->helper); -if (!helper) -return NF_ACCEPT ; +if (test_bit (IPS_SEQ_ADJUST_BIT , &ct->status) && + !nf_is_loopback_packet (skb)) { +if (!nf_ct_seq_adjust (skb, ct, ctinfo, protoff)) { +NF_CT_STAT_INC_ATOMIC (nf_ct_net (ct), drop); +return NF_DROP ; + } + } -return helper->help (skb,skb_network_offset (skb) +ip_hdrlen (skb), - ct, ctinfo); +/* We've seen it coming out the other side: confirm it */ +return nf_conntrack_confirm (skb); }static unsigned int ipv4_confirm (void *priv,struct sk_buff *skb,const struct nf_hook_state *state) { -struct nf_conn *ct;enum ip_conntrack_info ctinfo; +struct nf_conn *ct; ct =nf_ct_get (skb, &ctinfo);if (!ct || ctinfo ==IP_CT_RELATED_REPLY ) - goto out; +return nf_conntrack_confirm (skb); -/* adjust seqs for loopback traffic only in outgoing direction */ -if (test_bit (IPS_SEQ_ADJUST_BIT , &ct->status) && - !nf_is_loopback_packet (skb)) { -if (!nf_ct_seq_adjust (skb, ct, ctinfo,ip_hdrlen (skb))) { -NF_CT_STAT_INC_ATOMIC (nf_ct_net (ct), drop); -return NF_DROP ; - } - } -out: -/* We've seen it coming out the other side: confirm it */ -return nf_conntrack_confirm (skb); +return nf_confirm (skb, +skb_network_offset (skb) +ip_hdrlen (skb), + ct, ctinfo); } static unsigned int ipv4_conntrack_in(void *priv,
@@ -461,24 +461,12 @@ static const struct nf_hook_ops ipv4_conntrack_ops[] = { .priority = NF_IP_PRI_CONNTRACK, }, { - .hook = ipv4_helper, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_POST_ROUTING, - .priority = NF_IP_PRI_CONNTRACK_HELPER, - }, - { .hook = ipv4_confirm, .pf = NFPROTO_IPV4, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP_PRI_CONNTRACK_CONFIRM, }, { - .hook = ipv4_helper, - .pf = NFPROTO_IPV4, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP_PRI_CONNTRACK_HELPER, - }, - { .hook = ipv4_confirm, .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_IN,
@@ -623,31 +611,21 @@ static unsigned int ipv6_confirm(void *priv,struct nf_conn *ct;enum ip_conntrack_info ctinfo;unsigned char pnum =ipv6_hdr (skb)->nexthdr; -int protoff;__be16 frag_off; +int protoff; ct =nf_ct_get (skb, &ctinfo);if (!ct || ctinfo ==IP_CT_RELATED_REPLY ) - goto out; +return nf_conntrack_confirm (skb); protoff =ipv6_skip_exthdr (skb,sizeof (struct ipv6hdr ), &pnum, &frag_off);if (protoff <0 || (frag_off &htons (~0x7 )) !=0 ) {pr_debug ("proto header not found\n" ); - goto out; +return nf_conntrack_confirm (skb); } -/* adjust seqs for loopback traffic only in outgoing direction */ -if (test_bit (IPS_SEQ_ADJUST_BIT , &ct->status) && - !nf_is_loopback_packet (skb)) { -if (!nf_ct_seq_adjust (skb, ct, ctinfo, protoff)) { -NF_CT_STAT_INC_ATOMIC (nf_ct_net (ct), drop); -return NF_DROP ; - } - } -out: -/* We've seen it coming out the other side: confirm it */ -return nf_conntrack_confirm (skb); +return nf_confirm (skb, protoff, ct, ctinfo); } static unsigned int ipv6_conntrack_in(void *priv,
@@ -664,42 +642,6 @@ static unsigned int ipv6_conntrack_local(void *priv,return nf_conntrack_in (skb, state); } -static unsigned int ipv6_helper (void *priv, -struct sk_buff *skb, -const struct nf_hook_state *state) -{ -struct nf_conn *ct; -const struct nf_conn_help *help; -const struct nf_conntrack_helper *helper; -enum ip_conntrack_info ctinfo; -__be16 frag_off; -int protoff; -u8 nexthdr; - -/* This is where we call the helper: as the packet goes out. */ - ct =nf_ct_get (skb, &ctinfo); -if (!ct || ctinfo ==IP_CT_RELATED_REPLY ) -return NF_ACCEPT ; - - help =nfct_help (ct); -if (!help) -return NF_ACCEPT ; -/* rcu_read_lock()ed by nf_hook_thresh */ - helper =rcu_dereference (help->helper); -if (!helper) -return NF_ACCEPT ; - - nexthdr =ipv6_hdr (skb)->nexthdr; - protoff =ipv6_skip_exthdr (skb,sizeof (struct ipv6hdr ), &nexthdr, - &frag_off); -if (protoff <0 || (frag_off &htons (~0x7 )) !=0 ) { -pr_debug ("proto header not found\n" ); -return NF_ACCEPT ; - } - -return helper->help (skb, protoff, ct, ctinfo); -} -static const struct nf_hook_ops ipv6_conntrack_ops[] = { { .hook = ipv6_conntrack_in,
@@ -714,24 +656,12 @@ static const struct nf_hook_ops ipv6_conntrack_ops[] = { .priority = NF_IP6_PRI_CONNTRACK, }, { - .hook = ipv6_helper, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_POST_ROUTING, - .priority = NF_IP6_PRI_CONNTRACK_HELPER, - }, - { .hook = ipv6_confirm, .pf = NFPROTO_IPV6, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP6_PRI_LAST, }, { - .hook = ipv6_helper, - .pf = NFPROTO_IPV6, - .hooknum = NF_INET_LOCAL_IN, - .priority = NF_IP6_PRI_CONNTRACK_HELPER, - }, - { .hook = ipv6_confirm, .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_IN,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/33 netfilter: physdev: relax br_netfilter dependency
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Following command:
iptables -D FORWARD -m physdev ...
causes connectivity loss in some setups.
Reason is that iptables userspace will probe kernel for the module revision of the physdev patch, and physdev has an artificial dependency on br_netfilter (xt_physdev use makes no sense unless a br_netfilter module is loaded).
This causes the "phydev" module to be loaded, which in turn enables the "call-iptables" infrastructure.
bridged packets might then get dropped by the iptables ruleset.
The better fix would be to change the "call-iptables" defaults to 0 and enforce explicit setting to 1, but that breaks backwards compatibility.
This does the next best thing: add a request_module call to checkentry. This was a stray '-D ... -m physdev' won't activate br_netfilter anymore.
--- include/net/netfilter/br_netfilter.h | 1 - net/bridge/br_netfilter_hooks.c | 5 ----- net/netfilter/xt_physdev.c | 9 +++++++-- 3 files changed, 7 insertions(+), 8 deletions(-)
include/net/netfilter/br_netfilter.h +0 -1
@@ -43,7 +43,6 @@ static inline struct rtable *bridge_parent_rtable(const struct net_device *dev) }struct net_device *setup_pre_routing (struct sk_buff *skb); -void br_netfilter_enable (void );#if IS_ENABLED (CONFIG_IPV6 )int br_validate_ipv6 (struct net *net,struct sk_buff *skb);
net/bridge/br_netfilter_hooks.c +0 -5
@@ -881,11 +881,6 @@ static const struct nf_br_ops br_ops = { .br_dev_xmit_hook = br_nf_dev_xmit, }; -void br_netfilter_enable (void ) -{ -} -EXPORT_SYMBOL_GPL (br_netfilter_enable); -/* For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because * br_dev_queue_push_xmit is called afterwards */ static const struct nf_hook_ops br_nf_ops[] = {
net/netfilter/xt_physdev.c +7 -2
@@ -96,8 +96,7 @@ physdev_mt(const struct sk_buff *skb, struct xt_action_param *par)static int physdev_mt_check (const struct xt_mtchk_param *par) {const struct xt_physdev_info *info = par->matchinfo; - -br_netfilter_enable (); +static bool brnf_probed__read_mostly ;if (!(info->bitmask &XT_PHYSDEV_OP_MASK ) || info->bitmask & ~XT_PHYSDEV_OP_MASK )
@@ -111,6 +110,12 @@ static int physdev_mt_check(const struct xt_mtchk_param *par)if (par->hook_mask & (1 <<NF_INET_LOCAL_OUT ))return -EINVAL ; } + +if (!brnf_probed) { + brnf_probed = true; +request_module ("br_netfilter" ); + } +return 0 ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/33 netfilter: nf_tables: Support RULE_ID reference in new rule
In reply to Pablo Neira AyusoFrom: Phil Sutter <[email protected]>
To allow for a batch to contain rules in arbitrary ordering, introduce NFTA_RULE_POSITION_ID attribute which works just like NFTA_RULE_POSITION but contains the ID of another rule within the same batch. This helps iptables-nft-restore handling dumps with mixed insert/append commands correctly.
Note that NFTA_RULE_POSITION takes precedence over NFTA_RULE_POSITION_ID, so if the former is present, the latter is ignored.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 9 +++++++++ 2 files changed, 11 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -219,6 +219,7 @@ enum nft_chain_attributes {* @NFTA_RULE_POSITION: numeric handle of the previous rule (NLA_U64) * @NFTA_RULE_USERDATA: user data (NLA_BINARY, NFT_USERDATA_MAXLEN) * @NFTA_RULE_ID: uniquely identifies a rule in a transaction (NLA_U32) +* @NFTA_RULE_POSITION_ID: transaction unique identifier of the previous rule (NLA_U32) */ enum nft_rule_attributes {NFTA_RULE_UNSPEC ,
@@ -231,6 +232,7 @@ enum nft_rule_attributes {NFTA_RULE_USERDATA ,NFTA_RULE_PAD ,NFTA_RULE_ID , +NFTA_RULE_POSITION_ID , __NFTA_RULE_MAX };#define NFTA_RULE_MAX (__NFTA_RULE_MAX - 1)
net/netfilter/nf_tables_api.c +9 -0
@@ -2610,6 +2610,9 @@ static int nft_table_validate(struct net *net, const struct nft_table *table)return 0 ; } +static struct nft_rule *nft_rule_lookup_byid (const struct net *net, +const struct nlattr *nla); +#define NFT_RULE_MAXEXPRS 128 static int nf_tables_newrule(struct net *net, struct sock *nlsk,
@@ -2679,6 +2682,12 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,NL_SET_BAD_ATTR (extack, nla[NFTA_RULE_POSITION ]);return PTR_ERR (old_rule); } + }else if (nla[NFTA_RULE_POSITION_ID ]) { + old_rule =nft_rule_lookup_byid (net, nla[NFTA_RULE_POSITION_ID ]); +if (IS_ERR (old_rule)) { +NL_SET_BAD_ATTR (extack, nla[NFTA_RULE_POSITION_ID ]); +return PTR_ERR (old_rule); + } } }
Signature · 1 line
2.11.0
Re: [PATCH 06/33] netfilter: nf_tables: Support RULE_ID reference in new rule
Quoted 9 lines · Pablo Neira Ayuso
From: Phil Sutter <[email protected]>
To allow for a batch to contain rules in arbitrary ordering, introduce
NFTA_RULE_POSITION_IDattribute which works just likeNFTA_RULE_POSITIONbut contains the ID of another rule within the same batch. This helps iptables-nft-restore handling dumps with mixed insert/append commands correctly.
Quoted 3 lines
Note that
NFTA_RULE_POSITIONtakes precedence overNFTA_RULE_POSITION_ID, so if the former is present, the latter is ignored.
It looks like you forgot to add NFTA_RULE_POSITION_ID into nft_rule_policy[]?
Florian Westphal
maintainerRe: [PATCH 06/33] netfilter: nf_tables: Support RULE_ID reference in new rule
Quoted 6 lines · Cong Wang
Quoted 3 lines
Note that
NFTA_RULE_POSITIONtakes precedence overNFTA_RULE_POSITION_ID, so if the former is present, the latter is ignored.It looks like you forgot to add
NFTA_RULE_POSITION_IDinto nft_rule_policy[]?
Classic...
Thanks for spotting this, I'll send a patch.
Pablo Neira Ayuso
maintainerPATCH 7/33 netfilter: conntrack: handle builtin l4proto packet functions via direct calls
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The l4 protocol trackers are invoked via indirect call: l4proto->packet().
With one exception (gre), all l4trackers are builtin, so we can make .packet optional and use a direct call for most protocols.
--- include/net/netfilter/nf_conntrack_l4proto.h | 37 +++++++++++++++++++++++ net/netfilter/nf_conntrack_core.c | 45 +++++++++++++++++++++++++++- net/netfilter/nf_conntrack_proto_dccp.c | 8 ++--- net/netfilter/nf_conntrack_proto_icmp.c | 12 +++----- net/netfilter/nf_conntrack_proto_icmpv6.c | 10 +++---- net/netfilter/nf_conntrack_proto_sctp.c | 12 ++++---- net/netfilter/nf_conntrack_proto_tcp.c | 11 ++++--- net/netfilter/nf_conntrack_proto_udp.c | 22 +++++++------- 8 files changed, 113 insertions(+), 44 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +37 -0
@@ -99,6 +99,43 @@ int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,struct sk_buff *skb, unsigned int dataoff, const struct nf_hook_state *state); + +int nf_conntrack_icmp_packet (struct nf_conn *ct, +struct sk_buff *skb, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state); + +int nf_conntrack_icmpv6_packet (struct nf_conn *ct, +struct sk_buff *skb, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state); + +int nf_conntrack_udp_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state); +int nf_conntrack_udplite_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state); +int nf_conntrack_tcp_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state); +int nf_conntrack_dccp_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state); +int nf_conntrack_sctp_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state); +/* Existing built-in generic protocol */ extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
net/netfilter/nf_conntrack_core.c +44 -1
57 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_dccp.c +4 -4
@@ -472,9 +472,10 @@ static bool dccp_error(const struct dccp_hdr *dh,return true; } -static int dccp_packet (struct nf_conn *ct,struct sk_buff *skb, -unsigned int dataoff,enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_dccp_packet (struct nf_conn *ct,struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);struct dccp_hdr _dh, *dh;
@@ -839,7 +840,6 @@ static struct nf_proto_net *dccp_get_net_proto(struct net *net)const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp = { .l4proto =IPPROTO_DCCP , - .packet = dccp_packet, .can_early_drop = dccp_can_early_drop, #ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = dccp_print_conntrack,
net/netfilter/nf_conntrack_proto_icmp.c +4 -8
@@ -68,11 +68,10 @@ static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple, }/* Returns verdict for packet, or -1 for invalid. */ -static int icmp_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_icmp_packet (struct nf_conn *ct, +struct sk_buff *skb, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {/* Do not immediately delete the connection after the first successful reply to avoid excessive conntrackd traffic
@@ -350,9 +349,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp = .l4proto = IPPROTO_ICMP, .pkt_to_tuple = icmp_pkt_to_tuple, .invert_tuple = icmp_invert_tuple, - .packet = icmp_packet, - .destroy = NULL, - .me =NULL ,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = icmp_tuple_to_nlattr, .nlattr_tuple_size = icmp_nlattr_tuple_size,
net/netfilter/nf_conntrack_proto_icmpv6.c +4 -6
@@ -86,11 +86,10 @@ static unsigned int *icmpv6_get_timeouts(struct net *net) }/* Returns verdict for packet, or -1 for invalid. */ -static int icmpv6_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_icmpv6_packet (struct nf_conn *ct, +struct sk_buff *skb, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {unsigned int *timeout =nf_ct_timeout_lookup (ct);static const u8 valid_new[] = {
@@ -361,7 +360,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 = .l4proto = IPPROTO_ICMPV6, .pkt_to_tuple = icmpv6_pkt_to_tuple, .invert_tuple = icmpv6_invert_tuple, - .packet = icmpv6_packet,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = icmpv6_tuple_to_nlattr, .nlattr_tuple_size = icmpv6_nlattr_tuple_size,
net/netfilter/nf_conntrack_proto_sctp.c +5 -7
@@ -357,11 +357,11 @@ static bool sctp_error(struct sk_buff *skb, }/* Returns verdict for packet, or -NF_ACCEPT for invalid. */ -static int sctp_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_sctp_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {enum sctp_conntrack new_state, old_state;enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);
@@ -759,9 +759,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp = {#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = sctp_print_conntrack, #endif - .packet = sctp_packet, .can_early_drop = sctp_can_early_drop, - .me =THIS_MODULE ,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .nlattr_size = SCTP_NLATTR_SIZE, .to_nlattr = sctp_to_nlattr,
net/netfilter/nf_conntrack_proto_tcp.c +5 -6
@@ -829,11 +829,11 @@ static noinline bool tcp_new(struct nf_conn *ct, const struct sk_buff *skb, }/* Returns verdict for packet, or -1 for invalid. */ -static int tcp_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_tcp_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {struct net *net =nf_ct_net (ct);struct nf_tcp_net *tn =nf_tcp_pernet (net);
@@ -1535,7 +1535,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp =#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = tcp_print_conntrack, #endif - .packet = tcp_packet, .can_early_drop = tcp_can_early_drop,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .to_nlattr = tcp_to_nlattr,
net/netfilter/nf_conntrack_proto_udp.c +10 -12
@@ -85,11 +85,11 @@ static bool udp_error(struct sk_buff *skb, }/* Returns verdict for packet, and may modify conntracktype */ -static int udp_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_udp_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {unsigned int *timeouts;
@@ -177,11 +177,11 @@ static bool udplite_error(struct sk_buff *skb, }/* Returns verdict for packet, and may modify conntracktype */ -static int udplite_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_udplite_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {unsigned int *timeouts;
@@ -319,7 +319,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp = { .l4proto = IPPROTO_UDP, .allow_clash = true, - .packet = udp_packet,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
@@ -344,7 +343,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite = { .l4proto = IPPROTO_UDPLITE, .allow_clash = true, - .packet = udplite_packet,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/33 netfilter: conntrack: handle icmp pkt_to_tuple helper via direct calls
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
rather than handling them via indirect call, use a direct one instead. This leaves GRE as the last user of this indirect call facility.
--- include/net/netfilter/nf_conntrack_l4proto.h | 10 ++++++++++ net/netfilter/nf_conntrack_core.c | 6 ++++++ net/netfilter/nf_conntrack_proto_icmp.c | 5 ++--- net/netfilter/nf_conntrack_proto_icmpv6.c | 9 ++++----- 4 files changed, 22 insertions(+), 8 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +10 -0
@@ -90,6 +90,16 @@ struct nf_conntrack_l4proto {struct module *me; }; +bool icmp_pkt_to_tuple (const struct sk_buff *skb, +unsigned int dataoff, +struct net *net, +struct nf_conntrack_tuple *tuple); + +bool icmpv6_pkt_to_tuple (const struct sk_buff *skb, +unsigned int dataoff, +struct net *net, +struct nf_conntrack_tuple *tuple); + int nf_conntrack_icmpv4_error(struct nf_conn *tmpl, struct sk_buff *skb, unsigned int dataoff,
net/netfilter/nf_conntrack_core.c +6 -0
@@ -274,6 +274,12 @@ nf_ct_get_tuple(const struct sk_buff *skb, tuple->dst.protonum = protonum; tuple->dst.dir =IP_CT_DIR_ORIGINAL ; +switch (protonum) { +case IPPROTO_ICMPV6 : +return icmpv6_pkt_to_tuple (skb, dataoff, net, tuple); +case IPPROTO_ICMP : +return icmp_pkt_to_tuple (skb, dataoff, net, tuple); + }if (unlikely (l4proto->pkt_to_tuple))return l4proto->pkt_to_tuple (skb, dataoff, net, tuple);
net/netfilter/nf_conntrack_proto_icmp.c +2 -3
@@ -25,8 +25,8 @@static const unsigned int nf_ct_icmp_timeout =30 *HZ ; -static bool icmp_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff, -struct net *net,struct nf_conntrack_tuple *tuple) +bool icmp_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff, +struct net *net,struct nf_conntrack_tuple *tuple) {const struct icmphdr *hp;struct icmphdr _hdr;
@@ -347,7 +347,6 @@ static struct nf_proto_net *icmp_get_net_proto(struct net *net)const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp = { .l4proto =IPPROTO_ICMP , - .pkt_to_tuple = icmp_pkt_to_tuple, .invert_tuple = icmp_invert_tuple, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .tuple_to_nlattr = icmp_tuple_to_nlattr,
net/netfilter/nf_conntrack_proto_icmpv6.c +4 -5
@@ -30,10 +30,10 @@static const unsigned int nf_ct_icmpv6_timeout =30 *HZ ; -static bool icmpv6_pkt_to_tuple (const struct sk_buff *skb, -unsigned int dataoff, -struct net *net, -struct nf_conntrack_tuple *tuple) +bool icmpv6_pkt_to_tuple (const struct sk_buff *skb, +unsigned int dataoff, +struct net *net, +struct nf_conntrack_tuple *tuple) {const struct icmp6hdr *hp;struct icmp6hdr _hdr;
@@ -358,7 +358,6 @@ static struct nf_proto_net *icmpv6_get_net_proto(struct net *net)const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 = { .l4proto =IPPROTO_ICMPV6 , - .pkt_to_tuple = icmpv6_pkt_to_tuple, .invert_tuple = icmpv6_invert_tuple, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .tuple_to_nlattr = icmpv6_tuple_to_nlattr,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/33 netfilter: conntrack: gre: convert rwlock to rcu
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We can use gre. Lock is only needed when a new expectation is added.
In case a single spinlock proves to be problematic we can either add one per netns or use an array of locks combined with net_hash_mix() or similar to pick the 'correct' one.
But given this is only needed for an expectation rather than per packet a single one should be ok.
--- include/linux/netfilter/nf_conntrack_proto_gre.h | 1 + net/netfilter/nf_conntrack_proto_gre.c | 37 ++++++++++-------------- 2 files changed, 16 insertions(+), 22 deletions(-)
include/linux/netfilter/nf_conntrack_proto_gre.h +1 -0
@@ -19,6 +19,7 @@ struct nf_conn;struct nf_ct_gre_keymap {struct list_head list;struct nf_conntrack_tuple tuple; +struct rcu_head rcu; };enum grep_conntrack {
net/netfilter/nf_conntrack_proto_gre.c +15 -22
@@ -49,6 +49,8 @@ static const unsigned int gre_timeouts[GRE_CT_MAX] = { };static unsigned int proto_gre_net_id__read_mostly ; +/* used when expectation is added */ +static DEFINE_SPINLOCK (keymap_lock);static inline struct netns_proto_gre *gre_pernet (struct net *net) {
@@ -60,12 +62,12 @@ static void nf_ct_gre_keymap_flush(struct net *net)struct netns_proto_gre *net_gre =gre_pernet (net);struct nf_ct_gre_keymap *km, *tmp; -write_lock_bh (&net_gre->keymap_lock); +spin_lock_bh (&keymap_lock);list_for_each_entry_safe (km, tmp, &net_gre->keymap_list, list) { -list_del (&km->list); -kfree (km); +list_del_rcu (&km->list); +kfree_rcu (km, rcu); } -write_unlock_bh (&net_gre->keymap_lock); +spin_unlock_bh (&keymap_lock); } static inline int gre_key_cmpfn(const struct nf_ct_gre_keymap *km,
@@ -85,14 +87,12 @@ static __be16 gre_keymap_lookup(struct net *net, struct nf_conntrack_tuple *t)struct nf_ct_gre_keymap *km;__be16 key =0 ; -read_lock_bh (&net_gre->keymap_lock); -list_for_each_entry (km, &net_gre->keymap_list, list) { +list_for_each_entry_rcu (km, &net_gre->keymap_list, list) {if (gre_key_cmpfn (km, t)) { key = km->tuple.src.u.gre.key;break ; } } -read_unlock_bh (&net_gre->keymap_lock);pr_debug ("lookup src key 0x%x for " , key);nf_ct_dump_tuple (t);
@@ -112,14 +112,10 @@ int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir, kmp = &ct_pptp_info->keymap[dir];if (*kmp) {/* check whether it's a retransmission */ -read_lock_bh (&net_gre->keymap_lock); -list_for_each_entry (km, &net_gre->keymap_list, list) { -if (gre_key_cmpfn (km, t) && km == *kmp) { -read_unlock_bh (&net_gre->keymap_lock); +list_for_each_entry_rcu (km, &net_gre->keymap_list, list) { +if (gre_key_cmpfn (km, t) && km == *kmp)return 0 ; - } } -read_unlock_bh (&net_gre->keymap_lock);pr_debug ("trying to override keymap_%s for ct %p\n" , dir ==IP_CT_DIR_REPLY ?"reply" :"orig" , ct);return -EEXIST ;
@@ -134,9 +130,9 @@ int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir,pr_debug ("adding new entry %p: " , km);nf_ct_dump_tuple (&km->tuple); -write_lock_bh (&net_gre->keymap_lock); +spin_lock_bh (&keymap_lock);list_add_tail (&km->list, &net_gre->keymap_list); -write_unlock_bh (&net_gre->keymap_lock); +spin_unlock_bh (&keymap_lock);return 0 ; }
@@ -145,24 +141,22 @@ EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_add);/* destroy the keymap entries associated with specified master ct */ void nf_ct_gre_keymap_destroy (struct nf_conn *ct) { -struct net *net =nf_ct_net (ct); -struct netns_proto_gre *net_gre =gre_pernet (net);struct nf_ct_pptp_master *ct_pptp_info =nfct_help_data (ct);enum ip_conntrack_dir dir;pr_debug ("entering for ct %p\n" , ct); -write_lock_bh (&net_gre->keymap_lock); +spin_lock_bh (&keymap_lock);for (dir =IP_CT_DIR_ORIGINAL ; dir <IP_CT_DIR_MAX ; dir++) {if (ct_pptp_info->keymap[dir]) {pr_debug ("removing %p from list\n" , ct_pptp_info->keymap[dir]); -list_del (&ct_pptp_info->keymap[dir]->list); -kfree (ct_pptp_info->keymap[dir]); +list_del_rcu (&ct_pptp_info->keymap[dir]->list); +kfree_rcu (ct_pptp_info->keymap[dir], rcu); ct_pptp_info->keymap[dir] =NULL ; } } -write_unlock_bh (&net_gre->keymap_lock); +spin_unlock_bh (&keymap_lock); }EXPORT_SYMBOL_GPL (nf_ct_gre_keymap_destroy);
@@ -365,7 +359,6 @@ static int gre_init_net(struct net *net)struct nf_proto_net *nf = &net_gre->nf;int i; -rwlock_init (&net_gre->keymap_lock);INIT_LIST_HEAD (&net_gre->keymap_list);for (i =0 ; i <GRE_CT_MAX ; i++) net_gre->gre_timeouts[i] = gre_timeouts[i];
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/33 netfilter: conntrack: gre: switch module to be built-in
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This makes the last of the modular l4 trackers 'bool'.
After this, all infrastructure to handle dynamic l4 protocol registration becomes obsolete and can be removed in followup patches.
Old:
302824 net/netfilter/nf_conntrack.ko
21504 net/netfilter/nf_conntrack_proto_gre.ko
New:
313728 net/netfilter/nf_conntrack.ko
Old:
text data bss dec hex filename
6281 1732 4 8017 1f51 nf_conntrack_proto_gre.ko
108356 20613 236 129205 1f8b5 nf_conntrack.ko
New:
112095 21381 240 133716 20a54 nf_conntrack.ko
The size increase is only temporary.
--- include/linux/netfilter/nf_conntrack_proto_gre.h | 14 +--- include/net/netfilter/ipv4/nf_conntrack_ipv4.h | 3 + include/net/netfilter/nf_conntrack_l4proto.h | 7 ++ include/net/netns/conntrack.h | 17 +++++ net/netfilter/Kconfig | 2 +- net/netfilter/Makefile | 3 +- net/netfilter/nf_conntrack_proto.c | 7 +- net/netfilter/nf_conntrack_proto_gre.c | 93 +++++------------------- net/netfilter/nfnetlink_cttimeout.c | 7 +- 9 files changed, 55 insertions(+), 98 deletions(-)
include/linux/netfilter/nf_conntrack_proto_gre.h +1 -13
@@ -22,23 +22,11 @@ struct nf_ct_gre_keymap {struct rcu_head rcu; }; -enum grep_conntrack { -GRE_CT_UNREPLIED , -GRE_CT_REPLIED , -GRE_CT_MAX -}; - -struct netns_proto_gre { -struct nf_proto_net nf; -rwlock_t keymap_lock; -struct list_head keymap_list; -unsigned int gre_timeouts[GRE_CT_MAX ]; -}; -/* add new tuple->key_reply pair to keymap */ int nf_ct_gre_keymap_add (struct nf_conn *ct,enum ip_conntrack_dir dir,struct nf_conntrack_tuple *t); +void nf_ct_gre_keymap_flush (struct net *net);/* delete keymap entries */ void nf_ct_gre_keymap_destroy (struct nf_conn *ct);
include/net/netfilter/ipv4/nf_conntrack_ipv4.h +3 -0
@@ -22,5 +22,8 @@ extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp;#ifdef CONFIG_NF_CT_PROTO_UDPLITE extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite;#endif +#ifdef CONFIG_NF_CT_PROTO_GRE +extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre; +#endif #endif /*_NF_CONNTRACK_IPV4_H*/
include/net/netfilter/nf_conntrack_l4proto.h +7 -0
@@ -239,4 +239,11 @@ static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net) }#endif +#ifdef CONFIG_NF_CT_PROTO_GRE +static inline struct nf_gre_net *nf_gre_pernet (struct net *net) +{ +return &net->ct.nf_ct_proto.gre; +} +#endif +#endif /*_NF_CONNTRACK_PROTOCOL_H*/
include/net/netns/conntrack.h +17 -0
@@ -70,6 +70,20 @@ struct nf_sctp_net { };#endif +#ifdef CONFIG_NF_CT_PROTO_GRE +enum gre_conntrack { +GRE_CT_UNREPLIED , +GRE_CT_REPLIED , +GRE_CT_MAX +}; + +struct nf_gre_net { +struct nf_proto_net nf; +struct list_head keymap_list; +unsigned int timeouts[GRE_CT_MAX ]; +}; +#endif +struct nf_ip_net {struct nf_generic_net generic;struct nf_tcp_net tcp;
@@ -82,6 +96,9 @@ struct nf_ip_net {#ifdef CONFIG_NF_CT_PROTO_SCTP struct nf_sctp_net sctp;#endif +#ifdef CONFIG_NF_CT_PROTO_GRE +struct nf_gre_net gre; +#endif };struct ct_pcpu {
net/netfilter/Kconfig +1 -1
@@ -174,7 +174,7 @@ config NF_CT_PROTO_DCCP If unsure, say Y. config NF_CT_PROTO_GRE - tristate + bool config NF_CT_PROTO_SCTP bool 'SCTP protocol connection tracking support'
net/netfilter/Makefile +1 -2
@@ -13,6 +13,7 @@ nf_conntrack-$(CONFIG_NF_CONNTRACK_EVENTS) += nf_conntrack_ecache.o nf_conntrack-$(CONFIG_NF_CONNTRACK_LABELS) += nf_conntrack_labels.o nf_conntrack-$(CONFIG_NF_CT_PROTO_DCCP) += nf_conntrack_proto_dccp.o nf_conntrack-$(CONFIG_NF_CT_PROTO_SCTP) += nf_conntrack_proto_sctp.o +nf_conntrack-$(CONFIG_NF_CT_PROTO_GRE) += nf_conntrack_proto_gre.o obj-$(CONFIG_NETFILTER) = netfilter.o
@@ -25,8 +26,6 @@ obj-$(CONFIG_NETFILTER_NETLINK_OSF) += nfnetlink_osf.o # connection tracking obj-$(CONFIG_NF_CONNTRACK) += nf_conntrack.o -obj-$(CONFIG_NF_CT_PROTO_GRE) += nf_conntrack_proto_gre.o - # netlink interface for nf_conntrack obj-$(CONFIG_NF_CT_NETLINK) += nf_conntrack_netlink.o obj-$(CONFIG_NF_CT_NETLINK_TIMEOUT) += nfnetlink_cttimeout.o
net/netfilter/nf_conntrack_proto.c +6 -1
@@ -817,6 +817,9 @@ static const struct nf_conntrack_l4proto * const builtin_l4proto[] = {#ifdef CONFIG_NF_CT_PROTO_UDPLITE &nf_conntrack_l4proto_udplite,#endif +#ifdef CONFIG_NF_CT_PROTO_GRE + &nf_conntrack_l4proto_gre, +#endif #if IS_ENABLED (CONFIG_IPV6 ) &nf_conntrack_l4proto_icmpv6,#endif /* CONFIG_IPV6 */
@@ -897,9 +900,11 @@ void nf_conntrack_proto_pernet_fini(struct net *net) ARRAY_SIZE(builtin_l4proto)); pn->users--;nf_ct_l4proto_unregister_sysctl (pn); +#ifdef CONFIG_NF_CT_PROTO_GRE +nf_ct_gre_keymap_flush (net); +#endif } -module_param_call (hashsize, nf_conntrack_set_hashsize, param_get_uint, &nf_conntrack_htable_size,0600 );
net/netfilter/nf_conntrack_proto_gre.c +18 -75
167 lines not on this page · raw message
net/netfilter/nfnetlink_cttimeout.c +1 -6
@@ -474,12 +474,7 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,break ;case IPPROTO_GRE :#ifdef CONFIG_NF_CT_PROTO_GRE -if (l4proto->net_id) { -struct netns_proto_gre *net_gre; - - net_gre =net_generic (net, *l4proto->net_id); - timeouts = net_gre->gre_timeouts; - } + timeouts =nf_gre_pernet (net)->timeouts;#endif break ;case 255 :
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/33 netfilter: conntrack: remove net_id
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
No users anymore.
--- include/net/netfilter/nf_conntrack_l4proto.h | 2 +- net/netfilter/nf_conntrack_proto.c | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +1 -1
@@ -79,7 +79,7 @@ struct nf_conntrack_l4proto {/* Print out the private part of the conntrack. */ void (*print_conntrack)(struct seq_file *s,struct nf_conn *);#endif -unsigned int *net_id; +/* Init l4proto pernet data */ int (*init_net)(struct net *net);
net/netfilter/nf_conntrack_proto.c +2 -6
@@ -163,13 +163,9 @@ static int kill_l4proto(struct nf_conn *i, void *data)static struct nf_proto_net *nf_ct_l4proto_net (struct net *net,const struct nf_conntrack_l4proto *l4proto) { -if (l4proto->get_net_proto) { -/* statically built-in protocols use static per-net */ +if (l4proto->get_net_proto)return l4proto->get_net_proto (net); - }else if (l4proto->net_id) { -/* ... and loadable protocols use dynamic per-net */ -return net_generic (net, *l4proto->net_id); - } +return NULL ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 12/33 netfilter: conntrack: remove pkt_to_tuple callback
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
GRE is now builtin, so we can handle it via direct call and remove the callback.
--- include/linux/netfilter/nf_conntrack_proto_gre.h | 2 ++ include/net/netfilter/nf_conntrack_l4proto.h | 5 ----- net/netfilter/nf_conntrack_core.c | 6 ++++-- net/netfilter/nf_conntrack_proto_generic.c | 11 ----------- net/netfilter/nf_conntrack_proto_gre.c | 5 ++--- 5 files changed, 8 insertions(+), 21 deletions(-)
include/linux/netfilter/nf_conntrack_proto_gre.h +2 -0
@@ -30,5 +30,7 @@ void nf_ct_gre_keymap_flush(struct net *net);/* delete keymap entries */ void nf_ct_gre_keymap_destroy (struct nf_conn *ct); +bool gre_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff, +struct net *net,struct nf_conntrack_tuple *tuple);#endif /* __KERNEL__ */ #endif /* _CONNTRACK_PROTO_GRE_H */
include/net/netfilter/nf_conntrack_l4proto.h +0 -5
@@ -27,11 +27,6 @@ struct nf_conntrack_l4proto {/* protoinfo nlattr size, closes a hole */ u16 nlattr_size; -/* Try to fill in the third arg: dataoff is offset past network protocol -hdr. Return true if possible. */ -bool (*pkt_to_tuple)(const struct sk_buff *skb,unsigned int dataoff, -struct net *net,struct nf_conntrack_tuple *tuple); -/* Invert the per-proto part of the tuple: ie. turn xmit into reply. * Only used by icmp, most protocols use a generic version. */
net/netfilter/nf_conntrack_core.c +4 -2
@@ -279,9 +279,11 @@ nf_ct_get_tuple(const struct sk_buff *skb,return icmpv6_pkt_to_tuple (skb, dataoff, net, tuple);case IPPROTO_ICMP :return icmp_pkt_to_tuple (skb, dataoff, net, tuple); +#ifdef CONFIG_NF_CT_PROTO_GRE +case IPPROTO_GRE : +return gre_pkt_to_tuple (skb, dataoff, net, tuple); +#endif } -if (unlikely (l4proto->pkt_to_tuple)) -return l4proto->pkt_to_tuple (skb, dataoff, net, tuple);/* Actually only need first 4 bytes to get ports. */ inet_hdr =skb_header_pointer (skb, dataoff,sizeof (_inet_hdr), &_inet_hdr);
net/netfilter/nf_conntrack_proto_generic.c +0 -11
@@ -27,16 +27,6 @@ static bool nf_generic_should_process(u8 proto) } } -static bool generic_pkt_to_tuple (const struct sk_buff *skb, -unsigned int dataoff, -struct net *net,struct nf_conntrack_tuple *tuple) -{ - tuple->src.u.all =0 ; - tuple->dst.u.all =0 ; - -return true; -} -/* Returns verdict for packet, or -1 for invalid. */ static int generic_packet(struct nf_conn *ct, struct sk_buff *skb,
@@ -149,7 +139,6 @@ static struct nf_proto_net *generic_get_net_proto(struct net *net) const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic = { .l4proto = 255, - .pkt_to_tuple = generic_pkt_to_tuple, .packet = generic_packet, #ifdef CONFIG_NF_CONNTRACK_TIMEOUT .ctnl_timeout = {
net/netfilter/nf_conntrack_proto_gre.c +2 -3
@@ -162,8 +162,8 @@ EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_destroy);/* PUBLIC CONNTRACK PROTO HELPER FUNCTIONS */ /* gre hdr info to tuple */ -static bool gre_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff, -struct net *net,struct nf_conntrack_tuple *tuple) +bool gre_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff, +struct net *net,struct nf_conntrack_tuple *tuple) {const struct pptp_gre_header *pgrehdr;struct pptp_gre_header _pgrehdr;
@@ -368,7 +368,6 @@ static int gre_init_net(struct net *net)/* protocol helper struct */ const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre = { .l4proto =IPPROTO_GRE , - .pkt_to_tuple = gre_pkt_to_tuple, #ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = gre_print_conntrack, #endif
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 13/33 netfilter: conntrack: remove invert_tuple callback
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Only used by icmp(v6). Prefer a direct call and remove this function from the l4proto struct.
--- include/net/netfilter/nf_conntrack_l4proto.h | 11 +++++------ net/netfilter/nf_conntrack_core.c | 8 ++++++-- net/netfilter/nf_conntrack_proto_icmp.c | 5 ++--- net/netfilter/nf_conntrack_proto_icmpv6.c | 5 ++--- 4 files changed, 15 insertions(+), 14 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +5 -6
@@ -27,12 +27,6 @@ struct nf_conntrack_l4proto {/* protoinfo nlattr size, closes a hole */ u16 nlattr_size; -/* Invert the per-proto part of the tuple: ie. turn xmit into reply. -* Only used by icmp, most protocols use a generic version. -*/ -bool (*invert_tuple)(struct nf_conntrack_tuple *inverse, -const struct nf_conntrack_tuple *orig); -/* Returns verdict for packet, or -1 for invalid. */ int (*packet)(struct nf_conn *ct, struct sk_buff *skb,
@@ -95,6 +89,11 @@ bool icmpv6_pkt_to_tuple(const struct sk_buff *skb,struct net *net, struct nf_conntrack_tuple *tuple); +bool nf_conntrack_invert_icmp_tuple (struct nf_conntrack_tuple *tuple, +const struct nf_conntrack_tuple *orig); +bool nf_conntrack_invert_icmpv6_tuple (struct nf_conntrack_tuple *tuple, +const struct nf_conntrack_tuple *orig); + int nf_conntrack_icmpv4_error(struct nf_conn *tmpl, struct sk_buff *skb, unsigned int dataoff,
net/netfilter/nf_conntrack_core.c +6 -2
@@ -423,8 +423,12 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse, inverse->dst.protonum = orig->dst.protonum; -if (unlikely (l4proto->invert_tuple)) -return l4proto->invert_tuple (inverse, orig); +switch (orig->dst.protonum) { +case IPPROTO_ICMP : +return nf_conntrack_invert_icmp_tuple (inverse, orig); +case IPPROTO_ICMPV6 : +return nf_conntrack_invert_icmpv6_tuple (inverse, orig); + } inverse->src.u.all = orig->dst.u.all; inverse->dst.u.all = orig->src.u.all;
net/netfilter/nf_conntrack_proto_icmp.c +2 -3
@@ -54,8 +54,8 @@ static const u_int8_t invmap[] = { [ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1 }; -static bool icmp_invert_tuple (struct nf_conntrack_tuple *tuple, -const struct nf_conntrack_tuple *orig) +bool nf_conntrack_invert_icmp_tuple (struct nf_conntrack_tuple *tuple, +const struct nf_conntrack_tuple *orig) {if (orig->dst.u.icmp.type >=sizeof (invmap) || !invmap[orig->dst.u.icmp.type])
@@ -347,7 +347,6 @@ static struct nf_proto_net *icmp_get_net_proto(struct net *net)const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp = { .l4proto =IPPROTO_ICMP , - .invert_tuple = icmp_invert_tuple, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .tuple_to_nlattr = icmp_tuple_to_nlattr, .nlattr_tuple_size = icmp_nlattr_tuple_size,
net/netfilter/nf_conntrack_proto_icmpv6.c +2 -3
@@ -67,8 +67,8 @@ static const u_int8_t noct_valid_new[] = { [ICMPV6_MLD2_REPORT - 130] = 1 }; -static bool icmpv6_invert_tuple (struct nf_conntrack_tuple *tuple, -const struct nf_conntrack_tuple *orig) +bool nf_conntrack_invert_icmpv6_tuple (struct nf_conntrack_tuple *tuple, +const struct nf_conntrack_tuple *orig) {int type = orig->dst.u.icmp.type -128 ;if (type <0 || type >=sizeof (invmap) || !invmap[type])
@@ -358,7 +358,6 @@ static struct nf_proto_net *icmpv6_get_net_proto(struct net *net)const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 = { .l4proto =IPPROTO_ICMPV6 , - .invert_tuple = icmpv6_invert_tuple, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .tuple_to_nlattr = icmpv6_tuple_to_nlattr, .nlattr_tuple_size = icmpv6_nlattr_tuple_size,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 14/33 netfilter: conntrack: remove module owner field
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
No need to get/put module owner reference, none of these can be removed anymore.
--- include/net/netfilter/nf_conntrack_l4proto.h | 4 ---- net/netfilter/nf_conntrack_proto.c | 8 -------- net/netfilter/nf_conntrack_proto_gre.c | 1 - net/netfilter/nfnetlink_cttimeout.c | 6 ------ net/netfilter/nft_ct.c | 2 -- 5 files changed, 21 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +0 -4
@@ -74,9 +74,6 @@ struct nf_conntrack_l4proto {/* Return the per-net protocol part. */ struct nf_proto_net *(*get_net_proto)(struct net *net); - -/* Module (if any) which this is connected to. */ -struct module *me; }; bool icmp_pkt_to_tuple(const struct sk_buff *skb,
@@ -148,7 +145,6 @@ extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;const struct nf_conntrack_l4proto *__nf_ct_l4proto_find (u8 l4proto);const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get (u8 l4proto); -void nf_ct_l4proto_put (const struct nf_conntrack_l4proto *p);/* Protocol pernet registration. */ int nf_ct_l4proto_pernet_register_one(struct net *net,
net/netfilter/nf_conntrack_proto.c +0 -8
@@ -139,20 +139,12 @@ const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u8 l4num)rcu_read_lock (); p =__nf_ct_l4proto_find (l4num); -if (!try_module_get (p->me)) - p = &nf_conntrack_l4proto_generic;rcu_read_unlock ();return p; }EXPORT_SYMBOL_GPL (nf_ct_l4proto_find_get); -void nf_ct_l4proto_put (const struct nf_conntrack_l4proto *p) -{ -module_put (p->me); -} -EXPORT_SYMBOL_GPL (nf_ct_l4proto_put); -static int kill_l4proto (struct nf_conn *i,void *data) {const struct nf_conntrack_l4proto *l4proto;
net/netfilter/nf_conntrack_proto_gre.c +0 -1
@@ -373,7 +373,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre = {#endif .packet = gre_packet, .destroy = gre_destroy, - .me = THIS_MODULE,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
net/netfilter/nfnetlink_cttimeout.c +0 -6
@@ -152,7 +152,6 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl, err:kfree (timeout); err_proto_put: -nf_ct_l4proto_put (l4proto);return ret; }
@@ -302,7 +301,6 @@ static int ctnl_timeout_try_del(struct net *net, struct ctnl_timeout *timeout)if (refcount_dec_if_one (&timeout->refcnt)) {/* We are protected by nfnl mutex. */ list_del_rcu (&timeout->head); -nf_ct_l4proto_put (timeout->timeout.l4proto);nf_ct_untimeout (net, &timeout->timeout);kfree_rcu (timeout, rcu_head); }else {
@@ -372,10 +370,8 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl,if (ret <0 ) goto err; -nf_ct_l4proto_put (l4proto);return 0 ; err: -nf_ct_l4proto_put (l4proto);return ret; }
@@ -511,7 +507,6 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,/* this avoids a loop in nfnetlink. */ return ret == -EAGAIN ? -ENOBUFS : ret; err: -nf_ct_l4proto_put (l4proto);return err; }
@@ -592,7 +587,6 @@ static void __net_exit cttimeout_net_exit(struct net *net)list_for_each_entry_safe (cur, tmp, &net->nfct_timeout_list, head) {list_del_rcu (&cur->head); -nf_ct_l4proto_put (cur->timeout.l4proto);if (refcount_dec_and_test (&cur->refcnt))kfree_rcu (cur, rcu_head);
net/netfilter/nft_ct.c +0 -2
@@ -902,7 +902,6 @@ static int nft_ct_timeout_obj_init(const struct nft_ctx *ctx, err_free_timeout:kfree (timeout); err_proto_put: -nf_ct_l4proto_put (l4proto);return ret; }
@@ -913,7 +912,6 @@ static void nft_ct_timeout_obj_destroy(const struct nft_ctx *ctx,struct nf_ct_timeout *timeout = priv->timeout;nf_ct_untimeout (ctx->net, timeout); -nf_ct_l4proto_put (timeout->l4proto);nf_ct_netns_put (ctx->net, ctx->family);kfree (priv->timeout); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 15/33 netfilter: conntrack: remove remaining l4proto indirect packet calls
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Now that all l4trackers are builtin, no need to use a mix of direct and indirect calls.
This removes the last two users: gre and the generic l4 protocol tracker.
--- include/net/netfilter/nf_conntrack_l4proto.h | 12 ++++------ net/netfilter/nf_conntrack_core.c | 26 +++++++++++++++------ net/netfilter/nf_conntrack_proto_generic.c | 35 ---------------------------- net/netfilter/nf_conntrack_proto_gre.c | 11 ++++----- 4 files changed, 29 insertions(+), 55 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +5 -7
@@ -27,13 +27,6 @@ struct nf_conntrack_l4proto {/* protoinfo nlattr size, closes a hole */ u16 nlattr_size; -/* Returns verdict for packet, or -1 for invalid. */ -int (*packet)(struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state); -/* Called when a conntrack entry is destroyed */ void (*destroy)(struct nf_conn *ct);
@@ -136,6 +129,11 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,unsigned int dataoff, enum ip_conntrack_info ctinfo, const struct nf_hook_state *state); +int nf_conntrack_gre_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state);/* Existing built-in generic protocol */ extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
net/netfilter/nf_conntrack_core.c +19 -7
@@ -1534,6 +1534,18 @@ nf_conntrack_handle_icmp(struct nf_conn *tmpl,return ret; } +static int generic_packet (struct nf_conn *ct,struct sk_buff *skb, +enum ip_conntrack_info ctinfo) +{ +const unsigned int *timeout =nf_ct_timeout_lookup (ct); + +if (!timeout) + timeout = &nf_generic_pernet (nf_ct_net (ct))->timeout; + +nf_ct_refresh_acct (ct, ctinfo, skb, *timeout); +return NF_ACCEPT ; +} +/* Returns verdict for packet, or -1 for invalid. */ static int nf_conntrack_handle_packet(struct nf_conn *ct, struct sk_buff *skb,
@@ -1567,10 +1579,14 @@ static int nf_conntrack_handle_packet(struct nf_conn *ct,return nf_conntrack_dccp_packet (ct, skb, dataoff, ctinfo, state);#endif +#ifdef CONFIG_NF_CT_PROTO_GRE +case IPPROTO_GRE : +return nf_conntrack_gre_packet (ct, skb, dataoff, + ctinfo, state); +#endif } -WARN_ON_ONCE (1 ); -return -NF_ACCEPT ; +return generic_packet (ct, skb, ctinfo); }unsigned int
@@ -1634,11 +1650,7 @@ nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state) goto out; } -if (l4proto->packet) - ret = l4proto->packet (ct, skb, dataoff, ctinfo, state); -else - ret =nf_conntrack_handle_packet (ct, skb, dataoff, ctinfo, state); - + ret =nf_conntrack_handle_packet (ct, skb, dataoff, ctinfo, state);if (ret <=0 ) {/* Invalid: inverse of the return code tells * the netfilter core what to do */
net/netfilter/nf_conntrack_proto_generic.c +0 -35
@@ -15,40 +15,6 @@static const unsigned int nf_ct_generic_timeout =600 *HZ ; -static bool nf_generic_should_process (u8 proto) -{ -switch (proto) { -#ifdef CONFIG_NF_CT_PROTO_GRE_MODULE -case IPPROTO_GRE : -return false; -#endif -default : -return true; - } -} - -/* Returns verdict for packet, or -1 for invalid. */ -static int generic_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) -{ -const unsigned int *timeout =nf_ct_timeout_lookup (ct); - -if (!nf_generic_should_process (nf_ct_protonum (ct))) { -pr_warn_once ("conntrack: generic helper won't handle protocol %d. Please consider loading the specific helper module.\n" , -nf_ct_protonum (ct)); -return -NF_ACCEPT ; - } - -if (!timeout) - timeout = &nf_generic_pernet (nf_ct_net (ct))->timeout; - -nf_ct_refresh_acct (ct, ctinfo, skb, *timeout); -return NF_ACCEPT ; -} -#ifdef CONFIG_NF_CONNTRACK_TIMEOUT #include <linux/netfilter/nfnetlink.h>
@@ -139,7 +105,6 @@ static struct nf_proto_net *generic_get_net_proto(struct net *net)const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic = { .l4proto =255 , - .packet = generic_packet, #ifdef CONFIG_NF_CONNTRACK_TIMEOUT .ctnl_timeout = { .nlattr_to_obj = generic_timeout_nlattr_to_obj,
net/netfilter/nf_conntrack_proto_gre.c +5 -6
@@ -213,11 +213,11 @@ static unsigned int *gre_get_timeouts(struct net *net) }/* Returns verdict for packet, and may modify conntrack */ -static int gre_packet (struct nf_conn *ct, -struct sk_buff *skb, -unsigned int dataoff, -enum ip_conntrack_info ctinfo, -const struct nf_hook_state *state) +int nf_conntrack_gre_packet (struct nf_conn *ct, +struct sk_buff *skb, +unsigned int dataoff, +enum ip_conntrack_info ctinfo, +const struct nf_hook_state *state) {if (state->pf !=NFPROTO_IPV4 )return -NF_ACCEPT ;
@@ -371,7 +371,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre = {#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = gre_print_conntrack, #endif - .packet = gre_packet, .destroy = gre_destroy,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 16/33 netfilter: conntrack: remove pernet l4 proto register interface
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
No used anymore.
--- include/net/netfilter/nf_conntrack_l4proto.h | 12 ------------ net/netfilter/nf_conntrack_proto.c | 28 ++++++++++++---------------- 2 files changed, 12 insertions(+), 28 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +0 -12
@@ -144,18 +144,6 @@ const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u8 l4proto);const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get (u8 l4proto); -/* Protocol pernet registration. */ -int nf_ct_l4proto_pernet_register_one (struct net *net, -const struct nf_conntrack_l4proto *proto); -void nf_ct_l4proto_pernet_unregister_one (struct net *net, -const struct nf_conntrack_l4proto *proto); -int nf_ct_l4proto_pernet_register (struct net *net, -const struct nf_conntrack_l4proto *const proto[], -unsigned int num_proto); -void nf_ct_l4proto_pernet_unregister (struct net *net, -const struct nf_conntrack_l4proto *const proto[], -unsigned int num_proto); -/* Protocol global registration. */ int nf_ct_l4proto_register_one (const struct nf_conntrack_l4proto *proto);void nf_ct_l4proto_unregister_one (const struct nf_conntrack_l4proto *proto);
net/netfilter/nf_conntrack_proto.c +12 -16
@@ -221,8 +221,8 @@ int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *l4proto) }EXPORT_SYMBOL_GPL (nf_ct_l4proto_register_one); -int nf_ct_l4proto_pernet_register_one (struct net *net, -const struct nf_conntrack_l4proto *l4proto) +static int nf_ct_l4proto_pernet_register_one (struct net *net, +const struct nf_conntrack_l4proto *l4proto) {int ret =0 ;struct nf_proto_net *pn =NULL ;
@@ -245,7 +245,6 @@ int nf_ct_l4proto_pernet_register_one(struct net *net, out:return ret; } -EXPORT_SYMBOL_GPL (nf_ct_l4proto_pernet_register_one);static void __nf_ct_l4proto_unregister_one (const struct nf_conntrack_l4proto *l4proto)
@@ -272,7 +271,7 @@ void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto) }EXPORT_SYMBOL_GPL (nf_ct_l4proto_unregister_one); -void nf_ct_l4proto_pernet_unregister_one (struct net *net, +static void nf_ct_l4proto_pernet_unregister_one (struct net *net,const struct nf_conntrack_l4proto *l4proto) {struct nf_proto_net *pn =nf_ct_l4proto_net (net, l4proto);
@@ -283,7 +282,6 @@ void nf_ct_l4proto_pernet_unregister_one(struct net *net, pn->users--;nf_ct_l4proto_unregister_sysctl (pn); } -EXPORT_SYMBOL_GPL (nf_ct_l4proto_pernet_unregister_one); static void nf_ct_l4proto_unregister(const struct nf_conntrack_l4proto * const l4proto[],
@@ -322,7 +320,15 @@ nf_ct_l4proto_register(const struct nf_conntrack_l4proto * const l4proto[],return ret; } -int nf_ct_l4proto_pernet_register (struct net *net, +static void nf_ct_l4proto_pernet_unregister (struct net *net, +const struct nf_conntrack_l4proto *const l4proto[], +unsigned int num_proto) +{ +while (num_proto-- !=0 ) +nf_ct_l4proto_pernet_unregister_one (net, l4proto[num_proto]); +} + +static int nf_ct_l4proto_pernet_register (struct net *net,const struct nf_conntrack_l4proto *const l4proto[],unsigned int num_proto) {
@@ -341,16 +347,6 @@ int nf_ct_l4proto_pernet_register(struct net *net, }return ret; } -EXPORT_SYMBOL_GPL (nf_ct_l4proto_pernet_register); - -void nf_ct_l4proto_pernet_unregister (struct net *net, -const struct nf_conntrack_l4proto *const l4proto[], -unsigned int num_proto) -{ -while (num_proto-- !=0 ) -nf_ct_l4proto_pernet_unregister_one (net, l4proto[num_proto]); -} -EXPORT_SYMBOL_GPL (nf_ct_l4proto_pernet_unregister); static unsigned int nf_confirm(struct sk_buff *skb, unsigned int protoff,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 17/33 netfilter: conntrack: avoid unneeded nf_conntrack_l4proto lookups
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
after removal of the packet and invert function pointers, several places do not need to lookup the l4proto structure anymore.
Remove those lookups.
The function nf_ct_invert_tuplepr becomes redundant, replace it with nf_ct_invert_tuple everywhere.
--- include/net/netfilter/nf_conntrack.h | 2 -- include/net/netfilter/nf_conntrack_core.h | 3 +- net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 2 +- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 2 +- net/netfilter/nf_conntrack_core.c | 53 ++++++------------------------- net/netfilter/nf_conntrack_pptp.c | 2 +- net/netfilter/nf_conntrack_proto_icmp.c | 6 +--- net/netfilter/nf_conntrack_proto_icmpv6.c | 6 +--- net/netfilter/nf_nat_core.c | 12 +++---- net/openvswitch/conntrack.c | 2 +- 10 files changed, 22 insertions(+), 68 deletions(-)
include/net/netfilter/nf_conntrack.h +0 -2
@@ -187,8 +187,6 @@ bool nf_ct_delete(struct nf_conn *ct, u32 pid, int report);bool nf_ct_get_tuplepr (const struct sk_buff *skb,unsigned int nhoff,u_int16_t l3num,struct net *net,struct nf_conntrack_tuple *tuple); -bool nf_ct_invert_tuplepr (struct nf_conntrack_tuple *inverse, -const struct nf_conntrack_tuple *orig); void __nf_ct_refresh_acct(struct nf_conn *ct, enum ip_conntrack_info ctinfo, const struct sk_buff *skb,
include/net/netfilter/nf_conntrack_core.h +1 -2
@@ -39,8 +39,7 @@ void nf_conntrack_init_end(void);void nf_conntrack_cleanup_end (void );bool nf_ct_invert_tuple (struct nf_conntrack_tuple *inverse, -const struct nf_conntrack_tuple *orig, -const struct nf_conntrack_l4proto *l4proto); +const struct nf_conntrack_tuple *orig);/* Find a connection corresponding to a tuple. */ struct nf_conntrack_tuple_hash *
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +1 -1
@@ -214,7 +214,7 @@ int nf_nat_icmp_reply_translation(struct sk_buff *skb, }/* Change outer to look like the reply to an incoming packet */ -nf_ct_invert_tuplepr (&target, &ct->tuplehash[!dir].tuple); +nf_ct_invert_tuple (&target, &ct->tuplehash[!dir].tuple);if (!nf_nat_ipv4_manip_pkt (skb,0 , &target, manip))return 0 ;
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +1 -1
@@ -225,7 +225,7 @@ int nf_nat_icmpv6_reply_translation(struct sk_buff *skb, skb->len - hdrlen, 0)); } -nf_ct_invert_tuplepr (&target, &ct->tuplehash[!dir].tuple); +nf_ct_invert_tuple (&target, &ct->tuplehash[!dir].tuple);if (!nf_nat_ipv6_manip_pkt (skb,0 , &target, manip))return 0 ;
net/netfilter/nf_conntrack_core.c +9 -44
143 lines not on this page · raw message
net/netfilter/nf_conntrack_pptp.c +1 -1
@@ -121,7 +121,7 @@ static void pptp_expectfn(struct nf_conn *ct,struct nf_conntrack_expect *exp_other;/* obviously this tuple inversion only works until you do NAT */ -nf_ct_invert_tuplepr (&inv_t, &exp->tuple); +nf_ct_invert_tuple (&inv_t, &exp->tuple);pr_debug ("trying to unexpect other dir: " );nf_ct_dump_tuple (&inv_t);
net/netfilter/nf_conntrack_proto_icmp.c +1 -5
@@ -109,7 +109,6 @@ icmp_error_message(struct nf_conn *tmpl, struct sk_buff *skb, const struct nf_hook_state *state) {struct nf_conntrack_tuple innertuple, origtuple; -const struct nf_conntrack_l4proto *innerproto;const struct nf_conntrack_tuple_hash *h;const struct nf_conntrack_zone *zone;enum ip_conntrack_info ctinfo;
@@ -127,12 +126,9 @@ icmp_error_message(struct nf_conn *tmpl, struct sk_buff *skb,return -NF_ACCEPT ; } -/* rcu_read_lock()ed by nf_hook_thresh */ - innerproto =__nf_ct_l4proto_find (origtuple.dst.protonum); -/* Ordinarily, we'd expect the inverted tupleproto, but it's been preserved inside the ICMP. */ -if (!nf_ct_invert_tuple (&innertuple, &origtuple, innerproto)) { +if (!nf_ct_invert_tuple (&innertuple, &origtuple)) {pr_debug ("icmp_error_message: no match\n" );return -NF_ACCEPT ; }
net/netfilter/nf_conntrack_proto_icmpv6.c +1 -5
@@ -130,7 +130,6 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl, {struct nf_conntrack_tuple intuple, origtuple;const struct nf_conntrack_tuple_hash *h; -const struct nf_conntrack_l4proto *inproto;enum ip_conntrack_info ctinfo;struct nf_conntrack_zone tmp;
@@ -146,12 +145,9 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl,return -NF_ACCEPT ; } -/* rcu_read_lock()ed by nf_hook_thresh */ - inproto =__nf_ct_l4proto_find (origtuple.dst.protonum); -/* Ordinarily, we'd expect the inverted tupleproto, but it's been preserved inside the ICMP. */ -if (!nf_ct_invert_tuple (&intuple, &origtuple, inproto)) { +if (!nf_ct_invert_tuple (&intuple, &origtuple)) {pr_debug ("icmpv6_error: Can't invert tuple\n" );return -NF_ACCEPT ; }
net/netfilter/nf_nat_core.c +6 -6
@@ -158,7 +158,7 @@ nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,*/ struct nf_conntrack_tuple reply; -nf_ct_invert_tuplepr (&reply, tuple); +nf_ct_invert_tuple (&reply, tuple);return nf_conntrack_tuple_taken (&reply, ignored_conntrack); }EXPORT_SYMBOL (nf_nat_used_tuple);
@@ -253,7 +253,7 @@ find_appropriate_src(struct net *net, net_eq(net, nf_ct_net(ct)) && nf_ct_zone_equal(ct, zone, IP_CT_DIR_ORIGINAL)) {/* Copy source part from reply tuple. */ -nf_ct_invert_tuplepr (result, +nf_ct_invert_tuple (result, &ct->tuplehash[IP_CT_DIR_REPLY ].tuple); result->dst = tuple->dst;
@@ -560,8 +560,8 @@ nf_nat_setup_info(struct nf_conn *ct,* manipulations (future optimization: if num_manips == 0, * orig_tp = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple) */ -nf_ct_invert_tuplepr (&curr_tuple, - &ct->tuplehash[IP_CT_DIR_REPLY ].tuple); +nf_ct_invert_tuple (&curr_tuple, + &ct->tuplehash[IP_CT_DIR_REPLY ].tuple);get_unique_tuple (&new_tuple, &curr_tuple, range, ct, maniptype);
@@ -569,7 +569,7 @@ nf_nat_setup_info(struct nf_conn *ct,struct nf_conntrack_tuple reply;/* Alter conntrack table so will recognize replies. */ -nf_ct_invert_tuplepr (&reply, &new_tuple); +nf_ct_invert_tuple (&reply, &new_tuple);nf_conntrack_alter_reply (ct, &reply);/* Non-atomic: we own this at the moment. */
@@ -640,7 +640,7 @@ static unsigned int nf_nat_manip_pkt(struct sk_buff *skb, struct nf_conn *ct,struct nf_conntrack_tuple target;/* We are aiming to look like inverse of other direction. */ -nf_ct_invert_tuplepr (&target, &ct->tuplehash[!dir].tuple); +nf_ct_invert_tuple (&target, &ct->tuplehash[!dir].tuple); l3proto =__nf_nat_l3proto_find (target.src.l3num);if (!l3proto->manip_pkt (skb,0 , &target, mtype))
net/openvswitch/conntrack.c +1 -1
@@ -622,7 +622,7 @@ ovs_ct_find_existing(struct net *net, const struct nf_conntrack_zone *zone,if (natted) {struct nf_conntrack_tuple inverse; -if (!nf_ct_invert_tuplepr (&inverse, &tuple)) { +if (!nf_ct_invert_tuple (&inverse, &tuple)) {pr_debug ("ovs_ct_find_existing: Inversion failed!\n" );return NULL ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 18/33 netfilter: conntrack: unify sysctl handling
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Due to historical reasons, all l4 trackers register their own sysctls.
This leads to copy&pasted boilerplate code, that does exactly same thing, just with different data structure.
Place all of this in a single file.
This allows to remove the various ctl_table pointers from the ct_netns structure and reduces overall code size.
--- net/netfilter/nf_conntrack_proto_dccp.c | 86 +------ net/netfilter/nf_conntrack_proto_generic.c | 30 +-- net/netfilter/nf_conntrack_proto_gre.c | 42 +-- net/netfilter/nf_conntrack_proto_icmp.c | 29 +-- net/netfilter/nf_conntrack_proto_icmpv6.c | 29 +-- net/netfilter/nf_conntrack_proto_sctp.c | 89 +------ net/netfilter/nf_conntrack_proto_tcp.c | 116 +-------- net/netfilter/nf_conntrack_proto_udp.c | 36 +-- net/netfilter/nf_conntrack_standalone.c | 394 ++++++++++++++++++++++++++++- 9 files changed, 391 insertions(+), 460 deletions(-)
net/netfilter/nf_conntrack_proto_dccp.c +1 -85
@@ -724,90 +724,6 @@ dccp_timeout_nla_policy[CTA_TIMEOUT_DCCP_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -#ifdef CONFIG_SYSCTL -/* template, data assigned later */ -static struct ctl_table dccp_sysctl_table[] = { - { - .procname ="nf_conntrack_dccp_timeout_request" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_dccp_timeout_respond" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_dccp_timeout_partopen" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_dccp_timeout_open" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_dccp_timeout_closereq" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_dccp_timeout_closing" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_dccp_timeout_timewait" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_dccp_loose" , - .maxlen =sizeof (int ), - .mode =0644 , - .proc_handler = proc_dointvec, - }, - { } -}; -#endif /* CONFIG_SYSCTL */ - -static int dccp_kmemdup_sysctl_table (struct net *net,struct nf_proto_net *pn, -struct nf_dccp_net *dn) -{ -#ifdef CONFIG_SYSCTL -if (pn->ctl_table) -return 0 ; - - pn->ctl_table =kmemdup (dccp_sysctl_table, -sizeof (dccp_sysctl_table), -GFP_KERNEL ); -if (!pn->ctl_table) -return -ENOMEM ; - - pn->ctl_table[0 ].data = &dn->dccp_timeout[CT_DCCP_REQUEST ]; - pn->ctl_table[1 ].data = &dn->dccp_timeout[CT_DCCP_RESPOND ]; - pn->ctl_table[2 ].data = &dn->dccp_timeout[CT_DCCP_PARTOPEN ]; - pn->ctl_table[3 ].data = &dn->dccp_timeout[CT_DCCP_OPEN ]; - pn->ctl_table[4 ].data = &dn->dccp_timeout[CT_DCCP_CLOSEREQ ]; - pn->ctl_table[5 ].data = &dn->dccp_timeout[CT_DCCP_CLOSING ]; - pn->ctl_table[6 ].data = &dn->dccp_timeout[CT_DCCP_TIMEWAIT ]; - pn->ctl_table[7 ].data = &dn->dccp_loose; - -/* Don't export sysctls to unprivileged users */ -if (net->user_ns != &init_user_ns) - pn->ctl_table[0 ].procname =NULL ; -#endif -return 0 ; -} -static int dccp_init_net (struct net *net) {struct nf_dccp_net *dn =nf_dccp_pernet (net);
@@ -830,7 +746,7 @@ static int dccp_init_net(struct net *net) dn->dccp_timeout[CT_DCCP_NONE ] = dn->dccp_timeout[CT_DCCP_REQUEST ]; } -return dccp_kmemdup_sysctl_table (net, pn, dn); +return 0 ; }static struct nf_proto_net *dccp_get_net_proto (struct net *net)
net/netfilter/nf_conntrack_proto_generic.c +1 -29
@@ -60,41 +60,13 @@ generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -#ifdef CONFIG_SYSCTL -static struct ctl_table generic_sysctl_table[] = { - { - .procname ="nf_conntrack_generic_timeout" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { } -}; -#endif /* CONFIG_SYSCTL */ - -static int generic_kmemdup_sysctl_table (struct nf_proto_net *pn, -struct nf_generic_net *gn) -{ -#ifdef CONFIG_SYSCTL - pn->ctl_table =kmemdup (generic_sysctl_table, -sizeof (generic_sysctl_table), -GFP_KERNEL ); -if (!pn->ctl_table) -return -ENOMEM ; - - pn->ctl_table[0 ].data = &gn->timeout; -#endif -return 0 ; -} -static int generic_init_net (struct net *net) {struct nf_generic_net *gn =nf_generic_pernet (net); -struct nf_proto_net *pn = &gn->pn; gn->timeout = nf_ct_generic_timeout; -return generic_kmemdup_sysctl_table (pn, gn); +return 0 ; }static struct nf_proto_net *generic_get_net_proto (struct net *net)
net/netfilter/nf_conntrack_proto_gre.c +1 -41
54 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_icmp.c +1 -28
@@ -298,41 +298,14 @@ icmp_timeout_nla_policy[CTA_TIMEOUT_ICMP_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -#ifdef CONFIG_SYSCTL -static struct ctl_table icmp_sysctl_table[] = { - { - .procname ="nf_conntrack_icmp_timeout" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { } -}; -#endif /* CONFIG_SYSCTL */ - -static int icmp_kmemdup_sysctl_table (struct nf_proto_net *pn, -struct nf_icmp_net *in) -{ -#ifdef CONFIG_SYSCTL - pn->ctl_table =kmemdup (icmp_sysctl_table, -sizeof (icmp_sysctl_table), -GFP_KERNEL ); -if (!pn->ctl_table) -return -ENOMEM ; - - pn->ctl_table[0 ].data = &in->timeout; -#endif -return 0 ; -}static int icmp_init_net (struct net *net) {struct nf_icmp_net *in =nf_icmp_pernet (net); -struct nf_proto_net *pn = &in->pn; in->timeout = nf_ct_icmp_timeout; -return icmp_kmemdup_sysctl_table (pn, in); +return 0 ; }static struct nf_proto_net *icmp_get_net_proto (struct net *net)
net/netfilter/nf_conntrack_proto_icmpv6.c +1 -28
@@ -309,41 +309,14 @@ icmpv6_timeout_nla_policy[CTA_TIMEOUT_ICMPV6_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -#ifdef CONFIG_SYSCTL -static struct ctl_table icmpv6_sysctl_table[] = { - { - .procname ="nf_conntrack_icmpv6_timeout" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { } -}; -#endif /* CONFIG_SYSCTL */ - -static int icmpv6_kmemdup_sysctl_table (struct nf_proto_net *pn, -struct nf_icmp_net *in) -{ -#ifdef CONFIG_SYSCTL - pn->ctl_table =kmemdup (icmpv6_sysctl_table, -sizeof (icmpv6_sysctl_table), -GFP_KERNEL ); -if (!pn->ctl_table) -return -ENOMEM ; - - pn->ctl_table[0 ].data = &in->timeout; -#endif -return 0 ; -}static int icmpv6_init_net (struct net *net) {struct nf_icmp_net *in =nf_icmpv6_pernet (net); -struct nf_proto_net *pn = &in->pn; in->timeout = nf_ct_icmpv6_timeout; -return icmpv6_kmemdup_sysctl_table (pn, in); +return 0 ; }static struct nf_proto_net *icmpv6_get_net_proto (struct net *net)
net/netfilter/nf_conntrack_proto_sctp.c +1 -88
101 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_tcp.c +1 -115
128 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_udp.c +1 -35
@@ -260,40 +260,6 @@ udp_timeout_nla_policy[CTA_TIMEOUT_UDP_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -#ifdef CONFIG_SYSCTL -static struct ctl_table udp_sysctl_table[] = { - { - .procname ="nf_conntrack_udp_timeout" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname ="nf_conntrack_udp_timeout_stream" , - .maxlen =sizeof (unsigned int ), - .mode =0644 , - .proc_handler = proc_dointvec_jiffies, - }, - { } -}; -#endif /* CONFIG_SYSCTL */ - -static int udp_kmemdup_sysctl_table (struct nf_proto_net *pn, -struct nf_udp_net *un) -{ -#ifdef CONFIG_SYSCTL -if (pn->ctl_table) -return 0 ; - pn->ctl_table =kmemdup (udp_sysctl_table, -sizeof (udp_sysctl_table), -GFP_KERNEL ); -if (!pn->ctl_table) -return -ENOMEM ; - pn->ctl_table[0 ].data = &un->timeouts[UDP_CT_UNREPLIED ]; - pn->ctl_table[1 ].data = &un->timeouts[UDP_CT_REPLIED ]; -#endif -return 0 ; -}static int udp_init_net (struct net *net) {
@@ -307,7 +273,7 @@ static int udp_init_net(struct net *net) un->timeouts[i] = udp_timeouts[i]; } -return udp_kmemdup_sysctl_table (pn, un); +return 0 ; }static struct nf_proto_net *udp_get_net_proto (struct net *net)
net/netfilter/nf_conntrack_standalone.c +383 -11
452 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 19/33 netfilter: conntrack: remove sysctl registration helpers
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
After previous patch these are not used anymore.
--- include/net/netns/conntrack.h | 4 -- net/netfilter/nf_conntrack_proto.c | 77 +------------------------------------- 2 files changed, 1 insertion(+), 80 deletions(-)
include/net/netns/conntrack.h +0 -4
@@ -19,10 +19,6 @@ struct ctl_table_header;struct nf_conntrack_ecache ;struct nf_proto_net { -#ifdef CONFIG_SYSCTL -struct ctl_table_header *ctl_table_header; -struct ctl_table *ctl_table; -#endif unsigned int users; };
net/netfilter/nf_conntrack_proto.c +1 -76
117 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 20/33 netfilter: conntrack: remove l4proto init and get_net callbacks
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Those were needed we still had modular trackers.
As we don't have those anymore, prefer direct calls and remove all the (un)register infrastructure associated with this.
--- include/net/netfilter/nf_conntrack_l4proto.h | 15 ++-- include/net/netns/conntrack.h | 11 --- net/netfilter/nf_conntrack_proto.c | 103 ++++----------------------- net/netfilter/nf_conntrack_proto_dccp.c | 42 ++++------- net/netfilter/nf_conntrack_proto_generic.c | 11 +-- net/netfilter/nf_conntrack_proto_gre.c | 5 +- net/netfilter/nf_conntrack_proto_icmp.c | 12 +--- net/netfilter/nf_conntrack_proto_icmpv6.c | 12 +--- net/netfilter/nf_conntrack_proto_sctp.c | 29 +++----- net/netfilter/nf_conntrack_proto_tcp.c | 35 +++------ net/netfilter/nf_conntrack_proto_udp.c | 24 ++----- 11 files changed, 65 insertions(+), 234 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +9 -6
@@ -61,12 +61,6 @@ struct nf_conntrack_l4proto {/* Print out the private part of the conntrack. */ void (*print_conntrack)(struct seq_file *s,struct nf_conn *);#endif - -/* Init l4proto pernet data */ -int (*init_net)(struct net *net); - -/* Return the per-net protocol part. */ -struct nf_proto_net *(*get_net_proto)(struct net *net); }; bool icmp_pkt_to_tuple(const struct sk_buff *skb,
@@ -135,6 +129,15 @@ int nf_conntrack_gre_packet(struct nf_conn *ct,enum ip_conntrack_info ctinfo, const struct nf_hook_state *state); +void nf_conntrack_generic_init_net (struct net *net); +void nf_conntrack_tcp_init_net (struct net *net); +void nf_conntrack_udp_init_net (struct net *net); +void nf_conntrack_gre_init_net (struct net *net); +void nf_conntrack_dccp_init_net (struct net *net); +void nf_conntrack_sctp_init_net (struct net *net); +void nf_conntrack_icmp_init_net (struct net *net); +void nf_conntrack_icmpv6_init_net (struct net *net); +/* Existing built-in generic protocol */ extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
include/net/netns/conntrack.h +0 -11
@@ -18,17 +18,11 @@struct ctl_table_header ;struct nf_conntrack_ecache ; -struct nf_proto_net { -unsigned int users; -}; -struct nf_generic_net { -struct nf_proto_net pn;unsigned int timeout; };struct nf_tcp_net { -struct nf_proto_net pn;unsigned int timeouts[TCP_CONNTRACK_TIMEOUT_MAX ];unsigned int tcp_loose;unsigned int tcp_be_liberal;
@@ -42,18 +36,15 @@ enum udp_conntrack { };struct nf_udp_net { -struct nf_proto_net pn;unsigned int timeouts[UDP_CT_MAX ]; };struct nf_icmp_net { -struct nf_proto_net pn;unsigned int timeout; };#ifdef CONFIG_NF_CT_PROTO_DCCP struct nf_dccp_net { -struct nf_proto_net pn;int dccp_loose;unsigned int dccp_timeout[CT_DCCP_MAX +1 ]; };
@@ -61,7 +52,6 @@ struct nf_dccp_net {#ifdef CONFIG_NF_CT_PROTO_SCTP struct nf_sctp_net { -struct nf_proto_net pn;unsigned int timeouts[SCTP_CONNTRACK_MAX ]; };#endif
@@ -74,7 +64,6 @@ enum gre_conntrack { };struct nf_gre_net { -struct nf_proto_net nf;struct list_head keymap_list;unsigned int timeouts[GRE_CT_MAX ]; };
net/netfilter/nf_conntrack_proto.c +14 -89
138 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_dccp.c +15 -27
55 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_generic.c +1 -10
@@ -60,18 +60,11 @@ generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -static int generic_init_net (struct net *net) +void nf_conntrack_generic_init_net (struct net *net) {struct nf_generic_net *gn =nf_generic_pernet (net); gn->timeout = nf_ct_generic_timeout; - -return 0 ; -} - -static struct nf_proto_net *generic_get_net_proto (struct net *net) -{ -return &net->ct.nf_ct_proto.generic.pn; } const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic =
@@ -86,6 +79,4 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic = .nla_policy = generic_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = generic_init_net, - .get_net_proto = generic_get_net_proto, };
net/netfilter/nf_conntrack_proto_gre.c +1 -4
@@ -313,7 +313,7 @@ gre_timeout_nla_policy[CTA_TIMEOUT_GRE_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -static int gre_init_net (struct net *net) +void nf_conntrack_gre_init_net (struct net *net) {struct nf_gre_net *net_gre =gre_pernet (net);int i;
@@ -321,8 +321,6 @@ static int gre_init_net(struct net *net)INIT_LIST_HEAD (&net_gre->keymap_list);for (i =0 ; i <GRE_CT_MAX ; i++) net_gre->timeouts[i] = gre_timeouts[i]; - -return 0 ; }/* protocol helper struct */
@@ -347,5 +345,4 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre = { .nla_policy = gre_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = gre_init_net, };
net/netfilter/nf_conntrack_proto_icmp.c +1 -11
@@ -298,19 +298,11 @@ icmp_timeout_nla_policy[CTA_TIMEOUT_ICMP_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - -static int icmp_init_net (struct net *net) +void nf_conntrack_icmp_init_net (struct net *net) {struct nf_icmp_net *in =nf_icmp_pernet (net); in->timeout = nf_ct_icmp_timeout; - -return 0 ; -} - -static struct nf_proto_net *icmp_get_net_proto (struct net *net) -{ -return &net->ct.nf_ct_proto.icmp.pn; } const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp =
@@ -331,6 +323,4 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp = .nla_policy = icmp_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = icmp_init_net, - .get_net_proto = icmp_get_net_proto, };
net/netfilter/nf_conntrack_proto_icmpv6.c +1 -11
@@ -309,19 +309,11 @@ icmpv6_timeout_nla_policy[CTA_TIMEOUT_ICMPV6_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - -static int icmpv6_init_net (struct net *net) +void nf_conntrack_icmpv6_init_net (struct net *net) {struct nf_icmp_net *in =nf_icmpv6_pernet (net); in->timeout = nf_ct_icmpv6_timeout; - -return 0 ; -} - -static struct nf_proto_net *icmpv6_get_net_proto (struct net *net) -{ -return &net->ct.nf_ct_proto.icmpv6.pn; } const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
@@ -342,6 +334,4 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 = .nla_policy = icmpv6_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = icmpv6_init_net, - .get_net_proto = icmpv6_get_net_proto, };
net/netfilter/nf_conntrack_proto_sctp.c +8 -21
@@ -642,29 +642,18 @@ sctp_timeout_nla_policy[CTA_TIMEOUT_SCTP_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -static int sctp_init_net (struct net *net) +void nf_conntrack_sctp_init_net (struct net *net) {struct nf_sctp_net *sn =nf_sctp_pernet (net); -struct nf_proto_net *pn = &sn->pn; - -if (!pn->users) { -int i; - -for (i =0 ; i <SCTP_CONNTRACK_MAX ; i++) - sn->timeouts[i] = sctp_timeouts[i]; - -/* timeouts[0] is unused, init it so ->timeouts[0] contains -* 'new' timeout, like udp or icmp. -*/ - sn->timeouts[0 ] = sctp_timeouts[SCTP_CONNTRACK_CLOSED ]; - } +int i; -return 0 ; -} +for (i =0 ; i <SCTP_CONNTRACK_MAX ; i++) + sn->timeouts[i] = sctp_timeouts[i]; -static struct nf_proto_net *sctp_get_net_proto (struct net *net) -{ -return &net->ct.nf_ct_proto.sctp.pn; +/* timeouts[0] is unused, init it so ->timeouts[0] contains +* 'new' timeout, like udp or icmp. +*/ + sn->timeouts[0 ] = sctp_timeouts[SCTP_CONNTRACK_CLOSED ]; }const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp = {
@@ -691,6 +680,4 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp = { .nla_policy = sctp_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = sctp_init_net, - .get_net_proto = sctp_get_net_proto, };
net/netfilter/nf_conntrack_proto_tcp.c +11 -24
@@ -1387,32 +1387,21 @@ static const struct nla_policy tcp_timeout_nla_policy[CTA_TIMEOUT_TCP_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ -static int tcp_init_net (struct net *net) +void nf_conntrack_tcp_init_net (struct net *net) {struct nf_tcp_net *tn =nf_tcp_pernet (net); -struct nf_proto_net *pn = &tn->pn; - -if (!pn->users) { -int i; - -for (i =0 ; i <TCP_CONNTRACK_TIMEOUT_MAX ; i++) - tn->timeouts[i] = tcp_timeouts[i]; - -/* timeouts[0] is unused, make it same as SYN_SENT so -* ->timeouts[0] contains 'new' timeout, like udp or icmp. -*/ - tn->timeouts[0 ] = tcp_timeouts[TCP_CONNTRACK_SYN_SENT ]; - tn->tcp_loose = nf_ct_tcp_loose; - tn->tcp_be_liberal = nf_ct_tcp_be_liberal; - tn->tcp_max_retrans = nf_ct_tcp_max_retrans; - } +int i; -return 0 ; -} +for (i =0 ; i <TCP_CONNTRACK_TIMEOUT_MAX ; i++) + tn->timeouts[i] = tcp_timeouts[i]; -static struct nf_proto_net *tcp_get_net_proto (struct net *net) -{ -return &net->ct.nf_ct_proto.tcp.pn; +/* timeouts[0] is unused, make it same as SYN_SENT so +* ->timeouts[0] contains 'new' timeout, like udp or icmp. +*/ + tn->timeouts[0 ] = tcp_timeouts[TCP_CONNTRACK_SYN_SENT ]; + tn->tcp_loose = nf_ct_tcp_loose; + tn->tcp_be_liberal = nf_ct_tcp_be_liberal; + tn->tcp_max_retrans = nf_ct_tcp_max_retrans; } const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp =
@@ -1441,6 +1430,4 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp = .nla_policy = tcp_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = tcp_init_net, - .get_net_proto = tcp_get_net_proto, };
net/netfilter/nf_conntrack_proto_udp.c +4 -20
@@ -260,25 +260,13 @@ udp_timeout_nla_policy[CTA_TIMEOUT_UDP_MAX+1] = { };#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - -static int udp_init_net (struct net *net) +void nf_conntrack_udp_init_net (struct net *net) {struct nf_udp_net *un =nf_udp_pernet (net); -struct nf_proto_net *pn = &un->pn; - -if (!pn->users) { -int i; - -for (i =0 ; i <UDP_CT_MAX ; i++) - un->timeouts[i] = udp_timeouts[i]; - } +int i; -return 0 ; -} - -static struct nf_proto_net *udp_get_net_proto (struct net *net) -{ -return &net->ct.nf_ct_proto.udp.pn; +for (i =0 ; i <UDP_CT_MAX ; i++) + un->timeouts[i] = udp_timeouts[i]; } const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp =
@@ -300,8 +288,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp = .nla_policy = udp_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = udp_init_net, - .get_net_proto = udp_get_net_proto, };#ifdef CONFIG_NF_CT_PROTO_UDPLITE
@@ -324,7 +310,5 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite = .nla_policy = udp_timeout_nla_policy, },#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ - .init_net = udp_init_net, - .get_net_proto = udp_get_net_proto, };#endif
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 21/33 netfilter: conntrack: remove l4proto destroy hook
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Only one user (gre), add a direct call and remove this facility.
--- include/net/netfilter/nf_conntrack_l4proto.h | 3 --- net/netfilter/nf_conntrack_core.c | 15 +++++++++++---- net/netfilter/nf_conntrack_proto_gre.c | 14 -------------- 3 files changed, 11 insertions(+), 21 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +0 -3
@@ -27,9 +27,6 @@ struct nf_conntrack_l4proto {/* protoinfo nlattr size, closes a hole */ u16 nlattr_size; -/* Called when a conntrack entry is destroyed */ -void (*destroy)(struct nf_conn *ct); -/* called by gc worker if table is full */ bool (*can_early_drop)(const struct nf_conn *ct);
net/netfilter/nf_conntrack_core.c +11 -4
@@ -524,11 +524,18 @@ void nf_ct_tmpl_free(struct nf_conn *tmpl) }EXPORT_SYMBOL_GPL (nf_ct_tmpl_free); +static void destroy_gre_conntrack (struct nf_conn *ct) +{ +struct nf_conn *master = ct->master; + +if (master) +nf_ct_gre_keymap_destroy (master); +} +static void destroy_conntrack (struct nf_conntrack *nfct) {struct nf_conn *ct = (struct nf_conn *)nfct; -const struct nf_conntrack_l4proto *l4proto;pr_debug ("destroy_conntrack(%p)\n" , ct);WARN_ON (atomic_read (&nfct->use) !=0 );
@@ -537,9 +544,9 @@ destroy_conntrack(struct nf_conntrack *nfct)nf_ct_tmpl_free (ct);return ; } - l4proto =__nf_ct_l4proto_find (nf_ct_protonum (ct)); -if (l4proto->destroy) - l4proto->destroy (ct); + +if (unlikely (nf_ct_protonum (ct) ==IPPROTO_GRE )) +destroy_gre_conntrack (ct);local_bh_disable ();/* Expectations will have been removed in clean_from_lists,
net/netfilter/nf_conntrack_proto_gre.c +0 -14
@@ -249,19 +249,6 @@ int nf_conntrack_gre_packet(struct nf_conn *ct,return NF_ACCEPT ; } -/* Called when a conntrack entry has already been removed from the hashes -* and is about to be deleted from memory */ -static void gre_destroy (struct nf_conn *ct) -{ -struct nf_conn *master = ct->master; -pr_debug (" entering\n" ); - -if (!master) -pr_debug ("no master !?!\n" ); -else -nf_ct_gre_keymap_destroy (master); -} -#ifdef CONFIG_NF_CONNTRACK_TIMEOUT #include <linux/netfilter/nfnetlink.h>
@@ -329,7 +316,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre = {#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = gre_print_conntrack,#endif - .destroy = gre_destroy,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 22/33 netfilter: conntrack: remove nf_ct_l4proto_find_get
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Its now same as __nf_ct_l4proto_find(), so rename that to nf_ct_l4proto_find and use it everywhere.
It never returns NULL and doesn't need locks or reference counts.
Before this series:
302824 net/netfilter/nf_conntrack.ko
21504 net/netfilter/nf_conntrack_proto_gre.ko
text data bss dec hex filename
6281 1732 4 8017 1f51 nf_conntrack_proto_gre.ko
108356 20613 236 129205 1f8b5 nf_conntrack.ko
After:
294864 net/netfilter/nf_conntrack.ko
text data bss dec hex filename
106979 19557 240 126776 1ef38 nf_conntrack.ko
so, even with builtin gre, total size got reduced.
--- include/net/netfilter/nf_conntrack_core.h | 2 +- include/net/netfilter/nf_conntrack_l4proto.h | 8 +- net/netfilter/nf_conntrack_core.c | 11 +- net/netfilter/nf_conntrack_expect.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 14 +-- net/netfilter/nf_conntrack_proto.c | 175 ++++----------------------- net/netfilter/nf_conntrack_standalone.c | 3 +- net/netfilter/nf_flow_table_core.c | 2 +- net/netfilter/nfnetlink_cttimeout.c | 6 +- net/netfilter/nft_ct.c | 2 +- net/netfilter/xt_CT.c | 2 +- 11 files changed, 45 insertions(+), 182 deletions(-)
include/net/netfilter/nf_conntrack_core.h +1 -1
@@ -26,7 +26,7 @@ int nf_conntrack_init_net(struct net *net);void nf_conntrack_cleanup_net (struct net *net);void nf_conntrack_cleanup_net_list (struct list_head *net_exit_list); -int nf_conntrack_proto_pernet_init (struct net *net); +void nf_conntrack_proto_pernet_init (struct net *net);void nf_conntrack_proto_pernet_fini (struct net *net);int nf_conntrack_proto_init (void );
include/net/netfilter/nf_conntrack_l4proto.h +1 -7
@@ -140,13 +140,7 @@ extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;#define MAX_NF_CT_PROTO IPPROTO_UDPLITE -const struct nf_conntrack_l4proto *__nf_ct_l4proto_find (u8 l4proto); - -const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get (u8 l4proto); - -/* Protocol global registration. */ -int nf_ct_l4proto_register_one (const struct nf_conntrack_l4proto *proto); -void nf_ct_l4proto_unregister_one (const struct nf_conntrack_l4proto *proto); +const struct nf_conntrack_l4proto *nf_ct_l4proto_find (u8 l4proto);/* Generic netlink helpers */ int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
net/netfilter/nf_conntrack_core.c +3 -8
@@ -845,7 +845,7 @@ static int nf_ct_resolve_clash(struct net *net, struct sk_buff *skb,enum ip_conntrack_info oldinfo;struct nf_conn *loser_ct =nf_ct_get (skb, &oldinfo); - l4proto =__nf_ct_l4proto_find (nf_ct_protonum (ct)); + l4proto =nf_ct_l4proto_find (nf_ct_protonum (ct));if (l4proto->allow_clash && !nf_ct_is_dying (ct) &&atomic_inc_not_zero (&ct->ct_general.use)) {
@@ -1117,7 +1117,7 @@ static bool gc_worker_can_early_drop(const struct nf_conn *ct)if (!test_bit (IPS_ASSURED_BIT , &ct->status))return true; - l4proto =__nf_ct_l4proto_find (nf_ct_protonum (ct)); + l4proto =nf_ct_l4proto_find (nf_ct_protonum (ct));if (l4proto->can_early_drop && l4proto->can_early_drop (ct))return true;
@@ -2452,15 +2452,10 @@ int nf_conntrack_init_net(struct net *net)nf_conntrack_tstamp_pernet_init (net);nf_conntrack_ecache_pernet_init (net);nf_conntrack_helper_pernet_init (net); +nf_conntrack_proto_pernet_init (net); - ret =nf_conntrack_proto_pernet_init (net); -if (ret <0 ) - goto err_proto;return 0 ; -err_proto: -nf_conntrack_ecache_pernet_fini (net); -nf_conntrack_expect_pernet_fini (net); err_expect:free_percpu (net->ct.stat); err_pcpu_lists:
net/netfilter/nf_conntrack_expect.c +1 -1
@@ -610,7 +610,7 @@ static int exp_seq_show(struct seq_file *s, void *v) expect->tuple.src.l3num, expect->tuple.dst.protonum);print_tuple (s, &expect->tuple, -__nf_ct_l4proto_find (expect->tuple.dst.protonum)); +nf_ct_l4proto_find (expect->tuple.dst.protonum));if (expect->flags &NF_CT_EXPECT_PERMANENT ) {seq_puts (s,"PERMANENT" );
net/netfilter/nf_conntrack_netlink.c +6 -8
@@ -134,7 +134,7 @@ static int ctnetlink_dump_tuples(struct sk_buff *skb, ret =ctnetlink_dump_tuples_ip (skb, tuple);if (ret >=0 ) { - l4proto =__nf_ct_l4proto_find (tuple->dst.protonum); + l4proto =nf_ct_l4proto_find (tuple->dst.protonum); ret =ctnetlink_dump_tuples_proto (skb, tuple, l4proto); }rcu_read_unlock ();
@@ -182,7 +182,7 @@ static int ctnetlink_dump_protoinfo(struct sk_buff *skb, struct nf_conn *ct)struct nlattr *nest_proto;int ret; - l4proto =__nf_ct_l4proto_find (nf_ct_protonum (ct)); + l4proto =nf_ct_l4proto_find (nf_ct_protonum (ct));if (!l4proto->to_nlattr)return 0 ;
@@ -590,7 +590,7 @@ static size_t ctnetlink_proto_size(const struct nf_conn *ct) len =nla_policy_len (cta_ip_nla_policy,CTA_IP_MAX +1 ); len *=3u ;/* ORIG, REPLY, MASTER */ - l4proto =__nf_ct_l4proto_find (nf_ct_protonum (ct)); + l4proto =nf_ct_l4proto_find (nf_ct_protonum (ct)); len += l4proto->nlattr_size;if (l4proto->nlattr_tuple_size) { len4 = l4proto->nlattr_tuple_size ();
@@ -1059,7 +1059,7 @@ static int ctnetlink_parse_tuple_proto(struct nlattr *attr, tuple->dst.protonum =nla_get_u8 (tb[CTA_PROTO_NUM ]);rcu_read_lock (); - l4proto =__nf_ct_l4proto_find (tuple->dst.protonum); + l4proto =nf_ct_l4proto_find (tuple->dst.protonum);if (likely (l4proto->nlattr_to_tuple)) { ret = nla_validate_nested(attr, CTA_PROTO_MAX,
@@ -1722,11 +1722,9 @@ static int ctnetlink_change_protoinfo(struct nf_conn *ct,if (err <0 )return err; -rcu_read_lock (); - l4proto =__nf_ct_l4proto_find (nf_ct_protonum (ct)); + l4proto =nf_ct_l4proto_find (nf_ct_protonum (ct));if (l4proto->from_nlattr) err = l4proto->from_nlattr (tb, ct); -rcu_read_unlock ();return err; }
@@ -2676,7 +2674,7 @@ static int ctnetlink_exp_dump_mask(struct sk_buff *skb,rcu_read_lock (); ret =ctnetlink_dump_tuples_ip (skb, &m);if (ret >=0 ) { - l4proto =__nf_ct_l4proto_find (tuple->dst.protonum); + l4proto =nf_ct_l4proto_find (tuple->dst.protonum); ret =ctnetlink_dump_tuples_proto (skb, &m, l4proto); }rcu_read_unlock ();
net/netfilter/nf_conntrack_proto.c +26 -149
217 lines not on this page · raw message
net/netfilter/nf_conntrack_standalone.c +1 -2
@@ -310,8 +310,7 @@ static int ct_seq_show(struct seq_file *s, void *v)if (!net_eq (nf_ct_net (ct), net)) goto release; - l4proto =__nf_ct_l4proto_find (nf_ct_protonum (ct)); -WARN_ON (!l4proto); + l4proto =nf_ct_l4proto_find (nf_ct_protonum (ct)); ret = -ENOSPC ; seq_printf(s, "%-8s %u %-8s %u ",
net/netfilter/nf_flow_table_core.c +1 -1
@@ -120,7 +120,7 @@ static void flow_offload_fixup_ct_state(struct nf_conn *ct)if (l4num ==IPPROTO_TCP )flow_offload_fixup_tcp (&ct->proto.tcp); - l4proto =__nf_ct_l4proto_find (l4num); + l4proto =nf_ct_l4proto_find (l4num);if (!l4proto)return ;
net/netfilter/nfnetlink_cttimeout.c +3 -3
@@ -122,7 +122,7 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl,return -EBUSY ; } - l4proto =nf_ct_l4proto_find_get (l4num); + l4proto =nf_ct_l4proto_find (l4num);/* This protocol is not supportted, skip. */ if (l4proto->l4proto != l4num) {
@@ -357,7 +357,7 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl,return -EINVAL ; l4num =nla_get_u8 (cda[CTA_TIMEOUT_L4PROTO ]); - l4proto =nf_ct_l4proto_find_get (l4num); + l4proto =nf_ct_l4proto_find (l4num);/* This protocol is not supported, skip. */ if (l4proto->l4proto != l4num) {
@@ -438,7 +438,7 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl, l3num =ntohs (nla_get_be16 (cda[CTA_TIMEOUT_L3PROTO ])); l4num =nla_get_u8 (cda[CTA_TIMEOUT_L4PROTO ]); - l4proto =nf_ct_l4proto_find_get (l4num); + l4proto =nf_ct_l4proto_find (l4num); err = -EOPNOTSUPP ;if (l4proto->l4proto != l4num)
net/netfilter/nft_ct.c +1 -1
@@ -870,7 +870,7 @@ static int nft_ct_timeout_obj_init(const struct nft_ctx *ctx, l4num =nla_get_u8 (tb[NFTA_CT_TIMEOUT_L4PROTO ]); priv->l4proto = l4num; - l4proto =nf_ct_l4proto_find_get (l4num); + l4proto =nf_ct_l4proto_find (l4num);if (l4proto->l4proto != l4num) { ret = -EOPNOTSUPP ;
net/netfilter/xt_CT.c +1 -1
@@ -159,7 +159,7 @@ xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par,/* Make sure the timeout policy matches any existing protocol tracker, * otherwise default to generic. */ - l4proto =__nf_ct_l4proto_find (proto); + l4proto =nf_ct_l4proto_find (proto);if (timeout->l4proto->l4proto != l4proto->l4proto) { ret = -EINVAL ; pr_info_ratelimited("Timeout policy `%s' can only be used by L%d protocol number %d\n",
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 23/33 netfilter: nf_conntrack: provide modparam to always register conntrack hooks
In reply to Pablo Neira AyusoThe connection tracking hooks can be optionally registered per netns when conntrack is specifically invoked from the ruleset since 0c66dc1ea3f0 ("netfilter: conntrack: register hooks in netns when needed by ruleset"). Then, since 4d3a57f23dec ("netfilter: conntrack: do not enable connection tracking unless needed"), the default behaviour is changed to always register them on demand.
This patch provides a toggle that allows users to always register them. Without this toggle, in order to use conntrack for statistics collection, you need a dummy rule that refers to conntrack, eg.
iptables -I INPUT -m state --state NEW
This patch allows users to restore the original behaviour via modparam, ie. always register connection tracking, eg.
modprobe nf_conntrack enable_hooks=1
Hence, no dummy rule is required.
--- net/netfilter/nf_conntrack_standalone.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)
net/netfilter/nf_conntrack_standalone.c +24 -4
@@ -24,6 +24,10 @@#include <net/netfilter/nf_conntrack_timestamp.h> #include <linux/rculist_nulls.h> +static bool enable_hooks__read_mostly ; +MODULE_PARM_DESC (enable_hooks,"Always enable conntrack hooks" ); +module_param (enable_hooks, bool,0000 ); +unsigned int nf_conntrack_net_id__read_mostly ;#ifdef CONFIG_NF_CONNTRACK_PROCFS
@@ -1075,6 +1079,15 @@ static void nf_conntrack_standalone_fini_sysctl(struct net *net) }#endif /* CONFIG_SYSCTL */ +static void nf_conntrack_fini_net (struct net *net) +{ +if (enable_hooks) +nf_ct_netns_put (net,NFPROTO_INET ); + +nf_conntrack_standalone_fini_proc (net); +nf_conntrack_standalone_fini_sysctl (net); +} +static int nf_conntrack_pernet_init (struct net *net) {int ret;
@@ -1093,8 +1106,16 @@ static int nf_conntrack_pernet_init(struct net *net)if (ret <0 ) goto out_init_net; +if (enable_hooks) { + ret =nf_ct_netns_get (net,NFPROTO_INET ); +if (ret <0 ) + goto out_hooks; + } +return 0 ; +out_hooks: +nf_conntrack_fini_net (net); out_init_net:nf_conntrack_standalone_fini_proc (net); out_proc:
@@ -1106,10 +1127,9 @@ static void nf_conntrack_pernet_exit(struct list_head *net_exit_list) {struct net *net; -list_for_each_entry (net, net_exit_list, exit_list) { -nf_conntrack_standalone_fini_sysctl (net); -nf_conntrack_standalone_fini_proc (net); - } +list_for_each_entry (net, net_exit_list, exit_list) +nf_conntrack_fini_net (net); +nf_conntrack_cleanup_net_list (net_exit_list); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 24/33 netfilter: nft_meta: Add NFT_META_I/OIFKIND meta type
In reply to Pablo Neira AyusoFrom: wenxu <[email protected]>
In the ip_rcv the skb goes through the PREROUTING hook first, then kicks in vrf device and go through the same hook again. When conntrack dnat works with vrf, there will be some conflict with rules because the packet goes through the hook twice with different nf status.
ip link add user1 type vrf table 1
ip link add user2 type vrf table 2
ip l set dev tun1 master user1
ip l set dev tun2 master user2
nft add table firewall
nft add chain firewall zones { type filter hook prerouting priority - 300 \; } nft add rule firewall zones counter ct zone set iif map { "tun1" : 1, "tun2" : 2 } nft add chain firewall rule-1000-ingress
nft add rule firewall rule-1000-ingress ct zone 1 tcp dport 22 ct state new counter accept nft add rule firewall rule-1000-ingress counter drop
nft add chain firewall rule-1000-egress
nft add rule firewall rule-1000-egress tcp dport 22 ct state new counter drop nft add rule firewall rule-1000-egress counter accept
nft add chain firewall rules-all { type filter hook prerouting priority - 150 \; } nft add rule firewall rules-all ip daddr vmap { "2.2.2.11" : jump rule-1000-ingress } nft add rule firewall rules-all ct zone vmap { 1 : jump rule-1000-egress }
nft add rule firewall dnat-all ct zone vmap { 1 : jump dnat-1000 } nft add rule firewall dnat-1000 ip daddr 2.2.2.11 counter dnat to 10.0.0.7
For a package with ip daddr 2.2.2.11 and tcp dport 22, first time accept in the rule-1000-ingress and dnat to 10.0.0.7. Then second time the packet goto the wrong chain rule-1000-egress which leads the packet drop
With this patch, userspace can add the 'don't re-do entire ruleset for vrf' policy itself via:
nft add rule firewall rules-all meta iifkind "vrf" counter accept
--- include/uapi/linux/netfilter/nf_tables.h | 4 ++++ net/netfilter/nft_meta.c | 12 ++++++++++++ 2 files changed, 16 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -791,6 +791,8 @@ enum nft_exthdr_attributes {* @NFT_META_CGROUP: socket control group (skb->sk->sk_classid) * @NFT_META_PRANDOM: a 32bit pseudo-random number * @NFT_META_SECPATH: boolean, secpath_exists (!!skb->sp) +* @NFT_META_IIFKIND: packet input interface kind name (dev->rtnl_link_ops->kind) +* @NFT_META_OIFKIND: packet output interface kind name (dev->rtnl_link_ops->kind) */ enum nft_meta_keys {NFT_META_LEN ,
@@ -819,6 +821,8 @@ enum nft_meta_keys {NFT_META_CGROUP ,NFT_META_PRANDOM ,NFT_META_SECPATH , +NFT_META_IIFKIND , + NFT_META_OIFKIND, };/**
net/netfilter/nft_meta.c +12 -0
@@ -244,6 +244,16 @@ void nft_meta_get_eval(const struct nft_expr *expr,strncpy ((char *)dest, p->br->dev->name,IFNAMSIZ );return ;#endif +case NFT_META_IIFKIND : +if (in ==NULL || in->rtnl_link_ops ==NULL ) + goto err; +strncpy ((char *)dest, in->rtnl_link_ops->kind,IFNAMSIZ ); +break ; +case NFT_META_OIFKIND : +if (out ==NULL || out->rtnl_link_ops ==NULL ) + goto err; +strncpy ((char *)dest, out->rtnl_link_ops->kind,IFNAMSIZ ); +break ;default :WARN_ON (1 ); goto err;
@@ -340,6 +350,8 @@ static int nft_meta_get_init(const struct nft_ctx *ctx,break ;case NFT_META_IIFNAME :case NFT_META_OIFNAME : +case NFT_META_IIFKIND : +case NFT_META_OIFKIND : len =IFNAMSIZ ;break ;case NFT_META_PRANDOM :
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 25/33 netfilter: nat: un-export nf_nat_used_tuple
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Not used since 203f2e78200c27e ("netfilter: nat: remove l4proto->unique_tuple")
--- include/net/netfilter/nf_nat.h | 4 ---- net/netfilter/nf_nat_core.c | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-)
include/net/netfilter/nf_nat.h +0 -4
@@ -47,10 +47,6 @@ extern unsigned int nf_nat_alloc_null_binding(struct nf_conn *ct,struct nf_conn_nat *nf_ct_nat_ext_add (struct nf_conn *ct); -/* Is this tuple already taken? (not by us)*/ -int nf_nat_used_tuple (const struct nf_conntrack_tuple *tuple, -const struct nf_conn *ignored_conntrack); -static inline struct nf_conn_nat *nfct_nat (const struct nf_conn *ct) {#if defined(CONFIG_NF_NAT ) || defined(CONFIG_NF_NAT_MODULE )
net/netfilter/nf_nat_core.c +1 -2
@@ -146,7 +146,7 @@ hash_by_src(const struct net *n, const struct nf_conntrack_tuple *tuple) }/* Is this tuple already taken? (not by us) */ -int +static int nf_nat_used_tuple (const struct nf_conntrack_tuple *tuple,const struct nf_conn *ignored_conntrack) {
@@ -161,7 +161,6 @@ nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,nf_ct_invert_tuple (&reply, tuple);return nf_conntrack_tuple_taken (&reply, ignored_conntrack); } -EXPORT_SYMBOL (nf_nat_used_tuple);static bool nf_nat_inet_in_range (const struct nf_conntrack_tuple *t,const struct nf_nat_range2 *range)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 26/33 Revert "netfilter: nft_hash: add map lookups for hashing operations"
In reply to Pablo Neira AyusoFrom: Laura Garcia Liebana <[email protected]>
A better way to implement this from userspace has been found without specific code in the kernel side, revert this.
--- include/uapi/linux/netfilter/nf_tables.h | 4 +- net/netfilter/nft_hash.c | 121 ------------------------------- 2 files changed, 2 insertions(+), 123 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -2
@@ -877,8 +877,8 @@ enum nft_hash_attributes {NFTA_HASH_SEED ,NFTA_HASH_OFFSET ,NFTA_HASH_TYPE , -NFTA_HASH_SET_NAME , -NFTA_HASH_SET_ID , +NFTA_HASH_SET_NAME ,/* deprecated */ +NFTA_HASH_SET_ID ,/* deprecated */ __NFTA_HASH_MAX, };#define NFTA_HASH_MAX (__NFTA_HASH_MAX - 1)
net/netfilter/nft_hash.c +0 -121
193 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 27/33 netfilter: conntrack: fix IPV6=n builds
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Stephen Rothwell reports:
After merging the netfilter-next tree, today's linux-next build (powerpc ppc64_defconfig) failed like this:
ERROR: "nf_conntrack_invert_icmpv6_tuple" [nf_conntrack.ko] undefined!
ERROR: "nf_conntrack_icmpv6_packet" [nf_conntrack.ko] undefined!
ERROR: "nf_conntrack_icmpv6_init_net" [nf_conntrack.ko] undefined!
ERROR: "icmpv6_pkt_to_tuple" [nf_conntrack.ko] undefined!
ERROR: "nf_ct_gre_keymap_destroy" [nf_conntrack.ko] undefined!
icmpv6 related errors are due to lack of IS_ENABLED(CONFIG_IPV6) (no icmpv6 support is builtin if kernel has CONFIG_IPV6=n), the nf_ct_gre_keymap_destroy error is due to lack of PROTO_GRE check.
--- net/netfilter/nf_conntrack_core.c | 8 ++++++++ net/netfilter/nf_conntrack_proto.c | 2 ++ 2 files changed, 10 insertions(+)
net/netfilter/nf_conntrack_core.c +8 -0
@@ -274,8 +274,10 @@ nf_ct_get_tuple(const struct sk_buff *skb, tuple->dst.dir =IP_CT_DIR_ORIGINAL ;switch (protonum) { +#if IS_ENABLED (CONFIG_IPV6 )case IPPROTO_ICMPV6 :return icmpv6_pkt_to_tuple (skb, dataoff, net, tuple); +#endif case IPPROTO_ICMP :return icmp_pkt_to_tuple (skb, dataoff, net, tuple);#ifdef CONFIG_NF_CT_PROTO_GRE
@@ -412,8 +414,10 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,switch (orig->dst.protonum) {case IPPROTO_ICMP :return nf_conntrack_invert_icmp_tuple (inverse, orig); +#if IS_ENABLED (CONFIG_IPV6 )case IPPROTO_ICMPV6 :return nf_conntrack_invert_icmpv6_tuple (inverse, orig); +#endif } inverse->src.u.all = orig->dst.u.all;
@@ -526,10 +530,12 @@ EXPORT_SYMBOL_GPL(nf_ct_tmpl_free);static void destroy_gre_conntrack (struct nf_conn *ct) { +#ifdef CONFIG_NF_CT_PROTO_GRE struct nf_conn *master = ct->master;if (master)nf_ct_gre_keymap_destroy (master); +#endif } static void
@@ -1553,8 +1559,10 @@ static int nf_conntrack_handle_packet(struct nf_conn *ct, ctinfo, state);case IPPROTO_ICMP :return nf_conntrack_icmp_packet (ct, skb, ctinfo, state); +#if IS_ENABLED (CONFIG_IPV6 )case IPPROTO_ICMPV6 :return nf_conntrack_icmpv6_packet (ct, skb, ctinfo, state); +#endif #ifdef CONFIG_NF_CT_PROTO_UDPLITE case IPPROTO_UDPLITE : return nf_conntrack_udplite_packet(ct, skb, dataoff,
net/netfilter/nf_conntrack_proto.c +2 -0
@@ -597,7 +597,9 @@ void nf_conntrack_proto_pernet_init(struct net *net)nf_conntrack_udp_init_net (net);nf_conntrack_tcp_init_net (net);nf_conntrack_icmp_init_net (net); +#if IS_ENABLED (CONFIG_IPV6 )nf_conntrack_icmpv6_init_net (net); +#endif #ifdef CONFIG_NF_CT_PROTO_DCCP nf_conntrack_dccp_init_net (net);#endif
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 28/33 netfilter: conntrack: fix bogus port values for other l4 protocols
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We must only extract l4 proto information if we can track the layer 4 protocol.
Before removal of pkt_to_tuple callback, the code to extract port information was only reached for TCP/UDP/LITE/DCCP/SCTP.
The other protocols were handled by the indirect call, and the 'generic' tracker took care of other protocols that have no notion of 'ports'.
After removal of the callback we must be more strict here and only init port numbers for those protocols that have ports.
--- net/netfilter/nf_conntrack_core.c | 46 +++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-)
net/netfilter/nf_conntrack_core.c +35 -11
@@ -222,6 +222,24 @@ static u32 hash_conntrack(const struct net *net,return scale_hash (hash_conntrack_raw (tuple, net)); } +static bool nf_ct_get_tuple_ports (const struct sk_buff *skb, +unsigned int dataoff, +struct nf_conntrack_tuple *tuple) +{struct { +__be16 sport; +__be16 dport; + } _inet_hdr, *inet_hdr; + +/* Actually only need first 4 bytes to get ports. */ + inet_hdr =skb_header_pointer (skb, dataoff,sizeof (_inet_hdr), &_inet_hdr); +if (!inet_hdr) +return false; + + tuple->src.u.udp.port = inet_hdr->sport; + tuple->dst.u.udp.port = inet_hdr->dport; +return true; +} + static bool nf_ct_get_tuple(const struct sk_buff *skb, unsigned int nhoff,
@@ -234,10 +252,6 @@ nf_ct_get_tuple(const struct sk_buff *skb,unsigned int size;const __be32 *ap;__be32 _addrs[8 ]; -struct { -__be16 sport; -__be16 dport; - } _inet_hdr, *inet_hdr;memset (tuple,0 ,sizeof (*tuple));
@@ -284,15 +298,25 @@ nf_ct_get_tuple(const struct sk_buff *skb,case IPPROTO_GRE :return gre_pkt_to_tuple (skb, dataoff, net, tuple);#endif +case IPPROTO_TCP : +case IPPROTO_UDP :/* fallthrough */ +return nf_ct_get_tuple_ports (skb, dataoff, tuple); +#ifdef CONFIG_NF_CT_PROTO_UDPLITE +case IPPROTO_UDPLITE : +return nf_ct_get_tuple_ports (skb, dataoff, tuple); +#endif +#ifdef CONFIG_NF_CT_PROTO_SCTP +case IPPROTO_SCTP : +return nf_ct_get_tuple_ports (skb, dataoff, tuple); +#endif +#ifdef CONFIG_NF_CT_PROTO_DCCP +case IPPROTO_DCCP : +return nf_ct_get_tuple_ports (skb, dataoff, tuple); +#endif +default : +break ; } -/* Actually only need first 4 bytes to get ports. */ - inet_hdr =skb_header_pointer (skb, dataoff,sizeof (_inet_hdr), &_inet_hdr); -if (!inet_hdr) -return false; - - tuple->src.u.udp.port = inet_hdr->sport; - tuple->dst.u.udp.port = inet_hdr->dport;return true; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 29/33 ipvs: avoid indirect calls when calculating checksums
In reply to Pablo Neira AyusoFrom: Matteo Croce <[email protected]>
The function pointer ip_vs_protocol->csum_check is only used in protocol specific code, and never in the generic one.
Remove the function pointer from struct ip_vs_protocol and call the checksum functions directly.
This reduces the performance impact of the Spectre mitigation, and should give a small improvement even with RETPOLINES disabled.
--- include/net/ip_vs.h | 3 --- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 2 -- net/netfilter/ipvs/ip_vs_proto_sctp.c | 8 +++++--- net/netfilter/ipvs/ip_vs_proto_tcp.c | 12 +++++++----- net/netfilter/ipvs/ip_vs_proto_udp.c | 12 +++++++----- 5 files changed, 19 insertions(+), 18 deletions(-)
include/net/ip_vs.h +0 -3
@@ -453,9 +453,6 @@ struct ip_vs_protocol {int (*dnat_handler)(struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,struct ip_vs_iphdr *iph); -int (*csum_check)(int af,struct sk_buff *skb, -struct ip_vs_protocol *pp); -const char *(*state_name)(int state); void (*state_transition)(struct ip_vs_conn *cp, int direction,
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +0 -2
@@ -129,7 +129,6 @@ struct ip_vs_protocol ip_vs_protocol_ah = { .conn_out_get = ah_esp_conn_out_get, .snat_handler = NULL, .dnat_handler = NULL, - .csum_check = NULL, .state_transition = NULL, .register_app = NULL, .unregister_app = NULL,
@@ -152,7 +151,6 @@ struct ip_vs_protocol ip_vs_protocol_esp = { .conn_out_get = ah_esp_conn_out_get, .snat_handler = NULL, .dnat_handler = NULL, - .csum_check = NULL, .state_transition = NULL, .register_app = NULL, .unregister_app = NULL,
net/netfilter/ipvs/ip_vs_proto_sctp.c +5 -3
@@ -10,6 +10,9 @@#include <net/ip_vs.h> static int +sctp_csum_check (int af,struct sk_buff *skb,struct ip_vs_protocol *pp); + +static int sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, int *verdict, struct ip_vs_conn **cpp,
@@ -105,7 +108,7 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,int ret;/* Some checks before mangling */ -if (pp->csum_check && !pp->csum_check (cp->af, skb, pp)) +if (!sctp_csum_check (cp->af, skb, pp))return 0 ;/* Call application helper if needed */
@@ -152,7 +155,7 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,int ret;/* Some checks before mangling */ -if (pp->csum_check && !pp->csum_check (cp->af, skb, pp)) +if (!sctp_csum_check (cp->af, skb, pp))return 0 ;/* Call application helper if needed */
@@ -587,7 +590,6 @@ struct ip_vs_protocol ip_vs_protocol_sctp = { .conn_out_get = ip_vs_conn_out_get_proto, .snat_handler = sctp_snat_handler, .dnat_handler = sctp_dnat_handler, - .csum_check = sctp_csum_check, .state_name = sctp_state_name, .state_transition = sctp_state_transition, .app_conn_bind = sctp_app_conn_bind,
net/netfilter/ipvs/ip_vs_proto_tcp.c +7 -5
@@ -32,6 +32,9 @@#include <net/ip_vs.h> static int +tcp_csum_check (int af,struct sk_buff *skb,struct ip_vs_protocol *pp); + +static int tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, int *verdict, struct ip_vs_conn **cpp,
@@ -166,7 +169,7 @@ tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,int ret;/* Some checks before mangling */ -if (pp->csum_check && !pp->csum_check (cp->af, skb, pp)) +if (!tcp_csum_check (cp->af, skb, pp))return 0 ;/* Call application helper if needed */
@@ -192,7 +195,7 @@ tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,tcp_fast_csum_update (cp->af, tcph, &cp->daddr, &cp->vaddr, cp->dport, cp->vport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed = (cp->app && pp->csum_check) ? + skb->ip_summed = cp->app ?CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */
@@ -244,7 +247,7 @@ tcp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,int ret;/* Some checks before mangling */ -if (pp->csum_check && !pp->csum_check (cp->af, skb, pp)) +if (!tcp_csum_check (cp->af, skb, pp))return 0 ;/*
@@ -275,7 +278,7 @@ tcp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,tcp_fast_csum_update (cp->af, tcph, &cp->vaddr, &cp->daddr, cp->vport, cp->dport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed = (cp->app && pp->csum_check) ? + skb->ip_summed = cp->app ?CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */
@@ -736,7 +739,6 @@ struct ip_vs_protocol ip_vs_protocol_tcp = { .conn_out_get = ip_vs_conn_out_get_proto, .snat_handler = tcp_snat_handler, .dnat_handler = tcp_dnat_handler, - .csum_check = tcp_csum_check, .state_name = tcp_state_name, .state_transition = tcp_state_transition, .app_conn_bind = tcp_app_conn_bind,
net/netfilter/ipvs/ip_vs_proto_udp.c +7 -5
@@ -29,6 +29,9 @@#include <net/ip6_checksum.h> static int +udp_csum_check (int af,struct sk_buff *skb,struct ip_vs_protocol *pp); + +static int udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, int *verdict, struct ip_vs_conn **cpp,
@@ -156,7 +159,7 @@ udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,int ret;/* Some checks before mangling */ -if (pp->csum_check && !pp->csum_check (cp->af, skb, pp)) +if (!udp_csum_check (cp->af, skb, pp))return 0 ;/*
@@ -186,7 +189,7 @@ udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,udp_fast_csum_update (cp->af, udph, &cp->daddr, &cp->vaddr, cp->dport, cp->vport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed = (cp->app && pp->csum_check) ? + skb->ip_summed = cp->app ?CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */
@@ -239,7 +242,7 @@ udp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,int ret;/* Some checks before mangling */ -if (pp->csum_check && !pp->csum_check (cp->af, skb, pp)) +if (!udp_csum_check (cp->af, skb, pp))return 0 ;/*
@@ -270,7 +273,7 @@ udp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,udp_fast_csum_update (cp->af, udph, &cp->vaddr, &cp->daddr, cp->vport, cp->dport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed = (cp->app && pp->csum_check) ? + skb->ip_summed = cp->app ?CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */
@@ -494,7 +497,6 @@ struct ip_vs_protocol ip_vs_protocol_udp = { .conn_out_get = ip_vs_conn_out_get_proto, .snat_handler = udp_snat_handler, .dnat_handler = udp_dnat_handler, - .csum_check = udp_csum_check, .state_transition = udp_state_transition, .state_name = udp_state_name, .register_app = udp_register_app,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 30/33 ipvs: use indirect call wrappers
In reply to Pablo Neira AyusoFrom: Matteo Croce <[email protected]>
Use the new indirect call wrappers in IPVS when calling the TCP or UDP protocol specific functions.
This avoids an indirect calls in IPVS, and reduces the performance impact of the Spectre mitigation.
--- net/netfilter/ipvs/ip_vs_core.c | 49 ++++++++++++++++++++++++++++++------ net/netfilter/ipvs/ip_vs_proto_tcp.c | 3 ++- net/netfilter/ipvs/ip_vs_proto_udp.c | 3 ++- 3 files changed, 45 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +41 -8
@@ -53,6 +53,7 @@#endif #include <net/ip_vs.h> +#include <linux/indirect_call_wrapper.h> EXPORT_SYMBOL (register_ip_vs_scheduler);
@@ -70,6 +71,29 @@ EXPORT_SYMBOL(ip_vs_get_debug_level);#endif EXPORT_SYMBOL (ip_vs_new_conn_out); +#ifdef CONFIG_IP_VS_PROTO_TCP +INDIRECT_CALLABLE_DECLARE(int + tcp_snat_handler(struct sk_buff *skb,struct ip_vs_protocol *pp, +struct ip_vs_conn *cp,struct ip_vs_iphdr *iph)); +#endif + +#ifdef CONFIG_IP_VS_PROTO_UDP +INDIRECT_CALLABLE_DECLARE(int + udp_snat_handler(struct sk_buff *skb,struct ip_vs_protocol *pp, +struct ip_vs_conn *cp,struct ip_vs_iphdr *iph)); +#endif + +#if defined(CONFIG_IP_VS_PROTO_TCP ) && defined(CONFIG_IP_VS_PROTO_UDP ) +#define SNAT_CALL (f, ...) \ + INDIRECT_CALL_2(f, tcp_snat_handler, udp_snat_handler, __VA_ARGS__) +#elif defined(CONFIG_IP_VS_PROTO_TCP ) +#define SNAT_CALL (f, ...) INDIRECT_CALL_1(f, tcp_snat_handler, __VA_ARGS__) +#elif defined(CONFIG_IP_VS_PROTO_UDP ) +#define SNAT_CALL (f, ...) INDIRECT_CALL_1(f, udp_snat_handler, __VA_ARGS__) +#else +#define SNAT_CALL (f, ...) f(__VA_ARGS__) +#endif +static unsigned int ip_vs_net_id__read_mostly ;/* netns cnt used for uniqueness */ static atomic_t ipvs_netns_cnt =ATOMIC_INIT (0 );
@@ -478,7 +502,9 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,*/ if ((!skb->dev || skb->dev->flags &IFF_LOOPBACK )) { iph->hdr_flags ^=IP_VS_HDR_INVERSE ; - cp = pp->conn_in_get (svc->ipvs, svc->af, skb, iph); + cp =INDIRECT_CALL_1 (pp->conn_in_get, + ip_vs_conn_in_get_proto, svc->ipvs, + svc->af, skb, iph); iph->hdr_flags ^=IP_VS_HDR_INVERSE ;if (cp) {
@@ -972,7 +998,8 @@ static int ip_vs_out_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb,ip_vs_fill_iph_skb_icmp (AF_INET , skb, offset, true, &ciph);/* The embedded headers contain source and dest in reverse order */ - cp = pp->conn_out_get (ipvs,AF_INET , skb, &ciph); + cp =INDIRECT_CALL_1 (pp->conn_out_get, ip_vs_conn_out_get_proto, + ipvs,AF_INET , skb, &ciph);if (!cp)return NF_ACCEPT ;
@@ -1028,7 +1055,8 @@ static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,return NF_ACCEPT ;/* The embedded headers contain source and dest in reverse order */ - cp = pp->conn_out_get (ipvs,AF_INET6 , skb, &ciph); + cp =INDIRECT_CALL_1 (pp->conn_out_get, ip_vs_conn_out_get_proto, + ipvs,AF_INET6 , skb, &ciph);if (!cp)return NF_ACCEPT ;
@@ -1263,7 +1291,8 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, goto drop;/* mangle the packet */ -if (pp->snat_handler && !pp->snat_handler (skb, pp, cp, iph)) +if (pp->snat_handler && + !SNAT_CALL (pp->snat_handler, skb, pp, cp, iph)) goto drop;#ifdef CONFIG_IP_VS_IPV6
@@ -1389,7 +1418,8 @@ ip_vs_out(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, in/* * Check if the packet belongs to an existing entry */ - cp = pp->conn_out_get (ipvs, af, skb, &iph); + cp =INDIRECT_CALL_1 (pp->conn_out_get, ip_vs_conn_out_get_proto, + ipvs, af, skb, &iph);if (likely (cp)) {if (IP_VS_FWD_METHOD (cp) !=IP_VS_CONN_F_MASQ )
@@ -1644,7 +1674,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,/* The embedded headers contain source and dest in reverse order. * For IPIP this is error for request, not for reply. */ - cp = pp->conn_in_get (ipvs,AF_INET , skb, &ciph); + cp =INDIRECT_CALL_1 (pp->conn_in_get, ip_vs_conn_in_get_proto, + ipvs,AF_INET , skb, &ciph);if (!cp) {int v;
@@ -1796,7 +1827,8 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,/* The embedded headers contain source and dest in reverse order * if not from localhost */ - cp = pp->conn_in_get (ipvs,AF_INET6 , skb, &ciph); + cp =INDIRECT_CALL_1 (pp->conn_in_get, ip_vs_conn_in_get_proto, + ipvs,AF_INET6 , skb, &ciph);if (!cp) {int v;
@@ -1925,7 +1957,8 @@ ip_vs_in(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, int/* * Check if the packet belongs to an existing connection entry */ - cp = pp->conn_in_get (ipvs, af, skb, &iph); + cp =INDIRECT_CALL_1 (pp->conn_in_get, ip_vs_conn_in_get_proto, + ipvs, af, skb, &iph); conn_reuse_mode =sysctl_conn_reuse_mode (ipvs);if (conn_reuse_mode && !iph.fragoffs &&is_new_conn (skb, &iph) && cp) {
net/netfilter/ipvs/ip_vs_proto_tcp.c +2 -1
@@ -28,6 +28,7 @@#include <net/ip6_checksum.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h> +#include <linux/indirect_call_wrapper.h> #include <net/ip_vs.h>
@@ -146,7 +147,7 @@ tcp_partial_csum_update(int af, struct tcphdr *tcph, } -static int +INDIRECT_CALLABLE_SCOPE inttcp_snat_handler (struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,struct ip_vs_iphdr *iph) {
net/netfilter/ipvs/ip_vs_proto_udp.c +2 -1
@@ -23,6 +23,7 @@#include <linux/netfilter.h> #include <linux/netfilter_ipv4.h> #include <linux/udp.h> +#include <linux/indirect_call_wrapper.h> #include <net/ip_vs.h> #include <net/ip.h>
@@ -136,7 +137,7 @@ udp_partial_csum_update(int af, struct udphdr *uhdr, } -static int +INDIRECT_CALLABLE_SCOPE intudp_snat_handler (struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,struct ip_vs_iphdr *iph) {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 31/33 netfilter: nft_counter: remove wrong __percpu of nft_counter_resest()'s arg
In reply to Pablo Neira AyusoFrom: Luc Van Oostenryck <[email protected]>
nft_counter_rest() has its first argument declared as
struct nft_counter_percpu_priv __percpu *priv
but this structure is not percpu (it only countains a member 'counter' which is, correctly, a pointer to a percpu struct nft_counter).
So, remove the '__percpu' from the argument's declaration.
--- net/netfilter/nft_counter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_counter.c +1 -1
@@ -104,7 +104,7 @@ static void nft_counter_obj_destroy(const struct nft_ctx *ctx,nft_counter_do_destroy (priv); } -static void nft_counter_reset (struct nft_counter_percpu_priv __percpu *priv, +static void nft_counter_reset (struct nft_counter_percpu_priv *priv,struct nft_counter *total) {struct nft_counter *this_cpu;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 32/33 netfilter: conntrack: fix error path in nf_conntrack_pernet_init()
In reply to Pablo Neira AyusoFrom: Cong Wang <[email protected]>
When nf_ct_netns_get() fails, it should clean up itself, its caller doesn't need to call nf_conntrack_fini_net().
nf_conntrack_init_net() is called after registering sysctl and proc, so its cleanup function should be called before unregistering sysctl and proc.
--- net/netfilter/nf_conntrack_standalone.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_standalone.c +2 -2
@@ -1115,11 +1115,11 @@ static int nf_conntrack_pernet_init(struct net *net)return 0 ; out_hooks: -nf_conntrack_fini_net (net); +nf_conntrack_cleanup_net (net); out_init_net:nf_conntrack_standalone_fini_proc (net); out_proc: -nf_conntrack_cleanup_net (net); +nf_conntrack_standalone_fini_sysctl (net);return ret; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 33/33 netfilter: ipv4: remove useless export_symbol
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Only one caller; place it where needed and get rid of the EXPORT_SYMBOL.
--- include/linux/netfilter_ipv4.h | 6 ------ net/ipv4/netfilter.c | 18 ------------------ net/netfilter/utils.c | 19 +++++++++++++++++++ 3 files changed, 19 insertions(+), 24 deletions(-)
include/linux/netfilter_ipv4.h +0 -6
@@ -25,7 +25,6 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, u_int8_t protocol);int nf_ip_route (struct net *net,struct dst_entry **dst,struct flowi *fl,bool strict); -int nf_ip_reroute (struct sk_buff *skb,const struct nf_queue_entry *entry);#else static inline __sum16 nf_ip_checksum (struct sk_buff *skb,unsigned int hook,unsigned int dataoff,u_int8_t protocol)
@@ -37,11 +36,6 @@ static inline int nf_ip_route(struct net *net, struct dst_entry **dst, {return -EOPNOTSUPP ; } -static inline int nf_ip_reroute (struct sk_buff *skb, -const struct nf_queue_entry *entry) -{ -return -EOPNOTSUPP ; -}#endif /* CONFIG_INET */ #endif /*__LINUX_IP_NETFILTER_H*/
net/ipv4/netfilter.c +0 -18
@@ -80,24 +80,6 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t }EXPORT_SYMBOL (ip_route_me_harder); -int nf_ip_reroute (struct sk_buff *skb,const struct nf_queue_entry *entry) -{ -const struct ip_rt_info *rt_info =nf_queue_entry_reroute (entry); - -if (entry->state.hook ==NF_INET_LOCAL_OUT ) { -const struct iphdr *iph =ip_hdr (skb); - -if (!(iph->tos == rt_info->tos && - skb->mark == rt_info->mark && - iph->daddr == rt_info->daddr && - iph->saddr == rt_info->saddr)) -return ip_route_me_harder (entry->state.net, skb, -RTN_UNSPEC ); - } -return 0 ; -} -EXPORT_SYMBOL_GPL (nf_ip_reroute); -int nf_ip_route (struct net *net,struct dst_entry **dst,struct flowi *fl,bool strict__always_unused ) {
net/netfilter/utils.c +19 -0
@@ -180,6 +180,25 @@ int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl, }EXPORT_SYMBOL_GPL (nf_route); +static int nf_ip_reroute (struct sk_buff *skb,const struct nf_queue_entry *entry) +{ +#ifdef CONFIG_INET +const struct ip_rt_info *rt_info =nf_queue_entry_reroute (entry); + +if (entry->state.hook ==NF_INET_LOCAL_OUT ) { +const struct iphdr *iph =ip_hdr (skb); + +if (!(iph->tos == rt_info->tos && + skb->mark == rt_info->mark && + iph->daddr == rt_info->daddr && + iph->saddr == rt_info->saddr)) +return ip_route_me_harder (entry->state.net, skb, +RTN_UNSPEC ); + } +#endif +return 0 ; +} +int nf_reroute (struct sk_buff *skb,struct nf_queue_entry *entry) {const struct nf_ipv6_ops *v6ops;
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Tue, 29 Jan 2019 00:57:17 +0100
Quoted 1 line
The following patchset contains Netfilter/IPVS updates for your net-next tree:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thanks Pablo.