netfilter: conntrack: do not enable connection tracking unless needed
Subsystems (4)
Pablo Neira Ayuso
maintainerPATCH 20/47 netfilter: conntrack: do not enable connection tracking unless needed
From: Florian Westphal <[email protected]>
Discussion during NFWS 2017 in Faro has shown that the current conntrack behaviour is unreasonable.
Even if conntrack module is loaded on behalf of a single net namespace, its turned on for all namespaces, which is expensive. Commit 481fa373476 ("netfilter: conntrack: add nf_conntrack_default_on sysctl") attempted to provide an alternative to the 'default on' behaviour by adding a sysctl to change it.
However, as Eric points out, the sysctl only becomes available once the module is loaded, and then its too late.
So we either have to move the sysctl to the core, or, alternatively, change conntrack to become active only once the rule set requires this.
This does the latter, conntrack is only enabled when a rule needs it.
--- Documentation/networking/nf_conntrack-sysctl.txt | 11 --------- include/net/netfilter/nf_conntrack_l3proto.h | 15 ------------ net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 16 ++----------- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 17 ++------------ net/netfilter/nf_conntrack_proto.c | 29 ------------------------ net/netfilter/nf_conntrack_standalone.c | 10 -------- 6 files changed, 4 insertions(+), 94 deletions(-)
Documentation/networking/nf_conntrack-sysctl.txt +0 -11
@@ -96,17 +96,6 @@ nf_conntrack_max - INTEGER Size of connection tracking table. Default value is nf_conntrack_buckets value * 4. -nf_conntrack_default_on - BOOLEAN - 0 - don't register conntrack in new net namespaces - 1 - register conntrack in new net namespaces (default) - - This controls wheter newly created network namespaces have connection - tracking enabled by default. It will be enabled automatically - regardless of this setting if the new net namespace requires - connection tracking, e.g. when NAT rules are created. - This setting is only visible in initial user namespace, it has no - effect on existing namespaces. - nf_conntrack_tcp_be_liberal - BOOLEAN 0 - disabled (default) not 0 - enabled
include/net/netfilter/nf_conntrack_l3proto.h +0 -15
@@ -73,21 +73,6 @@ struct nf_conntrack_l3proto {extern struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[NFPROTO_NUMPROTO ]; -#ifdef CONFIG_SYSCTL -/* Protocol pernet registration. */ -int nf_ct_l3proto_pernet_register (struct net *net, -struct nf_conntrack_l3proto *proto); -#else -static inline int nf_ct_l3proto_pernet_register (struct net *n, -struct nf_conntrack_l3proto *p) -{ -return 0 ; -} -#endif - -void nf_ct_l3proto_pernet_unregister (struct net *net, -struct nf_conntrack_l3proto *proto); -/* Protocol global registration. */ int nf_ct_l3proto_register (struct nf_conntrack_l3proto *proto);void nf_ct_l3proto_unregister (struct nf_conntrack_l3proto *proto);
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +2 -14
@@ -398,24 +398,12 @@ static struct nf_conntrack_l4proto *builtin_l4proto4[] = {static int ipv4_net_init (struct net *net) { -int ret =0 ; - - ret =nf_ct_l4proto_pernet_register (net, builtin_l4proto4, -ARRAY_SIZE (builtin_l4proto4)); -if (ret <0 ) -return ret; - ret =nf_ct_l3proto_pernet_register (net, &nf_conntrack_l3proto_ipv4); -if (ret <0 ) { -pr_err ("nf_conntrack_ipv4: pernet registration failed\n" ); -nf_ct_l4proto_pernet_unregister (net, builtin_l4proto4, -ARRAY_SIZE (builtin_l4proto4)); - } -return ret; +return nf_ct_l4proto_pernet_register (net, builtin_l4proto4, +ARRAY_SIZE (builtin_l4proto4)); }static void ipv4_net_exit (struct net *net) { -nf_ct_l3proto_pernet_unregister (net, &nf_conntrack_l3proto_ipv4);nf_ct_l4proto_pernet_unregister (net, builtin_l4proto4,ARRAY_SIZE (builtin_l4proto4)); }
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +2 -15
@@ -398,25 +398,12 @@ static struct nf_conntrack_l4proto *builtin_l4proto6[] = {static int ipv6_net_init (struct net *net) { -int ret =0 ; - - ret =nf_ct_l4proto_pernet_register (net, builtin_l4proto6, -ARRAY_SIZE (builtin_l4proto6)); -if (ret <0 ) -return ret; - - ret =nf_ct_l3proto_pernet_register (net, &nf_conntrack_l3proto_ipv6); -if (ret <0 ) { -pr_err ("nf_conntrack_ipv6: pernet registration failed.\n" ); -nf_ct_l4proto_pernet_unregister (net, builtin_l4proto6, -ARRAY_SIZE (builtin_l4proto6)); - } -return ret; +return nf_ct_l4proto_pernet_register (net, builtin_l4proto6, +ARRAY_SIZE (builtin_l4proto6)); }static void ipv6_net_exit (struct net *net) { -nf_ct_l3proto_pernet_unregister (net, &nf_conntrack_l3proto_ipv6);nf_ct_l4proto_pernet_unregister (net, builtin_l4proto6,ARRAY_SIZE (builtin_l4proto6)); }
net/netfilter/nf_conntrack_proto.c +0 -29
@@ -238,20 +238,6 @@ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto) }EXPORT_SYMBOL_GPL (nf_ct_l3proto_register); -#ifdef CONFIG_SYSCTL -extern unsigned int nf_conntrack_default_on; - -int nf_ct_l3proto_pernet_register (struct net *net, -struct nf_conntrack_l3proto *proto) -{ -if (nf_conntrack_default_on ==0 ) -return 0 ; - -return proto->net_ns_get ? proto->net_ns_get (net) :0 ; -} -EXPORT_SYMBOL_GPL (nf_ct_l3proto_pernet_register); -#endif -void nf_ct_l3proto_unregister (struct nf_conntrack_l3proto *proto) {BUG_ON (proto->l3proto >=NFPROTO_NUMPROTO );
@@ -270,21 +256,6 @@ void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto) }EXPORT_SYMBOL_GPL (nf_ct_l3proto_unregister); -void nf_ct_l3proto_pernet_unregister (struct net *net, -struct nf_conntrack_l3proto *proto) -{ -/* -* nf_conntrack_default_on *might* have registered hooks. -* ->net_ns_put must cope with more puts() than get(), i.e. -* if nf_conntrack_default_on was 0 at time of -* nf_ct_l3proto_pernet_register invocation this net_ns_put() -* should be a noop. -*/ -if (proto->net_ns_put) - proto->net_ns_put (net); -} -EXPORT_SYMBOL_GPL (nf_ct_l3proto_pernet_unregister); -static struct nf_proto_net *nf_ct_l4proto_net (struct net *net,struct nf_conntrack_l4proto *l4proto) {
net/netfilter/nf_conntrack_standalone.c +0 -10
@@ -452,9 +452,6 @@ static int log_invalid_proto_max __read_mostly = 255;/* size the user *wants to set */ static unsigned int nf_conntrack_htable_size_user__read_mostly ; -extern unsigned int nf_conntrack_default_on; -unsigned int nf_conntrack_default_on__read_mostly =1 ; -static int nf_conntrack_hash_sysctl (struct ctl_table *table,int write,void __user *buffer,size_t *lenp,loff_t *ppos)
@@ -520,13 +517,6 @@ static struct ctl_table nf_ct_sysctl_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, - { - .procname = "nf_conntrack_default_on", - .data = &nf_conntrack_default_on, - .maxlen = sizeof(unsigned int), - .mode = 0644, - .proc_handler = proc_dointvec, - }, { } };
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 21/47 netfilter: xtables: Remove unused variable in compat_copy_entry_from_user()
From: Taehee Yoo <[email protected]>
The target variable is not used in the compat_copy_entry_from_user(). So It can be removed.
--- net/ipv4/netfilter/arp_tables.c | 2 -- net/ipv4/netfilter/ip_tables.c | 2 -- 2 files changed, 4 deletions(-)
net/ipv4/netfilter/arp_tables.c +0 -2
@@ -1117,7 +1117,6 @@ compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr, struct xt_table_info *newinfo, unsigned char *base) { struct xt_entry_target *t; -struct xt_target *target;struct arpt_entry *de;unsigned int origsize;int h;
@@ -1132,7 +1131,6 @@ compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr, de->target_offset = e->target_offset - (origsize - *size); t =compat_arpt_get_target (e); - target = t->u.kernel.target;xt_compat_target_from_user (t, dstptr, size); de->next_offset = e->next_offset - (origsize - *size);
net/ipv4/netfilter/ip_tables.c +0 -2
@@ -1355,7 +1355,6 @@ compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr, struct xt_table_info *newinfo, unsigned char *base) { struct xt_entry_target *t; -struct xt_target *target;struct ipt_entry *de;unsigned int origsize;int h;
@@ -1374,7 +1373,6 @@ compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr, de->target_offset = e->target_offset - (origsize - *size); t =compat_ipt_get_target (e); - target = t->u.kernel.target;xt_compat_target_from_user (t, dstptr, size); de->next_offset = e->next_offset - (origsize - *size);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 22/47 netfilter: constify nf_conntrack_l3/4proto parameters
In reply to Pablo Neira AyusoFrom: Julia Lawall <[email protected]>
When a nf_conntrack_l3/4proto parameter is not on the left hand side of an assignment, its address is not taken, and it is not passed to a function that may modify its fields, then it can be declared as const.
This change is useful from a documentation point of view, and can possibly facilitate making some nf_conntrack_l3/4proto structures const subsequently.
Done with the help of Coccinelle.
--- include/net/netfilter/nf_conntrack_l4proto.h | 14 +++++++------- include/net/netfilter/nf_conntrack_timeout.h | 2 +- net/netfilter/nf_conntrack_core.c | 8 ++++---- net/netfilter/nf_conntrack_netlink.c | 6 +++--- net/netfilter/nf_conntrack_proto.c | 24 ++++++++++++------------ net/netfilter/nfnetlink_cttimeout.c | 5 +++-- 6 files changed, 30 insertions(+), 29 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +7 -7
@@ -125,23 +125,23 @@ struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u_int16_t l3proto,struct nf_conntrack_l4proto *nf_ct_l4proto_find_get (u_int16_t l3proto,u_int8_t l4proto); -void nf_ct_l4proto_put (struct nf_conntrack_l4proto *p); +void nf_ct_l4proto_put (const struct nf_conntrack_l4proto *p);/* Protocol pernet registration. */ int nf_ct_l4proto_pernet_register_one (struct net *net, -struct nf_conntrack_l4proto *proto); +const struct nf_conntrack_l4proto *proto);void nf_ct_l4proto_pernet_unregister_one (struct net *net, -struct nf_conntrack_l4proto *proto); +const struct nf_conntrack_l4proto *proto);int nf_ct_l4proto_pernet_register (struct net *net, -struct nf_conntrack_l4proto *proto[], +struct nf_conntrack_l4proto *const proto[],unsigned int num_proto);void nf_ct_l4proto_pernet_unregister (struct net *net, -struct nf_conntrack_l4proto *proto[], -unsigned int num_proto); +struct nf_conntrack_l4proto *const proto[], +unsigned int num_proto);/* Protocol global registration. */ int nf_ct_l4proto_register_one (struct nf_conntrack_l4proto *proto); -void nf_ct_l4proto_unregister_one (struct nf_conntrack_l4proto *proto); +void nf_ct_l4proto_unregister_one (const struct nf_conntrack_l4proto *proto);int nf_ct_l4proto_register (struct nf_conntrack_l4proto *proto[],unsigned int num_proto); void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *proto[],
include/net/netfilter/nf_conntrack_timeout.h +1 -1
@@ -68,7 +68,7 @@ struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct,static inline unsigned int *nf_ct_timeout_lookup (struct net *net,struct nf_conn *ct, -struct nf_conntrack_l4proto *l4proto) +const struct nf_conntrack_l4proto *l4proto) {#ifdef CONFIG_NF_CONNTRACK_TIMEOUT struct nf_conn_timeout *timeout_ext;
net/netfilter/nf_conntrack_core.c +4 -4
@@ -1176,8 +1176,8 @@ EXPORT_SYMBOL_GPL(nf_conntrack_free); static noinline struct nf_conntrack_tuple_hash *init_conntrack (struct net *net,struct nf_conn *tmpl,const struct nf_conntrack_tuple *tuple, -struct nf_conntrack_l3proto *l3proto, -struct nf_conntrack_l4proto *l4proto, +const struct nf_conntrack_l3proto *l3proto, +const struct nf_conntrack_l4proto *l4proto,struct sk_buff *skb,unsigned int dataoff,u32 hash) {
@@ -1288,8 +1288,8 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl,unsigned int dataoff, u_int16_t l3num, u_int8_t protonum, - struct nf_conntrack_l3proto *l3proto, - struct nf_conntrack_l4proto *l4proto) + const struct nf_conntrack_l3proto *l3proto, + const struct nf_conntrack_l4proto *l4proto) { const struct nf_conntrack_zone *zone;struct nf_conntrack_tuple tuple;
net/netfilter/nf_conntrack_netlink.c +3 -3
@@ -61,8 +61,8 @@ MODULE_LICENSE("GPL");static char __initdata version[] ="0.93" ;static int ctnetlink_dump_tuples_proto (struct sk_buff *skb, -const struct nf_conntrack_tuple *tuple, -struct nf_conntrack_l4proto *l4proto) +const struct nf_conntrack_tuple *tuple, +const struct nf_conntrack_l4proto *l4proto) {int ret =0 ;struct nlattr *nest_parms;
@@ -86,7 +86,7 @@ static int ctnetlink_dump_tuples_proto(struct sk_buff *skb,static int ctnetlink_dump_tuples_ip (struct sk_buff *skb,const struct nf_conntrack_tuple *tuple, -struct nf_conntrack_l3proto *l3proto) +const struct nf_conntrack_l3proto *l3proto) {int ret =0 ;struct nlattr *nest_parms;
net/netfilter/nf_conntrack_proto.c +12 -12
@@ -188,7 +188,7 @@ nf_ct_l4proto_find_get(u_int16_t l3num, u_int8_t l4num) }EXPORT_SYMBOL_GPL (nf_ct_l4proto_find_get); -void nf_ct_l4proto_put (struct nf_conntrack_l4proto *p) +void nf_ct_l4proto_put (const struct nf_conntrack_l4proto *p) {module_put (p->me); }
@@ -257,7 +257,7 @@ void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto)EXPORT_SYMBOL_GPL (nf_ct_l3proto_unregister);static struct nf_proto_net *nf_ct_l4proto_net (struct net *net, -struct nf_conntrack_l4proto *l4proto) +const struct nf_conntrack_l4proto *l4proto) {if (l4proto->get_net_proto) {/* statically built-in protocols use static per-net */
@@ -272,7 +272,7 @@ static struct nf_proto_net *nf_ct_l4proto_net(struct net *net,static int nf_ct_l4proto_register_sysctl (struct net *net,struct nf_proto_net *pn, -struct nf_conntrack_l4proto *l4proto) +const struct nf_conntrack_l4proto *l4proto) {int err =0 ;
@@ -295,8 +295,8 @@ int nf_ct_l4proto_register_sysctl(struct net *net,static void nf_ct_l4proto_unregister_sysctl (struct net *net, -struct nf_proto_net *pn, -struct nf_conntrack_l4proto *l4proto) +struct nf_proto_net *pn, +const struct nf_conntrack_l4proto *l4proto) {#ifdef CONFIG_SYSCTL if (pn->ctl_table_header !=NULL )
@@ -366,7 +366,7 @@ int nf_ct_l4proto_register_one(struct nf_conntrack_l4proto *l4proto)EXPORT_SYMBOL_GPL (nf_ct_l4proto_register_one);int nf_ct_l4proto_pernet_register_one (struct net *net, -struct nf_conntrack_l4proto *l4proto) +const struct nf_conntrack_l4proto *l4proto) {int ret =0 ;struct nf_proto_net *pn =NULL ;
@@ -391,7 +391,7 @@ int nf_ct_l4proto_pernet_register_one(struct net *net, }EXPORT_SYMBOL_GPL (nf_ct_l4proto_pernet_register_one); -static void __nf_ct_l4proto_unregister_one (struct nf_conntrack_l4proto *l4proto) +static void __nf_ct_l4proto_unregister_one (const struct nf_conntrack_l4proto *l4proto) {BUG_ON (l4proto->l3proto >=ARRAY_SIZE (nf_ct_protos));
@@ -404,7 +404,7 @@ static void __nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto) &nf_conntrack_l4proto_generic); } -void nf_ct_l4proto_unregister_one (struct nf_conntrack_l4proto *l4proto) +void nf_ct_l4proto_unregister_one (const struct nf_conntrack_l4proto *l4proto) {mutex_lock (&nf_ct_proto_mutex);__nf_ct_l4proto_unregister_one (l4proto);
@@ -415,7 +415,7 @@ void nf_ct_l4proto_unregister_one(struct nf_conntrack_l4proto *l4proto)EXPORT_SYMBOL_GPL (nf_ct_l4proto_unregister_one);void nf_ct_l4proto_pernet_unregister_one (struct net *net, -struct nf_conntrack_l4proto *l4proto) +const struct nf_conntrack_l4proto *l4proto) {struct nf_proto_net *pn =nf_ct_l4proto_net (net, l4proto);
@@ -449,7 +449,7 @@ int nf_ct_l4proto_register(struct nf_conntrack_l4proto *l4proto[],EXPORT_SYMBOL_GPL (nf_ct_l4proto_register);int nf_ct_l4proto_pernet_register (struct net *net, -struct nf_conntrack_l4proto *l4proto[], +struct nf_conntrack_l4proto *const l4proto[],unsigned int num_proto) {int ret = -EINVAL ;
@@ -485,8 +485,8 @@ void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *l4proto[],EXPORT_SYMBOL_GPL (nf_ct_l4proto_unregister);void nf_ct_l4proto_pernet_unregister (struct net *net, -struct nf_conntrack_l4proto *l4proto[], -unsigned int num_proto) +struct nf_conntrack_l4proto *const l4proto[], +unsigned int num_proto) {while (num_proto-- !=0 )nf_ct_l4proto_pernet_unregister_one (net, l4proto[num_proto]);
net/netfilter/nfnetlink_cttimeout.c +3 -2
@@ -47,7 +47,8 @@ static const struct nla_policy cttimeout_nla_policy[CTA_TIMEOUT_MAX+1] = { };static int -ctnl_timeout_parse_policy (void *timeouts,struct nf_conntrack_l4proto *l4proto, +ctnl_timeout_parse_policy (void *timeouts, +const struct nf_conntrack_l4proto *l4proto,struct net *net,const struct nlattr *attr) {int ret =0 ;
@@ -401,7 +402,7 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl,static int cttimeout_default_fill_info (struct net *net,struct sk_buff *skb,u32 portid,u32 seq,u32 type,int event, -struct nf_conntrack_l4proto *l4proto) +const struct nf_conntrack_l4proto *l4proto) {struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;
Signature · 1 line
2.1.4