dm thin: wake worker when discard is prepared
[linux-2.6.git] / net / netfilter / nf_conntrack_acct.c
blobd61e0782a797db1d4f4548ef583108f08272b6f4
1 /* Accouting handling for netfilter. */
3 /*
4 * (C) 2008 Krzysztof Piotr Oledzki <ole@ans.pl>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #include <linux/netfilter.h>
12 #include <linux/slab.h>
13 #include <linux/kernel.h>
14 #include <linux/moduleparam.h>
15 #include <linux/export.h>
17 #include <net/netfilter/nf_conntrack.h>
18 #include <net/netfilter/nf_conntrack_extend.h>
19 #include <net/netfilter/nf_conntrack_acct.h>
21 static bool nf_ct_acct __read_mostly;
23 module_param_named(acct, nf_ct_acct, bool, 0644);
24 MODULE_PARM_DESC(acct, "Enable connection tracking flow accounting.");
26 #ifdef CONFIG_SYSCTL
27 static struct ctl_table acct_sysctl_table[] = {
29 .procname = "nf_conntrack_acct",
30 .data = &init_net.ct.sysctl_acct,
31 .maxlen = sizeof(unsigned int),
32 .mode = 0644,
33 .proc_handler = proc_dointvec,
37 #endif /* CONFIG_SYSCTL */
39 unsigned int
40 seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir)
42 struct nf_conn_counter *acct;
44 acct = nf_conn_acct_find(ct);
45 if (!acct)
46 return 0;
48 return seq_printf(s, "packets=%llu bytes=%llu ",
49 (unsigned long long)atomic64_read(&acct[dir].packets),
50 (unsigned long long)atomic64_read(&acct[dir].bytes));
52 EXPORT_SYMBOL_GPL(seq_print_acct);
54 static struct nf_ct_ext_type acct_extend __read_mostly = {
55 .len = sizeof(struct nf_conn_counter[IP_CT_DIR_MAX]),
56 .align = __alignof__(struct nf_conn_counter[IP_CT_DIR_MAX]),
57 .id = NF_CT_EXT_ACCT,
60 #ifdef CONFIG_SYSCTL
61 static int nf_conntrack_acct_init_sysctl(struct net *net)
63 struct ctl_table *table;
65 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
66 GFP_KERNEL);
67 if (!table)
68 goto out;
70 table[0].data = &net->ct.sysctl_acct;
72 net->ct.acct_sysctl_header = register_net_sysctl(net, "net/netfilter",
73 table);
74 if (!net->ct.acct_sysctl_header) {
75 printk(KERN_ERR "nf_conntrack_acct: can't register to sysctl.\n");
76 goto out_register;
78 return 0;
80 out_register:
81 kfree(table);
82 out:
83 return -ENOMEM;
86 static void nf_conntrack_acct_fini_sysctl(struct net *net)
88 struct ctl_table *table;
90 table = net->ct.acct_sysctl_header->ctl_table_arg;
91 unregister_net_sysctl_table(net->ct.acct_sysctl_header);
92 kfree(table);
94 #else
95 static int nf_conntrack_acct_init_sysctl(struct net *net)
97 return 0;
100 static void nf_conntrack_acct_fini_sysctl(struct net *net)
103 #endif
105 int nf_conntrack_acct_init(struct net *net)
107 int ret;
109 net->ct.sysctl_acct = nf_ct_acct;
111 if (net_eq(net, &init_net)) {
112 ret = nf_ct_extend_register(&acct_extend);
113 if (ret < 0) {
114 printk(KERN_ERR "nf_conntrack_acct: Unable to register extension\n");
115 goto out_extend_register;
119 ret = nf_conntrack_acct_init_sysctl(net);
120 if (ret < 0)
121 goto out_sysctl;
123 return 0;
125 out_sysctl:
126 if (net_eq(net, &init_net))
127 nf_ct_extend_unregister(&acct_extend);
128 out_extend_register:
129 return ret;
132 void nf_conntrack_acct_fini(struct net *net)
134 nf_conntrack_acct_fini_sysctl(net);
135 if (net_eq(net, &init_net))
136 nf_ct_extend_unregister(&acct_extend);