5 * Bart De Schuymer <bdschuym@pandora.be>
11 #include <linux/netfilter.h>
12 #include <linux/netfilter_bridge/ebtables.h>
13 #include <linux/netfilter_bridge/ebt_redirect.h>
14 #include <linux/module.h>
16 #include "../br_private.h"
18 static int ebt_target_redirect(struct sk_buff
*skb
, unsigned int hooknr
,
19 const struct net_device
*in
, const struct net_device
*out
,
20 const void *data
, unsigned int datalen
)
22 const struct ebt_redirect_info
*info
= data
;
24 if (!skb_make_writable(skb
, 0))
27 if (hooknr
!= NF_BR_BROUTING
)
28 memcpy(eth_hdr(skb
)->h_dest
,
29 in
->br_port
->br
->dev
->dev_addr
, ETH_ALEN
);
31 memcpy(eth_hdr(skb
)->h_dest
, in
->dev_addr
, ETH_ALEN
);
32 skb
->pkt_type
= PACKET_HOST
;
36 static int ebt_target_redirect_check(const char *tablename
, unsigned int hookmask
,
37 const struct ebt_entry
*e
, void *data
, unsigned int datalen
)
39 const struct ebt_redirect_info
*info
= data
;
41 if (datalen
!= EBT_ALIGN(sizeof(struct ebt_redirect_info
)))
43 if (BASE_CHAIN
&& info
->target
== EBT_RETURN
)
46 if ( (strcmp(tablename
, "nat") || hookmask
& ~(1 << NF_BR_PRE_ROUTING
)) &&
47 (strcmp(tablename
, "broute") || hookmask
& ~(1 << NF_BR_BROUTING
)) )
54 static struct ebt_target redirect_target __read_mostly
= {
55 .name
= EBT_REDIRECT_TARGET
,
56 .target
= ebt_target_redirect
,
57 .check
= ebt_target_redirect_check
,
61 static int __init
ebt_redirect_init(void)
63 return ebt_register_target(&redirect_target
);
66 static void __exit
ebt_redirect_fini(void)
68 ebt_unregister_target(&redirect_target
);
71 module_init(ebt_redirect_init
);
72 module_exit(ebt_redirect_fini
);
73 MODULE_DESCRIPTION("Ebtables: Packet redirection to localhost");
74 MODULE_LICENSE("GPL");