Commit | Line | Data |
---|---|---|
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 | |
2f711939 HFS |
19 | static int one = 1; |
20 | ||
fe2c6338 | 21 | static struct ctl_table ipv6_table_template[] = { |
1da177e4 | 22 | { |
1da177e4 | 23 | .procname = "bindv6only", |
99bc9c4e | 24 | .data = &init_net.ipv6.sysctl.bindv6only, |
1da177e4 LT |
25 | .maxlen = sizeof(int), |
26 | .mode = 0644, | |
6d9f239a | 27 | .proc_handler = proc_dointvec |
1da177e4 | 28 | }, |
509aba3b FLB |
29 | { |
30 | .procname = "anycast_src_echo_reply", | |
ec35b61e | 31 | .data = &init_net.ipv6.sysctl.anycast_src_echo_reply, |
509aba3b FLB |
32 | .maxlen = sizeof(int), |
33 | .mode = 0644, | |
34 | .proc_handler = proc_dointvec | |
35 | }, | |
6444f72b FF |
36 | { |
37 | .procname = "flowlabel_consistency", | |
38 | .data = &init_net.ipv6.sysctl.flowlabel_consistency, | |
39 | .maxlen = sizeof(int), | |
40 | .mode = 0644, | |
41 | .proc_handler = proc_dointvec | |
42 | }, | |
cb1ce2ef TH |
43 | { |
44 | .procname = "auto_flowlabels", | |
45 | .data = &init_net.ipv6.sysctl.auto_flowlabels, | |
46 | .maxlen = sizeof(int), | |
47 | .mode = 0644, | |
48 | .proc_handler = proc_dointvec | |
49 | }, | |
e110861f LC |
50 | { |
51 | .procname = "fwmark_reflect", | |
52 | .data = &init_net.ipv6.sysctl.fwmark_reflect, | |
53 | .maxlen = sizeof(int), | |
54 | .mode = 0644, | |
55 | .proc_handler = proc_dointvec | |
56 | }, | |
1855b7c3 HFS |
57 | { |
58 | .procname = "idgen_retries", | |
59 | .data = &init_net.ipv6.sysctl.idgen_retries, | |
60 | .maxlen = sizeof(int), | |
61 | .mode = 0644, | |
62 | .proc_handler = proc_dointvec, | |
63 | }, | |
64 | { | |
65 | .procname = "idgen_delay", | |
66 | .data = &init_net.ipv6.sysctl.idgen_delay, | |
67 | .maxlen = sizeof(int), | |
68 | .mode = 0644, | |
69 | .proc_handler = proc_dointvec_jiffies, | |
70 | }, | |
82a584b7 TH |
71 | { |
72 | .procname = "flowlabel_state_ranges", | |
73 | .data = &init_net.ipv6.sysctl.flowlabel_state_ranges, | |
74 | .maxlen = sizeof(int), | |
75 | .mode = 0644, | |
76 | .proc_handler = proc_dointvec | |
77 | }, | |
35a256fe TH |
78 | { |
79 | .procname = "ip_nonlocal_bind", | |
80 | .data = &init_net.ipv6.sysctl.ip_nonlocal_bind, | |
81 | .maxlen = sizeof(int), | |
82 | .mode = 0644, | |
83 | .proc_handler = proc_dointvec | |
84 | }, | |
f8572d8f | 85 | { } |
34ac2573 PE |
86 | }; |
87 | ||
fe2c6338 | 88 | static struct ctl_table ipv6_rotable[] = { |
1da177e4 | 89 | { |
1da177e4 LT |
90 | .procname = "mld_max_msf", |
91 | .data = &sysctl_mld_max_msf, | |
92 | .maxlen = sizeof(int), | |
93 | .mode = 0644, | |
6d9f239a | 94 | .proc_handler = proc_dointvec |
1da177e4 | 95 | }, |
2f711939 HFS |
96 | { |
97 | .procname = "mld_qrv", | |
98 | .data = &sysctl_mld_qrv, | |
99 | .maxlen = sizeof(int), | |
100 | .mode = 0644, | |
101 | .proc_handler = proc_dointvec_minmax, | |
102 | .extra1 = &one | |
103 | }, | |
f8572d8f | 104 | { } |
1da177e4 LT |
105 | }; |
106 | ||
2c8c1e72 | 107 | static int __net_init ipv6_sysctl_net_init(struct net *net) |
1da177e4 | 108 | { |
760f2d01 DL |
109 | struct ctl_table *ipv6_table; |
110 | struct ctl_table *ipv6_route_table; | |
111 | struct ctl_table *ipv6_icmp_table; | |
112 | int err; | |
113 | ||
114 | err = -ENOMEM; | |
115 | ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template), | |
116 | GFP_KERNEL); | |
117 | if (!ipv6_table) | |
118 | goto out; | |
6dceb036 | 119 | ipv6_table[0].data = &net->ipv6.sysctl.bindv6only; |
ec35b61e | 120 | ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply; |
6444f72b | 121 | ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency; |
cb1ce2ef | 122 | ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels; |
d247b6ab | 123 | ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect; |
1855b7c3 HFS |
124 | ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries; |
125 | ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay; | |
82a584b7 | 126 | ipv6_table[7].data = &net->ipv6.sysctl.flowlabel_state_ranges; |
35a256fe | 127 | ipv6_table[8].data = &net->ipv6.sysctl.ip_nonlocal_bind; |
760f2d01 DL |
128 | |
129 | ipv6_route_table = ipv6_route_sysctl_init(net); | |
130 | if (!ipv6_route_table) | |
131 | goto out_ipv6_table; | |
132 | ||
133 | ipv6_icmp_table = ipv6_icmp_sysctl_init(net); | |
134 | if (!ipv6_icmp_table) | |
135 | goto out_ipv6_route_table; | |
760f2d01 | 136 | |
6dceb036 EB |
137 | net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table); |
138 | if (!net->ipv6.sysctl.hdr) | |
760f2d01 DL |
139 | goto out_ipv6_icmp_table; |
140 | ||
6dceb036 EB |
141 | net->ipv6.sysctl.route_hdr = |
142 | register_net_sysctl(net, "net/ipv6/route", ipv6_route_table); | |
143 | if (!net->ipv6.sysctl.route_hdr) | |
144 | goto out_unregister_ipv6_table; | |
145 | ||
146 | net->ipv6.sysctl.icmp_hdr = | |
147 | register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table); | |
148 | if (!net->ipv6.sysctl.icmp_hdr) | |
149 | goto out_unregister_route_table; | |
150 | ||
760f2d01 DL |
151 | err = 0; |
152 | out: | |
153 | return err; | |
6dceb036 EB |
154 | out_unregister_route_table: |
155 | unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr); | |
156 | out_unregister_ipv6_table: | |
157 | unregister_net_sysctl_table(net->ipv6.sysctl.hdr); | |
760f2d01 DL |
158 | out_ipv6_icmp_table: |
159 | kfree(ipv6_icmp_table); | |
160 | out_ipv6_route_table: | |
161 | kfree(ipv6_route_table); | |
162 | out_ipv6_table: | |
163 | kfree(ipv6_table); | |
164 | goto out; | |
1da177e4 LT |
165 | } |
166 | ||
2c8c1e72 | 167 | static void __net_exit ipv6_sysctl_net_exit(struct net *net) |
89918fc2 | 168 | { |
760f2d01 DL |
169 | struct ctl_table *ipv6_table; |
170 | struct ctl_table *ipv6_route_table; | |
171 | struct ctl_table *ipv6_icmp_table; | |
172 | ||
6dceb036 EB |
173 | ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg; |
174 | ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg; | |
175 | ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg; | |
760f2d01 | 176 | |
6dceb036 EB |
177 | unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr); |
178 | unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr); | |
179 | unregister_net_sysctl_table(net->ipv6.sysctl.hdr); | |
760f2d01 DL |
180 | |
181 | kfree(ipv6_table); | |
182 | kfree(ipv6_route_table); | |
183 | kfree(ipv6_icmp_table); | |
89918fc2 DL |
184 | } |
185 | ||
186 | static struct pernet_operations ipv6_sysctl_net_ops = { | |
187 | .init = ipv6_sysctl_net_init, | |
188 | .exit = ipv6_sysctl_net_exit, | |
189 | }; | |
190 | ||
34ac2573 PE |
191 | static struct ctl_table_header *ip6_header; |
192 | ||
89918fc2 DL |
193 | int ipv6_sysctl_register(void) |
194 | { | |
c19a28e1 | 195 | int err = -ENOMEM; |
34ac2573 | 196 | |
43444757 | 197 | ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable); |
63159f29 | 198 | if (!ip6_header) |
34ac2573 PE |
199 | goto out; |
200 | ||
201 | err = register_pernet_subsys(&ipv6_sysctl_net_ops); | |
202 | if (err) | |
203 | goto err_pernet; | |
204 | out: | |
205 | return err; | |
206 | ||
207 | err_pernet: | |
208 | unregister_net_sysctl_table(ip6_header); | |
209 | goto out; | |
89918fc2 DL |
210 | } |
211 | ||
1da177e4 LT |
212 | void ipv6_sysctl_unregister(void) |
213 | { | |
34ac2573 | 214 | unregister_net_sysctl_table(ip6_header); |
89918fc2 | 215 | unregister_pernet_subsys(&ipv6_sysctl_net_ops); |
1da177e4 | 216 | } |