2 * Filtering ARP tables module.
4 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
8 #include <linux/module.h>
9 #include <linux/netfilter_arp/arp_tables.h>
11 MODULE_LICENSE("GPL");
12 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
13 MODULE_DESCRIPTION("arptables filter table");
15 #define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \
16 (1 << NF_ARP_FORWARD))
20 struct arpt_replace repl;
21 struct arpt_standard entries[3];
22 struct arpt_error term;
23 } initial_table __net_initdata = {
26 .valid_hooks = FILTER_VALID_HOOKS,
28 .size = sizeof(struct arpt_standard) * 3 + sizeof(struct arpt_error),
31 [NF_ARP_OUT] = sizeof(struct arpt_standard),
32 [NF_ARP_FORWARD] = 2 * sizeof(struct arpt_standard),
36 [NF_ARP_OUT] = sizeof(struct arpt_standard),
37 [NF_ARP_FORWARD] = 2 * sizeof(struct arpt_standard),
41 ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_IN */
42 ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_OUT */
43 ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_FORWARD */
45 .term = ARPT_ERROR_INIT,
48 static struct xt_table packet_filter = {
50 .valid_hooks = FILTER_VALID_HOOKS,
51 .lock = __RW_LOCK_UNLOCKED(packet_filter.lock),
57 /* The work comes in here from netfilter.c */
58 static unsigned int arpt_in_hook(unsigned int hook,
60 const struct net_device *in,
61 const struct net_device *out,
62 int (*okfn)(struct sk_buff *))
64 return arpt_do_table(skb, hook, in, out,
65 dev_net(in)->ipv4.arptable_filter);
68 static unsigned int arpt_out_hook(unsigned int hook,
70 const struct net_device *in,
71 const struct net_device *out,
72 int (*okfn)(struct sk_buff *))
74 return arpt_do_table(skb, hook, in, out,
75 dev_net(out)->ipv4.arptable_filter);
78 static struct nf_hook_ops arpt_ops[] __read_mostly = {
84 .priority = NF_IP_PRI_FILTER,
87 .hook = arpt_out_hook,
90 .hooknum = NF_ARP_OUT,
91 .priority = NF_IP_PRI_FILTER,
97 .hooknum = NF_ARP_FORWARD,
98 .priority = NF_IP_PRI_FILTER,
102 static int __net_init arptable_filter_net_init(struct net *net)
105 net->ipv4.arptable_filter =
106 arpt_register_table(net, &packet_filter, &initial_table.repl);
107 if (IS_ERR(net->ipv4.arptable_filter))
108 return PTR_ERR(net->ipv4.arptable_filter);
112 static void __net_exit arptable_filter_net_exit(struct net *net)
114 arpt_unregister_table(net->ipv4.arptable_filter);
117 static struct pernet_operations arptable_filter_net_ops = {
118 .init = arptable_filter_net_init,
119 .exit = arptable_filter_net_exit,
122 static int __init arptable_filter_init(void)
126 ret = register_pernet_subsys(&arptable_filter_net_ops);
130 ret = nf_register_hooks(arpt_ops, ARRAY_SIZE(arpt_ops));
136 unregister_pernet_subsys(&arptable_filter_net_ops);
140 static void __exit arptable_filter_fini(void)
142 nf_unregister_hooks(arpt_ops, ARRAY_SIZE(arpt_ops));
143 unregister_pernet_subsys(&arptable_filter_net_ops);
146 module_init(arptable_filter_init);
147 module_exit(arptable_filter_fini);