Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ebt_dnat |
| 3 | * |
| 4 | * Authors: |
| 5 | * Bart De Schuymer <bdschuym@pandora.be> |
| 6 | * |
| 7 | * June, 2002 |
| 8 | * |
| 9 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <net/sock.h> |
Jan Engelhardt | 18219d3 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 12 | #include <linux/netfilter.h> |
| 13 | #include <linux/netfilter/x_tables.h> |
| 14 | #include <linux/netfilter_bridge/ebtables.h> |
| 15 | #include <linux/netfilter_bridge/ebt_nat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame^] | 17 | static unsigned int |
| 18 | ebt_dnat_tg(struct sk_buff *skb, const struct net_device *in, |
| 19 | const struct net_device *out, unsigned int hook_nr, |
| 20 | const struct xt_target *target, const void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 22 | const struct ebt_nat_info *info = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Joonwoo Park | eb1197b | 2008-02-19 17:18:47 -0800 | [diff] [blame] | 24 | if (!skb_make_writable(skb, 0)) |
Joonwoo Park | 1b04ab4 | 2008-02-23 20:22:27 -0800 | [diff] [blame] | 25 | return EBT_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 27 | memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | return info->target; |
| 29 | } |
| 30 | |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame^] | 31 | static bool |
| 32 | ebt_dnat_tg_check(const char *tablename, const void *entry, |
| 33 | const struct xt_target *target, void *data, |
| 34 | unsigned int hookmask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 36 | const struct ebt_nat_info *info = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | if (BASE_CHAIN && info->target == EBT_RETURN) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 39 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | CLEAR_BASE_CHAIN_BIT; |
| 41 | if ( (strcmp(tablename, "nat") || |
| 42 | (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) && |
| 43 | (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) ) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 44 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | if (INVALID_TARGET) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 46 | return false; |
| 47 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Jan Engelhardt | 30083c9 | 2008-01-31 04:00:59 -0800 | [diff] [blame] | 50 | static struct ebt_target dnat __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | .name = EBT_DNAT_TARGET, |
Jan Engelhardt | 001a18d | 2008-10-08 11:35:14 +0200 | [diff] [blame] | 52 | .revision = 0, |
| 53 | .family = NFPROTO_BRIDGE, |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame^] | 54 | .target = ebt_dnat_tg, |
| 55 | .checkentry = ebt_dnat_tg_check, |
Jan Engelhardt | 18219d3 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 56 | .targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | .me = THIS_MODULE, |
| 58 | }; |
| 59 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 60 | static int __init ebt_dnat_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
| 62 | return ebt_register_target(&dnat); |
| 63 | } |
| 64 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 65 | static void __exit ebt_dnat_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | ebt_unregister_target(&dnat); |
| 68 | } |
| 69 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 70 | module_init(ebt_dnat_init); |
| 71 | module_exit(ebt_dnat_fini); |
Jan Engelhardt | f776c4c | 2008-01-31 04:00:30 -0800 | [diff] [blame] | 72 | MODULE_DESCRIPTION("Ebtables: Destination MAC address translation"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | MODULE_LICENSE("GPL"); |