blob: 610e324348d1cc5acdd861d8af916331d49244d7 [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;
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;
Michal Tesar651e9272013-07-19 14:09:01 +020039static int tcp_syn_retries_min = 1;
40static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000041static int ip_ping_group_range_min[] = { 0, 0 };
42static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Stephen Hemminger227b60f2007-10-10 17:30:46 -070044/* Update system visible IP port range */
45static void set_local_port_range(int range[2])
46{
Eric Dumazet3c689b72008-10-08 14:18:04 -070047 write_seqlock(&sysctl_local_ports.lock);
48 sysctl_local_ports.range[0] = range[0];
49 sysctl_local_ports.range[1] = range[1];
50 write_sequnlock(&sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070051}
52
53/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070054static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070055 void __user *buffer,
56 size_t *lenp, loff_t *ppos)
57{
58 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070059 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070060 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070061 .data = &range,
62 .maxlen = sizeof(range),
63 .mode = table->mode,
64 .extra1 = &ip_local_port_range_min,
65 .extra2 = &ip_local_port_range_max,
66 };
67
Eric Dumazet3c689b72008-10-08 14:18:04 -070068 inet_get_local_port_range(range, range + 1);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070069 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070070
71 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070072 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070073 ret = -EINVAL;
74 else
75 set_local_port_range(range);
76 }
77
78 return ret;
79}
80
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000081
Eric W. Biederman7064d162012-05-24 10:34:21 -060082static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000083{
Eric W. Biederman7064d162012-05-24 10:34:21 -060084 kgid_t *data = table->data;
Eric Dumazet95c96172012-04-15 05:58:06 +000085 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000086 do {
87 seq = read_seqbegin(&sysctl_local_ports.lock);
88
89 *low = data[0];
90 *high = data[1];
91 } while (read_seqretry(&sysctl_local_ports.lock, seq));
92}
93
94/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -060095static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000096{
Eric W. Biederman7064d162012-05-24 10:34:21 -060097 kgid_t *data = table->data;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000098 write_seqlock(&sysctl_local_ports.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -060099 data[0] = low;
100 data[1] = high;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000101 write_sequnlock(&sysctl_local_ports.lock);
102}
103
104/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700105static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000106 void __user *buffer,
107 size_t *lenp, loff_t *ppos)
108{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600109 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000110 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600111 gid_t urange[2];
112 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700113 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600114 .data = &urange,
115 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000116 .mode = table->mode,
117 .extra1 = &ip_ping_group_range_min,
118 .extra2 = &ip_ping_group_range_max,
119 };
120
Eric W. Biederman7064d162012-05-24 10:34:21 -0600121 inet_get_ping_group_range_table(table, &low, &high);
122 urange[0] = from_kgid_munged(user_ns, low);
123 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000124 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
125
Eric W. Biederman7064d162012-05-24 10:34:21 -0600126 if (write && ret == 0) {
127 low = make_kgid(user_ns, urange[0]);
128 high = make_kgid(user_ns, urange[1]);
129 if (!gid_valid(low) || !gid_valid(high) ||
130 (urange[1] < urange[0]) || gid_lt(high, low)) {
131 low = make_kgid(&init_user_ns, 1);
132 high = make_kgid(&init_user_ns, 0);
133 }
134 set_ping_group_range(table, low, high);
135 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000136
137 return ret;
138}
139
Joe Perchesfe2c6332013-06-11 23:04:25 -0700140static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700141 void __user *buffer, size_t *lenp, loff_t *ppos)
142{
143 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700144 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700145 .data = val,
146 .maxlen = TCP_CA_NAME_MAX,
147 };
148 int ret;
149
150 tcp_get_default_congestion_control(val);
151
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700152 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700153 if (write && ret == 0)
154 ret = tcp_set_default_congestion_control(val);
155 return ret;
156}
157
Joe Perchesfe2c6332013-06-11 23:04:25 -0700158static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700159 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800160 void __user *buffer, size_t *lenp,
161 loff_t *ppos)
162{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700163 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800164 int ret;
165
166 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
167 if (!tbl.data)
168 return -ENOMEM;
169 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700170 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800171 kfree(tbl.data);
172 return ret;
173}
174
Joe Perchesfe2c6332013-06-11 23:04:25 -0700175static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700176 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800177 void __user *buffer, size_t *lenp,
178 loff_t *ppos)
179{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700180 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800181 int ret;
182
183 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
184 if (!tbl.data)
185 return -ENOMEM;
186
187 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700188 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800189 if (write && ret == 0)
190 ret = tcp_set_allowed_congestion_control(tbl.data);
191 kfree(tbl.data);
192 return ret;
193}
194
Joe Perchesfe2c6332013-06-11 23:04:25 -0700195static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
Glauber Costa3dc43e32011-12-11 21:47:05 +0000196 void __user *buffer, size_t *lenp,
197 loff_t *ppos)
198{
199 int ret;
200 unsigned long vec[3];
201 struct net *net = current->nsproxy->net_ns;
Andrew Mortonc255a452012-07-31 16:43:02 -0700202#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000203 struct mem_cgroup *memcg;
204#endif
Glauber Costa3dc43e32011-12-11 21:47:05 +0000205
Joe Perchesfe2c6332013-06-11 23:04:25 -0700206 struct ctl_table tmp = {
Glauber Costa3dc43e32011-12-11 21:47:05 +0000207 .data = &vec,
208 .maxlen = sizeof(vec),
209 .mode = ctl->mode,
210 };
211
212 if (!write) {
213 ctl->data = &net->ipv4.sysctl_tcp_mem;
214 return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
215 }
216
217 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
218 if (ret)
219 return ret;
220
Andrew Mortonc255a452012-07-31 16:43:02 -0700221#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000222 rcu_read_lock();
223 memcg = mem_cgroup_from_task(current);
224
225 tcp_prot_mem(memcg, vec[0], 0);
226 tcp_prot_mem(memcg, vec[1], 1);
227 tcp_prot_mem(memcg, vec[2], 2);
228 rcu_read_unlock();
229#endif
230
Glauber Costa3dc43e32011-12-11 21:47:05 +0000231 net->ipv4.sysctl_tcp_mem[0] = vec[0];
232 net->ipv4.sysctl_tcp_mem[1] = vec[1];
233 net->ipv4.sysctl_tcp_mem[2] = vec[2];
234
235 return 0;
236}
237
Joe Perchesfe2c6332013-06-11 23:04:25 -0700238static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
239 void __user *buffer, size_t *lenp,
240 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000241{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700242 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000243 struct tcp_fastopen_context *ctxt;
244 int ret;
245 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
246
247 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
248 if (!tbl.data)
249 return -ENOMEM;
250
251 rcu_read_lock();
252 ctxt = rcu_dereference(tcp_fastopen_ctx);
253 if (ctxt)
254 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000255 else
256 memset(user_key, 0, sizeof(user_key));
Jerry Chu10467162012-08-31 12:29:11 +0000257 rcu_read_unlock();
258
259 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
260 user_key[0], user_key[1], user_key[2], user_key[3]);
261 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
262
263 if (write && ret == 0) {
264 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
265 user_key + 2, user_key + 3) != 4) {
266 ret = -EINVAL;
267 goto bad_key;
268 }
269 tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH);
270 }
271
272bad_key:
273 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
274 user_key[0], user_key[1], user_key[2], user_key[3],
275 (char *)tbl.data, ret);
276 kfree(tbl.data);
277 return ret;
278}
279
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800280static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "tcp_timestamps",
283 .data = &sysctl_tcp_timestamps,
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 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900288 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 .procname = "tcp_window_scaling",
290 .data = &sysctl_tcp_window_scaling,
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 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900295 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 .procname = "tcp_sack",
297 .data = &sysctl_tcp_sack,
298 .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 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900302 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 .procname = "tcp_retrans_collapse",
304 .data = &sysctl_tcp_retrans_collapse,
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 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900309 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900311 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 .maxlen = sizeof(int),
313 .mode = 0644,
Eric Dumazet249fab72010-12-13 12:16:14 -0800314 .proc_handler = proc_dointvec_minmax,
315 .extra1 = &ip_ttl_min,
316 .extra2 = &ip_ttl_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900318 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 .procname = "ip_no_pmtu_disc",
320 .data = &ipv4_config.no_pmtu_disc,
321 .maxlen = sizeof(int),
322 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800323 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 },
325 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 .procname = "ip_nonlocal_bind",
327 .data = &sysctl_ip_nonlocal_bind,
328 .maxlen = sizeof(int),
329 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800330 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 },
332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 .procname = "tcp_syn_retries",
334 .data = &sysctl_tcp_syn_retries,
335 .maxlen = sizeof(int),
336 .mode = 0644,
Michal Tesar651e9272013-07-19 14:09:01 +0200337 .proc_handler = proc_dointvec_minmax,
338 .extra1 = &tcp_syn_retries_min,
339 .extra2 = &tcp_syn_retries_max
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 },
341 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 .procname = "tcp_synack_retries",
343 .data = &sysctl_tcp_synack_retries,
344 .maxlen = sizeof(int),
345 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800346 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 },
348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 .procname = "tcp_max_orphans",
350 .data = &sysctl_tcp_max_orphans,
351 .maxlen = sizeof(int),
352 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800353 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 },
355 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700357 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 .maxlen = sizeof(int),
359 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800360 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 },
362 {
Alexander Duyck6648bd72012-06-21 13:58:31 +0000363 .procname = "ip_early_demux",
364 .data = &sysctl_ip_early_demux,
365 .maxlen = sizeof(int),
366 .mode = 0644,
367 .proc_handler = proc_dointvec
368 },
369 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 .procname = "ip_dynaddr",
371 .data = &sysctl_ip_dynaddr,
372 .maxlen = sizeof(int),
373 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800374 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 },
376 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 .procname = "tcp_keepalive_time",
378 .data = &sysctl_tcp_keepalive_time,
379 .maxlen = sizeof(int),
380 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800381 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 },
383 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 .procname = "tcp_keepalive_probes",
385 .data = &sysctl_tcp_keepalive_probes,
386 .maxlen = sizeof(int),
387 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800388 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 },
390 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 .procname = "tcp_keepalive_intvl",
392 .data = &sysctl_tcp_keepalive_intvl,
393 .maxlen = sizeof(int),
394 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800395 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 },
397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .procname = "tcp_retries1",
399 .data = &sysctl_tcp_retries1,
400 .maxlen = sizeof(int),
401 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800402 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 .extra2 = &tcp_retr1_max
404 },
405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .procname = "tcp_retries2",
407 .data = &sysctl_tcp_retries2,
408 .maxlen = sizeof(int),
409 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800410 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 .procname = "tcp_fin_timeout",
414 .data = &sysctl_tcp_fin_timeout,
415 .maxlen = sizeof(int),
416 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800417 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 },
419#ifdef CONFIG_SYN_COOKIES
420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .procname = "tcp_syncookies",
422 .data = &sysctl_tcp_syncookies,
423 .maxlen = sizeof(int),
424 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800425 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 },
427#endif
428 {
Yuchung Cheng2100c8d2012-07-19 06:43:05 +0000429 .procname = "tcp_fastopen",
430 .data = &sysctl_tcp_fastopen,
431 .maxlen = sizeof(int),
432 .mode = 0644,
433 .proc_handler = proc_dointvec,
434 },
435 {
Jerry Chu10467162012-08-31 12:29:11 +0000436 .procname = "tcp_fastopen_key",
437 .mode = 0600,
438 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
439 .proc_handler = proc_tcp_fastopen_key,
440 },
441 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700443 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 .maxlen = sizeof(int),
445 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800446 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 },
448 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 .procname = "tcp_abort_on_overflow",
450 .data = &sysctl_tcp_abort_on_overflow,
451 .maxlen = sizeof(int),
452 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800453 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 },
455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 .procname = "tcp_stdurg",
457 .data = &sysctl_tcp_stdurg,
458 .maxlen = sizeof(int),
459 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800460 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 },
462 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 .procname = "tcp_rfc1337",
464 .data = &sysctl_tcp_rfc1337,
465 .maxlen = sizeof(int),
466 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800467 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 },
469 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 .procname = "tcp_max_syn_backlog",
471 .data = &sysctl_max_syn_backlog,
472 .maxlen = sizeof(int),
473 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800474 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 },
476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .procname = "ip_local_port_range",
Eric Dumazet3c689b72008-10-08 14:18:04 -0700478 .data = &sysctl_local_ports.range,
479 .maxlen = sizeof(sysctl_local_ports.range),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800481 .proc_handler = ipv4_local_port_range,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 },
Amerigo Wange3826f12010-05-05 00:27:06 +0000483 {
484 .procname = "ip_local_reserved_ports",
485 .data = NULL, /* initialized in sysctl_ipv4_init */
486 .maxlen = 65536,
487 .mode = 0644,
488 .proc_handler = proc_do_large_bitmap,
489 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 .procname = "igmp_max_memberships",
492 .data = &sysctl_igmp_max_memberships,
493 .maxlen = sizeof(int),
494 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800495 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .procname = "igmp_max_msf",
499 .data = &sysctl_igmp_max_msf,
500 .maxlen = sizeof(int),
501 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800502 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 },
504 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .procname = "inet_peer_threshold",
506 .data = &inet_peer_threshold,
507 .maxlen = sizeof(int),
508 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800509 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 },
511 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .procname = "inet_peer_minttl",
513 .data = &inet_peer_minttl,
514 .maxlen = sizeof(int),
515 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800516 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 },
518 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 .procname = "inet_peer_maxttl",
520 .data = &inet_peer_maxttl,
521 .maxlen = sizeof(int),
522 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800523 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 },
525 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 .procname = "tcp_orphan_retries",
527 .data = &sysctl_tcp_orphan_retries,
528 .maxlen = sizeof(int),
529 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800530 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 },
532 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 .procname = "tcp_fack",
534 .data = &sysctl_tcp_fack,
535 .maxlen = sizeof(int),
536 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800537 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 },
539 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 .procname = "tcp_reordering",
541 .data = &sysctl_tcp_reordering,
542 .maxlen = sizeof(int),
543 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800544 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 },
546 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 .procname = "tcp_dsack",
548 .data = &sysctl_tcp_dsack,
549 .maxlen = sizeof(int),
550 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800551 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 },
553 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .procname = "tcp_wmem",
555 .data = &sysctl_tcp_wmem,
556 .maxlen = sizeof(sysctl_tcp_wmem),
557 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000558 .proc_handler = proc_dointvec_minmax,
559 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 },
561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "tcp_rmem",
563 .data = &sysctl_tcp_rmem,
564 .maxlen = sizeof(sysctl_tcp_rmem),
565 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000566 .proc_handler = proc_dointvec_minmax,
567 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 },
569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "tcp_app_win",
571 .data = &sysctl_tcp_app_win,
572 .maxlen = sizeof(int),
573 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800574 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 },
576 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 .procname = "tcp_adv_win_scale",
578 .data = &sysctl_tcp_adv_win_scale,
579 .maxlen = sizeof(int),
580 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000581 .proc_handler = proc_dointvec_minmax,
582 .extra1 = &tcp_adv_win_scale_min,
583 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
585 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 .procname = "tcp_tw_reuse",
587 .data = &sysctl_tcp_tw_reuse,
588 .maxlen = sizeof(int),
589 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800590 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 },
592 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 .procname = "tcp_frto",
594 .data = &sysctl_tcp_frto,
595 .maxlen = sizeof(int),
596 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800597 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 },
599 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .procname = "tcp_low_latency",
601 .data = &sysctl_tcp_low_latency,
602 .maxlen = sizeof(int),
603 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800604 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 },
606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "tcp_no_metrics_save",
608 .data = &sysctl_tcp_nometrics_save,
609 .maxlen = sizeof(int),
610 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800611 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 },
613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .procname = "tcp_moderate_rcvbuf",
615 .data = &sysctl_tcp_moderate_rcvbuf,
616 .maxlen = sizeof(int),
617 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800618 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 },
620 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .procname = "tcp_tso_win_divisor",
622 .data = &sysctl_tcp_tso_win_divisor,
623 .maxlen = sizeof(int),
624 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800625 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 },
627 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700628 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700630 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800631 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800633 {
John Heffner5d424d52006-03-20 17:53:41 -0800634 .procname = "tcp_mtu_probing",
635 .data = &sysctl_tcp_mtu_probing,
636 .maxlen = sizeof(int),
637 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800638 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800639 },
640 {
John Heffner5d424d52006-03-20 17:53:41 -0800641 .procname = "tcp_base_mss",
642 .data = &sysctl_tcp_base_mss,
643 .maxlen = sizeof(int),
644 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800645 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800646 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900647 {
Rick Jones15d99e02006-03-20 22:40:29 -0800648 .procname = "tcp_workaround_signed_windows",
649 .data = &sysctl_tcp_workaround_signed_windows,
650 .maxlen = sizeof(int),
651 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800652 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800653 },
Eric Dumazet46d3cea2012-07-11 05:50:31 +0000654 {
655 .procname = "tcp_limit_output_bytes",
656 .data = &sysctl_tcp_limit_output_bytes,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 .proc_handler = proc_dointvec
660 },
Eric Dumazet282f23c2012-07-17 10:13:05 +0200661 {
662 .procname = "tcp_challenge_ack_limit",
663 .data = &sysctl_tcp_challenge_ack_limit,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = proc_dointvec
667 },
Chris Leech95937822006-05-23 18:02:55 -0700668#ifdef CONFIG_NET_DMA
669 {
Chris Leech95937822006-05-23 18:02:55 -0700670 .procname = "tcp_dma_copybreak",
671 .data = &sysctl_tcp_dma_copybreak,
672 .maxlen = sizeof(int),
673 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800674 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700675 },
676#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700677 {
David S. Miller35089bb2006-06-13 22:33:04 -0700678 .procname = "tcp_slow_start_after_idle",
679 .data = &sysctl_tcp_slow_start_after_idle,
680 .maxlen = sizeof(int),
681 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800682 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700683 },
Paul Moore446fda42006-08-03 16:48:06 -0700684#ifdef CONFIG_NETLABEL
685 {
Paul Moore446fda42006-08-03 16:48:06 -0700686 .procname = "cipso_cache_enable",
687 .data = &cipso_v4_cache_enabled,
688 .maxlen = sizeof(int),
689 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800690 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700691 },
692 {
Paul Moore446fda42006-08-03 16:48:06 -0700693 .procname = "cipso_cache_bucket_size",
694 .data = &cipso_v4_cache_bucketsize,
695 .maxlen = sizeof(int),
696 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800697 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700698 },
699 {
Paul Moore446fda42006-08-03 16:48:06 -0700700 .procname = "cipso_rbm_optfmt",
701 .data = &cipso_v4_rbm_optfmt,
702 .maxlen = sizeof(int),
703 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800704 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700705 },
706 {
Paul Moore446fda42006-08-03 16:48:06 -0700707 .procname = "cipso_rbm_strictvalid",
708 .data = &cipso_v4_rbm_strictvalid,
709 .maxlen = sizeof(int),
710 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800711 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700712 },
713#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800714 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800715 .procname = "tcp_available_congestion_control",
716 .maxlen = TCP_CA_BUF_MAX,
717 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800718 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800719 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800720 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800721 .procname = "tcp_allowed_congestion_control",
722 .maxlen = TCP_CA_BUF_MAX,
723 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800724 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800725 },
John Heffner886236c2007-03-25 19:21:45 -0700726 {
John Heffner886236c2007-03-25 19:21:45 -0700727 .procname = "tcp_max_ssthresh",
728 .data = &sysctl_tcp_max_ssthresh,
729 .maxlen = sizeof(int),
730 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800731 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700732 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800733 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000734 .procname = "tcp_thin_linear_timeouts",
735 .data = &sysctl_tcp_thin_linear_timeouts,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = proc_dointvec
739 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000740 {
741 .procname = "tcp_thin_dupack",
742 .data = &sysctl_tcp_thin_dupack,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = proc_dointvec
746 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000747 {
Yuchung Chengeed530b2012-05-02 13:30:03 +0000748 .procname = "tcp_early_retrans",
749 .data = &sysctl_tcp_early_retrans,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = proc_dointvec_minmax,
753 .extra1 = &zero,
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +0000754 .extra2 = &four,
Yuchung Chengeed530b2012-05-02 13:30:03 +0000755 },
756 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800757 .procname = "udp_mem",
758 .data = &sysctl_udp_mem,
759 .maxlen = sizeof(sysctl_udp_mem),
760 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000761 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800762 },
763 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800764 .procname = "udp_rmem_min",
765 .data = &sysctl_udp_rmem_min,
766 .maxlen = sizeof(sysctl_udp_rmem_min),
767 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800768 .proc_handler = proc_dointvec_minmax,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000769 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800770 },
771 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800772 .procname = "udp_wmem_min",
773 .data = &sysctl_udp_wmem_min,
774 .maxlen = sizeof(sysctl_udp_wmem_min),
775 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800776 .proc_handler = proc_dointvec_minmax,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000777 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800778 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800779 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800781
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700782static struct ctl_table ipv4_net_table[] = {
783 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700784 .procname = "icmp_echo_ignore_all",
785 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
786 .maxlen = sizeof(int),
787 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800788 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700789 },
790 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700791 .procname = "icmp_echo_ignore_broadcasts",
792 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
793 .maxlen = sizeof(int),
794 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800795 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700796 },
797 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700798 .procname = "icmp_ignore_bogus_error_responses",
799 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
800 .maxlen = sizeof(int),
801 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800802 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700803 },
804 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700805 .procname = "icmp_errors_use_inbound_ifaddr",
806 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
807 .maxlen = sizeof(int),
808 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800809 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700810 },
811 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700812 .procname = "icmp_ratelimit",
813 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
814 .maxlen = sizeof(int),
815 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800816 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700817 },
818 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700819 .procname = "icmp_ratemask",
820 .data = &init_net.ipv4.sysctl_icmp_ratemask,
821 .maxlen = sizeof(int),
822 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800823 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700824 },
Neil Horman1080d702008-10-27 12:28:25 -0700825 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000826 .procname = "ping_group_range",
827 .data = &init_net.ipv4.sysctl_ping_group_range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600828 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000829 .mode = 0644,
830 .proc_handler = ipv4_ping_group_range,
831 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000832 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000833 .procname = "tcp_ecn",
834 .data = &init_net.ipv4.sysctl_tcp_ecn,
835 .maxlen = sizeof(int),
836 .mode = 0644,
837 .proc_handler = proc_dointvec
838 },
839 {
Glauber Costa3dc43e32011-12-11 21:47:05 +0000840 .procname = "tcp_mem",
841 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_mem),
842 .mode = 0644,
843 .proc_handler = ipv4_tcp_mem,
844 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700845 { }
846};
847
Pavel Emelyanov15775192008-03-26 01:54:18 -0700848static __net_init int ipv4_sysctl_init_net(struct net *net)
849{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700850 struct ctl_table *table;
851
852 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800853 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700854 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
855 if (table == NULL)
856 goto err_alloc;
857
858 table[0].data =
859 &net->ipv4.sysctl_icmp_echo_ignore_all;
860 table[1].data =
861 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
862 table[2].data =
863 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
864 table[3].data =
865 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
866 table[4].data =
867 &net->ipv4.sysctl_icmp_ratelimit;
868 table[5].data =
869 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700870 table[6].data =
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000871 &net->ipv4.sysctl_ping_group_range;
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000872 table[7].data =
873 &net->ipv4.sysctl_tcp_ecn;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000874
Eric W. Biederman464dc802012-11-16 03:02:59 +0000875 /* Don't export sysctls to unprivileged users */
876 if (net->user_ns != &init_user_ns)
877 table[0].procname = NULL;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700878 }
879
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000880 /*
881 * Sane defaults - nobody may create ping sockets.
882 * Boot scripts should set this to distro-specific group.
883 */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600884 net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
885 net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000886
Glauber Costa4acb4192012-01-30 01:20:17 +0000887 tcp_init_mem(net);
Glauber Costa3dc43e32011-12-11 21:47:05 +0000888
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000889 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700890 if (net->ipv4.ipv4_hdr == NULL)
891 goto err_reg;
892
Pavel Emelyanov15775192008-03-26 01:54:18 -0700893 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700894
895err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800896 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700897 kfree(table);
898err_alloc:
899 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700900}
901
902static __net_exit void ipv4_sysctl_exit_net(struct net *net)
903{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700904 struct ctl_table *table;
905
906 table = net->ipv4.ipv4_hdr->ctl_table_arg;
907 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
908 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700909}
910
911static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
912 .init = ipv4_sysctl_init_net,
913 .exit = ipv4_sysctl_exit_net,
914};
915
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800916static __init int sysctl_ipv4_init(void)
917{
918 struct ctl_table_header *hdr;
Amerigo Wange3826f12010-05-05 00:27:06 +0000919 struct ctl_table *i;
920
921 for (i = ipv4_table; i->procname; i++) {
922 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
923 i->data = sysctl_local_reserved_ports;
924 break;
925 }
926 }
927 if (!i->procname)
928 return -EINVAL;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800929
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000930 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700931 if (hdr == NULL)
932 return -ENOMEM;
933
934 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000935 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700936 return -ENOMEM;
937 }
938
939 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800940}
941
942__initcall(sysctl_ipv4_init);