1
2
3
4
5
6#include <linux/module.h>
7#include <linux/netfilter_ipv6/ip6_tables.h>
8#include <linux/slab.h>
9
10#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
11
12static const struct xt_table packet_raw = {
13 .name = "raw",
14 .valid_hooks = RAW_VALID_HOOKS,
15 .me = THIS_MODULE,
16 .af = NFPROTO_IPV6,
17 .priority = NF_IP6_PRI_RAW,
18};
19
20
21static unsigned int
22ip6table_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
23 const struct net_device *in, const struct net_device *out,
24 int (*okfn)(struct sk_buff *))
25{
26 const struct net *net = dev_net((in != NULL) ? in : out);
27
28 return ip6t_do_table(skb, ops->hooknum, in, out,
29 net->ipv6.ip6table_raw);
30}
31
32static struct nf_hook_ops *rawtable_ops __read_mostly;
33
34static int __net_init ip6table_raw_net_init(struct net *net)
35{
36 struct ip6t_replace *repl;
37
38 repl = ip6t_alloc_initial_table(&packet_raw);
39 if (repl == NULL)
40 return -ENOMEM;
41 net->ipv6.ip6table_raw =
42 ip6t_register_table(net, &packet_raw, repl);
43 kfree(repl);
44 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_raw);
45}
46
47static void __net_exit ip6table_raw_net_exit(struct net *net)
48{
49 ip6t_unregister_table(net, net->ipv6.ip6table_raw);
50}
51
52static struct pernet_operations ip6table_raw_net_ops = {
53 .init = ip6table_raw_net_init,
54 .exit = ip6table_raw_net_exit,
55};
56
57static int __init ip6table_raw_init(void)
58{
59 int ret;
60
61 ret = register_pernet_subsys(&ip6table_raw_net_ops);
62 if (ret < 0)
63 return ret;
64
65
66 rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
67 if (IS_ERR(rawtable_ops)) {
68 ret = PTR_ERR(rawtable_ops);
69 goto cleanup_table;
70 }
71
72 return ret;
73
74 cleanup_table:
75 unregister_pernet_subsys(&ip6table_raw_net_ops);
76 return ret;
77}
78
79static void __exit ip6table_raw_fini(void)
80{
81 xt_hook_unlink(&packet_raw, rawtable_ops);
82 unregister_pernet_subsys(&ip6table_raw_net_ops);
83}
84
85module_init(ip6table_raw_init);
86module_exit(ip6table_raw_fini);
87MODULE_LICENSE("GPL");
88