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.
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
14 #include <linux/netfilter/x_tables.h>
15 #include <linux/netfilter/nfnetlink_acct.h>
16 #include <linux/netfilter/xt_nfacct.h>
19 MODULE_DESCRIPTION("Xtables: match for the extended accounting infrastructure");
20 MODULE_LICENSE("GPL");
21 MODULE_ALIAS("ipt_nfacct");
22 MODULE_ALIAS("ip6t_nfacct");
24 static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
27 const struct xt_nfacct_match_info *info = par->targinfo;
29 nfnl_acct_update(skb, info->nfacct);
31 overquota = nfnl_acct_overquota(xt_net(par), info->nfacct);
33 return overquota == NFACCT_UNDERQUOTA ? false : true;
37 nfacct_mt_checkentry(const struct xt_mtchk_param *par)
39 struct xt_nfacct_match_info *info = par->matchinfo;
40 struct nf_acct *nfacct;
42 nfacct = nfnl_acct_find_get(par->net, info->name);
44 pr_info_ratelimited("accounting object `%s' does not exists\n",
48 info->nfacct = nfacct;
53 nfacct_mt_destroy(const struct xt_mtdtor_param *par)
55 const struct xt_nfacct_match_info *info = par->matchinfo;
57 nfnl_acct_put(info->nfacct);
60 static struct xt_match nfacct_mt_reg __read_mostly = {
62 .family = NFPROTO_UNSPEC,
63 .checkentry = nfacct_mt_checkentry,
65 .destroy = nfacct_mt_destroy,
66 .matchsize = sizeof(struct xt_nfacct_match_info),
67 .usersize = offsetof(struct xt_nfacct_match_info, nfacct),
71 static int __init nfacct_mt_init(void)
73 return xt_register_match(&nfacct_mt_reg);
76 static void __exit nfacct_mt_exit(void)
78 xt_unregister_match(&nfacct_mt_reg);
81 module_init(nfacct_mt_init);
82 module_exit(nfacct_mt_exit);