~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to net/netfilter/xt_quota.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Sam Johnston <samj@samj.net>
5
5
 */
6
6
#include <linux/skbuff.h>
 
7
#include <linux/slab.h>
7
8
#include <linux/spinlock.h>
8
9
 
9
10
#include <linux/netfilter/x_tables.h>
10
11
#include <linux/netfilter/xt_quota.h>
11
12
 
12
13
struct xt_quota_priv {
13
 
        uint64_t quota;
 
14
        spinlock_t      lock;
 
15
        uint64_t        quota;
14
16
};
15
17
 
16
18
MODULE_LICENSE("GPL");
19
21
MODULE_ALIAS("ipt_quota");
20
22
MODULE_ALIAS("ip6t_quota");
21
23
 
22
 
static DEFINE_SPINLOCK(quota_lock);
23
 
 
24
24
static bool
25
 
quota_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 
25
quota_mt(const struct sk_buff *skb, struct xt_action_param *par)
26
26
{
27
27
        struct xt_quota_info *q = (void *)par->matchinfo;
28
28
        struct xt_quota_priv *priv = q->master;
29
29
        bool ret = q->flags & XT_QUOTA_INVERT;
30
30
 
31
 
        spin_lock_bh(&quota_lock);
 
31
        spin_lock_bh(&priv->lock);
32
32
        if (priv->quota >= skb->len) {
33
33
                priv->quota -= skb->len;
34
34
                ret = !ret;
36
36
                /* we do not allow even small packets from now on */
37
37
                priv->quota = 0;
38
38
        }
39
 
        /* Copy quota back to matchinfo so that iptables can display it */
40
 
        q->quota = priv->quota;
41
 
        spin_unlock_bh(&quota_lock);
 
39
        spin_unlock_bh(&priv->lock);
42
40
 
43
41
        return ret;
44
42
}
45
43
 
46
 
static bool quota_mt_check(const struct xt_mtchk_param *par)
 
44
static int quota_mt_check(const struct xt_mtchk_param *par)
47
45
{
48
46
        struct xt_quota_info *q = par->matchinfo;
49
47
 
50
48
        if (q->flags & ~XT_QUOTA_MASK)
51
 
                return false;
 
49
                return -EINVAL;
52
50
 
53
51
        q->master = kmalloc(sizeof(*q->master), GFP_KERNEL);
54
52
        if (q->master == NULL)
55
 
                return false;
 
53
                return -ENOMEM;
56
54
 
 
55
        spin_lock_init(&q->master->lock);
57
56
        q->master->quota = q->quota;
58
 
        return true;
 
57
        return 0;
59
58
}
60
59
 
61
60
static void quota_mt_destroy(const struct xt_mtdtor_param *par)