2 * Filtering ARP tables module.
8 #include <linux/module.h>
9 #include <linux/netfilter/x_tables.h>
10 #include <linux/netfilter_arp/arp_tables.h>
11 #include <linux/slab.h>
13 MODULE_LICENSE("GPL");
15 MODULE_DESCRIPTION("arptables filter table");
17 #define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \
18 (1 << NF_ARP_FORWARD))
20 static const struct xt_table packet_filter = {
22 .valid_hooks = FILTER_VALID_HOOKS,
25 .priority = NF_IP_PRI_FILTER,
28 /* The work comes in here from netfilter.c */
30 arptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
31 const struct net_device *in, const struct net_device *out,
32 int (*okfn)(struct sk_buff *))
34 const struct net *net = dev_net((in != NULL) ? in : out);
36 return arpt_do_table(skb, ops->hooknum, in, out,
37 net->ipv4.arptable_filter);
40 static struct nf_hook_ops *arpfilter_ops __read_mostly;
42 static int __net_init arptable_filter_net_init(struct net *net)
44 struct arpt_replace *repl;
46 repl = arpt_alloc_initial_table(&packet_filter);
49 net->ipv4.arptable_filter =
50 arpt_register_table(net, &packet_filter, repl);
52 return PTR_ERR_OR_ZERO(net->ipv4.arptable_filter);
55 static void __net_exit arptable_filter_net_exit(struct net *net)
57 arpt_unregister_table(net->ipv4.arptable_filter);
60 static struct pernet_operations arptable_filter_net_ops = {
61 .init = arptable_filter_net_init,
62 .exit = arptable_filter_net_exit,
65 static int __init arptable_filter_init(void)
69 ret = register_pernet_subsys(&arptable_filter_net_ops);
73 arpfilter_ops = xt_hook_link(&packet_filter, arptable_filter_hook);
74 if (IS_ERR(arpfilter_ops)) {
75 ret = PTR_ERR(arpfilter_ops);
81 unregister_pernet_subsys(&arptable_filter_net_ops);
85 static void __exit arptable_filter_fini(void)
87 xt_hook_unlink(&packet_filter, arpfilter_ops);
88 unregister_pernet_subsys(&arptable_filter_net_ops);
91 module_init(arptable_filter_init);
92 module_exit(arptable_filter_fini);