net: spread __net_init, __net_exit
[safe/jmp/linux-2.6] / net / ipv6 / sysctl_net_ipv6.c
1 /*
2  * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem.
3  *
4  * Changes:
5  * YOSHIFUJI Hideaki @USAGI:    added icmp sysctl table.
6  */
7
8 #include <linux/mm.h>
9 #include <linux/sysctl.h>
10 #include <linux/in6.h>
11 #include <linux/ipv6.h>
12 #include <net/ndisc.h>
13 #include <net/ipv6.h>
14 #include <net/addrconf.h>
15 #include <net/inet_frag.h>
16
17 static ctl_table ipv6_table_template[] = {
18         {
19                 .procname       = "route",
20                 .maxlen         = 0,
21                 .mode           = 0555,
22                 .child          = ipv6_route_table_template
23         },
24         {
25                 .procname       = "icmp",
26                 .maxlen         = 0,
27                 .mode           = 0555,
28                 .child          = ipv6_icmp_table_template
29         },
30         {
31                 .procname       = "bindv6only",
32                 .data           = &init_net.ipv6.sysctl.bindv6only,
33                 .maxlen         = sizeof(int),
34                 .mode           = 0644,
35                 .proc_handler   = proc_dointvec
36         },
37         { }
38 };
39
40 static ctl_table ipv6_rotable[] = {
41         {
42                 .procname       = "mld_max_msf",
43                 .data           = &sysctl_mld_max_msf,
44                 .maxlen         = sizeof(int),
45                 .mode           = 0644,
46                 .proc_handler   = proc_dointvec
47         },
48         { }
49 };
50
51 struct ctl_path net_ipv6_ctl_path[] = {
52         { .procname = "net", },
53         { .procname = "ipv6", },
54         { },
55 };
56 EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
57
58 static int __net_init ipv6_sysctl_net_init(struct net *net)
59 {
60         struct ctl_table *ipv6_table;
61         struct ctl_table *ipv6_route_table;
62         struct ctl_table *ipv6_icmp_table;
63         int err;
64
65         err = -ENOMEM;
66         ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
67                              GFP_KERNEL);
68         if (!ipv6_table)
69                 goto out;
70
71         ipv6_route_table = ipv6_route_sysctl_init(net);
72         if (!ipv6_route_table)
73                 goto out_ipv6_table;
74         ipv6_table[0].child = ipv6_route_table;
75
76         ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
77         if (!ipv6_icmp_table)
78                 goto out_ipv6_route_table;
79         ipv6_table[1].child = ipv6_icmp_table;
80
81         ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
82
83         net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
84                                                            ipv6_table);
85         if (!net->ipv6.sysctl.table)
86                 goto out_ipv6_icmp_table;
87
88         err = 0;
89 out:
90         return err;
91
92 out_ipv6_icmp_table:
93         kfree(ipv6_icmp_table);
94 out_ipv6_route_table:
95         kfree(ipv6_route_table);
96 out_ipv6_table:
97         kfree(ipv6_table);
98         goto out;
99 }
100
101 static void __net_exit ipv6_sysctl_net_exit(struct net *net)
102 {
103         struct ctl_table *ipv6_table;
104         struct ctl_table *ipv6_route_table;
105         struct ctl_table *ipv6_icmp_table;
106
107         ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
108         ipv6_route_table = ipv6_table[0].child;
109         ipv6_icmp_table = ipv6_table[1].child;
110
111         unregister_net_sysctl_table(net->ipv6.sysctl.table);
112
113         kfree(ipv6_table);
114         kfree(ipv6_route_table);
115         kfree(ipv6_icmp_table);
116 }
117
118 static struct pernet_operations ipv6_sysctl_net_ops = {
119         .init = ipv6_sysctl_net_init,
120         .exit = ipv6_sysctl_net_exit,
121 };
122
123 static struct ctl_table_header *ip6_header;
124
125 int ipv6_sysctl_register(void)
126 {
127         int err = -ENOMEM;
128
129         ip6_header = register_net_sysctl_rotable(net_ipv6_ctl_path, ipv6_rotable);
130         if (ip6_header == NULL)
131                 goto out;
132
133         err = register_pernet_subsys(&ipv6_sysctl_net_ops);
134         if (err)
135                 goto err_pernet;
136 out:
137         return err;
138
139 err_pernet:
140         unregister_net_sysctl_table(ip6_header);
141         goto out;
142 }
143
144 void ipv6_sysctl_unregister(void)
145 {
146         unregister_net_sysctl_table(ip6_header);
147         unregister_pernet_subsys(&ipv6_sysctl_net_ops);
148 }
149
150 static struct ctl_table_header *ip6_base;
151
152 int ipv6_static_sysctl_register(void)
153 {
154         static struct ctl_table empty[1];
155         ip6_base = register_sysctl_paths(net_ipv6_ctl_path, empty);
156         if (ip6_base == NULL)
157                 return -ENOMEM;
158         return 0;
159 }
160
161 void ipv6_static_sysctl_unregister(void)
162 {
163         unregister_net_sysctl_table(ip6_base);
164 }