5 * Bart De Schuymer <bdschuym@pandora.be>
11 #include <linux/netfilter_bridge/ebtables.h>
12 #include <uapi/linux/netfilter_bridge.h>
13 #include <linux/module.h>
15 #define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
16 (1 << NF_BR_LOCAL_OUT))
18 static struct ebt_entries initial_chains[] = {
33 static struct ebt_replace_kernel initial_table = {
35 .valid_hooks = FILTER_VALID_HOOKS,
36 .entries_size = 3 * sizeof(struct ebt_entries),
38 [NF_BR_LOCAL_IN] = &initial_chains[0],
39 [NF_BR_FORWARD] = &initial_chains[1],
40 [NF_BR_LOCAL_OUT] = &initial_chains[2],
42 .entries = (char *)initial_chains,
45 static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
47 if (valid_hooks & ~FILTER_VALID_HOOKS)
52 static const struct ebt_table frame_filter = {
54 .table = &initial_table,
55 .valid_hooks = FILTER_VALID_HOOKS,
61 ebt_in_hook(void *priv, struct sk_buff *skb,
62 const struct nf_hook_state *state)
64 return ebt_do_table(skb, state, state->net->xt.frame_filter);
68 ebt_out_hook(void *priv, struct sk_buff *skb,
69 const struct nf_hook_state *state)
71 return ebt_do_table(skb, state, state->net->xt.frame_filter);
74 static const struct nf_hook_ops ebt_ops_filter[] = {
78 .hooknum = NF_BR_LOCAL_IN,
79 .priority = NF_BR_PRI_FILTER_BRIDGED,
84 .hooknum = NF_BR_FORWARD,
85 .priority = NF_BR_PRI_FILTER_BRIDGED,
90 .hooknum = NF_BR_LOCAL_OUT,
91 .priority = NF_BR_PRI_FILTER_OTHER,
95 static int __net_init frame_filter_net_init(struct net *net)
97 return ebt_register_table(net, &frame_filter, ebt_ops_filter,
98 &net->xt.frame_filter);
101 static void __net_exit frame_filter_net_exit(struct net *net)
103 ebt_unregister_table(net, net->xt.frame_filter, ebt_ops_filter);
106 static struct pernet_operations frame_filter_net_ops = {
107 .init = frame_filter_net_init,
108 .exit = frame_filter_net_exit,
111 static int __init ebtable_filter_init(void)
113 return register_pernet_subsys(&frame_filter_net_ops);
116 static void __exit ebtable_filter_fini(void)
118 unregister_pernet_subsys(&frame_filter_net_ops);
121 module_init(ebtable_filter_init);
122 module_exit(ebtable_filter_fini);
123 MODULE_LICENSE("GPL");