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 | */ | |
1da177e4 LT |
10 | #include <linux/module.h> |
11 | #include <net/sock.h> | |
12 | #include "../br_private.h" | |
18219d3f JE |
13 | #include <linux/netfilter.h> |
14 | #include <linux/netfilter/x_tables.h> | |
15 | #include <linux/netfilter_bridge/ebtables.h> | |
16 | #include <linux/netfilter_bridge/ebt_redirect.h> | |
1da177e4 | 17 | |
0ac6ab1f JE |
18 | static unsigned int ebt_target_redirect(struct sk_buff *skb, |
19 | unsigned int hooknr, | |
1da177e4 LT |
20 | const struct net_device *in, const struct net_device *out, |
21 | const void *data, unsigned int datalen) | |
22 | { | |
abfdf1c4 | 23 | const struct ebt_redirect_info *info = data; |
1da177e4 | 24 | |
eb1197bc | 25 | if (!skb_make_writable(skb, 0)) |
1b04ab45 | 26 | return EBT_DROP; |
1da177e4 | 27 | |
1da177e4 | 28 | if (hooknr != NF_BR_BROUTING) |
3db05fea | 29 | memcpy(eth_hdr(skb)->h_dest, |
1da177e4 LT |
30 | in->br_port->br->dev->dev_addr, ETH_ALEN); |
31 | else | |
3db05fea HX |
32 | memcpy(eth_hdr(skb)->h_dest, in->dev_addr, ETH_ALEN); |
33 | skb->pkt_type = PACKET_HOST; | |
1da177e4 LT |
34 | return info->target; |
35 | } | |
36 | ||
19eda879 | 37 | static bool ebt_target_redirect_check(const char *tablename, unsigned int hookmask, |
1da177e4 LT |
38 | const struct ebt_entry *e, void *data, unsigned int datalen) |
39 | { | |
abfdf1c4 | 40 | const struct ebt_redirect_info *info = data; |
1da177e4 | 41 | |
1da177e4 | 42 | if (BASE_CHAIN && info->target == EBT_RETURN) |
19eda879 | 43 | return false; |
1da177e4 LT |
44 | CLEAR_BASE_CHAIN_BIT; |
45 | if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) && | |
46 | (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) ) | |
19eda879 | 47 | return false; |
1da177e4 | 48 | if (INVALID_TARGET) |
19eda879 JE |
49 | return false; |
50 | return true; | |
1da177e4 LT |
51 | } |
52 | ||
30083c95 | 53 | static struct ebt_target redirect_target __read_mostly = { |
1da177e4 | 54 | .name = EBT_REDIRECT_TARGET, |
001a18d3 JE |
55 | .revision = 0, |
56 | .family = NFPROTO_BRIDGE, | |
1da177e4 LT |
57 | .target = ebt_target_redirect, |
58 | .check = ebt_target_redirect_check, | |
18219d3f | 59 | .targetsize = XT_ALIGN(sizeof(struct ebt_redirect_info)), |
1da177e4 LT |
60 | .me = THIS_MODULE, |
61 | }; | |
62 | ||
65b4b4e8 | 63 | static int __init ebt_redirect_init(void) |
1da177e4 LT |
64 | { |
65 | return ebt_register_target(&redirect_target); | |
66 | } | |
67 | ||
65b4b4e8 | 68 | static void __exit ebt_redirect_fini(void) |
1da177e4 LT |
69 | { |
70 | ebt_unregister_target(&redirect_target); | |
71 | } | |
72 | ||
65b4b4e8 AM |
73 | module_init(ebt_redirect_init); |
74 | module_exit(ebt_redirect_fini); | |
f776c4cd | 75 | MODULE_DESCRIPTION("Ebtables: Packet redirection to localhost"); |
1da177e4 | 76 | MODULE_LICENSE("GPL"); |