Blame view
net/netfilter/nf_conntrack_acct.c
3.07 KB
584015727 netfilter: accoun... |
1 2 3 4 5 6 7 8 9 10 11 |
/* Accouting handling for netfilter. */ /* * (C) 2008 Krzysztof Piotr Oledzki <ole@ans.pl> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/netfilter.h> |
5a0e3ad6a include cleanup: ... |
12 |
#include <linux/slab.h> |
584015727 netfilter: accoun... |
13 14 |
#include <linux/kernel.h> #include <linux/moduleparam.h> |
bc3b2d7fb net: Add export.h... |
15 |
#include <linux/export.h> |
584015727 netfilter: accoun... |
16 17 18 19 |
#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_extend.h> #include <net/netfilter/nf_conntrack_acct.h> |
eb9399220 module_param: mak... |
20 |
static bool nf_ct_acct __read_mostly; |
584015727 netfilter: accoun... |
21 22 23 24 25 |
module_param_named(acct, nf_ct_acct, bool, 0644); MODULE_PARM_DESC(acct, "Enable connection tracking flow accounting."); #ifdef CONFIG_SYSCTL |
584015727 netfilter: accoun... |
26 27 |
static struct ctl_table acct_sysctl_table[] = { { |
584015727 netfilter: accoun... |
28 |
.procname = "nf_conntrack_acct", |
d716a4dfb netfilter: netns ... |
29 |
.data = &init_net.ct.sysctl_acct, |
584015727 netfilter: accoun... |
30 31 |
.maxlen = sizeof(unsigned int), .mode = 0644, |
6d9f239a1 net: '&' redux |
32 |
.proc_handler = proc_dointvec, |
584015727 netfilter: accoun... |
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
}, {} }; #endif /* CONFIG_SYSCTL */ unsigned int seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir) { struct nf_conn_counter *acct; acct = nf_conn_acct_find(ct); if (!acct) return 0; return seq_printf(s, "packets=%llu bytes=%llu ", |
b3e0bfa71 netfilter: nf_con... |
48 49 |
(unsigned long long)atomic64_read(&acct[dir].packets), (unsigned long long)atomic64_read(&acct[dir].bytes)); |
584015727 netfilter: accoun... |
50 51 52 53 54 55 56 57 |
}; EXPORT_SYMBOL_GPL(seq_print_acct); static struct nf_ct_ext_type acct_extend __read_mostly = { .len = sizeof(struct nf_conn_counter[IP_CT_DIR_MAX]), .align = __alignof__(struct nf_conn_counter[IP_CT_DIR_MAX]), .id = NF_CT_EXT_ACCT, }; |
d716a4dfb netfilter: netns ... |
58 59 |
#ifdef CONFIG_SYSCTL static int nf_conntrack_acct_init_sysctl(struct net *net) |
584015727 netfilter: accoun... |
60 |
{ |
d716a4dfb netfilter: netns ... |
61 |
struct ctl_table *table; |
584015727 netfilter: accoun... |
62 |
|
d716a4dfb netfilter: netns ... |
63 64 65 66 67 68 |
table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table), GFP_KERNEL); if (!table) goto out; table[0].data = &net->ct.sysctl_acct; |
584015727 netfilter: accoun... |
69 |
|
d716a4dfb netfilter: netns ... |
70 71 72 73 74 75 |
net->ct.acct_sysctl_header = register_net_sysctl_table(net, nf_net_netfilter_sysctl_path, table); if (!net->ct.acct_sysctl_header) { printk(KERN_ERR "nf_conntrack_acct: can't register to sysctl. "); goto out_register; |
584015727 netfilter: accoun... |
76 |
} |
d716a4dfb netfilter: netns ... |
77 |
return 0; |
584015727 netfilter: accoun... |
78 |
|
d716a4dfb netfilter: netns ... |
79 80 81 82 83 |
out_register: kfree(table); out: return -ENOMEM; } |
584015727 netfilter: accoun... |
84 |
|
d716a4dfb netfilter: netns ... |
85 86 87 |
static void nf_conntrack_acct_fini_sysctl(struct net *net) { struct ctl_table *table; |
584015727 netfilter: accoun... |
88 |
|
d716a4dfb netfilter: netns ... |
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
table = net->ct.acct_sysctl_header->ctl_table_arg; unregister_net_sysctl_table(net->ct.acct_sysctl_header); kfree(table); } #else static int nf_conntrack_acct_init_sysctl(struct net *net) { return 0; } static void nf_conntrack_acct_fini_sysctl(struct net *net) { } #endif int nf_conntrack_acct_init(struct net *net) { int ret; net->ct.sysctl_acct = nf_ct_acct; if (net_eq(net, &init_net)) { |
d716a4dfb netfilter: netns ... |
111 112 113 114 115 116 117 118 119 120 121 |
ret = nf_ct_extend_register(&acct_extend); if (ret < 0) { printk(KERN_ERR "nf_conntrack_acct: Unable to register extension "); goto out_extend_register; } } ret = nf_conntrack_acct_init_sysctl(net); if (ret < 0) goto out_sysctl; |
584015727 netfilter: accoun... |
122 |
return 0; |
d716a4dfb netfilter: netns ... |
123 124 125 126 127 128 |
out_sysctl: if (net_eq(net, &init_net)) nf_ct_extend_unregister(&acct_extend); out_extend_register: return ret; |
584015727 netfilter: accoun... |
129 |
} |
d716a4dfb netfilter: netns ... |
130 |
void nf_conntrack_acct_fini(struct net *net) |
584015727 netfilter: accoun... |
131 |
{ |
d716a4dfb netfilter: netns ... |
132 133 134 |
nf_conntrack_acct_fini_sysctl(net); if (net_eq(net, &init_net)) nf_ct_extend_unregister(&acct_extend); |
584015727 netfilter: accoun... |
135 |
} |