netfilter: remove unused Ebtables functions
[safe/jmp/linux-2.6] / net / bridge / netfilter / ebt_redirect.c
1 /*
2  *  ebt_redirect
3  *
4  *      Authors:
5  *      Bart De Schuymer <bdschuym@pandora.be>
6  *
7  *  April, 2002
8  *
9  */
10 #include <linux/module.h>
11 #include <net/sock.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_redirect.h>
17
18 static unsigned int
19 ebt_redirect_tg(struct sk_buff *skb, const struct net_device *in,
20                 const struct net_device *out, unsigned int hooknr,
21                 const struct xt_target *target, const void *data)
22 {
23         const struct ebt_redirect_info *info = data;
24
25         if (!skb_make_writable(skb, 0))
26                 return EBT_DROP;
27
28         if (hooknr != NF_BR_BROUTING)
29                 memcpy(eth_hdr(skb)->h_dest,
30                        in->br_port->br->dev->dev_addr, ETH_ALEN);
31         else
32                 memcpy(eth_hdr(skb)->h_dest, in->dev_addr, ETH_ALEN);
33         skb->pkt_type = PACKET_HOST;
34         return info->target;
35 }
36
37 static bool
38 ebt_redirect_tg_check(const char *tablename, const void *e,
39                       const struct xt_target *target, void *data,
40                       unsigned int hookmask)
41 {
42         const struct ebt_redirect_info *info = data;
43
44         if (BASE_CHAIN && info->target == EBT_RETURN)
45                 return false;
46         CLEAR_BASE_CHAIN_BIT;
47         if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
48              (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
49                 return false;
50         if (INVALID_TARGET)
51                 return false;
52         return true;
53 }
54
55 static struct xt_target ebt_redirect_tg_reg __read_mostly = {
56         .name           = "redirect",
57         .revision       = 0,
58         .family         = NFPROTO_BRIDGE,
59         .hooks          = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
60                           (1 << NF_BR_BROUTING),
61         .target         = ebt_redirect_tg,
62         .checkentry     = ebt_redirect_tg_check,
63         .targetsize     = XT_ALIGN(sizeof(struct ebt_redirect_info)),
64         .me             = THIS_MODULE,
65 };
66
67 static int __init ebt_redirect_init(void)
68 {
69         return xt_register_target(&ebt_redirect_tg_reg);
70 }
71
72 static void __exit ebt_redirect_fini(void)
73 {
74         xt_unregister_target(&ebt_redirect_tg_reg);
75 }
76
77 module_init(ebt_redirect_init);
78 module_exit(ebt_redirect_fini);
79 MODULE_DESCRIPTION("Ebtables: Packet redirection to localhost");
80 MODULE_LICENSE("GPL");