ebtable_broute.c 1.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 *  ebtable_broute
 *
 *	Authors:
 *	Bart De Schuymer <bdschuym@pandora.be>
 *
 *  April, 2002
 *
 *  This table lets you choose between routing and bridging for frames
 *  entering on a bridge enslaved nic. This table is traversed before any
 *  other ebtables table. See net/bridge/br_input.c.
 */

#include <linux/netfilter_bridge/ebtables.h>
#include <linux/module.h>
#include <linux/if_bridge.h>

/* EBT_ACCEPT means the frame will be bridged
 * EBT_DROP means the frame will be routed
 */
static struct ebt_entries initial_chain = {
	.name		= "BROUTING",
	.policy		= EBT_ACCEPT,
};

26
static struct ebt_replace_kernel initial_table =
L
Linus Torvalds 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
	.name		= "broute",
	.valid_hooks	= 1 << NF_BR_BROUTING,
	.entries_size	= sizeof(struct ebt_entries),
	.hook_entry	= {
		[NF_BR_BROUTING]	= &initial_chain,
	},
	.entries	= (char *)&initial_chain,
};

static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
{
	if (valid_hooks & ~(1 << NF_BR_BROUTING))
		return -EINVAL;
	return 0;
}

static struct ebt_table broute_table =
{
	.name		= "broute",
	.table		= &initial_table,
	.valid_hooks	= 1 << NF_BR_BROUTING,
49
	.lock		= __RW_LOCK_UNLOCKED(broute_table.lock),
L
Linus Torvalds 已提交
50 51 52 53
	.check		= check,
	.me		= THIS_MODULE,
};

54
static int ebt_broute(struct sk_buff *skb)
L
Linus Torvalds 已提交
55 56 57
{
	int ret;

58
	ret = ebt_do_table(NF_BR_BROUTING, skb, skb->dev, NULL,
L
Linus Torvalds 已提交
59 60 61 62 63 64
	   &broute_table);
	if (ret == NF_DROP)
		return 1; /* route it */
	return 0; /* bridge it */
}

65
static int __init ebtable_broute_init(void)
L
Linus Torvalds 已提交
66 67 68
{
	int ret;

69
	ret = ebt_register_table(&init_net, &broute_table);
L
Linus Torvalds 已提交
70 71 72
	if (ret < 0)
		return ret;
	/* see br_input.c */
73
	rcu_assign_pointer(br_should_route_hook, ebt_broute);
L
Linus Torvalds 已提交
74 75 76
	return ret;
}

77
static void __exit ebtable_broute_fini(void)
L
Linus Torvalds 已提交
78
{
79
	rcu_assign_pointer(br_should_route_hook, NULL);
L
Linus Torvalds 已提交
80 81 82 83
	synchronize_net();
	ebt_unregister_table(&broute_table);
}

84 85
module_init(ebtable_broute_init);
module_exit(ebtable_broute_fini);
L
Linus Torvalds 已提交
86
MODULE_LICENSE("GPL");