Linux 3.12.28
[linux/fpc-iii.git] / net / netfilter / xt_nfacct.c
blobb3be0ef21f198ca8c7b025e1a775af9bd662d20e
1 /*
2 * (C) 2011 Pablo Neira Ayuso <pablo@netfilter.org>
3 * (C) 2011 Intra2net AG <http://www.intra2net.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 (or any
7 * later at your option) as published by the Free Software Foundation.
8 */
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
12 #include <linux/netfilter/x_tables.h>
13 #include <linux/netfilter/nfnetlink_acct.h>
14 #include <linux/netfilter/xt_nfacct.h>
16 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
17 MODULE_DESCRIPTION("Xtables: match for the extended accounting infrastructure");
18 MODULE_LICENSE("GPL");
19 MODULE_ALIAS("ipt_nfacct");
20 MODULE_ALIAS("ip6t_nfacct");
22 static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
24 const struct xt_nfacct_match_info *info = par->targinfo;
26 nfnl_acct_update(skb, info->nfacct);
28 return true;
31 static int
32 nfacct_mt_checkentry(const struct xt_mtchk_param *par)
34 struct xt_nfacct_match_info *info = par->matchinfo;
35 struct nf_acct *nfacct;
37 nfacct = nfnl_acct_find_get(info->name);
38 if (nfacct == NULL) {
39 pr_info("xt_nfacct: accounting object with name `%s' "
40 "does not exists\n", info->name);
41 return -ENOENT;
43 info->nfacct = nfacct;
44 return 0;
47 static void
48 nfacct_mt_destroy(const struct xt_mtdtor_param *par)
50 const struct xt_nfacct_match_info *info = par->matchinfo;
52 nfnl_acct_put(info->nfacct);
55 static struct xt_match nfacct_mt_reg __read_mostly = {
56 .name = "nfacct",
57 .family = NFPROTO_UNSPEC,
58 .checkentry = nfacct_mt_checkentry,
59 .match = nfacct_mt,
60 .destroy = nfacct_mt_destroy,
61 .matchsize = sizeof(struct xt_nfacct_match_info),
62 .me = THIS_MODULE,
65 static int __init nfacct_mt_init(void)
67 return xt_register_match(&nfacct_mt_reg);
70 static void __exit nfacct_mt_exit(void)
72 xt_unregister_match(&nfacct_mt_reg);
75 module_init(nfacct_mt_init);
76 module_exit(nfacct_mt_exit);