5 * Bart De Schuymer <bdschuym@pandora.be>
10 #include <linux/module.h>
12 #include "../br_private.h"
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_nat.h>
19 ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par)
21 const struct ebt_nat_info *info = par->targinfo;
23 if (!skb_make_writable(skb, 0))
26 ether_addr_copy(eth_hdr(skb)->h_dest, info->mac);
28 if (is_multicast_ether_addr(info->mac)) {
29 if (is_broadcast_ether_addr(info->mac))
30 skb->pkt_type = PACKET_BROADCAST;
32 skb->pkt_type = PACKET_MULTICAST;
34 const struct net_device *dev;
36 switch (xt_hooknum(par)) {
40 case NF_BR_PRE_ROUTING:
41 dev = br_port_get_rcu(xt_in(par))->br->dev;
48 if (!dev) /* NF_BR_LOCAL_OUT */
51 if (ether_addr_equal(info->mac, dev->dev_addr))
52 skb->pkt_type = PACKET_HOST;
54 skb->pkt_type = PACKET_OTHERHOST;
60 static int ebt_dnat_tg_check(const struct xt_tgchk_param *par)
62 const struct ebt_nat_info *info = par->targinfo;
63 unsigned int hook_mask;
65 if (BASE_CHAIN && info->target == EBT_RETURN)
68 hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
69 if ((strcmp(par->table, "nat") != 0 ||
70 (hook_mask & ~((1 << NF_BR_PRE_ROUTING) |
71 (1 << NF_BR_LOCAL_OUT)))) &&
72 (strcmp(par->table, "broute") != 0 ||
73 hook_mask & ~(1 << NF_BR_BROUTING)))
75 if (ebt_invalid_target(info->target))
80 static struct xt_target ebt_dnat_tg_reg __read_mostly = {
83 .family = NFPROTO_BRIDGE,
84 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
85 (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING),
86 .target = ebt_dnat_tg,
87 .checkentry = ebt_dnat_tg_check,
88 .targetsize = sizeof(struct ebt_nat_info),
92 static int __init ebt_dnat_init(void)
94 return xt_register_target(&ebt_dnat_tg_reg);
97 static void __exit ebt_dnat_fini(void)
99 xt_unregister_target(&ebt_dnat_tg_reg);
102 module_init(ebt_dnat_init);
103 module_exit(ebt_dnat_fini);
104 MODULE_DESCRIPTION("Ebtables: Destination MAC address translation");
105 MODULE_LICENSE("GPL");