Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ebt_redirect |
| 3 | * |
| 4 | * Authors: |
| 5 | * Bart De Schuymer <bdschuym@pandora.be> |
| 6 | * |
| 7 | * April, 2002 |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include <linux/netfilter_bridge/ebtables.h> |
| 12 | #include <linux/netfilter_bridge/ebt_redirect.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <net/sock.h> |
| 15 | #include "../br_private.h" |
| 16 | |
| 17 | static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr, |
| 18 | const struct net_device *in, const struct net_device *out, |
| 19 | const void *data, unsigned int datalen) |
| 20 | { |
| 21 | struct ebt_redirect_info *info = (struct ebt_redirect_info *)data; |
| 22 | |
| 23 | if (skb_shared(*pskb) || skb_cloned(*pskb)) { |
| 24 | struct sk_buff *nskb; |
| 25 | |
| 26 | nskb = skb_copy(*pskb, GFP_ATOMIC); |
| 27 | if (!nskb) |
| 28 | return NF_DROP; |
| 29 | if ((*pskb)->sk) |
| 30 | skb_set_owner_w(nskb, (*pskb)->sk); |
| 31 | kfree_skb(*pskb); |
| 32 | *pskb = nskb; |
| 33 | } |
| 34 | if (hooknr != NF_BR_BROUTING) |
| 35 | memcpy(eth_hdr(*pskb)->h_dest, |
| 36 | in->br_port->br->dev->dev_addr, ETH_ALEN); |
| 37 | else |
| 38 | memcpy(eth_hdr(*pskb)->h_dest, in->dev_addr, ETH_ALEN); |
| 39 | (*pskb)->pkt_type = PACKET_HOST; |
| 40 | return info->target; |
| 41 | } |
| 42 | |
| 43 | static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask, |
| 44 | const struct ebt_entry *e, void *data, unsigned int datalen) |
| 45 | { |
| 46 | struct ebt_redirect_info *info = (struct ebt_redirect_info *)data; |
| 47 | |
| 48 | if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info))) |
| 49 | return -EINVAL; |
| 50 | if (BASE_CHAIN && info->target == EBT_RETURN) |
| 51 | return -EINVAL; |
| 52 | CLEAR_BASE_CHAIN_BIT; |
| 53 | if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) && |
| 54 | (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) ) |
| 55 | return -EINVAL; |
| 56 | if (INVALID_TARGET) |
| 57 | return -EINVAL; |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static struct ebt_target redirect_target = |
| 62 | { |
| 63 | .name = EBT_REDIRECT_TARGET, |
| 64 | .target = ebt_target_redirect, |
| 65 | .check = ebt_target_redirect_check, |
| 66 | .me = THIS_MODULE, |
| 67 | }; |
| 68 | |
| 69 | static int __init init(void) |
| 70 | { |
| 71 | return ebt_register_target(&redirect_target); |
| 72 | } |
| 73 | |
| 74 | static void __exit fini(void) |
| 75 | { |
| 76 | ebt_unregister_target(&redirect_target); |
| 77 | } |
| 78 | |
| 79 | module_init(init); |
| 80 | module_exit(fini); |
| 81 | MODULE_LICENSE("GPL"); |