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