Skip to content

Commit ba3fbe6

Browse files
committed
netfilter: nf_conntrack: provide modparam to always register conntrack hooks
The connection tracking hooks can be optionally registered per netns when conntrack is specifically invoked from the ruleset since 0c66dc1 ("netfilter: conntrack: register hooks in netns when needed by ruleset"). Then, since 4d3a57f ("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. Reported-by: Laura Garcia <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 4a60dc7 commit ba3fbe6

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

net/netfilter/nf_conntrack_standalone.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include <net/netfilter/nf_conntrack_timestamp.h>
2525
#include <linux/rculist_nulls.h>
2626

27+
static bool enable_hooks __read_mostly;
28+
MODULE_PARM_DESC(enable_hooks, "Always enable conntrack hooks");
29+
module_param(enable_hooks, bool, 0000);
30+
2731
unsigned int nf_conntrack_net_id __read_mostly;
2832

2933
#ifdef CONFIG_NF_CONNTRACK_PROCFS
@@ -1075,6 +1079,15 @@ static void nf_conntrack_standalone_fini_sysctl(struct net *net)
10751079
}
10761080
#endif /* CONFIG_SYSCTL */
10771081

1082+
static void nf_conntrack_fini_net(struct net *net)
1083+
{
1084+
if (enable_hooks)
1085+
nf_ct_netns_put(net, NFPROTO_INET);
1086+
1087+
nf_conntrack_standalone_fini_proc(net);
1088+
nf_conntrack_standalone_fini_sysctl(net);
1089+
}
1090+
10781091
static int nf_conntrack_pernet_init(struct net *net)
10791092
{
10801093
int ret;
@@ -1093,8 +1106,16 @@ static int nf_conntrack_pernet_init(struct net *net)
10931106
if (ret < 0)
10941107
goto out_init_net;
10951108

1109+
if (enable_hooks) {
1110+
ret = nf_ct_netns_get(net, NFPROTO_INET);
1111+
if (ret < 0)
1112+
goto out_hooks;
1113+
}
1114+
10961115
return 0;
10971116

1117+
out_hooks:
1118+
nf_conntrack_fini_net(net);
10981119
out_init_net:
10991120
nf_conntrack_standalone_fini_proc(net);
11001121
out_proc:
@@ -1106,10 +1127,9 @@ static void nf_conntrack_pernet_exit(struct list_head *net_exit_list)
11061127
{
11071128
struct net *net;
11081129

1109-
list_for_each_entry(net, net_exit_list, exit_list) {
1110-
nf_conntrack_standalone_fini_sysctl(net);
1111-
nf_conntrack_standalone_fini_proc(net);
1112-
}
1130+
list_for_each_entry(net, net_exit_list, exit_list)
1131+
nf_conntrack_fini_net(net);
1132+
11131133
nf_conntrack_cleanup_net_list(net_exit_list);
11141134
}
11151135

0 commit comments

Comments
 (0)