netfilter: xtables: do centralized checkentry call (1/2)
[safe/jmp/linux-2.6] / net / bridge / netfilter / ebt_mark_m.c
1 /*
2  *  ebt_mark_m
3  *
4  *      Authors:
5  *      Bart De Schuymer <bdschuym@pandora.be>
6  *
7  *  July, 2002
8  *
9  */
10 #include <linux/module.h>
11 #include <linux/netfilter/x_tables.h>
12 #include <linux/netfilter_bridge/ebtables.h>
13 #include <linux/netfilter_bridge/ebt_mark_m.h>
14
15 static bool
16 ebt_mark_mt(const struct sk_buff *skb, const struct net_device *in,
17             const struct net_device *out, const struct xt_match *match,
18             const void *data, int offset, unsigned int protoff, bool *hotdrop)
19 {
20         const struct ebt_mark_m_info *info = data;
21
22         if (info->bitmask & EBT_MARK_OR)
23                 return !!(skb->mark & info->mask) ^ info->invert;
24         return ((skb->mark & info->mask) == info->mark) ^ info->invert;
25 }
26
27 static bool
28 ebt_mark_mt_check(const char *table, const void *e,
29                   const struct xt_match *match, void *data,
30                   unsigned int hook_mask)
31 {
32         const struct ebt_mark_m_info *info = data;
33
34         if (info->bitmask & ~EBT_MARK_MASK)
35                 return false;
36         if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
37                 return false;
38         if (!info->bitmask)
39                 return false;
40         return true;
41 }
42
43 static struct xt_match ebt_mark_mt_reg __read_mostly = {
44         .name           = "mark_m",
45         .revision       = 0,
46         .family         = NFPROTO_BRIDGE,
47         .match          = ebt_mark_mt,
48         .checkentry     = ebt_mark_mt_check,
49         .matchsize      = XT_ALIGN(sizeof(struct ebt_mark_m_info)),
50         .me             = THIS_MODULE,
51 };
52
53 static int __init ebt_mark_m_init(void)
54 {
55         return xt_register_match(&ebt_mark_mt_reg);
56 }
57
58 static void __exit ebt_mark_m_fini(void)
59 {
60         xt_unregister_match(&ebt_mark_mt_reg);
61 }
62
63 module_init(ebt_mark_m_init);
64 module_exit(ebt_mark_m_fini);
65 MODULE_DESCRIPTION("Ebtables: Packet mark match");
66 MODULE_LICENSE("GPL");