netfilter: move Ebtables to use Xtables
[linux-2.6/kvm.git] / net / bridge / netfilter / ebt_mark.c
blobdff19fc91cf50d0dd914a629d9e67d43bd0b320b
1 /*
2 * ebt_mark
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
7 * July, 2002
9 */
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.
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>
21 static unsigned int
22 ebt_mark_tg(struct sk_buff *skb, const struct net_device *in,
23 const struct net_device *out, unsigned int hook_nr,
24 const struct xt_target *target, const void *data)
26 const struct ebt_mark_t_info *info = data;
27 int action = info->target & -16;
29 if (action == MARK_SET_VALUE)
30 skb->mark = info->mark;
31 else if (action == MARK_OR_VALUE)
32 skb->mark |= info->mark;
33 else if (action == MARK_AND_VALUE)
34 skb->mark &= info->mark;
35 else
36 skb->mark ^= info->mark;
38 return info->target | ~EBT_VERDICT_BITS;
41 static bool
42 ebt_mark_tg_check(const char *table, const void *e,
43 const struct xt_target *target, void *data,
44 unsigned int hookmask)
46 const struct ebt_mark_t_info *info = data;
47 int tmp;
49 tmp = info->target | ~EBT_VERDICT_BITS;
50 if (BASE_CHAIN && tmp == EBT_RETURN)
51 return false;
52 CLEAR_BASE_CHAIN_BIT;
53 if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
54 return false;
55 tmp = info->target & ~EBT_VERDICT_BITS;
56 if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
57 tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
58 return false;
59 return true;
62 static struct xt_target ebt_mark_tg_reg __read_mostly = {
63 .name = "mark",
64 .revision = 0,
65 .family = NFPROTO_BRIDGE,
66 .target = ebt_mark_tg,
67 .checkentry = ebt_mark_tg_check,
68 .targetsize = XT_ALIGN(sizeof(struct ebt_mark_t_info)),
69 .me = THIS_MODULE,
72 static int __init ebt_mark_init(void)
74 return xt_register_target(&ebt_mark_tg_reg);
77 static void __exit ebt_mark_fini(void)
79 xt_unregister_target(&ebt_mark_tg_reg);
82 module_init(ebt_mark_init);
83 module_exit(ebt_mark_fini);
84 MODULE_DESCRIPTION("Ebtables: Packet mark modification");
85 MODULE_LICENSE("GPL");