blob: 891ed2f91467b9345743682a3dd6e818acb48fbd [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;
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -070033static int two = 2;
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +000034static int four = 4;
Eric Dumazet43e122b2015-08-21 17:38:02 -070035static int thousand = 1000;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070036static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090037static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static int ip_local_port_range_min[] = { 1, 1 };
39static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000040static int tcp_adv_win_scale_min = -31;
41static int tcp_adv_win_scale_max = 31;
Krister Johansen4548b682017-01-20 17:49:11 -080042static int ip_privileged_port_min;
43static int ip_privileged_port_max = 65535;
Eric Dumazet249fab72010-12-13 12:16:14 -080044static int ip_ttl_min = 1;
45static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020046static int tcp_syn_retries_min = 1;
47static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000048static int ip_ping_group_range_min[] = { 0, 0 };
49static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Eric Dumazet9c21d2f2018-05-17 14:47:29 -070050static int comp_sack_nr_max = 255;
Maciej Żenczykowskid4ce5802018-09-25 21:59:28 -070051static u32 u32_max_div_HZ = UINT_MAX / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Florian Westphalb6690b12017-07-30 03:57:20 +020053/* obsolete */
54static int sysctl_tcp_low_latency __read_mostly;
55
Stephen Hemminger227b60f2007-10-10 17:30:46 -070056/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070057static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070058{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070059 bool same_parity = !((range[0] ^ range[1]) & 1);
60
WANG Cong4ee3bd42015-11-03 14:32:57 -080061 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070062 if (same_parity && !net->ipv4.ip_local_ports.warned) {
63 net->ipv4.ip_local_ports.warned = true;
64 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
65 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070066 net->ipv4.ip_local_ports.range[0] = range[0];
67 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080068 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070069}
70
71/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070072static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070073 void __user *buffer,
74 size_t *lenp, loff_t *ppos)
75{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070076 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070077 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070078 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070079 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070080 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070081 .data = &range,
82 .maxlen = sizeof(range),
83 .mode = table->mode,
84 .extra1 = &ip_local_port_range_min,
85 .extra2 = &ip_local_port_range_max,
86 };
87
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070088 inet_get_local_port_range(net, &range[0], &range[1]);
89
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070090 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070091
92 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080093 /* Ensure that the upper limit is not smaller than the lower,
94 * and that the lower does not encroach upon the privileged
95 * port limit.
96 */
97 if ((range[1] < range[0]) ||
98 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -070099 ret = -EINVAL;
100 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700101 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -0700102 }
103
104 return ret;
105}
106
Krister Johansen4548b682017-01-20 17:49:11 -0800107/* Validate changes from /proc interface. */
108static int ipv4_privileged_ports(struct ctl_table *table, int write,
109 void __user *buffer, size_t *lenp, loff_t *ppos)
110{
111 struct net *net = container_of(table->data, struct net,
112 ipv4.sysctl_ip_prot_sock);
113 int ret;
114 int pports;
115 int range[2];
116 struct ctl_table tmp = {
117 .data = &pports,
118 .maxlen = sizeof(pports),
119 .mode = table->mode,
120 .extra1 = &ip_privileged_port_min,
121 .extra2 = &ip_privileged_port_max,
122 };
123
124 pports = net->ipv4.sysctl_ip_prot_sock;
125
126 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
127
128 if (write && ret == 0) {
129 inet_get_local_port_range(net, &range[0], &range[1]);
130 /* Ensure that the local port range doesn't overlap with the
131 * privileged port range.
132 */
133 if (range[0] < pports)
134 ret = -EINVAL;
135 else
136 net->ipv4.sysctl_ip_prot_sock = pports;
137 }
138
139 return ret;
140}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000141
Eric W. Biederman7064d162012-05-24 10:34:21 -0600142static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000143{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600144 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700145 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700146 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000147 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000148 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700149 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000150
151 *low = data[0];
152 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700153 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000154}
155
156/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600157static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000158{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600159 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700160 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700161 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700162 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600163 data[0] = low;
164 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700165 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000166}
167
168/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700169static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000170 void __user *buffer,
171 size_t *lenp, loff_t *ppos)
172{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600173 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000174 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600175 gid_t urange[2];
176 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700177 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600178 .data = &urange,
179 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000180 .mode = table->mode,
181 .extra1 = &ip_ping_group_range_min,
182 .extra2 = &ip_ping_group_range_max,
183 };
184
Eric W. Biederman7064d162012-05-24 10:34:21 -0600185 inet_get_ping_group_range_table(table, &low, &high);
186 urange[0] = from_kgid_munged(user_ns, low);
187 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000188 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
189
Eric W. Biederman7064d162012-05-24 10:34:21 -0600190 if (write && ret == 0) {
191 low = make_kgid(user_ns, urange[0]);
192 high = make_kgid(user_ns, urange[1]);
Tyler Hicks70ba5b62018-07-05 18:49:23 +0000193 if (!gid_valid(low) || !gid_valid(high))
194 return -EINVAL;
195 if (urange[1] < urange[0] || gid_lt(high, low)) {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600196 low = make_kgid(&init_user_ns, 1);
197 high = make_kgid(&init_user_ns, 0);
198 }
199 set_ping_group_range(table, low, high);
200 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000201
202 return ret;
203}
204
Petr Machatad18c5d12018-08-01 00:36:42 +0200205static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
206 void __user *buffer,
207 size_t *lenp, loff_t *ppos)
208{
209 struct net *net;
210 int ret;
211
212 net = container_of(table->data, struct net,
213 ipv4.sysctl_ip_fwd_update_priority);
214 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
215 if (write && ret == 0)
216 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
217 net);
218
219 return ret;
220}
221
Joe Perchesfe2c6332013-06-11 23:04:25 -0700222static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700223 void __user *buffer, size_t *lenp, loff_t *ppos)
224{
Stephen Hemminger6670e152017-11-14 08:25:49 -0800225 struct net *net = container_of(ctl->data, struct net,
226 ipv4.tcp_congestion_control);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700227 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700228 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700229 .data = val,
230 .maxlen = TCP_CA_NAME_MAX,
231 };
232 int ret;
233
Stephen Hemminger6670e152017-11-14 08:25:49 -0800234 tcp_get_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700235
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700236 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700237 if (write && ret == 0)
Stephen Hemminger6670e152017-11-14 08:25:49 -0800238 ret = tcp_set_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700239 return ret;
240}
241
Joe Perchesfe2c6332013-06-11 23:04:25 -0700242static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700243 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800244 void __user *buffer, size_t *lenp,
245 loff_t *ppos)
246{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700247 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800248 int ret;
249
250 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
251 if (!tbl.data)
252 return -ENOMEM;
253 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700254 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800255 kfree(tbl.data);
256 return ret;
257}
258
Joe Perchesfe2c6332013-06-11 23:04:25 -0700259static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700260 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800261 void __user *buffer, size_t *lenp,
262 loff_t *ppos)
263{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700264 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800265 int ret;
266
267 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
268 if (!tbl.data)
269 return -ENOMEM;
270
271 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700272 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800273 if (write && ret == 0)
274 ret = tcp_set_allowed_congestion_control(tbl.data);
275 kfree(tbl.data);
276 return ret;
277}
278
Haishuang Yan43713842017-09-27 11:35:42 +0800279static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700280 void __user *buffer, size_t *lenp,
281 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000282{
Haishuang Yan43713842017-09-27 11:35:42 +0800283 struct net *net = container_of(table->data, struct net,
284 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700285 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000286 struct tcp_fastopen_context *ctxt;
Jerry Chu10467162012-08-31 12:29:11 +0000287 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
Yuchung Chengc860e992018-06-27 16:04:48 -0700288 __le32 key[4];
289 int ret, i;
Jerry Chu10467162012-08-31 12:29:11 +0000290
291 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
292 if (!tbl.data)
293 return -ENOMEM;
294
295 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800296 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000297 if (ctxt)
Yuchung Chengc860e992018-06-27 16:04:48 -0700298 memcpy(key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000299 else
Yuchung Chengc860e992018-06-27 16:04:48 -0700300 memset(key, 0, sizeof(key));
Jerry Chu10467162012-08-31 12:29:11 +0000301 rcu_read_unlock();
302
Yuchung Chengc860e992018-06-27 16:04:48 -0700303 for (i = 0; i < ARRAY_SIZE(key); i++)
304 user_key[i] = le32_to_cpu(key[i]);
305
Jerry Chu10467162012-08-31 12:29:11 +0000306 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
307 user_key[0], user_key[1], user_key[2], user_key[3]);
308 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
309
310 if (write && ret == 0) {
311 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
312 user_key + 2, user_key + 3) != 4) {
313 ret = -EINVAL;
314 goto bad_key;
315 }
Yuchung Chengc860e992018-06-27 16:04:48 -0700316
317 for (i = 0; i < ARRAY_SIZE(user_key); i++)
318 key[i] = cpu_to_le32(user_key[i]);
319
320 tcp_fastopen_reset_cipher(net, NULL, key,
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700321 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000322 }
323
324bad_key:
325 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
Yuchung Chengc860e992018-06-27 16:04:48 -0700326 user_key[0], user_key[1], user_key[2], user_key[3],
Jerry Chu10467162012-08-31 12:29:11 +0000327 (char *)tbl.data, ret);
328 kfree(tbl.data);
329 return ret;
330}
331
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600332static void proc_configure_early_demux(int enabled, int protocol)
333{
334 struct net_protocol *ipprot;
335#if IS_ENABLED(CONFIG_IPV6)
336 struct inet6_protocol *ip6prot;
337#endif
338
David Ahern58c4c6a2017-04-22 09:33:16 -0700339 rcu_read_lock();
340
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600341 ipprot = rcu_dereference(inet_protos[protocol]);
342 if (ipprot)
343 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
344 NULL;
345
346#if IS_ENABLED(CONFIG_IPV6)
347 ip6prot = rcu_dereference(inet6_protos[protocol]);
348 if (ip6prot)
349 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
350 NULL;
351#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700352 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600353}
354
355static int proc_tcp_early_demux(struct ctl_table *table, int write,
356 void __user *buffer, size_t *lenp, loff_t *ppos)
357{
358 int ret = 0;
359
360 ret = proc_dointvec(table, write, buffer, lenp, ppos);
361
362 if (write && !ret) {
363 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
364
365 proc_configure_early_demux(enabled, IPPROTO_TCP);
366 }
367
368 return ret;
369}
370
371static int proc_udp_early_demux(struct ctl_table *table, int write,
372 void __user *buffer, size_t *lenp, loff_t *ppos)
373{
374 int ret = 0;
375
376 ret = proc_dointvec(table, write, buffer, lenp, ppos);
377
378 if (write && !ret) {
379 int enabled = init_net.ipv4.sysctl_udp_early_demux;
380
381 proc_configure_early_demux(enabled, IPPROTO_UDP);
382 }
383
384 return ret;
385}
386
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700387static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
388 int write,
389 void __user *buffer,
390 size_t *lenp, loff_t *ppos)
391{
Haishuang Yan3733be12017-09-27 11:35:43 +0800392 struct net *net = container_of(table->data, struct net,
393 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700394 int ret;
395
396 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
397 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800398 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700399
400 return ret;
401}
402
403static int proc_tcp_available_ulp(struct ctl_table *ctl,
404 int write,
405 void __user *buffer, size_t *lenp,
406 loff_t *ppos)
407{
408 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
409 int ret;
410
411 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
412 if (!tbl.data)
413 return -ENOMEM;
414 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
415 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
416 kfree(tbl.data);
417
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700418 return ret;
419}
420
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100421#ifdef CONFIG_IP_ROUTE_MULTIPATH
422static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
423 void __user *buffer, size_t *lenp,
424 loff_t *ppos)
425{
426 struct net *net = container_of(table->data, struct net,
427 ipv4.sysctl_fib_multipath_hash_policy);
428 int ret;
429
430 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
431 if (write && ret == 0)
David Ahern3192dac2018-03-02 08:32:16 -0800432 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100433
434 return ret;
435}
436#endif
437
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800438static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900439 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 .procname = "tcp_max_orphans",
441 .data = &sysctl_tcp_max_orphans,
442 .maxlen = sizeof(int),
443 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800444 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 },
446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 .procname = "inet_peer_threshold",
448 .data = &inet_peer_threshold,
449 .maxlen = sizeof(int),
450 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800451 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 },
453 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .procname = "inet_peer_minttl",
455 .data = &inet_peer_minttl,
456 .maxlen = sizeof(int),
457 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800458 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 },
460 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .procname = "inet_peer_maxttl",
462 .data = &inet_peer_maxttl,
463 .maxlen = sizeof(int),
464 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800465 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 },
467 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700468 .procname = "tcp_mem",
469 .maxlen = sizeof(sysctl_tcp_mem),
470 .data = &sysctl_tcp_mem,
471 .mode = 0644,
472 .proc_handler = proc_doulongvec_minmax,
473 },
474 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .procname = "tcp_low_latency",
476 .data = &sysctl_tcp_low_latency,
477 .maxlen = sizeof(int),
478 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800479 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 },
Paul Moore446fda42006-08-03 16:48:06 -0700481#ifdef CONFIG_NETLABEL
482 {
Paul Moore446fda42006-08-03 16:48:06 -0700483 .procname = "cipso_cache_enable",
484 .data = &cipso_v4_cache_enabled,
485 .maxlen = sizeof(int),
486 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800487 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700488 },
489 {
Paul Moore446fda42006-08-03 16:48:06 -0700490 .procname = "cipso_cache_bucket_size",
491 .data = &cipso_v4_cache_bucketsize,
492 .maxlen = sizeof(int),
493 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800494 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700495 },
496 {
Paul Moore446fda42006-08-03 16:48:06 -0700497 .procname = "cipso_rbm_optfmt",
498 .data = &cipso_v4_rbm_optfmt,
499 .maxlen = sizeof(int),
500 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800501 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700502 },
503 {
Paul Moore446fda42006-08-03 16:48:06 -0700504 .procname = "cipso_rbm_strictvalid",
505 .data = &cipso_v4_rbm_strictvalid,
506 .maxlen = sizeof(int),
507 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800508 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700509 },
510#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800511 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800512 .procname = "tcp_available_congestion_control",
513 .maxlen = TCP_CA_BUF_MAX,
514 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800515 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800516 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800517 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800518 .procname = "tcp_allowed_congestion_control",
519 .maxlen = TCP_CA_BUF_MAX,
520 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800521 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800522 },
John Heffner886236c2007-03-25 19:21:45 -0700523 {
Dave Watson734942c2017-06-14 11:37:14 -0700524 .procname = "tcp_available_ulp",
525 .maxlen = TCP_ULP_BUF_MAX,
526 .mode = 0444,
527 .proc_handler = proc_tcp_available_ulp,
528 },
529 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700530 .procname = "icmp_msgs_per_sec",
531 .data = &sysctl_icmp_msgs_per_sec,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = proc_dointvec_minmax,
535 .extra1 = &zero,
536 },
537 {
538 .procname = "icmp_msgs_burst",
539 .data = &sysctl_icmp_msgs_burst,
540 .maxlen = sizeof(int),
541 .mode = 0644,
542 .proc_handler = proc_dointvec_minmax,
543 .extra1 = &zero,
544 },
545 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800546 .procname = "udp_mem",
547 .data = &sysctl_udp_mem,
548 .maxlen = sizeof(sysctl_udp_mem),
549 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000550 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800551 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800552 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800554
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700555static struct ctl_table ipv4_net_table[] = {
556 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700557 .procname = "icmp_echo_ignore_all",
558 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
559 .maxlen = sizeof(int),
560 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800561 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700562 },
563 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700564 .procname = "icmp_echo_ignore_broadcasts",
565 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
566 .maxlen = sizeof(int),
567 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800568 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700569 },
570 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700571 .procname = "icmp_ignore_bogus_error_responses",
572 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
573 .maxlen = sizeof(int),
574 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800575 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700576 },
577 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700578 .procname = "icmp_errors_use_inbound_ifaddr",
579 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
580 .maxlen = sizeof(int),
581 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800582 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700583 },
584 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700585 .procname = "icmp_ratelimit",
586 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
587 .maxlen = sizeof(int),
588 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800589 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700590 },
591 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700592 .procname = "icmp_ratemask",
593 .data = &init_net.ipv4.sysctl_icmp_ratemask,
594 .maxlen = sizeof(int),
595 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800596 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700597 },
Neil Horman1080d702008-10-27 12:28:25 -0700598 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000599 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700600 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600601 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000602 .mode = 0644,
603 .proc_handler = ipv4_ping_group_range,
604 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000605 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000606 .procname = "tcp_ecn",
607 .data = &init_net.ipv4.sysctl_tcp_ecn,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = proc_dointvec
611 },
612 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200613 .procname = "tcp_ecn_fallback",
614 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = proc_dointvec
618 },
619 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200620 .procname = "ip_dynaddr",
621 .data = &init_net.ipv4.sysctl_ip_dynaddr,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 .proc_handler = proc_dointvec
625 },
626 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200627 .procname = "ip_early_demux",
628 .data = &init_net.ipv4.sysctl_ip_early_demux,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = proc_dointvec
632 },
633 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600634 .procname = "udp_early_demux",
635 .data = &init_net.ipv4.sysctl_udp_early_demux,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = proc_udp_early_demux
639 },
640 {
641 .procname = "tcp_early_demux",
642 .data = &init_net.ipv4.sysctl_tcp_early_demux,
643 .maxlen = sizeof(int),
644 .mode = 0644,
645 .proc_handler = proc_tcp_early_demux
646 },
647 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200648 .procname = "ip_default_ttl",
649 .data = &init_net.ipv4.sysctl_ip_default_ttl,
650 .maxlen = sizeof(int),
651 .mode = 0644,
652 .proc_handler = proc_dointvec_minmax,
653 .extra1 = &ip_ttl_min,
654 .extra2 = &ip_ttl_max,
655 },
656 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700657 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700658 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
659 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700660 .mode = 0644,
661 .proc_handler = ipv4_local_port_range,
662 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100663 {
WANG Cong122ff242014-05-12 16:04:53 -0700664 .procname = "ip_local_reserved_ports",
665 .data = &init_net.ipv4.sysctl_local_reserved_ports,
666 .maxlen = 65536,
667 .mode = 0644,
668 .proc_handler = proc_do_large_bitmap,
669 },
670 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100671 .procname = "ip_no_pmtu_disc",
672 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = proc_dointvec
676 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100677 {
678 .procname = "ip_forward_use_pmtu",
679 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 .proc_handler = proc_dointvec,
683 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700684 {
Petr Machata432e05d2018-08-01 00:36:03 +0200685 .procname = "ip_forward_update_priority",
686 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
687 .maxlen = sizeof(int),
688 .mode = 0644,
Petr Machatad18c5d12018-08-01 00:36:42 +0200689 .proc_handler = ipv4_fwd_update_priority,
Petr Machata432e05d2018-08-01 00:36:03 +0200690 .extra1 = &zero,
691 .extra2 = &one,
692 },
693 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200694 .procname = "ip_nonlocal_bind",
695 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
696 .maxlen = sizeof(int),
697 .mode = 0644,
698 .proc_handler = proc_dointvec
699 },
700 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700701 .procname = "fwmark_reflect",
702 .data = &init_net.ipv4.sysctl_fwmark_reflect,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = proc_dointvec,
706 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700707 {
708 .procname = "tcp_fwmark_accept",
709 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = proc_dointvec,
713 },
David Ahern6dd9a142015-12-16 13:20:44 -0800714#ifdef CONFIG_NET_L3_MASTER_DEV
715 {
716 .procname = "tcp_l3mdev_accept",
717 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = proc_dointvec_minmax,
721 .extra1 = &zero,
722 .extra2 = &one,
723 },
724#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800725 {
726 .procname = "tcp_mtu_probing",
727 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
728 .maxlen = sizeof(int),
729 .mode = 0644,
730 .proc_handler = proc_dointvec,
731 },
732 {
733 .procname = "tcp_base_mss",
734 .data = &init_net.ipv4.sysctl_tcp_base_mss,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = proc_dointvec,
738 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800739 {
740 .procname = "tcp_probe_threshold",
741 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dointvec,
745 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800746 {
747 .procname = "tcp_probe_interval",
748 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
Maciej Żenczykowskid4ce5802018-09-25 21:59:28 -0700749 .maxlen = sizeof(u32),
Fan Du05cbc0d2015-03-06 11:18:24 +0800750 .mode = 0644,
Maciej Żenczykowskid4ce5802018-09-25 21:59:28 -0700751 .proc_handler = proc_douintvec_minmax,
752 .extra2 = &u32_max_div_HZ,
Fan Du05cbc0d2015-03-06 11:18:24 +0800753 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100754 {
755 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200756 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100757 .maxlen = sizeof(int),
758 .mode = 0644,
759 .proc_handler = proc_dointvec
760 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200761 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200762 .procname = "igmp_max_memberships",
763 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
764 .maxlen = sizeof(int),
765 .mode = 0644,
766 .proc_handler = proc_dointvec
767 },
768 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200769 .procname = "igmp_max_msf",
770 .data = &init_net.ipv4.sysctl_igmp_max_msf,
771 .maxlen = sizeof(int),
772 .mode = 0644,
773 .proc_handler = proc_dointvec
774 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200775#ifdef CONFIG_IP_MULTICAST
776 {
777 .procname = "igmp_qrv",
778 .data = &init_net.ipv4.sysctl_igmp_qrv,
779 .maxlen = sizeof(int),
780 .mode = 0644,
781 .proc_handler = proc_dointvec_minmax,
782 .extra1 = &one
783 },
784#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200785 {
Stephen Hemminger6670e152017-11-14 08:25:49 -0800786 .procname = "tcp_congestion_control",
787 .data = &init_net.ipv4.tcp_congestion_control,
788 .mode = 0644,
789 .maxlen = TCP_CA_NAME_MAX,
790 .proc_handler = proc_tcp_congestion_control,
791 },
792 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200793 .procname = "tcp_keepalive_time",
794 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
795 .maxlen = sizeof(int),
796 .mode = 0644,
797 .proc_handler = proc_dointvec_jiffies,
798 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200799 {
800 .procname = "tcp_keepalive_probes",
801 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
802 .maxlen = sizeof(int),
803 .mode = 0644,
804 .proc_handler = proc_dointvec
805 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200806 {
807 .procname = "tcp_keepalive_intvl",
808 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = proc_dointvec_jiffies,
812 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200813 {
814 .procname = "tcp_syn_retries",
815 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
816 .maxlen = sizeof(int),
817 .mode = 0644,
818 .proc_handler = proc_dointvec_minmax,
819 .extra1 = &tcp_syn_retries_min,
820 .extra2 = &tcp_syn_retries_max
821 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200822 {
823 .procname = "tcp_synack_retries",
824 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
825 .maxlen = sizeof(int),
826 .mode = 0644,
827 .proc_handler = proc_dointvec
828 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200829#ifdef CONFIG_SYN_COOKIES
830 {
831 .procname = "tcp_syncookies",
832 .data = &init_net.ipv4.sysctl_tcp_syncookies,
833 .maxlen = sizeof(int),
834 .mode = 0644,
835 .proc_handler = proc_dointvec
836 },
837#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200838 {
839 .procname = "tcp_reordering",
840 .data = &init_net.ipv4.sysctl_tcp_reordering,
841 .maxlen = sizeof(int),
842 .mode = 0644,
843 .proc_handler = proc_dointvec
844 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200845 {
846 .procname = "tcp_retries1",
847 .data = &init_net.ipv4.sysctl_tcp_retries1,
848 .maxlen = sizeof(int),
849 .mode = 0644,
850 .proc_handler = proc_dointvec_minmax,
851 .extra2 = &tcp_retr1_max
852 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +0200853 {
854 .procname = "tcp_retries2",
855 .data = &init_net.ipv4.sysctl_tcp_retries2,
856 .maxlen = sizeof(int),
857 .mode = 0644,
858 .proc_handler = proc_dointvec
859 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +0200860 {
861 .procname = "tcp_orphan_retries",
862 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
863 .maxlen = sizeof(int),
864 .mode = 0644,
865 .proc_handler = proc_dointvec
866 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +0200867 {
868 .procname = "tcp_fin_timeout",
869 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
870 .maxlen = sizeof(int),
871 .mode = 0644,
872 .proc_handler = proc_dointvec_jiffies,
873 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200874 {
875 .procname = "tcp_notsent_lowat",
876 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
877 .maxlen = sizeof(unsigned int),
878 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +0300879 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200880 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800881 {
882 .procname = "tcp_tw_reuse",
883 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
884 .maxlen = sizeof(int),
885 .mode = 0644,
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -0700886 .proc_handler = proc_dointvec_minmax,
887 .extra1 = &zero,
888 .extra2 = &two,
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800889 },
Haishuang Yan1946e672016-12-28 17:52:32 +0800890 {
891 .procname = "tcp_max_tw_buckets",
892 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
893 .maxlen = sizeof(int),
894 .mode = 0644,
895 .proc_handler = proc_dointvec
896 },
897 {
Haishuang Yanfee83d02016-12-28 17:52:33 +0800898 .procname = "tcp_max_syn_backlog",
899 .data = &init_net.ipv4.sysctl_max_syn_backlog,
900 .maxlen = sizeof(int),
901 .mode = 0644,
902 .proc_handler = proc_dointvec
903 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +0800904 {
905 .procname = "tcp_fastopen",
906 .data = &init_net.ipv4.sysctl_tcp_fastopen,
907 .maxlen = sizeof(int),
908 .mode = 0644,
909 .proc_handler = proc_dointvec,
910 },
Haishuang Yan43713842017-09-27 11:35:42 +0800911 {
912 .procname = "tcp_fastopen_key",
913 .mode = 0600,
914 .data = &init_net.ipv4.sysctl_tcp_fastopen,
915 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
916 .proc_handler = proc_tcp_fastopen_key,
917 },
Haishuang Yan3733be12017-09-27 11:35:43 +0800918 {
919 .procname = "tcp_fastopen_blackhole_timeout_sec",
920 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = proc_tfo_blackhole_detect_timeout,
924 .extra1 = &zero,
925 },
David Aherna6db4492016-04-07 07:21:00 -0700926#ifdef CONFIG_IP_ROUTE_MULTIPATH
927 {
928 .procname = "fib_multipath_use_neigh",
929 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
930 .maxlen = sizeof(int),
931 .mode = 0644,
932 .proc_handler = proc_dointvec_minmax,
933 .extra1 = &zero,
934 .extra2 = &one,
935 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200936 {
937 .procname = "fib_multipath_hash_policy",
938 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
939 .maxlen = sizeof(int),
940 .mode = 0644,
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100941 .proc_handler = proc_fib_multipath_hash_policy,
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200942 .extra1 = &zero,
943 .extra2 = &one,
944 },
David Aherna6db4492016-04-07 07:21:00 -0700945#endif
Krister Johansen4548b682017-01-20 17:49:11 -0800946 {
947 .procname = "ip_unprivileged_port_start",
948 .maxlen = sizeof(int),
949 .data = &init_net.ipv4.sysctl_ip_prot_sock,
950 .mode = 0644,
951 .proc_handler = ipv4_privileged_ports,
952 },
Robert Shearman63a6fff2017-01-26 18:02:24 +0000953#ifdef CONFIG_NET_L3_MASTER_DEV
954 {
955 .procname = "udp_l3mdev_accept",
956 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
957 .maxlen = sizeof(int),
958 .mode = 0644,
959 .proc_handler = proc_dointvec_minmax,
960 .extra1 = &zero,
961 .extra2 = &one,
962 },
963#endif
Eric Dumazetf9301032017-06-07 10:34:37 -0700964 {
965 .procname = "tcp_sack",
966 .data = &init_net.ipv4.sysctl_tcp_sack,
967 .maxlen = sizeof(int),
968 .mode = 0644,
969 .proc_handler = proc_dointvec
970 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -0700971 {
972 .procname = "tcp_window_scaling",
973 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = proc_dointvec
977 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -0700978 {
979 .procname = "tcp_timestamps",
980 .data = &init_net.ipv4.sysctl_tcp_timestamps,
981 .maxlen = sizeof(int),
982 .mode = 0644,
983 .proc_handler = proc_dointvec
984 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -0700985 {
986 .procname = "tcp_early_retrans",
987 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
988 .maxlen = sizeof(int),
989 .mode = 0644,
990 .proc_handler = proc_dointvec_minmax,
991 .extra1 = &zero,
992 .extra2 = &four,
993 },
Eric Dumazete20223f2017-10-26 21:54:57 -0700994 {
995 .procname = "tcp_recovery",
996 .data = &init_net.ipv4.sysctl_tcp_recovery,
997 .maxlen = sizeof(int),
998 .mode = 0644,
999 .proc_handler = proc_dointvec,
1000 },
Eric Dumazet2c04ac82017-10-26 21:54:58 -07001001 {
1002 .procname = "tcp_thin_linear_timeouts",
1003 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1004 .maxlen = sizeof(int),
1005 .mode = 0644,
1006 .proc_handler = proc_dointvec
1007 },
Eric Dumazetb510f0d2017-10-26 21:54:59 -07001008 {
1009 .procname = "tcp_slow_start_after_idle",
1010 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = proc_dointvec
1014 },
Eric Dumazete0a1e5b2017-10-26 21:55:00 -07001015 {
1016 .procname = "tcp_retrans_collapse",
1017 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1018 .maxlen = sizeof(int),
1019 .mode = 0644,
1020 .proc_handler = proc_dointvec
1021 },
Eric Dumazet3f4c7c62017-10-26 21:55:01 -07001022 {
1023 .procname = "tcp_stdurg",
1024 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec
1028 },
Eric Dumazet625357a2017-10-26 21:55:02 -07001029 {
1030 .procname = "tcp_rfc1337",
1031 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1032 .maxlen = sizeof(int),
1033 .mode = 0644,
1034 .proc_handler = proc_dointvec
1035 },
Eric Dumazet65c94102017-10-26 21:55:03 -07001036 {
1037 .procname = "tcp_abort_on_overflow",
1038 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1039 .maxlen = sizeof(int),
1040 .mode = 0644,
1041 .proc_handler = proc_dointvec
1042 },
Eric Dumazet0bc65a22017-10-26 21:55:04 -07001043 {
1044 .procname = "tcp_fack",
1045 .data = &init_net.ipv4.sysctl_tcp_fack,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
1048 .proc_handler = proc_dointvec
1049 },
Eric Dumazetc6e21802017-10-26 21:55:06 -07001050 {
1051 .procname = "tcp_max_reordering",
1052 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1053 .maxlen = sizeof(int),
1054 .mode = 0644,
1055 .proc_handler = proc_dointvec
1056 },
Eric Dumazet6496f6b2017-10-26 21:55:07 -07001057 {
1058 .procname = "tcp_dsack",
1059 .data = &init_net.ipv4.sysctl_tcp_dsack,
1060 .maxlen = sizeof(int),
1061 .mode = 0644,
1062 .proc_handler = proc_dointvec
1063 },
Eric Dumazet0c126542017-10-26 21:55:08 -07001064 {
1065 .procname = "tcp_app_win",
1066 .data = &init_net.ipv4.sysctl_tcp_app_win,
1067 .maxlen = sizeof(int),
1068 .mode = 0644,
1069 .proc_handler = proc_dointvec
1070 },
Eric Dumazet94f08932017-10-26 21:55:09 -07001071 {
1072 .procname = "tcp_adv_win_scale",
1073 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1074 .maxlen = sizeof(int),
1075 .mode = 0644,
1076 .proc_handler = proc_dointvec_minmax,
1077 .extra1 = &tcp_adv_win_scale_min,
1078 .extra2 = &tcp_adv_win_scale_max,
1079 },
Eric Dumazetaf9b69a2017-10-26 21:55:10 -07001080 {
1081 .procname = "tcp_frto",
1082 .data = &init_net.ipv4.sysctl_tcp_frto,
1083 .maxlen = sizeof(int),
1084 .mode = 0644,
1085 .proc_handler = proc_dointvec
1086 },
Eric Dumazetec36e412017-10-27 07:47:21 -07001087 {
1088 .procname = "tcp_no_metrics_save",
1089 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
1092 .proc_handler = proc_dointvec,
1093 },
Eric Dumazet4540c0c2017-10-27 07:47:22 -07001094 {
1095 .procname = "tcp_moderate_rcvbuf",
1096 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1097 .maxlen = sizeof(int),
1098 .mode = 0644,
1099 .proc_handler = proc_dointvec,
1100 },
Eric Dumazetd06a9902017-10-27 07:47:23 -07001101 {
1102 .procname = "tcp_tso_win_divisor",
1103 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = proc_dointvec,
1107 },
Eric Dumazetceef9ab2017-10-27 07:47:24 -07001108 {
1109 .procname = "tcp_workaround_signed_windows",
1110 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1111 .maxlen = sizeof(int),
1112 .mode = 0644,
1113 .proc_handler = proc_dointvec
1114 },
Eric Dumazet9184d8b2017-10-27 07:47:25 -07001115 {
1116 .procname = "tcp_limit_output_bytes",
1117 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1118 .maxlen = sizeof(int),
1119 .mode = 0644,
1120 .proc_handler = proc_dointvec
1121 },
Eric Dumazetb530b682017-10-27 07:47:26 -07001122 {
1123 .procname = "tcp_challenge_ack_limit",
1124 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1125 .maxlen = sizeof(int),
1126 .mode = 0644,
1127 .proc_handler = proc_dointvec
1128 },
Eric Dumazet26e95962017-10-27 07:47:27 -07001129 {
1130 .procname = "tcp_min_tso_segs",
1131 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1132 .maxlen = sizeof(int),
1133 .mode = 0644,
1134 .proc_handler = proc_dointvec_minmax,
1135 .extra1 = &one,
1136 .extra2 = &gso_max_segs,
1137 },
Eric Dumazetbd239702017-10-27 07:47:28 -07001138 {
1139 .procname = "tcp_min_rtt_wlen",
1140 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
1143 .proc_handler = proc_dointvec
1144 },
Eric Dumazet790f00e2017-10-27 07:47:29 -07001145 {
1146 .procname = "tcp_autocorking",
1147 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1148 .maxlen = sizeof(int),
1149 .mode = 0644,
1150 .proc_handler = proc_dointvec_minmax,
1151 .extra1 = &zero,
1152 .extra2 = &one,
1153 },
Eric Dumazet4170ba62017-10-27 07:47:30 -07001154 {
1155 .procname = "tcp_invalid_ratelimit",
1156 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1157 .maxlen = sizeof(int),
1158 .mode = 0644,
1159 .proc_handler = proc_dointvec_ms_jiffies,
1160 },
Eric Dumazet23a7102a2017-10-27 07:47:31 -07001161 {
1162 .procname = "tcp_pacing_ss_ratio",
1163 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1164 .maxlen = sizeof(int),
1165 .mode = 0644,
1166 .proc_handler = proc_dointvec_minmax,
1167 .extra1 = &zero,
1168 .extra2 = &thousand,
1169 },
Eric Dumazetc26e91f2017-10-27 07:47:32 -07001170 {
1171 .procname = "tcp_pacing_ca_ratio",
1172 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1173 .maxlen = sizeof(int),
1174 .mode = 0644,
1175 .proc_handler = proc_dointvec_minmax,
1176 .extra1 = &zero,
1177 .extra2 = &thousand,
1178 },
Eric Dumazet356d1832017-11-07 00:29:28 -08001179 {
1180 .procname = "tcp_wmem",
1181 .data = &init_net.ipv4.sysctl_tcp_wmem,
1182 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1183 .mode = 0644,
1184 .proc_handler = proc_dointvec_minmax,
1185 .extra1 = &one,
1186 },
1187 {
1188 .procname = "tcp_rmem",
1189 .data = &init_net.ipv4.sysctl_tcp_rmem,
1190 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1191 .mode = 0644,
1192 .proc_handler = proc_dointvec_minmax,
1193 .extra1 = &one,
1194 },
Tonghao Zhang1e802952018-03-13 21:57:16 -07001195 {
Eric Dumazet6d82aa22018-05-17 14:47:28 -07001196 .procname = "tcp_comp_sack_delay_ns",
1197 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1198 .maxlen = sizeof(unsigned long),
1199 .mode = 0644,
1200 .proc_handler = proc_doulongvec_minmax,
1201 },
1202 {
Eric Dumazet9c21d2f2018-05-17 14:47:29 -07001203 .procname = "tcp_comp_sack_nr",
1204 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1205 .maxlen = sizeof(int),
1206 .mode = 0644,
1207 .proc_handler = proc_dointvec_minmax,
1208 .extra1 = &zero,
1209 .extra2 = &comp_sack_nr_max,
1210 },
1211 {
Tonghao Zhang1e802952018-03-13 21:57:16 -07001212 .procname = "udp_rmem_min",
1213 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1214 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1215 .mode = 0644,
1216 .proc_handler = proc_dointvec_minmax,
1217 .extra1 = &one
1218 },
1219 {
1220 .procname = "udp_wmem_min",
1221 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1222 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1223 .mode = 0644,
1224 .proc_handler = proc_dointvec_minmax,
1225 .extra1 = &one
1226 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001227 { }
1228};
1229
Pavel Emelyanov15775192008-03-26 01:54:18 -07001230static __net_init int ipv4_sysctl_init_net(struct net *net)
1231{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001232 struct ctl_table *table;
1233
1234 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001235 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001236 int i;
1237
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001238 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001239 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001240 goto err_alloc;
1241
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001242 /* Update the variables to point into the current struct net */
1243 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1244 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001245 }
1246
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001247 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001248 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001249 goto err_reg;
1250
WANG Cong122ff242014-05-12 16:04:53 -07001251 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1252 if (!net->ipv4.sysctl_local_reserved_ports)
1253 goto err_ports;
1254
Pavel Emelyanov15775192008-03-26 01:54:18 -07001255 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001256
WANG Cong122ff242014-05-12 16:04:53 -07001257err_ports:
1258 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001259err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001260 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001261 kfree(table);
1262err_alloc:
1263 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001264}
1265
1266static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1267{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001268 struct ctl_table *table;
1269
WANG Cong122ff242014-05-12 16:04:53 -07001270 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001271 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1272 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1273 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001274}
1275
1276static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1277 .init = ipv4_sysctl_init_net,
1278 .exit = ipv4_sysctl_exit_net,
1279};
1280
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001281static __init int sysctl_ipv4_init(void)
1282{
1283 struct ctl_table_header *hdr;
1284
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001285 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001286 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001287 return -ENOMEM;
1288
1289 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001290 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001291 return -ENOMEM;
1292 }
1293
1294 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001295}
1296
1297__initcall(sysctl_ipv4_init);