2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2013 Pablo Neira Ayuso <pablo@netfilter.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Development of this code funded by Astaro AG (http://www.astaro.com/)
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/netfilter_bridge.h>
15 #include <net/netfilter/nf_tables.h>
17 static struct nft_af_info nft_af_bridge __read_mostly = {
18 .family = NFPROTO_BRIDGE,
19 .nhooks = NF_BR_NUMHOOKS,
23 static int nf_tables_bridge_init_net(struct net *net)
25 net->nft.bridge = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
26 if (net->nft.bridge == NULL)
29 memcpy(net->nft.bridge, &nft_af_bridge, sizeof(nft_af_bridge));
31 if (nft_register_afinfo(net, net->nft.bridge) < 0)
36 kfree(net->nft.bridge);
40 static void nf_tables_bridge_exit_net(struct net *net)
42 nft_unregister_afinfo(net->nft.bridge);
43 kfree(net->nft.bridge);
46 static struct pernet_operations nf_tables_bridge_net_ops = {
47 .init = nf_tables_bridge_init_net,
48 .exit = nf_tables_bridge_exit_net,
52 nft_do_chain_bridge(const struct nf_hook_ops *ops,
54 const struct net_device *in,
55 const struct net_device *out,
56 int (*okfn)(struct sk_buff *))
58 struct nft_pktinfo pkt;
60 nft_set_pktinfo(&pkt, ops, skb, in, out);
62 return nft_do_chain_pktinfo(&pkt, ops);
65 static struct nf_chain_type filter_bridge = {
66 .family = NFPROTO_BRIDGE,
68 .type = NFT_CHAIN_T_DEFAULT,
69 .hook_mask = (1 << NF_BR_LOCAL_IN) |
70 (1 << NF_BR_FORWARD) |
71 (1 << NF_BR_LOCAL_OUT),
73 [NF_BR_LOCAL_IN] = nft_do_chain_bridge,
74 [NF_BR_FORWARD] = nft_do_chain_bridge,
75 [NF_BR_LOCAL_OUT] = nft_do_chain_bridge,
79 static int __init nf_tables_bridge_init(void)
83 nft_register_chain_type(&filter_bridge);
84 ret = register_pernet_subsys(&nf_tables_bridge_net_ops);
86 nft_unregister_chain_type(&filter_bridge);
91 static void __exit nf_tables_bridge_exit(void)
93 unregister_pernet_subsys(&nf_tables_bridge_net_ops);
94 nft_unregister_chain_type(&filter_bridge);
97 module_init(nf_tables_bridge_init);
98 module_exit(nf_tables_bridge_exit);
100 MODULE_LICENSE("GPL");
101 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
102 MODULE_ALIAS_NFT_FAMILY(AF_BRIDGE);