]>
Commit | Line | Data |
---|---|---|
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 | ||
18219d3f JE |
16 | #include <linux/module.h> |
17 | #include <linux/netfilter/x_tables.h> | |
1da177e4 LT |
18 | #include <linux/netfilter_bridge/ebtables.h> |
19 | #include <linux/netfilter_bridge/ebt_mark_t.h> | |
1da177e4 | 20 | |
2d06d4a5 | 21 | static unsigned int |
4b560b44 | 22 | ebt_mark_tg(struct sk_buff *skb, const struct xt_action_param *par) |
1da177e4 | 23 | { |
7eb35586 | 24 | const struct ebt_mark_t_info *info = par->targinfo; |
b18dfa90 | 25 | int action = info->target & -16; |
1da177e4 | 26 | |
b18dfa90 | 27 | if (action == MARK_SET_VALUE) |
3db05fea | 28 | skb->mark = info->mark; |
b18dfa90 | 29 | else if (action == MARK_OR_VALUE) |
3db05fea | 30 | skb->mark |= info->mark; |
b18dfa90 | 31 | else if (action == MARK_AND_VALUE) |
3db05fea | 32 | skb->mark &= info->mark; |
b18dfa90 | 33 | else |
3db05fea | 34 | skb->mark ^= info->mark; |
6869c4d8 | 35 | |
d12cdc3c | 36 | return info->target | ~EBT_VERDICT_BITS; |
1da177e4 LT |
37 | } |
38 | ||
135367b8 | 39 | static int ebt_mark_tg_check(const struct xt_tgchk_param *par) |
1da177e4 | 40 | { |
af5d6dc2 | 41 | const struct ebt_mark_t_info *info = par->targinfo; |
b18dfa90 | 42 | int tmp; |
1da177e4 | 43 | |
d12cdc3c | 44 | tmp = info->target | ~EBT_VERDICT_BITS; |
b18dfa90 | 45 | if (BASE_CHAIN && tmp == EBT_RETURN) |
d6b00a53 | 46 | return -EINVAL; |
b18dfa90 | 47 | if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0) |
d6b00a53 | 48 | return -EINVAL; |
d12cdc3c | 49 | tmp = info->target & ~EBT_VERDICT_BITS; |
b18dfa90 BDS |
50 | if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE && |
51 | tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE) | |
d6b00a53 JE |
52 | return -EINVAL; |
53 | return 0; | |
1da177e4 | 54 | } |
6e705f56 FW |
55 | #ifdef CONFIG_COMPAT |
56 | struct compat_ebt_mark_t_info { | |
57 | compat_ulong_t mark; | |
58 | compat_uint_t target; | |
59 | }; | |
60 | ||
61 | static void mark_tg_compat_from_user(void *dst, const void *src) | |
62 | { | |
63 | const struct compat_ebt_mark_t_info *user = src; | |
64 | struct ebt_mark_t_info *kern = dst; | |
65 | ||
66 | kern->mark = user->mark; | |
67 | kern->target = user->target; | |
68 | } | |
69 | ||
70 | static int mark_tg_compat_to_user(void __user *dst, const void *src) | |
71 | { | |
72 | struct compat_ebt_mark_t_info __user *user = dst; | |
73 | const struct ebt_mark_t_info *kern = src; | |
74 | ||
75 | if (put_user(kern->mark, &user->mark) || | |
76 | put_user(kern->target, &user->target)) | |
77 | return -EFAULT; | |
78 | return 0; | |
79 | } | |
80 | #endif | |
1da177e4 | 81 | |
043ef46c JE |
82 | static struct xt_target ebt_mark_tg_reg __read_mostly = { |
83 | .name = "mark", | |
001a18d3 JE |
84 | .revision = 0, |
85 | .family = NFPROTO_BRIDGE, | |
2d06d4a5 JE |
86 | .target = ebt_mark_tg, |
87 | .checkentry = ebt_mark_tg_check, | |
fc0e3df4 | 88 | .targetsize = sizeof(struct ebt_mark_t_info), |
6e705f56 FW |
89 | #ifdef CONFIG_COMPAT |
90 | .compatsize = sizeof(struct compat_ebt_mark_t_info), | |
91 | .compat_from_user = mark_tg_compat_from_user, | |
92 | .compat_to_user = mark_tg_compat_to_user, | |
93 | #endif | |
1da177e4 LT |
94 | .me = THIS_MODULE, |
95 | }; | |
96 | ||
65b4b4e8 | 97 | static int __init ebt_mark_init(void) |
1da177e4 | 98 | { |
043ef46c | 99 | return xt_register_target(&ebt_mark_tg_reg); |
1da177e4 LT |
100 | } |
101 | ||
65b4b4e8 | 102 | static void __exit ebt_mark_fini(void) |
1da177e4 | 103 | { |
043ef46c | 104 | xt_unregister_target(&ebt_mark_tg_reg); |
1da177e4 LT |
105 | } |
106 | ||
65b4b4e8 AM |
107 | module_init(ebt_mark_init); |
108 | module_exit(ebt_mark_fini); | |
f776c4cd | 109 | MODULE_DESCRIPTION("Ebtables: Packet mark modification"); |
1da177e4 | 110 | MODULE_LICENSE("GPL"); |