6512ad9b40979a442ca312947443c518330d0904
[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 ebt_filter_mark(const struct sk_buff *skb,
16    const struct net_device *in, const struct net_device *out, const void *data,
17    unsigned int datalen)
18 {
19         const struct ebt_mark_m_info *info = data;
20
21         if (info->bitmask & EBT_MARK_OR)
22                 return !!(skb->mark & info->mask) ^ info->invert;
23         return ((skb->mark & info->mask) == info->mark) ^ info->invert;
24 }
25
26 static bool ebt_mark_check(const char *tablename, unsigned int hookmask,
27    const struct ebt_entry *e, void *data, unsigned int datalen)
28 {
29         const struct ebt_mark_m_info *info = data;
30
31         if (info->bitmask & ~EBT_MARK_MASK)
32                 return false;
33         if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
34                 return false;
35         if (!info->bitmask)
36                 return false;
37         return true;
38 }
39
40 static struct ebt_match filter_mark __read_mostly = {
41         .name           = EBT_MARK_MATCH,
42         .revision       = 0,
43         .family         = NFPROTO_BRIDGE,
44         .match          = ebt_filter_mark,
45         .check          = ebt_mark_check,
46         .matchsize      = XT_ALIGN(sizeof(struct ebt_mark_m_info)),
47         .me             = THIS_MODULE,
48 };
49
50 static int __init ebt_mark_m_init(void)
51 {
52         return ebt_register_match(&filter_mark);
53 }
54
55 static void __exit ebt_mark_m_fini(void)
56 {
57         ebt_unregister_match(&filter_mark);
58 }
59
60 module_init(ebt_mark_m_init);
61 module_exit(ebt_mark_m_fini);
62 MODULE_DESCRIPTION("Ebtables: Packet mark match");
63 MODULE_LICENSE("GPL");