5 * Bart De Schuymer <bdschuym@pandora.be>
9 * This table lets you choose between routing and bridging for frames
10 * entering on a bridge enslaved nic. This table is traversed before any
11 * other ebtables table. See net/bridge/br_input.c.
14 #include <linux/netfilter_bridge/ebtables.h>
15 #include <linux/module.h>
16 #include <linux/if_bridge.h>
18 /* EBT_ACCEPT means the frame will be bridged
19 * EBT_DROP means the frame will be routed
21 static struct ebt_entries initial_chain = {
26 static struct ebt_replace_kernel initial_table = {
28 .valid_hooks = 1 << NF_BR_BROUTING,
29 .entries_size = sizeof(struct ebt_entries),
31 [NF_BR_BROUTING] = &initial_chain,
33 .entries = (char *)&initial_chain,
36 static const struct ebt_table broute_table = {
38 .table = &initial_table,
39 .valid_hooks = 1 << NF_BR_BROUTING,
43 static int ebt_broute(struct sk_buff *skb)
45 struct nf_hook_state state;
48 nf_hook_state_init(&state, NF_BR_BROUTING,
49 NFPROTO_BRIDGE, skb->dev, NULL, NULL,
50 dev_net(skb->dev), NULL);
52 ret = ebt_do_table(skb, &state, state.net->xt.broute_table);
54 return 1; /* route it */
55 return 0; /* bridge it */
58 static int __net_init broute_net_init(struct net *net)
60 return ebt_register_table(net, &broute_table, NULL,
61 &net->xt.broute_table);
64 static void __net_exit broute_net_exit(struct net *net)
66 ebt_unregister_table(net, net->xt.broute_table, NULL);
69 static struct pernet_operations broute_net_ops = {
70 .init = broute_net_init,
71 .exit = broute_net_exit,
74 static int __init ebtable_broute_init(void)
78 ret = register_pernet_subsys(&broute_net_ops);
82 RCU_INIT_POINTER(br_should_route_hook,
83 (br_should_route_hook_t *)ebt_broute);
87 static void __exit ebtable_broute_fini(void)
89 RCU_INIT_POINTER(br_should_route_hook, NULL);
91 unregister_pernet_subsys(&broute_net_ops);
94 module_init(ebtable_broute_init);
95 module_exit(ebtable_broute_fini);
96 MODULE_LICENSE("GPL");