Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / net / bridge / netfilter / ebt_mark.c
blob36723f47db0a7824bad1a64e47970b8fcd86911f
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/netfilter_bridge/ebtables.h>
17 #include <linux/netfilter_bridge/ebt_mark_t.h>
18 #include <linux/module.h>
20 static int ebt_target_mark(struct sk_buff *skb, unsigned int hooknr,
21 const struct net_device *in, const struct net_device *out,
22 const void *data, unsigned int datalen)
24 const struct ebt_mark_t_info *info = data;
25 int action = info->target & -16;
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;
36 return info->target | ~EBT_VERDICT_BITS;
39 static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
40 const struct ebt_entry *e, void *data, unsigned int datalen)
42 const struct ebt_mark_t_info *info = data;
43 int tmp;
45 if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
46 return -EINVAL;
47 tmp = info->target | ~EBT_VERDICT_BITS;
48 if (BASE_CHAIN && tmp == EBT_RETURN)
49 return -EINVAL;
50 CLEAR_BASE_CHAIN_BIT;
51 if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
52 return -EINVAL;
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 -EINVAL;
57 return 0;
60 static struct ebt_target mark_target __read_mostly = {
61 .name = EBT_MARK_TARGET,
62 .target = ebt_target_mark,
63 .check = ebt_target_mark_check,
64 .me = THIS_MODULE,
67 static int __init ebt_mark_init(void)
69 return ebt_register_target(&mark_target);
72 static void __exit ebt_mark_fini(void)
74 ebt_unregister_target(&mark_target);
77 module_init(ebt_mark_init);
78 module_exit(ebt_mark_fini);
79 MODULE_DESCRIPTION("Ebtables: Packet mark modification");
80 MODULE_LICENSE("GPL");