blob: ef0ff3357a44757d59f658614f3858687ef2ef47 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
7 */
8
9#include <linux/mm.h>
10#include <linux/module.h>
11#include <linux/sysctl.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030012#include <linux/igmp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020013#include <linux/inetdevice.h>
Stephen Hemminger227b60f2007-10-10 17:30:46 -070014#include <linux/seqlock.h>
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -080015#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000017#include <linux/nsproxy.h>
Glauber Costa3dc43e32011-12-11 21:47:05 +000018#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030020#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <net/ip.h>
22#include <net/route.h>
23#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080024#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070025#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070026#include <net/inet_frag.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000027#include <net/ping.h>
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060028#include <net/protocol.h>
Ido Schimmel3ae6ec02017-11-02 17:14:05 +010029#include <net/netevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Herbert Xu89cee8b2005-12-13 23:14:27 -080031static int zero;
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +000032static int one = 1;
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +000033static int four = 4;
Eric Dumazet43e122b2015-08-21 17:38:02 -070034static int thousand = 1000;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070035static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090036static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static int ip_local_port_range_min[] = { 1, 1 };
38static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000039static int tcp_adv_win_scale_min = -31;
40static int tcp_adv_win_scale_max = 31;
Krister Johansen4548b682017-01-20 17:49:11 -080041static int ip_privileged_port_min;
42static int ip_privileged_port_max = 65535;
Eric Dumazet249fab72010-12-13 12:16:14 -080043static int ip_ttl_min = 1;
44static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020045static int tcp_syn_retries_min = 1;
46static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000047static int ip_ping_group_range_min[] = { 0, 0 };
48static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Florian Westphalb6690b12017-07-30 03:57:20 +020050/* obsolete */
51static int sysctl_tcp_low_latency __read_mostly;
52
Stephen Hemminger227b60f2007-10-10 17:30:46 -070053/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070054static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070055{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070056 bool same_parity = !((range[0] ^ range[1]) & 1);
57
WANG Cong4ee3bd42015-11-03 14:32:57 -080058 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070059 if (same_parity && !net->ipv4.ip_local_ports.warned) {
60 net->ipv4.ip_local_ports.warned = true;
61 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
62 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070063 net->ipv4.ip_local_ports.range[0] = range[0];
64 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080065 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070066}
67
68/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070069static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070070 void __user *buffer,
71 size_t *lenp, loff_t *ppos)
72{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070073 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070074 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070075 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070076 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070077 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070078 .data = &range,
79 .maxlen = sizeof(range),
80 .mode = table->mode,
81 .extra1 = &ip_local_port_range_min,
82 .extra2 = &ip_local_port_range_max,
83 };
84
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070085 inet_get_local_port_range(net, &range[0], &range[1]);
86
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070087 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070088
89 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080090 /* Ensure that the upper limit is not smaller than the lower,
91 * and that the lower does not encroach upon the privileged
92 * port limit.
93 */
94 if ((range[1] < range[0]) ||
95 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -070096 ret = -EINVAL;
97 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070098 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070099 }
100
101 return ret;
102}
103
Krister Johansen4548b682017-01-20 17:49:11 -0800104/* Validate changes from /proc interface. */
105static int ipv4_privileged_ports(struct ctl_table *table, int write,
106 void __user *buffer, size_t *lenp, loff_t *ppos)
107{
108 struct net *net = container_of(table->data, struct net,
109 ipv4.sysctl_ip_prot_sock);
110 int ret;
111 int pports;
112 int range[2];
113 struct ctl_table tmp = {
114 .data = &pports,
115 .maxlen = sizeof(pports),
116 .mode = table->mode,
117 .extra1 = &ip_privileged_port_min,
118 .extra2 = &ip_privileged_port_max,
119 };
120
121 pports = net->ipv4.sysctl_ip_prot_sock;
122
123 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
124
125 if (write && ret == 0) {
126 inet_get_local_port_range(net, &range[0], &range[1]);
127 /* Ensure that the local port range doesn't overlap with the
128 * privileged port range.
129 */
130 if (range[0] < pports)
131 ret = -EINVAL;
132 else
133 net->ipv4.sysctl_ip_prot_sock = pports;
134 }
135
136 return ret;
137}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000138
Eric W. Biederman7064d162012-05-24 10:34:21 -0600139static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000140{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600141 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700142 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700143 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000144 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000145 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700146 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000147
148 *low = data[0];
149 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700150 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000151}
152
153/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600154static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000155{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600156 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700157 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700158 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700159 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600160 data[0] = low;
161 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700162 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000163}
164
165/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700166static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000167 void __user *buffer,
168 size_t *lenp, loff_t *ppos)
169{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600170 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000171 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600172 gid_t urange[2];
173 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700174 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600175 .data = &urange,
176 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000177 .mode = table->mode,
178 .extra1 = &ip_ping_group_range_min,
179 .extra2 = &ip_ping_group_range_max,
180 };
181
Eric W. Biederman7064d162012-05-24 10:34:21 -0600182 inet_get_ping_group_range_table(table, &low, &high);
183 urange[0] = from_kgid_munged(user_ns, low);
184 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000185 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
186
Eric W. Biederman7064d162012-05-24 10:34:21 -0600187 if (write && ret == 0) {
188 low = make_kgid(user_ns, urange[0]);
189 high = make_kgid(user_ns, urange[1]);
190 if (!gid_valid(low) || !gid_valid(high) ||
191 (urange[1] < urange[0]) || gid_lt(high, low)) {
192 low = make_kgid(&init_user_ns, 1);
193 high = make_kgid(&init_user_ns, 0);
194 }
195 set_ping_group_range(table, low, high);
196 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000197
198 return ret;
199}
200
Joe Perchesfe2c6332013-06-11 23:04:25 -0700201static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700202 void __user *buffer, size_t *lenp, loff_t *ppos)
203{
204 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700205 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700206 .data = val,
207 .maxlen = TCP_CA_NAME_MAX,
208 };
209 int ret;
210
211 tcp_get_default_congestion_control(val);
212
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700213 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700214 if (write && ret == 0)
215 ret = tcp_set_default_congestion_control(val);
216 return ret;
217}
218
Joe Perchesfe2c6332013-06-11 23:04:25 -0700219static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700220 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800221 void __user *buffer, size_t *lenp,
222 loff_t *ppos)
223{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700224 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800225 int ret;
226
227 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
228 if (!tbl.data)
229 return -ENOMEM;
230 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700231 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800232 kfree(tbl.data);
233 return ret;
234}
235
Joe Perchesfe2c6332013-06-11 23:04:25 -0700236static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700237 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800238 void __user *buffer, size_t *lenp,
239 loff_t *ppos)
240{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700241 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800242 int ret;
243
244 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
245 if (!tbl.data)
246 return -ENOMEM;
247
248 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700249 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800250 if (write && ret == 0)
251 ret = tcp_set_allowed_congestion_control(tbl.data);
252 kfree(tbl.data);
253 return ret;
254}
255
Haishuang Yan43713842017-09-27 11:35:42 +0800256static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700257 void __user *buffer, size_t *lenp,
258 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000259{
Haishuang Yan43713842017-09-27 11:35:42 +0800260 struct net *net = container_of(table->data, struct net,
261 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700262 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000263 struct tcp_fastopen_context *ctxt;
264 int ret;
265 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
266
267 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
268 if (!tbl.data)
269 return -ENOMEM;
270
271 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800272 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000273 if (ctxt)
274 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000275 else
276 memset(user_key, 0, sizeof(user_key));
Jerry Chu10467162012-08-31 12:29:11 +0000277 rcu_read_unlock();
278
279 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
280 user_key[0], user_key[1], user_key[2], user_key[3]);
281 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
282
283 if (write && ret == 0) {
284 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
285 user_key + 2, user_key + 3) != 4) {
286 ret = -EINVAL;
287 goto bad_key;
288 }
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700289 tcp_fastopen_reset_cipher(net, NULL, user_key,
290 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000291 }
292
293bad_key:
294 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
295 user_key[0], user_key[1], user_key[2], user_key[3],
296 (char *)tbl.data, ret);
297 kfree(tbl.data);
298 return ret;
299}
300
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600301static void proc_configure_early_demux(int enabled, int protocol)
302{
303 struct net_protocol *ipprot;
304#if IS_ENABLED(CONFIG_IPV6)
305 struct inet6_protocol *ip6prot;
306#endif
307
David Ahern58c4c6a2017-04-22 09:33:16 -0700308 rcu_read_lock();
309
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600310 ipprot = rcu_dereference(inet_protos[protocol]);
311 if (ipprot)
312 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
313 NULL;
314
315#if IS_ENABLED(CONFIG_IPV6)
316 ip6prot = rcu_dereference(inet6_protos[protocol]);
317 if (ip6prot)
318 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
319 NULL;
320#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700321 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600322}
323
324static int proc_tcp_early_demux(struct ctl_table *table, int write,
325 void __user *buffer, size_t *lenp, loff_t *ppos)
326{
327 int ret = 0;
328
329 ret = proc_dointvec(table, write, buffer, lenp, ppos);
330
331 if (write && !ret) {
332 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
333
334 proc_configure_early_demux(enabled, IPPROTO_TCP);
335 }
336
337 return ret;
338}
339
340static int proc_udp_early_demux(struct ctl_table *table, int write,
341 void __user *buffer, size_t *lenp, loff_t *ppos)
342{
343 int ret = 0;
344
345 ret = proc_dointvec(table, write, buffer, lenp, ppos);
346
347 if (write && !ret) {
348 int enabled = init_net.ipv4.sysctl_udp_early_demux;
349
350 proc_configure_early_demux(enabled, IPPROTO_UDP);
351 }
352
353 return ret;
354}
355
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700356static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
357 int write,
358 void __user *buffer,
359 size_t *lenp, loff_t *ppos)
360{
Haishuang Yan3733be12017-09-27 11:35:43 +0800361 struct net *net = container_of(table->data, struct net,
362 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700363 int ret;
364
365 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
366 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800367 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700368
369 return ret;
370}
371
372static int proc_tcp_available_ulp(struct ctl_table *ctl,
373 int write,
374 void __user *buffer, size_t *lenp,
375 loff_t *ppos)
376{
377 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
378 int ret;
379
380 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
381 if (!tbl.data)
382 return -ENOMEM;
383 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
384 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
385 kfree(tbl.data);
386
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700387 return ret;
388}
389
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100390#ifdef CONFIG_IP_ROUTE_MULTIPATH
391static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
392 void __user *buffer, size_t *lenp,
393 loff_t *ppos)
394{
395 struct net *net = container_of(table->data, struct net,
396 ipv4.sysctl_fib_multipath_hash_policy);
397 int ret;
398
399 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
400 if (write && ret == 0)
401 call_netevent_notifiers(NETEVENT_MULTIPATH_HASH_UPDATE, net);
402
403 return ret;
404}
405#endif
406
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800407static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .procname = "tcp_max_orphans",
410 .data = &sysctl_tcp_max_orphans,
411 .maxlen = sizeof(int),
412 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800413 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 },
415 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 .procname = "inet_peer_threshold",
417 .data = &inet_peer_threshold,
418 .maxlen = sizeof(int),
419 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800420 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 },
422 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 .procname = "inet_peer_minttl",
424 .data = &inet_peer_minttl,
425 .maxlen = sizeof(int),
426 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800427 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 },
429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 .procname = "inet_peer_maxttl",
431 .data = &inet_peer_maxttl,
432 .maxlen = sizeof(int),
433 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800434 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 },
436 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700437 .procname = "tcp_mem",
438 .maxlen = sizeof(sysctl_tcp_mem),
439 .data = &sysctl_tcp_mem,
440 .mode = 0644,
441 .proc_handler = proc_doulongvec_minmax,
442 },
443 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 .procname = "tcp_low_latency",
445 .data = &sysctl_tcp_low_latency,
446 .maxlen = sizeof(int),
447 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800448 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 },
450 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700451 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700453 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800454 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 },
Paul Moore446fda42006-08-03 16:48:06 -0700456#ifdef CONFIG_NETLABEL
457 {
Paul Moore446fda42006-08-03 16:48:06 -0700458 .procname = "cipso_cache_enable",
459 .data = &cipso_v4_cache_enabled,
460 .maxlen = sizeof(int),
461 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800462 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700463 },
464 {
Paul Moore446fda42006-08-03 16:48:06 -0700465 .procname = "cipso_cache_bucket_size",
466 .data = &cipso_v4_cache_bucketsize,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800469 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700470 },
471 {
Paul Moore446fda42006-08-03 16:48:06 -0700472 .procname = "cipso_rbm_optfmt",
473 .data = &cipso_v4_rbm_optfmt,
474 .maxlen = sizeof(int),
475 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800476 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700477 },
478 {
Paul Moore446fda42006-08-03 16:48:06 -0700479 .procname = "cipso_rbm_strictvalid",
480 .data = &cipso_v4_rbm_strictvalid,
481 .maxlen = sizeof(int),
482 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800483 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700484 },
485#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800486 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800487 .procname = "tcp_available_congestion_control",
488 .maxlen = TCP_CA_BUF_MAX,
489 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800490 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800491 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800492 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800493 .procname = "tcp_allowed_congestion_control",
494 .maxlen = TCP_CA_BUF_MAX,
495 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800496 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800497 },
John Heffner886236c2007-03-25 19:21:45 -0700498 {
Dave Watson734942c2017-06-14 11:37:14 -0700499 .procname = "tcp_available_ulp",
500 .maxlen = TCP_ULP_BUF_MAX,
501 .mode = 0444,
502 .proc_handler = proc_tcp_available_ulp,
503 },
504 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700505 .procname = "icmp_msgs_per_sec",
506 .data = &sysctl_icmp_msgs_per_sec,
507 .maxlen = sizeof(int),
508 .mode = 0644,
509 .proc_handler = proc_dointvec_minmax,
510 .extra1 = &zero,
511 },
512 {
513 .procname = "icmp_msgs_burst",
514 .data = &sysctl_icmp_msgs_burst,
515 .maxlen = sizeof(int),
516 .mode = 0644,
517 .proc_handler = proc_dointvec_minmax,
518 .extra1 = &zero,
519 },
520 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800521 .procname = "udp_mem",
522 .data = &sysctl_udp_mem,
523 .maxlen = sizeof(sysctl_udp_mem),
524 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000525 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800526 },
527 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800528 .procname = "udp_rmem_min",
529 .data = &sysctl_udp_rmem_min,
530 .maxlen = sizeof(sysctl_udp_rmem_min),
531 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800532 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700533 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800534 },
535 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800536 .procname = "udp_wmem_min",
537 .data = &sysctl_udp_wmem_min,
538 .maxlen = sizeof(sysctl_udp_wmem_min),
539 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800540 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700541 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800542 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800543 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800545
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700546static struct ctl_table ipv4_net_table[] = {
547 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700548 .procname = "icmp_echo_ignore_all",
549 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
550 .maxlen = sizeof(int),
551 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800552 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700553 },
554 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700555 .procname = "icmp_echo_ignore_broadcasts",
556 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
557 .maxlen = sizeof(int),
558 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800559 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700560 },
561 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700562 .procname = "icmp_ignore_bogus_error_responses",
563 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
564 .maxlen = sizeof(int),
565 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800566 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700567 },
568 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700569 .procname = "icmp_errors_use_inbound_ifaddr",
570 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
571 .maxlen = sizeof(int),
572 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800573 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700574 },
575 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700576 .procname = "icmp_ratelimit",
577 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
578 .maxlen = sizeof(int),
579 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800580 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700581 },
582 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700583 .procname = "icmp_ratemask",
584 .data = &init_net.ipv4.sysctl_icmp_ratemask,
585 .maxlen = sizeof(int),
586 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800587 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700588 },
Neil Horman1080d702008-10-27 12:28:25 -0700589 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000590 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700591 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600592 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000593 .mode = 0644,
594 .proc_handler = ipv4_ping_group_range,
595 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000596 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000597 .procname = "tcp_ecn",
598 .data = &init_net.ipv4.sysctl_tcp_ecn,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = proc_dointvec
602 },
603 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200604 .procname = "tcp_ecn_fallback",
605 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = proc_dointvec
609 },
610 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200611 .procname = "ip_dynaddr",
612 .data = &init_net.ipv4.sysctl_ip_dynaddr,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = proc_dointvec
616 },
617 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200618 .procname = "ip_early_demux",
619 .data = &init_net.ipv4.sysctl_ip_early_demux,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 .proc_handler = proc_dointvec
623 },
624 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600625 .procname = "udp_early_demux",
626 .data = &init_net.ipv4.sysctl_udp_early_demux,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = proc_udp_early_demux
630 },
631 {
632 .procname = "tcp_early_demux",
633 .data = &init_net.ipv4.sysctl_tcp_early_demux,
634 .maxlen = sizeof(int),
635 .mode = 0644,
636 .proc_handler = proc_tcp_early_demux
637 },
638 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200639 .procname = "ip_default_ttl",
640 .data = &init_net.ipv4.sysctl_ip_default_ttl,
641 .maxlen = sizeof(int),
642 .mode = 0644,
643 .proc_handler = proc_dointvec_minmax,
644 .extra1 = &ip_ttl_min,
645 .extra2 = &ip_ttl_max,
646 },
647 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700648 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700649 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
650 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700651 .mode = 0644,
652 .proc_handler = ipv4_local_port_range,
653 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100654 {
WANG Cong122ff242014-05-12 16:04:53 -0700655 .procname = "ip_local_reserved_ports",
656 .data = &init_net.ipv4.sysctl_local_reserved_ports,
657 .maxlen = 65536,
658 .mode = 0644,
659 .proc_handler = proc_do_large_bitmap,
660 },
661 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100662 .procname = "ip_no_pmtu_disc",
663 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = proc_dointvec
667 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100668 {
669 .procname = "ip_forward_use_pmtu",
670 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = proc_dointvec,
674 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700675 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200676 .procname = "ip_nonlocal_bind",
677 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
678 .maxlen = sizeof(int),
679 .mode = 0644,
680 .proc_handler = proc_dointvec
681 },
682 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700683 .procname = "fwmark_reflect",
684 .data = &init_net.ipv4.sysctl_fwmark_reflect,
685 .maxlen = sizeof(int),
686 .mode = 0644,
687 .proc_handler = proc_dointvec,
688 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700689 {
690 .procname = "tcp_fwmark_accept",
691 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 .proc_handler = proc_dointvec,
695 },
David Ahern6dd9a142015-12-16 13:20:44 -0800696#ifdef CONFIG_NET_L3_MASTER_DEV
697 {
698 .procname = "tcp_l3mdev_accept",
699 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = proc_dointvec_minmax,
703 .extra1 = &zero,
704 .extra2 = &one,
705 },
706#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800707 {
708 .procname = "tcp_mtu_probing",
709 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = proc_dointvec,
713 },
714 {
715 .procname = "tcp_base_mss",
716 .data = &init_net.ipv4.sysctl_tcp_base_mss,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = proc_dointvec,
720 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800721 {
722 .procname = "tcp_probe_threshold",
723 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
724 .maxlen = sizeof(int),
725 .mode = 0644,
726 .proc_handler = proc_dointvec,
727 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800728 {
729 .procname = "tcp_probe_interval",
730 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = proc_dointvec,
734 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100735 {
736 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200737 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100738 .maxlen = sizeof(int),
739 .mode = 0644,
740 .proc_handler = proc_dointvec
741 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200742 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200743 .procname = "igmp_max_memberships",
744 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = proc_dointvec
748 },
749 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200750 .procname = "igmp_max_msf",
751 .data = &init_net.ipv4.sysctl_igmp_max_msf,
752 .maxlen = sizeof(int),
753 .mode = 0644,
754 .proc_handler = proc_dointvec
755 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200756#ifdef CONFIG_IP_MULTICAST
757 {
758 .procname = "igmp_qrv",
759 .data = &init_net.ipv4.sysctl_igmp_qrv,
760 .maxlen = sizeof(int),
761 .mode = 0644,
762 .proc_handler = proc_dointvec_minmax,
763 .extra1 = &one
764 },
765#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200766 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200767 .procname = "tcp_keepalive_time",
768 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
769 .maxlen = sizeof(int),
770 .mode = 0644,
771 .proc_handler = proc_dointvec_jiffies,
772 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200773 {
774 .procname = "tcp_keepalive_probes",
775 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
776 .maxlen = sizeof(int),
777 .mode = 0644,
778 .proc_handler = proc_dointvec
779 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200780 {
781 .procname = "tcp_keepalive_intvl",
782 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
783 .maxlen = sizeof(int),
784 .mode = 0644,
785 .proc_handler = proc_dointvec_jiffies,
786 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200787 {
788 .procname = "tcp_syn_retries",
789 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
790 .maxlen = sizeof(int),
791 .mode = 0644,
792 .proc_handler = proc_dointvec_minmax,
793 .extra1 = &tcp_syn_retries_min,
794 .extra2 = &tcp_syn_retries_max
795 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200796 {
797 .procname = "tcp_synack_retries",
798 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = proc_dointvec
802 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200803#ifdef CONFIG_SYN_COOKIES
804 {
805 .procname = "tcp_syncookies",
806 .data = &init_net.ipv4.sysctl_tcp_syncookies,
807 .maxlen = sizeof(int),
808 .mode = 0644,
809 .proc_handler = proc_dointvec
810 },
811#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200812 {
813 .procname = "tcp_reordering",
814 .data = &init_net.ipv4.sysctl_tcp_reordering,
815 .maxlen = sizeof(int),
816 .mode = 0644,
817 .proc_handler = proc_dointvec
818 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200819 {
820 .procname = "tcp_retries1",
821 .data = &init_net.ipv4.sysctl_tcp_retries1,
822 .maxlen = sizeof(int),
823 .mode = 0644,
824 .proc_handler = proc_dointvec_minmax,
825 .extra2 = &tcp_retr1_max
826 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +0200827 {
828 .procname = "tcp_retries2",
829 .data = &init_net.ipv4.sysctl_tcp_retries2,
830 .maxlen = sizeof(int),
831 .mode = 0644,
832 .proc_handler = proc_dointvec
833 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +0200834 {
835 .procname = "tcp_orphan_retries",
836 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
837 .maxlen = sizeof(int),
838 .mode = 0644,
839 .proc_handler = proc_dointvec
840 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +0200841 {
842 .procname = "tcp_fin_timeout",
843 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = proc_dointvec_jiffies,
847 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200848 {
849 .procname = "tcp_notsent_lowat",
850 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
851 .maxlen = sizeof(unsigned int),
852 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +0300853 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200854 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800855 {
856 .procname = "tcp_tw_reuse",
857 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
858 .maxlen = sizeof(int),
859 .mode = 0644,
860 .proc_handler = proc_dointvec
861 },
Haishuang Yan1946e672016-12-28 17:52:32 +0800862 {
863 .procname = "tcp_max_tw_buckets",
864 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
865 .maxlen = sizeof(int),
866 .mode = 0644,
867 .proc_handler = proc_dointvec
868 },
869 {
Haishuang Yanfee83d02016-12-28 17:52:33 +0800870 .procname = "tcp_max_syn_backlog",
871 .data = &init_net.ipv4.sysctl_max_syn_backlog,
872 .maxlen = sizeof(int),
873 .mode = 0644,
874 .proc_handler = proc_dointvec
875 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +0800876 {
877 .procname = "tcp_fastopen",
878 .data = &init_net.ipv4.sysctl_tcp_fastopen,
879 .maxlen = sizeof(int),
880 .mode = 0644,
881 .proc_handler = proc_dointvec,
882 },
Haishuang Yan43713842017-09-27 11:35:42 +0800883 {
884 .procname = "tcp_fastopen_key",
885 .mode = 0600,
886 .data = &init_net.ipv4.sysctl_tcp_fastopen,
887 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
888 .proc_handler = proc_tcp_fastopen_key,
889 },
Haishuang Yan3733be12017-09-27 11:35:43 +0800890 {
891 .procname = "tcp_fastopen_blackhole_timeout_sec",
892 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
893 .maxlen = sizeof(int),
894 .mode = 0644,
895 .proc_handler = proc_tfo_blackhole_detect_timeout,
896 .extra1 = &zero,
897 },
David Aherna6db4492016-04-07 07:21:00 -0700898#ifdef CONFIG_IP_ROUTE_MULTIPATH
899 {
900 .procname = "fib_multipath_use_neigh",
901 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = proc_dointvec_minmax,
905 .extra1 = &zero,
906 .extra2 = &one,
907 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200908 {
909 .procname = "fib_multipath_hash_policy",
910 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
911 .maxlen = sizeof(int),
912 .mode = 0644,
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100913 .proc_handler = proc_fib_multipath_hash_policy,
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200914 .extra1 = &zero,
915 .extra2 = &one,
916 },
David Aherna6db4492016-04-07 07:21:00 -0700917#endif
Krister Johansen4548b682017-01-20 17:49:11 -0800918 {
919 .procname = "ip_unprivileged_port_start",
920 .maxlen = sizeof(int),
921 .data = &init_net.ipv4.sysctl_ip_prot_sock,
922 .mode = 0644,
923 .proc_handler = ipv4_privileged_ports,
924 },
Robert Shearman63a6fff2017-01-26 18:02:24 +0000925#ifdef CONFIG_NET_L3_MASTER_DEV
926 {
927 .procname = "udp_l3mdev_accept",
928 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
929 .maxlen = sizeof(int),
930 .mode = 0644,
931 .proc_handler = proc_dointvec_minmax,
932 .extra1 = &zero,
933 .extra2 = &one,
934 },
935#endif
Eric Dumazetf9301032017-06-07 10:34:37 -0700936 {
937 .procname = "tcp_sack",
938 .data = &init_net.ipv4.sysctl_tcp_sack,
939 .maxlen = sizeof(int),
940 .mode = 0644,
941 .proc_handler = proc_dointvec
942 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -0700943 {
944 .procname = "tcp_window_scaling",
945 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
946 .maxlen = sizeof(int),
947 .mode = 0644,
948 .proc_handler = proc_dointvec
949 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -0700950 {
951 .procname = "tcp_timestamps",
952 .data = &init_net.ipv4.sysctl_tcp_timestamps,
953 .maxlen = sizeof(int),
954 .mode = 0644,
955 .proc_handler = proc_dointvec
956 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -0700957 {
958 .procname = "tcp_early_retrans",
959 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
960 .maxlen = sizeof(int),
961 .mode = 0644,
962 .proc_handler = proc_dointvec_minmax,
963 .extra1 = &zero,
964 .extra2 = &four,
965 },
Eric Dumazete20223f2017-10-26 21:54:57 -0700966 {
967 .procname = "tcp_recovery",
968 .data = &init_net.ipv4.sysctl_tcp_recovery,
969 .maxlen = sizeof(int),
970 .mode = 0644,
971 .proc_handler = proc_dointvec,
972 },
Eric Dumazet2c04ac82017-10-26 21:54:58 -0700973 {
974 .procname = "tcp_thin_linear_timeouts",
975 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
976 .maxlen = sizeof(int),
977 .mode = 0644,
978 .proc_handler = proc_dointvec
979 },
Eric Dumazetb510f0d2017-10-26 21:54:59 -0700980 {
981 .procname = "tcp_slow_start_after_idle",
982 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
983 .maxlen = sizeof(int),
984 .mode = 0644,
985 .proc_handler = proc_dointvec
986 },
Eric Dumazete0a1e5b2017-10-26 21:55:00 -0700987 {
988 .procname = "tcp_retrans_collapse",
989 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = proc_dointvec
993 },
Eric Dumazet3f4c7c62017-10-26 21:55:01 -0700994 {
995 .procname = "tcp_stdurg",
996 .data = &init_net.ipv4.sysctl_tcp_stdurg,
997 .maxlen = sizeof(int),
998 .mode = 0644,
999 .proc_handler = proc_dointvec
1000 },
Eric Dumazet625357a2017-10-26 21:55:02 -07001001 {
1002 .procname = "tcp_rfc1337",
1003 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1004 .maxlen = sizeof(int),
1005 .mode = 0644,
1006 .proc_handler = proc_dointvec
1007 },
Eric Dumazet65c94102017-10-26 21:55:03 -07001008 {
1009 .procname = "tcp_abort_on_overflow",
1010 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = proc_dointvec
1014 },
Eric Dumazet0bc65a22017-10-26 21:55:04 -07001015 {
1016 .procname = "tcp_fack",
1017 .data = &init_net.ipv4.sysctl_tcp_fack,
1018 .maxlen = sizeof(int),
1019 .mode = 0644,
1020 .proc_handler = proc_dointvec
1021 },
Eric Dumazetc6e21802017-10-26 21:55:06 -07001022 {
1023 .procname = "tcp_max_reordering",
1024 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec
1028 },
Eric Dumazet6496f6b2017-10-26 21:55:07 -07001029 {
1030 .procname = "tcp_dsack",
1031 .data = &init_net.ipv4.sysctl_tcp_dsack,
1032 .maxlen = sizeof(int),
1033 .mode = 0644,
1034 .proc_handler = proc_dointvec
1035 },
Eric Dumazet0c126542017-10-26 21:55:08 -07001036 {
1037 .procname = "tcp_app_win",
1038 .data = &init_net.ipv4.sysctl_tcp_app_win,
1039 .maxlen = sizeof(int),
1040 .mode = 0644,
1041 .proc_handler = proc_dointvec
1042 },
Eric Dumazet94f08932017-10-26 21:55:09 -07001043 {
1044 .procname = "tcp_adv_win_scale",
1045 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
1048 .proc_handler = proc_dointvec_minmax,
1049 .extra1 = &tcp_adv_win_scale_min,
1050 .extra2 = &tcp_adv_win_scale_max,
1051 },
Eric Dumazetaf9b69a2017-10-26 21:55:10 -07001052 {
1053 .procname = "tcp_frto",
1054 .data = &init_net.ipv4.sysctl_tcp_frto,
1055 .maxlen = sizeof(int),
1056 .mode = 0644,
1057 .proc_handler = proc_dointvec
1058 },
Eric Dumazetec36e412017-10-27 07:47:21 -07001059 {
1060 .procname = "tcp_no_metrics_save",
1061 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1062 .maxlen = sizeof(int),
1063 .mode = 0644,
1064 .proc_handler = proc_dointvec,
1065 },
Eric Dumazet4540c0c2017-10-27 07:47:22 -07001066 {
1067 .procname = "tcp_moderate_rcvbuf",
1068 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1069 .maxlen = sizeof(int),
1070 .mode = 0644,
1071 .proc_handler = proc_dointvec,
1072 },
Eric Dumazetd06a9902017-10-27 07:47:23 -07001073 {
1074 .procname = "tcp_tso_win_divisor",
1075 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1076 .maxlen = sizeof(int),
1077 .mode = 0644,
1078 .proc_handler = proc_dointvec,
1079 },
Eric Dumazetceef9ab2017-10-27 07:47:24 -07001080 {
1081 .procname = "tcp_workaround_signed_windows",
1082 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1083 .maxlen = sizeof(int),
1084 .mode = 0644,
1085 .proc_handler = proc_dointvec
1086 },
Eric Dumazet9184d8b2017-10-27 07:47:25 -07001087 {
1088 .procname = "tcp_limit_output_bytes",
1089 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
1092 .proc_handler = proc_dointvec
1093 },
Eric Dumazetb530b682017-10-27 07:47:26 -07001094 {
1095 .procname = "tcp_challenge_ack_limit",
1096 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1097 .maxlen = sizeof(int),
1098 .mode = 0644,
1099 .proc_handler = proc_dointvec
1100 },
Eric Dumazet26e95962017-10-27 07:47:27 -07001101 {
1102 .procname = "tcp_min_tso_segs",
1103 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = proc_dointvec_minmax,
1107 .extra1 = &one,
1108 .extra2 = &gso_max_segs,
1109 },
Eric Dumazetbd239702017-10-27 07:47:28 -07001110 {
1111 .procname = "tcp_min_rtt_wlen",
1112 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1113 .maxlen = sizeof(int),
1114 .mode = 0644,
1115 .proc_handler = proc_dointvec
1116 },
Eric Dumazet790f00e2017-10-27 07:47:29 -07001117 {
1118 .procname = "tcp_autocorking",
1119 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1120 .maxlen = sizeof(int),
1121 .mode = 0644,
1122 .proc_handler = proc_dointvec_minmax,
1123 .extra1 = &zero,
1124 .extra2 = &one,
1125 },
Eric Dumazet4170ba62017-10-27 07:47:30 -07001126 {
1127 .procname = "tcp_invalid_ratelimit",
1128 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1129 .maxlen = sizeof(int),
1130 .mode = 0644,
1131 .proc_handler = proc_dointvec_ms_jiffies,
1132 },
Eric Dumazet23a7102a2017-10-27 07:47:31 -07001133 {
1134 .procname = "tcp_pacing_ss_ratio",
1135 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1136 .maxlen = sizeof(int),
1137 .mode = 0644,
1138 .proc_handler = proc_dointvec_minmax,
1139 .extra1 = &zero,
1140 .extra2 = &thousand,
1141 },
Eric Dumazetc26e91f2017-10-27 07:47:32 -07001142 {
1143 .procname = "tcp_pacing_ca_ratio",
1144 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1145 .maxlen = sizeof(int),
1146 .mode = 0644,
1147 .proc_handler = proc_dointvec_minmax,
1148 .extra1 = &zero,
1149 .extra2 = &thousand,
1150 },
Eric Dumazet356d1832017-11-07 00:29:28 -08001151 {
1152 .procname = "tcp_wmem",
1153 .data = &init_net.ipv4.sysctl_tcp_wmem,
1154 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1155 .mode = 0644,
1156 .proc_handler = proc_dointvec_minmax,
1157 .extra1 = &one,
1158 },
1159 {
1160 .procname = "tcp_rmem",
1161 .data = &init_net.ipv4.sysctl_tcp_rmem,
1162 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1163 .mode = 0644,
1164 .proc_handler = proc_dointvec_minmax,
1165 .extra1 = &one,
1166 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001167 { }
1168};
1169
Pavel Emelyanov15775192008-03-26 01:54:18 -07001170static __net_init int ipv4_sysctl_init_net(struct net *net)
1171{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001172 struct ctl_table *table;
1173
1174 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001175 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001176 int i;
1177
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001178 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001179 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001180 goto err_alloc;
1181
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001182 /* Update the variables to point into the current struct net */
1183 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1184 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001185 }
1186
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001187 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001188 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001189 goto err_reg;
1190
WANG Cong122ff242014-05-12 16:04:53 -07001191 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1192 if (!net->ipv4.sysctl_local_reserved_ports)
1193 goto err_ports;
1194
Pavel Emelyanov15775192008-03-26 01:54:18 -07001195 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001196
WANG Cong122ff242014-05-12 16:04:53 -07001197err_ports:
1198 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001199err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001200 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001201 kfree(table);
1202err_alloc:
1203 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001204}
1205
1206static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1207{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001208 struct ctl_table *table;
1209
WANG Cong122ff242014-05-12 16:04:53 -07001210 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001211 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1212 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1213 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001214}
1215
1216static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1217 .init = ipv4_sysctl_init_net,
1218 .exit = ipv4_sysctl_exit_net,
1219};
1220
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001221static __init int sysctl_ipv4_init(void)
1222{
1223 struct ctl_table_header *hdr;
1224
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001225 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001226 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001227 return -ENOMEM;
1228
1229 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001230 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001231 return -ENOMEM;
1232 }
1233
1234 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001235}
1236
1237__initcall(sysctl_ipv4_init);