blob: db48aebd9c470c2d3a40c7a4250b67887250985e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/in6.h>
11#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040013#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <net/ndisc.h>
15#include <net/ipv6.h>
16#include <net/addrconf.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070017#include <net/inet_frag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Hannes Frederic Sowa2f711932014-09-02 15:49:25 +020019static int one = 1;
20
Joe Perchesfe2c6332013-06-11 23:04:25 -070021static struct ctl_table ipv6_table_template[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 .procname = "bindv6only",
Daniel Lezcano99bc9c42008-01-10 02:54:53 -080024 .data = &init_net.ipv6.sysctl.bindv6only,
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 .maxlen = sizeof(int),
26 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080027 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 },
FX Le Bail509aba32014-01-07 14:57:27 +010029 {
30 .procname = "anycast_src_echo_reply",
FX Le Bailec35b612014-01-13 15:59:01 +010031 .data = &init_net.ipv6.sysctl.anycast_src_echo_reply,
FX Le Bail509aba32014-01-07 14:57:27 +010032 .maxlen = sizeof(int),
33 .mode = 0644,
34 .proc_handler = proc_dointvec
35 },
Florent Fourcot6444f722014-01-17 17:15:05 +010036 {
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 },
Lorenzo Colittie1108612014-05-13 10:17:33 -070043 {
Tom Herbertcb1ce2e2014-07-01 21:33:10 -070044 .procname = "auto_flowlabels",
45 .data = &init_net.ipv6.sysctl.auto_flowlabels,
46 .maxlen = sizeof(int),
47 .mode = 0644,
48 .proc_handler = proc_dointvec
49 },
50 {
Lorenzo Colittie1108612014-05-13 10:17:33 -070051 .procname = "fwmark_reflect",
52 .data = &init_net.ipv6.sysctl.fwmark_reflect,
53 .maxlen = sizeof(int),
54 .mode = 0644,
55 .proc_handler = proc_dointvec
56 },
Hannes Frederic Sowa1855b7c2015-03-23 23:36:05 +010057 {
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 },
Tom Herbert82a584b2015-04-29 15:33:21 -070071 {
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 },
Tom Herbert35a256f2015-07-08 16:58:22 -070078 {
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 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -080085 { }
Pavel Emelyanov34ac2572008-05-19 13:53:30 -070086};
87
Joe Perchesfe2c6332013-06-11 23:04:25 -070088static struct ctl_table ipv6_rotable[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 .procname = "mld_max_msf",
91 .data = &sysctl_mld_max_msf,
92 .maxlen = sizeof(int),
93 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080094 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 },
Hannes Frederic Sowa2f711932014-09-02 15:49:25 +020096 {
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 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800104 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +0000107static int __net_init ipv6_sysctl_net_init(struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800109 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;
Eric W. Biederman6dceb032012-04-19 13:37:09 +0000119 ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
FX Le Bailec35b612014-01-13 15:59:01 +0100120 ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply;
Florent Fourcot6444f722014-01-17 17:15:05 +0100121 ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency;
Tom Herbertcb1ce2e2014-07-01 21:33:10 -0700122 ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels;
David S. Millerd247b6a2014-08-05 18:46:26 -0700123 ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect;
Hannes Frederic Sowa1855b7c2015-03-23 23:36:05 +0100124 ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries;
125 ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay;
Tom Herbert82a584b2015-04-29 15:33:21 -0700126 ipv6_table[7].data = &net->ipv6.sysctl.flowlabel_state_ranges;
Tom Herbert35a256f2015-07-08 16:58:22 -0700127 ipv6_table[8].data = &net->ipv6.sysctl.ip_nonlocal_bind;
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800128
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;
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800136
Eric W. Biederman6dceb032012-04-19 13:37:09 +0000137 net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
138 if (!net->ipv6.sysctl.hdr)
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800139 goto out_ipv6_icmp_table;
Daniel Lezcano291480c2008-01-10 02:47:55 -0800140
Eric W. Biederman6dceb032012-04-19 13:37:09 +0000141 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
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800151 err = 0;
152out:
153 return err;
Eric W. Biederman6dceb032012-04-19 13:37:09 +0000154out_unregister_route_table:
155 unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
156out_unregister_ipv6_table:
157 unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800158out_ipv6_icmp_table:
159 kfree(ipv6_icmp_table);
160out_ipv6_route_table:
161 kfree(ipv6_route_table);
162out_ipv6_table:
163 kfree(ipv6_table);
164 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +0000167static void __net_exit ipv6_sysctl_net_exit(struct net *net)
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800168{
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800169 struct ctl_table *ipv6_table;
170 struct ctl_table *ipv6_route_table;
171 struct ctl_table *ipv6_icmp_table;
172
Eric W. Biederman6dceb032012-04-19 13:37:09 +0000173 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;
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800176
Eric W. Biederman6dceb032012-04-19 13:37:09 +0000177 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);
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800180
181 kfree(ipv6_table);
182 kfree(ipv6_route_table);
183 kfree(ipv6_icmp_table);
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800184}
185
186static struct pernet_operations ipv6_sysctl_net_ops = {
187 .init = ipv6_sysctl_net_init,
188 .exit = ipv6_sysctl_net_exit,
189};
190
Pavel Emelyanov34ac2572008-05-19 13:53:30 -0700191static struct ctl_table_header *ip6_header;
192
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800193int ipv6_sysctl_register(void)
194{
Fernando Carrijoc19a28e2009-01-07 18:09:08 -0800195 int err = -ENOMEM;
Pavel Emelyanov34ac2572008-05-19 13:53:30 -0700196
Eric W. Biederman43444752012-04-19 13:22:55 +0000197 ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
Ian Morris63159f22015-03-29 14:00:04 +0100198 if (!ip6_header)
Pavel Emelyanov34ac2572008-05-19 13:53:30 -0700199 goto out;
200
201 err = register_pernet_subsys(&ipv6_sysctl_net_ops);
202 if (err)
203 goto err_pernet;
204out:
205 return err;
206
207err_pernet:
208 unregister_net_sysctl_table(ip6_header);
209 goto out;
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800210}
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212void ipv6_sysctl_unregister(void)
213{
Pavel Emelyanov34ac2572008-05-19 13:53:30 -0700214 unregister_net_sysctl_table(ip6_header);
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800215 unregister_pernet_subsys(&ipv6_sysctl_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}