• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2008-2010 Patrick McHardy <kaber@trash.net>
3  * Copyright (c) 2013 Pablo Neira Ayuso <pablo@netfilter.org>
4  *
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.
8  *
9  * Development of this code funded by Astaro AG (http://www.astaro.com/)
10  */
11 
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/netfilter_arp.h>
15 #include <net/netfilter/nf_tables.h>
16 
17 static unsigned int
nft_do_chain_arp(void * priv,struct sk_buff * skb,const struct nf_hook_state * state)18 nft_do_chain_arp(void *priv,
19 		  struct sk_buff *skb,
20 		  const struct nf_hook_state *state)
21 {
22 	struct nft_pktinfo pkt;
23 
24 	nft_set_pktinfo(&pkt, skb, state);
25 
26 	return nft_do_chain(&pkt, priv);
27 }
28 
29 static struct nft_af_info nft_af_arp __read_mostly = {
30 	.family		= NFPROTO_ARP,
31 	.nhooks		= NF_ARP_NUMHOOKS,
32 	.owner		= THIS_MODULE,
33 	.nops		= 1,
34 	.hooks		= {
35 		[NF_ARP_IN]		= nft_do_chain_arp,
36 		[NF_ARP_OUT]		= nft_do_chain_arp,
37 		[NF_ARP_FORWARD]	= nft_do_chain_arp,
38 	},
39 };
40 
nf_tables_arp_init_net(struct net * net)41 static int nf_tables_arp_init_net(struct net *net)
42 {
43 	net->nft.arp = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
44 	if (net->nft.arp== NULL)
45 		return -ENOMEM;
46 
47 	memcpy(net->nft.arp, &nft_af_arp, sizeof(nft_af_arp));
48 
49 	if (nft_register_afinfo(net, net->nft.arp) < 0)
50 		goto err;
51 
52 	return 0;
53 err:
54 	kfree(net->nft.arp);
55 	return -ENOMEM;
56 }
57 
nf_tables_arp_exit_net(struct net * net)58 static void nf_tables_arp_exit_net(struct net *net)
59 {
60 	nft_unregister_afinfo(net->nft.arp);
61 	kfree(net->nft.arp);
62 }
63 
64 static struct pernet_operations nf_tables_arp_net_ops = {
65 	.init   = nf_tables_arp_init_net,
66 	.exit   = nf_tables_arp_exit_net,
67 };
68 
69 static const struct nf_chain_type filter_arp = {
70 	.name		= "filter",
71 	.type		= NFT_CHAIN_T_DEFAULT,
72 	.family		= NFPROTO_ARP,
73 	.owner		= THIS_MODULE,
74 	.hook_mask	= (1 << NF_ARP_IN) |
75 			  (1 << NF_ARP_OUT) |
76 			  (1 << NF_ARP_FORWARD),
77 };
78 
nf_tables_arp_init(void)79 static int __init nf_tables_arp_init(void)
80 {
81 	int ret;
82 
83 	nft_register_chain_type(&filter_arp);
84 	ret = register_pernet_subsys(&nf_tables_arp_net_ops);
85 	if (ret < 0)
86 		nft_unregister_chain_type(&filter_arp);
87 
88 	return ret;
89 }
90 
nf_tables_arp_exit(void)91 static void __exit nf_tables_arp_exit(void)
92 {
93 	unregister_pernet_subsys(&nf_tables_arp_net_ops);
94 	nft_unregister_chain_type(&filter_arp);
95 }
96 
97 module_init(nf_tables_arp_init);
98 module_exit(nf_tables_arp_exit);
99 
100 MODULE_LICENSE("GPL");
101 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
102 MODULE_ALIAS_NFT_FAMILY(3); /* NFPROTO_ARP */
103