blob: 960fd29d9b8e067e12f89a6dfdcb3fa7873ea468 [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;
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +000030static int one = 1;
Yuchung Chengeed530b2012-05-02 13:30:03 +000031static int two = 2;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090032static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static int ip_local_port_range_min[] = { 1, 1 };
34static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000035static int tcp_adv_win_scale_min = -31;
36static int tcp_adv_win_scale_max = 31;
Eric Dumazet249fab72010-12-13 12:16:14 -080037static int ip_ttl_min = 1;
38static int ip_ttl_max = 255;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000039static int ip_ping_group_range_min[] = { 0, 0 };
40static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Stephen Hemminger227b60f2007-10-10 17:30:46 -070042/* Update system visible IP port range */
43static void set_local_port_range(int range[2])
44{
Eric Dumazet3c689b72008-10-08 14:18:04 -070045 write_seqlock(&sysctl_local_ports.lock);
46 sysctl_local_ports.range[0] = range[0];
47 sysctl_local_ports.range[1] = range[1];
48 write_sequnlock(&sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070049}
50
51/* Validate changes from /proc interface. */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070052static int ipv4_local_port_range(ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070053 void __user *buffer,
54 size_t *lenp, loff_t *ppos)
55{
56 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070057 int range[2];
Stephen Hemminger227b60f2007-10-10 17:30:46 -070058 ctl_table tmp = {
59 .data = &range,
60 .maxlen = sizeof(range),
61 .mode = table->mode,
62 .extra1 = &ip_local_port_range_min,
63 .extra2 = &ip_local_port_range_max,
64 };
65
Eric Dumazet3c689b72008-10-08 14:18:04 -070066 inet_get_local_port_range(range, range + 1);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070067 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070068
69 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070070 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070071 ret = -EINVAL;
72 else
73 set_local_port_range(range);
74 }
75
76 return ret;
77}
78
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000079
Eric W. Biederman7064d162012-05-24 10:34:21 -060080static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000081{
Eric W. Biederman7064d162012-05-24 10:34:21 -060082 kgid_t *data = table->data;
Eric Dumazet95c96172012-04-15 05:58:06 +000083 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000084 do {
85 seq = read_seqbegin(&sysctl_local_ports.lock);
86
87 *low = data[0];
88 *high = data[1];
89 } while (read_seqretry(&sysctl_local_ports.lock, seq));
90}
91
92/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -060093static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000094{
Eric W. Biederman7064d162012-05-24 10:34:21 -060095 kgid_t *data = table->data;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000096 write_seqlock(&sysctl_local_ports.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -060097 data[0] = low;
98 data[1] = high;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000099 write_sequnlock(&sysctl_local_ports.lock);
100}
101
102/* Validate changes from /proc interface. */
103static int ipv4_ping_group_range(ctl_table *table, int write,
104 void __user *buffer,
105 size_t *lenp, loff_t *ppos)
106{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600107 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000108 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600109 gid_t urange[2];
110 kgid_t low, high;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000111 ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600112 .data = &urange,
113 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000114 .mode = table->mode,
115 .extra1 = &ip_ping_group_range_min,
116 .extra2 = &ip_ping_group_range_max,
117 };
118
Eric W. Biederman7064d162012-05-24 10:34:21 -0600119 inet_get_ping_group_range_table(table, &low, &high);
120 urange[0] = from_kgid_munged(user_ns, low);
121 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000122 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
123
Eric W. Biederman7064d162012-05-24 10:34:21 -0600124 if (write && ret == 0) {
125 low = make_kgid(user_ns, urange[0]);
126 high = make_kgid(user_ns, urange[1]);
127 if (!gid_valid(low) || !gid_valid(high) ||
128 (urange[1] < urange[0]) || gid_lt(high, low)) {
129 low = make_kgid(&init_user_ns, 1);
130 high = make_kgid(&init_user_ns, 0);
131 }
132 set_ping_group_range(table, low, high);
133 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000134
135 return ret;
136}
137
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700138static int proc_tcp_congestion_control(ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700139 void __user *buffer, size_t *lenp, loff_t *ppos)
140{
141 char val[TCP_CA_NAME_MAX];
142 ctl_table tbl = {
143 .data = val,
144 .maxlen = TCP_CA_NAME_MAX,
145 };
146 int ret;
147
148 tcp_get_default_congestion_control(val);
149
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700150 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700151 if (write && ret == 0)
152 ret = tcp_set_default_congestion_control(val);
153 return ret;
154}
155
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800156static int proc_tcp_available_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700157 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800158 void __user *buffer, size_t *lenp,
159 loff_t *ppos)
160{
161 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
162 int ret;
163
164 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
165 if (!tbl.data)
166 return -ENOMEM;
167 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700168 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800169 kfree(tbl.data);
170 return ret;
171}
172
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800173static int proc_allowed_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700174 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800175 void __user *buffer, size_t *lenp,
176 loff_t *ppos)
177{
178 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
179 int ret;
180
181 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
182 if (!tbl.data)
183 return -ENOMEM;
184
185 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700186 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800187 if (write && ret == 0)
188 ret = tcp_set_allowed_congestion_control(tbl.data);
189 kfree(tbl.data);
190 return ret;
191}
192
Glauber Costa3dc43e32011-12-11 21:47:05 +0000193static int ipv4_tcp_mem(ctl_table *ctl, int write,
194 void __user *buffer, size_t *lenp,
195 loff_t *ppos)
196{
197 int ret;
198 unsigned long vec[3];
199 struct net *net = current->nsproxy->net_ns;
Andrew Mortonc255a452012-07-31 16:43:02 -0700200#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000201 struct mem_cgroup *memcg;
202#endif
Glauber Costa3dc43e32011-12-11 21:47:05 +0000203
204 ctl_table tmp = {
205 .data = &vec,
206 .maxlen = sizeof(vec),
207 .mode = ctl->mode,
208 };
209
210 if (!write) {
211 ctl->data = &net->ipv4.sysctl_tcp_mem;
212 return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
213 }
214
215 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
216 if (ret)
217 return ret;
218
Andrew Mortonc255a452012-07-31 16:43:02 -0700219#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000220 rcu_read_lock();
221 memcg = mem_cgroup_from_task(current);
222
223 tcp_prot_mem(memcg, vec[0], 0);
224 tcp_prot_mem(memcg, vec[1], 1);
225 tcp_prot_mem(memcg, vec[2], 2);
226 rcu_read_unlock();
227#endif
228
Glauber Costa3dc43e32011-12-11 21:47:05 +0000229 net->ipv4.sysctl_tcp_mem[0] = vec[0];
230 net->ipv4.sysctl_tcp_mem[1] = vec[1];
231 net->ipv4.sysctl_tcp_mem[2] = vec[2];
232
233 return 0;
234}
235
stephen hemmingerbb717d72012-12-28 18:20:24 +0000236static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
237 size_t *lenp, loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000238{
239 ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
240 struct tcp_fastopen_context *ctxt;
241 int ret;
242 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
243
244 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
245 if (!tbl.data)
246 return -ENOMEM;
247
248 rcu_read_lock();
249 ctxt = rcu_dereference(tcp_fastopen_ctx);
250 if (ctxt)
251 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000252 else
253 memset(user_key, 0, sizeof(user_key));
Jerry Chu10467162012-08-31 12:29:11 +0000254 rcu_read_unlock();
255
256 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
257 user_key[0], user_key[1], user_key[2], user_key[3]);
258 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
259
260 if (write && ret == 0) {
261 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
262 user_key + 2, user_key + 3) != 4) {
263 ret = -EINVAL;
264 goto bad_key;
265 }
266 tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH);
267 }
268
269bad_key:
270 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
271 user_key[0], user_key[1], user_key[2], user_key[3],
272 (char *)tbl.data, ret);
273 kfree(tbl.data);
274 return ret;
275}
276
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800277static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900278 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 .procname = "tcp_timestamps",
280 .data = &sysctl_tcp_timestamps,
281 .maxlen = sizeof(int),
282 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800283 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900285 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .procname = "tcp_window_scaling",
287 .data = &sysctl_tcp_window_scaling,
288 .maxlen = sizeof(int),
289 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800290 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900292 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 .procname = "tcp_sack",
294 .data = &sysctl_tcp_sack,
295 .maxlen = sizeof(int),
296 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800297 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900299 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 .procname = "tcp_retrans_collapse",
301 .data = &sysctl_tcp_retrans_collapse,
302 .maxlen = sizeof(int),
303 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800304 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900306 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900308 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 .maxlen = sizeof(int),
310 .mode = 0644,
Eric Dumazet249fab72010-12-13 12:16:14 -0800311 .proc_handler = proc_dointvec_minmax,
312 .extra1 = &ip_ttl_min,
313 .extra2 = &ip_ttl_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900315 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 .procname = "ip_no_pmtu_disc",
317 .data = &ipv4_config.no_pmtu_disc,
318 .maxlen = sizeof(int),
319 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800320 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 },
322 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 .procname = "ip_nonlocal_bind",
324 .data = &sysctl_ip_nonlocal_bind,
325 .maxlen = sizeof(int),
326 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800327 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 },
329 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 .procname = "tcp_syn_retries",
331 .data = &sysctl_tcp_syn_retries,
332 .maxlen = sizeof(int),
333 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800334 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 },
336 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 .procname = "tcp_synack_retries",
338 .data = &sysctl_tcp_synack_retries,
339 .maxlen = sizeof(int),
340 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800341 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 },
343 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 .procname = "tcp_max_orphans",
345 .data = &sysctl_tcp_max_orphans,
346 .maxlen = sizeof(int),
347 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800348 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 },
350 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700352 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 .maxlen = sizeof(int),
354 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800355 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 },
357 {
Alexander Duyck6648bd72012-06-21 13:58:31 +0000358 .procname = "ip_early_demux",
359 .data = &sysctl_ip_early_demux,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = proc_dointvec
363 },
364 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 .procname = "ip_dynaddr",
366 .data = &sysctl_ip_dynaddr,
367 .maxlen = sizeof(int),
368 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800369 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 },
371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 .procname = "tcp_keepalive_time",
373 .data = &sysctl_tcp_keepalive_time,
374 .maxlen = sizeof(int),
375 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800376 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 },
378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 .procname = "tcp_keepalive_probes",
380 .data = &sysctl_tcp_keepalive_probes,
381 .maxlen = sizeof(int),
382 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800383 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 },
385 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 .procname = "tcp_keepalive_intvl",
387 .data = &sysctl_tcp_keepalive_intvl,
388 .maxlen = sizeof(int),
389 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800390 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 },
392 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 .procname = "tcp_retries1",
394 .data = &sysctl_tcp_retries1,
395 .maxlen = sizeof(int),
396 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800397 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .extra2 = &tcp_retr1_max
399 },
400 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 .procname = "tcp_retries2",
402 .data = &sysctl_tcp_retries2,
403 .maxlen = sizeof(int),
404 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800405 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 },
407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 .procname = "tcp_fin_timeout",
409 .data = &sysctl_tcp_fin_timeout,
410 .maxlen = sizeof(int),
411 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800412 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 },
414#ifdef CONFIG_SYN_COOKIES
415 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 .procname = "tcp_syncookies",
417 .data = &sysctl_tcp_syncookies,
418 .maxlen = sizeof(int),
419 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800420 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 },
422#endif
423 {
Yuchung Cheng2100c8d2012-07-19 06:43:05 +0000424 .procname = "tcp_fastopen",
425 .data = &sysctl_tcp_fastopen,
426 .maxlen = sizeof(int),
427 .mode = 0644,
428 .proc_handler = proc_dointvec,
429 },
430 {
Jerry Chu10467162012-08-31 12:29:11 +0000431 .procname = "tcp_fastopen_key",
432 .mode = 0600,
433 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
434 .proc_handler = proc_tcp_fastopen_key,
435 },
436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700438 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .maxlen = sizeof(int),
440 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800441 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 },
443 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 .procname = "tcp_abort_on_overflow",
445 .data = &sysctl_tcp_abort_on_overflow,
446 .maxlen = sizeof(int),
447 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800448 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 },
450 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 .procname = "tcp_stdurg",
452 .data = &sysctl_tcp_stdurg,
453 .maxlen = sizeof(int),
454 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800455 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 },
457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 .procname = "tcp_rfc1337",
459 .data = &sysctl_tcp_rfc1337,
460 .maxlen = sizeof(int),
461 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800462 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 },
464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .procname = "tcp_max_syn_backlog",
466 .data = &sysctl_max_syn_backlog,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800469 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 },
471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .procname = "ip_local_port_range",
Eric Dumazet3c689b72008-10-08 14:18:04 -0700473 .data = &sysctl_local_ports.range,
474 .maxlen = sizeof(sysctl_local_ports.range),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800476 .proc_handler = ipv4_local_port_range,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 },
Amerigo Wange3826f12010-05-05 00:27:06 +0000478 {
479 .procname = "ip_local_reserved_ports",
480 .data = NULL, /* initialized in sysctl_ipv4_init */
481 .maxlen = 65536,
482 .mode = 0644,
483 .proc_handler = proc_do_large_bitmap,
484 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .procname = "igmp_max_memberships",
487 .data = &sysctl_igmp_max_memberships,
488 .maxlen = sizeof(int),
489 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800490 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .procname = "igmp_max_msf",
494 .data = &sysctl_igmp_max_msf,
495 .maxlen = sizeof(int),
496 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800497 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 },
499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .procname = "inet_peer_threshold",
501 .data = &inet_peer_threshold,
502 .maxlen = sizeof(int),
503 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800504 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 },
506 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .procname = "inet_peer_minttl",
508 .data = &inet_peer_minttl,
509 .maxlen = sizeof(int),
510 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800511 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 },
513 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .procname = "inet_peer_maxttl",
515 .data = &inet_peer_maxttl,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800518 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
520 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 .procname = "tcp_orphan_retries",
522 .data = &sysctl_tcp_orphan_retries,
523 .maxlen = sizeof(int),
524 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800525 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 },
527 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 .procname = "tcp_fack",
529 .data = &sysctl_tcp_fack,
530 .maxlen = sizeof(int),
531 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800532 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 },
534 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 .procname = "tcp_reordering",
536 .data = &sysctl_tcp_reordering,
537 .maxlen = sizeof(int),
538 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800539 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 },
541 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 .procname = "tcp_dsack",
543 .data = &sysctl_tcp_dsack,
544 .maxlen = sizeof(int),
545 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800546 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 },
548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 .procname = "tcp_wmem",
550 .data = &sysctl_tcp_wmem,
551 .maxlen = sizeof(sysctl_tcp_wmem),
552 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000553 .proc_handler = proc_dointvec_minmax,
554 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 },
556 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .procname = "tcp_rmem",
558 .data = &sysctl_tcp_rmem,
559 .maxlen = sizeof(sysctl_tcp_rmem),
560 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000561 .proc_handler = proc_dointvec_minmax,
562 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 },
564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .procname = "tcp_app_win",
566 .data = &sysctl_tcp_app_win,
567 .maxlen = sizeof(int),
568 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800569 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 },
571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .procname = "tcp_adv_win_scale",
573 .data = &sysctl_tcp_adv_win_scale,
574 .maxlen = sizeof(int),
575 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000576 .proc_handler = proc_dointvec_minmax,
577 .extra1 = &tcp_adv_win_scale_min,
578 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "tcp_tw_reuse",
582 .data = &sysctl_tcp_tw_reuse,
583 .maxlen = sizeof(int),
584 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800585 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .procname = "tcp_frto",
589 .data = &sysctl_tcp_frto,
590 .maxlen = sizeof(int),
591 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800592 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
594 {
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800595 .procname = "tcp_frto_response",
596 .data = &sysctl_tcp_frto_response,
597 .maxlen = sizeof(int),
598 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800599 .proc_handler = proc_dointvec
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800600 },
601 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .procname = "tcp_low_latency",
603 .data = &sysctl_tcp_low_latency,
604 .maxlen = sizeof(int),
605 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800606 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 },
608 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .procname = "tcp_no_metrics_save",
610 .data = &sysctl_tcp_nometrics_save,
611 .maxlen = sizeof(int),
612 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800613 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 },
615 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 .procname = "tcp_moderate_rcvbuf",
617 .data = &sysctl_tcp_moderate_rcvbuf,
618 .maxlen = sizeof(int),
619 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800620 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 },
622 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 .procname = "tcp_tso_win_divisor",
624 .data = &sysctl_tcp_tso_win_divisor,
625 .maxlen = sizeof(int),
626 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800627 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 },
629 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700630 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700632 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800633 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800635 {
John Heffner5d424d52006-03-20 17:53:41 -0800636 .procname = "tcp_mtu_probing",
637 .data = &sysctl_tcp_mtu_probing,
638 .maxlen = sizeof(int),
639 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800640 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800641 },
642 {
John Heffner5d424d52006-03-20 17:53:41 -0800643 .procname = "tcp_base_mss",
644 .data = &sysctl_tcp_base_mss,
645 .maxlen = sizeof(int),
646 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800647 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800648 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900649 {
Rick Jones15d99e02006-03-20 22:40:29 -0800650 .procname = "tcp_workaround_signed_windows",
651 .data = &sysctl_tcp_workaround_signed_windows,
652 .maxlen = sizeof(int),
653 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800654 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800655 },
Eric Dumazet46d3cea2012-07-11 05:50:31 +0000656 {
657 .procname = "tcp_limit_output_bytes",
658 .data = &sysctl_tcp_limit_output_bytes,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = proc_dointvec
662 },
Eric Dumazet282f23c2012-07-17 10:13:05 +0200663 {
664 .procname = "tcp_challenge_ack_limit",
665 .data = &sysctl_tcp_challenge_ack_limit,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = proc_dointvec
669 },
Chris Leech95937822006-05-23 18:02:55 -0700670#ifdef CONFIG_NET_DMA
671 {
Chris Leech95937822006-05-23 18:02:55 -0700672 .procname = "tcp_dma_copybreak",
673 .data = &sysctl_tcp_dma_copybreak,
674 .maxlen = sizeof(int),
675 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800676 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700677 },
678#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700679 {
David S. Miller35089bb2006-06-13 22:33:04 -0700680 .procname = "tcp_slow_start_after_idle",
681 .data = &sysctl_tcp_slow_start_after_idle,
682 .maxlen = sizeof(int),
683 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800684 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700685 },
Paul Moore446fda42006-08-03 16:48:06 -0700686#ifdef CONFIG_NETLABEL
687 {
Paul Moore446fda42006-08-03 16:48:06 -0700688 .procname = "cipso_cache_enable",
689 .data = &cipso_v4_cache_enabled,
690 .maxlen = sizeof(int),
691 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800692 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700693 },
694 {
Paul Moore446fda42006-08-03 16:48:06 -0700695 .procname = "cipso_cache_bucket_size",
696 .data = &cipso_v4_cache_bucketsize,
697 .maxlen = sizeof(int),
698 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800699 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700700 },
701 {
Paul Moore446fda42006-08-03 16:48:06 -0700702 .procname = "cipso_rbm_optfmt",
703 .data = &cipso_v4_rbm_optfmt,
704 .maxlen = sizeof(int),
705 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800706 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700707 },
708 {
Paul Moore446fda42006-08-03 16:48:06 -0700709 .procname = "cipso_rbm_strictvalid",
710 .data = &cipso_v4_rbm_strictvalid,
711 .maxlen = sizeof(int),
712 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800713 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700714 },
715#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800716 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800717 .procname = "tcp_available_congestion_control",
718 .maxlen = TCP_CA_BUF_MAX,
719 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800720 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800721 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800722 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800723 .procname = "tcp_allowed_congestion_control",
724 .maxlen = TCP_CA_BUF_MAX,
725 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800726 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800727 },
John Heffner886236c2007-03-25 19:21:45 -0700728 {
John Heffner886236c2007-03-25 19:21:45 -0700729 .procname = "tcp_max_ssthresh",
730 .data = &sysctl_tcp_max_ssthresh,
731 .maxlen = sizeof(int),
732 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800733 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700734 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800735 {
William Allen Simpson519855c2009-12-02 18:14:19 +0000736 .procname = "tcp_cookie_size",
737 .data = &sysctl_tcp_cookie_size,
738 .maxlen = sizeof(int),
739 .mode = 0644,
740 .proc_handler = proc_dointvec
741 },
742 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000743 .procname = "tcp_thin_linear_timeouts",
744 .data = &sysctl_tcp_thin_linear_timeouts,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = proc_dointvec
748 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000749 {
750 .procname = "tcp_thin_dupack",
751 .data = &sysctl_tcp_thin_dupack,
752 .maxlen = sizeof(int),
753 .mode = 0644,
754 .proc_handler = proc_dointvec
755 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000756 {
Yuchung Chengeed530b2012-05-02 13:30:03 +0000757 .procname = "tcp_early_retrans",
758 .data = &sysctl_tcp_early_retrans,
759 .maxlen = sizeof(int),
760 .mode = 0644,
761 .proc_handler = proc_dointvec_minmax,
762 .extra1 = &zero,
763 .extra2 = &two,
764 },
765 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800766 .procname = "udp_mem",
767 .data = &sysctl_udp_mem,
768 .maxlen = sizeof(sysctl_udp_mem),
769 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000770 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800771 },
772 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800773 .procname = "udp_rmem_min",
774 .data = &sysctl_udp_rmem_min,
775 .maxlen = sizeof(sysctl_udp_rmem_min),
776 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800777 .proc_handler = proc_dointvec_minmax,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000778 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800779 },
780 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800781 .procname = "udp_wmem_min",
782 .data = &sysctl_udp_wmem_min,
783 .maxlen = sizeof(sysctl_udp_wmem_min),
784 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800785 .proc_handler = proc_dointvec_minmax,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000786 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800787 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800788 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800790
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700791static struct ctl_table ipv4_net_table[] = {
792 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700793 .procname = "icmp_echo_ignore_all",
794 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
795 .maxlen = sizeof(int),
796 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800797 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700798 },
799 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700800 .procname = "icmp_echo_ignore_broadcasts",
801 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800804 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700805 },
806 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700807 .procname = "icmp_ignore_bogus_error_responses",
808 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
809 .maxlen = sizeof(int),
810 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800811 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700812 },
813 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700814 .procname = "icmp_errors_use_inbound_ifaddr",
815 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
816 .maxlen = sizeof(int),
817 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800818 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700819 },
820 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700821 .procname = "icmp_ratelimit",
822 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
823 .maxlen = sizeof(int),
824 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800825 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700826 },
827 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700828 .procname = "icmp_ratemask",
829 .data = &init_net.ipv4.sysctl_icmp_ratemask,
830 .maxlen = sizeof(int),
831 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800832 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700833 },
Neil Horman1080d702008-10-27 12:28:25 -0700834 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000835 .procname = "ping_group_range",
836 .data = &init_net.ipv4.sysctl_ping_group_range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600837 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000838 .mode = 0644,
839 .proc_handler = ipv4_ping_group_range,
840 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000841 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000842 .procname = "tcp_ecn",
843 .data = &init_net.ipv4.sysctl_tcp_ecn,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = proc_dointvec
847 },
848 {
Glauber Costa3dc43e32011-12-11 21:47:05 +0000849 .procname = "tcp_mem",
850 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_mem),
851 .mode = 0644,
852 .proc_handler = ipv4_tcp_mem,
853 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700854 { }
855};
856
Pavel Emelyanov15775192008-03-26 01:54:18 -0700857static __net_init int ipv4_sysctl_init_net(struct net *net)
858{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700859 struct ctl_table *table;
860
861 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800862 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700863 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
864 if (table == NULL)
865 goto err_alloc;
866
867 table[0].data =
868 &net->ipv4.sysctl_icmp_echo_ignore_all;
869 table[1].data =
870 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
871 table[2].data =
872 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
873 table[3].data =
874 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
875 table[4].data =
876 &net->ipv4.sysctl_icmp_ratelimit;
877 table[5].data =
878 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700879 table[6].data =
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000880 &net->ipv4.sysctl_ping_group_range;
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000881 table[7].data =
882 &net->ipv4.sysctl_tcp_ecn;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000883
Eric W. Biederman464dc802012-11-16 03:02:59 +0000884 /* Don't export sysctls to unprivileged users */
885 if (net->user_ns != &init_user_ns)
886 table[0].procname = NULL;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700887 }
888
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000889 /*
890 * Sane defaults - nobody may create ping sockets.
891 * Boot scripts should set this to distro-specific group.
892 */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600893 net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
894 net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000895
Glauber Costa4acb4192012-01-30 01:20:17 +0000896 tcp_init_mem(net);
Glauber Costa3dc43e32011-12-11 21:47:05 +0000897
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000898 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700899 if (net->ipv4.ipv4_hdr == NULL)
900 goto err_reg;
901
Pavel Emelyanov15775192008-03-26 01:54:18 -0700902 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700903
904err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800905 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700906 kfree(table);
907err_alloc:
908 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700909}
910
911static __net_exit void ipv4_sysctl_exit_net(struct net *net)
912{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700913 struct ctl_table *table;
914
915 table = net->ipv4.ipv4_hdr->ctl_table_arg;
916 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
917 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700918}
919
920static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
921 .init = ipv4_sysctl_init_net,
922 .exit = ipv4_sysctl_exit_net,
923};
924
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800925static __init int sysctl_ipv4_init(void)
926{
927 struct ctl_table_header *hdr;
Amerigo Wange3826f12010-05-05 00:27:06 +0000928 struct ctl_table *i;
929
930 for (i = ipv4_table; i->procname; i++) {
931 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
932 i->data = sysctl_local_reserved_ports;
933 break;
934 }
935 }
936 if (!i->procname)
937 return -EINVAL;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800938
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000939 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700940 if (hdr == NULL)
941 return -ENOMEM;
942
943 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000944 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700945 return -ENOMEM;
946 }
947
948 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800949}
950
951__initcall(sysctl_ipv4_init);