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 | |
| 16 | #include <linux/netfilter_bridge/ebtables.h> |
| 17 | #include <linux/netfilter_bridge/ebt_mark_t.h> |
| 18 | #include <linux/module.h> |
| 19 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 20 | static int ebt_target_mark(struct sk_buff *skb, unsigned int hooknr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | const struct net_device *in, const struct net_device *out, |
| 22 | const void *data, unsigned int datalen) |
| 23 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 24 | const struct ebt_mark_t_info *info = data; |
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 | |
| 39 | static int ebt_target_mark_check(const char *tablename, unsigned int hookmask, |
| 40 | const struct ebt_entry *e, void *data, unsigned int datalen) |
| 41 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 42 | const struct ebt_mark_t_info *info = data; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 43 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info))) |
| 46 | return -EINVAL; |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 47 | tmp = info->target | ~EBT_VERDICT_BITS; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 48 | if (BASE_CHAIN && tmp == EBT_RETURN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | return -EINVAL; |
| 50 | CLEAR_BASE_CHAIN_BIT; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 51 | if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0) |
| 52 | return -EINVAL; |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 53 | tmp = info->target & ~EBT_VERDICT_BITS; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 54 | if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE && |
| 55 | tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | return -EINVAL; |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static 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 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 68 | static int __init ebt_mark_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | return ebt_register_target(&mark_target); |
| 71 | } |
| 72 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 73 | static void __exit ebt_mark_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | ebt_unregister_target(&mark_target); |
| 76 | } |
| 77 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 78 | module_init(ebt_mark_init); |
| 79 | module_exit(ebt_mark_fini); |
Jan Engelhardt | f776c4c | 2008-01-31 04:00:30 -0800 | [diff] [blame^] | 80 | MODULE_DESCRIPTION("Ebtables: Packet mark modification"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | MODULE_LICENSE("GPL"); |