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 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 21 | static int ebt_target_mark(struct sk_buff *skb, unsigned int hooknr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | const struct net_device *in, const struct net_device *out, |
| 23 | const void *data, unsigned int datalen) |
| 24 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 25 | const struct ebt_mark_t_info *info = data; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 26 | int action = info->target & -16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 28 | if (action == MARK_SET_VALUE) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 29 | skb->mark = info->mark; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 30 | else if (action == MARK_OR_VALUE) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 31 | skb->mark |= info->mark; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 32 | else if (action == MARK_AND_VALUE) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 33 | skb->mark &= info->mark; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 34 | else |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 35 | skb->mark ^= info->mark; |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 36 | |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 37 | return info->target | ~EBT_VERDICT_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static int ebt_target_mark_check(const char *tablename, unsigned int hookmask, |
| 41 | const struct ebt_entry *e, void *data, unsigned int datalen) |
| 42 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 43 | const struct ebt_mark_t_info *info = data; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 44 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 46 | tmp = info->target | ~EBT_VERDICT_BITS; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 47 | if (BASE_CHAIN && tmp == EBT_RETURN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | return -EINVAL; |
| 49 | CLEAR_BASE_CHAIN_BIT; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 50 | if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0) |
| 51 | return -EINVAL; |
Bart De Schuymer | d12cdc3 | 2006-11-29 02:35:40 +0100 | [diff] [blame] | 52 | tmp = info->target & ~EBT_VERDICT_BITS; |
Bart De Schuymer | b18dfa9 | 2006-10-02 16:12:52 -0700 | [diff] [blame] | 53 | if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE && |
| 54 | tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | return -EINVAL; |
| 56 | return 0; |
| 57 | } |
| 58 | |
Jan Engelhardt | 30083c9 | 2008-01-31 04:00:59 -0800 | [diff] [blame] | 59 | static struct ebt_target mark_target __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .name = EBT_MARK_TARGET, |
| 61 | .target = ebt_target_mark, |
| 62 | .check = ebt_target_mark_check, |
Jan Engelhardt | 18219d3 | 2008-10-08 11:35:13 +0200 | [diff] [blame^] | 63 | .targetsize = XT_ALIGN(sizeof(struct ebt_mark_t_info)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | .me = THIS_MODULE, |
| 65 | }; |
| 66 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 67 | static int __init ebt_mark_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
| 69 | return ebt_register_target(&mark_target); |
| 70 | } |
| 71 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 72 | static void __exit ebt_mark_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | ebt_unregister_target(&mark_target); |
| 75 | } |
| 76 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 77 | module_init(ebt_mark_init); |
| 78 | module_exit(ebt_mark_fini); |
Jan Engelhardt | f776c4c | 2008-01-31 04:00:30 -0800 | [diff] [blame] | 79 | MODULE_DESCRIPTION("Ebtables: Packet mark modification"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | MODULE_LICENSE("GPL"); |