1 // SPDX-License-Identifier: GPL-2.0
3 * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem.
6 * YOSHIFUJI Hideaki @USAGI: added icmp sysctl table.
10 #include <linux/sysctl.h>
11 #include <linux/in6.h>
12 #include <linux/ipv6.h>
13 #include <linux/slab.h>
14 #include <linux/export.h>
15 #include <net/ndisc.h>
17 #include <net/addrconf.h>
18 #include <net/inet_frag.h>
19 #include <net/netevent.h>
20 #ifdef CONFIG_NETLABEL
21 #include <net/calipso.h>
25 static int flowlabel_reflect_max = 0x7;
26 static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX;
28 static int proc_rt6_multipath_hash_policy(struct ctl_table *table, int write,
29 void *buffer, size_t *lenp, loff_t *ppos)
34 net = container_of(table->data, struct net,
35 ipv6.sysctl.multipath_hash_policy);
36 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
37 if (write && ret == 0)
38 call_netevent_notifiers(NETEVENT_IPV6_MPATH_HASH_UPDATE, net);
43 static struct ctl_table ipv6_table_template[] = {
45 .procname = "bindv6only",
46 .data = &init_net.ipv6.sysctl.bindv6only,
49 .proc_handler = proc_dou8vec_minmax,
52 .procname = "anycast_src_echo_reply",
53 .data = &init_net.ipv6.sysctl.anycast_src_echo_reply,
56 .proc_handler = proc_dou8vec_minmax,
59 .procname = "flowlabel_consistency",
60 .data = &init_net.ipv6.sysctl.flowlabel_consistency,
63 .proc_handler = proc_dou8vec_minmax,
66 .procname = "auto_flowlabels",
67 .data = &init_net.ipv6.sysctl.auto_flowlabels,
70 .proc_handler = proc_dou8vec_minmax,
71 .extra2 = &auto_flowlabels_max
74 .procname = "fwmark_reflect",
75 .data = &init_net.ipv6.sysctl.fwmark_reflect,
78 .proc_handler = proc_dou8vec_minmax,
81 .procname = "idgen_retries",
82 .data = &init_net.ipv6.sysctl.idgen_retries,
83 .maxlen = sizeof(int),
85 .proc_handler = proc_dointvec,
88 .procname = "idgen_delay",
89 .data = &init_net.ipv6.sysctl.idgen_delay,
90 .maxlen = sizeof(int),
92 .proc_handler = proc_dointvec_jiffies,
95 .procname = "flowlabel_state_ranges",
96 .data = &init_net.ipv6.sysctl.flowlabel_state_ranges,
99 .proc_handler = proc_dou8vec_minmax,
102 .procname = "ip_nonlocal_bind",
103 .data = &init_net.ipv6.sysctl.ip_nonlocal_bind,
104 .maxlen = sizeof(u8),
106 .proc_handler = proc_dou8vec_minmax,
109 .procname = "flowlabel_reflect",
110 .data = &init_net.ipv6.sysctl.flowlabel_reflect,
111 .maxlen = sizeof(int),
113 .proc_handler = proc_dointvec_minmax,
114 .extra1 = SYSCTL_ZERO,
115 .extra2 = &flowlabel_reflect_max,
118 .procname = "max_dst_opts_number",
119 .data = &init_net.ipv6.sysctl.max_dst_opts_cnt,
120 .maxlen = sizeof(int),
122 .proc_handler = proc_dointvec
125 .procname = "max_hbh_opts_number",
126 .data = &init_net.ipv6.sysctl.max_hbh_opts_cnt,
127 .maxlen = sizeof(int),
129 .proc_handler = proc_dointvec
132 .procname = "max_dst_opts_length",
133 .data = &init_net.ipv6.sysctl.max_dst_opts_len,
134 .maxlen = sizeof(int),
136 .proc_handler = proc_dointvec
139 .procname = "max_hbh_length",
140 .data = &init_net.ipv6.sysctl.max_hbh_opts_len,
141 .maxlen = sizeof(int),
143 .proc_handler = proc_dointvec
146 .procname = "fib_multipath_hash_policy",
147 .data = &init_net.ipv6.sysctl.multipath_hash_policy,
148 .maxlen = sizeof(u8),
150 .proc_handler = proc_rt6_multipath_hash_policy,
151 .extra1 = SYSCTL_ZERO,
155 .procname = "seg6_flowlabel",
156 .data = &init_net.ipv6.sysctl.seg6_flowlabel,
157 .maxlen = sizeof(int),
159 .proc_handler = proc_dointvec
162 .procname = "fib_notify_on_flag_change",
163 .data = &init_net.ipv6.sysctl.fib_notify_on_flag_change,
164 .maxlen = sizeof(u8),
166 .proc_handler = proc_dou8vec_minmax,
167 .extra1 = SYSCTL_ZERO,
173 static struct ctl_table ipv6_rotable[] = {
175 .procname = "mld_max_msf",
176 .data = &sysctl_mld_max_msf,
177 .maxlen = sizeof(int),
179 .proc_handler = proc_dointvec
182 .procname = "mld_qrv",
183 .data = &sysctl_mld_qrv,
184 .maxlen = sizeof(int),
186 .proc_handler = proc_dointvec_minmax,
189 #ifdef CONFIG_NETLABEL
191 .procname = "calipso_cache_enable",
192 .data = &calipso_cache_enabled,
193 .maxlen = sizeof(int),
195 .proc_handler = proc_dointvec,
198 .procname = "calipso_cache_bucket_size",
199 .data = &calipso_cache_bucketsize,
200 .maxlen = sizeof(int),
202 .proc_handler = proc_dointvec,
204 #endif /* CONFIG_NETLABEL */
208 static int __net_init ipv6_sysctl_net_init(struct net *net)
210 struct ctl_table *ipv6_table;
211 struct ctl_table *ipv6_route_table;
212 struct ctl_table *ipv6_icmp_table;
216 ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
220 /* Update the variables to point into the current struct net */
221 for (i = 0; i < ARRAY_SIZE(ipv6_table_template) - 1; i++)
222 ipv6_table[i].data += (void *)net - (void *)&init_net;
224 ipv6_route_table = ipv6_route_sysctl_init(net);
225 if (!ipv6_route_table)
228 ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
229 if (!ipv6_icmp_table)
230 goto out_ipv6_route_table;
232 net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
233 if (!net->ipv6.sysctl.hdr)
234 goto out_ipv6_icmp_table;
236 net->ipv6.sysctl.route_hdr =
237 register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
238 if (!net->ipv6.sysctl.route_hdr)
239 goto out_unregister_ipv6_table;
241 net->ipv6.sysctl.icmp_hdr =
242 register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
243 if (!net->ipv6.sysctl.icmp_hdr)
244 goto out_unregister_route_table;
249 out_unregister_route_table:
250 unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
251 out_unregister_ipv6_table:
252 unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
254 kfree(ipv6_icmp_table);
255 out_ipv6_route_table:
256 kfree(ipv6_route_table);
262 static void __net_exit ipv6_sysctl_net_exit(struct net *net)
264 struct ctl_table *ipv6_table;
265 struct ctl_table *ipv6_route_table;
266 struct ctl_table *ipv6_icmp_table;
268 ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
269 ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
270 ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
272 unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
273 unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
274 unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
277 kfree(ipv6_route_table);
278 kfree(ipv6_icmp_table);
281 static struct pernet_operations ipv6_sysctl_net_ops = {
282 .init = ipv6_sysctl_net_init,
283 .exit = ipv6_sysctl_net_exit,
286 static struct ctl_table_header *ip6_header;
288 int ipv6_sysctl_register(void)
292 ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
296 err = register_pernet_subsys(&ipv6_sysctl_net_ops);
303 unregister_net_sysctl_table(ip6_header);
307 void ipv6_sysctl_unregister(void)
309 unregister_net_sysctl_table(ip6_header);
310 unregister_pernet_subsys(&ipv6_sysctl_net_ops);