blob: c08f096d46b5ec83f379e84e6a5bd32e0088c22f [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;
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +000031static int four = 4;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070032static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090033static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static int ip_local_port_range_min[] = { 1, 1 };
35static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000036static int tcp_adv_win_scale_min = -31;
37static int tcp_adv_win_scale_max = 31;
Eric Dumazet249fab72010-12-13 12:16:14 -080038static int ip_ttl_min = 1;
39static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020040static int tcp_syn_retries_min = 1;
41static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000042static int ip_ping_group_range_min[] = { 0, 0 };
43static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Stephen Hemminger227b60f2007-10-10 17:30:46 -070045/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070046static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070047{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070048 write_seqlock(&net->ipv4.sysctl_local_ports.lock);
49 net->ipv4.sysctl_local_ports.range[0] = range[0];
50 net->ipv4.sysctl_local_ports.range[1] = range[1];
51 write_sequnlock(&net->ipv4.sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070052}
53
54/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070055static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070056 void __user *buffer,
57 size_t *lenp, loff_t *ppos)
58{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070059 struct net *net =
60 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070061 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070062 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070063 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070064 .data = &range,
65 .maxlen = sizeof(range),
66 .mode = table->mode,
67 .extra1 = &ip_local_port_range_min,
68 .extra2 = &ip_local_port_range_max,
69 };
70
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070071 inet_get_local_port_range(net, &range[0], &range[1]);
72
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070073 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070074
75 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070076 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070077 ret = -EINVAL;
78 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070079 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070080 }
81
82 return ret;
83}
84
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000085
Eric W. Biederman7064d162012-05-24 10:34:21 -060086static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000087{
Eric W. Biederman7064d162012-05-24 10:34:21 -060088 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070089 struct net *net =
90 container_of(table->data, struct net, ipv4.sysctl_ping_group_range);
Eric Dumazet95c96172012-04-15 05:58:06 +000091 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000092 do {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070093 seq = read_seqbegin(&net->ipv4.sysctl_local_ports.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000094
95 *low = data[0];
96 *high = data[1];
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070097 } while (read_seqretry(&net->ipv4.sysctl_local_ports.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000098}
99
100/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600101static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000102{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600103 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700104 struct net *net =
105 container_of(table->data, struct net, ipv4.sysctl_ping_group_range);
106 write_seqlock(&net->ipv4.sysctl_local_ports.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600107 data[0] = low;
108 data[1] = high;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700109 write_sequnlock(&net->ipv4.sysctl_local_ports.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000110}
111
112/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700113static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000114 void __user *buffer,
115 size_t *lenp, loff_t *ppos)
116{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600117 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000118 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600119 gid_t urange[2];
120 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700121 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600122 .data = &urange,
123 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000124 .mode = table->mode,
125 .extra1 = &ip_ping_group_range_min,
126 .extra2 = &ip_ping_group_range_max,
127 };
128
Eric W. Biederman7064d162012-05-24 10:34:21 -0600129 inet_get_ping_group_range_table(table, &low, &high);
130 urange[0] = from_kgid_munged(user_ns, low);
131 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000132 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
133
Eric W. Biederman7064d162012-05-24 10:34:21 -0600134 if (write && ret == 0) {
135 low = make_kgid(user_ns, urange[0]);
136 high = make_kgid(user_ns, urange[1]);
137 if (!gid_valid(low) || !gid_valid(high) ||
138 (urange[1] < urange[0]) || gid_lt(high, low)) {
139 low = make_kgid(&init_user_ns, 1);
140 high = make_kgid(&init_user_ns, 0);
141 }
142 set_ping_group_range(table, low, high);
143 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000144
145 return ret;
146}
147
Joe Perchesfe2c6332013-06-11 23:04:25 -0700148static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700149 void __user *buffer, size_t *lenp, loff_t *ppos)
150{
151 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700152 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700153 .data = val,
154 .maxlen = TCP_CA_NAME_MAX,
155 };
156 int ret;
157
158 tcp_get_default_congestion_control(val);
159
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700160 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700161 if (write && ret == 0)
162 ret = tcp_set_default_congestion_control(val);
163 return ret;
164}
165
Joe Perchesfe2c6332013-06-11 23:04:25 -0700166static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800168 void __user *buffer, size_t *lenp,
169 loff_t *ppos)
170{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700171 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800172 int ret;
173
174 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
175 if (!tbl.data)
176 return -ENOMEM;
177 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700178 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800179 kfree(tbl.data);
180 return ret;
181}
182
Joe Perchesfe2c6332013-06-11 23:04:25 -0700183static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700184 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800185 void __user *buffer, size_t *lenp,
186 loff_t *ppos)
187{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700188 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800189 int ret;
190
191 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
192 if (!tbl.data)
193 return -ENOMEM;
194
195 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700196 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800197 if (write && ret == 0)
198 ret = tcp_set_allowed_congestion_control(tbl.data);
199 kfree(tbl.data);
200 return ret;
201}
202
Joe Perchesfe2c6332013-06-11 23:04:25 -0700203static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
Glauber Costa3dc43e32011-12-11 21:47:05 +0000204 void __user *buffer, size_t *lenp,
205 loff_t *ppos)
206{
207 int ret;
208 unsigned long vec[3];
209 struct net *net = current->nsproxy->net_ns;
Andrew Mortonc255a452012-07-31 16:43:02 -0700210#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000211 struct mem_cgroup *memcg;
212#endif
Glauber Costa3dc43e32011-12-11 21:47:05 +0000213
Joe Perchesfe2c6332013-06-11 23:04:25 -0700214 struct ctl_table tmp = {
Glauber Costa3dc43e32011-12-11 21:47:05 +0000215 .data = &vec,
216 .maxlen = sizeof(vec),
217 .mode = ctl->mode,
218 };
219
220 if (!write) {
221 ctl->data = &net->ipv4.sysctl_tcp_mem;
222 return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
223 }
224
225 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
226 if (ret)
227 return ret;
228
Andrew Mortonc255a452012-07-31 16:43:02 -0700229#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000230 rcu_read_lock();
231 memcg = mem_cgroup_from_task(current);
232
233 tcp_prot_mem(memcg, vec[0], 0);
234 tcp_prot_mem(memcg, vec[1], 1);
235 tcp_prot_mem(memcg, vec[2], 2);
236 rcu_read_unlock();
237#endif
238
Glauber Costa3dc43e32011-12-11 21:47:05 +0000239 net->ipv4.sysctl_tcp_mem[0] = vec[0];
240 net->ipv4.sysctl_tcp_mem[1] = vec[1];
241 net->ipv4.sysctl_tcp_mem[2] = vec[2];
242
243 return 0;
244}
245
Joe Perchesfe2c6332013-06-11 23:04:25 -0700246static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
247 void __user *buffer, size_t *lenp,
248 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000249{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700250 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000251 struct tcp_fastopen_context *ctxt;
252 int ret;
253 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
254
255 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
256 if (!tbl.data)
257 return -ENOMEM;
258
259 rcu_read_lock();
260 ctxt = rcu_dereference(tcp_fastopen_ctx);
261 if (ctxt)
262 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000263 else
264 memset(user_key, 0, sizeof(user_key));
Jerry Chu10467162012-08-31 12:29:11 +0000265 rcu_read_unlock();
266
267 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
268 user_key[0], user_key[1], user_key[2], user_key[3]);
269 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
270
271 if (write && ret == 0) {
272 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
273 user_key + 2, user_key + 3) != 4) {
274 ret = -EINVAL;
275 goto bad_key;
276 }
277 tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH);
278 }
279
280bad_key:
281 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
282 user_key[0], user_key[1], user_key[2], user_key[3],
283 (char *)tbl.data, ret);
284 kfree(tbl.data);
285 return ret;
286}
287
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800288static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900289 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 .procname = "tcp_timestamps",
291 .data = &sysctl_tcp_timestamps,
292 .maxlen = sizeof(int),
293 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800294 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900296 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 .procname = "tcp_window_scaling",
298 .data = &sysctl_tcp_window_scaling,
299 .maxlen = sizeof(int),
300 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800301 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900303 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 .procname = "tcp_sack",
305 .data = &sysctl_tcp_sack,
306 .maxlen = sizeof(int),
307 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800308 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900310 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 .procname = "tcp_retrans_collapse",
312 .data = &sysctl_tcp_retrans_collapse,
313 .maxlen = sizeof(int),
314 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800315 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900317 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900319 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 .maxlen = sizeof(int),
321 .mode = 0644,
Eric Dumazet249fab72010-12-13 12:16:14 -0800322 .proc_handler = proc_dointvec_minmax,
323 .extra1 = &ip_ttl_min,
324 .extra2 = &ip_ttl_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900326 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 .procname = "ip_no_pmtu_disc",
328 .data = &ipv4_config.no_pmtu_disc,
329 .maxlen = sizeof(int),
330 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800331 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 },
333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 .procname = "ip_nonlocal_bind",
335 .data = &sysctl_ip_nonlocal_bind,
336 .maxlen = sizeof(int),
337 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800338 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 },
340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 .procname = "tcp_syn_retries",
342 .data = &sysctl_tcp_syn_retries,
343 .maxlen = sizeof(int),
344 .mode = 0644,
Michal Tesar651e9272013-07-19 14:09:01 +0200345 .proc_handler = proc_dointvec_minmax,
346 .extra1 = &tcp_syn_retries_min,
347 .extra2 = &tcp_syn_retries_max
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 },
349 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 .procname = "tcp_synack_retries",
351 .data = &sysctl_tcp_synack_retries,
352 .maxlen = sizeof(int),
353 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800354 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 },
356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 .procname = "tcp_max_orphans",
358 .data = &sysctl_tcp_max_orphans,
359 .maxlen = sizeof(int),
360 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800361 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 },
363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700365 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 .maxlen = sizeof(int),
367 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800368 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 },
370 {
Alexander Duyck6648bd72012-06-21 13:58:31 +0000371 .procname = "ip_early_demux",
372 .data = &sysctl_ip_early_demux,
373 .maxlen = sizeof(int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec
376 },
377 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .procname = "ip_dynaddr",
379 .data = &sysctl_ip_dynaddr,
380 .maxlen = sizeof(int),
381 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800382 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 },
384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .procname = "tcp_keepalive_time",
386 .data = &sysctl_tcp_keepalive_time,
387 .maxlen = sizeof(int),
388 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800389 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 },
391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .procname = "tcp_keepalive_probes",
393 .data = &sysctl_tcp_keepalive_probes,
394 .maxlen = sizeof(int),
395 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800396 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 },
398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .procname = "tcp_keepalive_intvl",
400 .data = &sysctl_tcp_keepalive_intvl,
401 .maxlen = sizeof(int),
402 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800403 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 },
405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .procname = "tcp_retries1",
407 .data = &sysctl_tcp_retries1,
408 .maxlen = sizeof(int),
409 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800410 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .extra2 = &tcp_retr1_max
412 },
413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 .procname = "tcp_retries2",
415 .data = &sysctl_tcp_retries2,
416 .maxlen = sizeof(int),
417 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800418 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 },
420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .procname = "tcp_fin_timeout",
422 .data = &sysctl_tcp_fin_timeout,
423 .maxlen = sizeof(int),
424 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800425 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 },
427#ifdef CONFIG_SYN_COOKIES
428 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 .procname = "tcp_syncookies",
430 .data = &sysctl_tcp_syncookies,
431 .maxlen = sizeof(int),
432 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800433 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 },
435#endif
436 {
Yuchung Cheng2100c8d2012-07-19 06:43:05 +0000437 .procname = "tcp_fastopen",
438 .data = &sysctl_tcp_fastopen,
439 .maxlen = sizeof(int),
440 .mode = 0644,
441 .proc_handler = proc_dointvec,
442 },
443 {
Jerry Chu10467162012-08-31 12:29:11 +0000444 .procname = "tcp_fastopen_key",
445 .mode = 0600,
446 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
447 .proc_handler = proc_tcp_fastopen_key,
448 },
449 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700451 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 .maxlen = sizeof(int),
453 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800454 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 },
456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "tcp_abort_on_overflow",
458 .data = &sysctl_tcp_abort_on_overflow,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800461 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .procname = "tcp_stdurg",
465 .data = &sysctl_tcp_stdurg,
466 .maxlen = sizeof(int),
467 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800468 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 },
470 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 .procname = "tcp_rfc1337",
472 .data = &sysctl_tcp_rfc1337,
473 .maxlen = sizeof(int),
474 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800475 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 },
477 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 .procname = "tcp_max_syn_backlog",
479 .data = &sysctl_max_syn_backlog,
480 .maxlen = sizeof(int),
481 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800482 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 },
484 {
Amerigo Wange3826f12010-05-05 00:27:06 +0000485 .procname = "ip_local_reserved_ports",
486 .data = NULL, /* initialized in sysctl_ipv4_init */
487 .maxlen = 65536,
488 .mode = 0644,
489 .proc_handler = proc_do_large_bitmap,
490 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .procname = "igmp_max_memberships",
493 .data = &sysctl_igmp_max_memberships,
494 .maxlen = sizeof(int),
495 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800496 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .procname = "igmp_max_msf",
500 .data = &sysctl_igmp_max_msf,
501 .maxlen = sizeof(int),
502 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800503 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
505 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .procname = "inet_peer_threshold",
507 .data = &inet_peer_threshold,
508 .maxlen = sizeof(int),
509 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800510 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 },
512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .procname = "inet_peer_minttl",
514 .data = &inet_peer_minttl,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800517 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 },
519 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .procname = "inet_peer_maxttl",
521 .data = &inet_peer_maxttl,
522 .maxlen = sizeof(int),
523 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800524 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 },
526 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .procname = "tcp_orphan_retries",
528 .data = &sysctl_tcp_orphan_retries,
529 .maxlen = sizeof(int),
530 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800531 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 },
533 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 .procname = "tcp_fack",
535 .data = &sysctl_tcp_fack,
536 .maxlen = sizeof(int),
537 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800538 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 },
540 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 .procname = "tcp_reordering",
542 .data = &sysctl_tcp_reordering,
543 .maxlen = sizeof(int),
544 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800545 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 },
547 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 .procname = "tcp_dsack",
549 .data = &sysctl_tcp_dsack,
550 .maxlen = sizeof(int),
551 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800552 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 },
554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 .procname = "tcp_wmem",
556 .data = &sysctl_tcp_wmem,
557 .maxlen = sizeof(sysctl_tcp_wmem),
558 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000559 .proc_handler = proc_dointvec_minmax,
560 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 },
562 {
Eric Dumazetc9bee3b72013-07-22 20:27:07 -0700563 .procname = "tcp_notsent_lowat",
564 .data = &sysctl_tcp_notsent_lowat,
565 .maxlen = sizeof(sysctl_tcp_notsent_lowat),
566 .mode = 0644,
567 .proc_handler = proc_dointvec,
568 },
569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "tcp_rmem",
571 .data = &sysctl_tcp_rmem,
572 .maxlen = sizeof(sysctl_tcp_rmem),
573 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000574 .proc_handler = proc_dointvec_minmax,
575 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
577 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 .procname = "tcp_app_win",
579 .data = &sysctl_tcp_app_win,
580 .maxlen = sizeof(int),
581 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800582 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 },
584 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .procname = "tcp_adv_win_scale",
586 .data = &sysctl_tcp_adv_win_scale,
587 .maxlen = sizeof(int),
588 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000589 .proc_handler = proc_dointvec_minmax,
590 .extra1 = &tcp_adv_win_scale_min,
591 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 },
593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "tcp_tw_reuse",
595 .data = &sysctl_tcp_tw_reuse,
596 .maxlen = sizeof(int),
597 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800598 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
600 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .procname = "tcp_frto",
602 .data = &sysctl_tcp_frto,
603 .maxlen = sizeof(int),
604 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800605 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 },
607 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .procname = "tcp_low_latency",
609 .data = &sysctl_tcp_low_latency,
610 .maxlen = sizeof(int),
611 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800612 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 },
614 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 .procname = "tcp_no_metrics_save",
616 .data = &sysctl_tcp_nometrics_save,
617 .maxlen = sizeof(int),
618 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800619 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 },
621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .procname = "tcp_moderate_rcvbuf",
623 .data = &sysctl_tcp_moderate_rcvbuf,
624 .maxlen = sizeof(int),
625 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800626 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 },
628 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .procname = "tcp_tso_win_divisor",
630 .data = &sysctl_tcp_tso_win_divisor,
631 .maxlen = sizeof(int),
632 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800633 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 },
635 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700636 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700638 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800639 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800641 {
John Heffner5d424d52006-03-20 17:53:41 -0800642 .procname = "tcp_mtu_probing",
643 .data = &sysctl_tcp_mtu_probing,
644 .maxlen = sizeof(int),
645 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800646 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800647 },
648 {
John Heffner5d424d52006-03-20 17:53:41 -0800649 .procname = "tcp_base_mss",
650 .data = &sysctl_tcp_base_mss,
651 .maxlen = sizeof(int),
652 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800653 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800654 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900655 {
Rick Jones15d99e02006-03-20 22:40:29 -0800656 .procname = "tcp_workaround_signed_windows",
657 .data = &sysctl_tcp_workaround_signed_windows,
658 .maxlen = sizeof(int),
659 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800660 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800661 },
Eric Dumazet46d3cea2012-07-11 05:50:31 +0000662 {
663 .procname = "tcp_limit_output_bytes",
664 .data = &sysctl_tcp_limit_output_bytes,
665 .maxlen = sizeof(int),
666 .mode = 0644,
667 .proc_handler = proc_dointvec
668 },
Eric Dumazet282f23c2012-07-17 10:13:05 +0200669 {
670 .procname = "tcp_challenge_ack_limit",
671 .data = &sysctl_tcp_challenge_ack_limit,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = proc_dointvec
675 },
Chris Leech95937822006-05-23 18:02:55 -0700676#ifdef CONFIG_NET_DMA
677 {
Chris Leech95937822006-05-23 18:02:55 -0700678 .procname = "tcp_dma_copybreak",
679 .data = &sysctl_tcp_dma_copybreak,
680 .maxlen = sizeof(int),
681 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800682 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700683 },
684#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700685 {
David S. Miller35089bb2006-06-13 22:33:04 -0700686 .procname = "tcp_slow_start_after_idle",
687 .data = &sysctl_tcp_slow_start_after_idle,
688 .maxlen = sizeof(int),
689 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800690 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700691 },
Paul Moore446fda42006-08-03 16:48:06 -0700692#ifdef CONFIG_NETLABEL
693 {
Paul Moore446fda42006-08-03 16:48:06 -0700694 .procname = "cipso_cache_enable",
695 .data = &cipso_v4_cache_enabled,
696 .maxlen = sizeof(int),
697 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800698 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700699 },
700 {
Paul Moore446fda42006-08-03 16:48:06 -0700701 .procname = "cipso_cache_bucket_size",
702 .data = &cipso_v4_cache_bucketsize,
703 .maxlen = sizeof(int),
704 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800705 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700706 },
707 {
Paul Moore446fda42006-08-03 16:48:06 -0700708 .procname = "cipso_rbm_optfmt",
709 .data = &cipso_v4_rbm_optfmt,
710 .maxlen = sizeof(int),
711 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800712 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700713 },
714 {
Paul Moore446fda42006-08-03 16:48:06 -0700715 .procname = "cipso_rbm_strictvalid",
716 .data = &cipso_v4_rbm_strictvalid,
717 .maxlen = sizeof(int),
718 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800719 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700720 },
721#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800722 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800723 .procname = "tcp_available_congestion_control",
724 .maxlen = TCP_CA_BUF_MAX,
725 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800726 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800727 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800728 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800729 .procname = "tcp_allowed_congestion_control",
730 .maxlen = TCP_CA_BUF_MAX,
731 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800732 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800733 },
John Heffner886236c2007-03-25 19:21:45 -0700734 {
John Heffner886236c2007-03-25 19:21:45 -0700735 .procname = "tcp_max_ssthresh",
736 .data = &sysctl_tcp_max_ssthresh,
737 .maxlen = sizeof(int),
738 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800739 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700740 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800741 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000742 .procname = "tcp_thin_linear_timeouts",
743 .data = &sysctl_tcp_thin_linear_timeouts,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = proc_dointvec
747 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000748 {
749 .procname = "tcp_thin_dupack",
750 .data = &sysctl_tcp_thin_dupack,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec
754 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000755 {
Yuchung Chengeed530b2012-05-02 13:30:03 +0000756 .procname = "tcp_early_retrans",
757 .data = &sysctl_tcp_early_retrans,
758 .maxlen = sizeof(int),
759 .mode = 0644,
760 .proc_handler = proc_dointvec_minmax,
761 .extra1 = &zero,
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +0000762 .extra2 = &four,
Yuchung Chengeed530b2012-05-02 13:30:03 +0000763 },
764 {
Eric Dumazet95bd09e2013-08-27 05:46:32 -0700765 .procname = "tcp_min_tso_segs",
766 .data = &sysctl_tcp_min_tso_segs,
767 .maxlen = sizeof(int),
768 .mode = 0644,
769 .proc_handler = proc_dointvec_minmax,
770 .extra1 = &zero,
771 .extra2 = &gso_max_segs,
772 },
773 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800774 .procname = "udp_mem",
775 .data = &sysctl_udp_mem,
776 .maxlen = sizeof(sysctl_udp_mem),
777 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000778 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800779 },
780 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800781 .procname = "udp_rmem_min",
782 .data = &sysctl_udp_rmem_min,
783 .maxlen = sizeof(sysctl_udp_rmem_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 },
788 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800789 .procname = "udp_wmem_min",
790 .data = &sysctl_udp_wmem_min,
791 .maxlen = sizeof(sysctl_udp_wmem_min),
792 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800793 .proc_handler = proc_dointvec_minmax,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000794 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800795 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800796 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800798
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700799static struct ctl_table ipv4_net_table[] = {
800 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700801 .procname = "icmp_echo_ignore_all",
802 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
803 .maxlen = sizeof(int),
804 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800805 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700806 },
807 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700808 .procname = "icmp_echo_ignore_broadcasts",
809 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
810 .maxlen = sizeof(int),
811 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800812 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700813 },
814 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700815 .procname = "icmp_ignore_bogus_error_responses",
816 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
817 .maxlen = sizeof(int),
818 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800819 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700820 },
821 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700822 .procname = "icmp_errors_use_inbound_ifaddr",
823 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
824 .maxlen = sizeof(int),
825 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800826 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700827 },
828 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700829 .procname = "icmp_ratelimit",
830 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
831 .maxlen = sizeof(int),
832 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800833 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700834 },
835 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700836 .procname = "icmp_ratemask",
837 .data = &init_net.ipv4.sysctl_icmp_ratemask,
838 .maxlen = sizeof(int),
839 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800840 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700841 },
Neil Horman1080d702008-10-27 12:28:25 -0700842 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000843 .procname = "ping_group_range",
844 .data = &init_net.ipv4.sysctl_ping_group_range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600845 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000846 .mode = 0644,
847 .proc_handler = ipv4_ping_group_range,
848 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000849 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000850 .procname = "tcp_ecn",
851 .data = &init_net.ipv4.sysctl_tcp_ecn,
852 .maxlen = sizeof(int),
853 .mode = 0644,
854 .proc_handler = proc_dointvec
855 },
856 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700857 .procname = "ip_local_port_range",
858 .maxlen = sizeof(init_net.ipv4.sysctl_local_ports.range),
859 .data = &init_net.ipv4.sysctl_local_ports.range,
860 .mode = 0644,
861 .proc_handler = ipv4_local_port_range,
862 },
863 {
Glauber Costa3dc43e32011-12-11 21:47:05 +0000864 .procname = "tcp_mem",
865 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_mem),
866 .mode = 0644,
867 .proc_handler = ipv4_tcp_mem,
868 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700869 { }
870};
871
Pavel Emelyanov15775192008-03-26 01:54:18 -0700872static __net_init int ipv4_sysctl_init_net(struct net *net)
873{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700874 struct ctl_table *table;
875
876 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800877 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700878 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
879 if (table == NULL)
880 goto err_alloc;
881
882 table[0].data =
883 &net->ipv4.sysctl_icmp_echo_ignore_all;
884 table[1].data =
885 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
886 table[2].data =
887 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
888 table[3].data =
889 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
890 table[4].data =
891 &net->ipv4.sysctl_icmp_ratelimit;
892 table[5].data =
893 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700894 table[6].data =
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000895 &net->ipv4.sysctl_ping_group_range;
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000896 table[7].data =
897 &net->ipv4.sysctl_tcp_ecn;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700898 table[8].data =
899 &net->ipv4.sysctl_local_ports.range;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000900
Eric W. Biederman464dc802012-11-16 03:02:59 +0000901 /* Don't export sysctls to unprivileged users */
902 if (net->user_ns != &init_user_ns)
903 table[0].procname = NULL;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700904 }
905
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000906 /*
907 * Sane defaults - nobody may create ping sockets.
908 * Boot scripts should set this to distro-specific group.
909 */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600910 net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
911 net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000912
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700913 /*
914 * Set defaults for local port range
915 */
916 seqlock_init(&net->ipv4.sysctl_local_ports.lock);
917 net->ipv4.sysctl_local_ports.range[0] = 32768;
918 net->ipv4.sysctl_local_ports.range[1] = 61000;
919
Glauber Costa4acb4192012-01-30 01:20:17 +0000920 tcp_init_mem(net);
Glauber Costa3dc43e32011-12-11 21:47:05 +0000921
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000922 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700923 if (net->ipv4.ipv4_hdr == NULL)
924 goto err_reg;
925
Pavel Emelyanov15775192008-03-26 01:54:18 -0700926 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700927
928err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800929 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700930 kfree(table);
931err_alloc:
932 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700933}
934
935static __net_exit void ipv4_sysctl_exit_net(struct net *net)
936{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700937 struct ctl_table *table;
938
939 table = net->ipv4.ipv4_hdr->ctl_table_arg;
940 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
941 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700942}
943
944static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
945 .init = ipv4_sysctl_init_net,
946 .exit = ipv4_sysctl_exit_net,
947};
948
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800949static __init int sysctl_ipv4_init(void)
950{
951 struct ctl_table_header *hdr;
Amerigo Wange3826f12010-05-05 00:27:06 +0000952 struct ctl_table *i;
953
954 for (i = ipv4_table; i->procname; i++) {
955 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
956 i->data = sysctl_local_reserved_ports;
957 break;
958 }
959 }
960 if (!i->procname)
961 return -EINVAL;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800962
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000963 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700964 if (hdr == NULL)
965 return -ENOMEM;
966
967 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000968 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700969 return -ENOMEM;
970 }
971
972 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800973}
974
975__initcall(sysctl_ipv4_init);