blob: c1f9ca293e9c8315c2e21728205cb90a75985876 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ebt_redirect
3 *
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * April, 2002
8 *
9 */
10
Herbert Xu2ca7b0a2007-10-14 00:39:55 -070011#include <linux/netfilter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/netfilter_bridge/ebtables.h>
13#include <linux/netfilter_bridge/ebt_redirect.h>
14#include <linux/module.h>
15#include <net/sock.h>
16#include "../br_private.h"
17
Herbert Xu3db05fe2007-10-15 00:53:15 -070018static int ebt_target_redirect(struct sk_buff *skb, unsigned int hooknr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 const struct net_device *in, const struct net_device *out,
20 const void *data, unsigned int datalen)
21{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080022 const struct ebt_redirect_info *info = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Herbert Xu3db05fe2007-10-15 00:53:15 -070024 if (skb_make_writable(skb, 0))
Herbert Xu2ca7b0a2007-10-14 00:39:55 -070025 return NF_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 if (hooknr != NF_BR_BROUTING)
Herbert Xu3db05fe2007-10-15 00:53:15 -070028 memcpy(eth_hdr(skb)->h_dest,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 in->br_port->br->dev->dev_addr, ETH_ALEN);
30 else
Herbert Xu3db05fe2007-10-15 00:53:15 -070031 memcpy(eth_hdr(skb)->h_dest, in->dev_addr, ETH_ALEN);
32 skb->pkt_type = PACKET_HOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 return info->target;
34}
35
36static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
37 const struct ebt_entry *e, void *data, unsigned int datalen)
38{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080039 const struct ebt_redirect_info *info = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
42 return -EINVAL;
43 if (BASE_CHAIN && info->target == EBT_RETURN)
44 return -EINVAL;
45 CLEAR_BASE_CHAIN_BIT;
46 if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
47 (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
48 return -EINVAL;
49 if (INVALID_TARGET)
50 return -EINVAL;
51 return 0;
52}
53
54static struct ebt_target redirect_target =
55{
56 .name = EBT_REDIRECT_TARGET,
57 .target = ebt_target_redirect,
58 .check = ebt_target_redirect_check,
59 .me = THIS_MODULE,
60};
61
Andrew Morton65b4b4e2006-03-28 16:37:06 -080062static int __init ebt_redirect_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 return ebt_register_target(&redirect_target);
65}
66
Andrew Morton65b4b4e2006-03-28 16:37:06 -080067static void __exit ebt_redirect_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 ebt_unregister_target(&redirect_target);
70}
71
Andrew Morton65b4b4e2006-03-28 16:37:06 -080072module_init(ebt_redirect_init);
73module_exit(ebt_redirect_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074MODULE_LICENSE("GPL");