Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jan Engelhardt | 18219d3 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/netfilter/x_tables.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/netfilter_bridge/ebtables.h> |
| 19 | #include <linux/netfilter_bridge/ebt_mark_t.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 21 | static unsigned int |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 22 | ebt_mark_tg(struct sk_buff *skb, const struct xt_target_param *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 24 | const struct ebt_mark_t_info *info = par->targinfo; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 25 | int action = info->target & -16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 27 | if (action == MARK_SET_VALUE) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 28 | skb->mark = info->mark; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 29 | else if (action == MARK_OR_VALUE) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 30 | skb->mark |= info->mark; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 31 | else if (action == MARK_AND_VALUE) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 32 | skb->mark &= info->mark; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 33 | else |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 34 | skb->mark ^= info->mark; |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 35 | |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 36 | return info->target | ~EBT_VERDICT_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 39 | static bool ebt_mark_tg_check(const struct xt_tgchk_param *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 41 | const struct ebt_mark_t_info *info = par->targinfo; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 42 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 44 | tmp = info->target | ~EBT_VERDICT_BITS; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 45 | if (BASE_CHAIN && tmp == EBT_RETURN) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 46 | return false; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 47 | if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 48 | return false; |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 49 | tmp = info->target & ~EBT_VERDICT_BITS; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 50 | if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE && |
| 51 | tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 52 | return false; |
| 53 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
Florian Westphal | 6e705f5 | 2010-01-27 14:39:05 +0100 | [diff] [blame^] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Jan Engelhardt | 043ef46 | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 82 | static struct xt_target ebt_mark_tg_reg __read_mostly = { |
| 83 | .name = "mark", |
Jan Engelhardt | 001a18d | 2008-10-08 11:35:14 +0200 | [diff] [blame] | 84 | .revision = 0, |
| 85 | .family = NFPROTO_BRIDGE, |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 86 | .target = ebt_mark_tg, |
| 87 | .checkentry = ebt_mark_tg_check, |
Florian Westphal | fc0e3df | 2010-02-15 18:16:26 +0100 | [diff] [blame] | 88 | .targetsize = sizeof(struct ebt_mark_t_info), |
Florian Westphal | 6e705f5 | 2010-01-27 14:39:05 +0100 | [diff] [blame^] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | .me = THIS_MODULE, |
| 95 | }; |
| 96 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 97 | static int __init ebt_mark_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Jan Engelhardt | 043ef46 | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 99 | return xt_register_target(&ebt_mark_tg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 102 | static void __exit ebt_mark_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Jan Engelhardt | 043ef46 | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 104 | xt_unregister_target(&ebt_mark_tg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 107 | module_init(ebt_mark_init); |
| 108 | module_exit(ebt_mark_fini); |
Jan Engelhardt | f776c4c | 2008-01-31 04:00:30 -0800 | [diff] [blame] | 109 | MODULE_DESCRIPTION("Ebtables: Packet mark modification"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | MODULE_LICENSE("GPL"); |