blob: b92f422f2fa805cd5cca8264fe9ae5aa6d6a65b8 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Florian Westphalb6690b12017-07-30 03:57:20 +020052/* obsolete */
53static int sysctl_tcp_low_latency __read_mostly;
54
Stephen Hemminger227b60f2007-10-10 17:30:46 -070055/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070056static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070057{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070058 bool same_parity = !((range[0] ^ range[1]) & 1);
59
WANG Cong4ee3bd42015-11-03 14:32:57 -080060 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070061 if (same_parity && !net->ipv4.ip_local_ports.warned) {
62 net->ipv4.ip_local_ports.warned = true;
63 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
64 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070065 net->ipv4.ip_local_ports.range[0] = range[0];
66 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080067 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070068}
69
70/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070071static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070072 void __user *buffer,
73 size_t *lenp, loff_t *ppos)
74{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070075 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070076 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070077 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070078 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070079 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070080 .data = &range,
81 .maxlen = sizeof(range),
82 .mode = table->mode,
83 .extra1 = &ip_local_port_range_min,
84 .extra2 = &ip_local_port_range_max,
85 };
86
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070087 inet_get_local_port_range(net, &range[0], &range[1]);
88
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070089 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070090
91 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080092 /* Ensure that the upper limit is not smaller than the lower,
93 * and that the lower does not encroach upon the privileged
94 * port limit.
95 */
96 if ((range[1] < range[0]) ||
97 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -070098 ret = -EINVAL;
99 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700100 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -0700101 }
102
103 return ret;
104}
105
Krister Johansen4548b682017-01-20 17:49:11 -0800106/* Validate changes from /proc interface. */
107static int ipv4_privileged_ports(struct ctl_table *table, int write,
108 void __user *buffer, size_t *lenp, loff_t *ppos)
109{
110 struct net *net = container_of(table->data, struct net,
111 ipv4.sysctl_ip_prot_sock);
112 int ret;
113 int pports;
114 int range[2];
115 struct ctl_table tmp = {
116 .data = &pports,
117 .maxlen = sizeof(pports),
118 .mode = table->mode,
119 .extra1 = &ip_privileged_port_min,
120 .extra2 = &ip_privileged_port_max,
121 };
122
123 pports = net->ipv4.sysctl_ip_prot_sock;
124
125 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
126
127 if (write && ret == 0) {
128 inet_get_local_port_range(net, &range[0], &range[1]);
129 /* Ensure that the local port range doesn't overlap with the
130 * privileged port range.
131 */
132 if (range[0] < pports)
133 ret = -EINVAL;
134 else
135 net->ipv4.sysctl_ip_prot_sock = pports;
136 }
137
138 return ret;
139}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000140
Eric W. Biederman7064d162012-05-24 10:34:21 -0600141static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000142{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600143 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700144 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700145 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000146 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000147 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700148 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000149
150 *low = data[0];
151 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700152 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000153}
154
155/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600156static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000157{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600158 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700159 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700160 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700161 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600162 data[0] = low;
163 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700164 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000165}
166
167/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700168static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000169 void __user *buffer,
170 size_t *lenp, loff_t *ppos)
171{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600172 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000173 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600174 gid_t urange[2];
175 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700176 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600177 .data = &urange,
178 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000179 .mode = table->mode,
180 .extra1 = &ip_ping_group_range_min,
181 .extra2 = &ip_ping_group_range_max,
182 };
183
Eric W. Biederman7064d162012-05-24 10:34:21 -0600184 inet_get_ping_group_range_table(table, &low, &high);
185 urange[0] = from_kgid_munged(user_ns, low);
186 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000187 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
188
Eric W. Biederman7064d162012-05-24 10:34:21 -0600189 if (write && ret == 0) {
190 low = make_kgid(user_ns, urange[0]);
191 high = make_kgid(user_ns, urange[1]);
Tyler Hicks70ba5b62018-07-05 18:49:23 +0000192 if (!gid_valid(low) || !gid_valid(high))
193 return -EINVAL;
194 if (urange[1] < urange[0] || gid_lt(high, low)) {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600195 low = make_kgid(&init_user_ns, 1);
196 high = make_kgid(&init_user_ns, 0);
197 }
198 set_ping_group_range(table, low, high);
199 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000200
201 return ret;
202}
203
Petr Machatad18c5d12018-08-01 00:36:42 +0200204static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
205 void __user *buffer,
206 size_t *lenp, loff_t *ppos)
207{
208 struct net *net;
209 int ret;
210
211 net = container_of(table->data, struct net,
212 ipv4.sysctl_ip_fwd_update_priority);
213 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
214 if (write && ret == 0)
215 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
216 net);
217
218 return ret;
219}
220
Joe Perchesfe2c6332013-06-11 23:04:25 -0700221static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700222 void __user *buffer, size_t *lenp, loff_t *ppos)
223{
Stephen Hemminger6670e152017-11-14 08:25:49 -0800224 struct net *net = container_of(ctl->data, struct net,
225 ipv4.tcp_congestion_control);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700226 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700227 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700228 .data = val,
229 .maxlen = TCP_CA_NAME_MAX,
230 };
231 int ret;
232
Stephen Hemminger6670e152017-11-14 08:25:49 -0800233 tcp_get_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700234
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700235 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700236 if (write && ret == 0)
Stephen Hemminger6670e152017-11-14 08:25:49 -0800237 ret = tcp_set_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700238 return ret;
239}
240
Joe Perchesfe2c6332013-06-11 23:04:25 -0700241static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700242 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800243 void __user *buffer, size_t *lenp,
244 loff_t *ppos)
245{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700246 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800247 int ret;
248
249 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
250 if (!tbl.data)
251 return -ENOMEM;
252 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700253 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800254 kfree(tbl.data);
255 return ret;
256}
257
Joe Perchesfe2c6332013-06-11 23:04:25 -0700258static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700259 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800260 void __user *buffer, size_t *lenp,
261 loff_t *ppos)
262{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700263 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800264 int ret;
265
266 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
267 if (!tbl.data)
268 return -ENOMEM;
269
270 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700271 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800272 if (write && ret == 0)
273 ret = tcp_set_allowed_congestion_control(tbl.data);
274 kfree(tbl.data);
275 return ret;
276}
277
Haishuang Yan43713842017-09-27 11:35:42 +0800278static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700279 void __user *buffer, size_t *lenp,
280 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000281{
Haishuang Yan43713842017-09-27 11:35:42 +0800282 struct net *net = container_of(table->data, struct net,
283 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700284 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000285 struct tcp_fastopen_context *ctxt;
Jerry Chu10467162012-08-31 12:29:11 +0000286 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
Yuchung Chengc860e992018-06-27 16:04:48 -0700287 __le32 key[4];
288 int ret, i;
Jerry Chu10467162012-08-31 12:29:11 +0000289
290 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
291 if (!tbl.data)
292 return -ENOMEM;
293
294 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800295 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000296 if (ctxt)
Yuchung Chengc860e992018-06-27 16:04:48 -0700297 memcpy(key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000298 else
Yuchung Chengc860e992018-06-27 16:04:48 -0700299 memset(key, 0, sizeof(key));
Jerry Chu10467162012-08-31 12:29:11 +0000300 rcu_read_unlock();
301
Yuchung Chengc860e992018-06-27 16:04:48 -0700302 for (i = 0; i < ARRAY_SIZE(key); i++)
303 user_key[i] = le32_to_cpu(key[i]);
304
Jerry Chu10467162012-08-31 12:29:11 +0000305 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
306 user_key[0], user_key[1], user_key[2], user_key[3]);
307 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
308
309 if (write && ret == 0) {
310 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
311 user_key + 2, user_key + 3) != 4) {
312 ret = -EINVAL;
313 goto bad_key;
314 }
Yuchung Chengc860e992018-06-27 16:04:48 -0700315
316 for (i = 0; i < ARRAY_SIZE(user_key); i++)
317 key[i] = cpu_to_le32(user_key[i]);
318
319 tcp_fastopen_reset_cipher(net, NULL, key,
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700320 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000321 }
322
323bad_key:
324 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
Yuchung Chengc860e992018-06-27 16:04:48 -0700325 user_key[0], user_key[1], user_key[2], user_key[3],
Jerry Chu10467162012-08-31 12:29:11 +0000326 (char *)tbl.data, ret);
327 kfree(tbl.data);
328 return ret;
329}
330
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600331static void proc_configure_early_demux(int enabled, int protocol)
332{
333 struct net_protocol *ipprot;
334#if IS_ENABLED(CONFIG_IPV6)
335 struct inet6_protocol *ip6prot;
336#endif
337
David Ahern58c4c6a2017-04-22 09:33:16 -0700338 rcu_read_lock();
339
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600340 ipprot = rcu_dereference(inet_protos[protocol]);
341 if (ipprot)
342 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
343 NULL;
344
345#if IS_ENABLED(CONFIG_IPV6)
346 ip6prot = rcu_dereference(inet6_protos[protocol]);
347 if (ip6prot)
348 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
349 NULL;
350#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700351 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600352}
353
354static int proc_tcp_early_demux(struct ctl_table *table, int write,
355 void __user *buffer, size_t *lenp, loff_t *ppos)
356{
357 int ret = 0;
358
359 ret = proc_dointvec(table, write, buffer, lenp, ppos);
360
361 if (write && !ret) {
362 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
363
364 proc_configure_early_demux(enabled, IPPROTO_TCP);
365 }
366
367 return ret;
368}
369
370static int proc_udp_early_demux(struct ctl_table *table, int write,
371 void __user *buffer, size_t *lenp, loff_t *ppos)
372{
373 int ret = 0;
374
375 ret = proc_dointvec(table, write, buffer, lenp, ppos);
376
377 if (write && !ret) {
378 int enabled = init_net.ipv4.sysctl_udp_early_demux;
379
380 proc_configure_early_demux(enabled, IPPROTO_UDP);
381 }
382
383 return ret;
384}
385
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700386static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
387 int write,
388 void __user *buffer,
389 size_t *lenp, loff_t *ppos)
390{
Haishuang Yan3733be12017-09-27 11:35:43 +0800391 struct net *net = container_of(table->data, struct net,
392 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700393 int ret;
394
395 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
396 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800397 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700398
399 return ret;
400}
401
402static int proc_tcp_available_ulp(struct ctl_table *ctl,
403 int write,
404 void __user *buffer, size_t *lenp,
405 loff_t *ppos)
406{
407 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
408 int ret;
409
410 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
411 if (!tbl.data)
412 return -ENOMEM;
413 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
414 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
415 kfree(tbl.data);
416
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700417 return ret;
418}
419
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100420#ifdef CONFIG_IP_ROUTE_MULTIPATH
421static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
422 void __user *buffer, size_t *lenp,
423 loff_t *ppos)
424{
425 struct net *net = container_of(table->data, struct net,
426 ipv4.sysctl_fib_multipath_hash_policy);
427 int ret;
428
429 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
430 if (write && ret == 0)
David Ahern3192dac2018-03-02 08:32:16 -0800431 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100432
433 return ret;
434}
435#endif
436
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800437static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .procname = "tcp_max_orphans",
440 .data = &sysctl_tcp_max_orphans,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800443 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 },
445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .procname = "inet_peer_threshold",
447 .data = &inet_peer_threshold,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800450 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 },
452 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 .procname = "inet_peer_minttl",
454 .data = &inet_peer_minttl,
455 .maxlen = sizeof(int),
456 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800457 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 },
459 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .procname = "inet_peer_maxttl",
461 .data = &inet_peer_maxttl,
462 .maxlen = sizeof(int),
463 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800464 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 },
466 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700467 .procname = "tcp_mem",
468 .maxlen = sizeof(sysctl_tcp_mem),
469 .data = &sysctl_tcp_mem,
470 .mode = 0644,
471 .proc_handler = proc_doulongvec_minmax,
472 },
473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "tcp_low_latency",
475 .data = &sysctl_tcp_low_latency,
476 .maxlen = sizeof(int),
477 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800478 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
Paul Moore446fda42006-08-03 16:48:06 -0700480#ifdef CONFIG_NETLABEL
481 {
Paul Moore446fda42006-08-03 16:48:06 -0700482 .procname = "cipso_cache_enable",
483 .data = &cipso_v4_cache_enabled,
484 .maxlen = sizeof(int),
485 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800486 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700487 },
488 {
Paul Moore446fda42006-08-03 16:48:06 -0700489 .procname = "cipso_cache_bucket_size",
490 .data = &cipso_v4_cache_bucketsize,
491 .maxlen = sizeof(int),
492 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800493 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700494 },
495 {
Paul Moore446fda42006-08-03 16:48:06 -0700496 .procname = "cipso_rbm_optfmt",
497 .data = &cipso_v4_rbm_optfmt,
498 .maxlen = sizeof(int),
499 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800500 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700501 },
502 {
Paul Moore446fda42006-08-03 16:48:06 -0700503 .procname = "cipso_rbm_strictvalid",
504 .data = &cipso_v4_rbm_strictvalid,
505 .maxlen = sizeof(int),
506 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800507 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700508 },
509#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800510 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800511 .procname = "tcp_available_congestion_control",
512 .maxlen = TCP_CA_BUF_MAX,
513 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800514 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800515 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800516 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800517 .procname = "tcp_allowed_congestion_control",
518 .maxlen = TCP_CA_BUF_MAX,
519 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800520 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800521 },
John Heffner886236c2007-03-25 19:21:45 -0700522 {
Dave Watson734942c2017-06-14 11:37:14 -0700523 .procname = "tcp_available_ulp",
524 .maxlen = TCP_ULP_BUF_MAX,
525 .mode = 0444,
526 .proc_handler = proc_tcp_available_ulp,
527 },
528 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700529 .procname = "icmp_msgs_per_sec",
530 .data = &sysctl_icmp_msgs_per_sec,
531 .maxlen = sizeof(int),
532 .mode = 0644,
533 .proc_handler = proc_dointvec_minmax,
534 .extra1 = &zero,
535 },
536 {
537 .procname = "icmp_msgs_burst",
538 .data = &sysctl_icmp_msgs_burst,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 .proc_handler = proc_dointvec_minmax,
542 .extra1 = &zero,
543 },
544 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800545 .procname = "udp_mem",
546 .data = &sysctl_udp_mem,
547 .maxlen = sizeof(sysctl_udp_mem),
548 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000549 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800550 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800551 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800553
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700554static struct ctl_table ipv4_net_table[] = {
555 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700556 .procname = "icmp_echo_ignore_all",
557 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
558 .maxlen = sizeof(int),
559 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800560 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700561 },
562 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700563 .procname = "icmp_echo_ignore_broadcasts",
564 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
565 .maxlen = sizeof(int),
566 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800567 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700568 },
569 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700570 .procname = "icmp_ignore_bogus_error_responses",
571 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
572 .maxlen = sizeof(int),
573 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800574 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700575 },
576 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700577 .procname = "icmp_errors_use_inbound_ifaddr",
578 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
579 .maxlen = sizeof(int),
580 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800581 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700582 },
583 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700584 .procname = "icmp_ratelimit",
585 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
586 .maxlen = sizeof(int),
587 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800588 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700589 },
590 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700591 .procname = "icmp_ratemask",
592 .data = &init_net.ipv4.sysctl_icmp_ratemask,
593 .maxlen = sizeof(int),
594 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800595 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700596 },
Neil Horman1080d702008-10-27 12:28:25 -0700597 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000598 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700599 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600600 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000601 .mode = 0644,
602 .proc_handler = ipv4_ping_group_range,
603 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000604 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000605 .procname = "tcp_ecn",
606 .data = &init_net.ipv4.sysctl_tcp_ecn,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = proc_dointvec
610 },
611 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200612 .procname = "tcp_ecn_fallback",
613 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
614 .maxlen = sizeof(int),
615 .mode = 0644,
616 .proc_handler = proc_dointvec
617 },
618 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200619 .procname = "ip_dynaddr",
620 .data = &init_net.ipv4.sysctl_ip_dynaddr,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = proc_dointvec
624 },
625 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200626 .procname = "ip_early_demux",
627 .data = &init_net.ipv4.sysctl_ip_early_demux,
628 .maxlen = sizeof(int),
629 .mode = 0644,
630 .proc_handler = proc_dointvec
631 },
632 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600633 .procname = "udp_early_demux",
634 .data = &init_net.ipv4.sysctl_udp_early_demux,
635 .maxlen = sizeof(int),
636 .mode = 0644,
637 .proc_handler = proc_udp_early_demux
638 },
639 {
640 .procname = "tcp_early_demux",
641 .data = &init_net.ipv4.sysctl_tcp_early_demux,
642 .maxlen = sizeof(int),
643 .mode = 0644,
644 .proc_handler = proc_tcp_early_demux
645 },
646 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200647 .procname = "ip_default_ttl",
648 .data = &init_net.ipv4.sysctl_ip_default_ttl,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = proc_dointvec_minmax,
652 .extra1 = &ip_ttl_min,
653 .extra2 = &ip_ttl_max,
654 },
655 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700656 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700657 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
658 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700659 .mode = 0644,
660 .proc_handler = ipv4_local_port_range,
661 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100662 {
WANG Cong122ff242014-05-12 16:04:53 -0700663 .procname = "ip_local_reserved_ports",
664 .data = &init_net.ipv4.sysctl_local_reserved_ports,
665 .maxlen = 65536,
666 .mode = 0644,
667 .proc_handler = proc_do_large_bitmap,
668 },
669 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100670 .procname = "ip_no_pmtu_disc",
671 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = proc_dointvec
675 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100676 {
677 .procname = "ip_forward_use_pmtu",
678 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
679 .maxlen = sizeof(int),
680 .mode = 0644,
681 .proc_handler = proc_dointvec,
682 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700683 {
Petr Machata432e05d2018-08-01 00:36:03 +0200684 .procname = "ip_forward_update_priority",
685 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
686 .maxlen = sizeof(int),
687 .mode = 0644,
Petr Machatad18c5d12018-08-01 00:36:42 +0200688 .proc_handler = ipv4_fwd_update_priority,
Petr Machata432e05d2018-08-01 00:36:03 +0200689 .extra1 = &zero,
690 .extra2 = &one,
691 },
692 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200693 .procname = "ip_nonlocal_bind",
694 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
695 .maxlen = sizeof(int),
696 .mode = 0644,
697 .proc_handler = proc_dointvec
698 },
699 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700700 .procname = "fwmark_reflect",
701 .data = &init_net.ipv4.sysctl_fwmark_reflect,
702 .maxlen = sizeof(int),
703 .mode = 0644,
704 .proc_handler = proc_dointvec,
705 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700706 {
707 .procname = "tcp_fwmark_accept",
708 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
709 .maxlen = sizeof(int),
710 .mode = 0644,
711 .proc_handler = proc_dointvec,
712 },
David Ahern6dd9a142015-12-16 13:20:44 -0800713#ifdef CONFIG_NET_L3_MASTER_DEV
714 {
715 .procname = "tcp_l3mdev_accept",
716 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = proc_dointvec_minmax,
720 .extra1 = &zero,
721 .extra2 = &one,
722 },
723#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800724 {
725 .procname = "tcp_mtu_probing",
726 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = proc_dointvec,
730 },
731 {
732 .procname = "tcp_base_mss",
733 .data = &init_net.ipv4.sysctl_tcp_base_mss,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = proc_dointvec,
737 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800738 {
739 .procname = "tcp_probe_threshold",
740 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
741 .maxlen = sizeof(int),
742 .mode = 0644,
743 .proc_handler = proc_dointvec,
744 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800745 {
746 .procname = "tcp_probe_interval",
747 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
748 .maxlen = sizeof(int),
749 .mode = 0644,
750 .proc_handler = proc_dointvec,
751 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100752 {
753 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200754 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100755 .maxlen = sizeof(int),
756 .mode = 0644,
757 .proc_handler = proc_dointvec
758 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200759 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200760 .procname = "igmp_max_memberships",
761 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
762 .maxlen = sizeof(int),
763 .mode = 0644,
764 .proc_handler = proc_dointvec
765 },
766 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200767 .procname = "igmp_max_msf",
768 .data = &init_net.ipv4.sysctl_igmp_max_msf,
769 .maxlen = sizeof(int),
770 .mode = 0644,
771 .proc_handler = proc_dointvec
772 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200773#ifdef CONFIG_IP_MULTICAST
774 {
775 .procname = "igmp_qrv",
776 .data = &init_net.ipv4.sysctl_igmp_qrv,
777 .maxlen = sizeof(int),
778 .mode = 0644,
779 .proc_handler = proc_dointvec_minmax,
780 .extra1 = &one
781 },
782#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200783 {
Stephen Hemminger6670e152017-11-14 08:25:49 -0800784 .procname = "tcp_congestion_control",
785 .data = &init_net.ipv4.tcp_congestion_control,
786 .mode = 0644,
787 .maxlen = TCP_CA_NAME_MAX,
788 .proc_handler = proc_tcp_congestion_control,
789 },
790 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200791 .procname = "tcp_keepalive_time",
792 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
793 .maxlen = sizeof(int),
794 .mode = 0644,
795 .proc_handler = proc_dointvec_jiffies,
796 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200797 {
798 .procname = "tcp_keepalive_probes",
799 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
800 .maxlen = sizeof(int),
801 .mode = 0644,
802 .proc_handler = proc_dointvec
803 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200804 {
805 .procname = "tcp_keepalive_intvl",
806 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
807 .maxlen = sizeof(int),
808 .mode = 0644,
809 .proc_handler = proc_dointvec_jiffies,
810 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200811 {
812 .procname = "tcp_syn_retries",
813 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = proc_dointvec_minmax,
817 .extra1 = &tcp_syn_retries_min,
818 .extra2 = &tcp_syn_retries_max
819 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200820 {
821 .procname = "tcp_synack_retries",
822 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = proc_dointvec
826 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200827#ifdef CONFIG_SYN_COOKIES
828 {
829 .procname = "tcp_syncookies",
830 .data = &init_net.ipv4.sysctl_tcp_syncookies,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = proc_dointvec
834 },
835#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200836 {
837 .procname = "tcp_reordering",
838 .data = &init_net.ipv4.sysctl_tcp_reordering,
839 .maxlen = sizeof(int),
840 .mode = 0644,
841 .proc_handler = proc_dointvec
842 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200843 {
844 .procname = "tcp_retries1",
845 .data = &init_net.ipv4.sysctl_tcp_retries1,
846 .maxlen = sizeof(int),
847 .mode = 0644,
848 .proc_handler = proc_dointvec_minmax,
849 .extra2 = &tcp_retr1_max
850 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +0200851 {
852 .procname = "tcp_retries2",
853 .data = &init_net.ipv4.sysctl_tcp_retries2,
854 .maxlen = sizeof(int),
855 .mode = 0644,
856 .proc_handler = proc_dointvec
857 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +0200858 {
859 .procname = "tcp_orphan_retries",
860 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
861 .maxlen = sizeof(int),
862 .mode = 0644,
863 .proc_handler = proc_dointvec
864 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +0200865 {
866 .procname = "tcp_fin_timeout",
867 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
868 .maxlen = sizeof(int),
869 .mode = 0644,
870 .proc_handler = proc_dointvec_jiffies,
871 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200872 {
873 .procname = "tcp_notsent_lowat",
874 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
875 .maxlen = sizeof(unsigned int),
876 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +0300877 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200878 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800879 {
880 .procname = "tcp_tw_reuse",
881 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
882 .maxlen = sizeof(int),
883 .mode = 0644,
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -0700884 .proc_handler = proc_dointvec_minmax,
885 .extra1 = &zero,
886 .extra2 = &two,
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800887 },
Haishuang Yan1946e672016-12-28 17:52:32 +0800888 {
889 .procname = "tcp_max_tw_buckets",
890 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
891 .maxlen = sizeof(int),
892 .mode = 0644,
893 .proc_handler = proc_dointvec
894 },
895 {
Haishuang Yanfee83d02016-12-28 17:52:33 +0800896 .procname = "tcp_max_syn_backlog",
897 .data = &init_net.ipv4.sysctl_max_syn_backlog,
898 .maxlen = sizeof(int),
899 .mode = 0644,
900 .proc_handler = proc_dointvec
901 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +0800902 {
903 .procname = "tcp_fastopen",
904 .data = &init_net.ipv4.sysctl_tcp_fastopen,
905 .maxlen = sizeof(int),
906 .mode = 0644,
907 .proc_handler = proc_dointvec,
908 },
Haishuang Yan43713842017-09-27 11:35:42 +0800909 {
910 .procname = "tcp_fastopen_key",
911 .mode = 0600,
912 .data = &init_net.ipv4.sysctl_tcp_fastopen,
913 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
914 .proc_handler = proc_tcp_fastopen_key,
915 },
Haishuang Yan3733be12017-09-27 11:35:43 +0800916 {
917 .procname = "tcp_fastopen_blackhole_timeout_sec",
918 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
919 .maxlen = sizeof(int),
920 .mode = 0644,
921 .proc_handler = proc_tfo_blackhole_detect_timeout,
922 .extra1 = &zero,
923 },
David Aherna6db4492016-04-07 07:21:00 -0700924#ifdef CONFIG_IP_ROUTE_MULTIPATH
925 {
926 .procname = "fib_multipath_use_neigh",
927 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec_minmax,
931 .extra1 = &zero,
932 .extra2 = &one,
933 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200934 {
935 .procname = "fib_multipath_hash_policy",
936 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
937 .maxlen = sizeof(int),
938 .mode = 0644,
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100939 .proc_handler = proc_fib_multipath_hash_policy,
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200940 .extra1 = &zero,
941 .extra2 = &one,
942 },
David Aherna6db4492016-04-07 07:21:00 -0700943#endif
Krister Johansen4548b682017-01-20 17:49:11 -0800944 {
945 .procname = "ip_unprivileged_port_start",
946 .maxlen = sizeof(int),
947 .data = &init_net.ipv4.sysctl_ip_prot_sock,
948 .mode = 0644,
949 .proc_handler = ipv4_privileged_ports,
950 },
Robert Shearman63a6fff2017-01-26 18:02:24 +0000951#ifdef CONFIG_NET_L3_MASTER_DEV
952 {
953 .procname = "udp_l3mdev_accept",
954 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
955 .maxlen = sizeof(int),
956 .mode = 0644,
957 .proc_handler = proc_dointvec_minmax,
958 .extra1 = &zero,
959 .extra2 = &one,
960 },
961#endif
Eric Dumazetf9301032017-06-07 10:34:37 -0700962 {
963 .procname = "tcp_sack",
964 .data = &init_net.ipv4.sysctl_tcp_sack,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = proc_dointvec
968 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -0700969 {
970 .procname = "tcp_window_scaling",
971 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
972 .maxlen = sizeof(int),
973 .mode = 0644,
974 .proc_handler = proc_dointvec
975 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -0700976 {
977 .procname = "tcp_timestamps",
978 .data = &init_net.ipv4.sysctl_tcp_timestamps,
979 .maxlen = sizeof(int),
980 .mode = 0644,
981 .proc_handler = proc_dointvec
982 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -0700983 {
984 .procname = "tcp_early_retrans",
985 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
986 .maxlen = sizeof(int),
987 .mode = 0644,
988 .proc_handler = proc_dointvec_minmax,
989 .extra1 = &zero,
990 .extra2 = &four,
991 },
Eric Dumazete20223f2017-10-26 21:54:57 -0700992 {
993 .procname = "tcp_recovery",
994 .data = &init_net.ipv4.sysctl_tcp_recovery,
995 .maxlen = sizeof(int),
996 .mode = 0644,
997 .proc_handler = proc_dointvec,
998 },
Eric Dumazet2c04ac82017-10-26 21:54:58 -0700999 {
1000 .procname = "tcp_thin_linear_timeouts",
1001 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1002 .maxlen = sizeof(int),
1003 .mode = 0644,
1004 .proc_handler = proc_dointvec
1005 },
Eric Dumazetb510f0d2017-10-26 21:54:59 -07001006 {
1007 .procname = "tcp_slow_start_after_idle",
1008 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
1011 .proc_handler = proc_dointvec
1012 },
Eric Dumazete0a1e5b2017-10-26 21:55:00 -07001013 {
1014 .procname = "tcp_retrans_collapse",
1015 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1016 .maxlen = sizeof(int),
1017 .mode = 0644,
1018 .proc_handler = proc_dointvec
1019 },
Eric Dumazet3f4c7c62017-10-26 21:55:01 -07001020 {
1021 .procname = "tcp_stdurg",
1022 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1023 .maxlen = sizeof(int),
1024 .mode = 0644,
1025 .proc_handler = proc_dointvec
1026 },
Eric Dumazet625357a2017-10-26 21:55:02 -07001027 {
1028 .procname = "tcp_rfc1337",
1029 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1030 .maxlen = sizeof(int),
1031 .mode = 0644,
1032 .proc_handler = proc_dointvec
1033 },
Eric Dumazet65c94102017-10-26 21:55:03 -07001034 {
1035 .procname = "tcp_abort_on_overflow",
1036 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1037 .maxlen = sizeof(int),
1038 .mode = 0644,
1039 .proc_handler = proc_dointvec
1040 },
Eric Dumazet0bc65a22017-10-26 21:55:04 -07001041 {
1042 .procname = "tcp_fack",
1043 .data = &init_net.ipv4.sysctl_tcp_fack,
1044 .maxlen = sizeof(int),
1045 .mode = 0644,
1046 .proc_handler = proc_dointvec
1047 },
Eric Dumazetc6e21802017-10-26 21:55:06 -07001048 {
1049 .procname = "tcp_max_reordering",
1050 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1051 .maxlen = sizeof(int),
1052 .mode = 0644,
1053 .proc_handler = proc_dointvec
1054 },
Eric Dumazet6496f6b2017-10-26 21:55:07 -07001055 {
1056 .procname = "tcp_dsack",
1057 .data = &init_net.ipv4.sysctl_tcp_dsack,
1058 .maxlen = sizeof(int),
1059 .mode = 0644,
1060 .proc_handler = proc_dointvec
1061 },
Eric Dumazet0c126542017-10-26 21:55:08 -07001062 {
1063 .procname = "tcp_app_win",
1064 .data = &init_net.ipv4.sysctl_tcp_app_win,
1065 .maxlen = sizeof(int),
1066 .mode = 0644,
1067 .proc_handler = proc_dointvec
1068 },
Eric Dumazet94f08932017-10-26 21:55:09 -07001069 {
1070 .procname = "tcp_adv_win_scale",
1071 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1072 .maxlen = sizeof(int),
1073 .mode = 0644,
1074 .proc_handler = proc_dointvec_minmax,
1075 .extra1 = &tcp_adv_win_scale_min,
1076 .extra2 = &tcp_adv_win_scale_max,
1077 },
Eric Dumazetaf9b69a2017-10-26 21:55:10 -07001078 {
1079 .procname = "tcp_frto",
1080 .data = &init_net.ipv4.sysctl_tcp_frto,
1081 .maxlen = sizeof(int),
1082 .mode = 0644,
1083 .proc_handler = proc_dointvec
1084 },
Eric Dumazetec36e412017-10-27 07:47:21 -07001085 {
1086 .procname = "tcp_no_metrics_save",
1087 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1088 .maxlen = sizeof(int),
1089 .mode = 0644,
1090 .proc_handler = proc_dointvec,
1091 },
Eric Dumazet4540c0c2017-10-27 07:47:22 -07001092 {
1093 .procname = "tcp_moderate_rcvbuf",
1094 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1095 .maxlen = sizeof(int),
1096 .mode = 0644,
1097 .proc_handler = proc_dointvec,
1098 },
Eric Dumazetd06a9902017-10-27 07:47:23 -07001099 {
1100 .procname = "tcp_tso_win_divisor",
1101 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1102 .maxlen = sizeof(int),
1103 .mode = 0644,
1104 .proc_handler = proc_dointvec,
1105 },
Eric Dumazetceef9ab2017-10-27 07:47:24 -07001106 {
1107 .procname = "tcp_workaround_signed_windows",
1108 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1109 .maxlen = sizeof(int),
1110 .mode = 0644,
1111 .proc_handler = proc_dointvec
1112 },
Eric Dumazet9184d8b2017-10-27 07:47:25 -07001113 {
1114 .procname = "tcp_limit_output_bytes",
1115 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1116 .maxlen = sizeof(int),
1117 .mode = 0644,
1118 .proc_handler = proc_dointvec
1119 },
Eric Dumazetb530b682017-10-27 07:47:26 -07001120 {
1121 .procname = "tcp_challenge_ack_limit",
1122 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1123 .maxlen = sizeof(int),
1124 .mode = 0644,
1125 .proc_handler = proc_dointvec
1126 },
Eric Dumazet26e95962017-10-27 07:47:27 -07001127 {
1128 .procname = "tcp_min_tso_segs",
1129 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1130 .maxlen = sizeof(int),
1131 .mode = 0644,
1132 .proc_handler = proc_dointvec_minmax,
1133 .extra1 = &one,
1134 .extra2 = &gso_max_segs,
1135 },
Eric Dumazetbd239702017-10-27 07:47:28 -07001136 {
1137 .procname = "tcp_min_rtt_wlen",
1138 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1139 .maxlen = sizeof(int),
1140 .mode = 0644,
1141 .proc_handler = proc_dointvec
1142 },
Eric Dumazet790f00e2017-10-27 07:47:29 -07001143 {
1144 .procname = "tcp_autocorking",
1145 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1146 .maxlen = sizeof(int),
1147 .mode = 0644,
1148 .proc_handler = proc_dointvec_minmax,
1149 .extra1 = &zero,
1150 .extra2 = &one,
1151 },
Eric Dumazet4170ba62017-10-27 07:47:30 -07001152 {
1153 .procname = "tcp_invalid_ratelimit",
1154 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1155 .maxlen = sizeof(int),
1156 .mode = 0644,
1157 .proc_handler = proc_dointvec_ms_jiffies,
1158 },
Eric Dumazet23a7102a2017-10-27 07:47:31 -07001159 {
1160 .procname = "tcp_pacing_ss_ratio",
1161 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1162 .maxlen = sizeof(int),
1163 .mode = 0644,
1164 .proc_handler = proc_dointvec_minmax,
1165 .extra1 = &zero,
1166 .extra2 = &thousand,
1167 },
Eric Dumazetc26e91f2017-10-27 07:47:32 -07001168 {
1169 .procname = "tcp_pacing_ca_ratio",
1170 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1171 .maxlen = sizeof(int),
1172 .mode = 0644,
1173 .proc_handler = proc_dointvec_minmax,
1174 .extra1 = &zero,
1175 .extra2 = &thousand,
1176 },
Eric Dumazet356d1832017-11-07 00:29:28 -08001177 {
1178 .procname = "tcp_wmem",
1179 .data = &init_net.ipv4.sysctl_tcp_wmem,
1180 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1181 .mode = 0644,
1182 .proc_handler = proc_dointvec_minmax,
1183 .extra1 = &one,
1184 },
1185 {
1186 .procname = "tcp_rmem",
1187 .data = &init_net.ipv4.sysctl_tcp_rmem,
1188 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1189 .mode = 0644,
1190 .proc_handler = proc_dointvec_minmax,
1191 .extra1 = &one,
1192 },
Tonghao Zhang1e802952018-03-13 21:57:16 -07001193 {
Eric Dumazet6d82aa22018-05-17 14:47:28 -07001194 .procname = "tcp_comp_sack_delay_ns",
1195 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1196 .maxlen = sizeof(unsigned long),
1197 .mode = 0644,
1198 .proc_handler = proc_doulongvec_minmax,
1199 },
1200 {
Eric Dumazet9c21d2f2018-05-17 14:47:29 -07001201 .procname = "tcp_comp_sack_nr",
1202 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1203 .maxlen = sizeof(int),
1204 .mode = 0644,
1205 .proc_handler = proc_dointvec_minmax,
1206 .extra1 = &zero,
1207 .extra2 = &comp_sack_nr_max,
1208 },
1209 {
Tonghao Zhang1e802952018-03-13 21:57:16 -07001210 .procname = "udp_rmem_min",
1211 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1212 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1213 .mode = 0644,
1214 .proc_handler = proc_dointvec_minmax,
1215 .extra1 = &one
1216 },
1217 {
1218 .procname = "udp_wmem_min",
1219 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1220 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1221 .mode = 0644,
1222 .proc_handler = proc_dointvec_minmax,
1223 .extra1 = &one
1224 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001225 { }
1226};
1227
Pavel Emelyanov15775192008-03-26 01:54:18 -07001228static __net_init int ipv4_sysctl_init_net(struct net *net)
1229{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001230 struct ctl_table *table;
1231
1232 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001233 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001234 int i;
1235
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001236 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001237 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001238 goto err_alloc;
1239
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001240 /* Update the variables to point into the current struct net */
1241 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1242 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001243 }
1244
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001245 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001246 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001247 goto err_reg;
1248
WANG Cong122ff242014-05-12 16:04:53 -07001249 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1250 if (!net->ipv4.sysctl_local_reserved_ports)
1251 goto err_ports;
1252
Pavel Emelyanov15775192008-03-26 01:54:18 -07001253 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001254
WANG Cong122ff242014-05-12 16:04:53 -07001255err_ports:
1256 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001257err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001258 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001259 kfree(table);
1260err_alloc:
1261 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001262}
1263
1264static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1265{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001266 struct ctl_table *table;
1267
WANG Cong122ff242014-05-12 16:04:53 -07001268 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001269 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1270 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1271 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001272}
1273
1274static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1275 .init = ipv4_sysctl_init_net,
1276 .exit = ipv4_sysctl_exit_net,
1277};
1278
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001279static __init int sysctl_ipv4_init(void)
1280{
1281 struct ctl_table_header *hdr;
1282
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001283 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001284 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001285 return -ENOMEM;
1286
1287 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001288 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001289 return -ENOMEM;
1290 }
1291
1292 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001293}
1294
1295__initcall(sysctl_ipv4_init);