5 * Bart De Schuymer <bdschuym@pandora.be>
10 #include <linux/module.h>
12 #include <linux/if_arp.h>
14 #include <linux/netfilter.h>
15 #include <linux/netfilter/x_tables.h>
16 #include <linux/netfilter_bridge/ebtables.h>
17 #include <linux/netfilter_bridge/ebt_nat.h>
20 ebt_snat_tg(struct sk_buff *skb, const struct net_device *in,
21 const struct net_device *out, unsigned int hook_nr,
22 const struct xt_target *target, const void *data)
24 const struct ebt_nat_info *info = data;
26 if (!skb_make_writable(skb, 0))
29 memcpy(eth_hdr(skb)->h_source, info->mac, ETH_ALEN);
30 if (!(info->target & NAT_ARP_BIT) &&
31 eth_hdr(skb)->h_proto == htons(ETH_P_ARP)) {
32 const struct arphdr *ap;
35 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
38 if (ap->ar_hln != ETH_ALEN)
40 if (skb_store_bits(skb, sizeof(_ah), info->mac,ETH_ALEN))
44 return info->target | ~EBT_VERDICT_BITS;
48 ebt_snat_tg_check(const char *tablename, const void *e,
49 const struct xt_target *target, void *data,
50 unsigned int hookmask)
52 const struct ebt_nat_info *info = data;
55 tmp = info->target | ~EBT_VERDICT_BITS;
56 if (BASE_CHAIN && tmp == EBT_RETURN)
59 if (strcmp(tablename, "nat"))
61 if (hookmask & ~(1 << NF_BR_POST_ROUTING))
64 if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
66 tmp = info->target | EBT_VERDICT_BITS;
67 if ((tmp & ~NAT_ARP_BIT) != ~NAT_ARP_BIT)
72 static struct ebt_target snat __read_mostly = {
73 .name = EBT_SNAT_TARGET,
75 .family = NFPROTO_BRIDGE,
76 .target = ebt_snat_tg,
77 .checkentry = ebt_snat_tg_check,
78 .targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)),
82 static int __init ebt_snat_init(void)
84 return ebt_register_target(&snat);
87 static void __exit ebt_snat_fini(void)
89 ebt_unregister_target(&snat);
92 module_init(ebt_snat_init);
93 module_exit(ebt_snat_fini);
94 MODULE_DESCRIPTION("Ebtables: Source MAC address translation");
95 MODULE_LICENSE("GPL");