blob: 5fa335fd385254def583b9a5100fbe7b9ce94cd6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
7 */
8
9#include <linux/mm.h>
10#include <linux/module.h>
11#include <linux/sysctl.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030012#include <linux/igmp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020013#include <linux/inetdevice.h>
Stephen Hemminger227b60f2007-10-10 17:30:46 -070014#include <linux/seqlock.h>
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -080015#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000017#include <linux/nsproxy.h>
Glauber Costa3dc43e32011-12-11 21:47:05 +000018#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030020#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <net/ip.h>
22#include <net/route.h>
23#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080024#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070025#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070026#include <net/inet_frag.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000027#include <net/ping.h>
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060028#include <net/protocol.h>
Ido Schimmel3ae6ec02017-11-02 17:14:05 +010029#include <net/netevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Herbert Xu89cee8b2005-12-13 23:14:27 -080031static int zero;
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +000032static int one = 1;
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -070033static int two = 2;
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +000034static int four = 4;
Eric Dumazet43e122b2015-08-21 17:38:02 -070035static int thousand = 1000;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070036static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090037static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static int ip_local_port_range_min[] = { 1, 1 };
39static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000040static int tcp_adv_win_scale_min = -31;
41static int tcp_adv_win_scale_max = 31;
Krister Johansen4548b682017-01-20 17:49:11 -080042static int ip_privileged_port_min;
43static int ip_privileged_port_max = 65535;
Eric Dumazet249fab72010-12-13 12:16:14 -080044static int ip_ttl_min = 1;
45static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020046static int tcp_syn_retries_min = 1;
47static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000048static int ip_ping_group_range_min[] = { 0, 0 };
49static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Eric Dumazet9c21d2f2018-05-17 14:47:29 -070050static int comp_sack_nr_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Florian Westphalb6690b12017-07-30 03:57:20 +020052/* obsolete */
53static int sysctl_tcp_low_latency __read_mostly;
54
Stephen Hemminger227b60f2007-10-10 17:30:46 -070055/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070056static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070057{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070058 bool same_parity = !((range[0] ^ range[1]) & 1);
59
WANG Cong4ee3bd42015-11-03 14:32:57 -080060 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070061 if (same_parity && !net->ipv4.ip_local_ports.warned) {
62 net->ipv4.ip_local_ports.warned = true;
63 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
64 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070065 net->ipv4.ip_local_ports.range[0] = range[0];
66 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080067 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070068}
69
70/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070071static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070072 void __user *buffer,
73 size_t *lenp, loff_t *ppos)
74{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070075 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070076 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070077 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070078 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070079 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070080 .data = &range,
81 .maxlen = sizeof(range),
82 .mode = table->mode,
83 .extra1 = &ip_local_port_range_min,
84 .extra2 = &ip_local_port_range_max,
85 };
86
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070087 inet_get_local_port_range(net, &range[0], &range[1]);
88
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070089 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070090
91 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080092 /* Ensure that the upper limit is not smaller than the lower,
93 * and that the lower does not encroach upon the privileged
94 * port limit.
95 */
96 if ((range[1] < range[0]) ||
97 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -070098 ret = -EINVAL;
99 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700100 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -0700101 }
102
103 return ret;
104}
105
Krister Johansen4548b682017-01-20 17:49:11 -0800106/* Validate changes from /proc interface. */
107static int ipv4_privileged_ports(struct ctl_table *table, int write,
108 void __user *buffer, size_t *lenp, loff_t *ppos)
109{
110 struct net *net = container_of(table->data, struct net,
111 ipv4.sysctl_ip_prot_sock);
112 int ret;
113 int pports;
114 int range[2];
115 struct ctl_table tmp = {
116 .data = &pports,
117 .maxlen = sizeof(pports),
118 .mode = table->mode,
119 .extra1 = &ip_privileged_port_min,
120 .extra2 = &ip_privileged_port_max,
121 };
122
123 pports = net->ipv4.sysctl_ip_prot_sock;
124
125 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
126
127 if (write && ret == 0) {
128 inet_get_local_port_range(net, &range[0], &range[1]);
129 /* Ensure that the local port range doesn't overlap with the
130 * privileged port range.
131 */
132 if (range[0] < pports)
133 ret = -EINVAL;
134 else
135 net->ipv4.sysctl_ip_prot_sock = pports;
136 }
137
138 return ret;
139}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000140
Eric W. Biederman7064d162012-05-24 10:34:21 -0600141static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000142{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600143 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700144 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700145 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000146 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000147 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700148 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000149
150 *low = data[0];
151 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700152 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000153}
154
155/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600156static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000157{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600158 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700159 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700160 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700161 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600162 data[0] = low;
163 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700164 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000165}
166
167/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700168static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000169 void __user *buffer,
170 size_t *lenp, loff_t *ppos)
171{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600172 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000173 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600174 gid_t urange[2];
175 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700176 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600177 .data = &urange,
178 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000179 .mode = table->mode,
180 .extra1 = &ip_ping_group_range_min,
181 .extra2 = &ip_ping_group_range_max,
182 };
183
Eric W. Biederman7064d162012-05-24 10:34:21 -0600184 inet_get_ping_group_range_table(table, &low, &high);
185 urange[0] = from_kgid_munged(user_ns, low);
186 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000187 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
188
Eric W. Biederman7064d162012-05-24 10:34:21 -0600189 if (write && ret == 0) {
190 low = make_kgid(user_ns, urange[0]);
191 high = make_kgid(user_ns, urange[1]);
Tyler Hicks70ba5b62018-07-05 18:49:23 +0000192 if (!gid_valid(low) || !gid_valid(high))
193 return -EINVAL;
194 if (urange[1] < urange[0] || gid_lt(high, low)) {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600195 low = make_kgid(&init_user_ns, 1);
196 high = make_kgid(&init_user_ns, 0);
197 }
198 set_ping_group_range(table, low, high);
199 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000200
201 return ret;
202}
203
Joe Perchesfe2c6332013-06-11 23:04:25 -0700204static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700205 void __user *buffer, size_t *lenp, loff_t *ppos)
206{
Stephen Hemminger6670e152017-11-14 08:25:49 -0800207 struct net *net = container_of(ctl->data, struct net,
208 ipv4.tcp_congestion_control);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700209 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700210 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700211 .data = val,
212 .maxlen = TCP_CA_NAME_MAX,
213 };
214 int ret;
215
Stephen Hemminger6670e152017-11-14 08:25:49 -0800216 tcp_get_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700217
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700218 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700219 if (write && ret == 0)
Stephen Hemminger6670e152017-11-14 08:25:49 -0800220 ret = tcp_set_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700221 return ret;
222}
223
Joe Perchesfe2c6332013-06-11 23:04:25 -0700224static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700225 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800226 void __user *buffer, size_t *lenp,
227 loff_t *ppos)
228{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700229 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800230 int ret;
231
232 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
233 if (!tbl.data)
234 return -ENOMEM;
235 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700236 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800237 kfree(tbl.data);
238 return ret;
239}
240
Joe Perchesfe2c6332013-06-11 23:04:25 -0700241static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700242 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800243 void __user *buffer, size_t *lenp,
244 loff_t *ppos)
245{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700246 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800247 int ret;
248
249 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
250 if (!tbl.data)
251 return -ENOMEM;
252
253 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700254 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800255 if (write && ret == 0)
256 ret = tcp_set_allowed_congestion_control(tbl.data);
257 kfree(tbl.data);
258 return ret;
259}
260
Haishuang Yan43713842017-09-27 11:35:42 +0800261static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700262 void __user *buffer, size_t *lenp,
263 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000264{
Haishuang Yan43713842017-09-27 11:35:42 +0800265 struct net *net = container_of(table->data, struct net,
266 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700267 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000268 struct tcp_fastopen_context *ctxt;
Jerry Chu10467162012-08-31 12:29:11 +0000269 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
Yuchung Chengc860e992018-06-27 16:04:48 -0700270 __le32 key[4];
271 int ret, i;
Jerry Chu10467162012-08-31 12:29:11 +0000272
273 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
274 if (!tbl.data)
275 return -ENOMEM;
276
277 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800278 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000279 if (ctxt)
Yuchung Chengc860e992018-06-27 16:04:48 -0700280 memcpy(key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000281 else
Yuchung Chengc860e992018-06-27 16:04:48 -0700282 memset(key, 0, sizeof(key));
Jerry Chu10467162012-08-31 12:29:11 +0000283 rcu_read_unlock();
284
Yuchung Chengc860e992018-06-27 16:04:48 -0700285 for (i = 0; i < ARRAY_SIZE(key); i++)
286 user_key[i] = le32_to_cpu(key[i]);
287
Jerry Chu10467162012-08-31 12:29:11 +0000288 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
289 user_key[0], user_key[1], user_key[2], user_key[3]);
290 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
291
292 if (write && ret == 0) {
293 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
294 user_key + 2, user_key + 3) != 4) {
295 ret = -EINVAL;
296 goto bad_key;
297 }
Yuchung Chengc860e992018-06-27 16:04:48 -0700298
299 for (i = 0; i < ARRAY_SIZE(user_key); i++)
300 key[i] = cpu_to_le32(user_key[i]);
301
302 tcp_fastopen_reset_cipher(net, NULL, key,
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700303 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000304 }
305
306bad_key:
307 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
Yuchung Chengc860e992018-06-27 16:04:48 -0700308 user_key[0], user_key[1], user_key[2], user_key[3],
Jerry Chu10467162012-08-31 12:29:11 +0000309 (char *)tbl.data, ret);
310 kfree(tbl.data);
311 return ret;
312}
313
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600314static void proc_configure_early_demux(int enabled, int protocol)
315{
316 struct net_protocol *ipprot;
317#if IS_ENABLED(CONFIG_IPV6)
318 struct inet6_protocol *ip6prot;
319#endif
320
David Ahern58c4c6a2017-04-22 09:33:16 -0700321 rcu_read_lock();
322
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600323 ipprot = rcu_dereference(inet_protos[protocol]);
324 if (ipprot)
325 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
326 NULL;
327
328#if IS_ENABLED(CONFIG_IPV6)
329 ip6prot = rcu_dereference(inet6_protos[protocol]);
330 if (ip6prot)
331 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
332 NULL;
333#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700334 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600335}
336
337static int proc_tcp_early_demux(struct ctl_table *table, int write,
338 void __user *buffer, size_t *lenp, loff_t *ppos)
339{
340 int ret = 0;
341
342 ret = proc_dointvec(table, write, buffer, lenp, ppos);
343
344 if (write && !ret) {
345 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
346
347 proc_configure_early_demux(enabled, IPPROTO_TCP);
348 }
349
350 return ret;
351}
352
353static int proc_udp_early_demux(struct ctl_table *table, int write,
354 void __user *buffer, size_t *lenp, loff_t *ppos)
355{
356 int ret = 0;
357
358 ret = proc_dointvec(table, write, buffer, lenp, ppos);
359
360 if (write && !ret) {
361 int enabled = init_net.ipv4.sysctl_udp_early_demux;
362
363 proc_configure_early_demux(enabled, IPPROTO_UDP);
364 }
365
366 return ret;
367}
368
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700369static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
370 int write,
371 void __user *buffer,
372 size_t *lenp, loff_t *ppos)
373{
Haishuang Yan3733be12017-09-27 11:35:43 +0800374 struct net *net = container_of(table->data, struct net,
375 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700376 int ret;
377
378 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
379 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800380 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700381
382 return ret;
383}
384
385static int proc_tcp_available_ulp(struct ctl_table *ctl,
386 int write,
387 void __user *buffer, size_t *lenp,
388 loff_t *ppos)
389{
390 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
391 int ret;
392
393 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
394 if (!tbl.data)
395 return -ENOMEM;
396 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
397 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
398 kfree(tbl.data);
399
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700400 return ret;
401}
402
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100403#ifdef CONFIG_IP_ROUTE_MULTIPATH
404static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
405 void __user *buffer, size_t *lenp,
406 loff_t *ppos)
407{
408 struct net *net = container_of(table->data, struct net,
409 ipv4.sysctl_fib_multipath_hash_policy);
410 int ret;
411
412 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
413 if (write && ret == 0)
David Ahern3192dac2018-03-02 08:32:16 -0800414 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100415
416 return ret;
417}
418#endif
419
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800420static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .procname = "tcp_max_orphans",
423 .data = &sysctl_tcp_max_orphans,
424 .maxlen = sizeof(int),
425 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800426 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 },
428 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 .procname = "inet_peer_threshold",
430 .data = &inet_peer_threshold,
431 .maxlen = sizeof(int),
432 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800433 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 },
435 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 .procname = "inet_peer_minttl",
437 .data = &inet_peer_minttl,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800440 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 },
442 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 .procname = "inet_peer_maxttl",
444 .data = &inet_peer_maxttl,
445 .maxlen = sizeof(int),
446 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800447 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 },
449 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700450 .procname = "tcp_mem",
451 .maxlen = sizeof(sysctl_tcp_mem),
452 .data = &sysctl_tcp_mem,
453 .mode = 0644,
454 .proc_handler = proc_doulongvec_minmax,
455 },
456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "tcp_low_latency",
458 .data = &sysctl_tcp_low_latency,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800461 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
Paul Moore446fda42006-08-03 16:48:06 -0700463#ifdef CONFIG_NETLABEL
464 {
Paul Moore446fda42006-08-03 16:48:06 -0700465 .procname = "cipso_cache_enable",
466 .data = &cipso_v4_cache_enabled,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800469 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700470 },
471 {
Paul Moore446fda42006-08-03 16:48:06 -0700472 .procname = "cipso_cache_bucket_size",
473 .data = &cipso_v4_cache_bucketsize,
474 .maxlen = sizeof(int),
475 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800476 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700477 },
478 {
Paul Moore446fda42006-08-03 16:48:06 -0700479 .procname = "cipso_rbm_optfmt",
480 .data = &cipso_v4_rbm_optfmt,
481 .maxlen = sizeof(int),
482 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800483 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700484 },
485 {
Paul Moore446fda42006-08-03 16:48:06 -0700486 .procname = "cipso_rbm_strictvalid",
487 .data = &cipso_v4_rbm_strictvalid,
488 .maxlen = sizeof(int),
489 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800490 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700491 },
492#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800493 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800494 .procname = "tcp_available_congestion_control",
495 .maxlen = TCP_CA_BUF_MAX,
496 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800497 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800498 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800499 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800500 .procname = "tcp_allowed_congestion_control",
501 .maxlen = TCP_CA_BUF_MAX,
502 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800503 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800504 },
John Heffner886236c2007-03-25 19:21:45 -0700505 {
Dave Watson734942c2017-06-14 11:37:14 -0700506 .procname = "tcp_available_ulp",
507 .maxlen = TCP_ULP_BUF_MAX,
508 .mode = 0444,
509 .proc_handler = proc_tcp_available_ulp,
510 },
511 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700512 .procname = "icmp_msgs_per_sec",
513 .data = &sysctl_icmp_msgs_per_sec,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = proc_dointvec_minmax,
517 .extra1 = &zero,
518 },
519 {
520 .procname = "icmp_msgs_burst",
521 .data = &sysctl_icmp_msgs_burst,
522 .maxlen = sizeof(int),
523 .mode = 0644,
524 .proc_handler = proc_dointvec_minmax,
525 .extra1 = &zero,
526 },
527 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800528 .procname = "udp_mem",
529 .data = &sysctl_udp_mem,
530 .maxlen = sizeof(sysctl_udp_mem),
531 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000532 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800533 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800534 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800536
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700537static struct ctl_table ipv4_net_table[] = {
538 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700539 .procname = "icmp_echo_ignore_all",
540 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800543 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700544 },
545 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700546 .procname = "icmp_echo_ignore_broadcasts",
547 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
548 .maxlen = sizeof(int),
549 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800550 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700551 },
552 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700553 .procname = "icmp_ignore_bogus_error_responses",
554 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
555 .maxlen = sizeof(int),
556 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800557 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700558 },
559 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700560 .procname = "icmp_errors_use_inbound_ifaddr",
561 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
562 .maxlen = sizeof(int),
563 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800564 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700565 },
566 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700567 .procname = "icmp_ratelimit",
568 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
569 .maxlen = sizeof(int),
570 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800571 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700572 },
573 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700574 .procname = "icmp_ratemask",
575 .data = &init_net.ipv4.sysctl_icmp_ratemask,
576 .maxlen = sizeof(int),
577 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800578 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700579 },
Neil Horman1080d702008-10-27 12:28:25 -0700580 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000581 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700582 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600583 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000584 .mode = 0644,
585 .proc_handler = ipv4_ping_group_range,
586 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000587 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000588 .procname = "tcp_ecn",
589 .data = &init_net.ipv4.sysctl_tcp_ecn,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = proc_dointvec
593 },
594 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200595 .procname = "tcp_ecn_fallback",
596 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = proc_dointvec
600 },
601 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200602 .procname = "ip_dynaddr",
603 .data = &init_net.ipv4.sysctl_ip_dynaddr,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = proc_dointvec
607 },
608 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200609 .procname = "ip_early_demux",
610 .data = &init_net.ipv4.sysctl_ip_early_demux,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 .proc_handler = proc_dointvec
614 },
615 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600616 .procname = "udp_early_demux",
617 .data = &init_net.ipv4.sysctl_udp_early_demux,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = proc_udp_early_demux
621 },
622 {
623 .procname = "tcp_early_demux",
624 .data = &init_net.ipv4.sysctl_tcp_early_demux,
625 .maxlen = sizeof(int),
626 .mode = 0644,
627 .proc_handler = proc_tcp_early_demux
628 },
629 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200630 .procname = "ip_default_ttl",
631 .data = &init_net.ipv4.sysctl_ip_default_ttl,
632 .maxlen = sizeof(int),
633 .mode = 0644,
634 .proc_handler = proc_dointvec_minmax,
635 .extra1 = &ip_ttl_min,
636 .extra2 = &ip_ttl_max,
637 },
638 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700639 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700640 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
641 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700642 .mode = 0644,
643 .proc_handler = ipv4_local_port_range,
644 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100645 {
WANG Cong122ff242014-05-12 16:04:53 -0700646 .procname = "ip_local_reserved_ports",
647 .data = &init_net.ipv4.sysctl_local_reserved_ports,
648 .maxlen = 65536,
649 .mode = 0644,
650 .proc_handler = proc_do_large_bitmap,
651 },
652 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100653 .procname = "ip_no_pmtu_disc",
654 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = proc_dointvec
658 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100659 {
660 .procname = "ip_forward_use_pmtu",
661 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 .proc_handler = proc_dointvec,
665 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700666 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200667 .procname = "ip_nonlocal_bind",
668 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = proc_dointvec
672 },
673 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700674 .procname = "fwmark_reflect",
675 .data = &init_net.ipv4.sysctl_fwmark_reflect,
676 .maxlen = sizeof(int),
677 .mode = 0644,
678 .proc_handler = proc_dointvec,
679 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700680 {
681 .procname = "tcp_fwmark_accept",
682 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
683 .maxlen = sizeof(int),
684 .mode = 0644,
685 .proc_handler = proc_dointvec,
686 },
David Ahern6dd9a142015-12-16 13:20:44 -0800687#ifdef CONFIG_NET_L3_MASTER_DEV
688 {
689 .procname = "tcp_l3mdev_accept",
690 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
691 .maxlen = sizeof(int),
692 .mode = 0644,
693 .proc_handler = proc_dointvec_minmax,
694 .extra1 = &zero,
695 .extra2 = &one,
696 },
697#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800698 {
699 .procname = "tcp_mtu_probing",
700 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
701 .maxlen = sizeof(int),
702 .mode = 0644,
703 .proc_handler = proc_dointvec,
704 },
705 {
706 .procname = "tcp_base_mss",
707 .data = &init_net.ipv4.sysctl_tcp_base_mss,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = proc_dointvec,
711 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800712 {
713 .procname = "tcp_probe_threshold",
714 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
715 .maxlen = sizeof(int),
716 .mode = 0644,
717 .proc_handler = proc_dointvec,
718 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800719 {
720 .procname = "tcp_probe_interval",
721 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
722 .maxlen = sizeof(int),
723 .mode = 0644,
724 .proc_handler = proc_dointvec,
725 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100726 {
727 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200728 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100729 .maxlen = sizeof(int),
730 .mode = 0644,
731 .proc_handler = proc_dointvec
732 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200733 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200734 .procname = "igmp_max_memberships",
735 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = proc_dointvec
739 },
740 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200741 .procname = "igmp_max_msf",
742 .data = &init_net.ipv4.sysctl_igmp_max_msf,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = proc_dointvec
746 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200747#ifdef CONFIG_IP_MULTICAST
748 {
749 .procname = "igmp_qrv",
750 .data = &init_net.ipv4.sysctl_igmp_qrv,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec_minmax,
754 .extra1 = &one
755 },
756#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200757 {
Stephen Hemminger6670e152017-11-14 08:25:49 -0800758 .procname = "tcp_congestion_control",
759 .data = &init_net.ipv4.tcp_congestion_control,
760 .mode = 0644,
761 .maxlen = TCP_CA_NAME_MAX,
762 .proc_handler = proc_tcp_congestion_control,
763 },
764 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200765 .procname = "tcp_keepalive_time",
766 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
767 .maxlen = sizeof(int),
768 .mode = 0644,
769 .proc_handler = proc_dointvec_jiffies,
770 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200771 {
772 .procname = "tcp_keepalive_probes",
773 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
774 .maxlen = sizeof(int),
775 .mode = 0644,
776 .proc_handler = proc_dointvec
777 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200778 {
779 .procname = "tcp_keepalive_intvl",
780 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = proc_dointvec_jiffies,
784 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200785 {
786 .procname = "tcp_syn_retries",
787 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
788 .maxlen = sizeof(int),
789 .mode = 0644,
790 .proc_handler = proc_dointvec_minmax,
791 .extra1 = &tcp_syn_retries_min,
792 .extra2 = &tcp_syn_retries_max
793 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200794 {
795 .procname = "tcp_synack_retries",
796 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
797 .maxlen = sizeof(int),
798 .mode = 0644,
799 .proc_handler = proc_dointvec
800 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200801#ifdef CONFIG_SYN_COOKIES
802 {
803 .procname = "tcp_syncookies",
804 .data = &init_net.ipv4.sysctl_tcp_syncookies,
805 .maxlen = sizeof(int),
806 .mode = 0644,
807 .proc_handler = proc_dointvec
808 },
809#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200810 {
811 .procname = "tcp_reordering",
812 .data = &init_net.ipv4.sysctl_tcp_reordering,
813 .maxlen = sizeof(int),
814 .mode = 0644,
815 .proc_handler = proc_dointvec
816 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200817 {
818 .procname = "tcp_retries1",
819 .data = &init_net.ipv4.sysctl_tcp_retries1,
820 .maxlen = sizeof(int),
821 .mode = 0644,
822 .proc_handler = proc_dointvec_minmax,
823 .extra2 = &tcp_retr1_max
824 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +0200825 {
826 .procname = "tcp_retries2",
827 .data = &init_net.ipv4.sysctl_tcp_retries2,
828 .maxlen = sizeof(int),
829 .mode = 0644,
830 .proc_handler = proc_dointvec
831 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +0200832 {
833 .procname = "tcp_orphan_retries",
834 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
835 .maxlen = sizeof(int),
836 .mode = 0644,
837 .proc_handler = proc_dointvec
838 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +0200839 {
840 .procname = "tcp_fin_timeout",
841 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
842 .maxlen = sizeof(int),
843 .mode = 0644,
844 .proc_handler = proc_dointvec_jiffies,
845 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200846 {
847 .procname = "tcp_notsent_lowat",
848 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
849 .maxlen = sizeof(unsigned int),
850 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +0300851 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200852 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800853 {
854 .procname = "tcp_tw_reuse",
855 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
856 .maxlen = sizeof(int),
857 .mode = 0644,
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -0700858 .proc_handler = proc_dointvec_minmax,
859 .extra1 = &zero,
860 .extra2 = &two,
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800861 },
Haishuang Yan1946e672016-12-28 17:52:32 +0800862 {
863 .procname = "tcp_max_tw_buckets",
864 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
865 .maxlen = sizeof(int),
866 .mode = 0644,
867 .proc_handler = proc_dointvec
868 },
869 {
Haishuang Yanfee83d02016-12-28 17:52:33 +0800870 .procname = "tcp_max_syn_backlog",
871 .data = &init_net.ipv4.sysctl_max_syn_backlog,
872 .maxlen = sizeof(int),
873 .mode = 0644,
874 .proc_handler = proc_dointvec
875 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +0800876 {
877 .procname = "tcp_fastopen",
878 .data = &init_net.ipv4.sysctl_tcp_fastopen,
879 .maxlen = sizeof(int),
880 .mode = 0644,
881 .proc_handler = proc_dointvec,
882 },
Haishuang Yan43713842017-09-27 11:35:42 +0800883 {
884 .procname = "tcp_fastopen_key",
885 .mode = 0600,
886 .data = &init_net.ipv4.sysctl_tcp_fastopen,
887 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
888 .proc_handler = proc_tcp_fastopen_key,
889 },
Haishuang Yan3733be12017-09-27 11:35:43 +0800890 {
891 .procname = "tcp_fastopen_blackhole_timeout_sec",
892 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
893 .maxlen = sizeof(int),
894 .mode = 0644,
895 .proc_handler = proc_tfo_blackhole_detect_timeout,
896 .extra1 = &zero,
897 },
David Aherna6db4492016-04-07 07:21:00 -0700898#ifdef CONFIG_IP_ROUTE_MULTIPATH
899 {
900 .procname = "fib_multipath_use_neigh",
901 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = proc_dointvec_minmax,
905 .extra1 = &zero,
906 .extra2 = &one,
907 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200908 {
909 .procname = "fib_multipath_hash_policy",
910 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
911 .maxlen = sizeof(int),
912 .mode = 0644,
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100913 .proc_handler = proc_fib_multipath_hash_policy,
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200914 .extra1 = &zero,
915 .extra2 = &one,
916 },
David Aherna6db4492016-04-07 07:21:00 -0700917#endif
Krister Johansen4548b682017-01-20 17:49:11 -0800918 {
919 .procname = "ip_unprivileged_port_start",
920 .maxlen = sizeof(int),
921 .data = &init_net.ipv4.sysctl_ip_prot_sock,
922 .mode = 0644,
923 .proc_handler = ipv4_privileged_ports,
924 },
Robert Shearman63a6fff2017-01-26 18:02:24 +0000925#ifdef CONFIG_NET_L3_MASTER_DEV
926 {
927 .procname = "udp_l3mdev_accept",
928 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
929 .maxlen = sizeof(int),
930 .mode = 0644,
931 .proc_handler = proc_dointvec_minmax,
932 .extra1 = &zero,
933 .extra2 = &one,
934 },
935#endif
Eric Dumazetf9301032017-06-07 10:34:37 -0700936 {
937 .procname = "tcp_sack",
938 .data = &init_net.ipv4.sysctl_tcp_sack,
939 .maxlen = sizeof(int),
940 .mode = 0644,
941 .proc_handler = proc_dointvec
942 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -0700943 {
944 .procname = "tcp_window_scaling",
945 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
946 .maxlen = sizeof(int),
947 .mode = 0644,
948 .proc_handler = proc_dointvec
949 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -0700950 {
951 .procname = "tcp_timestamps",
952 .data = &init_net.ipv4.sysctl_tcp_timestamps,
953 .maxlen = sizeof(int),
954 .mode = 0644,
955 .proc_handler = proc_dointvec
956 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -0700957 {
958 .procname = "tcp_early_retrans",
959 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
960 .maxlen = sizeof(int),
961 .mode = 0644,
962 .proc_handler = proc_dointvec_minmax,
963 .extra1 = &zero,
964 .extra2 = &four,
965 },
Eric Dumazete20223f2017-10-26 21:54:57 -0700966 {
967 .procname = "tcp_recovery",
968 .data = &init_net.ipv4.sysctl_tcp_recovery,
969 .maxlen = sizeof(int),
970 .mode = 0644,
971 .proc_handler = proc_dointvec,
972 },
Eric Dumazet2c04ac82017-10-26 21:54:58 -0700973 {
974 .procname = "tcp_thin_linear_timeouts",
975 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
976 .maxlen = sizeof(int),
977 .mode = 0644,
978 .proc_handler = proc_dointvec
979 },
Eric Dumazetb510f0d2017-10-26 21:54:59 -0700980 {
981 .procname = "tcp_slow_start_after_idle",
982 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
983 .maxlen = sizeof(int),
984 .mode = 0644,
985 .proc_handler = proc_dointvec
986 },
Eric Dumazete0a1e5b2017-10-26 21:55:00 -0700987 {
988 .procname = "tcp_retrans_collapse",
989 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = proc_dointvec
993 },
Eric Dumazet3f4c7c62017-10-26 21:55:01 -0700994 {
995 .procname = "tcp_stdurg",
996 .data = &init_net.ipv4.sysctl_tcp_stdurg,
997 .maxlen = sizeof(int),
998 .mode = 0644,
999 .proc_handler = proc_dointvec
1000 },
Eric Dumazet625357a2017-10-26 21:55:02 -07001001 {
1002 .procname = "tcp_rfc1337",
1003 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1004 .maxlen = sizeof(int),
1005 .mode = 0644,
1006 .proc_handler = proc_dointvec
1007 },
Eric Dumazet65c94102017-10-26 21:55:03 -07001008 {
1009 .procname = "tcp_abort_on_overflow",
1010 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = proc_dointvec
1014 },
Eric Dumazet0bc65a22017-10-26 21:55:04 -07001015 {
1016 .procname = "tcp_fack",
1017 .data = &init_net.ipv4.sysctl_tcp_fack,
1018 .maxlen = sizeof(int),
1019 .mode = 0644,
1020 .proc_handler = proc_dointvec
1021 },
Eric Dumazetc6e21802017-10-26 21:55:06 -07001022 {
1023 .procname = "tcp_max_reordering",
1024 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec
1028 },
Eric Dumazet6496f6b2017-10-26 21:55:07 -07001029 {
1030 .procname = "tcp_dsack",
1031 .data = &init_net.ipv4.sysctl_tcp_dsack,
1032 .maxlen = sizeof(int),
1033 .mode = 0644,
1034 .proc_handler = proc_dointvec
1035 },
Eric Dumazet0c126542017-10-26 21:55:08 -07001036 {
1037 .procname = "tcp_app_win",
1038 .data = &init_net.ipv4.sysctl_tcp_app_win,
1039 .maxlen = sizeof(int),
1040 .mode = 0644,
1041 .proc_handler = proc_dointvec
1042 },
Eric Dumazet94f08932017-10-26 21:55:09 -07001043 {
1044 .procname = "tcp_adv_win_scale",
1045 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
1048 .proc_handler = proc_dointvec_minmax,
1049 .extra1 = &tcp_adv_win_scale_min,
1050 .extra2 = &tcp_adv_win_scale_max,
1051 },
Eric Dumazetaf9b69a2017-10-26 21:55:10 -07001052 {
1053 .procname = "tcp_frto",
1054 .data = &init_net.ipv4.sysctl_tcp_frto,
1055 .maxlen = sizeof(int),
1056 .mode = 0644,
1057 .proc_handler = proc_dointvec
1058 },
Eric Dumazetec36e412017-10-27 07:47:21 -07001059 {
1060 .procname = "tcp_no_metrics_save",
1061 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1062 .maxlen = sizeof(int),
1063 .mode = 0644,
1064 .proc_handler = proc_dointvec,
1065 },
Eric Dumazet4540c0c2017-10-27 07:47:22 -07001066 {
1067 .procname = "tcp_moderate_rcvbuf",
1068 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1069 .maxlen = sizeof(int),
1070 .mode = 0644,
1071 .proc_handler = proc_dointvec,
1072 },
Eric Dumazetd06a9902017-10-27 07:47:23 -07001073 {
1074 .procname = "tcp_tso_win_divisor",
1075 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1076 .maxlen = sizeof(int),
1077 .mode = 0644,
1078 .proc_handler = proc_dointvec,
1079 },
Eric Dumazetceef9ab2017-10-27 07:47:24 -07001080 {
1081 .procname = "tcp_workaround_signed_windows",
1082 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1083 .maxlen = sizeof(int),
1084 .mode = 0644,
1085 .proc_handler = proc_dointvec
1086 },
Eric Dumazet9184d8b2017-10-27 07:47:25 -07001087 {
1088 .procname = "tcp_limit_output_bytes",
1089 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
1092 .proc_handler = proc_dointvec
1093 },
Eric Dumazetb530b682017-10-27 07:47:26 -07001094 {
1095 .procname = "tcp_challenge_ack_limit",
1096 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1097 .maxlen = sizeof(int),
1098 .mode = 0644,
1099 .proc_handler = proc_dointvec
1100 },
Eric Dumazet26e95962017-10-27 07:47:27 -07001101 {
1102 .procname = "tcp_min_tso_segs",
1103 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = proc_dointvec_minmax,
1107 .extra1 = &one,
1108 .extra2 = &gso_max_segs,
1109 },
Eric Dumazetbd239702017-10-27 07:47:28 -07001110 {
1111 .procname = "tcp_min_rtt_wlen",
1112 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1113 .maxlen = sizeof(int),
1114 .mode = 0644,
1115 .proc_handler = proc_dointvec
1116 },
Eric Dumazet790f00e2017-10-27 07:47:29 -07001117 {
1118 .procname = "tcp_autocorking",
1119 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1120 .maxlen = sizeof(int),
1121 .mode = 0644,
1122 .proc_handler = proc_dointvec_minmax,
1123 .extra1 = &zero,
1124 .extra2 = &one,
1125 },
Eric Dumazet4170ba62017-10-27 07:47:30 -07001126 {
1127 .procname = "tcp_invalid_ratelimit",
1128 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1129 .maxlen = sizeof(int),
1130 .mode = 0644,
1131 .proc_handler = proc_dointvec_ms_jiffies,
1132 },
Eric Dumazet23a7102a2017-10-27 07:47:31 -07001133 {
1134 .procname = "tcp_pacing_ss_ratio",
1135 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1136 .maxlen = sizeof(int),
1137 .mode = 0644,
1138 .proc_handler = proc_dointvec_minmax,
1139 .extra1 = &zero,
1140 .extra2 = &thousand,
1141 },
Eric Dumazetc26e91f2017-10-27 07:47:32 -07001142 {
1143 .procname = "tcp_pacing_ca_ratio",
1144 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1145 .maxlen = sizeof(int),
1146 .mode = 0644,
1147 .proc_handler = proc_dointvec_minmax,
1148 .extra1 = &zero,
1149 .extra2 = &thousand,
1150 },
Eric Dumazet356d1832017-11-07 00:29:28 -08001151 {
1152 .procname = "tcp_wmem",
1153 .data = &init_net.ipv4.sysctl_tcp_wmem,
1154 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1155 .mode = 0644,
1156 .proc_handler = proc_dointvec_minmax,
1157 .extra1 = &one,
1158 },
1159 {
1160 .procname = "tcp_rmem",
1161 .data = &init_net.ipv4.sysctl_tcp_rmem,
1162 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1163 .mode = 0644,
1164 .proc_handler = proc_dointvec_minmax,
1165 .extra1 = &one,
1166 },
Tonghao Zhang1e802952018-03-13 21:57:16 -07001167 {
Eric Dumazet6d82aa22018-05-17 14:47:28 -07001168 .procname = "tcp_comp_sack_delay_ns",
1169 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1170 .maxlen = sizeof(unsigned long),
1171 .mode = 0644,
1172 .proc_handler = proc_doulongvec_minmax,
1173 },
1174 {
Eric Dumazet9c21d2f2018-05-17 14:47:29 -07001175 .procname = "tcp_comp_sack_nr",
1176 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1177 .maxlen = sizeof(int),
1178 .mode = 0644,
1179 .proc_handler = proc_dointvec_minmax,
1180 .extra1 = &zero,
1181 .extra2 = &comp_sack_nr_max,
1182 },
1183 {
Tonghao Zhang1e802952018-03-13 21:57:16 -07001184 .procname = "udp_rmem_min",
1185 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1186 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1187 .mode = 0644,
1188 .proc_handler = proc_dointvec_minmax,
1189 .extra1 = &one
1190 },
1191 {
1192 .procname = "udp_wmem_min",
1193 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1194 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1195 .mode = 0644,
1196 .proc_handler = proc_dointvec_minmax,
1197 .extra1 = &one
1198 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001199 { }
1200};
1201
Pavel Emelyanov15775192008-03-26 01:54:18 -07001202static __net_init int ipv4_sysctl_init_net(struct net *net)
1203{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001204 struct ctl_table *table;
1205
1206 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001207 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001208 int i;
1209
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001210 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001211 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001212 goto err_alloc;
1213
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001214 /* Update the variables to point into the current struct net */
1215 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1216 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001217 }
1218
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001219 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001220 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001221 goto err_reg;
1222
WANG Cong122ff242014-05-12 16:04:53 -07001223 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1224 if (!net->ipv4.sysctl_local_reserved_ports)
1225 goto err_ports;
1226
Pavel Emelyanov15775192008-03-26 01:54:18 -07001227 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001228
WANG Cong122ff242014-05-12 16:04:53 -07001229err_ports:
1230 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001231err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001232 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001233 kfree(table);
1234err_alloc:
1235 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001236}
1237
1238static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1239{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001240 struct ctl_table *table;
1241
WANG Cong122ff242014-05-12 16:04:53 -07001242 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001243 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1244 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1245 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001246}
1247
1248static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1249 .init = ipv4_sysctl_init_net,
1250 .exit = ipv4_sysctl_exit_net,
1251};
1252
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001253static __init int sysctl_ipv4_init(void)
1254{
1255 struct ctl_table_header *hdr;
1256
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001257 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001258 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001259 return -ENOMEM;
1260
1261 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001262 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001263 return -ENOMEM;
1264 }
1265
1266 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001267}
1268
1269__initcall(sysctl_ipv4_init);