blob: d2211c4a477e4e842f7ce9a4bdadeb6757b06088 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ebt_dnat
3 *
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * June, 2002
8 *
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11#include <net/sock.h>
Jan Engelhardt18219d32008-10-08 11:35:13 +020012#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 Torvalds1da177e2005-04-16 15:20:36 -070016
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020017static unsigned int
18ebt_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 Torvalds1da177e2005-04-16 15:20:36 -070021{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080022 const struct ebt_nat_info *info = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Joonwoo Parkeb1197b2008-02-19 17:18:47 -080024 if (!skb_make_writable(skb, 0))
Joonwoo Park1b04ab42008-02-23 20:22:27 -080025 return EBT_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Herbert Xu3db05fe2007-10-15 00:53:15 -070027 memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 return info->target;
29}
30
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020031static bool
32ebt_dnat_tg_check(const char *tablename, const void *entry,
33 const struct xt_target *target, void *data,
34 unsigned int hookmask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080036 const struct ebt_nat_info *info = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 if (BASE_CHAIN && info->target == EBT_RETURN)
Jan Engelhardt19eda872008-10-08 11:35:13 +020039 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 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 Engelhardt19eda872008-10-08 11:35:13 +020044 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 if (INVALID_TARGET)
Jan Engelhardt19eda872008-10-08 11:35:13 +020046 return false;
47 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Jan Engelhardt043ef462008-10-08 11:35:15 +020050static struct xt_target ebt_dnat_tg_reg __read_mostly = {
51 .name = "dnat",
Jan Engelhardt001a18d2008-10-08 11:35:14 +020052 .revision = 0,
53 .family = NFPROTO_BRIDGE,
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020054 .target = ebt_dnat_tg,
55 .checkentry = ebt_dnat_tg_check,
Jan Engelhardt18219d32008-10-08 11:35:13 +020056 .targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)),
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 .me = THIS_MODULE,
58};
59
Andrew Morton65b4b4e2006-03-28 16:37:06 -080060static int __init ebt_dnat_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Jan Engelhardt043ef462008-10-08 11:35:15 +020062 return xt_register_target(&ebt_dnat_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Andrew Morton65b4b4e2006-03-28 16:37:06 -080065static void __exit ebt_dnat_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Jan Engelhardt043ef462008-10-08 11:35:15 +020067 xt_unregister_target(&ebt_dnat_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Andrew Morton65b4b4e2006-03-28 16:37:06 -080070module_init(ebt_dnat_init);
71module_exit(ebt_dnat_fini);
Jan Engelhardtf776c4c2008-01-31 04:00:30 -080072MODULE_DESCRIPTION("Ebtables: Destination MAC address translation");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073MODULE_LICENSE("GPL");