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 | |
2d06d4a5 JE |
18 | static unsigned int |
19 | ebt_redirect_tg(struct sk_buff *skb, const struct net_device *in, | |
20 | const struct net_device *out, unsigned int hooknr, | |
21 | const struct xt_target *target, const void *data) | |
1da177e4 | 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 | ||
2d06d4a5 JE |
37 | static bool |
38 | ebt_redirect_tg_check(const char *tablename, const void *e, | |
39 | const struct xt_target *target, void *data, | |
40 | unsigned int hookmask) | |
1da177e4 | 41 | { |
abfdf1c4 | 42 | const struct ebt_redirect_info *info = data; |
1da177e4 | 43 | |
1da177e4 | 44 | if (BASE_CHAIN && info->target == EBT_RETURN) |
19eda879 | 45 | return false; |
1da177e4 LT |
46 | CLEAR_BASE_CHAIN_BIT; |
47 | if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) && | |
48 | (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) ) | |
19eda879 | 49 | return false; |
1da177e4 | 50 | if (INVALID_TARGET) |
19eda879 JE |
51 | return false; |
52 | return true; | |
1da177e4 LT |
53 | } |
54 | ||
043ef46c JE |
55 | static struct xt_target ebt_redirect_tg_reg __read_mostly = { |
56 | .name = "redirect", | |
001a18d3 JE |
57 | .revision = 0, |
58 | .family = NFPROTO_BRIDGE, | |
f2ff525c JE |
59 | .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) | |
60 | (1 << NF_BR_BROUTING), | |
2d06d4a5 JE |
61 | .target = ebt_redirect_tg, |
62 | .checkentry = ebt_redirect_tg_check, | |
18219d3f | 63 | .targetsize = XT_ALIGN(sizeof(struct ebt_redirect_info)), |
1da177e4 LT |
64 | .me = THIS_MODULE, |
65 | }; | |
66 | ||
65b4b4e8 | 67 | static int __init ebt_redirect_init(void) |
1da177e4 | 68 | { |
043ef46c | 69 | return xt_register_target(&ebt_redirect_tg_reg); |
1da177e4 LT |
70 | } |
71 | ||
65b4b4e8 | 72 | static void __exit ebt_redirect_fini(void) |
1da177e4 | 73 | { |
043ef46c | 74 | xt_unregister_target(&ebt_redirect_tg_reg); |
1da177e4 LT |
75 | } |
76 | ||
65b4b4e8 AM |
77 | module_init(ebt_redirect_init); |
78 | module_exit(ebt_redirect_fini); | |
f776c4cd | 79 | MODULE_DESCRIPTION("Ebtables: Packet redirection to localhost"); |
1da177e4 | 80 | MODULE_LICENSE("GPL"); |