blob: 78019adcae875a438264ee47723670f6b54cacf9 [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>
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060027#include <net/protocol.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 Dumazet43e122b2015-08-21 17:38:02 -070032static int thousand = 1000;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070033static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090034static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static int ip_local_port_range_min[] = { 1, 1 };
36static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000037static int tcp_adv_win_scale_min = -31;
38static int tcp_adv_win_scale_max = 31;
Krister Johansen4548b682017-01-20 17:49:11 -080039static int ip_privileged_port_min;
40static int ip_privileged_port_max = 65535;
Eric Dumazet249fab72010-12-13 12:16:14 -080041static int ip_ttl_min = 1;
42static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020043static int tcp_syn_retries_min = 1;
44static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000045static int ip_ping_group_range_min[] = { 0, 0 };
46static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Florian Westphalb6690b12017-07-30 03:57:20 +020048/* obsolete */
49static int sysctl_tcp_low_latency __read_mostly;
50
Stephen Hemminger227b60f2007-10-10 17:30:46 -070051/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070052static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070053{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070054 bool same_parity = !((range[0] ^ range[1]) & 1);
55
WANG Cong4ee3bd42015-11-03 14:32:57 -080056 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070057 if (same_parity && !net->ipv4.ip_local_ports.warned) {
58 net->ipv4.ip_local_ports.warned = true;
59 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
60 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070061 net->ipv4.ip_local_ports.range[0] = range[0];
62 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080063 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070064}
65
66/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070067static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070068 void __user *buffer,
69 size_t *lenp, loff_t *ppos)
70{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070071 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070072 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070073 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070074 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070075 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070076 .data = &range,
77 .maxlen = sizeof(range),
78 .mode = table->mode,
79 .extra1 = &ip_local_port_range_min,
80 .extra2 = &ip_local_port_range_max,
81 };
82
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070083 inet_get_local_port_range(net, &range[0], &range[1]);
84
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070085 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070086
87 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080088 /* Ensure that the upper limit is not smaller than the lower,
89 * and that the lower does not encroach upon the privileged
90 * port limit.
91 */
92 if ((range[1] < range[0]) ||
93 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -070094 ret = -EINVAL;
95 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070096 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070097 }
98
99 return ret;
100}
101
Krister Johansen4548b682017-01-20 17:49:11 -0800102/* Validate changes from /proc interface. */
103static int ipv4_privileged_ports(struct ctl_table *table, int write,
104 void __user *buffer, size_t *lenp, loff_t *ppos)
105{
106 struct net *net = container_of(table->data, struct net,
107 ipv4.sysctl_ip_prot_sock);
108 int ret;
109 int pports;
110 int range[2];
111 struct ctl_table tmp = {
112 .data = &pports,
113 .maxlen = sizeof(pports),
114 .mode = table->mode,
115 .extra1 = &ip_privileged_port_min,
116 .extra2 = &ip_privileged_port_max,
117 };
118
119 pports = net->ipv4.sysctl_ip_prot_sock;
120
121 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
122
123 if (write && ret == 0) {
124 inet_get_local_port_range(net, &range[0], &range[1]);
125 /* Ensure that the local port range doesn't overlap with the
126 * privileged port range.
127 */
128 if (range[0] < pports)
129 ret = -EINVAL;
130 else
131 net->ipv4.sysctl_ip_prot_sock = pports;
132 }
133
134 return ret;
135}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000136
Eric W. Biederman7064d162012-05-24 10:34:21 -0600137static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000138{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600139 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700140 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700141 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000142 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000143 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700144 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000145
146 *low = data[0];
147 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700148 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000149}
150
151/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600152static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000153{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600154 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700155 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700156 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700157 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600158 data[0] = low;
159 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700160 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000161}
162
163/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700164static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000165 void __user *buffer,
166 size_t *lenp, loff_t *ppos)
167{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600168 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000169 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600170 gid_t urange[2];
171 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700172 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600173 .data = &urange,
174 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000175 .mode = table->mode,
176 .extra1 = &ip_ping_group_range_min,
177 .extra2 = &ip_ping_group_range_max,
178 };
179
Eric W. Biederman7064d162012-05-24 10:34:21 -0600180 inet_get_ping_group_range_table(table, &low, &high);
181 urange[0] = from_kgid_munged(user_ns, low);
182 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000183 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
184
Eric W. Biederman7064d162012-05-24 10:34:21 -0600185 if (write && ret == 0) {
186 low = make_kgid(user_ns, urange[0]);
187 high = make_kgid(user_ns, urange[1]);
188 if (!gid_valid(low) || !gid_valid(high) ||
189 (urange[1] < urange[0]) || gid_lt(high, low)) {
190 low = make_kgid(&init_user_ns, 1);
191 high = make_kgid(&init_user_ns, 0);
192 }
193 set_ping_group_range(table, low, high);
194 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000195
196 return ret;
197}
198
Joe Perchesfe2c6332013-06-11 23:04:25 -0700199static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700200 void __user *buffer, size_t *lenp, loff_t *ppos)
201{
202 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700203 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700204 .data = val,
205 .maxlen = TCP_CA_NAME_MAX,
206 };
207 int ret;
208
209 tcp_get_default_congestion_control(val);
210
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700211 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700212 if (write && ret == 0)
213 ret = tcp_set_default_congestion_control(val);
214 return ret;
215}
216
Joe Perchesfe2c6332013-06-11 23:04:25 -0700217static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700218 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800219 void __user *buffer, size_t *lenp,
220 loff_t *ppos)
221{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700222 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800223 int ret;
224
225 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
226 if (!tbl.data)
227 return -ENOMEM;
228 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700229 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800230 kfree(tbl.data);
231 return ret;
232}
233
Joe Perchesfe2c6332013-06-11 23:04:25 -0700234static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700235 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800236 void __user *buffer, size_t *lenp,
237 loff_t *ppos)
238{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700239 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800240 int ret;
241
242 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
243 if (!tbl.data)
244 return -ENOMEM;
245
246 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700247 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800248 if (write && ret == 0)
249 ret = tcp_set_allowed_congestion_control(tbl.data);
250 kfree(tbl.data);
251 return ret;
252}
253
Haishuang Yan43713842017-09-27 11:35:42 +0800254static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700255 void __user *buffer, size_t *lenp,
256 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000257{
Haishuang Yan43713842017-09-27 11:35:42 +0800258 struct net *net = container_of(table->data, struct net,
259 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700260 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000261 struct tcp_fastopen_context *ctxt;
262 int ret;
263 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
264
265 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
266 if (!tbl.data)
267 return -ENOMEM;
268
269 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800270 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000271 if (ctxt)
272 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000273 else
274 memset(user_key, 0, sizeof(user_key));
Jerry Chu10467162012-08-31 12:29:11 +0000275 rcu_read_unlock();
276
277 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
278 user_key[0], user_key[1], user_key[2], user_key[3]);
279 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
280
281 if (write && ret == 0) {
282 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
283 user_key + 2, user_key + 3) != 4) {
284 ret = -EINVAL;
285 goto bad_key;
286 }
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700287 tcp_fastopen_reset_cipher(net, NULL, user_key,
288 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000289 }
290
291bad_key:
292 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
293 user_key[0], user_key[1], user_key[2], user_key[3],
294 (char *)tbl.data, ret);
295 kfree(tbl.data);
296 return ret;
297}
298
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600299static void proc_configure_early_demux(int enabled, int protocol)
300{
301 struct net_protocol *ipprot;
302#if IS_ENABLED(CONFIG_IPV6)
303 struct inet6_protocol *ip6prot;
304#endif
305
David Ahern58c4c6a2017-04-22 09:33:16 -0700306 rcu_read_lock();
307
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600308 ipprot = rcu_dereference(inet_protos[protocol]);
309 if (ipprot)
310 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
311 NULL;
312
313#if IS_ENABLED(CONFIG_IPV6)
314 ip6prot = rcu_dereference(inet6_protos[protocol]);
315 if (ip6prot)
316 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
317 NULL;
318#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700319 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600320}
321
322static int proc_tcp_early_demux(struct ctl_table *table, int write,
323 void __user *buffer, size_t *lenp, loff_t *ppos)
324{
325 int ret = 0;
326
327 ret = proc_dointvec(table, write, buffer, lenp, ppos);
328
329 if (write && !ret) {
330 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
331
332 proc_configure_early_demux(enabled, IPPROTO_TCP);
333 }
334
335 return ret;
336}
337
338static int proc_udp_early_demux(struct ctl_table *table, int write,
339 void __user *buffer, size_t *lenp, loff_t *ppos)
340{
341 int ret = 0;
342
343 ret = proc_dointvec(table, write, buffer, lenp, ppos);
344
345 if (write && !ret) {
346 int enabled = init_net.ipv4.sysctl_udp_early_demux;
347
348 proc_configure_early_demux(enabled, IPPROTO_UDP);
349 }
350
351 return ret;
352}
353
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700354static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
355 int write,
356 void __user *buffer,
357 size_t *lenp, loff_t *ppos)
358{
Haishuang Yan3733be12017-09-27 11:35:43 +0800359 struct net *net = container_of(table->data, struct net,
360 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700361 int ret;
362
363 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
364 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800365 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700366
367 return ret;
368}
369
370static int proc_tcp_available_ulp(struct ctl_table *ctl,
371 int write,
372 void __user *buffer, size_t *lenp,
373 loff_t *ppos)
374{
375 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
376 int ret;
377
378 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
379 if (!tbl.data)
380 return -ENOMEM;
381 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
382 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
383 kfree(tbl.data);
384
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700385 return ret;
386}
387
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800388static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .procname = "tcp_retrans_collapse",
391 .data = &sysctl_tcp_retrans_collapse,
392 .maxlen = sizeof(int),
393 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800394 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900396 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 .procname = "tcp_max_orphans",
398 .data = &sysctl_tcp_max_orphans,
399 .maxlen = sizeof(int),
400 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800401 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 },
403 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .procname = "tcp_abort_on_overflow",
405 .data = &sysctl_tcp_abort_on_overflow,
406 .maxlen = sizeof(int),
407 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800408 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 },
410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .procname = "tcp_stdurg",
412 .data = &sysctl_tcp_stdurg,
413 .maxlen = sizeof(int),
414 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800415 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 },
417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .procname = "tcp_rfc1337",
419 .data = &sysctl_tcp_rfc1337,
420 .maxlen = sizeof(int),
421 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800422 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 },
424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .procname = "inet_peer_threshold",
426 .data = &inet_peer_threshold,
427 .maxlen = sizeof(int),
428 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800429 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 },
431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .procname = "inet_peer_minttl",
433 .data = &inet_peer_minttl,
434 .maxlen = sizeof(int),
435 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800436 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 },
438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .procname = "inet_peer_maxttl",
440 .data = &inet_peer_maxttl,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800443 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 },
445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .procname = "tcp_fack",
447 .data = &sysctl_tcp_fack,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800450 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 },
452 {
Eric Dumazetdca145f2014-10-27 21:45:24 -0700453 .procname = "tcp_max_reordering",
454 .data = &sysctl_tcp_max_reordering,
455 .maxlen = sizeof(int),
456 .mode = 0644,
457 .proc_handler = proc_dointvec
458 },
459 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .procname = "tcp_dsack",
461 .data = &sysctl_tcp_dsack,
462 .maxlen = sizeof(int),
463 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800464 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 },
466 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700467 .procname = "tcp_mem",
468 .maxlen = sizeof(sysctl_tcp_mem),
469 .data = &sysctl_tcp_mem,
470 .mode = 0644,
471 .proc_handler = proc_doulongvec_minmax,
472 },
473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "tcp_wmem",
475 .data = &sysctl_tcp_wmem,
476 .maxlen = sizeof(sysctl_tcp_wmem),
477 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000478 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700479 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 },
481 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .procname = "tcp_rmem",
483 .data = &sysctl_tcp_rmem,
484 .maxlen = sizeof(sysctl_tcp_rmem),
485 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000486 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700487 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 },
489 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 .procname = "tcp_app_win",
491 .data = &sysctl_tcp_app_win,
492 .maxlen = sizeof(int),
493 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800494 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 },
496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .procname = "tcp_adv_win_scale",
498 .data = &sysctl_tcp_adv_win_scale,
499 .maxlen = sizeof(int),
500 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000501 .proc_handler = proc_dointvec_minmax,
502 .extra1 = &tcp_adv_win_scale_min,
503 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
505 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .procname = "tcp_frto",
507 .data = &sysctl_tcp_frto,
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 {
Yuchung Chengf6722582015-10-16 21:57:42 -0700513 .procname = "tcp_min_rtt_wlen",
514 .data = &sysctl_tcp_min_rtt_wlen,
515 .maxlen = sizeof(int),
516 .mode = 0644,
517 .proc_handler = proc_dointvec
518 },
519 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .procname = "tcp_low_latency",
521 .data = &sysctl_tcp_low_latency,
522 .maxlen = sizeof(int),
523 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800524 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 },
526 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .procname = "tcp_no_metrics_save",
528 .data = &sysctl_tcp_nometrics_save,
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_moderate_rcvbuf",
535 .data = &sysctl_tcp_moderate_rcvbuf,
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_tso_win_divisor",
542 .data = &sysctl_tcp_tso_win_divisor,
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 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700548 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700550 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800551 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800553 {
Rick Jones15d99e02006-03-20 22:40:29 -0800554 .procname = "tcp_workaround_signed_windows",
555 .data = &sysctl_tcp_workaround_signed_windows,
556 .maxlen = sizeof(int),
557 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800558 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800559 },
Eric Dumazet46d3cea2012-07-11 05:50:31 +0000560 {
561 .procname = "tcp_limit_output_bytes",
562 .data = &sysctl_tcp_limit_output_bytes,
563 .maxlen = sizeof(int),
564 .mode = 0644,
565 .proc_handler = proc_dointvec
566 },
Eric Dumazet282f23c2012-07-17 10:13:05 +0200567 {
568 .procname = "tcp_challenge_ack_limit",
569 .data = &sysctl_tcp_challenge_ack_limit,
570 .maxlen = sizeof(int),
571 .mode = 0644,
572 .proc_handler = proc_dointvec
573 },
David S. Miller35089bb2006-06-13 22:33:04 -0700574 {
David S. Miller35089bb2006-06-13 22:33:04 -0700575 .procname = "tcp_slow_start_after_idle",
576 .data = &sysctl_tcp_slow_start_after_idle,
577 .maxlen = sizeof(int),
578 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800579 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700580 },
Paul Moore446fda42006-08-03 16:48:06 -0700581#ifdef CONFIG_NETLABEL
582 {
Paul Moore446fda42006-08-03 16:48:06 -0700583 .procname = "cipso_cache_enable",
584 .data = &cipso_v4_cache_enabled,
585 .maxlen = sizeof(int),
586 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800587 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700588 },
589 {
Paul Moore446fda42006-08-03 16:48:06 -0700590 .procname = "cipso_cache_bucket_size",
591 .data = &cipso_v4_cache_bucketsize,
592 .maxlen = sizeof(int),
593 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800594 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700595 },
596 {
Paul Moore446fda42006-08-03 16:48:06 -0700597 .procname = "cipso_rbm_optfmt",
598 .data = &cipso_v4_rbm_optfmt,
599 .maxlen = sizeof(int),
600 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800601 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700602 },
603 {
Paul Moore446fda42006-08-03 16:48:06 -0700604 .procname = "cipso_rbm_strictvalid",
605 .data = &cipso_v4_rbm_strictvalid,
606 .maxlen = sizeof(int),
607 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800608 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700609 },
610#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800611 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800612 .procname = "tcp_available_congestion_control",
613 .maxlen = TCP_CA_BUF_MAX,
614 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800615 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800616 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800617 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800618 .procname = "tcp_allowed_congestion_control",
619 .maxlen = TCP_CA_BUF_MAX,
620 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800621 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800622 },
John Heffner886236c2007-03-25 19:21:45 -0700623 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000624 .procname = "tcp_thin_linear_timeouts",
625 .data = &sysctl_tcp_thin_linear_timeouts,
626 .maxlen = sizeof(int),
627 .mode = 0644,
628 .proc_handler = proc_dointvec
629 },
Weilong Chen5797deb2013-12-23 14:37:31 +0800630 {
Eric Dumazet95bd09e2013-08-27 05:46:32 -0700631 .procname = "tcp_min_tso_segs",
632 .data = &sysctl_tcp_min_tso_segs,
633 .maxlen = sizeof(int),
634 .mode = 0644,
635 .proc_handler = proc_dointvec_minmax,
Eric Dumazetd6a4e262015-05-26 08:55:28 -0700636 .extra1 = &one,
Eric Dumazet95bd09e2013-08-27 05:46:32 -0700637 .extra2 = &gso_max_segs,
638 },
639 {
Eric Dumazet43e122b2015-08-21 17:38:02 -0700640 .procname = "tcp_pacing_ss_ratio",
641 .data = &sysctl_tcp_pacing_ss_ratio,
642 .maxlen = sizeof(int),
643 .mode = 0644,
644 .proc_handler = proc_dointvec_minmax,
645 .extra1 = &zero,
646 .extra2 = &thousand,
647 },
648 {
649 .procname = "tcp_pacing_ca_ratio",
650 .data = &sysctl_tcp_pacing_ca_ratio,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = proc_dointvec_minmax,
654 .extra1 = &zero,
655 .extra2 = &thousand,
656 },
657 {
Eric Dumazetf54b3112013-12-05 22:36:05 -0800658 .procname = "tcp_autocorking",
659 .data = &sysctl_tcp_autocorking,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = proc_dointvec_minmax,
663 .extra1 = &zero,
664 .extra2 = &one,
665 },
666 {
Neal Cardwell032ee422015-02-06 16:04:38 -0500667 .procname = "tcp_invalid_ratelimit",
668 .data = &sysctl_tcp_invalid_ratelimit,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = proc_dointvec_ms_jiffies,
672 },
673 {
Dave Watson734942c2017-06-14 11:37:14 -0700674 .procname = "tcp_available_ulp",
675 .maxlen = TCP_ULP_BUF_MAX,
676 .mode = 0444,
677 .proc_handler = proc_tcp_available_ulp,
678 },
679 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700680 .procname = "icmp_msgs_per_sec",
681 .data = &sysctl_icmp_msgs_per_sec,
682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = proc_dointvec_minmax,
685 .extra1 = &zero,
686 },
687 {
688 .procname = "icmp_msgs_burst",
689 .data = &sysctl_icmp_msgs_burst,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = proc_dointvec_minmax,
693 .extra1 = &zero,
694 },
695 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800696 .procname = "udp_mem",
697 .data = &sysctl_udp_mem,
698 .maxlen = sizeof(sysctl_udp_mem),
699 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000700 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800701 },
702 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800703 .procname = "udp_rmem_min",
704 .data = &sysctl_udp_rmem_min,
705 .maxlen = sizeof(sysctl_udp_rmem_min),
706 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800707 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700708 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800709 },
710 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800711 .procname = "udp_wmem_min",
712 .data = &sysctl_udp_wmem_min,
713 .maxlen = sizeof(sysctl_udp_wmem_min),
714 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800715 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700716 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800717 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800718 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800720
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700721static struct ctl_table ipv4_net_table[] = {
722 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700723 .procname = "icmp_echo_ignore_all",
724 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
725 .maxlen = sizeof(int),
726 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800727 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700728 },
729 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700730 .procname = "icmp_echo_ignore_broadcasts",
731 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
732 .maxlen = sizeof(int),
733 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800734 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700735 },
736 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700737 .procname = "icmp_ignore_bogus_error_responses",
738 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
739 .maxlen = sizeof(int),
740 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800741 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700742 },
743 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700744 .procname = "icmp_errors_use_inbound_ifaddr",
745 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
746 .maxlen = sizeof(int),
747 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800748 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700749 },
750 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700751 .procname = "icmp_ratelimit",
752 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
753 .maxlen = sizeof(int),
754 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800755 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700756 },
757 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700758 .procname = "icmp_ratemask",
759 .data = &init_net.ipv4.sysctl_icmp_ratemask,
760 .maxlen = sizeof(int),
761 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800762 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700763 },
Neil Horman1080d702008-10-27 12:28:25 -0700764 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000765 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700766 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600767 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000768 .mode = 0644,
769 .proc_handler = ipv4_ping_group_range,
770 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000771 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000772 .procname = "tcp_ecn",
773 .data = &init_net.ipv4.sysctl_tcp_ecn,
774 .maxlen = sizeof(int),
775 .mode = 0644,
776 .proc_handler = proc_dointvec
777 },
778 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200779 .procname = "tcp_ecn_fallback",
780 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = proc_dointvec
784 },
785 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200786 .procname = "ip_dynaddr",
787 .data = &init_net.ipv4.sysctl_ip_dynaddr,
788 .maxlen = sizeof(int),
789 .mode = 0644,
790 .proc_handler = proc_dointvec
791 },
792 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200793 .procname = "ip_early_demux",
794 .data = &init_net.ipv4.sysctl_ip_early_demux,
795 .maxlen = sizeof(int),
796 .mode = 0644,
797 .proc_handler = proc_dointvec
798 },
799 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600800 .procname = "udp_early_demux",
801 .data = &init_net.ipv4.sysctl_udp_early_demux,
802 .maxlen = sizeof(int),
803 .mode = 0644,
804 .proc_handler = proc_udp_early_demux
805 },
806 {
807 .procname = "tcp_early_demux",
808 .data = &init_net.ipv4.sysctl_tcp_early_demux,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = proc_tcp_early_demux
812 },
813 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200814 .procname = "ip_default_ttl",
815 .data = &init_net.ipv4.sysctl_ip_default_ttl,
816 .maxlen = sizeof(int),
817 .mode = 0644,
818 .proc_handler = proc_dointvec_minmax,
819 .extra1 = &ip_ttl_min,
820 .extra2 = &ip_ttl_max,
821 },
822 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700823 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700824 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
825 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700826 .mode = 0644,
827 .proc_handler = ipv4_local_port_range,
828 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100829 {
WANG Cong122ff242014-05-12 16:04:53 -0700830 .procname = "ip_local_reserved_ports",
831 .data = &init_net.ipv4.sysctl_local_reserved_ports,
832 .maxlen = 65536,
833 .mode = 0644,
834 .proc_handler = proc_do_large_bitmap,
835 },
836 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100837 .procname = "ip_no_pmtu_disc",
838 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
839 .maxlen = sizeof(int),
840 .mode = 0644,
841 .proc_handler = proc_dointvec
842 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100843 {
844 .procname = "ip_forward_use_pmtu",
845 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
846 .maxlen = sizeof(int),
847 .mode = 0644,
848 .proc_handler = proc_dointvec,
849 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700850 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200851 .procname = "ip_nonlocal_bind",
852 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
853 .maxlen = sizeof(int),
854 .mode = 0644,
855 .proc_handler = proc_dointvec
856 },
857 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700858 .procname = "fwmark_reflect",
859 .data = &init_net.ipv4.sysctl_fwmark_reflect,
860 .maxlen = sizeof(int),
861 .mode = 0644,
862 .proc_handler = proc_dointvec,
863 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700864 {
865 .procname = "tcp_fwmark_accept",
866 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
867 .maxlen = sizeof(int),
868 .mode = 0644,
869 .proc_handler = proc_dointvec,
870 },
David Ahern6dd9a142015-12-16 13:20:44 -0800871#ifdef CONFIG_NET_L3_MASTER_DEV
872 {
873 .procname = "tcp_l3mdev_accept",
874 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = proc_dointvec_minmax,
878 .extra1 = &zero,
879 .extra2 = &one,
880 },
881#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800882 {
883 .procname = "tcp_mtu_probing",
884 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
885 .maxlen = sizeof(int),
886 .mode = 0644,
887 .proc_handler = proc_dointvec,
888 },
889 {
890 .procname = "tcp_base_mss",
891 .data = &init_net.ipv4.sysctl_tcp_base_mss,
892 .maxlen = sizeof(int),
893 .mode = 0644,
894 .proc_handler = proc_dointvec,
895 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800896 {
897 .procname = "tcp_probe_threshold",
898 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
899 .maxlen = sizeof(int),
900 .mode = 0644,
901 .proc_handler = proc_dointvec,
902 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800903 {
904 .procname = "tcp_probe_interval",
905 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
906 .maxlen = sizeof(int),
907 .mode = 0644,
908 .proc_handler = proc_dointvec,
909 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100910 {
911 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200912 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100913 .maxlen = sizeof(int),
914 .mode = 0644,
915 .proc_handler = proc_dointvec
916 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200917 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200918 .procname = "igmp_max_memberships",
919 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
920 .maxlen = sizeof(int),
921 .mode = 0644,
922 .proc_handler = proc_dointvec
923 },
924 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200925 .procname = "igmp_max_msf",
926 .data = &init_net.ipv4.sysctl_igmp_max_msf,
927 .maxlen = sizeof(int),
928 .mode = 0644,
929 .proc_handler = proc_dointvec
930 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200931#ifdef CONFIG_IP_MULTICAST
932 {
933 .procname = "igmp_qrv",
934 .data = &init_net.ipv4.sysctl_igmp_qrv,
935 .maxlen = sizeof(int),
936 .mode = 0644,
937 .proc_handler = proc_dointvec_minmax,
938 .extra1 = &one
939 },
940#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200941 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200942 .procname = "tcp_keepalive_time",
943 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
944 .maxlen = sizeof(int),
945 .mode = 0644,
946 .proc_handler = proc_dointvec_jiffies,
947 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200948 {
949 .procname = "tcp_keepalive_probes",
950 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
951 .maxlen = sizeof(int),
952 .mode = 0644,
953 .proc_handler = proc_dointvec
954 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200955 {
956 .procname = "tcp_keepalive_intvl",
957 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
958 .maxlen = sizeof(int),
959 .mode = 0644,
960 .proc_handler = proc_dointvec_jiffies,
961 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200962 {
963 .procname = "tcp_syn_retries",
964 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = proc_dointvec_minmax,
968 .extra1 = &tcp_syn_retries_min,
969 .extra2 = &tcp_syn_retries_max
970 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200971 {
972 .procname = "tcp_synack_retries",
973 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = proc_dointvec
977 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200978#ifdef CONFIG_SYN_COOKIES
979 {
980 .procname = "tcp_syncookies",
981 .data = &init_net.ipv4.sysctl_tcp_syncookies,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = proc_dointvec
985 },
986#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200987 {
988 .procname = "tcp_reordering",
989 .data = &init_net.ipv4.sysctl_tcp_reordering,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = proc_dointvec
993 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200994 {
995 .procname = "tcp_retries1",
996 .data = &init_net.ipv4.sysctl_tcp_retries1,
997 .maxlen = sizeof(int),
998 .mode = 0644,
999 .proc_handler = proc_dointvec_minmax,
1000 .extra2 = &tcp_retr1_max
1001 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +02001002 {
1003 .procname = "tcp_retries2",
1004 .data = &init_net.ipv4.sysctl_tcp_retries2,
1005 .maxlen = sizeof(int),
1006 .mode = 0644,
1007 .proc_handler = proc_dointvec
1008 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +02001009 {
1010 .procname = "tcp_orphan_retries",
1011 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
1012 .maxlen = sizeof(int),
1013 .mode = 0644,
1014 .proc_handler = proc_dointvec
1015 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +02001016 {
1017 .procname = "tcp_fin_timeout",
1018 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
1019 .maxlen = sizeof(int),
1020 .mode = 0644,
1021 .proc_handler = proc_dointvec_jiffies,
1022 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +02001023 {
1024 .procname = "tcp_notsent_lowat",
1025 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
1026 .maxlen = sizeof(unsigned int),
1027 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +03001028 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +02001029 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +08001030 {
1031 .procname = "tcp_tw_reuse",
1032 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
1035 .proc_handler = proc_dointvec
1036 },
Haishuang Yan1946e672016-12-28 17:52:32 +08001037 {
1038 .procname = "tcp_max_tw_buckets",
1039 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
1040 .maxlen = sizeof(int),
1041 .mode = 0644,
1042 .proc_handler = proc_dointvec
1043 },
1044 {
Haishuang Yanfee83d02016-12-28 17:52:33 +08001045 .procname = "tcp_max_syn_backlog",
1046 .data = &init_net.ipv4.sysctl_max_syn_backlog,
1047 .maxlen = sizeof(int),
1048 .mode = 0644,
1049 .proc_handler = proc_dointvec
1050 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +08001051 {
1052 .procname = "tcp_fastopen",
1053 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1054 .maxlen = sizeof(int),
1055 .mode = 0644,
1056 .proc_handler = proc_dointvec,
1057 },
Haishuang Yan43713842017-09-27 11:35:42 +08001058 {
1059 .procname = "tcp_fastopen_key",
1060 .mode = 0600,
1061 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1062 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
1063 .proc_handler = proc_tcp_fastopen_key,
1064 },
Haishuang Yan3733be12017-09-27 11:35:43 +08001065 {
1066 .procname = "tcp_fastopen_blackhole_timeout_sec",
1067 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
1070 .proc_handler = proc_tfo_blackhole_detect_timeout,
1071 .extra1 = &zero,
1072 },
David Aherna6db4492016-04-07 07:21:00 -07001073#ifdef CONFIG_IP_ROUTE_MULTIPATH
1074 {
1075 .procname = "fib_multipath_use_neigh",
1076 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1077 .maxlen = sizeof(int),
1078 .mode = 0644,
1079 .proc_handler = proc_dointvec_minmax,
1080 .extra1 = &zero,
1081 .extra2 = &one,
1082 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +02001083 {
1084 .procname = "fib_multipath_hash_policy",
1085 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1086 .maxlen = sizeof(int),
1087 .mode = 0644,
1088 .proc_handler = proc_dointvec_minmax,
1089 .extra1 = &zero,
1090 .extra2 = &one,
1091 },
David Aherna6db4492016-04-07 07:21:00 -07001092#endif
Krister Johansen4548b682017-01-20 17:49:11 -08001093 {
1094 .procname = "ip_unprivileged_port_start",
1095 .maxlen = sizeof(int),
1096 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1097 .mode = 0644,
1098 .proc_handler = ipv4_privileged_ports,
1099 },
Robert Shearman63a6fff2017-01-26 18:02:24 +00001100#ifdef CONFIG_NET_L3_MASTER_DEV
1101 {
1102 .procname = "udp_l3mdev_accept",
1103 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = proc_dointvec_minmax,
1107 .extra1 = &zero,
1108 .extra2 = &one,
1109 },
1110#endif
Eric Dumazetf9301032017-06-07 10:34:37 -07001111 {
1112 .procname = "tcp_sack",
1113 .data = &init_net.ipv4.sysctl_tcp_sack,
1114 .maxlen = sizeof(int),
1115 .mode = 0644,
1116 .proc_handler = proc_dointvec
1117 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -07001118 {
1119 .procname = "tcp_window_scaling",
1120 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1121 .maxlen = sizeof(int),
1122 .mode = 0644,
1123 .proc_handler = proc_dointvec
1124 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -07001125 {
1126 .procname = "tcp_timestamps",
1127 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1128 .maxlen = sizeof(int),
1129 .mode = 0644,
1130 .proc_handler = proc_dointvec
1131 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -07001132 {
1133 .procname = "tcp_early_retrans",
1134 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = proc_dointvec_minmax,
1138 .extra1 = &zero,
1139 .extra2 = &four,
1140 },
Eric Dumazete20223f2017-10-26 21:54:57 -07001141 {
1142 .procname = "tcp_recovery",
1143 .data = &init_net.ipv4.sysctl_tcp_recovery,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = proc_dointvec,
1147 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001148 { }
1149};
1150
Pavel Emelyanov15775192008-03-26 01:54:18 -07001151static __net_init int ipv4_sysctl_init_net(struct net *net)
1152{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001153 struct ctl_table *table;
1154
1155 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001156 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001157 int i;
1158
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001159 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001160 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001161 goto err_alloc;
1162
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001163 /* Update the variables to point into the current struct net */
1164 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1165 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001166 }
1167
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001168 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001169 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001170 goto err_reg;
1171
WANG Cong122ff242014-05-12 16:04:53 -07001172 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1173 if (!net->ipv4.sysctl_local_reserved_ports)
1174 goto err_ports;
1175
Pavel Emelyanov15775192008-03-26 01:54:18 -07001176 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001177
WANG Cong122ff242014-05-12 16:04:53 -07001178err_ports:
1179 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001180err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001181 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001182 kfree(table);
1183err_alloc:
1184 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001185}
1186
1187static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1188{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001189 struct ctl_table *table;
1190
WANG Cong122ff242014-05-12 16:04:53 -07001191 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001192 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1193 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1194 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001195}
1196
1197static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1198 .init = ipv4_sysctl_init_net,
1199 .exit = ipv4_sysctl_exit_net,
1200};
1201
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001202static __init int sysctl_ipv4_init(void)
1203{
1204 struct ctl_table_header *hdr;
1205
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001206 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001207 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001208 return -ENOMEM;
1209
1210 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001211 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001212 return -ENOMEM;
1213 }
1214
1215 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001216}
1217
1218__initcall(sysctl_ipv4_init);