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 #include "../br_private.h"
20 /* EBT_ACCEPT means the frame will be bridged
21 * EBT_DROP means the frame will be routed
23 static struct ebt_entries initial_chain = {
28 static struct ebt_replace_kernel initial_table = {
30 .valid_hooks = 1 << NF_BR_BROUTING,
31 .entries_size = sizeof(struct ebt_entries),
33 [NF_BR_BROUTING] = &initial_chain,
35 .entries = (char *)&initial_chain,
38 static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
40 if (valid_hooks & ~(1 << NF_BR_BROUTING))
45 static const struct ebt_table broute_table = {
47 .table = &initial_table,
48 .valid_hooks = 1 << NF_BR_BROUTING,
53 static unsigned int ebt_broute(void *priv, struct sk_buff *skb,
54 const struct nf_hook_state *s)
56 struct net_bridge_port *p = br_port_get_rcu(skb->dev);
57 struct nf_hook_state state;
61 if (!p || p->state != BR_STATE_FORWARDING)
64 nf_hook_state_init(&state, NF_BR_BROUTING,
65 NFPROTO_BRIDGE, s->in, NULL, NULL,
68 ret = ebt_do_table(skb, &state, state.net->xt.broute_table);
73 /* DROP in ebtables -t broute means that the
74 * skb should be routed, not bridged.
75 * This is awkward, but can't be changed for compatibility
78 * We map DROP to ACCEPT and set the ->br_netfilter_broute flag.
80 BR_INPUT_SKB_CB(skb)->br_netfilter_broute = 1;
82 /* undo PACKET_HOST mangling done in br_input in case the dst
83 * address matches the logical bridge but not the port.
85 dest = eth_hdr(skb)->h_dest;
86 if (skb->pkt_type == PACKET_HOST &&
87 !ether_addr_equal(skb->dev->dev_addr, dest) &&
88 ether_addr_equal(p->br->dev->dev_addr, dest))
89 skb->pkt_type = PACKET_OTHERHOST;
94 static const struct nf_hook_ops ebt_ops_broute = {
97 .hooknum = NF_BR_PRE_ROUTING,
98 .priority = NF_BR_PRI_FIRST,
101 static int __net_init broute_net_init(struct net *net)
103 return ebt_register_table(net, &broute_table, &ebt_ops_broute,
104 &net->xt.broute_table);
107 static void __net_exit broute_net_exit(struct net *net)
109 ebt_unregister_table(net, net->xt.broute_table, &ebt_ops_broute);
112 static struct pernet_operations broute_net_ops = {
113 .init = broute_net_init,
114 .exit = broute_net_exit,
117 static int __init ebtable_broute_init(void)
119 return register_pernet_subsys(&broute_net_ops);
122 static void __exit ebtable_broute_fini(void)
124 unregister_pernet_subsys(&broute_net_ops);
127 module_init(ebtable_broute_init);
128 module_exit(ebtable_broute_fini);
129 MODULE_LICENSE("GPL");