blob: b4ba422f2714310025ab3d3437e588d54db4d8e1 [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>
12#include <net/ndisc.h>
13#include <net/ipv6.h>
14#include <net/addrconf.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070015#include <net/inet_frag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Daniel Lezcano760f2d02008-01-10 02:53:43 -080017extern struct ctl_table *ipv6_route_sysctl_init(struct net *net);
18extern struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
19
20static ctl_table ipv6_table_template[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 {
22 .ctl_name = NET_IPV6_ROUTE,
23 .procname = "route",
24 .maxlen = 0,
25 .mode = 0555,
Daniel Lezcano760f2d02008-01-10 02:53:43 -080026 .child = ipv6_route_table_template
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 },
28 {
29 .ctl_name = NET_IPV6_ICMP,
30 .procname = "icmp",
31 .maxlen = 0,
32 .mode = 0555,
Daniel Lezcano760f2d02008-01-10 02:53:43 -080033 .child = ipv6_icmp_table_template
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 },
35 {
36 .ctl_name = NET_IPV6_BINDV6ONLY,
37 .procname = "bindv6only",
Daniel Lezcano99bc9c42008-01-10 02:54:53 -080038 .data = &init_net.ipv6.sysctl.bindv6only,
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 .maxlen = sizeof(int),
40 .mode = 0644,
41 .proc_handler = &proc_dointvec
42 },
43 {
44 .ctl_name = NET_IPV6_IP6FRAG_HIGH_THRESH,
45 .procname = "ip6frag_high_thresh",
Daniel Lezcanoe71e0342008-01-10 02:56:03 -080046 .data = &init_net.ipv6.sysctl.frags.high_thresh,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .maxlen = sizeof(int),
48 .mode = 0644,
49 .proc_handler = &proc_dointvec
50 },
51 {
52 .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH,
53 .procname = "ip6frag_low_thresh",
Daniel Lezcanoe71e0342008-01-10 02:56:03 -080054 .data = &init_net.ipv6.sysctl.frags.low_thresh,
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 .maxlen = sizeof(int),
56 .mode = 0644,
57 .proc_handler = &proc_dointvec
58 },
59 {
60 .ctl_name = NET_IPV6_IP6FRAG_TIME,
61 .procname = "ip6frag_time",
Daniel Lezcanoe71e0342008-01-10 02:56:03 -080062 .data = &init_net.ipv6.sysctl.frags.timeout,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 .maxlen = sizeof(int),
64 .mode = 0644,
65 .proc_handler = &proc_dointvec_jiffies,
66 .strategy = &sysctl_jiffies,
67 },
68 {
69 .ctl_name = NET_IPV6_IP6FRAG_SECRET_INTERVAL,
70 .procname = "ip6frag_secret_interval",
Daniel Lezcanoe71e0342008-01-10 02:56:03 -080071 .data = &init_net.ipv6.sysctl.frags.secret_interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 .maxlen = sizeof(int),
73 .mode = 0644,
74 .proc_handler = &proc_dointvec_jiffies,
75 .strategy = &sysctl_jiffies
76 },
77 {
78 .ctl_name = NET_IPV6_MLD_MAX_MSF,
79 .procname = "mld_max_msf",
80 .data = &sysctl_mld_max_msf,
81 .maxlen = sizeof(int),
82 .mode = 0644,
83 .proc_handler = &proc_dointvec
84 },
85 { .ctl_name = 0 }
86};
87
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -080088struct ctl_path net_ipv6_ctl_path[] = {
Pavel Emelyanov4d43b782007-12-05 01:44:02 -080089 { .procname = "net", .ctl_name = CTL_NET, },
90 { .procname = "ipv6", .ctl_name = NET_IPV6, },
91 { },
92};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -080093EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
Pavel Emelyanov4d43b782007-12-05 01:44:02 -080094
Daniel Lezcano89918fc2008-01-10 02:49:34 -080095static int ipv6_sysctl_net_init(struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Daniel Lezcano760f2d02008-01-10 02:53:43 -080097 struct ctl_table *ipv6_table;
98 struct ctl_table *ipv6_route_table;
99 struct ctl_table *ipv6_icmp_table;
100 int err;
101
102 err = -ENOMEM;
103 ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
104 GFP_KERNEL);
105 if (!ipv6_table)
106 goto out;
107
108 ipv6_route_table = ipv6_route_sysctl_init(net);
109 if (!ipv6_route_table)
110 goto out_ipv6_table;
111
112 ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
113 if (!ipv6_icmp_table)
114 goto out_ipv6_route_table;
115
Daniel Lezcano49905092008-01-10 03:01:01 -0800116 ipv6_route_table[0].data = &net->ipv6.sysctl.flush_delay;
117 /* ipv6_route_table[1].data will be handled when we have
118 routes per namespace */
119 ipv6_route_table[2].data = &net->ipv6.sysctl.ip6_rt_max_size;
120 ipv6_route_table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
121 ipv6_route_table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout;
122 ipv6_route_table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval;
123 ipv6_route_table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity;
124 ipv6_route_table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires;
125 ipv6_route_table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss;
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800126 ipv6_table[0].child = ipv6_route_table;
Daniel Lezcano49905092008-01-10 03:01:01 -0800127
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800128 ipv6_table[1].child = ipv6_icmp_table;
129
Daniel Lezcano99bc9c42008-01-10 02:54:53 -0800130 ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
Daniel Lezcanoe71e0342008-01-10 02:56:03 -0800131 ipv6_table[3].data = &net->ipv6.sysctl.frags.high_thresh;
132 ipv6_table[4].data = &net->ipv6.sysctl.frags.low_thresh;
133 ipv6_table[5].data = &net->ipv6.sysctl.frags.timeout;
134 ipv6_table[6].data = &net->ipv6.sysctl.frags.secret_interval;
Daniel Lezcano99bc9c42008-01-10 02:54:53 -0800135
Daniel Lezcano7c765092008-01-10 02:57:43 -0800136 /* We don't want this value to be per namespace, it should be global
137 to all namespaces, so make it read-only when we are not in the
138 init network namespace */
139 if (net != &init_net)
140 ipv6_table[7].mode = 0444;
141
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800142 net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
143 ipv6_table);
144 if (!net->ipv6.sysctl.table)
Daniel Lezcano291480c2008-01-10 02:47:55 -0800145 return -ENOMEM;
146
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800147 if (!net->ipv6.sysctl.table)
148 goto out_ipv6_icmp_table;
Daniel Lezcano291480c2008-01-10 02:47:55 -0800149
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800150 err = 0;
151out:
152 return err;
153
154out_ipv6_icmp_table:
155 kfree(ipv6_icmp_table);
156out_ipv6_route_table:
157 kfree(ipv6_route_table);
158out_ipv6_table:
159 kfree(ipv6_table);
160 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800163static void ipv6_sysctl_net_exit(struct net *net)
164{
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800165 struct ctl_table *ipv6_table;
166 struct ctl_table *ipv6_route_table;
167 struct ctl_table *ipv6_icmp_table;
168
169 ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
170 ipv6_route_table = ipv6_table[0].child;
171 ipv6_icmp_table = ipv6_table[1].child;
172
173 unregister_net_sysctl_table(net->ipv6.sysctl.table);
174
175 kfree(ipv6_table);
176 kfree(ipv6_route_table);
177 kfree(ipv6_icmp_table);
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800178}
179
180static struct pernet_operations ipv6_sysctl_net_ops = {
181 .init = ipv6_sysctl_net_init,
182 .exit = ipv6_sysctl_net_exit,
183};
184
185int ipv6_sysctl_register(void)
186{
187 return register_pernet_subsys(&ipv6_sysctl_net_ops);
188}
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190void ipv6_sysctl_unregister(void)
191{
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800192 unregister_pernet_subsys(&ipv6_sysctl_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}