blob: 875867b64d6a6597bf4fcd3498ed55741cbe33f7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
7 */
8
9#include <linux/mm.h>
10#include <linux/module.h>
11#include <linux/sysctl.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030012#include <linux/igmp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020013#include <linux/inetdevice.h>
Stephen Hemminger227b60f2007-10-10 17:30:46 -070014#include <linux/seqlock.h>
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -080015#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000017#include <linux/nsproxy.h>
Glauber Costa3dc43e32011-12-11 21:47:05 +000018#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030020#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <net/ip.h>
22#include <net/route.h>
23#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080024#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070025#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070026#include <net/inet_frag.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000027#include <net/ping.h>
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060028#include <net/protocol.h>
Ido Schimmel3ae6ec02017-11-02 17:14:05 +010029#include <net/netevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Herbert Xu89cee8b2005-12-13 23:14:27 -080031static int zero;
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +000032static int one = 1;
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -070033static int two = 2;
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +000034static int four = 4;
Eric Dumazet43e122b2015-08-21 17:38:02 -070035static int thousand = 1000;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070036static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090037static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static int ip_local_port_range_min[] = { 1, 1 };
39static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000040static int tcp_adv_win_scale_min = -31;
41static int tcp_adv_win_scale_max = 31;
Krister Johansen4548b682017-01-20 17:49:11 -080042static int ip_privileged_port_min;
43static int ip_privileged_port_max = 65535;
Eric Dumazet249fab72010-12-13 12:16:14 -080044static int ip_ttl_min = 1;
45static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020046static int tcp_syn_retries_min = 1;
47static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000048static int ip_ping_group_range_min[] = { 0, 0 };
49static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Eric Dumazet9c21d2f2018-05-17 14:47:29 -070050static int comp_sack_nr_max = 255;
Maciej Żenczykowskid4ce5802018-09-25 21:59:28 -070051static u32 u32_max_div_HZ = UINT_MAX / HZ;
ZhangXiaoxu19fad202019-04-16 09:47:24 +080052static int one_day_secs = 24 * 3600;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Florian Westphalb6690b12017-07-30 03:57:20 +020054/* obsolete */
55static int sysctl_tcp_low_latency __read_mostly;
56
Stephen Hemminger227b60f2007-10-10 17:30:46 -070057/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070058static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070059{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070060 bool same_parity = !((range[0] ^ range[1]) & 1);
61
WANG Cong4ee3bd42015-11-03 14:32:57 -080062 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070063 if (same_parity && !net->ipv4.ip_local_ports.warned) {
64 net->ipv4.ip_local_ports.warned = true;
65 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
66 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070067 net->ipv4.ip_local_ports.range[0] = range[0];
68 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080069 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070070}
71
72/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070073static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070074 void __user *buffer,
75 size_t *lenp, loff_t *ppos)
76{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070077 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070078 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070079 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070080 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070081 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070082 .data = &range,
83 .maxlen = sizeof(range),
84 .mode = table->mode,
85 .extra1 = &ip_local_port_range_min,
86 .extra2 = &ip_local_port_range_max,
87 };
88
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070089 inet_get_local_port_range(net, &range[0], &range[1]);
90
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070091 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070092
93 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080094 /* Ensure that the upper limit is not smaller than the lower,
95 * and that the lower does not encroach upon the privileged
96 * port limit.
97 */
98 if ((range[1] < range[0]) ||
99 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -0700100 ret = -EINVAL;
101 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700102 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -0700103 }
104
105 return ret;
106}
107
Krister Johansen4548b682017-01-20 17:49:11 -0800108/* Validate changes from /proc interface. */
109static int ipv4_privileged_ports(struct ctl_table *table, int write,
110 void __user *buffer, size_t *lenp, loff_t *ppos)
111{
112 struct net *net = container_of(table->data, struct net,
113 ipv4.sysctl_ip_prot_sock);
114 int ret;
115 int pports;
116 int range[2];
117 struct ctl_table tmp = {
118 .data = &pports,
119 .maxlen = sizeof(pports),
120 .mode = table->mode,
121 .extra1 = &ip_privileged_port_min,
122 .extra2 = &ip_privileged_port_max,
123 };
124
125 pports = net->ipv4.sysctl_ip_prot_sock;
126
127 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
128
129 if (write && ret == 0) {
130 inet_get_local_port_range(net, &range[0], &range[1]);
131 /* Ensure that the local port range doesn't overlap with the
132 * privileged port range.
133 */
134 if (range[0] < pports)
135 ret = -EINVAL;
136 else
137 net->ipv4.sysctl_ip_prot_sock = pports;
138 }
139
140 return ret;
141}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000142
Eric W. Biederman7064d162012-05-24 10:34:21 -0600143static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000144{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600145 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700146 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700147 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000148 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000149 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700150 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000151
152 *low = data[0];
153 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700154 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000155}
156
157/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600158static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000159{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600160 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700161 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700162 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700163 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600164 data[0] = low;
165 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700166 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000167}
168
169/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700170static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000171 void __user *buffer,
172 size_t *lenp, loff_t *ppos)
173{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600174 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000175 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600176 gid_t urange[2];
177 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700178 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600179 .data = &urange,
180 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000181 .mode = table->mode,
182 .extra1 = &ip_ping_group_range_min,
183 .extra2 = &ip_ping_group_range_max,
184 };
185
Eric W. Biederman7064d162012-05-24 10:34:21 -0600186 inet_get_ping_group_range_table(table, &low, &high);
187 urange[0] = from_kgid_munged(user_ns, low);
188 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000189 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
190
Eric W. Biederman7064d162012-05-24 10:34:21 -0600191 if (write && ret == 0) {
192 low = make_kgid(user_ns, urange[0]);
193 high = make_kgid(user_ns, urange[1]);
Tyler Hicks70ba5b62018-07-05 18:49:23 +0000194 if (!gid_valid(low) || !gid_valid(high))
195 return -EINVAL;
196 if (urange[1] < urange[0] || gid_lt(high, low)) {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600197 low = make_kgid(&init_user_ns, 1);
198 high = make_kgid(&init_user_ns, 0);
199 }
200 set_ping_group_range(table, low, high);
201 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000202
203 return ret;
204}
205
Petr Machatad18c5d12018-08-01 00:36:42 +0200206static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
207 void __user *buffer,
208 size_t *lenp, loff_t *ppos)
209{
210 struct net *net;
211 int ret;
212
213 net = container_of(table->data, struct net,
214 ipv4.sysctl_ip_fwd_update_priority);
215 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
216 if (write && ret == 0)
217 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
218 net);
219
220 return ret;
221}
222
Joe Perchesfe2c6332013-06-11 23:04:25 -0700223static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700224 void __user *buffer, size_t *lenp, loff_t *ppos)
225{
Stephen Hemminger6670e152017-11-14 08:25:49 -0800226 struct net *net = container_of(ctl->data, struct net,
227 ipv4.tcp_congestion_control);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700228 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700229 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700230 .data = val,
231 .maxlen = TCP_CA_NAME_MAX,
232 };
233 int ret;
234
Stephen Hemminger6670e152017-11-14 08:25:49 -0800235 tcp_get_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700236
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700237 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700238 if (write && ret == 0)
Stephen Hemminger6670e152017-11-14 08:25:49 -0800239 ret = tcp_set_default_congestion_control(net, val);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700240 return ret;
241}
242
Joe Perchesfe2c6332013-06-11 23:04:25 -0700243static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700244 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800245 void __user *buffer, size_t *lenp,
246 loff_t *ppos)
247{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700248 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800249 int ret;
250
251 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
252 if (!tbl.data)
253 return -ENOMEM;
254 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700255 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800256 kfree(tbl.data);
257 return ret;
258}
259
Joe Perchesfe2c6332013-06-11 23:04:25 -0700260static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700261 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800262 void __user *buffer, size_t *lenp,
263 loff_t *ppos)
264{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700265 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800266 int ret;
267
268 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
269 if (!tbl.data)
270 return -ENOMEM;
271
272 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700273 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800274 if (write && ret == 0)
275 ret = tcp_set_allowed_congestion_control(tbl.data);
276 kfree(tbl.data);
277 return ret;
278}
279
Haishuang Yan43713842017-09-27 11:35:42 +0800280static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
Joe Perchesfe2c6332013-06-11 23:04:25 -0700281 void __user *buffer, size_t *lenp,
282 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000283{
Haishuang Yan43713842017-09-27 11:35:42 +0800284 struct net *net = container_of(table->data, struct net,
285 ipv4.sysctl_tcp_fastopen);
Joe Perchesfe2c6332013-06-11 23:04:25 -0700286 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000287 struct tcp_fastopen_context *ctxt;
Jerry Chu10467162012-08-31 12:29:11 +0000288 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
Yuchung Chengc860e992018-06-27 16:04:48 -0700289 __le32 key[4];
290 int ret, i;
Jerry Chu10467162012-08-31 12:29:11 +0000291
292 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
293 if (!tbl.data)
294 return -ENOMEM;
295
296 rcu_read_lock();
Haishuang Yan43713842017-09-27 11:35:42 +0800297 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
Jerry Chu10467162012-08-31 12:29:11 +0000298 if (ctxt)
Yuchung Chengc860e992018-06-27 16:04:48 -0700299 memcpy(key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000300 else
Yuchung Chengc860e992018-06-27 16:04:48 -0700301 memset(key, 0, sizeof(key));
Jerry Chu10467162012-08-31 12:29:11 +0000302 rcu_read_unlock();
303
Yuchung Chengc860e992018-06-27 16:04:48 -0700304 for (i = 0; i < ARRAY_SIZE(key); i++)
305 user_key[i] = le32_to_cpu(key[i]);
306
Jerry Chu10467162012-08-31 12:29:11 +0000307 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
308 user_key[0], user_key[1], user_key[2], user_key[3]);
309 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
310
311 if (write && ret == 0) {
312 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
313 user_key + 2, user_key + 3) != 4) {
314 ret = -EINVAL;
315 goto bad_key;
316 }
Yuchung Chengc860e992018-06-27 16:04:48 -0700317
318 for (i = 0; i < ARRAY_SIZE(user_key); i++)
319 key[i] = cpu_to_le32(user_key[i]);
320
321 tcp_fastopen_reset_cipher(net, NULL, key,
Yuchung Cheng1fba70e2017-10-18 11:22:51 -0700322 TCP_FASTOPEN_KEY_LENGTH);
Jerry Chu10467162012-08-31 12:29:11 +0000323 }
324
325bad_key:
326 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
Yuchung Chengc860e992018-06-27 16:04:48 -0700327 user_key[0], user_key[1], user_key[2], user_key[3],
Jerry Chu10467162012-08-31 12:29:11 +0000328 (char *)tbl.data, ret);
329 kfree(tbl.data);
330 return ret;
331}
332
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600333static void proc_configure_early_demux(int enabled, int protocol)
334{
335 struct net_protocol *ipprot;
336#if IS_ENABLED(CONFIG_IPV6)
337 struct inet6_protocol *ip6prot;
338#endif
339
David Ahern58c4c6a2017-04-22 09:33:16 -0700340 rcu_read_lock();
341
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600342 ipprot = rcu_dereference(inet_protos[protocol]);
343 if (ipprot)
344 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
345 NULL;
346
347#if IS_ENABLED(CONFIG_IPV6)
348 ip6prot = rcu_dereference(inet6_protos[protocol]);
349 if (ip6prot)
350 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
351 NULL;
352#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700353 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600354}
355
356static int proc_tcp_early_demux(struct ctl_table *table, int write,
357 void __user *buffer, size_t *lenp, loff_t *ppos)
358{
359 int ret = 0;
360
361 ret = proc_dointvec(table, write, buffer, lenp, ppos);
362
363 if (write && !ret) {
364 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
365
366 proc_configure_early_demux(enabled, IPPROTO_TCP);
367 }
368
369 return ret;
370}
371
372static int proc_udp_early_demux(struct ctl_table *table, int write,
373 void __user *buffer, size_t *lenp, loff_t *ppos)
374{
375 int ret = 0;
376
377 ret = proc_dointvec(table, write, buffer, lenp, ppos);
378
379 if (write && !ret) {
380 int enabled = init_net.ipv4.sysctl_udp_early_demux;
381
382 proc_configure_early_demux(enabled, IPPROTO_UDP);
383 }
384
385 return ret;
386}
387
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700388static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
389 int write,
390 void __user *buffer,
391 size_t *lenp, loff_t *ppos)
392{
Haishuang Yan3733be12017-09-27 11:35:43 +0800393 struct net *net = container_of(table->data, struct net,
394 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700395 int ret;
396
397 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
398 if (write && ret == 0)
Haishuang Yan3733be12017-09-27 11:35:43 +0800399 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson734942c2017-06-14 11:37:14 -0700400
401 return ret;
402}
403
404static int proc_tcp_available_ulp(struct ctl_table *ctl,
405 int write,
406 void __user *buffer, size_t *lenp,
407 loff_t *ppos)
408{
409 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
410 int ret;
411
412 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
413 if (!tbl.data)
414 return -ENOMEM;
415 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
416 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
417 kfree(tbl.data);
418
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700419 return ret;
420}
421
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100422#ifdef CONFIG_IP_ROUTE_MULTIPATH
423static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
424 void __user *buffer, size_t *lenp,
425 loff_t *ppos)
426{
427 struct net *net = container_of(table->data, struct net,
428 ipv4.sysctl_fib_multipath_hash_policy);
429 int ret;
430
431 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
432 if (write && ret == 0)
David Ahern3192dac2018-03-02 08:32:16 -0800433 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100434
435 return ret;
436}
437#endif
438
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800439static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900440 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 .procname = "tcp_max_orphans",
442 .data = &sysctl_tcp_max_orphans,
443 .maxlen = sizeof(int),
444 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800445 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 },
447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 .procname = "inet_peer_threshold",
449 .data = &inet_peer_threshold,
450 .maxlen = sizeof(int),
451 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800452 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 },
454 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 .procname = "inet_peer_minttl",
456 .data = &inet_peer_minttl,
457 .maxlen = sizeof(int),
458 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800459 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 },
461 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 .procname = "inet_peer_maxttl",
463 .data = &inet_peer_maxttl,
464 .maxlen = sizeof(int),
465 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800466 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 },
468 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700469 .procname = "tcp_mem",
470 .maxlen = sizeof(sysctl_tcp_mem),
471 .data = &sysctl_tcp_mem,
472 .mode = 0644,
473 .proc_handler = proc_doulongvec_minmax,
474 },
475 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 .procname = "tcp_low_latency",
477 .data = &sysctl_tcp_low_latency,
478 .maxlen = sizeof(int),
479 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800480 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 },
Paul Moore446fda42006-08-03 16:48:06 -0700482#ifdef CONFIG_NETLABEL
483 {
Paul Moore446fda42006-08-03 16:48:06 -0700484 .procname = "cipso_cache_enable",
485 .data = &cipso_v4_cache_enabled,
486 .maxlen = sizeof(int),
487 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800488 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700489 },
490 {
Paul Moore446fda42006-08-03 16:48:06 -0700491 .procname = "cipso_cache_bucket_size",
492 .data = &cipso_v4_cache_bucketsize,
493 .maxlen = sizeof(int),
494 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800495 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700496 },
497 {
Paul Moore446fda42006-08-03 16:48:06 -0700498 .procname = "cipso_rbm_optfmt",
499 .data = &cipso_v4_rbm_optfmt,
500 .maxlen = sizeof(int),
501 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800502 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700503 },
504 {
Paul Moore446fda42006-08-03 16:48:06 -0700505 .procname = "cipso_rbm_strictvalid",
506 .data = &cipso_v4_rbm_strictvalid,
507 .maxlen = sizeof(int),
508 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800509 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700510 },
511#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800512 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800513 .procname = "tcp_available_congestion_control",
514 .maxlen = TCP_CA_BUF_MAX,
515 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800516 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800517 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800518 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800519 .procname = "tcp_allowed_congestion_control",
520 .maxlen = TCP_CA_BUF_MAX,
521 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800522 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800523 },
John Heffner886236c2007-03-25 19:21:45 -0700524 {
Dave Watson734942c2017-06-14 11:37:14 -0700525 .procname = "tcp_available_ulp",
526 .maxlen = TCP_ULP_BUF_MAX,
527 .mode = 0444,
528 .proc_handler = proc_tcp_available_ulp,
529 },
530 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700531 .procname = "icmp_msgs_per_sec",
532 .data = &sysctl_icmp_msgs_per_sec,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = proc_dointvec_minmax,
536 .extra1 = &zero,
537 },
538 {
539 .procname = "icmp_msgs_burst",
540 .data = &sysctl_icmp_msgs_burst,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = proc_dointvec_minmax,
544 .extra1 = &zero,
545 },
546 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800547 .procname = "udp_mem",
548 .data = &sysctl_udp_mem,
549 .maxlen = sizeof(sysctl_udp_mem),
550 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000551 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800552 },
David Ahern9ab948a2019-03-20 09:18:59 -0700553 {
554 .procname = "fib_sync_mem",
555 .data = &sysctl_fib_sync_mem,
556 .maxlen = sizeof(sysctl_fib_sync_mem),
557 .mode = 0644,
558 .proc_handler = proc_douintvec_minmax,
559 .extra1 = &sysctl_fib_sync_mem_min,
560 .extra2 = &sysctl_fib_sync_mem_max,
561 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800562 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800564
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700565static struct ctl_table ipv4_net_table[] = {
566 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700567 .procname = "icmp_echo_ignore_all",
568 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
569 .maxlen = sizeof(int),
570 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800571 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700572 },
573 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700574 .procname = "icmp_echo_ignore_broadcasts",
575 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
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 },
580 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700581 .procname = "icmp_ignore_bogus_error_responses",
582 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
583 .maxlen = sizeof(int),
584 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800585 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700586 },
587 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700588 .procname = "icmp_errors_use_inbound_ifaddr",
589 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
590 .maxlen = sizeof(int),
591 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800592 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700593 },
594 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700595 .procname = "icmp_ratelimit",
596 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
597 .maxlen = sizeof(int),
598 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800599 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700600 },
601 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700602 .procname = "icmp_ratemask",
603 .data = &init_net.ipv4.sysctl_icmp_ratemask,
604 .maxlen = sizeof(int),
605 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800606 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700607 },
Neil Horman1080d702008-10-27 12:28:25 -0700608 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000609 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700610 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600611 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000612 .mode = 0644,
613 .proc_handler = ipv4_ping_group_range,
614 },
Mike Manning68974452018-11-07 15:36:05 +0000615#ifdef CONFIG_NET_L3_MASTER_DEV
616 {
617 .procname = "raw_l3mdev_accept",
618 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
619 .maxlen = sizeof(int),
620 .mode = 0644,
621 .proc_handler = proc_dointvec_minmax,
622 .extra1 = &zero,
623 .extra2 = &one,
624 },
625#endif
Glauber Costa3dc43e32011-12-11 21:47:05 +0000626 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000627 .procname = "tcp_ecn",
628 .data = &init_net.ipv4.sysctl_tcp_ecn,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = proc_dointvec
632 },
633 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200634 .procname = "tcp_ecn_fallback",
635 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = proc_dointvec
639 },
640 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200641 .procname = "ip_dynaddr",
642 .data = &init_net.ipv4.sysctl_ip_dynaddr,
643 .maxlen = sizeof(int),
644 .mode = 0644,
645 .proc_handler = proc_dointvec
646 },
647 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200648 .procname = "ip_early_demux",
649 .data = &init_net.ipv4.sysctl_ip_early_demux,
650 .maxlen = sizeof(int),
651 .mode = 0644,
652 .proc_handler = proc_dointvec
653 },
654 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600655 .procname = "udp_early_demux",
656 .data = &init_net.ipv4.sysctl_udp_early_demux,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 .proc_handler = proc_udp_early_demux
660 },
661 {
662 .procname = "tcp_early_demux",
663 .data = &init_net.ipv4.sysctl_tcp_early_demux,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = proc_tcp_early_demux
667 },
668 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200669 .procname = "ip_default_ttl",
670 .data = &init_net.ipv4.sysctl_ip_default_ttl,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = proc_dointvec_minmax,
674 .extra1 = &ip_ttl_min,
675 .extra2 = &ip_ttl_max,
676 },
677 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700678 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700679 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
680 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700681 .mode = 0644,
682 .proc_handler = ipv4_local_port_range,
683 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100684 {
WANG Cong122ff242014-05-12 16:04:53 -0700685 .procname = "ip_local_reserved_ports",
686 .data = &init_net.ipv4.sysctl_local_reserved_ports,
687 .maxlen = 65536,
688 .mode = 0644,
689 .proc_handler = proc_do_large_bitmap,
690 },
691 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100692 .procname = "ip_no_pmtu_disc",
693 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
694 .maxlen = sizeof(int),
695 .mode = 0644,
696 .proc_handler = proc_dointvec
697 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100698 {
699 .procname = "ip_forward_use_pmtu",
700 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
701 .maxlen = sizeof(int),
702 .mode = 0644,
703 .proc_handler = proc_dointvec,
704 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700705 {
Petr Machata432e05d2018-08-01 00:36:03 +0200706 .procname = "ip_forward_update_priority",
707 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
708 .maxlen = sizeof(int),
709 .mode = 0644,
Petr Machatad18c5d12018-08-01 00:36:42 +0200710 .proc_handler = ipv4_fwd_update_priority,
Petr Machata432e05d2018-08-01 00:36:03 +0200711 .extra1 = &zero,
712 .extra2 = &one,
713 },
714 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200715 .procname = "ip_nonlocal_bind",
716 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = proc_dointvec
720 },
721 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700722 .procname = "fwmark_reflect",
723 .data = &init_net.ipv4.sysctl_fwmark_reflect,
724 .maxlen = sizeof(int),
725 .mode = 0644,
726 .proc_handler = proc_dointvec,
727 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700728 {
729 .procname = "tcp_fwmark_accept",
730 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = proc_dointvec,
734 },
David Ahern6dd9a142015-12-16 13:20:44 -0800735#ifdef CONFIG_NET_L3_MASTER_DEV
736 {
737 .procname = "tcp_l3mdev_accept",
738 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
739 .maxlen = sizeof(int),
740 .mode = 0644,
741 .proc_handler = proc_dointvec_minmax,
742 .extra1 = &zero,
743 .extra2 = &one,
744 },
745#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800746 {
747 .procname = "tcp_mtu_probing",
748 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
749 .maxlen = sizeof(int),
750 .mode = 0644,
751 .proc_handler = proc_dointvec,
752 },
753 {
754 .procname = "tcp_base_mss",
755 .data = &init_net.ipv4.sysctl_tcp_base_mss,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = proc_dointvec,
759 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800760 {
761 .procname = "tcp_probe_threshold",
762 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
763 .maxlen = sizeof(int),
764 .mode = 0644,
765 .proc_handler = proc_dointvec,
766 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800767 {
768 .procname = "tcp_probe_interval",
769 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
Maciej Żenczykowskid4ce5802018-09-25 21:59:28 -0700770 .maxlen = sizeof(u32),
Fan Du05cbc0d2015-03-06 11:18:24 +0800771 .mode = 0644,
Maciej Żenczykowskid4ce5802018-09-25 21:59:28 -0700772 .proc_handler = proc_douintvec_minmax,
773 .extra2 = &u32_max_div_HZ,
Fan Du05cbc0d2015-03-06 11:18:24 +0800774 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100775 {
776 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200777 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100778 .maxlen = sizeof(int),
779 .mode = 0644,
780 .proc_handler = proc_dointvec
781 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200782 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200783 .procname = "igmp_max_memberships",
784 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
785 .maxlen = sizeof(int),
786 .mode = 0644,
787 .proc_handler = proc_dointvec
788 },
789 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200790 .procname = "igmp_max_msf",
791 .data = &init_net.ipv4.sysctl_igmp_max_msf,
792 .maxlen = sizeof(int),
793 .mode = 0644,
794 .proc_handler = proc_dointvec
795 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200796#ifdef CONFIG_IP_MULTICAST
797 {
798 .procname = "igmp_qrv",
799 .data = &init_net.ipv4.sysctl_igmp_qrv,
800 .maxlen = sizeof(int),
801 .mode = 0644,
802 .proc_handler = proc_dointvec_minmax,
803 .extra1 = &one
804 },
805#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200806 {
Stephen Hemminger6670e152017-11-14 08:25:49 -0800807 .procname = "tcp_congestion_control",
808 .data = &init_net.ipv4.tcp_congestion_control,
809 .mode = 0644,
810 .maxlen = TCP_CA_NAME_MAX,
811 .proc_handler = proc_tcp_congestion_control,
812 },
813 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200814 .procname = "tcp_keepalive_time",
815 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
816 .maxlen = sizeof(int),
817 .mode = 0644,
818 .proc_handler = proc_dointvec_jiffies,
819 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200820 {
821 .procname = "tcp_keepalive_probes",
822 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = proc_dointvec
826 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200827 {
828 .procname = "tcp_keepalive_intvl",
829 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
830 .maxlen = sizeof(int),
831 .mode = 0644,
832 .proc_handler = proc_dointvec_jiffies,
833 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200834 {
835 .procname = "tcp_syn_retries",
836 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
837 .maxlen = sizeof(int),
838 .mode = 0644,
839 .proc_handler = proc_dointvec_minmax,
840 .extra1 = &tcp_syn_retries_min,
841 .extra2 = &tcp_syn_retries_max
842 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +0200843 {
844 .procname = "tcp_synack_retries",
845 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
846 .maxlen = sizeof(int),
847 .mode = 0644,
848 .proc_handler = proc_dointvec
849 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +0200850#ifdef CONFIG_SYN_COOKIES
851 {
852 .procname = "tcp_syncookies",
853 .data = &init_net.ipv4.sysctl_tcp_syncookies,
854 .maxlen = sizeof(int),
855 .mode = 0644,
856 .proc_handler = proc_dointvec
857 },
858#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +0200859 {
860 .procname = "tcp_reordering",
861 .data = &init_net.ipv4.sysctl_tcp_reordering,
862 .maxlen = sizeof(int),
863 .mode = 0644,
864 .proc_handler = proc_dointvec
865 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +0200866 {
867 .procname = "tcp_retries1",
868 .data = &init_net.ipv4.sysctl_tcp_retries1,
869 .maxlen = sizeof(int),
870 .mode = 0644,
871 .proc_handler = proc_dointvec_minmax,
872 .extra2 = &tcp_retr1_max
873 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +0200874 {
875 .procname = "tcp_retries2",
876 .data = &init_net.ipv4.sysctl_tcp_retries2,
877 .maxlen = sizeof(int),
878 .mode = 0644,
879 .proc_handler = proc_dointvec
880 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +0200881 {
882 .procname = "tcp_orphan_retries",
883 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
884 .maxlen = sizeof(int),
885 .mode = 0644,
886 .proc_handler = proc_dointvec
887 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +0200888 {
889 .procname = "tcp_fin_timeout",
890 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
891 .maxlen = sizeof(int),
892 .mode = 0644,
893 .proc_handler = proc_dointvec_jiffies,
894 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200895 {
896 .procname = "tcp_notsent_lowat",
897 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
898 .maxlen = sizeof(unsigned int),
899 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +0300900 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +0200901 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800902 {
903 .procname = "tcp_tw_reuse",
904 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
905 .maxlen = sizeof(int),
906 .mode = 0644,
Maciej Żenczykowski79e9fed2018-06-03 10:41:17 -0700907 .proc_handler = proc_dointvec_minmax,
908 .extra1 = &zero,
909 .extra2 = &two,
Haishuang Yan56ab6b92016-12-25 14:33:16 +0800910 },
Haishuang Yan1946e672016-12-28 17:52:32 +0800911 {
912 .procname = "tcp_max_tw_buckets",
913 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
914 .maxlen = sizeof(int),
915 .mode = 0644,
916 .proc_handler = proc_dointvec
917 },
918 {
Haishuang Yanfee83d02016-12-28 17:52:33 +0800919 .procname = "tcp_max_syn_backlog",
920 .data = &init_net.ipv4.sysctl_max_syn_backlog,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = proc_dointvec
924 },
Haishuang Yane1cfcbe2017-09-27 11:35:40 +0800925 {
926 .procname = "tcp_fastopen",
927 .data = &init_net.ipv4.sysctl_tcp_fastopen,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
931 },
Haishuang Yan43713842017-09-27 11:35:42 +0800932 {
933 .procname = "tcp_fastopen_key",
934 .mode = 0600,
935 .data = &init_net.ipv4.sysctl_tcp_fastopen,
936 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
937 .proc_handler = proc_tcp_fastopen_key,
938 },
Haishuang Yan3733be12017-09-27 11:35:43 +0800939 {
940 .procname = "tcp_fastopen_blackhole_timeout_sec",
941 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
942 .maxlen = sizeof(int),
943 .mode = 0644,
944 .proc_handler = proc_tfo_blackhole_detect_timeout,
945 .extra1 = &zero,
946 },
David Aherna6db4492016-04-07 07:21:00 -0700947#ifdef CONFIG_IP_ROUTE_MULTIPATH
948 {
949 .procname = "fib_multipath_use_neigh",
950 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
951 .maxlen = sizeof(int),
952 .mode = 0644,
953 .proc_handler = proc_dointvec_minmax,
954 .extra1 = &zero,
955 .extra2 = &one,
956 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200957 {
958 .procname = "fib_multipath_hash_policy",
959 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
960 .maxlen = sizeof(int),
961 .mode = 0644,
Ido Schimmel3ae6ec02017-11-02 17:14:05 +0100962 .proc_handler = proc_fib_multipath_hash_policy,
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +0200963 .extra1 = &zero,
964 .extra2 = &one,
965 },
David Aherna6db4492016-04-07 07:21:00 -0700966#endif
Krister Johansen4548b682017-01-20 17:49:11 -0800967 {
968 .procname = "ip_unprivileged_port_start",
969 .maxlen = sizeof(int),
970 .data = &init_net.ipv4.sysctl_ip_prot_sock,
971 .mode = 0644,
972 .proc_handler = ipv4_privileged_ports,
973 },
Robert Shearman63a6fff2017-01-26 18:02:24 +0000974#ifdef CONFIG_NET_L3_MASTER_DEV
975 {
976 .procname = "udp_l3mdev_accept",
977 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
978 .maxlen = sizeof(int),
979 .mode = 0644,
980 .proc_handler = proc_dointvec_minmax,
981 .extra1 = &zero,
982 .extra2 = &one,
983 },
984#endif
Eric Dumazetf9301032017-06-07 10:34:37 -0700985 {
986 .procname = "tcp_sack",
987 .data = &init_net.ipv4.sysctl_tcp_sack,
988 .maxlen = sizeof(int),
989 .mode = 0644,
990 .proc_handler = proc_dointvec
991 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -0700992 {
993 .procname = "tcp_window_scaling",
994 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
995 .maxlen = sizeof(int),
996 .mode = 0644,
997 .proc_handler = proc_dointvec
998 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -0700999 {
1000 .procname = "tcp_timestamps",
1001 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1002 .maxlen = sizeof(int),
1003 .mode = 0644,
1004 .proc_handler = proc_dointvec
1005 },
Eric Dumazet2ae21cf2017-10-26 21:54:56 -07001006 {
1007 .procname = "tcp_early_retrans",
1008 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
1011 .proc_handler = proc_dointvec_minmax,
1012 .extra1 = &zero,
1013 .extra2 = &four,
1014 },
Eric Dumazete20223f2017-10-26 21:54:57 -07001015 {
1016 .procname = "tcp_recovery",
1017 .data = &init_net.ipv4.sysctl_tcp_recovery,
1018 .maxlen = sizeof(int),
1019 .mode = 0644,
1020 .proc_handler = proc_dointvec,
1021 },
Eric Dumazet2c04ac82017-10-26 21:54:58 -07001022 {
1023 .procname = "tcp_thin_linear_timeouts",
1024 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec
1028 },
Eric Dumazetb510f0d2017-10-26 21:54:59 -07001029 {
1030 .procname = "tcp_slow_start_after_idle",
1031 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1032 .maxlen = sizeof(int),
1033 .mode = 0644,
1034 .proc_handler = proc_dointvec
1035 },
Eric Dumazete0a1e5b2017-10-26 21:55:00 -07001036 {
1037 .procname = "tcp_retrans_collapse",
1038 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1039 .maxlen = sizeof(int),
1040 .mode = 0644,
1041 .proc_handler = proc_dointvec
1042 },
Eric Dumazet3f4c7c62017-10-26 21:55:01 -07001043 {
1044 .procname = "tcp_stdurg",
1045 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
1048 .proc_handler = proc_dointvec
1049 },
Eric Dumazet625357a2017-10-26 21:55:02 -07001050 {
1051 .procname = "tcp_rfc1337",
1052 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1053 .maxlen = sizeof(int),
1054 .mode = 0644,
1055 .proc_handler = proc_dointvec
1056 },
Eric Dumazet65c94102017-10-26 21:55:03 -07001057 {
1058 .procname = "tcp_abort_on_overflow",
1059 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1060 .maxlen = sizeof(int),
1061 .mode = 0644,
1062 .proc_handler = proc_dointvec
1063 },
Eric Dumazet0bc65a22017-10-26 21:55:04 -07001064 {
1065 .procname = "tcp_fack",
1066 .data = &init_net.ipv4.sysctl_tcp_fack,
1067 .maxlen = sizeof(int),
1068 .mode = 0644,
1069 .proc_handler = proc_dointvec
1070 },
Eric Dumazetc6e21802017-10-26 21:55:06 -07001071 {
1072 .procname = "tcp_max_reordering",
1073 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1074 .maxlen = sizeof(int),
1075 .mode = 0644,
1076 .proc_handler = proc_dointvec
1077 },
Eric Dumazet6496f6b2017-10-26 21:55:07 -07001078 {
1079 .procname = "tcp_dsack",
1080 .data = &init_net.ipv4.sysctl_tcp_dsack,
1081 .maxlen = sizeof(int),
1082 .mode = 0644,
1083 .proc_handler = proc_dointvec
1084 },
Eric Dumazet0c126542017-10-26 21:55:08 -07001085 {
1086 .procname = "tcp_app_win",
1087 .data = &init_net.ipv4.sysctl_tcp_app_win,
1088 .maxlen = sizeof(int),
1089 .mode = 0644,
1090 .proc_handler = proc_dointvec
1091 },
Eric Dumazet94f08932017-10-26 21:55:09 -07001092 {
1093 .procname = "tcp_adv_win_scale",
1094 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1095 .maxlen = sizeof(int),
1096 .mode = 0644,
1097 .proc_handler = proc_dointvec_minmax,
1098 .extra1 = &tcp_adv_win_scale_min,
1099 .extra2 = &tcp_adv_win_scale_max,
1100 },
Eric Dumazetaf9b69a2017-10-26 21:55:10 -07001101 {
1102 .procname = "tcp_frto",
1103 .data = &init_net.ipv4.sysctl_tcp_frto,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = proc_dointvec
1107 },
Eric Dumazetec36e412017-10-27 07:47:21 -07001108 {
1109 .procname = "tcp_no_metrics_save",
1110 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1111 .maxlen = sizeof(int),
1112 .mode = 0644,
1113 .proc_handler = proc_dointvec,
1114 },
Eric Dumazet4540c0c2017-10-27 07:47:22 -07001115 {
1116 .procname = "tcp_moderate_rcvbuf",
1117 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1118 .maxlen = sizeof(int),
1119 .mode = 0644,
1120 .proc_handler = proc_dointvec,
1121 },
Eric Dumazetd06a9902017-10-27 07:47:23 -07001122 {
1123 .procname = "tcp_tso_win_divisor",
1124 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1125 .maxlen = sizeof(int),
1126 .mode = 0644,
1127 .proc_handler = proc_dointvec,
1128 },
Eric Dumazetceef9ab2017-10-27 07:47:24 -07001129 {
1130 .procname = "tcp_workaround_signed_windows",
1131 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1132 .maxlen = sizeof(int),
1133 .mode = 0644,
1134 .proc_handler = proc_dointvec
1135 },
Eric Dumazet9184d8b2017-10-27 07:47:25 -07001136 {
1137 .procname = "tcp_limit_output_bytes",
1138 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1139 .maxlen = sizeof(int),
1140 .mode = 0644,
1141 .proc_handler = proc_dointvec
1142 },
Eric Dumazetb530b682017-10-27 07:47:26 -07001143 {
1144 .procname = "tcp_challenge_ack_limit",
1145 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1146 .maxlen = sizeof(int),
1147 .mode = 0644,
1148 .proc_handler = proc_dointvec
1149 },
Eric Dumazet26e95962017-10-27 07:47:27 -07001150 {
1151 .procname = "tcp_min_tso_segs",
1152 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1153 .maxlen = sizeof(int),
1154 .mode = 0644,
1155 .proc_handler = proc_dointvec_minmax,
1156 .extra1 = &one,
1157 .extra2 = &gso_max_segs,
1158 },
Eric Dumazetbd239702017-10-27 07:47:28 -07001159 {
1160 .procname = "tcp_min_rtt_wlen",
1161 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1162 .maxlen = sizeof(int),
1163 .mode = 0644,
ZhangXiaoxu19fad202019-04-16 09:47:24 +08001164 .proc_handler = proc_dointvec_minmax,
1165 .extra1 = &zero,
1166 .extra2 = &one_day_secs
Eric Dumazetbd239702017-10-27 07:47:28 -07001167 },
Eric Dumazet790f00e2017-10-27 07:47:29 -07001168 {
1169 .procname = "tcp_autocorking",
1170 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1171 .maxlen = sizeof(int),
1172 .mode = 0644,
1173 .proc_handler = proc_dointvec_minmax,
1174 .extra1 = &zero,
1175 .extra2 = &one,
1176 },
Eric Dumazet4170ba62017-10-27 07:47:30 -07001177 {
1178 .procname = "tcp_invalid_ratelimit",
1179 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1180 .maxlen = sizeof(int),
1181 .mode = 0644,
1182 .proc_handler = proc_dointvec_ms_jiffies,
1183 },
Eric Dumazet23a7102a2017-10-27 07:47:31 -07001184 {
1185 .procname = "tcp_pacing_ss_ratio",
1186 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1187 .maxlen = sizeof(int),
1188 .mode = 0644,
1189 .proc_handler = proc_dointvec_minmax,
1190 .extra1 = &zero,
1191 .extra2 = &thousand,
1192 },
Eric Dumazetc26e91f2017-10-27 07:47:32 -07001193 {
1194 .procname = "tcp_pacing_ca_ratio",
1195 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1196 .maxlen = sizeof(int),
1197 .mode = 0644,
1198 .proc_handler = proc_dointvec_minmax,
1199 .extra1 = &zero,
1200 .extra2 = &thousand,
1201 },
Eric Dumazet356d1832017-11-07 00:29:28 -08001202 {
1203 .procname = "tcp_wmem",
1204 .data = &init_net.ipv4.sysctl_tcp_wmem,
1205 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1206 .mode = 0644,
1207 .proc_handler = proc_dointvec_minmax,
1208 .extra1 = &one,
1209 },
1210 {
1211 .procname = "tcp_rmem",
1212 .data = &init_net.ipv4.sysctl_tcp_rmem,
1213 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1214 .mode = 0644,
1215 .proc_handler = proc_dointvec_minmax,
1216 .extra1 = &one,
1217 },
Tonghao Zhang1e802952018-03-13 21:57:16 -07001218 {
Eric Dumazet6d82aa22018-05-17 14:47:28 -07001219 .procname = "tcp_comp_sack_delay_ns",
1220 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1221 .maxlen = sizeof(unsigned long),
1222 .mode = 0644,
1223 .proc_handler = proc_doulongvec_minmax,
1224 },
1225 {
Eric Dumazet9c21d2f2018-05-17 14:47:29 -07001226 .procname = "tcp_comp_sack_nr",
1227 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1228 .maxlen = sizeof(int),
1229 .mode = 0644,
1230 .proc_handler = proc_dointvec_minmax,
1231 .extra1 = &zero,
1232 .extra2 = &comp_sack_nr_max,
1233 },
1234 {
Tonghao Zhang1e802952018-03-13 21:57:16 -07001235 .procname = "udp_rmem_min",
1236 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1237 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1238 .mode = 0644,
1239 .proc_handler = proc_dointvec_minmax,
1240 .extra1 = &one
1241 },
1242 {
1243 .procname = "udp_wmem_min",
1244 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1245 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1246 .mode = 0644,
1247 .proc_handler = proc_dointvec_minmax,
1248 .extra1 = &one
1249 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001250 { }
1251};
1252
Pavel Emelyanov15775192008-03-26 01:54:18 -07001253static __net_init int ipv4_sysctl_init_net(struct net *net)
1254{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001255 struct ctl_table *table;
1256
1257 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001258 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001259 int i;
1260
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001261 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001262 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001263 goto err_alloc;
1264
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001265 /* Update the variables to point into the current struct net */
1266 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1267 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001268 }
1269
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001270 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001271 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001272 goto err_reg;
1273
WANG Cong122ff242014-05-12 16:04:53 -07001274 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1275 if (!net->ipv4.sysctl_local_reserved_ports)
1276 goto err_ports;
1277
Pavel Emelyanov15775192008-03-26 01:54:18 -07001278 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001279
WANG Cong122ff242014-05-12 16:04:53 -07001280err_ports:
1281 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001282err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001283 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001284 kfree(table);
1285err_alloc:
1286 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001287}
1288
1289static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1290{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001291 struct ctl_table *table;
1292
WANG Cong122ff242014-05-12 16:04:53 -07001293 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001294 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1295 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1296 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001297}
1298
1299static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1300 .init = ipv4_sysctl_init_net,
1301 .exit = ipv4_sysctl_exit_net,
1302};
1303
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001304static __init int sysctl_ipv4_init(void)
1305{
1306 struct ctl_table_header *hdr;
1307
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001308 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001309 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001310 return -ENOMEM;
1311
1312 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001313 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001314 return -ENOMEM;
1315 }
1316
1317 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001318}
1319
1320__initcall(sysctl_ipv4_init);