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 | |
| 20 | static 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; |
| 25 | |
| 26 | if ((*pskb)->nfmark != info->mark) { |
| 27 | (*pskb)->nfmark = info->mark; |
| 28 | (*pskb)->nfcache |= NFC_ALTERED; |
| 29 | } |
| 30 | return info->target; |
| 31 | } |
| 32 | |
| 33 | static int ebt_target_mark_check(const char *tablename, unsigned int hookmask, |
| 34 | const struct ebt_entry *e, void *data, unsigned int datalen) |
| 35 | { |
| 36 | struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data; |
| 37 | |
| 38 | if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info))) |
| 39 | return -EINVAL; |
| 40 | if (BASE_CHAIN && info->target == EBT_RETURN) |
| 41 | return -EINVAL; |
| 42 | CLEAR_BASE_CHAIN_BIT; |
| 43 | if (INVALID_TARGET) |
| 44 | return -EINVAL; |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static struct ebt_target mark_target = |
| 49 | { |
| 50 | .name = EBT_MARK_TARGET, |
| 51 | .target = ebt_target_mark, |
| 52 | .check = ebt_target_mark_check, |
| 53 | .me = THIS_MODULE, |
| 54 | }; |
| 55 | |
| 56 | static int __init init(void) |
| 57 | { |
| 58 | return ebt_register_target(&mark_target); |
| 59 | } |
| 60 | |
| 61 | static void __exit fini(void) |
| 62 | { |
| 63 | ebt_unregister_target(&mark_target); |
| 64 | } |
| 65 | |
| 66 | module_init(init); |
| 67 | module_exit(fini); |
| 68 | MODULE_LICENSE("GPL"); |