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_redirect.h>
18 static unsigned int ebt_target_redirect(struct sk_buff *skb,
20 const struct net_device *in, const struct net_device *out,
21 const void *data, unsigned int datalen)
23 const struct ebt_redirect_info *info = data;
25 if (!skb_make_writable(skb, 0))
28 if (hooknr != NF_BR_BROUTING)
29 memcpy(eth_hdr(skb)->h_dest,
30 in->br_port->br->dev->dev_addr, ETH_ALEN);
32 memcpy(eth_hdr(skb)->h_dest, in->dev_addr, ETH_ALEN);
33 skb->pkt_type = PACKET_HOST;
37 static bool ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
38 const struct ebt_entry *e, void *data, unsigned int datalen)
40 const struct ebt_redirect_info *info = data;
42 if (BASE_CHAIN && info->target == EBT_RETURN)
45 if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
46 (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
53 static struct ebt_target redirect_target __read_mostly = {
54 .name = EBT_REDIRECT_TARGET,
56 .family = NFPROTO_BRIDGE,
57 .target = ebt_target_redirect,
58 .check = ebt_target_redirect_check,
59 .targetsize = XT_ALIGN(sizeof(struct ebt_redirect_info)),
63 static int __init ebt_redirect_init(void)
65 return ebt_register_target(&redirect_target);
68 static void __exit ebt_redirect_fini(void)
70 ebt_unregister_target(&redirect_target);
73 module_init(ebt_redirect_init);
74 module_exit(ebt_redirect_fini);
75 MODULE_DESCRIPTION("Ebtables: Packet redirection to localhost");
76 MODULE_LICENSE("GPL");