sysctl_net_ipv4.c 39.5 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5 6 7 8 9
/*
 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
 *
 * Begun April 1, 1996, Mike Shaver.
 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
 */

#include <linux/sysctl.h>
10
#include <linux/seqlock.h>
11
#include <linux/init.h>
12
#include <linux/slab.h>
13
#include <net/icmp.h>
Linus Torvalds's avatar
Linus Torvalds committed
14
#include <net/ip.h>
15
#include <net/ip_fib.h>
Linus Torvalds's avatar
Linus Torvalds committed
16
#include <net/tcp.h>
Hideo Aoki's avatar
Hideo Aoki committed
17
#include <net/udp.h>
Paul Moore's avatar
Paul Moore committed
18
#include <net/cipso_ipv4.h>
19
#include <net/ping.h>
20
#include <net/protocol.h>
21
#include <net/netevent.h>
Linus Torvalds's avatar
Linus Torvalds committed
22

23
static int tcp_retr1_max = 255;
Linus Torvalds's avatar
Linus Torvalds committed
24 25
static int ip_local_port_range_min[] = { 1, 1 };
static int ip_local_port_range_max[] = { 65535, 65535 };
26 27
static int tcp_adv_win_scale_min = -31;
static int tcp_adv_win_scale_max = 31;
28 29
static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
static int tcp_min_snd_mss_max = 65535;
30 31
static int ip_privileged_port_min;
static int ip_privileged_port_max = 65535;
32 33
static int ip_ttl_min = 1;
static int ip_ttl_max = 255;
34 35
static int tcp_syn_retries_min = 1;
static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
36 37
static int ip_ping_group_range_min[] = { 0, 0 };
static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
38
static u32 u32_max_div_HZ = UINT_MAX / HZ;
39
static int one_day_secs = 24 * 3600;
40 41
static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
	FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
42
static unsigned int tcp_child_ehash_entries_max = 16 * 1024 * 1024;
43
static unsigned int udp_child_hash_entries_max = UDP_HTABLE_SIZE_MAX;
44 45
static int tcp_plb_max_rounds = 31;
static int tcp_plb_max_cong_thresh = 256;
Linus Torvalds's avatar
Linus Torvalds committed
46

47 48 49
/* obsolete */
static int sysctl_tcp_low_latency __read_mostly;

50
/* Update system visible IP port range */
51
static void set_local_port_range(struct net *net, int range[2])
52
{
53 54
	bool same_parity = !((range[0] ^ range[1]) & 1);

55
	write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
56 57 58 59
	if (same_parity && !net->ipv4.ip_local_ports.warned) {
		net->ipv4.ip_local_ports.warned = true;
		pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
	}
60 61
	net->ipv4.ip_local_ports.range[0] = range[0];
	net->ipv4.ip_local_ports.range[1] = range[1];
62
	write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
63 64 65
}

/* Validate changes from /proc interface. */
66
static int ipv4_local_port_range(struct ctl_table *table, int write,
67
				 void *buffer, size_t *lenp, loff_t *ppos)
68
{
69
	struct net *net =
70
		container_of(table->data, struct net, ipv4.ip_local_ports.range);
71
	int ret;
72
	int range[2];
73
	struct ctl_table tmp = {
74 75 76 77 78 79 80
		.data = &range,
		.maxlen = sizeof(range),
		.mode = table->mode,
		.extra1 = &ip_local_port_range_min,
		.extra2 = &ip_local_port_range_max,
	};

81 82
	inet_get_local_port_range(net, &range[0], &range[1]);

83
	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
84 85

	if (write && ret == 0) {
86 87 88 89 90
		/* Ensure that the upper limit is not smaller than the lower,
		 * and that the lower does not encroach upon the privileged
		 * port limit.
		 */
		if ((range[1] < range[0]) ||
91
		    (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
92 93
			ret = -EINVAL;
		else
94
			set_local_port_range(net, range);
95 96 97 98 99
	}

	return ret;
}

100 101
/* Validate changes from /proc interface. */
static int ipv4_privileged_ports(struct ctl_table *table, int write,
102
				void *buffer, size_t *lenp, loff_t *ppos)
103 104 105 106 107 108 109 110 111 112 113 114 115 116
{
	struct net *net = container_of(table->data, struct net,
	    ipv4.sysctl_ip_prot_sock);
	int ret;
	int pports;
	int range[2];
	struct ctl_table tmp = {
		.data = &pports,
		.maxlen = sizeof(pports),
		.mode = table->mode,
		.extra1 = &ip_privileged_port_min,
		.extra2 = &ip_privileged_port_max,
	};

117
	pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
118 119 120 121 122 123 124 125 126 127 128

	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);

	if (write && ret == 0) {
		inet_get_local_port_range(net, &range[0], &range[1]);
		/* Ensure that the local port range doesn't overlap with the
		 * privileged port range.
		 */
		if (range[0] < pports)
			ret = -EINVAL;
		else
129
			WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
130 131 132 133
	}

	return ret;
}
134

135
static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
136
{
137
	kgid_t *data = table->data;
138
	struct net *net =
139
		container_of(table->data, struct net, ipv4.ping_group_range.range);
140
	unsigned int seq;
141
	do {
142
		seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
143 144 145

		*low = data[0];
		*high = data[1];
146
	} while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
147 148 149
}

/* Update system visible IP port range */
150
static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
151
{
152
	kgid_t *data = table->data;
153
	struct net *net =
154
		container_of(table->data, struct net, ipv4.ping_group_range.range);
155
	write_seqlock(&net->ipv4.ping_group_range.lock);
156 157
	data[0] = low;
	data[1] = high;
158
	write_sequnlock(&net->ipv4.ping_group_range.lock);
159 160 161
}

/* Validate changes from /proc interface. */
162
static int ipv4_ping_group_range(struct ctl_table *table, int write,
163
				 void *buffer, size_t *lenp, loff_t *ppos)
164
{
165
	struct user_namespace *user_ns = current_user_ns();
166
	int ret;
167 168
	gid_t urange[2];
	kgid_t low, high;
169
	struct ctl_table tmp = {
170 171
		.data = &urange,
		.maxlen = sizeof(urange),
172 173 174 175 176
		.mode = table->mode,
		.extra1 = &ip_ping_group_range_min,
		.extra2 = &ip_ping_group_range_max,
	};

177 178 179
	inet_get_ping_group_range_table(table, &low, &high);
	urange[0] = from_kgid_munged(user_ns, low);
	urange[1] = from_kgid_munged(user_ns, high);
180 181
	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);

182 183 184
	if (write && ret == 0) {
		low = make_kgid(user_ns, urange[0]);
		high = make_kgid(user_ns, urange[1]);
185 186 187
		if (!gid_valid(low) || !gid_valid(high))
			return -EINVAL;
		if (urange[1] < urange[0] || gid_lt(high, low)) {
188 189 190 191 192
			low = make_kgid(&init_user_ns, 1);
			high = make_kgid(&init_user_ns, 0);
		}
		set_ping_group_range(table, low, high);
	}
193 194 195 196

	return ret;
}

197
static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
198
				    void *buffer, size_t *lenp, loff_t *ppos)
199 200 201 202 203 204
{
	struct net *net;
	int ret;

	net = container_of(table->data, struct net,
			   ipv4.sysctl_ip_fwd_update_priority);
205
	ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
206 207 208 209 210 211 212
	if (write && ret == 0)
		call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
					net);

	return ret;
}

213
static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
214
				       void *buffer, size_t *lenp, loff_t *ppos)
215
{
216 217
	struct net *net = container_of(ctl->data, struct net,
				       ipv4.tcp_congestion_control);
218
	char val[TCP_CA_NAME_MAX];
219
	struct ctl_table tbl = {
220 221 222 223 224
		.data = val,
		.maxlen = TCP_CA_NAME_MAX,
	};
	int ret;

225
	tcp_get_default_congestion_control(net, val);
226

227
	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
228
	if (write && ret == 0)
229
		ret = tcp_set_default_congestion_control(net, val);
230 231 232
	return ret;
}

233
static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
234 235
						 int write, void *buffer,
						 size_t *lenp, loff_t *ppos)
236
{
237
	struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
238 239 240 241 242 243
	int ret;

	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
	if (!tbl.data)
		return -ENOMEM;
	tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
244
	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
245 246 247 248
	kfree(tbl.data);
	return ret;
}

249
static int proc_allowed_congestion_control(struct ctl_table *ctl,
250 251
					   int write, void *buffer,
					   size_t *lenp, loff_t *ppos)
252
{
253
	struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
254 255 256 257 258 259 260
	int ret;

	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
	if (!tbl.data)
		return -ENOMEM;

	tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
261
	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
262 263 264 265 266 267
	if (write && ret == 0)
		ret = tcp_set_allowed_congestion_control(tbl.data);
	kfree(tbl.data);
	return ret;
}

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
static int sscanf_key(char *buf, __le32 *key)
{
	u32 user_key[4];
	int i, ret = 0;

	if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
		   user_key + 2, user_key + 3) != 4) {
		ret = -EINVAL;
	} else {
		for (i = 0; i < ARRAY_SIZE(user_key); i++)
			key[i] = cpu_to_le32(user_key[i]);
	}
	pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
		 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);

	return ret;
}

286
static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
287
				 void *buffer, size_t *lenp, loff_t *ppos)
288
{
289 290
	struct net *net = container_of(table->data, struct net,
	    ipv4.sysctl_tcp_fastopen);
291 292 293 294 295 296
	/* maxlen to print the list of keys in hex (*2), with dashes
	 * separating doublewords and a comma in between keys.
	 */
	struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
					    2 * TCP_FASTOPEN_KEY_MAX) +
					    (TCP_FASTOPEN_KEY_MAX * 5)) };
297 298
	u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
	__le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
299
	char *backup_data;
300
	int ret, i = 0, off = 0, n_keys;
301 302 303 304 305

	tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
	if (!tbl.data)
		return -ENOMEM;

306
	n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
307 308 309 310 311 312
	if (!n_keys) {
		memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
		n_keys = 1;
	}

	for (i = 0; i < n_keys * 4; i++)
313 314
		user_key[i] = le32_to_cpu(key[i]);

315 316 317 318 319 320 321
	for (i = 0; i < n_keys; i++) {
		off += snprintf(tbl.data + off, tbl.maxlen - off,
				"%08x-%08x-%08x-%08x",
				user_key[i * 4],
				user_key[i * 4 + 1],
				user_key[i * 4 + 2],
				user_key[i * 4 + 3]);
322 323 324 325

		if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
			break;

326 327 328 329
		if (i + 1 < n_keys)
			off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
	}

330 331 332
	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);

	if (write && ret == 0) {
333 334 335 336 337 338
		backup_data = strchr(tbl.data, ',');
		if (backup_data) {
			*backup_data = '\0';
			backup_data++;
		}
		if (sscanf_key(tbl.data, key)) {
339 340 341
			ret = -EINVAL;
			goto bad_key;
		}
342 343 344 345 346 347 348
		if (backup_data) {
			if (sscanf_key(backup_data, key + 4)) {
				ret = -EINVAL;
				goto bad_key;
			}
		}
		tcp_fastopen_reset_cipher(net, NULL, key,
349
					  backup_data ? key + 4 : NULL);
350 351 352 353 354 355 356
	}

bad_key:
	kfree(tbl.data);
	return ret;
}

357
static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
358
					     int write, void *buffer,
359 360
					     size_t *lenp, loff_t *ppos)
{
361 362
	struct net *net = container_of(table->data, struct net,
	    ipv4.sysctl_tcp_fastopen_blackhole_timeout);
363 364 365 366
	int ret;

	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
	if (write && ret == 0)
367
		atomic_set(&net->ipv4.tfo_active_disable_times, 0);
Dave Watson's avatar
Dave Watson committed
368 369 370 371 372

	return ret;
}

static int proc_tcp_available_ulp(struct ctl_table *ctl,
373
				  int write, void *buffer, size_t *lenp,
Dave Watson's avatar
Dave Watson committed
374 375 376 377 378 379 380 381 382 383 384 385
				  loff_t *ppos)
{
	struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
	int ret;

	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
	if (!tbl.data)
		return -ENOMEM;
	tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
	kfree(tbl.data);

386 387 388
	return ret;
}

389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
static int proc_tcp_ehash_entries(struct ctl_table *table, int write,
				  void *buffer, size_t *lenp, loff_t *ppos)
{
	struct net *net = container_of(table->data, struct net,
				       ipv4.sysctl_tcp_child_ehash_entries);
	struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
	int tcp_ehash_entries;
	struct ctl_table tbl;

	tcp_ehash_entries = hinfo->ehash_mask + 1;

	/* A negative number indicates that the child netns
	 * shares the global ehash.
	 */
	if (!net_eq(net, &init_net) && !hinfo->pernet)
		tcp_ehash_entries *= -1;

406
	memset(&tbl, 0, sizeof(tbl));
407 408 409 410 411 412
	tbl.data = &tcp_ehash_entries;
	tbl.maxlen = sizeof(int);

	return proc_dointvec(&tbl, write, buffer, lenp, ppos);
}

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
static int proc_udp_hash_entries(struct ctl_table *table, int write,
				 void *buffer, size_t *lenp, loff_t *ppos)
{
	struct net *net = container_of(table->data, struct net,
				       ipv4.sysctl_udp_child_hash_entries);
	int udp_hash_entries;
	struct ctl_table tbl;

	udp_hash_entries = net->ipv4.udp_table->mask + 1;

	/* A negative number indicates that the child netns
	 * shares the global udp_table.
	 */
	if (!net_eq(net, &init_net) && net->ipv4.udp_table == &udp_table)
		udp_hash_entries *= -1;

	memset(&tbl, 0, sizeof(tbl));
	tbl.data = &udp_hash_entries;
	tbl.maxlen = sizeof(int);

	return proc_dointvec(&tbl, write, buffer, lenp, ppos);
}

436 437
#ifdef CONFIG_IP_ROUTE_MULTIPATH
static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
438
					  void *buffer, size_t *lenp,
439 440 441 442 443 444
					  loff_t *ppos)
{
	struct net *net = container_of(table->data, struct net,
	    ipv4.sysctl_fib_multipath_hash_policy);
	int ret;

445
	ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
446
	if (write && ret == 0)
447
		call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
448 449 450

	return ret;
}
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466

static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
					  void *buffer, size_t *lenp,
					  loff_t *ppos)
{
	struct net *net;
	int ret;

	net = container_of(table->data, struct net,
			   ipv4.sysctl_fib_multipath_hash_fields);
	ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
	if (write && ret == 0)
		call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);

	return ret;
}
467 468
#endif

469
static struct ctl_table ipv4_table[] = {
Linus Torvalds's avatar
Linus Torvalds committed
470 471 472 473 474
	{
		.procname	= "tcp_max_orphans",
		.data		= &sysctl_tcp_max_orphans,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
475
		.proc_handler	= proc_dointvec
Linus Torvalds's avatar
Linus Torvalds committed
476 477 478 479 480 481
	},
	{
		.procname	= "inet_peer_threshold",
		.data		= &inet_peer_threshold,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
482
		.proc_handler	= proc_dointvec
Linus Torvalds's avatar
Linus Torvalds committed
483 484 485 486 487 488
	},
	{
		.procname	= "inet_peer_minttl",
		.data		= &inet_peer_minttl,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
489
		.proc_handler	= proc_dointvec_jiffies,
Linus Torvalds's avatar
Linus Torvalds committed
490 491 492 493 494 495
	},
	{
		.procname	= "inet_peer_maxttl",
		.data		= &inet_peer_maxttl,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
496
		.proc_handler	= proc_dointvec_jiffies,
Linus Torvalds's avatar
Linus Torvalds committed
497
	},
498 499 500 501 502 503 504
	{
		.procname	= "tcp_mem",
		.maxlen		= sizeof(sysctl_tcp_mem),
		.data		= &sysctl_tcp_mem,
		.mode		= 0644,
		.proc_handler	= proc_doulongvec_minmax,
	},
Linus Torvalds's avatar
Linus Torvalds committed
505 506 507 508 509
	{
		.procname	= "tcp_low_latency",
		.data		= &sysctl_tcp_low_latency,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
510
		.proc_handler	= proc_dointvec
Linus Torvalds's avatar
Linus Torvalds committed
511
	},
Paul Moore's avatar
Paul Moore committed
512 513 514 515 516 517
#ifdef CONFIG_NETLABEL
	{
		.procname	= "cipso_cache_enable",
		.data		= &cipso_v4_cache_enabled,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
518
		.proc_handler	= proc_dointvec,
Paul Moore's avatar
Paul Moore committed
519 520 521 522 523 524
	},
	{
		.procname	= "cipso_cache_bucket_size",
		.data		= &cipso_v4_cache_bucketsize,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
525
		.proc_handler	= proc_dointvec,
Paul Moore's avatar
Paul Moore committed
526 527 528 529 530 531
	},
	{
		.procname	= "cipso_rbm_optfmt",
		.data		= &cipso_v4_rbm_optfmt,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
532
		.proc_handler	= proc_dointvec,
Paul Moore's avatar
Paul Moore committed
533 534 535 536 537 538
	},
	{
		.procname	= "cipso_rbm_strictvalid",
		.data		= &cipso_v4_rbm_strictvalid,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
539
		.proc_handler	= proc_dointvec,
Paul Moore's avatar
Paul Moore committed
540 541
	},
#endif /* CONFIG_NETLABEL */
Dave Watson's avatar
Dave Watson committed
542 543 544 545 546 547
	{
		.procname	= "tcp_available_ulp",
		.maxlen		= TCP_ULP_BUF_MAX,
		.mode		= 0444,
		.proc_handler   = proc_tcp_available_ulp,
	},
548 549 550 551 552 553
	{
		.procname	= "icmp_msgs_per_sec",
		.data		= &sysctl_icmp_msgs_per_sec,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
554
		.extra1		= SYSCTL_ZERO,
555 556 557 558 559 560 561
	},
	{
		.procname	= "icmp_msgs_burst",
		.data		= &sysctl_icmp_msgs_burst,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
562
		.extra1		= SYSCTL_ZERO,
563
	},
Hideo Aoki's avatar
Hideo Aoki committed
564 565 566 567 568
	{
		.procname	= "udp_mem",
		.data		= &sysctl_udp_mem,
		.maxlen		= sizeof(sysctl_udp_mem),
		.mode		= 0644,
Eric Dumazet's avatar
Eric Dumazet committed
569
		.proc_handler	= proc_doulongvec_minmax,
Hideo Aoki's avatar
Hideo Aoki committed
570
	},
571 572 573 574 575 576 577 578 579
	{
		.procname	= "fib_sync_mem",
		.data		= &sysctl_fib_sync_mem,
		.maxlen		= sizeof(sysctl_fib_sync_mem),
		.mode		= 0644,
		.proc_handler	= proc_douintvec_minmax,
		.extra1		= &sysctl_fib_sync_mem_min,
		.extra2		= &sysctl_fib_sync_mem_max,
	},
580
	{ }
Linus Torvalds's avatar
Linus Torvalds committed
581
};
582

583
static struct ctl_table ipv4_net_table[] = {
584 585
	{
		.procname	= "tcp_max_tw_buckets",
586
		.data		= &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
587 588 589 590
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
591 592 593
	{
		.procname	= "icmp_echo_ignore_all",
		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
594
		.maxlen		= sizeof(u8),
595
		.mode		= 0644,
596
		.proc_handler	= proc_dou8vec_minmax,
597 598
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE
599
	},
600 601 602
	{
		.procname	= "icmp_echo_enable_probe",
		.data		= &init_net.ipv4.sysctl_icmp_echo_enable_probe,
603
		.maxlen		= sizeof(u8),
604
		.mode		= 0644,
605
		.proc_handler	= proc_dou8vec_minmax,
606 607 608
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE
	},
609 610 611
	{
		.procname	= "icmp_echo_ignore_broadcasts",
		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
612
		.maxlen		= sizeof(u8),
613
		.mode		= 0644,
614
		.proc_handler	= proc_dou8vec_minmax,
615 616
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE
617 618 619 620
	},
	{
		.procname	= "icmp_ignore_bogus_error_responses",
		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
621
		.maxlen		= sizeof(u8),
622
		.mode		= 0644,
623
		.proc_handler	= proc_dou8vec_minmax,
624 625
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE
626 627 628 629
	},
	{
		.procname	= "icmp_errors_use_inbound_ifaddr",
		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
630
		.maxlen		= sizeof(u8),
631
		.mode		= 0644,
632
		.proc_handler	= proc_dou8vec_minmax,
633 634
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE
635 636 637 638 639 640
	},
	{
		.procname	= "icmp_ratelimit",
		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
641
		.proc_handler	= proc_dointvec_ms_jiffies,
642 643 644 645 646 647
	},
	{
		.procname	= "icmp_ratemask",
		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
		.maxlen		= sizeof(int),
		.mode		= 0644,
Alexey Dobriyan's avatar
Alexey Dobriyan committed
648
		.proc_handler	= proc_dointvec
649
	},
650 651
	{
		.procname	= "ping_group_range",
652
		.data		= &init_net.ipv4.ping_group_range.range,
653
		.maxlen		= sizeof(gid_t)*2,
654 655 656
		.mode		= 0644,
		.proc_handler	= ipv4_ping_group_range,
	},
657 658 659 660
#ifdef CONFIG_NET_L3_MASTER_DEV
	{
		.procname	= "raw_l3mdev_accept",
		.data		= &init_net.ipv4.sysctl_raw_l3mdev_accept,
661
		.maxlen		= sizeof(u8),
662
		.mode		= 0644,
663
		.proc_handler	= proc_dou8vec_minmax,
664 665
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
666 667
	},
#endif
668 669 670
	{
		.procname	= "tcp_ecn",
		.data		= &init_net.ipv4.sysctl_tcp_ecn,
671
		.maxlen		= sizeof(u8),
672
		.mode		= 0644,
673
		.proc_handler	= proc_dou8vec_minmax,
674 675
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_TWO,
676
	},
677 678 679
	{
		.procname	= "tcp_ecn_fallback",
		.data		= &init_net.ipv4.sysctl_tcp_ecn_fallback,
680
		.maxlen		= sizeof(u8),
681
		.mode		= 0644,
682
		.proc_handler	= proc_dou8vec_minmax,
683 684
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
685
	},
686 687 688
	{
		.procname	= "ip_dynaddr",
		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
689
		.maxlen		= sizeof(u8),
690
		.mode		= 0644,
691
		.proc_handler	= proc_dou8vec_minmax,
692
	},
693 694 695
	{
		.procname	= "ip_early_demux",
		.data		= &init_net.ipv4.sysctl_ip_early_demux,
696
		.maxlen		= sizeof(u8),
697
		.mode		= 0644,
698
		.proc_handler	= proc_dou8vec_minmax,
699
	},
700 701 702
	{
		.procname       = "udp_early_demux",
		.data           = &init_net.ipv4.sysctl_udp_early_demux,
703
		.maxlen         = sizeof(u8),
704
		.mode           = 0644,
705
		.proc_handler   = proc_dou8vec_minmax,
706 707 708 709
	},
	{
		.procname       = "tcp_early_demux",
		.data           = &init_net.ipv4.sysctl_tcp_early_demux,
710
		.maxlen         = sizeof(u8),
711
		.mode           = 0644,
712
		.proc_handler   = proc_dou8vec_minmax,
713
	},
714 715 716
	{
		.procname       = "nexthop_compat_mode",
		.data           = &init_net.ipv4.sysctl_nexthop_compat_mode,
717
		.maxlen         = sizeof(u8),
718
		.mode           = 0644,
719
		.proc_handler   = proc_dou8vec_minmax,
720 721 722
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
	},
723 724 725
	{
		.procname	= "ip_default_ttl",
		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
726
		.maxlen		= sizeof(u8),
727
		.mode		= 0644,
728
		.proc_handler	= proc_dou8vec_minmax,
729 730 731
		.extra1		= &ip_ttl_min,
		.extra2		= &ip_ttl_max,
	},
732 733
	{
		.procname	= "ip_local_port_range",
734 735
		.maxlen		= sizeof(init_net.ipv4.ip_local_ports.range),
		.data		= &init_net.ipv4.ip_local_ports.range,
736 737 738
		.mode		= 0644,
		.proc_handler	= ipv4_local_port_range,
	},
739 740 741 742 743 744 745
	{
		.procname	= "ip_local_reserved_ports",
		.data		= &init_net.ipv4.sysctl_local_reserved_ports,
		.maxlen		= 65536,
		.mode		= 0644,
		.proc_handler	= proc_do_large_bitmap,
	},
746 747 748
	{
		.procname	= "ip_no_pmtu_disc",
		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
749
		.maxlen		= sizeof(u8),
750
		.mode		= 0644,
751
		.proc_handler	= proc_dou8vec_minmax,
752
	},
753 754 755
	{
		.procname	= "ip_forward_use_pmtu",
		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
756
		.maxlen		= sizeof(u8),
757
		.mode		= 0644,
758
		.proc_handler	= proc_dou8vec_minmax,
759
	},
760 761 762
	{
		.procname	= "ip_forward_update_priority",
		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
763
		.maxlen		= sizeof(u8),
764
		.mode		= 0644,
765
		.proc_handler   = ipv4_fwd_update_priority,
766 767
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
768
	},
769 770 771
	{
		.procname	= "ip_nonlocal_bind",
		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
772
		.maxlen		= sizeof(u8),
773
		.mode		= 0644,
774
		.proc_handler	= proc_dou8vec_minmax,
775
	},
776 777 778
	{
		.procname	= "ip_autobind_reuse",
		.data		= &init_net.ipv4.sysctl_ip_autobind_reuse,
779
		.maxlen		= sizeof(u8),
780
		.mode		= 0644,
781
		.proc_handler	= proc_dou8vec_minmax,
782 783 784
		.extra1         = SYSCTL_ZERO,
		.extra2         = SYSCTL_ONE,
	},
785 786 787
	{
		.procname	= "fwmark_reflect",
		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
788
		.maxlen		= sizeof(u8),
789
		.mode		= 0644,
790
		.proc_handler	= proc_dou8vec_minmax,
791
	},
792 793 794
	{
		.procname	= "tcp_fwmark_accept",
		.data		= &init_net.ipv4.sysctl_tcp_fwmark_accept,
795
		.maxlen		= sizeof(u8),
796
		.mode		= 0644,
797
		.proc_handler	= proc_dou8vec_minmax,
798
	},
799 800 801 802
#ifdef CONFIG_NET_L3_MASTER_DEV
	{
		.procname	= "tcp_l3mdev_accept",
		.data		= &init_net.ipv4.sysctl_tcp_l3mdev_accept,
803
		.maxlen		= sizeof(u8),
804
		.mode		= 0644,
805
		.proc_handler	= proc_dou8vec_minmax,
806 807
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
808 809
	},
#endif
810 811 812
	{
		.procname	= "tcp_mtu_probing",
		.data		= &init_net.ipv4.sysctl_tcp_mtu_probing,
813
		.maxlen		= sizeof(u8),
814
		.mode		= 0644,
815
		.proc_handler	= proc_dou8vec_minmax,
816 817 818 819 820 821 822 823
	},
	{
		.procname	= "tcp_base_mss",
		.data		= &init_net.ipv4.sysctl_tcp_base_mss,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec,
	},
824 825 826 827 828 829 830 831 832
	{
		.procname	= "tcp_min_snd_mss",
		.data		= &init_net.ipv4.sysctl_tcp_min_snd_mss,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
		.extra1		= &tcp_min_snd_mss_min,
		.extra2		= &tcp_min_snd_mss_max,
	},
833 834 835 836 837 838 839 840 841
	{
		.procname	= "tcp_mtu_probe_floor",
		.data		= &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
		.extra1		= &tcp_min_snd_mss_min,
		.extra2		= &tcp_min_snd_mss_max,
	},
842 843 844 845 846 847 848
	{
		.procname	= "tcp_probe_threshold",
		.data		= &init_net.ipv4.sysctl_tcp_probe_threshold,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec,
	},
849 850 851
	{
		.procname	= "tcp_probe_interval",
		.data		= &init_net.ipv4.sysctl_tcp_probe_interval,
852
		.maxlen		= sizeof(u32),
853
		.mode		= 0644,
854 855
		.proc_handler	= proc_douintvec_minmax,
		.extra2		= &u32_max_div_HZ,
856
	},
857 858
	{
		.procname	= "igmp_link_local_mcast_reports",
859
		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
860
		.maxlen		= sizeof(u8),
861
		.mode		= 0644,
862
		.proc_handler	= proc_dou8vec_minmax,
863
	},
864 865 866 867 868 869 870
	{
		.procname	= "igmp_max_memberships",
		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
871 872 873 874 875 876 877
	{
		.procname	= "igmp_max_msf",
		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
878 879 880 881 882 883 884
#ifdef CONFIG_IP_MULTICAST
	{
		.procname	= "igmp_qrv",
		.data		= &init_net.ipv4.sysctl_igmp_qrv,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
885
		.extra1		= SYSCTL_ONE
886 887
	},
#endif
888 889 890 891 892 893 894
	{
		.procname	= "tcp_congestion_control",
		.data		= &init_net.ipv4.tcp_congestion_control,
		.mode		= 0644,
		.maxlen		= TCP_CA_NAME_MAX,
		.proc_handler	= proc_tcp_congestion_control,
	},
895 896 897 898 899 900 901 902 903 904 905 906
	{
		.procname	= "tcp_available_congestion_control",
		.maxlen		= TCP_CA_BUF_MAX,
		.mode		= 0444,
		.proc_handler   = proc_tcp_available_congestion_control,
	},
	{
		.procname	= "tcp_allowed_congestion_control",
		.maxlen		= TCP_CA_BUF_MAX,
		.mode		= 0644,
		.proc_handler   = proc_allowed_congestion_control,
	},
907 908 909 910 911 912 913
	{
		.procname	= "tcp_keepalive_time",
		.data		= &init_net.ipv4.sysctl_tcp_keepalive_time,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_jiffies,
	},
914 915 916
	{
		.procname	= "tcp_keepalive_probes",
		.data		= &init_net.ipv4.sysctl_tcp_keepalive_probes,
917
		.maxlen		= sizeof(u8),
918
		.mode		= 0644,
919
		.proc_handler	= proc_dou8vec_minmax,
920
	},
921 922 923 924 925 926 927
	{
		.procname	= "tcp_keepalive_intvl",
		.data		= &init_net.ipv4.sysctl_tcp_keepalive_intvl,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_jiffies,
	},
928 929 930
	{
		.procname	= "tcp_syn_retries",
		.data		= &init_net.ipv4.sysctl_tcp_syn_retries,
931
		.maxlen		= sizeof(u8),
932
		.mode		= 0644,
933
		.proc_handler	= proc_dou8vec_minmax,
934 935 936
		.extra1		= &tcp_syn_retries_min,
		.extra2		= &tcp_syn_retries_max
	},
937 938 939
	{
		.procname	= "tcp_synack_retries",
		.data		= &init_net.ipv4.sysctl_tcp_synack_retries,
940
		.maxlen		= sizeof(u8),
941
		.mode		= 0644,
942
		.proc_handler	= proc_dou8vec_minmax,
943
	},
944 945 946 947
#ifdef CONFIG_SYN_COOKIES
	{
		.procname	= "tcp_syncookies",
		.data		= &init_net.ipv4.sysctl_tcp_syncookies,
948
		.maxlen		= sizeof(u8),
949
		.mode		= 0644,
950
		.proc_handler	= proc_dou8vec_minmax,
951 952
	},
#endif
953 954 955 956 957 958 959 960 961
	{
		.procname	= "tcp_migrate_req",
		.data		= &init_net.ipv4.sysctl_tcp_migrate_req,
		.maxlen		= sizeof(u8),
		.mode		= 0644,
		.proc_handler	= proc_dou8vec_minmax,
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE
	},
962 963 964 965 966 967 968
	{
		.procname	= "tcp_reordering",
		.data		= &init_net.ipv4.sysctl_tcp_reordering,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
969 970 971
	{
		.procname	= "tcp_retries1",
		.data		= &init_net.ipv4.sysctl_tcp_retries1,
972
		.maxlen		= sizeof(u8),
973
		.mode		= 0644,
974
		.proc_handler	= proc_dou8vec_minmax,
975 976
		.extra2		= &tcp_retr1_max
	},
977 978 979
	{
		.procname	= "tcp_retries2",
		.data		= &init_net.ipv4.sysctl_tcp_retries2,
980
		.maxlen		= sizeof(u8),
981
		.mode		= 0644,
982
		.proc_handler	= proc_dou8vec_minmax,
983
	},
984 985 986
	{
		.procname	= "tcp_orphan_retries",
		.data		= &init_net.ipv4.sysctl_tcp_orphan_retries,
987
		.maxlen		= sizeof(u8),
988
		.mode		= 0644,
989
		.proc_handler	= proc_dou8vec_minmax,
990
	},
991 992 993 994 995 996 997
	{
		.procname	= "tcp_fin_timeout",
		.data		= &init_net.ipv4.sysctl_tcp_fin_timeout,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_jiffies,
	},
998 999 1000 1001 1002
	{
		.procname	= "tcp_notsent_lowat",
		.data		= &init_net.ipv4.sysctl_tcp_notsent_lowat,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
1003
		.proc_handler	= proc_douintvec,
1004
	},
1005 1006 1007
	{
		.procname	= "tcp_tw_reuse",
		.data		= &init_net.ipv4.sysctl_tcp_tw_reuse,
1008
		.maxlen		= sizeof(u8),
1009
		.mode		= 0644,
1010
		.proc_handler	= proc_dou8vec_minmax,
1011
		.extra1		= SYSCTL_ZERO,
1012
		.extra2		= SYSCTL_TWO,
1013
	},
1014 1015 1016 1017 1018 1019 1020
	{
		.procname	= "tcp_max_syn_backlog",
		.data		= &init_net.ipv4.sysctl_max_syn_backlog,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
1021 1022 1023 1024 1025 1026 1027
	{
		.procname	= "tcp_fastopen",
		.data		= &init_net.ipv4.sysctl_tcp_fastopen,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec,
	},
1028 1029 1030 1031
	{
		.procname	= "tcp_fastopen_key",
		.mode		= 0600,
		.data		= &init_net.ipv4.sysctl_tcp_fastopen,
1032 1033 1034 1035 1036 1037
		/* maxlen to print the list of keys in hex (*2), with dashes
		 * separating doublewords and a comma in between keys.
		 */
		.maxlen		= ((TCP_FASTOPEN_KEY_LENGTH *
				   2 * TCP_FASTOPEN_KEY_MAX) +
				   (TCP_FASTOPEN_KEY_MAX * 5)),
1038 1039
		.proc_handler	= proc_tcp_fastopen_key,
	},
1040 1041 1042 1043 1044 1045
	{
		.procname	= "tcp_fastopen_blackhole_timeout_sec",
		.data		= &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_tfo_blackhole_detect_timeout,
1046
		.extra1		= SYSCTL_ZERO,
1047
	},
1048 1049 1050 1051
#ifdef CONFIG_IP_ROUTE_MULTIPATH
	{
		.procname	= "fib_multipath_use_neigh",
		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1052
		.maxlen		= sizeof(u8),
1053
		.mode		= 0644,
1054
		.proc_handler	= proc_dou8vec_minmax,
1055 1056
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
1057 1058 1059 1060
	},
	{
		.procname	= "fib_multipath_hash_policy",
		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1061
		.maxlen		= sizeof(u8),
1062
		.mode		= 0644,
1063
		.proc_handler	= proc_fib_multipath_hash_policy,
1064
		.extra1		= SYSCTL_ZERO,
1065
		.extra2		= SYSCTL_THREE,
1066
	},
1067 1068 1069 1070 1071
	{
		.procname	= "fib_multipath_hash_fields",
		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
		.maxlen		= sizeof(u32),
		.mode		= 0644,
1072
		.proc_handler	= proc_fib_multipath_hash_fields,
1073 1074 1075
		.extra1		= SYSCTL_ONE,
		.extra2		= &fib_multipath_hash_fields_all_mask,
	},
1076
#endif
1077 1078 1079 1080 1081 1082 1083
	{
		.procname	= "ip_unprivileged_port_start",
		.maxlen		= sizeof(int),
		.data		= &init_net.ipv4.sysctl_ip_prot_sock,
		.mode		= 0644,
		.proc_handler	= ipv4_privileged_ports,
	},
1084 1085 1086 1087
#ifdef CONFIG_NET_L3_MASTER_DEV
	{
		.procname	= "udp_l3mdev_accept",
		.data		= &init_net.ipv4.sysctl_udp_l3mdev_accept,
1088
		.maxlen		= sizeof(u8),
1089
		.mode		= 0644,
1090
		.proc_handler	= proc_dou8vec_minmax,
1091 1092
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
1093 1094
	},
#endif
1095 1096 1097
	{
		.procname	= "tcp_sack",
		.data		= &init_net.ipv4.sysctl_tcp_sack,
1098
		.maxlen		= sizeof(u8),
1099
		.mode		= 0644,
1100
		.proc_handler	= proc_dou8vec_minmax,
1101
	},
1102 1103 1104
	{
		.procname	= "tcp_window_scaling",
		.data		= &init_net.ipv4.sysctl_tcp_window_scaling,
1105
		.maxlen		= sizeof(u8),
1106
		.mode		= 0644,
1107
		.proc_handler	= proc_dou8vec_minmax,
1108
	},
1109 1110 1111
	{
		.procname	= "tcp_timestamps",
		.data		= &init_net.ipv4.sysctl_tcp_timestamps,
1112
		.maxlen		= sizeof(u8),
1113
		.mode		= 0644,
1114
		.proc_handler	= proc_dou8vec_minmax,
1115
	},
1116 1117 1118
	{
		.procname	= "tcp_early_retrans",
		.data		= &init_net.ipv4.sysctl_tcp_early_retrans,
1119
		.maxlen		= sizeof(u8),
1120
		.mode		= 0644,
1121
		.proc_handler	= proc_dou8vec_minmax,
1122
		.extra1		= SYSCTL_ZERO,
1123
		.extra2		= SYSCTL_FOUR,
1124
	},
1125 1126 1127
	{
		.procname	= "tcp_recovery",
		.data		= &init_net.ipv4.sysctl_tcp_recovery,
1128
		.maxlen		= sizeof(u8),
1129
		.mode		= 0644,
1130
		.proc_handler	= proc_dou8vec_minmax,
1131
	},
1132 1133 1134
	{
		.procname       = "tcp_thin_linear_timeouts",
		.data           = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1135
		.maxlen         = sizeof(u8),
1136
		.mode           = 0644,
1137
		.proc_handler   = proc_dou8vec_minmax,
1138
	},
1139 1140 1141
	{
		.procname	= "tcp_slow_start_after_idle",
		.data		= &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1142
		.maxlen		= sizeof(u8),
1143
		.mode		= 0644,
1144
		.proc_handler	= proc_dou8vec_minmax,
1145
	},
1146 1147 1148
	{
		.procname	= "tcp_retrans_collapse",
		.data		= &init_net.ipv4.sysctl_tcp_retrans_collapse,
1149
		.maxlen		= sizeof(u8),
1150
		.mode		= 0644,
1151
		.proc_handler	= proc_dou8vec_minmax,
1152
	},
1153 1154 1155
	{
		.procname	= "tcp_stdurg",
		.data		= &init_net.ipv4.sysctl_tcp_stdurg,
1156
		.maxlen		= sizeof(u8),
1157
		.mode		= 0644,
1158
		.proc_handler	= proc_dou8vec_minmax,
1159
	},
1160 1161 1162
	{
		.procname	= "tcp_rfc1337",
		.data		= &init_net.ipv4.sysctl_tcp_rfc1337,
1163
		.maxlen		= sizeof(u8),
1164
		.mode		= 0644,
1165
		.proc_handler	= proc_dou8vec_minmax,
1166
	},
1167 1168 1169
	{
		.procname	= "tcp_abort_on_overflow",
		.data		= &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1170
		.maxlen		= sizeof(u8),
1171
		.mode		= 0644,
1172
		.proc_handler	= proc_dou8vec_minmax,
1173
	},
1174 1175 1176
	{
		.procname	= "tcp_fack",
		.data		= &init_net.ipv4.sysctl_tcp_fack,
1177
		.maxlen		= sizeof(u8),
1178
		.mode		= 0644,
1179
		.proc_handler	= proc_dou8vec_minmax,
1180
	},
1181 1182 1183 1184 1185 1186 1187
	{
		.procname	= "tcp_max_reordering",
		.data		= &init_net.ipv4.sysctl_tcp_max_reordering,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
1188 1189 1190
	{
		.procname	= "tcp_dsack",
		.data		= &init_net.ipv4.sysctl_tcp_dsack,
1191
		.maxlen		= sizeof(u8),
1192
		.mode		= 0644,
1193
		.proc_handler	= proc_dou8vec_minmax,
1194
	},
1195 1196 1197
	{
		.procname	= "tcp_app_win",
		.data		= &init_net.ipv4.sysctl_tcp_app_win,
1198
		.maxlen		= sizeof(u8),
1199
		.mode		= 0644,
1200
		.proc_handler	= proc_dou8vec_minmax,
1201
	},
1202 1203 1204 1205 1206 1207 1208 1209 1210
	{
		.procname	= "tcp_adv_win_scale",
		.data		= &init_net.ipv4.sysctl_tcp_adv_win_scale,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
		.extra1		= &tcp_adv_win_scale_min,
		.extra2		= &tcp_adv_win_scale_max,
	},
1211 1212 1213
	{
		.procname	= "tcp_frto",
		.data		= &init_net.ipv4.sysctl_tcp_frto,
1214
		.maxlen		= sizeof(u8),
1215
		.mode		= 0644,
1216
		.proc_handler	= proc_dou8vec_minmax,
1217
	},
1218 1219 1220
	{
		.procname	= "tcp_no_metrics_save",
		.data		= &init_net.ipv4.sysctl_tcp_nometrics_save,
1221
		.maxlen		= sizeof(u8),
1222
		.mode		= 0644,
1223
		.proc_handler	= proc_dou8vec_minmax,
1224
	},
1225 1226 1227
	{
		.procname	= "tcp_no_ssthresh_metrics_save",
		.data		= &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1228
		.maxlen		= sizeof(u8),
1229
		.mode		= 0644,
1230
		.proc_handler	= proc_dou8vec_minmax,
1231 1232 1233
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
	},
1234 1235 1236
	{
		.procname	= "tcp_moderate_rcvbuf",
		.data		= &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1237
		.maxlen		= sizeof(u8),
1238
		.mode		= 0644,
1239
		.proc_handler	= proc_dou8vec_minmax,
1240
	},
1241 1242 1243
	{
		.procname	= "tcp_tso_win_divisor",
		.data		= &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1244
		.maxlen		= sizeof(u8),
1245
		.mode		= 0644,
1246
		.proc_handler	= proc_dou8vec_minmax,
1247
	},
1248 1249 1250
	{
		.procname	= "tcp_workaround_signed_windows",
		.data		= &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1251
		.maxlen		= sizeof(u8),
1252
		.mode		= 0644,
1253
		.proc_handler	= proc_dou8vec_minmax,
1254
	},
1255 1256 1257 1258 1259 1260 1261
	{
		.procname	= "tcp_limit_output_bytes",
		.data		= &init_net.ipv4.sysctl_tcp_limit_output_bytes,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
1262 1263 1264 1265 1266 1267 1268
	{
		.procname	= "tcp_challenge_ack_limit",
		.data		= &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
1269 1270 1271
	{
		.procname	= "tcp_min_tso_segs",
		.data		= &init_net.ipv4.sysctl_tcp_min_tso_segs,
1272
		.maxlen		= sizeof(u8),
1273
		.mode		= 0644,
1274
		.proc_handler	= proc_dou8vec_minmax,
1275
		.extra1		= SYSCTL_ONE,
1276
	},
1277 1278 1279 1280 1281 1282 1283
	{
		.procname	= "tcp_tso_rtt_log",
		.data		= &init_net.ipv4.sysctl_tcp_tso_rtt_log,
		.maxlen		= sizeof(u8),
		.mode		= 0644,
		.proc_handler	= proc_dou8vec_minmax,
	},
1284 1285 1286 1287 1288
	{
		.procname	= "tcp_min_rtt_wlen",
		.data		= &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
		.maxlen		= sizeof(int),
		.mode		= 0644,
1289
		.proc_handler	= proc_dointvec_minmax,
1290
		.extra1		= SYSCTL_ZERO,
1291
		.extra2		= &one_day_secs
1292
	},
1293 1294 1295
	{
		.procname	= "tcp_autocorking",
		.data		= &init_net.ipv4.sysctl_tcp_autocorking,
1296
		.maxlen		= sizeof(u8),
1297
		.mode		= 0644,
1298
		.proc_handler	= proc_dou8vec_minmax,
1299 1300
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
1301
	},
1302 1303 1304 1305 1306 1307 1308
	{
		.procname	= "tcp_invalid_ratelimit",
		.data		= &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_ms_jiffies,
	},
1309 1310 1311 1312 1313 1314
	{
		.procname	= "tcp_pacing_ss_ratio",
		.data		= &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
1315
		.extra1		= SYSCTL_ZERO,
1316
		.extra2		= SYSCTL_ONE_THOUSAND,
1317
	},
1318 1319 1320 1321 1322 1323
	{
		.procname	= "tcp_pacing_ca_ratio",
		.data		= &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
1324
		.extra1		= SYSCTL_ZERO,
1325
		.extra2		= SYSCTL_ONE_THOUSAND,
1326
	},
1327 1328 1329 1330 1331 1332
	{
		.procname	= "tcp_wmem",
		.data		= &init_net.ipv4.sysctl_tcp_wmem,
		.maxlen		= sizeof(init_net.ipv4.sysctl_tcp_wmem),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
1333
		.extra1		= SYSCTL_ONE,
1334 1335 1336 1337 1338 1339 1340
	},
	{
		.procname	= "tcp_rmem",
		.data		= &init_net.ipv4.sysctl_tcp_rmem,
		.maxlen		= sizeof(init_net.ipv4.sysctl_tcp_rmem),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
1341
		.extra1		= SYSCTL_ONE,
1342
	},
1343 1344 1345 1346 1347 1348 1349
	{
		.procname	= "tcp_comp_sack_delay_ns",
		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
		.maxlen		= sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= proc_doulongvec_minmax,
	},
1350 1351 1352 1353 1354 1355 1356
	{
		.procname	= "tcp_comp_sack_slack_ns",
		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
		.maxlen		= sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= proc_doulongvec_minmax,
	},
1357 1358 1359
	{
		.procname	= "tcp_comp_sack_nr",
		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1360
		.maxlen		= sizeof(u8),
1361
		.mode		= 0644,
1362
		.proc_handler	= proc_dou8vec_minmax,
1363
		.extra1		= SYSCTL_ZERO,
1364
	},
1365 1366 1367
	{
		.procname       = "tcp_reflect_tos",
		.data           = &init_net.ipv4.sysctl_tcp_reflect_tos,
1368
		.maxlen         = sizeof(u8),
1369
		.mode           = 0644,
1370
		.proc_handler   = proc_dou8vec_minmax,
1371 1372 1373
		.extra1         = SYSCTL_ZERO,
		.extra2         = SYSCTL_ONE,
	},
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
	{
		.procname	= "tcp_ehash_entries",
		.data		= &init_net.ipv4.sysctl_tcp_child_ehash_entries,
		.mode		= 0444,
		.proc_handler	= proc_tcp_ehash_entries,
	},
	{
		.procname	= "tcp_child_ehash_entries",
		.data		= &init_net.ipv4.sysctl_tcp_child_ehash_entries,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= proc_douintvec_minmax,
		.extra1		= SYSCTL_ZERO,
		.extra2		= &tcp_child_ehash_entries_max,
	},
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
	{
		.procname	= "udp_hash_entries",
		.data		= &init_net.ipv4.sysctl_udp_child_hash_entries,
		.mode		= 0444,
		.proc_handler	= proc_udp_hash_entries,
	},
	{
		.procname	= "udp_child_hash_entries",
		.data		= &init_net.ipv4.sysctl_udp_child_hash_entries,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= proc_douintvec_minmax,
		.extra1		= SYSCTL_ZERO,
		.extra2		= &udp_child_hash_entries_max,
	},
1404 1405 1406 1407 1408 1409
	{
		.procname	= "udp_rmem_min",
		.data		= &init_net.ipv4.sysctl_udp_rmem_min,
		.maxlen		= sizeof(init_net.ipv4.sysctl_udp_rmem_min),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
1410
		.extra1		= SYSCTL_ONE
1411 1412 1413 1414 1415 1416 1417
	},
	{
		.procname	= "udp_wmem_min",
		.data		= &init_net.ipv4.sysctl_udp_wmem_min,
		.maxlen		= sizeof(init_net.ipv4.sysctl_udp_wmem_min),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
1418
		.extra1		= SYSCTL_ONE
1419
	},
1420 1421 1422
	{
		.procname	= "fib_notify_on_flag_change",
		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1423
		.maxlen		= sizeof(u8),
1424
		.mode		= 0644,
1425
		.proc_handler	= proc_dou8vec_minmax,
1426
		.extra1		= SYSCTL_ZERO,
1427
		.extra2		= SYSCTL_TWO,
1428
	},
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
	{
		.procname       = "tcp_plb_enabled",
		.data           = &init_net.ipv4.sysctl_tcp_plb_enabled,
		.maxlen         = sizeof(u8),
		.mode           = 0644,
		.proc_handler   = proc_dou8vec_minmax,
		.extra1         = SYSCTL_ZERO,
		.extra2         = SYSCTL_ONE,
	},
	{
		.procname       = "tcp_plb_idle_rehash_rounds",
		.data           = &init_net.ipv4.sysctl_tcp_plb_idle_rehash_rounds,
		.maxlen         = sizeof(u8),
		.mode           = 0644,
		.proc_handler   = proc_dou8vec_minmax,
		.extra2		= &tcp_plb_max_rounds,
	},
	{
		.procname       = "tcp_plb_rehash_rounds",
		.data           = &init_net.ipv4.sysctl_tcp_plb_rehash_rounds,
		.maxlen         = sizeof(u8),
		.mode           = 0644,
		.proc_handler   = proc_dou8vec_minmax,
		.extra2         = &tcp_plb_max_rounds,
	},
	{
		.procname       = "tcp_plb_suspend_rto_sec",
		.data           = &init_net.ipv4.sysctl_tcp_plb_suspend_rto_sec,
		.maxlen         = sizeof(u8),
		.mode           = 0644,
		.proc_handler   = proc_dou8vec_minmax,
	},
	{
		.procname       = "tcp_plb_cong_thresh",
		.data           = &init_net.ipv4.sysctl_tcp_plb_cong_thresh,
		.maxlen         = sizeof(int),
		.mode           = 0644,
		.proc_handler   = proc_dointvec_minmax,
		.extra1         = SYSCTL_ZERO,
		.extra2         = &tcp_plb_max_cong_thresh,
	},
1470 1471 1472
	{ }
};

1473 1474
static __net_init int ipv4_sysctl_init_net(struct net *net)
{
1475 1476 1477
	struct ctl_table *table;

	table = ipv4_net_table;
1478
	if (!net_eq(net, &init_net)) {
1479 1480
		int i;

1481
		table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1482
		if (!table)
1483 1484
			goto err_alloc;

1485
		for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
			if (table[i].data) {
				/* Update the variables to point into
				 * the current struct net
				 */
				table[i].data += (void *)net - (void *)&init_net;
			} else {
				/* Entries without data pointer are global;
				 * Make them read-only in non-init_net ns
				 */
				table[i].mode &= ~0222;
			}
		}
1498 1499
	}

1500
	net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1501
	if (!net->ipv4.ipv4_hdr)
1502 1503
		goto err_reg;

1504 1505 1506 1507
	net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
	if (!net->ipv4.sysctl_local_reserved_ports)
		goto err_ports;

1508
	return 0;
1509

1510 1511
err_ports:
	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1512
err_reg:
1513
	if (!net_eq(net, &init_net))
1514 1515 1516
		kfree(table);
err_alloc:
	return -ENOMEM;
1517 1518 1519 1520
}

static __net_exit void ipv4_sysctl_exit_net(struct net *net)
{
1521 1522
	struct ctl_table *table;

1523
	kfree(net->ipv4.sysctl_local_reserved_ports);
1524 1525 1526
	table = net->ipv4.ipv4_hdr->ctl_table_arg;
	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
	kfree(table);
1527 1528 1529 1530 1531 1532 1533
}

static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
	.init = ipv4_sysctl_init_net,
	.exit = ipv4_sysctl_exit_net,
};

1534 1535 1536 1537
static __init int sysctl_ipv4_init(void)
{
	struct ctl_table_header *hdr;

1538
	hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1539
	if (!hdr)
1540 1541 1542
		return -ENOMEM;

	if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1543
		unregister_net_sysctl_table(hdr);
1544 1545 1546 1547
		return -ENOMEM;
	}

	return 0;
1548 1549 1550
}

__initcall(sysctl_ipv4_init);