netfilter: xtables: use xt_table for hook instantiation
[linux-2.6.git] / net / ipv6 / netfilter / ip6table_raw.c
1 /*
2  * IPv6 raw table, a port of the IPv4 raw table to IPv6
3  *
4  * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5  */
6 #include <linux/module.h>
7 #include <linux/netfilter_ipv6/ip6_tables.h>
8
9 #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
10
11 static const struct
12 {
13         struct ip6t_replace repl;
14         struct ip6t_standard entries[2];
15         struct ip6t_error term;
16 } initial_table __net_initdata = {
17         .repl = {
18                 .name = "raw",
19                 .valid_hooks = RAW_VALID_HOOKS,
20                 .num_entries = 3,
21                 .size = sizeof(struct ip6t_standard) * 2 + sizeof(struct ip6t_error),
22                 .hook_entry = {
23                         [NF_INET_PRE_ROUTING] = 0,
24                         [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
25                 },
26                 .underflow = {
27                         [NF_INET_PRE_ROUTING] = 0,
28                         [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
29                 },
30         },
31         .entries = {
32                 IP6T_STANDARD_INIT(NF_ACCEPT),  /* PRE_ROUTING */
33                 IP6T_STANDARD_INIT(NF_ACCEPT),  /* LOCAL_OUT */
34         },
35         .term = IP6T_ERROR_INIT,                /* ERROR */
36 };
37
38 static const struct xt_table packet_raw = {
39         .name = "raw",
40         .valid_hooks = RAW_VALID_HOOKS,
41         .me = THIS_MODULE,
42         .af = NFPROTO_IPV6,
43         .priority = NF_IP6_PRI_FIRST,
44 };
45
46 /* The work comes in here from netfilter.c. */
47 static unsigned int
48 ip6table_raw_hook(unsigned int hook, struct sk_buff *skb,
49                   const struct net_device *in, const struct net_device *out,
50                   int (*okfn)(struct sk_buff *))
51 {
52         const struct net *net = dev_net((in != NULL) ? in : out);
53
54         return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw);
55 }
56
57 static struct nf_hook_ops *rawtable_ops __read_mostly;
58
59 static int __net_init ip6table_raw_net_init(struct net *net)
60 {
61         /* Register table */
62         net->ipv6.ip6table_raw =
63                 ip6t_register_table(net, &packet_raw, &initial_table.repl);
64         if (IS_ERR(net->ipv6.ip6table_raw))
65                 return PTR_ERR(net->ipv6.ip6table_raw);
66         return 0;
67 }
68
69 static void __net_exit ip6table_raw_net_exit(struct net *net)
70 {
71         ip6t_unregister_table(net, net->ipv6.ip6table_raw);
72 }
73
74 static struct pernet_operations ip6table_raw_net_ops = {
75         .init = ip6table_raw_net_init,
76         .exit = ip6table_raw_net_exit,
77 };
78
79 static int __init ip6table_raw_init(void)
80 {
81         int ret;
82
83         ret = register_pernet_subsys(&ip6table_raw_net_ops);
84         if (ret < 0)
85                 return ret;
86
87         /* Register hooks */
88         rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
89         if (IS_ERR(rawtable_ops)) {
90                 ret = PTR_ERR(rawtable_ops);
91                 goto cleanup_table;
92         }
93
94         return ret;
95
96  cleanup_table:
97         unregister_pernet_subsys(&ip6table_raw_net_ops);
98         return ret;
99 }
100
101 static void __exit ip6table_raw_fini(void)
102 {
103         xt_hook_unlink(&packet_raw, rawtable_ops);
104         unregister_pernet_subsys(&ip6table_raw_net_ops);
105 }
106
107 module_init(ip6table_raw_init);
108 module_exit(ip6table_raw_fini);
109 MODULE_LICENSE("GPL");