netfilter: xtables: move extension arguments into compound structure (6/6)
[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 xt_target_param *par)
20 {
21         const struct ebt_redirect_info *info = par->targinfo;
22
23         if (!skb_make_writable(skb, 0))
24                 return EBT_DROP;
25
26         if (par->hooknum != NF_BR_BROUTING)
27                 memcpy(eth_hdr(skb)->h_dest,
28                        par->in->br_port->br->dev->dev_addr, ETH_ALEN);
29         else
30                 memcpy(eth_hdr(skb)->h_dest, par->in->dev_addr, ETH_ALEN);
31         skb->pkt_type = PACKET_HOST;
32         return info->target;
33 }
34
35 static bool ebt_redirect_tg_check(const struct xt_tgchk_param *par)
36 {
37         const struct ebt_redirect_info *info = par->targinfo;
38         unsigned int hook_mask;
39
40         if (BASE_CHAIN && info->target == EBT_RETURN)
41                 return false;
42
43         hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
44         if ((strcmp(par->table, "nat") != 0 ||
45             hook_mask & ~(1 << NF_BR_PRE_ROUTING)) &&
46             (strcmp(par->table, "broute") != 0 ||
47             hook_mask & ~(1 << NF_BR_BROUTING)))
48                 return false;
49         if (INVALID_TARGET)
50                 return false;
51         return true;
52 }
53
54 static struct xt_target ebt_redirect_tg_reg __read_mostly = {
55         .name           = "redirect",
56         .revision       = 0,
57         .family         = NFPROTO_BRIDGE,
58         .hooks          = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
59                           (1 << NF_BR_BROUTING),
60         .target         = ebt_redirect_tg,
61         .checkentry     = ebt_redirect_tg_check,
62         .targetsize     = XT_ALIGN(sizeof(struct ebt_redirect_info)),
63         .me             = THIS_MODULE,
64 };
65
66 static int __init ebt_redirect_init(void)
67 {
68         return xt_register_target(&ebt_redirect_tg_reg);
69 }
70
71 static void __exit ebt_redirect_fini(void)
72 {
73         xt_unregister_target(&ebt_redirect_tg_reg);
74 }
75
76 module_init(ebt_redirect_init);
77 module_exit(ebt_redirect_fini);
78 MODULE_DESCRIPTION("Ebtables: Packet redirection to localhost");
79 MODULE_LICENSE("GPL");