blob: 4cb9cd2f2c390fc14289f918da8098af0549f5f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Begun April 1, 1996, Mike Shaver.
5 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
6 */
7
8#include <linux/mm.h>
9#include <linux/module.h>
10#include <linux/sysctl.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030011#include <linux/igmp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020012#include <linux/inetdevice.h>
Stephen Hemminger227b60f2007-10-10 17:30:46 -070013#include <linux/seqlock.h>
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -080014#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000016#include <linux/nsproxy.h>
Glauber Costa3dc43e32011-12-11 21:47:05 +000017#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030019#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <net/ip.h>
21#include <net/route.h>
22#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080023#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070024#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070025#include <net/inet_frag.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000026#include <net/ping.h>
Glauber Costa3aaabe22011-12-11 21:47:06 +000027#include <net/tcp_memcontrol.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Herbert Xu89cee8b2005-12-13 23:14:27 -080029static int zero;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090030static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static int ip_local_port_range_min[] = { 1, 1 };
32static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000033static int tcp_adv_win_scale_min = -31;
34static int tcp_adv_win_scale_max = 31;
Eric Dumazet249fab72010-12-13 12:16:14 -080035static int ip_ttl_min = 1;
36static int ip_ttl_max = 255;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000037static int ip_ping_group_range_min[] = { 0, 0 };
38static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Stephen Hemminger227b60f2007-10-10 17:30:46 -070040/* Update system visible IP port range */
41static void set_local_port_range(int range[2])
42{
Eric Dumazet3c689b72008-10-08 14:18:04 -070043 write_seqlock(&sysctl_local_ports.lock);
44 sysctl_local_ports.range[0] = range[0];
45 sysctl_local_ports.range[1] = range[1];
46 write_sequnlock(&sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070047}
48
49/* Validate changes from /proc interface. */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070050static int ipv4_local_port_range(ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070051 void __user *buffer,
52 size_t *lenp, loff_t *ppos)
53{
54 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070055 int range[2];
Stephen Hemminger227b60f2007-10-10 17:30:46 -070056 ctl_table tmp = {
57 .data = &range,
58 .maxlen = sizeof(range),
59 .mode = table->mode,
60 .extra1 = &ip_local_port_range_min,
61 .extra2 = &ip_local_port_range_max,
62 };
63
Eric Dumazet3c689b72008-10-08 14:18:04 -070064 inet_get_local_port_range(range, range + 1);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070065 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070066
67 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070068 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070069 ret = -EINVAL;
70 else
71 set_local_port_range(range);
72 }
73
74 return ret;
75}
76
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000077
Eric Dumazete6560d42011-12-14 03:51:28 +000078static void inet_get_ping_group_range_table(struct ctl_table *table, gid_t *low, gid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000079{
80 gid_t *data = table->data;
81 unsigned seq;
82 do {
83 seq = read_seqbegin(&sysctl_local_ports.lock);
84
85 *low = data[0];
86 *high = data[1];
87 } while (read_seqretry(&sysctl_local_ports.lock, seq));
88}
89
90/* Update system visible IP port range */
Eric Dumazete6560d42011-12-14 03:51:28 +000091static void set_ping_group_range(struct ctl_table *table, gid_t range[2])
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000092{
93 gid_t *data = table->data;
94 write_seqlock(&sysctl_local_ports.lock);
95 data[0] = range[0];
96 data[1] = range[1];
97 write_sequnlock(&sysctl_local_ports.lock);
98}
99
100/* Validate changes from /proc interface. */
101static int ipv4_ping_group_range(ctl_table *table, int write,
102 void __user *buffer,
103 size_t *lenp, loff_t *ppos)
104{
105 int ret;
106 gid_t range[2];
107 ctl_table tmp = {
108 .data = &range,
109 .maxlen = sizeof(range),
110 .mode = table->mode,
111 .extra1 = &ip_ping_group_range_min,
112 .extra2 = &ip_ping_group_range_max,
113 };
114
115 inet_get_ping_group_range_table(table, range, range + 1);
116 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
117
118 if (write && ret == 0)
119 set_ping_group_range(table, range);
120
121 return ret;
122}
123
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700124static int proc_tcp_congestion_control(ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700125 void __user *buffer, size_t *lenp, loff_t *ppos)
126{
127 char val[TCP_CA_NAME_MAX];
128 ctl_table tbl = {
129 .data = val,
130 .maxlen = TCP_CA_NAME_MAX,
131 };
132 int ret;
133
134 tcp_get_default_congestion_control(val);
135
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700136 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700137 if (write && ret == 0)
138 ret = tcp_set_default_congestion_control(val);
139 return ret;
140}
141
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800142static int proc_tcp_available_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700143 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800144 void __user *buffer, size_t *lenp,
145 loff_t *ppos)
146{
147 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
148 int ret;
149
150 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
151 if (!tbl.data)
152 return -ENOMEM;
153 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700154 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800155 kfree(tbl.data);
156 return ret;
157}
158
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800159static int proc_allowed_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700160 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800161 void __user *buffer, size_t *lenp,
162 loff_t *ppos)
163{
164 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
165 int ret;
166
167 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
168 if (!tbl.data)
169 return -ENOMEM;
170
171 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700172 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800173 if (write && ret == 0)
174 ret = tcp_set_allowed_congestion_control(tbl.data);
175 kfree(tbl.data);
176 return ret;
177}
178
Glauber Costa3dc43e32011-12-11 21:47:05 +0000179static int ipv4_tcp_mem(ctl_table *ctl, int write,
180 void __user *buffer, size_t *lenp,
181 loff_t *ppos)
182{
183 int ret;
184 unsigned long vec[3];
185 struct net *net = current->nsproxy->net_ns;
Glauber Costa3aaabe22011-12-11 21:47:06 +0000186#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
187 struct mem_cgroup *memcg;
188#endif
Glauber Costa3dc43e32011-12-11 21:47:05 +0000189
190 ctl_table tmp = {
191 .data = &vec,
192 .maxlen = sizeof(vec),
193 .mode = ctl->mode,
194 };
195
196 if (!write) {
197 ctl->data = &net->ipv4.sysctl_tcp_mem;
198 return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
199 }
200
201 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
202 if (ret)
203 return ret;
204
Glauber Costa3aaabe22011-12-11 21:47:06 +0000205#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
206 rcu_read_lock();
207 memcg = mem_cgroup_from_task(current);
208
209 tcp_prot_mem(memcg, vec[0], 0);
210 tcp_prot_mem(memcg, vec[1], 1);
211 tcp_prot_mem(memcg, vec[2], 2);
212 rcu_read_unlock();
213#endif
214
Glauber Costa3dc43e32011-12-11 21:47:05 +0000215 net->ipv4.sysctl_tcp_mem[0] = vec[0];
216 net->ipv4.sysctl_tcp_mem[1] = vec[1];
217 net->ipv4.sysctl_tcp_mem[2] = vec[2];
218
219 return 0;
220}
221
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800222static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900223 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .procname = "tcp_timestamps",
225 .data = &sysctl_tcp_timestamps,
226 .maxlen = sizeof(int),
227 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800228 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900230 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 .procname = "tcp_window_scaling",
232 .data = &sysctl_tcp_window_scaling,
233 .maxlen = sizeof(int),
234 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800235 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900237 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .procname = "tcp_sack",
239 .data = &sysctl_tcp_sack,
240 .maxlen = sizeof(int),
241 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800242 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 .procname = "tcp_retrans_collapse",
246 .data = &sysctl_tcp_retrans_collapse,
247 .maxlen = sizeof(int),
248 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800249 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900253 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 .maxlen = sizeof(int),
255 .mode = 0644,
Eric Dumazet249fab72010-12-13 12:16:14 -0800256 .proc_handler = proc_dointvec_minmax,
257 .extra1 = &ip_ttl_min,
258 .extra2 = &ip_ttl_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900260 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 .procname = "ip_no_pmtu_disc",
262 .data = &ipv4_config.no_pmtu_disc,
263 .maxlen = sizeof(int),
264 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800265 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 },
267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 .procname = "ip_nonlocal_bind",
269 .data = &sysctl_ip_nonlocal_bind,
270 .maxlen = sizeof(int),
271 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800272 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 },
274 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 .procname = "tcp_syn_retries",
276 .data = &sysctl_tcp_syn_retries,
277 .maxlen = sizeof(int),
278 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800279 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 },
281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "tcp_synack_retries",
283 .data = &sysctl_tcp_synack_retries,
284 .maxlen = sizeof(int),
285 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800286 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 },
288 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 .procname = "tcp_max_orphans",
290 .data = &sysctl_tcp_max_orphans,
291 .maxlen = sizeof(int),
292 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800293 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 },
295 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700297 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 .maxlen = sizeof(int),
299 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800300 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 },
302 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 .procname = "ip_dynaddr",
304 .data = &sysctl_ip_dynaddr,
305 .maxlen = sizeof(int),
306 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800307 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 },
309 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 .procname = "tcp_keepalive_time",
311 .data = &sysctl_tcp_keepalive_time,
312 .maxlen = sizeof(int),
313 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800314 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 },
316 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 .procname = "tcp_keepalive_probes",
318 .data = &sysctl_tcp_keepalive_probes,
319 .maxlen = sizeof(int),
320 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800321 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 },
323 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 .procname = "tcp_keepalive_intvl",
325 .data = &sysctl_tcp_keepalive_intvl,
326 .maxlen = sizeof(int),
327 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800328 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 },
330 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 .procname = "tcp_retries1",
332 .data = &sysctl_tcp_retries1,
333 .maxlen = sizeof(int),
334 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800335 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 .extra2 = &tcp_retr1_max
337 },
338 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 .procname = "tcp_retries2",
340 .data = &sysctl_tcp_retries2,
341 .maxlen = sizeof(int),
342 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800343 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 },
345 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 .procname = "tcp_fin_timeout",
347 .data = &sysctl_tcp_fin_timeout,
348 .maxlen = sizeof(int),
349 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800350 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 },
352#ifdef CONFIG_SYN_COOKIES
353 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 .procname = "tcp_syncookies",
355 .data = &sysctl_tcp_syncookies,
356 .maxlen = sizeof(int),
357 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800358 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 },
360#endif
361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700363 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 .maxlen = sizeof(int),
365 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800366 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 },
368 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 .procname = "tcp_abort_on_overflow",
370 .data = &sysctl_tcp_abort_on_overflow,
371 .maxlen = sizeof(int),
372 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800373 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 },
375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .procname = "tcp_stdurg",
377 .data = &sysctl_tcp_stdurg,
378 .maxlen = sizeof(int),
379 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800380 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 },
382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 .procname = "tcp_rfc1337",
384 .data = &sysctl_tcp_rfc1337,
385 .maxlen = sizeof(int),
386 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800387 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 },
389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .procname = "tcp_max_syn_backlog",
391 .data = &sysctl_max_syn_backlog,
392 .maxlen = sizeof(int),
393 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800394 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 },
396 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 .procname = "ip_local_port_range",
Eric Dumazet3c689b72008-10-08 14:18:04 -0700398 .data = &sysctl_local_ports.range,
399 .maxlen = sizeof(sysctl_local_ports.range),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800401 .proc_handler = ipv4_local_port_range,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 },
Amerigo Wange3826f12010-05-05 00:27:06 +0000403 {
404 .procname = "ip_local_reserved_ports",
405 .data = NULL, /* initialized in sysctl_ipv4_init */
406 .maxlen = 65536,
407 .mode = 0644,
408 .proc_handler = proc_do_large_bitmap,
409 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .procname = "igmp_max_memberships",
412 .data = &sysctl_igmp_max_memberships,
413 .maxlen = sizeof(int),
414 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800415 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .procname = "igmp_max_msf",
419 .data = &sysctl_igmp_max_msf,
420 .maxlen = sizeof(int),
421 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800422 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 },
424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .procname = "inet_peer_threshold",
426 .data = &inet_peer_threshold,
427 .maxlen = sizeof(int),
428 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800429 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 },
431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .procname = "inet_peer_minttl",
433 .data = &inet_peer_minttl,
434 .maxlen = sizeof(int),
435 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800436 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 },
438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .procname = "inet_peer_maxttl",
440 .data = &inet_peer_maxttl,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800443 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 },
445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .procname = "tcp_orphan_retries",
447 .data = &sysctl_tcp_orphan_retries,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800450 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 },
452 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 .procname = "tcp_fack",
454 .data = &sysctl_tcp_fack,
455 .maxlen = sizeof(int),
456 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800457 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 },
459 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .procname = "tcp_reordering",
461 .data = &sysctl_tcp_reordering,
462 .maxlen = sizeof(int),
463 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800464 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 },
466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .procname = "tcp_ecn",
468 .data = &sysctl_tcp_ecn,
469 .maxlen = sizeof(int),
470 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800471 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 },
473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "tcp_dsack",
475 .data = &sysctl_tcp_dsack,
476 .maxlen = sizeof(int),
477 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800478 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
480 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 .procname = "tcp_wmem",
482 .data = &sysctl_tcp_wmem,
483 .maxlen = sizeof(sysctl_tcp_wmem),
484 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800485 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 },
487 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .procname = "tcp_rmem",
489 .data = &sysctl_tcp_rmem,
490 .maxlen = sizeof(sysctl_tcp_rmem),
491 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800492 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 },
494 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .procname = "tcp_app_win",
496 .data = &sysctl_tcp_app_win,
497 .maxlen = sizeof(int),
498 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800499 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 },
501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .procname = "tcp_adv_win_scale",
503 .data = &sysctl_tcp_adv_win_scale,
504 .maxlen = sizeof(int),
505 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &tcp_adv_win_scale_min,
508 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 },
510 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 .procname = "tcp_tw_reuse",
512 .data = &sysctl_tcp_tw_reuse,
513 .maxlen = sizeof(int),
514 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800515 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 },
517 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .procname = "tcp_frto",
519 .data = &sysctl_tcp_frto,
520 .maxlen = sizeof(int),
521 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800522 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 },
524 {
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800525 .procname = "tcp_frto_response",
526 .data = &sysctl_tcp_frto_response,
527 .maxlen = sizeof(int),
528 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800529 .proc_handler = proc_dointvec
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800530 },
531 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 .procname = "tcp_low_latency",
533 .data = &sysctl_tcp_low_latency,
534 .maxlen = sizeof(int),
535 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800536 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 },
538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "tcp_no_metrics_save",
540 .data = &sysctl_tcp_nometrics_save,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800543 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 },
545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "tcp_moderate_rcvbuf",
547 .data = &sysctl_tcp_moderate_rcvbuf,
548 .maxlen = sizeof(int),
549 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800550 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 .procname = "tcp_tso_win_divisor",
554 .data = &sysctl_tcp_tso_win_divisor,
555 .maxlen = sizeof(int),
556 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800557 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 },
559 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700560 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700562 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800563 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800565 {
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800566 .procname = "tcp_abc",
567 .data = &sysctl_tcp_abc,
568 .maxlen = sizeof(int),
569 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800570 .proc_handler = proc_dointvec,
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800571 },
John Heffner5d424d52006-03-20 17:53:41 -0800572 {
John Heffner5d424d52006-03-20 17:53:41 -0800573 .procname = "tcp_mtu_probing",
574 .data = &sysctl_tcp_mtu_probing,
575 .maxlen = sizeof(int),
576 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800577 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800578 },
579 {
John Heffner5d424d52006-03-20 17:53:41 -0800580 .procname = "tcp_base_mss",
581 .data = &sysctl_tcp_base_mss,
582 .maxlen = sizeof(int),
583 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800584 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800585 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900586 {
Rick Jones15d99e02006-03-20 22:40:29 -0800587 .procname = "tcp_workaround_signed_windows",
588 .data = &sysctl_tcp_workaround_signed_windows,
589 .maxlen = sizeof(int),
590 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800591 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800592 },
Chris Leech95937822006-05-23 18:02:55 -0700593#ifdef CONFIG_NET_DMA
594 {
Chris Leech95937822006-05-23 18:02:55 -0700595 .procname = "tcp_dma_copybreak",
596 .data = &sysctl_tcp_dma_copybreak,
597 .maxlen = sizeof(int),
598 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800599 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700600 },
601#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700602 {
David S. Miller35089bb2006-06-13 22:33:04 -0700603 .procname = "tcp_slow_start_after_idle",
604 .data = &sysctl_tcp_slow_start_after_idle,
605 .maxlen = sizeof(int),
606 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800607 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700608 },
Paul Moore446fda42006-08-03 16:48:06 -0700609#ifdef CONFIG_NETLABEL
610 {
Paul Moore446fda42006-08-03 16:48:06 -0700611 .procname = "cipso_cache_enable",
612 .data = &cipso_v4_cache_enabled,
613 .maxlen = sizeof(int),
614 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800615 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700616 },
617 {
Paul Moore446fda42006-08-03 16:48:06 -0700618 .procname = "cipso_cache_bucket_size",
619 .data = &cipso_v4_cache_bucketsize,
620 .maxlen = sizeof(int),
621 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800622 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700623 },
624 {
Paul Moore446fda42006-08-03 16:48:06 -0700625 .procname = "cipso_rbm_optfmt",
626 .data = &cipso_v4_rbm_optfmt,
627 .maxlen = sizeof(int),
628 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800629 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700630 },
631 {
Paul Moore446fda42006-08-03 16:48:06 -0700632 .procname = "cipso_rbm_strictvalid",
633 .data = &cipso_v4_rbm_strictvalid,
634 .maxlen = sizeof(int),
635 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800636 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700637 },
638#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800639 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800640 .procname = "tcp_available_congestion_control",
641 .maxlen = TCP_CA_BUF_MAX,
642 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800643 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800644 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800645 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800646 .procname = "tcp_allowed_congestion_control",
647 .maxlen = TCP_CA_BUF_MAX,
648 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800649 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800650 },
John Heffner886236c2007-03-25 19:21:45 -0700651 {
John Heffner886236c2007-03-25 19:21:45 -0700652 .procname = "tcp_max_ssthresh",
653 .data = &sysctl_tcp_max_ssthresh,
654 .maxlen = sizeof(int),
655 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800656 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700657 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800658 {
William Allen Simpson519855c2009-12-02 18:14:19 +0000659 .procname = "tcp_cookie_size",
660 .data = &sysctl_tcp_cookie_size,
661 .maxlen = sizeof(int),
662 .mode = 0644,
663 .proc_handler = proc_dointvec
664 },
665 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000666 .procname = "tcp_thin_linear_timeouts",
667 .data = &sysctl_tcp_thin_linear_timeouts,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = proc_dointvec
671 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000672 {
673 .procname = "tcp_thin_dupack",
674 .data = &sysctl_tcp_thin_dupack,
675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = proc_dointvec
678 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000679 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800680 .procname = "udp_mem",
681 .data = &sysctl_udp_mem,
682 .maxlen = sizeof(sysctl_udp_mem),
683 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000684 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800685 },
686 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800687 .procname = "udp_rmem_min",
688 .data = &sysctl_udp_rmem_min,
689 .maxlen = sizeof(sysctl_udp_rmem_min),
690 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800691 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800692 .extra1 = &zero
693 },
694 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800695 .procname = "udp_wmem_min",
696 .data = &sysctl_udp_wmem_min,
697 .maxlen = sizeof(sysctl_udp_wmem_min),
698 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800699 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800700 .extra1 = &zero
701 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800702 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800704
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700705static struct ctl_table ipv4_net_table[] = {
706 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700707 .procname = "icmp_echo_ignore_all",
708 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
709 .maxlen = sizeof(int),
710 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800711 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700712 },
713 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700714 .procname = "icmp_echo_ignore_broadcasts",
715 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
716 .maxlen = sizeof(int),
717 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800718 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700719 },
720 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700721 .procname = "icmp_ignore_bogus_error_responses",
722 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
723 .maxlen = sizeof(int),
724 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800725 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700726 },
727 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700728 .procname = "icmp_errors_use_inbound_ifaddr",
729 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
730 .maxlen = sizeof(int),
731 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800732 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700733 },
734 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700735 .procname = "icmp_ratelimit",
736 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
737 .maxlen = sizeof(int),
738 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800739 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700740 },
741 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700742 .procname = "icmp_ratemask",
743 .data = &init_net.ipv4.sysctl_icmp_ratemask,
744 .maxlen = sizeof(int),
745 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800746 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700747 },
Neil Horman1080d702008-10-27 12:28:25 -0700748 {
Neil Horman1080d702008-10-27 12:28:25 -0700749 .procname = "rt_cache_rebuild_count",
750 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
751 .maxlen = sizeof(int),
752 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800753 .proc_handler = proc_dointvec
Neil Horman1080d702008-10-27 12:28:25 -0700754 },
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000755 {
756 .procname = "ping_group_range",
757 .data = &init_net.ipv4.sysctl_ping_group_range,
758 .maxlen = sizeof(init_net.ipv4.sysctl_ping_group_range),
759 .mode = 0644,
760 .proc_handler = ipv4_ping_group_range,
761 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000762 {
763 .procname = "tcp_mem",
764 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_mem),
765 .mode = 0644,
766 .proc_handler = ipv4_tcp_mem,
767 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700768 { }
769};
770
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800771struct ctl_path net_ipv4_ctl_path[] = {
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800772 { .procname = "net", },
773 { .procname = "ipv4", },
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800774 { },
775};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800776EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800777
Pavel Emelyanov15775192008-03-26 01:54:18 -0700778static __net_init int ipv4_sysctl_init_net(struct net *net)
779{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700780 struct ctl_table *table;
Glauber Costa3dc43e32011-12-11 21:47:05 +0000781 unsigned long limit;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700782
783 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800784 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700785 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
786 if (table == NULL)
787 goto err_alloc;
788
789 table[0].data =
790 &net->ipv4.sysctl_icmp_echo_ignore_all;
791 table[1].data =
792 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
793 table[2].data =
794 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
795 table[3].data =
796 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
797 table[4].data =
798 &net->ipv4.sysctl_icmp_ratelimit;
799 table[5].data =
800 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700801 table[6].data =
802 &net->ipv4.sysctl_rt_cache_rebuild_count;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000803 table[7].data =
804 &net->ipv4.sysctl_ping_group_range;
805
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700806 }
807
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000808 /*
809 * Sane defaults - nobody may create ping sockets.
810 * Boot scripts should set this to distro-specific group.
811 */
812 net->ipv4.sysctl_ping_group_range[0] = 1;
813 net->ipv4.sysctl_ping_group_range[1] = 0;
814
Neil Horman1080d702008-10-27 12:28:25 -0700815 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
816
Glauber Costa4acb4192012-01-30 01:20:17 +0000817 tcp_init_mem(net);
Glauber Costa3dc43e32011-12-11 21:47:05 +0000818 limit = nr_free_buffer_pages() / 8;
819 limit = max(limit, 128UL);
820 net->ipv4.sysctl_tcp_mem[0] = limit / 4 * 3;
821 net->ipv4.sysctl_tcp_mem[1] = limit;
822 net->ipv4.sysctl_tcp_mem[2] = net->ipv4.sysctl_tcp_mem[0] * 2;
823
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700824 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
825 net_ipv4_ctl_path, table);
826 if (net->ipv4.ipv4_hdr == NULL)
827 goto err_reg;
828
Pavel Emelyanov15775192008-03-26 01:54:18 -0700829 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700830
831err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800832 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700833 kfree(table);
834err_alloc:
835 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700836}
837
838static __net_exit void ipv4_sysctl_exit_net(struct net *net)
839{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700840 struct ctl_table *table;
841
842 table = net->ipv4.ipv4_hdr->ctl_table_arg;
843 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
844 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700845}
846
847static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
848 .init = ipv4_sysctl_init_net,
849 .exit = ipv4_sysctl_exit_net,
850};
851
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800852static __init int sysctl_ipv4_init(void)
853{
854 struct ctl_table_header *hdr;
Amerigo Wange3826f12010-05-05 00:27:06 +0000855 struct ctl_table *i;
856
857 for (i = ipv4_table; i->procname; i++) {
858 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
859 i->data = sysctl_local_reserved_ports;
860 break;
861 }
862 }
863 if (!i->procname)
864 return -EINVAL;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800865
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800866 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700867 if (hdr == NULL)
868 return -ENOMEM;
869
870 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
871 unregister_sysctl_table(hdr);
872 return -ENOMEM;
873 }
874
875 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800876}
877
878__initcall(sysctl_ipv4_init);