2 * Filtering ARP tables module.
4 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
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");
14 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
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(unsigned int hook
, 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
, hook
, in
, out
, net
->ipv4
.arptable_filter
);
39 static struct nf_hook_ops
*arpfilter_ops __read_mostly
;
41 static int __net_init
arptable_filter_net_init(struct net
*net
)
43 struct arpt_replace
*repl
;
45 repl
= arpt_alloc_initial_table(&packet_filter
);
48 net
->ipv4
.arptable_filter
=
49 arpt_register_table(net
, &packet_filter
, repl
);
51 if (IS_ERR(net
->ipv4
.arptable_filter
))
52 return PTR_ERR(net
->ipv4
.arptable_filter
);
56 static void __net_exit
arptable_filter_net_exit(struct net
*net
)
58 arpt_unregister_table(net
->ipv4
.arptable_filter
);
61 static struct pernet_operations arptable_filter_net_ops
= {
62 .init
= arptable_filter_net_init
,
63 .exit
= arptable_filter_net_exit
,
66 static int __init
arptable_filter_init(void)
70 ret
= register_pernet_subsys(&arptable_filter_net_ops
);
74 arpfilter_ops
= xt_hook_link(&packet_filter
, arptable_filter_hook
);
75 if (IS_ERR(arpfilter_ops
)) {
76 ret
= PTR_ERR(arpfilter_ops
);
82 unregister_pernet_subsys(&arptable_filter_net_ops
);
86 static void __exit
arptable_filter_fini(void)
88 xt_hook_unlink(&packet_filter
, arpfilter_ops
);
89 unregister_pernet_subsys(&arptable_filter_net_ops
);
92 module_init(arptable_filter_init
);
93 module_exit(arptable_filter_fini
);