Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfashe...
[linux-2.6-block.git] / net / bridge / netfilter / ebt_mark.c
CommitLineData
1da177e4
LT
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/netfilter_bridge/ebtables.h>
17#include <linux/netfilter_bridge/ebt_mark_t.h>
18#include <linux/module.h>
19
20static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
21 const struct net_device *in, const struct net_device *out,
22 const void *data, unsigned int datalen)
23{
24 struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
b18dfa90 25 int action = info->target & -16;
1da177e4 26
b18dfa90 27 if (action == MARK_SET_VALUE)
82e91ffe 28 (*pskb)->mark = info->mark;
b18dfa90 29 else if (action == MARK_OR_VALUE)
82e91ffe 30 (*pskb)->mark |= info->mark;
b18dfa90 31 else if (action == MARK_AND_VALUE)
82e91ffe 32 (*pskb)->mark &= info->mark;
b18dfa90 33 else
82e91ffe 34 (*pskb)->mark ^= info->mark;
6869c4d8 35
d12cdc3c 36 return info->target | ~EBT_VERDICT_BITS;
1da177e4
LT
37}
38
39static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
40 const struct ebt_entry *e, void *data, unsigned int datalen)
41{
42 struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
b18dfa90 43 int tmp;
1da177e4
LT
44
45 if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
46 return -EINVAL;
d12cdc3c 47 tmp = info->target | ~EBT_VERDICT_BITS;
b18dfa90 48 if (BASE_CHAIN && tmp == EBT_RETURN)
1da177e4
LT
49 return -EINVAL;
50 CLEAR_BASE_CHAIN_BIT;
b18dfa90
BDS
51 if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
52 return -EINVAL;
d12cdc3c 53 tmp = info->target & ~EBT_VERDICT_BITS;
b18dfa90
BDS
54 if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
55 tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
1da177e4
LT
56 return -EINVAL;
57 return 0;
58}
59
60static struct ebt_target mark_target =
61{
62 .name = EBT_MARK_TARGET,
63 .target = ebt_target_mark,
64 .check = ebt_target_mark_check,
65 .me = THIS_MODULE,
66};
67
65b4b4e8 68static int __init ebt_mark_init(void)
1da177e4
LT
69{
70 return ebt_register_target(&mark_target);
71}
72
65b4b4e8 73static void __exit ebt_mark_fini(void)
1da177e4
LT
74{
75 ebt_unregister_target(&mark_target);
76}
77
65b4b4e8
AM
78module_init(ebt_mark_init);
79module_exit(ebt_mark_fini);
1da177e4 80MODULE_LICENSE("GPL");