blob: af0a857d8352f2bc94d4f6baa0438a7ac9b2157b [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]);
192 if (!gid_valid(low) || !gid_valid(high) ||
193 (urange[1] < urange[0]) || gid_lt(high, low)) {
194 low = make_kgid(&init_user_ns, 1);
195 high = make_kgid(&init_user_ns, 0);
196 }
197 set_ping_group_range(table, low, high);
198 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000199
200 return ret;
201}
202
Joe Perchesfe2c6332013-06-11 23:04:25 -0700203static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700204 void __user *buffer, size_t *lenp, loff_t *ppos)
205{
Stephen Hemminger6670e152017-11-14 08:25:49 -0800206 struct net *net = container_of(ctl->data, struct net,
207 ipv4.tcp_congestion_control);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700208 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700209 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700210 .data = val,
211 .maxlen = TCP_CA_NAME_MAX,
212 };
213 int ret;
214
Stephen Hemminger6670e152017-11-14 08:25:49 -0800215 tcp_get_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700216
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700217 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700218 if (write && ret == 0)
Stephen Hemminger6670e152017-11-14 08:25:49 -0800219 ret = tcp_set_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700220 return ret;
221}
222
Joe Perchesfe2c6332013-06-11 23:04:25 -0700223static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700224 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800225 void __user *buffer, size_t *lenp,
226 loff_t *ppos)
227{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700228 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800229 int ret;
230
231 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
232 if (!tbl.data)
233 return -ENOMEM;
234 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700235 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800236 kfree(tbl.data);
237 return ret;
238}
239
Joe Perchesfe2c6332013-06-11 23:04:25 -0700240static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700241 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800242 void __user *buffer, size_t *lenp,
243 loff_t *ppos)
244{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700245 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800246 int ret;
247
248 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
249 if (!tbl.data)
250 return -ENOMEM;
251
252 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700253 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800254 if (write && ret == 0)
255 ret = tcp_set_allowed_congestion_control(tbl.data);
256 kfree(tbl.data);
257 return ret;
258}
259
Haishuang Yan43713842017-09-27 11:35:42 +0800260static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700261 void __user *buffer, size_t *lenp,
262 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000263{
Haishuang Yan43713842017-09-27 11:35:42 +0800264 struct net *net = container_of(table->data, struct net,
265 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700266 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000267 struct tcp_fastopen_context *ctxt;
Jerry Chu10467162012-08-31 12:29:11 +0000268 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
Yuchung Chengc860e992018-06-27 16:04:48 -0700269 __le32 key[4];
270 int ret, i;
Jerry Chu10467162012-08-31 12:29:11 +0000271
272 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
273 if (!tbl.data)
274 return -ENOMEM;
275
276 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800277 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000278 if (ctxt)
Yuchung Chengc860e992018-06-27 16:04:48 -0700279 memcpy(key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000280 else
Yuchung Chengc860e992018-06-27 16:04:48 -0700281 memset(key, 0, sizeof(key));
Jerry Chu10467162012-08-31 12:29:11 +0000282 rcu_read_unlock();
283
Yuchung Chengc860e992018-06-27 16:04:48 -0700284 for (i = 0; i < ARRAY_SIZE(key); i++)
285 user_key[i] = le32_to_cpu(key[i]);
286
Jerry Chu10467162012-08-31 12:29:11 +0000287 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
288 user_key[0], user_key[1], user_key[2], user_key[3]);
289 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
290
291 if (write && ret == 0) {
292 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
293 user_key + 2, user_key + 3) != 4) {
294 ret = -EINVAL;
295 goto bad_key;
296 }
Yuchung Chengc860e992018-06-27 16:04:48 -0700297
298 for (i = 0; i < ARRAY_SIZE(user_key); i++)
299 key[i] = cpu_to_le32(user_key[i]);
300
301 tcp_fastopen_reset_cipher(net, NULL, key,
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700302 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000303 }
304
305bad_key:
306 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
Yuchung Chengc860e992018-06-27 16:04:48 -0700307 user_key[0], user_key[1], user_key[2], user_key[3],
Jerry Chu10467162012-08-31 12:29:11 +0000308 (char *)tbl.data, ret);
309 kfree(tbl.data);
310 return ret;
311}
312
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600313static void proc_configure_early_demux(int enabled, int protocol)
314{
315 struct net_protocol *ipprot;
316#if IS_ENABLED(CONFIG_IPV6)
317 struct inet6_protocol *ip6prot;
318#endif
319
David Ahern58c4c6a2017-04-22 09:33:16 -0700320 rcu_read_lock();
321
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600322 ipprot = rcu_dereference(inet_protos[protocol]);
323 if (ipprot)
324 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
325 NULL;
326
327#if IS_ENABLED(CONFIG_IPV6)
328 ip6prot = rcu_dereference(inet6_protos[protocol]);
329 if (ip6prot)
330 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
331 NULL;
332#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700333 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600334}
335
336static int proc_tcp_early_demux(struct ctl_table *table, int write,
337 void __user *buffer, size_t *lenp, loff_t *ppos)
338{
339 int ret = 0;
340
341 ret = proc_dointvec(table, write, buffer, lenp, ppos);
342
343 if (write && !ret) {
344 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
345
346 proc_configure_early_demux(enabled, IPPROTO_TCP);
347 }
348
349 return ret;
350}
351
352static int proc_udp_early_demux(struct ctl_table *table, int write,
353 void __user *buffer, size_t *lenp, loff_t *ppos)
354{
355 int ret = 0;
356
357 ret = proc_dointvec(table, write, buffer, lenp, ppos);
358
359 if (write && !ret) {
360 int enabled = init_net.ipv4.sysctl_udp_early_demux;
361
362 proc_configure_early_demux(enabled, IPPROTO_UDP);
363 }
364
365 return ret;
366}
367
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700368static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
369 int write,
370 void __user *buffer,
371 size_t *lenp, loff_t *ppos)
372{
Haishuang Yan3733be12017-09-27 11:35:43 +0800373 struct net *net = container_of(table->data, struct net,
374 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700375 int ret;
376
377 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
378 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800379 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700380
381 return ret;
382}
383
384static int proc_tcp_available_ulp(struct ctl_table *ctl,
385 int write,
386 void __user *buffer, size_t *lenp,
387 loff_t *ppos)
388{
389 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
390 int ret;
391
392 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
393 if (!tbl.data)
394 return -ENOMEM;
395 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
396 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
397 kfree(tbl.data);
398
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700399 return ret;
400}
401
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100402#ifdef CONFIG_IP_ROUTE_MULTIPATH
403static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
404 void __user *buffer, size_t *lenp,
405 loff_t *ppos)
406{
407 struct net *net = container_of(table->data, struct net,
408 ipv4.sysctl_fib_multipath_hash_policy);
409 int ret;
410
411 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
412 if (write && ret == 0)
David Ahern3192dac2018-03-02 08:32:16 -0800413 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100414
415 return ret;
416}
417#endif
418
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800419static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .procname = "tcp_max_orphans",
422 .data = &sysctl_tcp_max_orphans,
423 .maxlen = sizeof(int),
424 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800425 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 },
427 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 .procname = "inet_peer_threshold",
429 .data = &inet_peer_threshold,
430 .maxlen = sizeof(int),
431 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800432 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 },
434 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 .procname = "inet_peer_minttl",
436 .data = &inet_peer_minttl,
437 .maxlen = sizeof(int),
438 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800439 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 },
441 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 .procname = "inet_peer_maxttl",
443 .data = &inet_peer_maxttl,
444 .maxlen = sizeof(int),
445 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800446 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 },
448 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700449 .procname = "tcp_mem",
450 .maxlen = sizeof(sysctl_tcp_mem),
451 .data = &sysctl_tcp_mem,
452 .mode = 0644,
453 .proc_handler = proc_doulongvec_minmax,
454 },
455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 .procname = "tcp_low_latency",
457 .data = &sysctl_tcp_low_latency,
458 .maxlen = sizeof(int),
459 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800460 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 },
Paul Moore446fda42006-08-03 16:48:06 -0700462#ifdef CONFIG_NETLABEL
463 {
Paul Moore446fda42006-08-03 16:48:06 -0700464 .procname = "cipso_cache_enable",
465 .data = &cipso_v4_cache_enabled,
466 .maxlen = sizeof(int),
467 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800468 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700469 },
470 {
Paul Moore446fda42006-08-03 16:48:06 -0700471 .procname = "cipso_cache_bucket_size",
472 .data = &cipso_v4_cache_bucketsize,
473 .maxlen = sizeof(int),
474 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800475 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700476 },
477 {
Paul Moore446fda42006-08-03 16:48:06 -0700478 .procname = "cipso_rbm_optfmt",
479 .data = &cipso_v4_rbm_optfmt,
480 .maxlen = sizeof(int),
481 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800482 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700483 },
484 {
Paul Moore446fda42006-08-03 16:48:06 -0700485 .procname = "cipso_rbm_strictvalid",
486 .data = &cipso_v4_rbm_strictvalid,
487 .maxlen = sizeof(int),
488 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800489 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700490 },
491#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800492 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800493 .procname = "tcp_available_congestion_control",
494 .maxlen = TCP_CA_BUF_MAX,
495 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800496 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800497 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800498 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800499 .procname = "tcp_allowed_congestion_control",
500 .maxlen = TCP_CA_BUF_MAX,
501 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800502 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800503 },
John Heffner886236c2007-03-25 19:21:45 -0700504 {
Dave Watson734942c2017-06-14 11:37:14 -0700505 .procname = "tcp_available_ulp",
506 .maxlen = TCP_ULP_BUF_MAX,
507 .mode = 0444,
508 .proc_handler = proc_tcp_available_ulp,
509 },
510 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700511 .procname = "icmp_msgs_per_sec",
512 .data = &sysctl_icmp_msgs_per_sec,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = proc_dointvec_minmax,
516 .extra1 = &zero,
517 },
518 {
519 .procname = "icmp_msgs_burst",
520 .data = &sysctl_icmp_msgs_burst,
521 .maxlen = sizeof(int),
522 .mode = 0644,
523 .proc_handler = proc_dointvec_minmax,
524 .extra1 = &zero,
525 },
526 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800527 .procname = "udp_mem",
528 .data = &sysctl_udp_mem,
529 .maxlen = sizeof(sysctl_udp_mem),
530 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000531 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800532 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800533 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800535
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700536static struct ctl_table ipv4_net_table[] = {
537 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700538 .procname = "icmp_echo_ignore_all",
539 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
540 .maxlen = sizeof(int),
541 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800542 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700543 },
544 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700545 .procname = "icmp_echo_ignore_broadcasts",
546 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
547 .maxlen = sizeof(int),
548 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800549 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700550 },
551 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700552 .procname = "icmp_ignore_bogus_error_responses",
553 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
554 .maxlen = sizeof(int),
555 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800556 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700557 },
558 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700559 .procname = "icmp_errors_use_inbound_ifaddr",
560 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
561 .maxlen = sizeof(int),
562 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800563 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700564 },
565 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700566 .procname = "icmp_ratelimit",
567 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
568 .maxlen = sizeof(int),
569 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800570 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700571 },
572 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700573 .procname = "icmp_ratemask",
574 .data = &init_net.ipv4.sysctl_icmp_ratemask,
575 .maxlen = sizeof(int),
576 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800577 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700578 },
Neil Horman1080d702008-10-27 12:28:25 -0700579 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000580 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700581 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600582 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000583 .mode = 0644,
584 .proc_handler = ipv4_ping_group_range,
585 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000586 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000587 .procname = "tcp_ecn",
588 .data = &init_net.ipv4.sysctl_tcp_ecn,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec
592 },
593 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200594 .procname = "tcp_ecn_fallback",
595 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = proc_dointvec
599 },
600 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200601 .procname = "ip_dynaddr",
602 .data = &init_net.ipv4.sysctl_ip_dynaddr,
603 .maxlen = sizeof(int),
604 .mode = 0644,
605 .proc_handler = proc_dointvec
606 },
607 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200608 .procname = "ip_early_demux",
609 .data = &init_net.ipv4.sysctl_ip_early_demux,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = proc_dointvec
613 },
614 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600615 .procname = "udp_early_demux",
616 .data = &init_net.ipv4.sysctl_udp_early_demux,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = proc_udp_early_demux
620 },
621 {
622 .procname = "tcp_early_demux",
623 .data = &init_net.ipv4.sysctl_tcp_early_demux,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = proc_tcp_early_demux
627 },
628 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200629 .procname = "ip_default_ttl",
630 .data = &init_net.ipv4.sysctl_ip_default_ttl,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = proc_dointvec_minmax,
634 .extra1 = &ip_ttl_min,
635 .extra2 = &ip_ttl_max,
636 },
637 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700638 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700639 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
640 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700641 .mode = 0644,
642 .proc_handler = ipv4_local_port_range,
643 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100644 {
WANG Cong122ff242014-05-12 16:04:53 -0700645 .procname = "ip_local_reserved_ports",
646 .data = &init_net.ipv4.sysctl_local_reserved_ports,
647 .maxlen = 65536,
648 .mode = 0644,
649 .proc_handler = proc_do_large_bitmap,
650 },
651 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100652 .procname = "ip_no_pmtu_disc",
653 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
654 .maxlen = sizeof(int),
655 .mode = 0644,
656 .proc_handler = proc_dointvec
657 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100658 {
659 .procname = "ip_forward_use_pmtu",
660 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
661 .maxlen = sizeof(int),
662 .mode = 0644,
663 .proc_handler = proc_dointvec,
664 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700665 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200666 .procname = "ip_nonlocal_bind",
667 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = proc_dointvec
671 },
672 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700673 .procname = "fwmark_reflect",
674 .data = &init_net.ipv4.sysctl_fwmark_reflect,
675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = proc_dointvec,
678 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700679 {
680 .procname = "tcp_fwmark_accept",
681 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = proc_dointvec,
685 },
David Ahern6dd9a142015-12-16 13:20:44 -0800686#ifdef CONFIG_NET_L3_MASTER_DEV
687 {
688 .procname = "tcp_l3mdev_accept",
689 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = proc_dointvec_minmax,
693 .extra1 = &zero,
694 .extra2 = &one,
695 },
696#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800697 {
698 .procname = "tcp_mtu_probing",
699 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = proc_dointvec,
703 },
704 {
705 .procname = "tcp_base_mss",
706 .data = &init_net.ipv4.sysctl_tcp_base_mss,
707 .maxlen = sizeof(int),
708 .mode = 0644,
709 .proc_handler = proc_dointvec,
710 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800711 {
712 .procname = "tcp_probe_threshold",
713 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = proc_dointvec,
717 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800718 {
719 .procname = "tcp_probe_interval",
720 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = proc_dointvec,
724 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100725 {
726 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200727 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100728 .maxlen = sizeof(int),
729 .mode = 0644,
730 .proc_handler = proc_dointvec
731 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200732 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200733 .procname = "igmp_max_memberships",
734 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = proc_dointvec
738 },
739 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200740 .procname = "igmp_max_msf",
741 .data = &init_net.ipv4.sysctl_igmp_max_msf,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dointvec
745 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200746#ifdef CONFIG_IP_MULTICAST
747 {
748 .procname = "igmp_qrv",
749 .data = &init_net.ipv4.sysctl_igmp_qrv,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = proc_dointvec_minmax,
753 .extra1 = &one
754 },
755#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200756 {
Stephen Hemminger6670e152017-11-14 08:25:49 -0800757 .procname = "tcp_congestion_control",
758 .data = &init_net.ipv4.tcp_congestion_control,
759 .mode = 0644,
760 .maxlen = TCP_CA_NAME_MAX,
761 .proc_handler = proc_tcp_congestion_control,
762 },
763 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200764 .procname = "tcp_keepalive_time",
765 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = proc_dointvec_jiffies,
769 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200770 {
771 .procname = "tcp_keepalive_probes",
772 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
773 .maxlen = sizeof(int),
774 .mode = 0644,
775 .proc_handler = proc_dointvec
776 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200777 {
778 .procname = "tcp_keepalive_intvl",
779 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
780 .maxlen = sizeof(int),
781 .mode = 0644,
782 .proc_handler = proc_dointvec_jiffies,
783 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200784 {
785 .procname = "tcp_syn_retries",
786 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = proc_dointvec_minmax,
790 .extra1 = &tcp_syn_retries_min,
791 .extra2 = &tcp_syn_retries_max
792 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200793 {
794 .procname = "tcp_synack_retries",
795 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
796 .maxlen = sizeof(int),
797 .mode = 0644,
798 .proc_handler = proc_dointvec
799 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200800#ifdef CONFIG_SYN_COOKIES
801 {
802 .procname = "tcp_syncookies",
803 .data = &init_net.ipv4.sysctl_tcp_syncookies,
804 .maxlen = sizeof(int),
805 .mode = 0644,
806 .proc_handler = proc_dointvec
807 },
808#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200809 {
810 .procname = "tcp_reordering",
811 .data = &init_net.ipv4.sysctl_tcp_reordering,
812 .maxlen = sizeof(int),
813 .mode = 0644,
814 .proc_handler = proc_dointvec
815 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200816 {
817 .procname = "tcp_retries1",
818 .data = &init_net.ipv4.sysctl_tcp_retries1,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = proc_dointvec_minmax,
822 .extra2 = &tcp_retr1_max
823 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +0200824 {
825 .procname = "tcp_retries2",
826 .data = &init_net.ipv4.sysctl_tcp_retries2,
827 .maxlen = sizeof(int),
828 .mode = 0644,
829 .proc_handler = proc_dointvec
830 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +0200831 {
832 .procname = "tcp_orphan_retries",
833 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
834 .maxlen = sizeof(int),
835 .mode = 0644,
836 .proc_handler = proc_dointvec
837 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +0200838 {
839 .procname = "tcp_fin_timeout",
840 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
841 .maxlen = sizeof(int),
842 .mode = 0644,
843 .proc_handler = proc_dointvec_jiffies,
844 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200845 {
846 .procname = "tcp_notsent_lowat",
847 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
848 .maxlen = sizeof(unsigned int),
849 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +0300850 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200851 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800852 {
853 .procname = "tcp_tw_reuse",
854 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
855 .maxlen = sizeof(int),
856 .mode = 0644,
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -0700857 .proc_handler = proc_dointvec_minmax,
858 .extra1 = &zero,
859 .extra2 = &two,
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800860 },
Haishuang Yan1946e672016-12-28 17:52:32 +0800861 {
862 .procname = "tcp_max_tw_buckets",
863 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
864 .maxlen = sizeof(int),
865 .mode = 0644,
866 .proc_handler = proc_dointvec
867 },
868 {
Haishuang Yanfee83d02016-12-28 17:52:33 +0800869 .procname = "tcp_max_syn_backlog",
870 .data = &init_net.ipv4.sysctl_max_syn_backlog,
871 .maxlen = sizeof(int),
872 .mode = 0644,
873 .proc_handler = proc_dointvec
874 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +0800875 {
876 .procname = "tcp_fastopen",
877 .data = &init_net.ipv4.sysctl_tcp_fastopen,
878 .maxlen = sizeof(int),
879 .mode = 0644,
880 .proc_handler = proc_dointvec,
881 },
Haishuang Yan43713842017-09-27 11:35:42 +0800882 {
883 .procname = "tcp_fastopen_key",
884 .mode = 0600,
885 .data = &init_net.ipv4.sysctl_tcp_fastopen,
886 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
887 .proc_handler = proc_tcp_fastopen_key,
888 },
Haishuang Yan3733be12017-09-27 11:35:43 +0800889 {
890 .procname = "tcp_fastopen_blackhole_timeout_sec",
891 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
892 .maxlen = sizeof(int),
893 .mode = 0644,
894 .proc_handler = proc_tfo_blackhole_detect_timeout,
895 .extra1 = &zero,
896 },
David Aherna6db4492016-04-07 07:21:00 -0700897#ifdef CONFIG_IP_ROUTE_MULTIPATH
898 {
899 .procname = "fib_multipath_use_neigh",
900 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = proc_dointvec_minmax,
904 .extra1 = &zero,
905 .extra2 = &one,
906 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200907 {
908 .procname = "fib_multipath_hash_policy",
909 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
910 .maxlen = sizeof(int),
911 .mode = 0644,
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100912 .proc_handler = proc_fib_multipath_hash_policy,
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200913 .extra1 = &zero,
914 .extra2 = &one,
915 },
David Aherna6db4492016-04-07 07:21:00 -0700916#endif
Krister Johansen4548b682017-01-20 17:49:11 -0800917 {
918 .procname = "ip_unprivileged_port_start",
919 .maxlen = sizeof(int),
920 .data = &init_net.ipv4.sysctl_ip_prot_sock,
921 .mode = 0644,
922 .proc_handler = ipv4_privileged_ports,
923 },
Robert Shearman63a6fff2017-01-26 18:02:24 +0000924#ifdef CONFIG_NET_L3_MASTER_DEV
925 {
926 .procname = "udp_l3mdev_accept",
927 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec_minmax,
931 .extra1 = &zero,
932 .extra2 = &one,
933 },
934#endif
Eric Dumazetf9301032017-06-07 10:34:37 -0700935 {
936 .procname = "tcp_sack",
937 .data = &init_net.ipv4.sysctl_tcp_sack,
938 .maxlen = sizeof(int),
939 .mode = 0644,
940 .proc_handler = proc_dointvec
941 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -0700942 {
943 .procname = "tcp_window_scaling",
944 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
945 .maxlen = sizeof(int),
946 .mode = 0644,
947 .proc_handler = proc_dointvec
948 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -0700949 {
950 .procname = "tcp_timestamps",
951 .data = &init_net.ipv4.sysctl_tcp_timestamps,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec
955 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -0700956 {
957 .procname = "tcp_early_retrans",
958 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
959 .maxlen = sizeof(int),
960 .mode = 0644,
961 .proc_handler = proc_dointvec_minmax,
962 .extra1 = &zero,
963 .extra2 = &four,
964 },
Eric Dumazete20223f2017-10-26 21:54:57 -0700965 {
966 .procname = "tcp_recovery",
967 .data = &init_net.ipv4.sysctl_tcp_recovery,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = proc_dointvec,
971 },
Eric Dumazet2c04ac82017-10-26 21:54:58 -0700972 {
973 .procname = "tcp_thin_linear_timeouts",
974 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
975 .maxlen = sizeof(int),
976 .mode = 0644,
977 .proc_handler = proc_dointvec
978 },
Eric Dumazetb510f0d2017-10-26 21:54:59 -0700979 {
980 .procname = "tcp_slow_start_after_idle",
981 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = proc_dointvec
985 },
Eric Dumazete0a1e5b2017-10-26 21:55:00 -0700986 {
987 .procname = "tcp_retrans_collapse",
988 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = proc_dointvec
992 },
Eric Dumazet3f4c7c62017-10-26 21:55:01 -0700993 {
994 .procname = "tcp_stdurg",
995 .data = &init_net.ipv4.sysctl_tcp_stdurg,
996 .maxlen = sizeof(int),
997 .mode = 0644,
998 .proc_handler = proc_dointvec
999 },
Eric Dumazet625357a2017-10-26 21:55:02 -07001000 {
1001 .procname = "tcp_rfc1337",
1002 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1003 .maxlen = sizeof(int),
1004 .mode = 0644,
1005 .proc_handler = proc_dointvec
1006 },
Eric Dumazet65c94102017-10-26 21:55:03 -07001007 {
1008 .procname = "tcp_abort_on_overflow",
1009 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1010 .maxlen = sizeof(int),
1011 .mode = 0644,
1012 .proc_handler = proc_dointvec
1013 },
Eric Dumazet0bc65a22017-10-26 21:55:04 -07001014 {
1015 .procname = "tcp_fack",
1016 .data = &init_net.ipv4.sysctl_tcp_fack,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
1019 .proc_handler = proc_dointvec
1020 },
Eric Dumazetc6e21802017-10-26 21:55:06 -07001021 {
1022 .procname = "tcp_max_reordering",
1023 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1024 .maxlen = sizeof(int),
1025 .mode = 0644,
1026 .proc_handler = proc_dointvec
1027 },
Eric Dumazet6496f6b2017-10-26 21:55:07 -07001028 {
1029 .procname = "tcp_dsack",
1030 .data = &init_net.ipv4.sysctl_tcp_dsack,
1031 .maxlen = sizeof(int),
1032 .mode = 0644,
1033 .proc_handler = proc_dointvec
1034 },
Eric Dumazet0c126542017-10-26 21:55:08 -07001035 {
1036 .procname = "tcp_app_win",
1037 .data = &init_net.ipv4.sysctl_tcp_app_win,
1038 .maxlen = sizeof(int),
1039 .mode = 0644,
1040 .proc_handler = proc_dointvec
1041 },
Eric Dumazet94f08932017-10-26 21:55:09 -07001042 {
1043 .procname = "tcp_adv_win_scale",
1044 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1045 .maxlen = sizeof(int),
1046 .mode = 0644,
1047 .proc_handler = proc_dointvec_minmax,
1048 .extra1 = &tcp_adv_win_scale_min,
1049 .extra2 = &tcp_adv_win_scale_max,
1050 },
Eric Dumazetaf9b69a2017-10-26 21:55:10 -07001051 {
1052 .procname = "tcp_frto",
1053 .data = &init_net.ipv4.sysctl_tcp_frto,
1054 .maxlen = sizeof(int),
1055 .mode = 0644,
1056 .proc_handler = proc_dointvec
1057 },
Eric Dumazetec36e412017-10-27 07:47:21 -07001058 {
1059 .procname = "tcp_no_metrics_save",
1060 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1061 .maxlen = sizeof(int),
1062 .mode = 0644,
1063 .proc_handler = proc_dointvec,
1064 },
Eric Dumazet4540c0c2017-10-27 07:47:22 -07001065 {
1066 .procname = "tcp_moderate_rcvbuf",
1067 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
1070 .proc_handler = proc_dointvec,
1071 },
Eric Dumazetd06a9902017-10-27 07:47:23 -07001072 {
1073 .procname = "tcp_tso_win_divisor",
1074 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1075 .maxlen = sizeof(int),
1076 .mode = 0644,
1077 .proc_handler = proc_dointvec,
1078 },
Eric Dumazetceef9ab2017-10-27 07:47:24 -07001079 {
1080 .procname = "tcp_workaround_signed_windows",
1081 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1082 .maxlen = sizeof(int),
1083 .mode = 0644,
1084 .proc_handler = proc_dointvec
1085 },
Eric Dumazet9184d8b2017-10-27 07:47:25 -07001086 {
1087 .procname = "tcp_limit_output_bytes",
1088 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1089 .maxlen = sizeof(int),
1090 .mode = 0644,
1091 .proc_handler = proc_dointvec
1092 },
Eric Dumazetb530b682017-10-27 07:47:26 -07001093 {
1094 .procname = "tcp_challenge_ack_limit",
1095 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
1098 .proc_handler = proc_dointvec
1099 },
Eric Dumazet26e95962017-10-27 07:47:27 -07001100 {
1101 .procname = "tcp_min_tso_segs",
1102 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1103 .maxlen = sizeof(int),
1104 .mode = 0644,
1105 .proc_handler = proc_dointvec_minmax,
1106 .extra1 = &one,
1107 .extra2 = &gso_max_segs,
1108 },
Eric Dumazetbd239702017-10-27 07:47:28 -07001109 {
1110 .procname = "tcp_min_rtt_wlen",
1111 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1112 .maxlen = sizeof(int),
1113 .mode = 0644,
1114 .proc_handler = proc_dointvec
1115 },
Eric Dumazet790f00e2017-10-27 07:47:29 -07001116 {
1117 .procname = "tcp_autocorking",
1118 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1119 .maxlen = sizeof(int),
1120 .mode = 0644,
1121 .proc_handler = proc_dointvec_minmax,
1122 .extra1 = &zero,
1123 .extra2 = &one,
1124 },
Eric Dumazet4170ba62017-10-27 07:47:30 -07001125 {
1126 .procname = "tcp_invalid_ratelimit",
1127 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1128 .maxlen = sizeof(int),
1129 .mode = 0644,
1130 .proc_handler = proc_dointvec_ms_jiffies,
1131 },
Eric Dumazet23a7102a2017-10-27 07:47:31 -07001132 {
1133 .procname = "tcp_pacing_ss_ratio",
1134 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = proc_dointvec_minmax,
1138 .extra1 = &zero,
1139 .extra2 = &thousand,
1140 },
Eric Dumazetc26e91f2017-10-27 07:47:32 -07001141 {
1142 .procname = "tcp_pacing_ca_ratio",
1143 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = proc_dointvec_minmax,
1147 .extra1 = &zero,
1148 .extra2 = &thousand,
1149 },
Eric Dumazet356d1832017-11-07 00:29:28 -08001150 {
1151 .procname = "tcp_wmem",
1152 .data = &init_net.ipv4.sysctl_tcp_wmem,
1153 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1154 .mode = 0644,
1155 .proc_handler = proc_dointvec_minmax,
1156 .extra1 = &one,
1157 },
1158 {
1159 .procname = "tcp_rmem",
1160 .data = &init_net.ipv4.sysctl_tcp_rmem,
1161 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1162 .mode = 0644,
1163 .proc_handler = proc_dointvec_minmax,
1164 .extra1 = &one,
1165 },
Tonghao Zhang1e802952018-03-13 21:57:16 -07001166 {
Eric Dumazet6d82aa22018-05-17 14:47:28 -07001167 .procname = "tcp_comp_sack_delay_ns",
1168 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1169 .maxlen = sizeof(unsigned long),
1170 .mode = 0644,
1171 .proc_handler = proc_doulongvec_minmax,
1172 },
1173 {
Eric Dumazet9c21d2f2018-05-17 14:47:29 -07001174 .procname = "tcp_comp_sack_nr",
1175 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1176 .maxlen = sizeof(int),
1177 .mode = 0644,
1178 .proc_handler = proc_dointvec_minmax,
1179 .extra1 = &zero,
1180 .extra2 = &comp_sack_nr_max,
1181 },
1182 {
Tonghao Zhang1e802952018-03-13 21:57:16 -07001183 .procname = "udp_rmem_min",
1184 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1185 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1186 .mode = 0644,
1187 .proc_handler = proc_dointvec_minmax,
1188 .extra1 = &one
1189 },
1190 {
1191 .procname = "udp_wmem_min",
1192 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1193 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1194 .mode = 0644,
1195 .proc_handler = proc_dointvec_minmax,
1196 .extra1 = &one
1197 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001198 { }
1199};
1200
Pavel Emelyanov15775192008-03-26 01:54:18 -07001201static __net_init int ipv4_sysctl_init_net(struct net *net)
1202{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001203 struct ctl_table *table;
1204
1205 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001206 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001207 int i;
1208
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001209 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001210 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001211 goto err_alloc;
1212
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001213 /* Update the variables to point into the current struct net */
1214 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1215 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001216 }
1217
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001218 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001219 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001220 goto err_reg;
1221
WANG Cong122ff242014-05-12 16:04:53 -07001222 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1223 if (!net->ipv4.sysctl_local_reserved_ports)
1224 goto err_ports;
1225
Pavel Emelyanov15775192008-03-26 01:54:18 -07001226 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001227
WANG Cong122ff242014-05-12 16:04:53 -07001228err_ports:
1229 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001230err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001231 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001232 kfree(table);
1233err_alloc:
1234 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001235}
1236
1237static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1238{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001239 struct ctl_table *table;
1240
WANG Cong122ff242014-05-12 16:04:53 -07001241 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001242 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1243 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1244 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001245}
1246
1247static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1248 .init = ipv4_sysctl_init_net,
1249 .exit = ipv4_sysctl_exit_net,
1250};
1251
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001252static __init int sysctl_ipv4_init(void)
1253{
1254 struct ctl_table_header *hdr;
1255
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001256 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001257 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001258 return -ENOMEM;
1259
1260 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001261 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001262 return -ENOMEM;
1263 }
1264
1265 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001266}
1267
1268__initcall(sysctl_ipv4_init);