blob: d2eed3ddcb0a1ad9778d96d46c685f6c60b93d8d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
7 */
8
9#include <linux/mm.h>
10#include <linux/module.h>
11#include <linux/sysctl.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030012#include <linux/igmp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020013#include <linux/inetdevice.h>
Stephen Hemminger227b60f2007-10-10 17:30:46 -070014#include <linux/seqlock.h>
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -080015#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000017#include <linux/nsproxy.h>
Glauber Costa3dc43e32011-12-11 21:47:05 +000018#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030020#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <net/ip.h>
22#include <net/route.h>
23#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080024#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070025#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070026#include <net/inet_frag.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000027#include <net/ping.h>
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060028#include <net/protocol.h>
Ido Schimmel3ae6ec02017-11-02 17:14:05 +010029#include <net/netevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Herbert Xu89cee8b2005-12-13 23:14:27 -080031static int zero;
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +000032static int one = 1;
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +000033static int four = 4;
Eric Dumazet43e122b2015-08-21 17:38:02 -070034static int thousand = 1000;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070035static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090036static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static int ip_local_port_range_min[] = { 1, 1 };
38static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000039static int tcp_adv_win_scale_min = -31;
40static int tcp_adv_win_scale_max = 31;
Krister Johansen4548b682017-01-20 17:49:11 -080041static int ip_privileged_port_min;
42static int ip_privileged_port_max = 65535;
Eric Dumazet249fab72010-12-13 12:16:14 -080043static int ip_ttl_min = 1;
44static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020045static int tcp_syn_retries_min = 1;
46static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000047static int ip_ping_group_range_min[] = { 0, 0 };
48static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Eric Dumazet9c21d2f2018-05-17 14:47:29 -070049static int comp_sack_nr_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Florian Westphalb6690b12017-07-30 03:57:20 +020051/* obsolete */
52static int sysctl_tcp_low_latency __read_mostly;
53
Stephen Hemminger227b60f2007-10-10 17:30:46 -070054/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070055static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070056{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070057 bool same_parity = !((range[0] ^ range[1]) & 1);
58
WANG Cong4ee3bd42015-11-03 14:32:57 -080059 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070060 if (same_parity && !net->ipv4.ip_local_ports.warned) {
61 net->ipv4.ip_local_ports.warned = true;
62 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
63 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070064 net->ipv4.ip_local_ports.range[0] = range[0];
65 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080066 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070067}
68
69/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070070static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070071 void __user *buffer,
72 size_t *lenp, loff_t *ppos)
73{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070074 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070075 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070076 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070077 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070078 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070079 .data = &range,
80 .maxlen = sizeof(range),
81 .mode = table->mode,
82 .extra1 = &ip_local_port_range_min,
83 .extra2 = &ip_local_port_range_max,
84 };
85
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070086 inet_get_local_port_range(net, &range[0], &range[1]);
87
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070088 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070089
90 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080091 /* Ensure that the upper limit is not smaller than the lower,
92 * and that the lower does not encroach upon the privileged
93 * port limit.
94 */
95 if ((range[1] < range[0]) ||
96 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -070097 ret = -EINVAL;
98 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070099 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -0700100 }
101
102 return ret;
103}
104
Krister Johansen4548b682017-01-20 17:49:11 -0800105/* Validate changes from /proc interface. */
106static int ipv4_privileged_ports(struct ctl_table *table, int write,
107 void __user *buffer, size_t *lenp, loff_t *ppos)
108{
109 struct net *net = container_of(table->data, struct net,
110 ipv4.sysctl_ip_prot_sock);
111 int ret;
112 int pports;
113 int range[2];
114 struct ctl_table tmp = {
115 .data = &pports,
116 .maxlen = sizeof(pports),
117 .mode = table->mode,
118 .extra1 = &ip_privileged_port_min,
119 .extra2 = &ip_privileged_port_max,
120 };
121
122 pports = net->ipv4.sysctl_ip_prot_sock;
123
124 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
125
126 if (write && ret == 0) {
127 inet_get_local_port_range(net, &range[0], &range[1]);
128 /* Ensure that the local port range doesn't overlap with the
129 * privileged port range.
130 */
131 if (range[0] < pports)
132 ret = -EINVAL;
133 else
134 net->ipv4.sysctl_ip_prot_sock = pports;
135 }
136
137 return ret;
138}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000139
Eric W. Biederman7064d162012-05-24 10:34:21 -0600140static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000141{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600142 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700143 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700144 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000145 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000146 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700147 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000148
149 *low = data[0];
150 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700151 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000152}
153
154/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600155static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000156{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600157 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700158 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700159 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700160 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600161 data[0] = low;
162 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700163 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000164}
165
166/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700167static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000168 void __user *buffer,
169 size_t *lenp, loff_t *ppos)
170{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600171 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000172 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600173 gid_t urange[2];
174 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700175 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600176 .data = &urange,
177 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000178 .mode = table->mode,
179 .extra1 = &ip_ping_group_range_min,
180 .extra2 = &ip_ping_group_range_max,
181 };
182
Eric W. Biederman7064d162012-05-24 10:34:21 -0600183 inet_get_ping_group_range_table(table, &low, &high);
184 urange[0] = from_kgid_munged(user_ns, low);
185 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000186 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
187
Eric W. Biederman7064d162012-05-24 10:34:21 -0600188 if (write && ret == 0) {
189 low = make_kgid(user_ns, urange[0]);
190 high = make_kgid(user_ns, urange[1]);
191 if (!gid_valid(low) || !gid_valid(high) ||
192 (urange[1] < urange[0]) || gid_lt(high, low)) {
193 low = make_kgid(&init_user_ns, 1);
194 high = make_kgid(&init_user_ns, 0);
195 }
196 set_ping_group_range(table, low, high);
197 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000198
199 return ret;
200}
201
Joe Perchesfe2c6332013-06-11 23:04:25 -0700202static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700203 void __user *buffer, size_t *lenp, loff_t *ppos)
204{
Stephen Hemminger6670e152017-11-14 08:25:49 -0800205 struct net *net = container_of(ctl->data, struct net,
206 ipv4.tcp_congestion_control);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700207 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700208 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700209 .data = val,
210 .maxlen = TCP_CA_NAME_MAX,
211 };
212 int ret;
213
Stephen Hemminger6670e152017-11-14 08:25:49 -0800214 tcp_get_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700215
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700216 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700217 if (write && ret == 0)
Stephen Hemminger6670e152017-11-14 08:25:49 -0800218 ret = tcp_set_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700219 return ret;
220}
221
Joe Perchesfe2c6332013-06-11 23:04:25 -0700222static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700223 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800224 void __user *buffer, size_t *lenp,
225 loff_t *ppos)
226{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700227 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800228 int ret;
229
230 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
231 if (!tbl.data)
232 return -ENOMEM;
233 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700234 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800235 kfree(tbl.data);
236 return ret;
237}
238
Joe Perchesfe2c6332013-06-11 23:04:25 -0700239static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700240 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800241 void __user *buffer, size_t *lenp,
242 loff_t *ppos)
243{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700244 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800245 int ret;
246
247 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
248 if (!tbl.data)
249 return -ENOMEM;
250
251 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700252 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800253 if (write && ret == 0)
254 ret = tcp_set_allowed_congestion_control(tbl.data);
255 kfree(tbl.data);
256 return ret;
257}
258
Haishuang Yan43713842017-09-27 11:35:42 +0800259static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700260 void __user *buffer, size_t *lenp,
261 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000262{
Haishuang Yan43713842017-09-27 11:35:42 +0800263 struct net *net = container_of(table->data, struct net,
264 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700265 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000266 struct tcp_fastopen_context *ctxt;
267 int ret;
268 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
269
270 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
271 if (!tbl.data)
272 return -ENOMEM;
273
274 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800275 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000276 if (ctxt)
277 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000278 else
279 memset(user_key, 0, sizeof(user_key));
Jerry Chu10467162012-08-31 12:29:11 +0000280 rcu_read_unlock();
281
282 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
283 user_key[0], user_key[1], user_key[2], user_key[3]);
284 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
285
286 if (write && ret == 0) {
287 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
288 user_key + 2, user_key + 3) != 4) {
289 ret = -EINVAL;
290 goto bad_key;
291 }
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700292 tcp_fastopen_reset_cipher(net, NULL, user_key,
293 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000294 }
295
296bad_key:
297 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
298 user_key[0], user_key[1], user_key[2], user_key[3],
299 (char *)tbl.data, ret);
300 kfree(tbl.data);
301 return ret;
302}
303
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600304static void proc_configure_early_demux(int enabled, int protocol)
305{
306 struct net_protocol *ipprot;
307#if IS_ENABLED(CONFIG_IPV6)
308 struct inet6_protocol *ip6prot;
309#endif
310
David Ahern58c4c6a2017-04-22 09:33:16 -0700311 rcu_read_lock();
312
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600313 ipprot = rcu_dereference(inet_protos[protocol]);
314 if (ipprot)
315 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
316 NULL;
317
318#if IS_ENABLED(CONFIG_IPV6)
319 ip6prot = rcu_dereference(inet6_protos[protocol]);
320 if (ip6prot)
321 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
322 NULL;
323#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700324 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600325}
326
327static int proc_tcp_early_demux(struct ctl_table *table, int write,
328 void __user *buffer, size_t *lenp, loff_t *ppos)
329{
330 int ret = 0;
331
332 ret = proc_dointvec(table, write, buffer, lenp, ppos);
333
334 if (write && !ret) {
335 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
336
337 proc_configure_early_demux(enabled, IPPROTO_TCP);
338 }
339
340 return ret;
341}
342
343static int proc_udp_early_demux(struct ctl_table *table, int write,
344 void __user *buffer, size_t *lenp, loff_t *ppos)
345{
346 int ret = 0;
347
348 ret = proc_dointvec(table, write, buffer, lenp, ppos);
349
350 if (write && !ret) {
351 int enabled = init_net.ipv4.sysctl_udp_early_demux;
352
353 proc_configure_early_demux(enabled, IPPROTO_UDP);
354 }
355
356 return ret;
357}
358
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700359static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
360 int write,
361 void __user *buffer,
362 size_t *lenp, loff_t *ppos)
363{
Haishuang Yan3733be12017-09-27 11:35:43 +0800364 struct net *net = container_of(table->data, struct net,
365 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700366 int ret;
367
368 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
369 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800370 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700371
372 return ret;
373}
374
375static int proc_tcp_available_ulp(struct ctl_table *ctl,
376 int write,
377 void __user *buffer, size_t *lenp,
378 loff_t *ppos)
379{
380 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
381 int ret;
382
383 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
384 if (!tbl.data)
385 return -ENOMEM;
386 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
387 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
388 kfree(tbl.data);
389
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700390 return ret;
391}
392
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100393#ifdef CONFIG_IP_ROUTE_MULTIPATH
394static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
395 void __user *buffer, size_t *lenp,
396 loff_t *ppos)
397{
398 struct net *net = container_of(table->data, struct net,
399 ipv4.sysctl_fib_multipath_hash_policy);
400 int ret;
401
402 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
403 if (write && ret == 0)
David Ahern3192dac2018-03-02 08:32:16 -0800404 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100405
406 return ret;
407}
408#endif
409
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800410static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .procname = "tcp_max_orphans",
413 .data = &sysctl_tcp_max_orphans,
414 .maxlen = sizeof(int),
415 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800416 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 },
418 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 .procname = "inet_peer_threshold",
420 .data = &inet_peer_threshold,
421 .maxlen = sizeof(int),
422 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800423 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 },
425 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 .procname = "inet_peer_minttl",
427 .data = &inet_peer_minttl,
428 .maxlen = sizeof(int),
429 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800430 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 },
432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 .procname = "inet_peer_maxttl",
434 .data = &inet_peer_maxttl,
435 .maxlen = sizeof(int),
436 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800437 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 },
439 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700440 .procname = "tcp_mem",
441 .maxlen = sizeof(sysctl_tcp_mem),
442 .data = &sysctl_tcp_mem,
443 .mode = 0644,
444 .proc_handler = proc_doulongvec_minmax,
445 },
446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 .procname = "tcp_low_latency",
448 .data = &sysctl_tcp_low_latency,
449 .maxlen = sizeof(int),
450 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800451 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 },
Paul Moore446fda42006-08-03 16:48:06 -0700453#ifdef CONFIG_NETLABEL
454 {
Paul Moore446fda42006-08-03 16:48:06 -0700455 .procname = "cipso_cache_enable",
456 .data = &cipso_v4_cache_enabled,
457 .maxlen = sizeof(int),
458 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800459 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700460 },
461 {
Paul Moore446fda42006-08-03 16:48:06 -0700462 .procname = "cipso_cache_bucket_size",
463 .data = &cipso_v4_cache_bucketsize,
464 .maxlen = sizeof(int),
465 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800466 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700467 },
468 {
Paul Moore446fda42006-08-03 16:48:06 -0700469 .procname = "cipso_rbm_optfmt",
470 .data = &cipso_v4_rbm_optfmt,
471 .maxlen = sizeof(int),
472 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800473 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700474 },
475 {
Paul Moore446fda42006-08-03 16:48:06 -0700476 .procname = "cipso_rbm_strictvalid",
477 .data = &cipso_v4_rbm_strictvalid,
478 .maxlen = sizeof(int),
479 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800480 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700481 },
482#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800483 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800484 .procname = "tcp_available_congestion_control",
485 .maxlen = TCP_CA_BUF_MAX,
486 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800487 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800488 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800489 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800490 .procname = "tcp_allowed_congestion_control",
491 .maxlen = TCP_CA_BUF_MAX,
492 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800493 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800494 },
John Heffner886236c2007-03-25 19:21:45 -0700495 {
Dave Watson734942c2017-06-14 11:37:14 -0700496 .procname = "tcp_available_ulp",
497 .maxlen = TCP_ULP_BUF_MAX,
498 .mode = 0444,
499 .proc_handler = proc_tcp_available_ulp,
500 },
501 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700502 .procname = "icmp_msgs_per_sec",
503 .data = &sysctl_icmp_msgs_per_sec,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &zero,
508 },
509 {
510 .procname = "icmp_msgs_burst",
511 .data = &sysctl_icmp_msgs_burst,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = proc_dointvec_minmax,
515 .extra1 = &zero,
516 },
517 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800518 .procname = "udp_mem",
519 .data = &sysctl_udp_mem,
520 .maxlen = sizeof(sysctl_udp_mem),
521 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000522 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800523 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800524 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800526
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700527static struct ctl_table ipv4_net_table[] = {
528 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700529 .procname = "icmp_echo_ignore_all",
530 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
531 .maxlen = sizeof(int),
532 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800533 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700534 },
535 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700536 .procname = "icmp_echo_ignore_broadcasts",
537 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
538 .maxlen = sizeof(int),
539 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800540 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700541 },
542 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700543 .procname = "icmp_ignore_bogus_error_responses",
544 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
545 .maxlen = sizeof(int),
546 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800547 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700548 },
549 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700550 .procname = "icmp_errors_use_inbound_ifaddr",
551 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
552 .maxlen = sizeof(int),
553 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800554 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700555 },
556 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700557 .procname = "icmp_ratelimit",
558 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
559 .maxlen = sizeof(int),
560 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800561 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700562 },
563 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700564 .procname = "icmp_ratemask",
565 .data = &init_net.ipv4.sysctl_icmp_ratemask,
566 .maxlen = sizeof(int),
567 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800568 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700569 },
Neil Horman1080d702008-10-27 12:28:25 -0700570 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000571 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700572 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600573 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000574 .mode = 0644,
575 .proc_handler = ipv4_ping_group_range,
576 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000577 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000578 .procname = "tcp_ecn",
579 .data = &init_net.ipv4.sysctl_tcp_ecn,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = proc_dointvec
583 },
584 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200585 .procname = "tcp_ecn_fallback",
586 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
587 .maxlen = sizeof(int),
588 .mode = 0644,
589 .proc_handler = proc_dointvec
590 },
591 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200592 .procname = "ip_dynaddr",
593 .data = &init_net.ipv4.sysctl_ip_dynaddr,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = proc_dointvec
597 },
598 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200599 .procname = "ip_early_demux",
600 .data = &init_net.ipv4.sysctl_ip_early_demux,
601 .maxlen = sizeof(int),
602 .mode = 0644,
603 .proc_handler = proc_dointvec
604 },
605 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600606 .procname = "udp_early_demux",
607 .data = &init_net.ipv4.sysctl_udp_early_demux,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = proc_udp_early_demux
611 },
612 {
613 .procname = "tcp_early_demux",
614 .data = &init_net.ipv4.sysctl_tcp_early_demux,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = proc_tcp_early_demux
618 },
619 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200620 .procname = "ip_default_ttl",
621 .data = &init_net.ipv4.sysctl_ip_default_ttl,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 .proc_handler = proc_dointvec_minmax,
625 .extra1 = &ip_ttl_min,
626 .extra2 = &ip_ttl_max,
627 },
628 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700629 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700630 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
631 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700632 .mode = 0644,
633 .proc_handler = ipv4_local_port_range,
634 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100635 {
WANG Cong122ff242014-05-12 16:04:53 -0700636 .procname = "ip_local_reserved_ports",
637 .data = &init_net.ipv4.sysctl_local_reserved_ports,
638 .maxlen = 65536,
639 .mode = 0644,
640 .proc_handler = proc_do_large_bitmap,
641 },
642 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100643 .procname = "ip_no_pmtu_disc",
644 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = proc_dointvec
648 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100649 {
650 .procname = "ip_forward_use_pmtu",
651 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = proc_dointvec,
655 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700656 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200657 .procname = "ip_nonlocal_bind",
658 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = proc_dointvec
662 },
663 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700664 .procname = "fwmark_reflect",
665 .data = &init_net.ipv4.sysctl_fwmark_reflect,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = proc_dointvec,
669 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700670 {
671 .procname = "tcp_fwmark_accept",
672 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = proc_dointvec,
676 },
David Ahern6dd9a142015-12-16 13:20:44 -0800677#ifdef CONFIG_NET_L3_MASTER_DEV
678 {
679 .procname = "tcp_l3mdev_accept",
680 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 .proc_handler = proc_dointvec_minmax,
684 .extra1 = &zero,
685 .extra2 = &one,
686 },
687#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800688 {
689 .procname = "tcp_mtu_probing",
690 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
691 .maxlen = sizeof(int),
692 .mode = 0644,
693 .proc_handler = proc_dointvec,
694 },
695 {
696 .procname = "tcp_base_mss",
697 .data = &init_net.ipv4.sysctl_tcp_base_mss,
698 .maxlen = sizeof(int),
699 .mode = 0644,
700 .proc_handler = proc_dointvec,
701 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800702 {
703 .procname = "tcp_probe_threshold",
704 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
705 .maxlen = sizeof(int),
706 .mode = 0644,
707 .proc_handler = proc_dointvec,
708 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800709 {
710 .procname = "tcp_probe_interval",
711 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
712 .maxlen = sizeof(int),
713 .mode = 0644,
714 .proc_handler = proc_dointvec,
715 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100716 {
717 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200718 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = proc_dointvec
722 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200723 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200724 .procname = "igmp_max_memberships",
725 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
726 .maxlen = sizeof(int),
727 .mode = 0644,
728 .proc_handler = proc_dointvec
729 },
730 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200731 .procname = "igmp_max_msf",
732 .data = &init_net.ipv4.sysctl_igmp_max_msf,
733 .maxlen = sizeof(int),
734 .mode = 0644,
735 .proc_handler = proc_dointvec
736 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200737#ifdef CONFIG_IP_MULTICAST
738 {
739 .procname = "igmp_qrv",
740 .data = &init_net.ipv4.sysctl_igmp_qrv,
741 .maxlen = sizeof(int),
742 .mode = 0644,
743 .proc_handler = proc_dointvec_minmax,
744 .extra1 = &one
745 },
746#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200747 {
Stephen Hemminger6670e152017-11-14 08:25:49 -0800748 .procname = "tcp_congestion_control",
749 .data = &init_net.ipv4.tcp_congestion_control,
750 .mode = 0644,
751 .maxlen = TCP_CA_NAME_MAX,
752 .proc_handler = proc_tcp_congestion_control,
753 },
754 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200755 .procname = "tcp_keepalive_time",
756 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
757 .maxlen = sizeof(int),
758 .mode = 0644,
759 .proc_handler = proc_dointvec_jiffies,
760 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200761 {
762 .procname = "tcp_keepalive_probes",
763 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
764 .maxlen = sizeof(int),
765 .mode = 0644,
766 .proc_handler = proc_dointvec
767 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200768 {
769 .procname = "tcp_keepalive_intvl",
770 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
771 .maxlen = sizeof(int),
772 .mode = 0644,
773 .proc_handler = proc_dointvec_jiffies,
774 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200775 {
776 .procname = "tcp_syn_retries",
777 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
778 .maxlen = sizeof(int),
779 .mode = 0644,
780 .proc_handler = proc_dointvec_minmax,
781 .extra1 = &tcp_syn_retries_min,
782 .extra2 = &tcp_syn_retries_max
783 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200784 {
785 .procname = "tcp_synack_retries",
786 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = proc_dointvec
790 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200791#ifdef CONFIG_SYN_COOKIES
792 {
793 .procname = "tcp_syncookies",
794 .data = &init_net.ipv4.sysctl_tcp_syncookies,
795 .maxlen = sizeof(int),
796 .mode = 0644,
797 .proc_handler = proc_dointvec
798 },
799#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200800 {
801 .procname = "tcp_reordering",
802 .data = &init_net.ipv4.sysctl_tcp_reordering,
803 .maxlen = sizeof(int),
804 .mode = 0644,
805 .proc_handler = proc_dointvec
806 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200807 {
808 .procname = "tcp_retries1",
809 .data = &init_net.ipv4.sysctl_tcp_retries1,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = proc_dointvec_minmax,
813 .extra2 = &tcp_retr1_max
814 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +0200815 {
816 .procname = "tcp_retries2",
817 .data = &init_net.ipv4.sysctl_tcp_retries2,
818 .maxlen = sizeof(int),
819 .mode = 0644,
820 .proc_handler = proc_dointvec
821 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +0200822 {
823 .procname = "tcp_orphan_retries",
824 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
825 .maxlen = sizeof(int),
826 .mode = 0644,
827 .proc_handler = proc_dointvec
828 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +0200829 {
830 .procname = "tcp_fin_timeout",
831 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
832 .maxlen = sizeof(int),
833 .mode = 0644,
834 .proc_handler = proc_dointvec_jiffies,
835 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200836 {
837 .procname = "tcp_notsent_lowat",
838 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
839 .maxlen = sizeof(unsigned int),
840 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +0300841 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200842 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800843 {
844 .procname = "tcp_tw_reuse",
845 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
846 .maxlen = sizeof(int),
847 .mode = 0644,
848 .proc_handler = proc_dointvec
849 },
Haishuang Yan1946e672016-12-28 17:52:32 +0800850 {
851 .procname = "tcp_max_tw_buckets",
852 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
853 .maxlen = sizeof(int),
854 .mode = 0644,
855 .proc_handler = proc_dointvec
856 },
857 {
Haishuang Yanfee83d02016-12-28 17:52:33 +0800858 .procname = "tcp_max_syn_backlog",
859 .data = &init_net.ipv4.sysctl_max_syn_backlog,
860 .maxlen = sizeof(int),
861 .mode = 0644,
862 .proc_handler = proc_dointvec
863 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +0800864 {
865 .procname = "tcp_fastopen",
866 .data = &init_net.ipv4.sysctl_tcp_fastopen,
867 .maxlen = sizeof(int),
868 .mode = 0644,
869 .proc_handler = proc_dointvec,
870 },
Haishuang Yan43713842017-09-27 11:35:42 +0800871 {
872 .procname = "tcp_fastopen_key",
873 .mode = 0600,
874 .data = &init_net.ipv4.sysctl_tcp_fastopen,
875 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
876 .proc_handler = proc_tcp_fastopen_key,
877 },
Haishuang Yan3733be12017-09-27 11:35:43 +0800878 {
879 .procname = "tcp_fastopen_blackhole_timeout_sec",
880 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
881 .maxlen = sizeof(int),
882 .mode = 0644,
883 .proc_handler = proc_tfo_blackhole_detect_timeout,
884 .extra1 = &zero,
885 },
David Aherna6db4492016-04-07 07:21:00 -0700886#ifdef CONFIG_IP_ROUTE_MULTIPATH
887 {
888 .procname = "fib_multipath_use_neigh",
889 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
890 .maxlen = sizeof(int),
891 .mode = 0644,
892 .proc_handler = proc_dointvec_minmax,
893 .extra1 = &zero,
894 .extra2 = &one,
895 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200896 {
897 .procname = "fib_multipath_hash_policy",
898 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
899 .maxlen = sizeof(int),
900 .mode = 0644,
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100901 .proc_handler = proc_fib_multipath_hash_policy,
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200902 .extra1 = &zero,
903 .extra2 = &one,
904 },
David Aherna6db4492016-04-07 07:21:00 -0700905#endif
Krister Johansen4548b682017-01-20 17:49:11 -0800906 {
907 .procname = "ip_unprivileged_port_start",
908 .maxlen = sizeof(int),
909 .data = &init_net.ipv4.sysctl_ip_prot_sock,
910 .mode = 0644,
911 .proc_handler = ipv4_privileged_ports,
912 },
Robert Shearman63a6fff2017-01-26 18:02:24 +0000913#ifdef CONFIG_NET_L3_MASTER_DEV
914 {
915 .procname = "udp_l3mdev_accept",
916 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
917 .maxlen = sizeof(int),
918 .mode = 0644,
919 .proc_handler = proc_dointvec_minmax,
920 .extra1 = &zero,
921 .extra2 = &one,
922 },
923#endif
Eric Dumazetf9301032017-06-07 10:34:37 -0700924 {
925 .procname = "tcp_sack",
926 .data = &init_net.ipv4.sysctl_tcp_sack,
927 .maxlen = sizeof(int),
928 .mode = 0644,
929 .proc_handler = proc_dointvec
930 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -0700931 {
932 .procname = "tcp_window_scaling",
933 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
934 .maxlen = sizeof(int),
935 .mode = 0644,
936 .proc_handler = proc_dointvec
937 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -0700938 {
939 .procname = "tcp_timestamps",
940 .data = &init_net.ipv4.sysctl_tcp_timestamps,
941 .maxlen = sizeof(int),
942 .mode = 0644,
943 .proc_handler = proc_dointvec
944 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -0700945 {
946 .procname = "tcp_early_retrans",
947 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
948 .maxlen = sizeof(int),
949 .mode = 0644,
950 .proc_handler = proc_dointvec_minmax,
951 .extra1 = &zero,
952 .extra2 = &four,
953 },
Eric Dumazete20223f2017-10-26 21:54:57 -0700954 {
955 .procname = "tcp_recovery",
956 .data = &init_net.ipv4.sysctl_tcp_recovery,
957 .maxlen = sizeof(int),
958 .mode = 0644,
959 .proc_handler = proc_dointvec,
960 },
Eric Dumazet2c04ac82017-10-26 21:54:58 -0700961 {
962 .procname = "tcp_thin_linear_timeouts",
963 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
964 .maxlen = sizeof(int),
965 .mode = 0644,
966 .proc_handler = proc_dointvec
967 },
Eric Dumazetb510f0d2017-10-26 21:54:59 -0700968 {
969 .procname = "tcp_slow_start_after_idle",
970 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
971 .maxlen = sizeof(int),
972 .mode = 0644,
973 .proc_handler = proc_dointvec
974 },
Eric Dumazete0a1e5b2017-10-26 21:55:00 -0700975 {
976 .procname = "tcp_retrans_collapse",
977 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
978 .maxlen = sizeof(int),
979 .mode = 0644,
980 .proc_handler = proc_dointvec
981 },
Eric Dumazet3f4c7c62017-10-26 21:55:01 -0700982 {
983 .procname = "tcp_stdurg",
984 .data = &init_net.ipv4.sysctl_tcp_stdurg,
985 .maxlen = sizeof(int),
986 .mode = 0644,
987 .proc_handler = proc_dointvec
988 },
Eric Dumazet625357a2017-10-26 21:55:02 -0700989 {
990 .procname = "tcp_rfc1337",
991 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
992 .maxlen = sizeof(int),
993 .mode = 0644,
994 .proc_handler = proc_dointvec
995 },
Eric Dumazet65c94102017-10-26 21:55:03 -0700996 {
997 .procname = "tcp_abort_on_overflow",
998 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
999 .maxlen = sizeof(int),
1000 .mode = 0644,
1001 .proc_handler = proc_dointvec
1002 },
Eric Dumazet0bc65a22017-10-26 21:55:04 -07001003 {
1004 .procname = "tcp_fack",
1005 .data = &init_net.ipv4.sysctl_tcp_fack,
1006 .maxlen = sizeof(int),
1007 .mode = 0644,
1008 .proc_handler = proc_dointvec
1009 },
Eric Dumazetc6e21802017-10-26 21:55:06 -07001010 {
1011 .procname = "tcp_max_reordering",
1012 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1013 .maxlen = sizeof(int),
1014 .mode = 0644,
1015 .proc_handler = proc_dointvec
1016 },
Eric Dumazet6496f6b2017-10-26 21:55:07 -07001017 {
1018 .procname = "tcp_dsack",
1019 .data = &init_net.ipv4.sysctl_tcp_dsack,
1020 .maxlen = sizeof(int),
1021 .mode = 0644,
1022 .proc_handler = proc_dointvec
1023 },
Eric Dumazet0c126542017-10-26 21:55:08 -07001024 {
1025 .procname = "tcp_app_win",
1026 .data = &init_net.ipv4.sysctl_tcp_app_win,
1027 .maxlen = sizeof(int),
1028 .mode = 0644,
1029 .proc_handler = proc_dointvec
1030 },
Eric Dumazet94f08932017-10-26 21:55:09 -07001031 {
1032 .procname = "tcp_adv_win_scale",
1033 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1034 .maxlen = sizeof(int),
1035 .mode = 0644,
1036 .proc_handler = proc_dointvec_minmax,
1037 .extra1 = &tcp_adv_win_scale_min,
1038 .extra2 = &tcp_adv_win_scale_max,
1039 },
Eric Dumazetaf9b69a2017-10-26 21:55:10 -07001040 {
1041 .procname = "tcp_frto",
1042 .data = &init_net.ipv4.sysctl_tcp_frto,
1043 .maxlen = sizeof(int),
1044 .mode = 0644,
1045 .proc_handler = proc_dointvec
1046 },
Eric Dumazetec36e412017-10-27 07:47:21 -07001047 {
1048 .procname = "tcp_no_metrics_save",
1049 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1050 .maxlen = sizeof(int),
1051 .mode = 0644,
1052 .proc_handler = proc_dointvec,
1053 },
Eric Dumazet4540c0c2017-10-27 07:47:22 -07001054 {
1055 .procname = "tcp_moderate_rcvbuf",
1056 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1057 .maxlen = sizeof(int),
1058 .mode = 0644,
1059 .proc_handler = proc_dointvec,
1060 },
Eric Dumazetd06a9902017-10-27 07:47:23 -07001061 {
1062 .procname = "tcp_tso_win_divisor",
1063 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1064 .maxlen = sizeof(int),
1065 .mode = 0644,
1066 .proc_handler = proc_dointvec,
1067 },
Eric Dumazetceef9ab2017-10-27 07:47:24 -07001068 {
1069 .procname = "tcp_workaround_signed_windows",
1070 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1071 .maxlen = sizeof(int),
1072 .mode = 0644,
1073 .proc_handler = proc_dointvec
1074 },
Eric Dumazet9184d8b2017-10-27 07:47:25 -07001075 {
1076 .procname = "tcp_limit_output_bytes",
1077 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1078 .maxlen = sizeof(int),
1079 .mode = 0644,
1080 .proc_handler = proc_dointvec
1081 },
Eric Dumazetb530b682017-10-27 07:47:26 -07001082 {
1083 .procname = "tcp_challenge_ack_limit",
1084 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1085 .maxlen = sizeof(int),
1086 .mode = 0644,
1087 .proc_handler = proc_dointvec
1088 },
Eric Dumazet26e95962017-10-27 07:47:27 -07001089 {
1090 .procname = "tcp_min_tso_segs",
1091 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1092 .maxlen = sizeof(int),
1093 .mode = 0644,
1094 .proc_handler = proc_dointvec_minmax,
1095 .extra1 = &one,
1096 .extra2 = &gso_max_segs,
1097 },
Eric Dumazetbd239702017-10-27 07:47:28 -07001098 {
1099 .procname = "tcp_min_rtt_wlen",
1100 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1101 .maxlen = sizeof(int),
1102 .mode = 0644,
1103 .proc_handler = proc_dointvec
1104 },
Eric Dumazet790f00e2017-10-27 07:47:29 -07001105 {
1106 .procname = "tcp_autocorking",
1107 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1108 .maxlen = sizeof(int),
1109 .mode = 0644,
1110 .proc_handler = proc_dointvec_minmax,
1111 .extra1 = &zero,
1112 .extra2 = &one,
1113 },
Eric Dumazet4170ba62017-10-27 07:47:30 -07001114 {
1115 .procname = "tcp_invalid_ratelimit",
1116 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1117 .maxlen = sizeof(int),
1118 .mode = 0644,
1119 .proc_handler = proc_dointvec_ms_jiffies,
1120 },
Eric Dumazet23a7102a2017-10-27 07:47:31 -07001121 {
1122 .procname = "tcp_pacing_ss_ratio",
1123 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1124 .maxlen = sizeof(int),
1125 .mode = 0644,
1126 .proc_handler = proc_dointvec_minmax,
1127 .extra1 = &zero,
1128 .extra2 = &thousand,
1129 },
Eric Dumazetc26e91f2017-10-27 07:47:32 -07001130 {
1131 .procname = "tcp_pacing_ca_ratio",
1132 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1133 .maxlen = sizeof(int),
1134 .mode = 0644,
1135 .proc_handler = proc_dointvec_minmax,
1136 .extra1 = &zero,
1137 .extra2 = &thousand,
1138 },
Eric Dumazet356d1832017-11-07 00:29:28 -08001139 {
1140 .procname = "tcp_wmem",
1141 .data = &init_net.ipv4.sysctl_tcp_wmem,
1142 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1143 .mode = 0644,
1144 .proc_handler = proc_dointvec_minmax,
1145 .extra1 = &one,
1146 },
1147 {
1148 .procname = "tcp_rmem",
1149 .data = &init_net.ipv4.sysctl_tcp_rmem,
1150 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1151 .mode = 0644,
1152 .proc_handler = proc_dointvec_minmax,
1153 .extra1 = &one,
1154 },
Tonghao Zhang1e802952018-03-13 21:57:16 -07001155 {
Eric Dumazet6d82aa22018-05-17 14:47:28 -07001156 .procname = "tcp_comp_sack_delay_ns",
1157 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1158 .maxlen = sizeof(unsigned long),
1159 .mode = 0644,
1160 .proc_handler = proc_doulongvec_minmax,
1161 },
1162 {
Eric Dumazet9c21d2f2018-05-17 14:47:29 -07001163 .procname = "tcp_comp_sack_nr",
1164 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1165 .maxlen = sizeof(int),
1166 .mode = 0644,
1167 .proc_handler = proc_dointvec_minmax,
1168 .extra1 = &zero,
1169 .extra2 = &comp_sack_nr_max,
1170 },
1171 {
Tonghao Zhang1e802952018-03-13 21:57:16 -07001172 .procname = "udp_rmem_min",
1173 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1174 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1175 .mode = 0644,
1176 .proc_handler = proc_dointvec_minmax,
1177 .extra1 = &one
1178 },
1179 {
1180 .procname = "udp_wmem_min",
1181 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1182 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1183 .mode = 0644,
1184 .proc_handler = proc_dointvec_minmax,
1185 .extra1 = &one
1186 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001187 { }
1188};
1189
Pavel Emelyanov15775192008-03-26 01:54:18 -07001190static __net_init int ipv4_sysctl_init_net(struct net *net)
1191{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001192 struct ctl_table *table;
1193
1194 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001195 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001196 int i;
1197
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001198 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001199 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001200 goto err_alloc;
1201
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001202 /* Update the variables to point into the current struct net */
1203 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1204 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001205 }
1206
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001207 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001208 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001209 goto err_reg;
1210
WANG Cong122ff242014-05-12 16:04:53 -07001211 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1212 if (!net->ipv4.sysctl_local_reserved_ports)
1213 goto err_ports;
1214
Pavel Emelyanov15775192008-03-26 01:54:18 -07001215 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001216
WANG Cong122ff242014-05-12 16:04:53 -07001217err_ports:
1218 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001219err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001220 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001221 kfree(table);
1222err_alloc:
1223 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001224}
1225
1226static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1227{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001228 struct ctl_table *table;
1229
WANG Cong122ff242014-05-12 16:04:53 -07001230 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001231 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1232 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1233 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001234}
1235
1236static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1237 .init = ipv4_sysctl_init_net,
1238 .exit = ipv4_sysctl_exit_net,
1239};
1240
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001241static __init int sysctl_ipv4_init(void)
1242{
1243 struct ctl_table_header *hdr;
1244
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001245 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001246 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001247 return -ENOMEM;
1248
1249 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001250 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001251 return -ENOMEM;
1252 }
1253
1254 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001255}
1256
1257__initcall(sysctl_ipv4_init);