Full support for Ginger Console
[linux-ginger.git] / net / bridge / netfilter / ebt_dnat.c
blob6b49ea9e31fb04f5852499f575a14f10750bf876
1 /*
2 * ebt_dnat
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
7 * June, 2002
9 */
10 #include <linux/module.h>
11 #include <net/sock.h>
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>
17 static unsigned int
18 ebt_dnat_tg(struct sk_buff *skb, const struct xt_target_param *par)
20 const struct ebt_nat_info *info = par->targinfo;
22 if (!skb_make_writable(skb, 0))
23 return EBT_DROP;
25 memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN);
26 return info->target;
29 static bool ebt_dnat_tg_check(const struct xt_tgchk_param *par)
31 const struct ebt_nat_info *info = par->targinfo;
32 unsigned int hook_mask;
34 if (BASE_CHAIN && info->target == EBT_RETURN)
35 return false;
37 hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
38 if ((strcmp(par->table, "nat") != 0 ||
39 (hook_mask & ~((1 << NF_BR_PRE_ROUTING) |
40 (1 << NF_BR_LOCAL_OUT)))) &&
41 (strcmp(par->table, "broute") != 0 ||
42 hook_mask & ~(1 << NF_BR_BROUTING)))
43 return false;
44 if (INVALID_TARGET)
45 return false;
46 return true;
49 static struct xt_target ebt_dnat_tg_reg __read_mostly = {
50 .name = "dnat",
51 .revision = 0,
52 .family = NFPROTO_BRIDGE,
53 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
54 (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING),
55 .target = ebt_dnat_tg,
56 .checkentry = ebt_dnat_tg_check,
57 .targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)),
58 .me = THIS_MODULE,
61 static int __init ebt_dnat_init(void)
63 return xt_register_target(&ebt_dnat_tg_reg);
66 static void __exit ebt_dnat_fini(void)
68 xt_unregister_target(&ebt_dnat_tg_reg);
71 module_init(ebt_dnat_init);
72 module_exit(ebt_dnat_fini);
73 MODULE_DESCRIPTION("Ebtables: Destination MAC address translation");
74 MODULE_LICENSE("GPL");