netfilter: xtables: move extension arguments into compound structure (4/6)
[linux-2.6-microblaze.git] / net / bridge / netfilter / ebt_mark.c
1 /*
2  *  ebt_mark
3  *
4  *      Authors:
5  *      Bart De Schuymer <bdschuym@pandora.be>
6  *
7  *  July, 2002
8  *
9  */
10
11 /* The mark target can be used in any chain,
12  * I believe adding a mangle table just for marking is total overkill.
13  * Marking a frame doesn't really change anything in the frame anyway.
14  */
15
16 #include <linux/module.h>
17 #include <linux/netfilter/x_tables.h>
18 #include <linux/netfilter_bridge/ebtables.h>
19 #include <linux/netfilter_bridge/ebt_mark_t.h>
20
21 static unsigned int
22 ebt_mark_tg(struct sk_buff *skb, const struct xt_target_param *par)
23 {
24         const struct ebt_mark_t_info *info = par->targinfo;
25         int action = info->target & -16;
26
27         if (action == MARK_SET_VALUE)
28                 skb->mark = info->mark;
29         else if (action == MARK_OR_VALUE)
30                 skb->mark |= info->mark;
31         else if (action == MARK_AND_VALUE)
32                 skb->mark &= info->mark;
33         else
34                 skb->mark ^= info->mark;
35
36         return info->target | ~EBT_VERDICT_BITS;
37 }
38
39 static bool
40 ebt_mark_tg_check(const char *table, const void *e,
41                   const struct xt_target *target, void *data,
42                   unsigned int hookmask)
43 {
44         const struct ebt_mark_t_info *info = data;
45         int tmp;
46
47         tmp = info->target | ~EBT_VERDICT_BITS;
48         if (BASE_CHAIN && tmp == EBT_RETURN)
49                 return false;
50         CLEAR_BASE_CHAIN_BIT;
51         if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
52                 return false;
53         tmp = info->target & ~EBT_VERDICT_BITS;
54         if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
55             tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
56                 return false;
57         return true;
58 }
59
60 static struct xt_target ebt_mark_tg_reg __read_mostly = {
61         .name           = "mark",
62         .revision       = 0,
63         .family         = NFPROTO_BRIDGE,
64         .target         = ebt_mark_tg,
65         .checkentry     = ebt_mark_tg_check,
66         .targetsize     = XT_ALIGN(sizeof(struct ebt_mark_t_info)),
67         .me             = THIS_MODULE,
68 };
69
70 static int __init ebt_mark_init(void)
71 {
72         return xt_register_target(&ebt_mark_tg_reg);
73 }
74
75 static void __exit ebt_mark_fini(void)
76 {
77         xt_unregister_target(&ebt_mark_tg_reg);
78 }
79
80 module_init(ebt_mark_init);
81 module_exit(ebt_mark_fini);
82 MODULE_DESCRIPTION("Ebtables: Packet mark modification");
83 MODULE_LICENSE("GPL");