netfilter: remove unused Ebtables functions
[safe/jmp/linux-2.6] / net / bridge / netfilter / ebt_snat.c
1 /*
2  *  ebt_snat
3  *
4  *      Authors:
5  *      Bart De Schuymer <bdschuym@pandora.be>
6  *
7  *  June, 2002
8  *
9  */
10 #include <linux/module.h>
11 #include <net/sock.h>
12 #include <linux/if_arp.h>
13 #include <net/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>
18
19 static unsigned int
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)
23 {
24         const struct ebt_nat_info *info = data;
25
26         if (!skb_make_writable(skb, 0))
27                 return EBT_DROP;
28
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;
33                 struct arphdr _ah;
34
35                 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
36                 if (ap == NULL)
37                         return EBT_DROP;
38                 if (ap->ar_hln != ETH_ALEN)
39                         goto out;
40                 if (skb_store_bits(skb, sizeof(_ah), info->mac,ETH_ALEN))
41                         return EBT_DROP;
42         }
43 out:
44         return info->target | ~EBT_VERDICT_BITS;
45 }
46
47 static bool
48 ebt_snat_tg_check(const char *tablename, const void *e,
49                   const struct xt_target *target, void *data,
50                   unsigned int hookmask)
51 {
52         const struct ebt_nat_info *info = data;
53         int tmp;
54
55         tmp = info->target | ~EBT_VERDICT_BITS;
56         if (BASE_CHAIN && tmp == EBT_RETURN)
57                 return false;
58         CLEAR_BASE_CHAIN_BIT;
59
60         if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
61                 return false;
62         tmp = info->target | EBT_VERDICT_BITS;
63         if ((tmp & ~NAT_ARP_BIT) != ~NAT_ARP_BIT)
64                 return false;
65         return true;
66 }
67
68 static struct xt_target ebt_snat_tg_reg __read_mostly = {
69         .name           = "snat",
70         .revision       = 0,
71         .family         = NFPROTO_BRIDGE,
72         .table          = "nat",
73         .hooks          = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_POST_ROUTING),
74         .target         = ebt_snat_tg,
75         .checkentry     = ebt_snat_tg_check,
76         .targetsize     = XT_ALIGN(sizeof(struct ebt_nat_info)),
77         .me             = THIS_MODULE,
78 };
79
80 static int __init ebt_snat_init(void)
81 {
82         return xt_register_target(&ebt_snat_tg_reg);
83 }
84
85 static void __exit ebt_snat_fini(void)
86 {
87         xt_unregister_target(&ebt_snat_tg_reg);
88 }
89
90 module_init(ebt_snat_init);
91 module_exit(ebt_snat_fini);
92 MODULE_DESCRIPTION("Ebtables: Source MAC address translation");
93 MODULE_LICENSE("GPL");