blob: 9bf8097260660e7621ba670d59b9991aa6b146fe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Begun April 1, 1996, Mike Shaver.
5 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
6 */
7
8#include <linux/mm.h>
9#include <linux/module.h>
10#include <linux/sysctl.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030011#include <linux/igmp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020012#include <linux/inetdevice.h>
Stephen Hemminger227b60f2007-10-10 17:30:46 -070013#include <linux/seqlock.h>
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -080014#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000016#include <linux/nsproxy.h>
Glauber Costa3dc43e32011-12-11 21:47:05 +000017#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030019#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <net/ip.h>
21#include <net/route.h>
22#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080023#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070024#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070025#include <net/inet_frag.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000026#include <net/ping.h>
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060027#include <net/protocol.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Herbert Xu89cee8b2005-12-13 23:14:27 -080029static int zero;
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +000030static int one = 1;
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +000031static int four = 4;
Eric Dumazet43e122b2015-08-21 17:38:02 -070032static int thousand = 1000;
Eric Dumazet95bd09e2013-08-27 05:46:32 -070033static int gso_max_segs = GSO_MAX_SEGS;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090034static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static int ip_local_port_range_min[] = { 1, 1 };
36static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000037static int tcp_adv_win_scale_min = -31;
38static int tcp_adv_win_scale_max = 31;
Krister Johansen4548b682017-01-20 17:49:11 -080039static int ip_privileged_port_min;
40static int ip_privileged_port_max = 65535;
Eric Dumazet249fab72010-12-13 12:16:14 -080041static int ip_ttl_min = 1;
42static int ip_ttl_max = 255;
Michal Tesar651e9272013-07-19 14:09:01 +020043static int tcp_syn_retries_min = 1;
44static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000045static int ip_ping_group_range_min[] = { 0, 0 };
46static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Stephen Hemminger227b60f2007-10-10 17:30:46 -070048/* Update system visible IP port range */
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070049static void set_local_port_range(struct net *net, int range[2])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070050{
Eric Dumazeted2dfd92015-05-27 11:34:37 -070051 bool same_parity = !((range[0] ^ range[1]) & 1);
52
WANG Cong4ee3bd42015-11-03 14:32:57 -080053 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
Eric Dumazeted2dfd92015-05-27 11:34:37 -070054 if (same_parity && !net->ipv4.ip_local_ports.warned) {
55 net->ipv4.ip_local_ports.warned = true;
56 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
57 }
Cong Wangc9d8f1a2014-05-06 11:02:49 -070058 net->ipv4.ip_local_ports.range[0] = range[0];
59 net->ipv4.ip_local_ports.range[1] = range[1];
WANG Cong4ee3bd42015-11-03 14:32:57 -080060 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070061}
62
63/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -070064static int ipv4_local_port_range(struct ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070065 void __user *buffer,
66 size_t *lenp, loff_t *ppos)
67{
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070068 struct net *net =
Cong Wangc9d8f1a2014-05-06 11:02:49 -070069 container_of(table->data, struct net, ipv4.ip_local_ports.range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070070 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070071 int range[2];
Joe Perchesfe2c6332013-06-11 23:04:25 -070072 struct ctl_table tmp = {
Stephen Hemminger227b60f2007-10-10 17:30:46 -070073 .data = &range,
74 .maxlen = sizeof(range),
75 .mode = table->mode,
76 .extra1 = &ip_local_port_range_min,
77 .extra2 = &ip_local_port_range_max,
78 };
79
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070080 inet_get_local_port_range(net, &range[0], &range[1]);
81
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070082 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070083
84 if (write && ret == 0) {
Krister Johansen4548b682017-01-20 17:49:11 -080085 /* Ensure that the upper limit is not smaller than the lower,
86 * and that the lower does not encroach upon the privileged
87 * port limit.
88 */
89 if ((range[1] < range[0]) ||
90 (range[0] < net->ipv4.sysctl_ip_prot_sock))
Stephen Hemminger227b60f2007-10-10 17:30:46 -070091 ret = -EINVAL;
92 else
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -070093 set_local_port_range(net, range);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070094 }
95
96 return ret;
97}
98
Krister Johansen4548b682017-01-20 17:49:11 -080099/* Validate changes from /proc interface. */
100static int ipv4_privileged_ports(struct ctl_table *table, int write,
101 void __user *buffer, size_t *lenp, loff_t *ppos)
102{
103 struct net *net = container_of(table->data, struct net,
104 ipv4.sysctl_ip_prot_sock);
105 int ret;
106 int pports;
107 int range[2];
108 struct ctl_table tmp = {
109 .data = &pports,
110 .maxlen = sizeof(pports),
111 .mode = table->mode,
112 .extra1 = &ip_privileged_port_min,
113 .extra2 = &ip_privileged_port_max,
114 };
115
116 pports = net->ipv4.sysctl_ip_prot_sock;
117
118 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
119
120 if (write && ret == 0) {
121 inet_get_local_port_range(net, &range[0], &range[1]);
122 /* Ensure that the local port range doesn't overlap with the
123 * privileged port range.
124 */
125 if (range[0] < pports)
126 ret = -EINVAL;
127 else
128 net->ipv4.sysctl_ip_prot_sock = pports;
129 }
130
131 return ret;
132}
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000133
Eric W. Biederman7064d162012-05-24 10:34:21 -0600134static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000135{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600136 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700137 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700138 container_of(table->data, struct net, ipv4.ping_group_range.range);
Eric Dumazet95c96172012-04-15 05:58:06 +0000139 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000140 do {
WANG Cong396a30c2016-10-20 14:19:46 -0700141 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000142
143 *low = data[0];
144 *high = data[1];
WANG Cong396a30c2016-10-20 14:19:46 -0700145 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000146}
147
148/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600149static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000150{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600151 kgid_t *data = table->data;
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700152 struct net *net =
Cong Wangba6b9182014-05-06 11:02:50 -0700153 container_of(table->data, struct net, ipv4.ping_group_range.range);
WANG Cong396a30c2016-10-20 14:19:46 -0700154 write_seqlock(&net->ipv4.ping_group_range.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -0600155 data[0] = low;
156 data[1] = high;
WANG Cong396a30c2016-10-20 14:19:46 -0700157 write_sequnlock(&net->ipv4.ping_group_range.lock);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000158}
159
160/* Validate changes from /proc interface. */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700161static int ipv4_ping_group_range(struct ctl_table *table, int write,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000162 void __user *buffer,
163 size_t *lenp, loff_t *ppos)
164{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600165 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000166 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600167 gid_t urange[2];
168 kgid_t low, high;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700169 struct ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600170 .data = &urange,
171 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000172 .mode = table->mode,
173 .extra1 = &ip_ping_group_range_min,
174 .extra2 = &ip_ping_group_range_max,
175 };
176
Eric W. Biederman7064d162012-05-24 10:34:21 -0600177 inet_get_ping_group_range_table(table, &low, &high);
178 urange[0] = from_kgid_munged(user_ns, low);
179 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000180 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
181
Eric W. Biederman7064d162012-05-24 10:34:21 -0600182 if (write && ret == 0) {
183 low = make_kgid(user_ns, urange[0]);
184 high = make_kgid(user_ns, urange[1]);
185 if (!gid_valid(low) || !gid_valid(high) ||
186 (urange[1] < urange[0]) || gid_lt(high, low)) {
187 low = make_kgid(&init_user_ns, 1);
188 high = make_kgid(&init_user_ns, 0);
189 }
190 set_ping_group_range(table, low, high);
191 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000192
193 return ret;
194}
195
Joe Perchesfe2c6332013-06-11 23:04:25 -0700196static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700197 void __user *buffer, size_t *lenp, loff_t *ppos)
198{
199 char val[TCP_CA_NAME_MAX];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700200 struct ctl_table tbl = {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700201 .data = val,
202 .maxlen = TCP_CA_NAME_MAX,
203 };
204 int ret;
205
206 tcp_get_default_congestion_control(val);
207
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700208 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700209 if (write && ret == 0)
210 ret = tcp_set_default_congestion_control(val);
211 return ret;
212}
213
Joe Perchesfe2c6332013-06-11 23:04:25 -0700214static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700215 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800216 void __user *buffer, size_t *lenp,
217 loff_t *ppos)
218{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700219 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800220 int ret;
221
222 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
223 if (!tbl.data)
224 return -ENOMEM;
225 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700226 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800227 kfree(tbl.data);
228 return ret;
229}
230
Joe Perchesfe2c6332013-06-11 23:04:25 -0700231static int proc_allowed_congestion_control(struct ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700232 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800233 void __user *buffer, size_t *lenp,
234 loff_t *ppos)
235{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700236 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800237 int ret;
238
239 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
240 if (!tbl.data)
241 return -ENOMEM;
242
243 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700244 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800245 if (write && ret == 0)
246 ret = tcp_set_allowed_congestion_control(tbl.data);
247 kfree(tbl.data);
248 return ret;
249}
250
Joe Perchesfe2c6332013-06-11 23:04:25 -0700251static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
252 void __user *buffer, size_t *lenp,
253 loff_t *ppos)
Jerry Chu10467162012-08-31 12:29:11 +0000254{
Joe Perchesfe2c6332013-06-11 23:04:25 -0700255 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
Jerry Chu10467162012-08-31 12:29:11 +0000256 struct tcp_fastopen_context *ctxt;
257 int ret;
258 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
259
260 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
261 if (!tbl.data)
262 return -ENOMEM;
263
264 rcu_read_lock();
265 ctxt = rcu_dereference(tcp_fastopen_ctx);
266 if (ctxt)
267 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
Alan Cox0e24c4f2012-10-11 06:24:14 +0000268 else
269 memset(user_key, 0, sizeof(user_key));
Jerry Chu10467162012-08-31 12:29:11 +0000270 rcu_read_unlock();
271
272 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
273 user_key[0], user_key[1], user_key[2], user_key[3]);
274 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
275
276 if (write && ret == 0) {
277 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
278 user_key + 2, user_key + 3) != 4) {
279 ret = -EINVAL;
280 goto bad_key;
281 }
Hannes Frederic Sowa222e83d2013-10-19 21:48:58 +0200282 /* Generate a dummy secret but don't publish it. This
283 * is needed so we don't regenerate a new key on the
284 * first invocation of tcp_fastopen_cookie_gen
285 */
286 tcp_fastopen_init_key_once(false);
Jerry Chu10467162012-08-31 12:29:11 +0000287 tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH);
288 }
289
290bad_key:
291 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
292 user_key[0], user_key[1], user_key[2], user_key[3],
293 (char *)tbl.data, ret);
294 kfree(tbl.data);
295 return ret;
296}
297
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600298static void proc_configure_early_demux(int enabled, int protocol)
299{
300 struct net_protocol *ipprot;
301#if IS_ENABLED(CONFIG_IPV6)
302 struct inet6_protocol *ip6prot;
303#endif
304
David Ahern58c4c6a2017-04-22 09:33:16 -0700305 rcu_read_lock();
306
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600307 ipprot = rcu_dereference(inet_protos[protocol]);
308 if (ipprot)
309 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
310 NULL;
311
312#if IS_ENABLED(CONFIG_IPV6)
313 ip6prot = rcu_dereference(inet6_protos[protocol]);
314 if (ip6prot)
315 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
316 NULL;
317#endif
David Ahern58c4c6a2017-04-22 09:33:16 -0700318 rcu_read_unlock();
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600319}
320
321static int proc_tcp_early_demux(struct ctl_table *table, int write,
322 void __user *buffer, size_t *lenp, loff_t *ppos)
323{
324 int ret = 0;
325
326 ret = proc_dointvec(table, write, buffer, lenp, ppos);
327
328 if (write && !ret) {
329 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
330
331 proc_configure_early_demux(enabled, IPPROTO_TCP);
332 }
333
334 return ret;
335}
336
337static int proc_udp_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_udp_early_demux;
346
347 proc_configure_early_demux(enabled, IPPROTO_UDP);
348 }
349
350 return ret;
351}
352
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700353static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
354 int write,
355 void __user *buffer,
356 size_t *lenp, loff_t *ppos)
357{
358 int ret;
359
360 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
361 if (write && ret == 0)
362 tcp_fastopen_active_timeout_reset();
Dave Watson734942c2017-06-14 11:37:14 -0700363
364 return ret;
365}
366
367static int proc_tcp_available_ulp(struct ctl_table *ctl,
368 int write,
369 void __user *buffer, size_t *lenp,
370 loff_t *ppos)
371{
372 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
373 int ret;
374
375 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
376 if (!tbl.data)
377 return -ENOMEM;
378 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
379 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
380 kfree(tbl.data);
381
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700382 return ret;
383}
384
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800385static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900386 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 .procname = "tcp_retrans_collapse",
388 .data = &sysctl_tcp_retrans_collapse,
389 .maxlen = sizeof(int),
390 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800391 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900393 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 .procname = "tcp_max_orphans",
395 .data = &sysctl_tcp_max_orphans,
396 .maxlen = sizeof(int),
397 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800398 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 },
400 {
Yuchung Cheng2100c8d2012-07-19 06:43:05 +0000401 .procname = "tcp_fastopen",
402 .data = &sysctl_tcp_fastopen,
403 .maxlen = sizeof(int),
404 .mode = 0644,
405 .proc_handler = proc_dointvec,
406 },
407 {
Jerry Chu10467162012-08-31 12:29:11 +0000408 .procname = "tcp_fastopen_key",
409 .mode = 0600,
410 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
411 .proc_handler = proc_tcp_fastopen_key,
412 },
413 {
Wei Wangcf1ef3f2017-04-20 14:45:46 -0700414 .procname = "tcp_fastopen_blackhole_timeout_sec",
415 .data = &sysctl_tcp_fastopen_blackhole_timeout,
416 .maxlen = sizeof(int),
417 .mode = 0644,
418 .proc_handler = proc_tfo_blackhole_detect_timeout,
419 .extra1 = &zero,
420 },
421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .procname = "tcp_abort_on_overflow",
423 .data = &sysctl_tcp_abort_on_overflow,
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 = "tcp_stdurg",
430 .data = &sysctl_tcp_stdurg,
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 = "tcp_rfc1337",
437 .data = &sysctl_tcp_rfc1337,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800440 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 },
442 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 .procname = "inet_peer_threshold",
444 .data = &inet_peer_threshold,
445 .maxlen = sizeof(int),
446 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800447 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 },
449 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 .procname = "inet_peer_minttl",
451 .data = &inet_peer_minttl,
452 .maxlen = sizeof(int),
453 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800454 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 },
456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "inet_peer_maxttl",
458 .data = &inet_peer_maxttl,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800461 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .procname = "tcp_fack",
465 .data = &sysctl_tcp_fack,
466 .maxlen = sizeof(int),
467 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800468 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 },
470 {
Yuchung Cheng4f41b1c2015-10-16 21:57:47 -0700471 .procname = "tcp_recovery",
472 .data = &sysctl_tcp_recovery,
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = proc_dointvec,
476 },
477 {
Eric Dumazetdca145f2014-10-27 21:45:24 -0700478 .procname = "tcp_max_reordering",
479 .data = &sysctl_tcp_max_reordering,
480 .maxlen = sizeof(int),
481 .mode = 0644,
482 .proc_handler = proc_dointvec
483 },
484 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 .procname = "tcp_dsack",
486 .data = &sysctl_tcp_dsack,
487 .maxlen = sizeof(int),
488 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800489 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 },
491 {
Eric W. Biedermana4fe34b2013-10-19 16:25:36 -0700492 .procname = "tcp_mem",
493 .maxlen = sizeof(sysctl_tcp_mem),
494 .data = &sysctl_tcp_mem,
495 .mode = 0644,
496 .proc_handler = proc_doulongvec_minmax,
497 },
498 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .procname = "tcp_wmem",
500 .data = &sysctl_tcp_wmem,
501 .maxlen = sizeof(sysctl_tcp_wmem),
502 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000503 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700504 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 },
506 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .procname = "tcp_rmem",
508 .data = &sysctl_tcp_rmem,
509 .maxlen = sizeof(sysctl_tcp_rmem),
510 .mode = 0644,
bingtian.ly@taobao.comcdda8892013-01-23 20:35:28 +0000511 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700512 .extra1 = &one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
514 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 .procname = "tcp_app_win",
516 .data = &sysctl_tcp_app_win,
517 .maxlen = sizeof(int),
518 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800519 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 },
521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .procname = "tcp_adv_win_scale",
523 .data = &sysctl_tcp_adv_win_scale,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000526 .proc_handler = proc_dointvec_minmax,
527 .extra1 = &tcp_adv_win_scale_min,
528 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 },
530 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 .procname = "tcp_frto",
532 .data = &sysctl_tcp_frto,
533 .maxlen = sizeof(int),
534 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800535 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 },
537 {
Yuchung Chengf6722582015-10-16 21:57:42 -0700538 .procname = "tcp_min_rtt_wlen",
539 .data = &sysctl_tcp_min_rtt_wlen,
540 .maxlen = sizeof(int),
541 .mode = 0644,
542 .proc_handler = proc_dointvec
543 },
544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .procname = "tcp_low_latency",
546 .data = &sysctl_tcp_low_latency,
547 .maxlen = sizeof(int),
548 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800549 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 },
551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .procname = "tcp_no_metrics_save",
553 .data = &sysctl_tcp_nometrics_save,
554 .maxlen = sizeof(int),
555 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800556 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 },
558 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .procname = "tcp_moderate_rcvbuf",
560 .data = &sysctl_tcp_moderate_rcvbuf,
561 .maxlen = sizeof(int),
562 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800563 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 },
565 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .procname = "tcp_tso_win_divisor",
567 .data = &sysctl_tcp_tso_win_divisor,
568 .maxlen = sizeof(int),
569 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800570 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 },
572 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700573 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700575 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800576 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800578 {
Rick Jones15d99e02006-03-20 22:40:29 -0800579 .procname = "tcp_workaround_signed_windows",
580 .data = &sysctl_tcp_workaround_signed_windows,
581 .maxlen = sizeof(int),
582 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800583 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800584 },
Eric Dumazet46d3cea2012-07-11 05:50:31 +0000585 {
586 .procname = "tcp_limit_output_bytes",
587 .data = &sysctl_tcp_limit_output_bytes,
588 .maxlen = sizeof(int),
589 .mode = 0644,
590 .proc_handler = proc_dointvec
591 },
Eric Dumazet282f23c2012-07-17 10:13:05 +0200592 {
593 .procname = "tcp_challenge_ack_limit",
594 .data = &sysctl_tcp_challenge_ack_limit,
595 .maxlen = sizeof(int),
596 .mode = 0644,
597 .proc_handler = proc_dointvec
598 },
David S. Miller35089bb2006-06-13 22:33:04 -0700599 {
David S. Miller35089bb2006-06-13 22:33:04 -0700600 .procname = "tcp_slow_start_after_idle",
601 .data = &sysctl_tcp_slow_start_after_idle,
602 .maxlen = sizeof(int),
603 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800604 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700605 },
Paul Moore446fda42006-08-03 16:48:06 -0700606#ifdef CONFIG_NETLABEL
607 {
Paul Moore446fda42006-08-03 16:48:06 -0700608 .procname = "cipso_cache_enable",
609 .data = &cipso_v4_cache_enabled,
610 .maxlen = sizeof(int),
611 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800612 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700613 },
614 {
Paul Moore446fda42006-08-03 16:48:06 -0700615 .procname = "cipso_cache_bucket_size",
616 .data = &cipso_v4_cache_bucketsize,
617 .maxlen = sizeof(int),
618 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800619 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700620 },
621 {
Paul Moore446fda42006-08-03 16:48:06 -0700622 .procname = "cipso_rbm_optfmt",
623 .data = &cipso_v4_rbm_optfmt,
624 .maxlen = sizeof(int),
625 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800626 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700627 },
628 {
Paul Moore446fda42006-08-03 16:48:06 -0700629 .procname = "cipso_rbm_strictvalid",
630 .data = &cipso_v4_rbm_strictvalid,
631 .maxlen = sizeof(int),
632 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800633 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700634 },
635#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800636 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800637 .procname = "tcp_available_congestion_control",
638 .maxlen = TCP_CA_BUF_MAX,
639 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800640 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800641 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800642 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800643 .procname = "tcp_allowed_congestion_control",
644 .maxlen = TCP_CA_BUF_MAX,
645 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800646 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800647 },
John Heffner886236c2007-03-25 19:21:45 -0700648 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000649 .procname = "tcp_thin_linear_timeouts",
650 .data = &sysctl_tcp_thin_linear_timeouts,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = proc_dointvec
654 },
Weilong Chen5797deb2013-12-23 14:37:31 +0800655 {
Yuchung Chengeed530b2012-05-02 13:30:03 +0000656 .procname = "tcp_early_retrans",
657 .data = &sysctl_tcp_early_retrans,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = proc_dointvec_minmax,
661 .extra1 = &zero,
Nandita Dukkipati6ba8a3b2013-03-11 10:00:43 +0000662 .extra2 = &four,
Yuchung Chengeed530b2012-05-02 13:30:03 +0000663 },
664 {
Eric Dumazet95bd09e2013-08-27 05:46:32 -0700665 .procname = "tcp_min_tso_segs",
666 .data = &sysctl_tcp_min_tso_segs,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = proc_dointvec_minmax,
Eric Dumazetd6a4e262015-05-26 08:55:28 -0700670 .extra1 = &one,
Eric Dumazet95bd09e2013-08-27 05:46:32 -0700671 .extra2 = &gso_max_segs,
672 },
673 {
Eric Dumazet43e122b2015-08-21 17:38:02 -0700674 .procname = "tcp_pacing_ss_ratio",
675 .data = &sysctl_tcp_pacing_ss_ratio,
676 .maxlen = sizeof(int),
677 .mode = 0644,
678 .proc_handler = proc_dointvec_minmax,
679 .extra1 = &zero,
680 .extra2 = &thousand,
681 },
682 {
683 .procname = "tcp_pacing_ca_ratio",
684 .data = &sysctl_tcp_pacing_ca_ratio,
685 .maxlen = sizeof(int),
686 .mode = 0644,
687 .proc_handler = proc_dointvec_minmax,
688 .extra1 = &zero,
689 .extra2 = &thousand,
690 },
691 {
Eric Dumazetf54b3112013-12-05 22:36:05 -0800692 .procname = "tcp_autocorking",
693 .data = &sysctl_tcp_autocorking,
694 .maxlen = sizeof(int),
695 .mode = 0644,
696 .proc_handler = proc_dointvec_minmax,
697 .extra1 = &zero,
698 .extra2 = &one,
699 },
700 {
Neal Cardwell032ee422015-02-06 16:04:38 -0500701 .procname = "tcp_invalid_ratelimit",
702 .data = &sysctl_tcp_invalid_ratelimit,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = proc_dointvec_ms_jiffies,
706 },
707 {
Dave Watson734942c2017-06-14 11:37:14 -0700708 .procname = "tcp_available_ulp",
709 .maxlen = TCP_ULP_BUF_MAX,
710 .mode = 0444,
711 .proc_handler = proc_tcp_available_ulp,
712 },
713 {
Eric Dumazet4cdf5072014-09-19 07:38:40 -0700714 .procname = "icmp_msgs_per_sec",
715 .data = &sysctl_icmp_msgs_per_sec,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = proc_dointvec_minmax,
719 .extra1 = &zero,
720 },
721 {
722 .procname = "icmp_msgs_burst",
723 .data = &sysctl_icmp_msgs_burst,
724 .maxlen = sizeof(int),
725 .mode = 0644,
726 .proc_handler = proc_dointvec_minmax,
727 .extra1 = &zero,
728 },
729 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800730 .procname = "udp_mem",
731 .data = &sysctl_udp_mem,
732 .maxlen = sizeof(sysctl_udp_mem),
733 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000734 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800735 },
736 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800737 .procname = "udp_rmem_min",
738 .data = &sysctl_udp_rmem_min,
739 .maxlen = sizeof(sysctl_udp_rmem_min),
740 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800741 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700742 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800743 },
744 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800745 .procname = "udp_wmem_min",
746 .data = &sysctl_udp_wmem_min,
747 .maxlen = sizeof(sysctl_udp_wmem_min),
748 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800749 .proc_handler = proc_dointvec_minmax,
Calvin Owens5d378522015-08-13 14:21:34 -0700750 .extra1 = &one
Hideo Aoki95766ff2007-12-31 00:29:24 -0800751 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800752 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800754
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700755static struct ctl_table ipv4_net_table[] = {
756 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700757 .procname = "icmp_echo_ignore_all",
758 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
759 .maxlen = sizeof(int),
760 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800761 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700762 },
763 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700764 .procname = "icmp_echo_ignore_broadcasts",
765 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
766 .maxlen = sizeof(int),
767 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800768 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700769 },
770 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700771 .procname = "icmp_ignore_bogus_error_responses",
772 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
773 .maxlen = sizeof(int),
774 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800775 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700776 },
777 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700778 .procname = "icmp_errors_use_inbound_ifaddr",
779 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
780 .maxlen = sizeof(int),
781 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800782 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700783 },
784 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700785 .procname = "icmp_ratelimit",
786 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
787 .maxlen = sizeof(int),
788 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800789 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700790 },
791 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700792 .procname = "icmp_ratemask",
793 .data = &init_net.ipv4.sysctl_icmp_ratemask,
794 .maxlen = sizeof(int),
795 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800796 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700797 },
Neil Horman1080d702008-10-27 12:28:25 -0700798 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000799 .procname = "ping_group_range",
Cong Wangba6b9182014-05-06 11:02:50 -0700800 .data = &init_net.ipv4.ping_group_range.range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600801 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000802 .mode = 0644,
803 .proc_handler = ipv4_ping_group_range,
804 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000805 {
Hannes Frederic Sowa5d134f12013-01-05 16:10:48 +0000806 .procname = "tcp_ecn",
807 .data = &init_net.ipv4.sysctl_tcp_ecn,
808 .maxlen = sizeof(int),
809 .mode = 0644,
810 .proc_handler = proc_dointvec
811 },
812 {
Daniel Borkmann49213552015-05-19 21:04:22 +0200813 .procname = "tcp_ecn_fallback",
814 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
815 .maxlen = sizeof(int),
816 .mode = 0644,
817 .proc_handler = proc_dointvec
818 },
819 {
Nikolay Borisov287b7f32016-02-15 12:11:29 +0200820 .procname = "ip_dynaddr",
821 .data = &init_net.ipv4.sysctl_ip_dynaddr,
822 .maxlen = sizeof(int),
823 .mode = 0644,
824 .proc_handler = proc_dointvec
825 },
826 {
Nikolay Borisove21145a2016-02-15 12:11:30 +0200827 .procname = "ip_early_demux",
828 .data = &init_net.ipv4.sysctl_ip_early_demux,
829 .maxlen = sizeof(int),
830 .mode = 0644,
831 .proc_handler = proc_dointvec
832 },
833 {
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -0600834 .procname = "udp_early_demux",
835 .data = &init_net.ipv4.sysctl_udp_early_demux,
836 .maxlen = sizeof(int),
837 .mode = 0644,
838 .proc_handler = proc_udp_early_demux
839 },
840 {
841 .procname = "tcp_early_demux",
842 .data = &init_net.ipv4.sysctl_tcp_early_demux,
843 .maxlen = sizeof(int),
844 .mode = 0644,
845 .proc_handler = proc_tcp_early_demux
846 },
847 {
Nikolay Borisovfa50d972016-02-15 12:11:27 +0200848 .procname = "ip_default_ttl",
849 .data = &init_net.ipv4.sysctl_ip_default_ttl,
850 .maxlen = sizeof(int),
851 .mode = 0644,
852 .proc_handler = proc_dointvec_minmax,
853 .extra1 = &ip_ttl_min,
854 .extra2 = &ip_ttl_max,
855 },
856 {
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700857 .procname = "ip_local_port_range",
Cong Wangc9d8f1a2014-05-06 11:02:49 -0700858 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
859 .data = &init_net.ipv4.ip_local_ports.range,
Eric W. Biederman0bbf87d2013-09-28 14:10:59 -0700860 .mode = 0644,
861 .proc_handler = ipv4_local_port_range,
862 },
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100863 {
WANG Cong122ff242014-05-12 16:04:53 -0700864 .procname = "ip_local_reserved_ports",
865 .data = &init_net.ipv4.sysctl_local_reserved_ports,
866 .maxlen = 65536,
867 .mode = 0644,
868 .proc_handler = proc_do_large_bitmap,
869 },
870 {
Hannes Frederic Sowa974eda12013-12-14 05:13:38 +0100871 .procname = "ip_no_pmtu_disc",
872 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
873 .maxlen = sizeof(int),
874 .mode = 0644,
875 .proc_handler = proc_dointvec
876 },
Hannes Frederic Sowaf87c10a2014-01-09 10:01:15 +0100877 {
878 .procname = "ip_forward_use_pmtu",
879 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
880 .maxlen = sizeof(int),
881 .mode = 0644,
882 .proc_handler = proc_dointvec,
883 },
Lorenzo Colittie1108612014-05-13 10:17:33 -0700884 {
Vincent Bernat49a60152014-09-05 15:09:03 +0200885 .procname = "ip_nonlocal_bind",
886 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
887 .maxlen = sizeof(int),
888 .mode = 0644,
889 .proc_handler = proc_dointvec
890 },
891 {
Lorenzo Colittie1108612014-05-13 10:17:33 -0700892 .procname = "fwmark_reflect",
893 .data = &init_net.ipv4.sysctl_fwmark_reflect,
894 .maxlen = sizeof(int),
895 .mode = 0644,
896 .proc_handler = proc_dointvec,
897 },
Lorenzo Colitti84f39b02014-05-13 10:17:35 -0700898 {
899 .procname = "tcp_fwmark_accept",
900 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = proc_dointvec,
904 },
David Ahern6dd9a142015-12-16 13:20:44 -0800905#ifdef CONFIG_NET_L3_MASTER_DEV
906 {
907 .procname = "tcp_l3mdev_accept",
908 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
909 .maxlen = sizeof(int),
910 .mode = 0644,
911 .proc_handler = proc_dointvec_minmax,
912 .extra1 = &zero,
913 .extra2 = &one,
914 },
915#endif
Fan Dub0f9ca52015-02-10 09:53:16 +0800916 {
917 .procname = "tcp_mtu_probing",
918 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
919 .maxlen = sizeof(int),
920 .mode = 0644,
921 .proc_handler = proc_dointvec,
922 },
923 {
924 .procname = "tcp_base_mss",
925 .data = &init_net.ipv4.sysctl_tcp_base_mss,
926 .maxlen = sizeof(int),
927 .mode = 0644,
928 .proc_handler = proc_dointvec,
929 },
Fan Du6b58e0a2015-03-06 11:18:23 +0800930 {
931 .procname = "tcp_probe_threshold",
932 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
933 .maxlen = sizeof(int),
934 .mode = 0644,
935 .proc_handler = proc_dointvec,
936 },
Fan Du05cbc0d2015-03-06 11:18:24 +0800937 {
938 .procname = "tcp_probe_interval",
939 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
940 .maxlen = sizeof(int),
941 .mode = 0644,
942 .proc_handler = proc_dointvec,
943 },
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100944 {
945 .procname = "igmp_link_local_mcast_reports",
Nikolay Borisov87a8a2a2016-02-09 00:13:50 +0200946 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
Philip Downeydf2cf4a2015-08-27 16:46:26 +0100947 .maxlen = sizeof(int),
948 .mode = 0644,
949 .proc_handler = proc_dointvec
950 },
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200951 {
Nikolay Borisov815c5272016-02-08 23:29:21 +0200952 .procname = "igmp_max_memberships",
953 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = proc_dointvec
957 },
958 {
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200959 .procname = "igmp_max_msf",
960 .data = &init_net.ipv4.sysctl_igmp_max_msf,
961 .maxlen = sizeof(int),
962 .mode = 0644,
963 .proc_handler = proc_dointvec
964 },
Nikolay Borisov165094a2016-02-08 23:29:24 +0200965#ifdef CONFIG_IP_MULTICAST
966 {
967 .procname = "igmp_qrv",
968 .data = &init_net.ipv4.sysctl_igmp_qrv,
969 .maxlen = sizeof(int),
970 .mode = 0644,
971 .proc_handler = proc_dointvec_minmax,
972 .extra1 = &one
973 },
974#endif
Nikolay Borisov166b6b22016-02-08 23:29:22 +0200975 {
Nikolay Borisov13b287e2016-01-07 16:38:43 +0200976 .procname = "tcp_keepalive_time",
977 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
978 .maxlen = sizeof(int),
979 .mode = 0644,
980 .proc_handler = proc_dointvec_jiffies,
981 },
Nikolay Borisov9bd68612016-01-07 16:38:44 +0200982 {
983 .procname = "tcp_keepalive_probes",
984 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
985 .maxlen = sizeof(int),
986 .mode = 0644,
987 .proc_handler = proc_dointvec
988 },
Nikolay Borisovb840d152016-01-07 16:38:45 +0200989 {
990 .procname = "tcp_keepalive_intvl",
991 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
992 .maxlen = sizeof(int),
993 .mode = 0644,
994 .proc_handler = proc_dointvec_jiffies,
995 },
Nikolay Borisov6fa25162016-02-03 09:46:49 +0200996 {
997 .procname = "tcp_syn_retries",
998 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
999 .maxlen = sizeof(int),
1000 .mode = 0644,
1001 .proc_handler = proc_dointvec_minmax,
1002 .extra1 = &tcp_syn_retries_min,
1003 .extra2 = &tcp_syn_retries_max
1004 },
Nikolay Borisov7c083ec2016-02-03 09:46:50 +02001005 {
1006 .procname = "tcp_synack_retries",
1007 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
1008 .maxlen = sizeof(int),
1009 .mode = 0644,
1010 .proc_handler = proc_dointvec
1011 },
Nikolay Borisov12ed8242016-02-03 09:46:51 +02001012#ifdef CONFIG_SYN_COOKIES
1013 {
1014 .procname = "tcp_syncookies",
1015 .data = &init_net.ipv4.sysctl_tcp_syncookies,
1016 .maxlen = sizeof(int),
1017 .mode = 0644,
1018 .proc_handler = proc_dointvec
1019 },
1020#endif
Nikolay Borisov1043e252016-02-03 09:46:52 +02001021 {
1022 .procname = "tcp_reordering",
1023 .data = &init_net.ipv4.sysctl_tcp_reordering,
1024 .maxlen = sizeof(int),
1025 .mode = 0644,
1026 .proc_handler = proc_dointvec
1027 },
Nikolay Borisovae5c3f42016-02-03 09:46:53 +02001028 {
1029 .procname = "tcp_retries1",
1030 .data = &init_net.ipv4.sysctl_tcp_retries1,
1031 .maxlen = sizeof(int),
1032 .mode = 0644,
1033 .proc_handler = proc_dointvec_minmax,
1034 .extra2 = &tcp_retr1_max
1035 },
Nikolay Borisovc6214a92016-02-03 09:46:54 +02001036 {
1037 .procname = "tcp_retries2",
1038 .data = &init_net.ipv4.sysctl_tcp_retries2,
1039 .maxlen = sizeof(int),
1040 .mode = 0644,
1041 .proc_handler = proc_dointvec
1042 },
Nikolay Borisovc402d9b2016-02-03 09:46:55 +02001043 {
1044 .procname = "tcp_orphan_retries",
1045 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
1048 .proc_handler = proc_dointvec
1049 },
Nikolay Borisov1e579ca2016-02-03 09:46:56 +02001050 {
1051 .procname = "tcp_fin_timeout",
1052 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
1053 .maxlen = sizeof(int),
1054 .mode = 0644,
1055 .proc_handler = proc_dointvec_jiffies,
1056 },
Nikolay Borisov4979f2d2016-02-03 09:46:57 +02001057 {
1058 .procname = "tcp_notsent_lowat",
1059 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
1060 .maxlen = sizeof(unsigned int),
1061 .mode = 0644,
Pavel Tikhomirovb007f092017-01-09 10:45:49 +03001062 .proc_handler = proc_douintvec,
Nikolay Borisov4979f2d2016-02-03 09:46:57 +02001063 },
Haishuang Yan56ab6b92016-12-25 14:33:16 +08001064 {
1065 .procname = "tcp_tw_reuse",
1066 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
1067 .maxlen = sizeof(int),
1068 .mode = 0644,
1069 .proc_handler = proc_dointvec
1070 },
Haishuang Yan1946e672016-12-28 17:52:32 +08001071 {
1072 .procname = "tcp_max_tw_buckets",
1073 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
1074 .maxlen = sizeof(int),
1075 .mode = 0644,
1076 .proc_handler = proc_dointvec
1077 },
1078 {
Haishuang Yanfee83d02016-12-28 17:52:33 +08001079 .procname = "tcp_max_syn_backlog",
1080 .data = &init_net.ipv4.sysctl_max_syn_backlog,
1081 .maxlen = sizeof(int),
1082 .mode = 0644,
1083 .proc_handler = proc_dointvec
1084 },
David Aherna6db4492016-04-07 07:21:00 -07001085#ifdef CONFIG_IP_ROUTE_MULTIPATH
1086 {
1087 .procname = "fib_multipath_use_neigh",
1088 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1089 .maxlen = sizeof(int),
1090 .mode = 0644,
1091 .proc_handler = proc_dointvec_minmax,
1092 .extra1 = &zero,
1093 .extra2 = &one,
1094 },
Nikolay Aleksandrovbf4e0a32017-03-16 15:28:00 +02001095 {
1096 .procname = "fib_multipath_hash_policy",
1097 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1098 .maxlen = sizeof(int),
1099 .mode = 0644,
1100 .proc_handler = proc_dointvec_minmax,
1101 .extra1 = &zero,
1102 .extra2 = &one,
1103 },
David Aherna6db4492016-04-07 07:21:00 -07001104#endif
Krister Johansen4548b682017-01-20 17:49:11 -08001105 {
1106 .procname = "ip_unprivileged_port_start",
1107 .maxlen = sizeof(int),
1108 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1109 .mode = 0644,
1110 .proc_handler = ipv4_privileged_ports,
1111 },
Robert Shearman63a6fff2017-01-26 18:02:24 +00001112#ifdef CONFIG_NET_L3_MASTER_DEV
1113 {
1114 .procname = "udp_l3mdev_accept",
1115 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1116 .maxlen = sizeof(int),
1117 .mode = 0644,
1118 .proc_handler = proc_dointvec_minmax,
1119 .extra1 = &zero,
1120 .extra2 = &one,
1121 },
1122#endif
Eric Dumazetf9301032017-06-07 10:34:37 -07001123 {
1124 .procname = "tcp_sack",
1125 .data = &init_net.ipv4.sysctl_tcp_sack,
1126 .maxlen = sizeof(int),
1127 .mode = 0644,
1128 .proc_handler = proc_dointvec
1129 },
Eric Dumazet9bb37ef2017-06-07 10:34:38 -07001130 {
1131 .procname = "tcp_window_scaling",
1132 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1133 .maxlen = sizeof(int),
1134 .mode = 0644,
1135 .proc_handler = proc_dointvec
1136 },
Eric Dumazet5d2ed052017-06-07 10:34:39 -07001137 {
1138 .procname = "tcp_timestamps",
1139 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1140 .maxlen = sizeof(int),
1141 .mode = 0644,
1142 .proc_handler = proc_dointvec
1143 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001144 { }
1145};
1146
Pavel Emelyanov15775192008-03-26 01:54:18 -07001147static __net_init int ipv4_sysctl_init_net(struct net *net)
1148{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001149 struct ctl_table *table;
1150
1151 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001152 if (!net_eq(net, &init_net)) {
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001153 int i;
1154
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001155 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
Ian Morris51456b22015-04-03 09:17:26 +01001156 if (!table)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001157 goto err_alloc;
1158
Eric W. Biederman0a6fa232013-10-19 16:27:03 -07001159 /* Update the variables to point into the current struct net */
1160 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1161 table[i].data += (void *)net - (void *)&init_net;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001162 }
1163
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001164 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Ian Morris51456b22015-04-03 09:17:26 +01001165 if (!net->ipv4.ipv4_hdr)
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001166 goto err_reg;
1167
WANG Cong122ff242014-05-12 16:04:53 -07001168 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1169 if (!net->ipv4.sysctl_local_reserved_ports)
1170 goto err_ports;
1171
Pavel Emelyanov15775192008-03-26 01:54:18 -07001172 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001173
WANG Cong122ff242014-05-12 16:04:53 -07001174err_ports:
1175 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001176err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001177 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001178 kfree(table);
1179err_alloc:
1180 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -07001181}
1182
1183static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1184{
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001185 struct ctl_table *table;
1186
WANG Cong122ff242014-05-12 16:04:53 -07001187 kfree(net->ipv4.sysctl_local_reserved_ports);
Pavel Emelyanov68528f02008-03-26 01:56:24 -07001188 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1189 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1190 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001191}
1192
1193static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1194 .init = ipv4_sysctl_init_net,
1195 .exit = ipv4_sysctl_exit_net,
1196};
1197
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001198static __init int sysctl_ipv4_init(void)
1199{
1200 struct ctl_table_header *hdr;
1201
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +00001202 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Ian Morris51456b22015-04-03 09:17:26 +01001203 if (!hdr)
Pavel Emelyanov15775192008-03-26 01:54:18 -07001204 return -ENOMEM;
1205
1206 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +00001207 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -07001208 return -ENOMEM;
1209 }
1210
1211 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -08001212}
1213
1214__initcall(sysctl_ipv4_init);