netfilter: xt_connbytes: Force CT accounting to be enabled
authorTim Gardner <tim.gardner@canonical.com>
Fri, 25 Jun 2010 12:44:07 +0000 (14:44 +0200)
committerPatrick McHardy <kaber@trash.net>
Fri, 25 Jun 2010 12:44:07 +0000 (14:44 +0200)
Check at rule install time that CT accounting is enabled. Force it
to be enabled if not while also emitting a warning since this is not
the default state.

This is in preparation for deprecating CONFIG_NF_CT_ACCT upon which
CONFIG_NETFILTER_XT_MATCH_CONNBYTES depended being set.

Added 2 CT accounting support functions:

nf_ct_acct_enabled() - Get CT accounting state.
nf_ct_set_acct() - Enable/disable CT accountuing.

Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Acked-by: Jan Engelhardt <jengelh@medozas.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>
include/net/netfilter/nf_conntrack_acct.h
net/netfilter/xt_connbytes.c

index 03e218f0be43a66ad65f82d244e1ff7db5391e78..4e9c63a20db22dd498933745ed9cf2627e74fd47 100644 (file)
@@ -45,6 +45,18 @@ struct nf_conn_counter *nf_ct_acct_ext_add(struct nf_conn *ct, gfp_t gfp)
 extern unsigned int
 seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir);
 
+/* Check if connection tracking accounting is enabled */
+static inline bool nf_ct_acct_enabled(struct net *net)
+{
+       return net->ct.sysctl_acct != 0;
+}
+
+/* Enable/disable connection tracking accounting */
+static inline void nf_ct_set_acct(struct net *net, bool enable)
+{
+       net->ct.sysctl_acct = enable;
+}
+
 extern int nf_conntrack_acct_init(struct net *net);
 extern void nf_conntrack_acct_fini(struct net *net);
 
index 73517835303d4fa68b2b34247d3907e2a7f4c3ca..5b138506690ec578105911ffb64309b5297d6458 100644 (file)
@@ -112,6 +112,16 @@ static int connbytes_mt_check(const struct xt_mtchk_param *par)
        if (ret < 0)
                pr_info("cannot load conntrack support for proto=%u\n",
                        par->family);
+
+       /*
+        * This filter cannot function correctly unless connection tracking
+        * accounting is enabled, so complain in the hope that someone notices.
+        */
+       if (!nf_ct_acct_enabled(par->net)) {
+               pr_warning("Forcing CT accounting to be enabled\n");
+               nf_ct_set_acct(par->net, true);
+       }
+
        return ret;
 }