net: Add export.h for EXPORT_SYMBOL/THIS_MODULE to non-modules
[linux-2.6-block.git] / net / ipv6 / sysctl_net_ipv6.c
CommitLineData
1da177e4
LT
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>
1da177e4
LT
10#include <linux/in6.h>
11#include <linux/ipv6.h>
5a0e3ad6 12#include <linux/slab.h>
bc3b2d7f 13#include <linux/export.h>
1da177e4
LT
14#include <net/ndisc.h>
15#include <net/ipv6.h>
16#include <net/addrconf.h>
04128f23 17#include <net/inet_frag.h>
1da177e4 18
bf36076a
EB
19static struct ctl_table empty[1];
20
9d2a8fa9
EB
21static ctl_table ipv6_static_skeleton[] = {
22 {
23 .procname = "neigh",
24 .maxlen = 0,
25 .mode = 0555,
26 .child = empty,
27 },
28 { }
29};
30
760f2d01 31static ctl_table ipv6_table_template[] = {
1da177e4 32 {
1da177e4
LT
33 .procname = "route",
34 .maxlen = 0,
35 .mode = 0555,
760f2d01 36 .child = ipv6_route_table_template
1da177e4
LT
37 },
38 {
1da177e4
LT
39 .procname = "icmp",
40 .maxlen = 0,
41 .mode = 0555,
760f2d01 42 .child = ipv6_icmp_table_template
1da177e4
LT
43 },
44 {
1da177e4 45 .procname = "bindv6only",
99bc9c4e 46 .data = &init_net.ipv6.sysctl.bindv6only,
1da177e4
LT
47 .maxlen = sizeof(int),
48 .mode = 0644,
6d9f239a 49 .proc_handler = proc_dointvec
1da177e4 50 },
f8572d8f 51 { }
34ac2573
PE
52};
53
81e43213 54static ctl_table ipv6_rotable[] = {
1da177e4 55 {
1da177e4
LT
56 .procname = "mld_max_msf",
57 .data = &sysctl_mld_max_msf,
58 .maxlen = sizeof(int),
59 .mode = 0644,
6d9f239a 60 .proc_handler = proc_dointvec
1da177e4 61 },
f8572d8f 62 { }
1da177e4
LT
63};
64
3d7cc2ba 65struct ctl_path net_ipv6_ctl_path[] = {
f8572d8f
EB
66 { .procname = "net", },
67 { .procname = "ipv6", },
4d43b78a 68 { },
1da177e4 69};
3d7cc2ba 70EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
1da177e4 71
2c8c1e72 72static int __net_init ipv6_sysctl_net_init(struct net *net)
1da177e4 73{
760f2d01
DL
74 struct ctl_table *ipv6_table;
75 struct ctl_table *ipv6_route_table;
76 struct ctl_table *ipv6_icmp_table;
77 int err;
78
79 err = -ENOMEM;
80 ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
81 GFP_KERNEL);
82 if (!ipv6_table)
83 goto out;
84
85 ipv6_route_table = ipv6_route_sysctl_init(net);
86 if (!ipv6_route_table)
87 goto out_ipv6_table;
5ee09105 88 ipv6_table[0].child = ipv6_route_table;
760f2d01
DL
89
90 ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
91 if (!ipv6_icmp_table)
92 goto out_ipv6_route_table;
760f2d01
DL
93 ipv6_table[1].child = ipv6_icmp_table;
94
99bc9c4e
DL
95 ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
96
760f2d01
DL
97 net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
98 ipv6_table);
760f2d01
DL
99 if (!net->ipv6.sysctl.table)
100 goto out_ipv6_icmp_table;
101
102 err = 0;
103out:
104 return err;
291480c0 105
760f2d01
DL
106out_ipv6_icmp_table:
107 kfree(ipv6_icmp_table);
108out_ipv6_route_table:
109 kfree(ipv6_route_table);
110out_ipv6_table:
111 kfree(ipv6_table);
112 goto out;
1da177e4
LT
113}
114
2c8c1e72 115static void __net_exit ipv6_sysctl_net_exit(struct net *net)
89918fc2 116{
760f2d01
DL
117 struct ctl_table *ipv6_table;
118 struct ctl_table *ipv6_route_table;
119 struct ctl_table *ipv6_icmp_table;
120
121 ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
122 ipv6_route_table = ipv6_table[0].child;
123 ipv6_icmp_table = ipv6_table[1].child;
124
125 unregister_net_sysctl_table(net->ipv6.sysctl.table);
126
127 kfree(ipv6_table);
128 kfree(ipv6_route_table);
129 kfree(ipv6_icmp_table);
89918fc2
DL
130}
131
132static struct pernet_operations ipv6_sysctl_net_ops = {
133 .init = ipv6_sysctl_net_init,
134 .exit = ipv6_sysctl_net_exit,
135};
136
34ac2573
PE
137static struct ctl_table_header *ip6_header;
138
89918fc2
DL
139int ipv6_sysctl_register(void)
140{
c19a28e1 141 int err = -ENOMEM;
34ac2573 142
81e43213 143 ip6_header = register_net_sysctl_rotable(net_ipv6_ctl_path, ipv6_rotable);
34ac2573
PE
144 if (ip6_header == NULL)
145 goto out;
146
147 err = register_pernet_subsys(&ipv6_sysctl_net_ops);
148 if (err)
149 goto err_pernet;
150out:
151 return err;
152
153err_pernet:
154 unregister_net_sysctl_table(ip6_header);
155 goto out;
89918fc2
DL
156}
157
1da177e4
LT
158void ipv6_sysctl_unregister(void)
159{
34ac2573 160 unregister_net_sysctl_table(ip6_header);
89918fc2 161 unregister_pernet_subsys(&ipv6_sysctl_net_ops);
1da177e4 162}
eeb61f71
AV
163
164static struct ctl_table_header *ip6_base;
165
166int ipv6_static_sysctl_register(void)
167{
9d2a8fa9 168 ip6_base = register_sysctl_paths(net_ipv6_ctl_path, ipv6_static_skeleton);
eeb61f71
AV
169 if (ip6_base == NULL)
170 return -ENOMEM;
171 return 0;
172}
173
174void ipv6_static_sysctl_unregister(void)
175{
176 unregister_net_sysctl_table(ip6_base);
177}