xref: /linux/net/ipv4/sysctl_net_ipv4.c (revision 2a52ca7c98960aafb0eca9ef96b2d0c932171357)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4  *
5  * Begun April 1, 1996, Mike Shaver.
6  * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
7  */
8 
9 #include <linux/sysctl.h>
10 #include <linux/seqlock.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include <net/icmp.h>
14 #include <net/ip.h>
15 #include <net/ip_fib.h>
16 #include <net/tcp.h>
17 #include <net/udp.h>
18 #include <net/cipso_ipv4.h>
19 #include <net/ping.h>
20 #include <net/protocol.h>
21 #include <net/netevent.h>
22 
23 static int tcp_retr1_max = 255;
24 static int ip_local_port_range_min[] = { 1, 1 };
25 static int ip_local_port_range_max[] = { 65535, 65535 };
26 static int tcp_adv_win_scale_min = -31;
27 static int tcp_adv_win_scale_max = 31;
28 static int tcp_app_win_max = 31;
29 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
30 static int tcp_min_snd_mss_max = 65535;
31 static int ip_privileged_port_min;
32 static int ip_privileged_port_max = 65535;
33 static int ip_ttl_min = 1;
34 static int ip_ttl_max = 255;
35 static int tcp_syn_retries_min = 1;
36 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
37 static int tcp_syn_linear_timeouts_max = MAX_TCP_SYNCNT;
38 static unsigned long ip_ping_group_range_min[] = { 0, 0 };
39 static unsigned long ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
40 static u32 u32_max_div_HZ = UINT_MAX / HZ;
41 static int one_day_secs = 24 * 3600;
42 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
43 	FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
44 static unsigned int tcp_child_ehash_entries_max = 16 * 1024 * 1024;
45 static unsigned int udp_child_hash_entries_max = UDP_HTABLE_SIZE_MAX;
46 static int tcp_plb_max_rounds = 31;
47 static int tcp_plb_max_cong_thresh = 256;
48 
49 /* obsolete */
50 static int sysctl_tcp_low_latency __read_mostly;
51 
52 /* Update system visible IP port range */
53 static void set_local_port_range(struct net *net, unsigned int low, unsigned int high)
54 {
55 	bool same_parity = !((low ^ high) & 1);
56 
57 	if (same_parity && !net->ipv4.ip_local_ports.warned) {
58 		net->ipv4.ip_local_ports.warned = true;
59 		pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
60 	}
61 	WRITE_ONCE(net->ipv4.ip_local_ports.range, high << 16 | low);
62 }
63 
64 /* Validate changes from /proc interface. */
65 static int ipv4_local_port_range(struct ctl_table *table, int write,
66 				 void *buffer, size_t *lenp, loff_t *ppos)
67 {
68 	struct net *net = table->data;
69 	int ret;
70 	int range[2];
71 	struct ctl_table tmp = {
72 		.data = &range,
73 		.maxlen = sizeof(range),
74 		.mode = table->mode,
75 		.extra1 = &ip_local_port_range_min,
76 		.extra2 = &ip_local_port_range_max,
77 	};
78 
79 	inet_get_local_port_range(net, &range[0], &range[1]);
80 
81 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
82 
83 	if (write && ret == 0) {
84 		/* Ensure that the upper limit is not smaller than the lower,
85 		 * and that the lower does not encroach upon the privileged
86 		 * port limit.
87 		 */
88 		if ((range[1] < range[0]) ||
89 		    (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
90 			ret = -EINVAL;
91 		else
92 			set_local_port_range(net, range[0], range[1]);
93 	}
94 
95 	return ret;
96 }
97 
98 /* Validate changes from /proc interface. */
99 static int ipv4_privileged_ports(struct ctl_table *table, int write,
100 				void *buffer, size_t *lenp, loff_t *ppos)
101 {
102 	struct net *net = container_of(table->data, struct net,
103 	    ipv4.sysctl_ip_prot_sock);
104 	int ret;
105 	int pports;
106 	int range[2];
107 	struct ctl_table tmp = {
108 		.data = &pports,
109 		.maxlen = sizeof(pports),
110 		.mode = table->mode,
111 		.extra1 = &ip_privileged_port_min,
112 		.extra2 = &ip_privileged_port_max,
113 	};
114 
115 	pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
116 
117 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
118 
119 	if (write && ret == 0) {
120 		inet_get_local_port_range(net, &range[0], &range[1]);
121 		/* Ensure that the local port range doesn't overlap with the
122 		 * privileged port range.
123 		 */
124 		if (range[0] < pports)
125 			ret = -EINVAL;
126 		else
127 			WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
128 	}
129 
130 	return ret;
131 }
132 
133 static void inet_get_ping_group_range_table(const struct ctl_table *table,
134 					    kgid_t *low, kgid_t *high)
135 {
136 	kgid_t *data = table->data;
137 	struct net *net =
138 		container_of(table->data, struct net, ipv4.ping_group_range.range);
139 	unsigned int seq;
140 	do {
141 		seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
142 
143 		*low = data[0];
144 		*high = data[1];
145 	} while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
146 }
147 
148 /* Update system visible IP port range */
149 static void set_ping_group_range(const struct ctl_table *table,
150 				 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 	data[0] = low;
157 	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 	unsigned long urange[2];
168 	kgid_t low, high;
169 	struct ctl_table tmp = {
170 		.data = &urange,
171 		.maxlen = sizeof(urange),
172 		.mode = table->mode,
173 		.extra1 = &ip_ping_group_range_min,
174 		.extra2 = &ip_ping_group_range_max,
175 	};
176 
177 	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);
180 	ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
181 
182 	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 			return -EINVAL;
187 		if (urange[1] < urange[0] || gid_lt(high, low)) {
188 			low = make_kgid(&init_user_ns, 1);
189 			high = make_kgid(&init_user_ns, 0);
190 		}
191 		set_ping_group_range(table, low, high);
192 	}
193 
194 	return ret;
195 }
196 
197 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
198 				    void *buffer, size_t *lenp, loff_t *ppos)
199 {
200 	struct net *net;
201 	int ret;
202 
203 	net = container_of(table->data, struct net,
204 			   ipv4.sysctl_ip_fwd_update_priority);
205 	ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
206 	if (write && ret == 0)
207 		call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
208 					net);
209 
210 	return ret;
211 }
212 
213 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
214 				       void *buffer, size_t *lenp, loff_t *ppos)
215 {
216 	struct net *net = container_of(ctl->data, struct net,
217 				       ipv4.tcp_congestion_control);
218 	char val[TCP_CA_NAME_MAX];
219 	struct ctl_table tbl = {
220 		.data = val,
221 		.maxlen = TCP_CA_NAME_MAX,
222 	};
223 	int ret;
224 
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 	return ret;
231 }
232 
233 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
234 						 int write, void *buffer,
235 						 size_t *lenp, loff_t *ppos)
236 {
237 	struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
238 	int ret;
239 
240 	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
241 	if (!tbl.data)
242 		return -ENOMEM;
243 	tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
244 	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
245 	kfree(tbl.data);
246 	return ret;
247 }
248 
249 static int proc_allowed_congestion_control(struct ctl_table *ctl,
250 					   int write, void *buffer,
251 					   size_t *lenp, loff_t *ppos)
252 {
253 	struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
254 	int ret;
255 
256 	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
257 	if (!tbl.data)
258 		return -ENOMEM;
259 
260 	tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
261 	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
262 	if (write && ret == 0)
263 		ret = tcp_set_allowed_congestion_control(tbl.data);
264 	kfree(tbl.data);
265 	return ret;
266 }
267 
268 static int sscanf_key(char *buf, __le32 *key)
269 {
270 	u32 user_key[4];
271 	int i, ret = 0;
272 
273 	if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
274 		   user_key + 2, user_key + 3) != 4) {
275 		ret = -EINVAL;
276 	} else {
277 		for (i = 0; i < ARRAY_SIZE(user_key); i++)
278 			key[i] = cpu_to_le32(user_key[i]);
279 	}
280 	pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
281 		 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
282 
283 	return ret;
284 }
285 
286 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
287 				 void *buffer, size_t *lenp, loff_t *ppos)
288 {
289 	struct net *net = container_of(table->data, struct net,
290 	    ipv4.sysctl_tcp_fastopen);
291 	/* maxlen to print the list of keys in hex (*2), with dashes
292 	 * separating doublewords and a comma in between keys.
293 	 */
294 	struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
295 					    2 * TCP_FASTOPEN_KEY_MAX) +
296 					    (TCP_FASTOPEN_KEY_MAX * 5)) };
297 	u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
298 	__le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
299 	char *backup_data;
300 	int ret, i = 0, off = 0, n_keys;
301 
302 	tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
303 	if (!tbl.data)
304 		return -ENOMEM;
305 
306 	n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
307 	if (!n_keys) {
308 		memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
309 		n_keys = 1;
310 	}
311 
312 	for (i = 0; i < n_keys * 4; i++)
313 		user_key[i] = le32_to_cpu(key[i]);
314 
315 	for (i = 0; i < n_keys; i++) {
316 		off += snprintf(tbl.data + off, tbl.maxlen - off,
317 				"%08x-%08x-%08x-%08x",
318 				user_key[i * 4],
319 				user_key[i * 4 + 1],
320 				user_key[i * 4 + 2],
321 				user_key[i * 4 + 3]);
322 
323 		if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
324 			break;
325 
326 		if (i + 1 < n_keys)
327 			off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
328 	}
329 
330 	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
331 
332 	if (write && ret == 0) {
333 		backup_data = strchr(tbl.data, ',');
334 		if (backup_data) {
335 			*backup_data = '\0';
336 			backup_data++;
337 		}
338 		if (sscanf_key(tbl.data, key)) {
339 			ret = -EINVAL;
340 			goto bad_key;
341 		}
342 		if (backup_data) {
343 			if (sscanf_key(backup_data, key + 4)) {
344 				ret = -EINVAL;
345 				goto bad_key;
346 			}
347 		}
348 		tcp_fastopen_reset_cipher(net, NULL, key,
349 					  backup_data ? key + 4 : NULL);
350 	}
351 
352 bad_key:
353 	kfree(tbl.data);
354 	return ret;
355 }
356 
357 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
358 					     int write, void *buffer,
359 					     size_t *lenp, loff_t *ppos)
360 {
361 	struct net *net = container_of(table->data, struct net,
362 	    ipv4.sysctl_tcp_fastopen_blackhole_timeout);
363 	int ret;
364 
365 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
366 	if (write && ret == 0)
367 		atomic_set(&net->ipv4.tfo_active_disable_times, 0);
368 
369 	return ret;
370 }
371 
372 static int proc_tcp_available_ulp(struct ctl_table *ctl,
373 				  int write, void *buffer, size_t *lenp,
374 				  loff_t *ppos)
375 {
376 	struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
377 	int ret;
378 
379 	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
380 	if (!tbl.data)
381 		return -ENOMEM;
382 	tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
383 	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
384 	kfree(tbl.data);
385 
386 	return ret;
387 }
388 
389 static int proc_tcp_ehash_entries(struct ctl_table *table, int write,
390 				  void *buffer, size_t *lenp, loff_t *ppos)
391 {
392 	struct net *net = container_of(table->data, struct net,
393 				       ipv4.sysctl_tcp_child_ehash_entries);
394 	struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
395 	int tcp_ehash_entries;
396 	struct ctl_table tbl;
397 
398 	tcp_ehash_entries = hinfo->ehash_mask + 1;
399 
400 	/* A negative number indicates that the child netns
401 	 * shares the global ehash.
402 	 */
403 	if (!net_eq(net, &init_net) && !hinfo->pernet)
404 		tcp_ehash_entries *= -1;
405 
406 	memset(&tbl, 0, sizeof(tbl));
407 	tbl.data = &tcp_ehash_entries;
408 	tbl.maxlen = sizeof(int);
409 
410 	return proc_dointvec(&tbl, write, buffer, lenp, ppos);
411 }
412 
413 static int proc_udp_hash_entries(struct ctl_table *table, int write,
414 				 void *buffer, size_t *lenp, loff_t *ppos)
415 {
416 	struct net *net = container_of(table->data, struct net,
417 				       ipv4.sysctl_udp_child_hash_entries);
418 	int udp_hash_entries;
419 	struct ctl_table tbl;
420 
421 	udp_hash_entries = net->ipv4.udp_table->mask + 1;
422 
423 	/* A negative number indicates that the child netns
424 	 * shares the global udp_table.
425 	 */
426 	if (!net_eq(net, &init_net) && net->ipv4.udp_table == &udp_table)
427 		udp_hash_entries *= -1;
428 
429 	memset(&tbl, 0, sizeof(tbl));
430 	tbl.data = &udp_hash_entries;
431 	tbl.maxlen = sizeof(int);
432 
433 	return proc_dointvec(&tbl, write, buffer, lenp, ppos);
434 }
435 
436 #ifdef CONFIG_IP_ROUTE_MULTIPATH
437 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
438 					  void *buffer, size_t *lenp,
439 					  loff_t *ppos)
440 {
441 	struct net *net = container_of(table->data, struct net,
442 	    ipv4.sysctl_fib_multipath_hash_policy);
443 	int ret;
444 
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 	return ret;
450 }
451 
452 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
453 					  void *buffer, size_t *lenp,
454 					  loff_t *ppos)
455 {
456 	struct net *net;
457 	int ret;
458 
459 	net = container_of(table->data, struct net,
460 			   ipv4.sysctl_fib_multipath_hash_fields);
461 	ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
462 	if (write && ret == 0)
463 		call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
464 
465 	return ret;
466 }
467 #endif
468 
469 static struct ctl_table ipv4_table[] = {
470 	{
471 		.procname	= "tcp_max_orphans",
472 		.data		= &sysctl_tcp_max_orphans,
473 		.maxlen		= sizeof(int),
474 		.mode		= 0644,
475 		.proc_handler	= proc_dointvec
476 	},
477 	{
478 		.procname	= "inet_peer_threshold",
479 		.data		= &inet_peer_threshold,
480 		.maxlen		= sizeof(int),
481 		.mode		= 0644,
482 		.proc_handler	= proc_dointvec
483 	},
484 	{
485 		.procname	= "inet_peer_minttl",
486 		.data		= &inet_peer_minttl,
487 		.maxlen		= sizeof(int),
488 		.mode		= 0644,
489 		.proc_handler	= proc_dointvec_jiffies,
490 	},
491 	{
492 		.procname	= "inet_peer_maxttl",
493 		.data		= &inet_peer_maxttl,
494 		.maxlen		= sizeof(int),
495 		.mode		= 0644,
496 		.proc_handler	= proc_dointvec_jiffies,
497 	},
498 	{
499 		.procname	= "tcp_mem",
500 		.maxlen		= sizeof(sysctl_tcp_mem),
501 		.data		= &sysctl_tcp_mem,
502 		.mode		= 0644,
503 		.proc_handler	= proc_doulongvec_minmax,
504 	},
505 	{
506 		.procname	= "tcp_low_latency",
507 		.data		= &sysctl_tcp_low_latency,
508 		.maxlen		= sizeof(int),
509 		.mode		= 0644,
510 		.proc_handler	= proc_dointvec
511 	},
512 #ifdef CONFIG_NETLABEL
513 	{
514 		.procname	= "cipso_cache_enable",
515 		.data		= &cipso_v4_cache_enabled,
516 		.maxlen		= sizeof(int),
517 		.mode		= 0644,
518 		.proc_handler	= proc_dointvec,
519 	},
520 	{
521 		.procname	= "cipso_cache_bucket_size",
522 		.data		= &cipso_v4_cache_bucketsize,
523 		.maxlen		= sizeof(int),
524 		.mode		= 0644,
525 		.proc_handler	= proc_dointvec,
526 	},
527 	{
528 		.procname	= "cipso_rbm_optfmt",
529 		.data		= &cipso_v4_rbm_optfmt,
530 		.maxlen		= sizeof(int),
531 		.mode		= 0644,
532 		.proc_handler	= proc_dointvec,
533 	},
534 	{
535 		.procname	= "cipso_rbm_strictvalid",
536 		.data		= &cipso_v4_rbm_strictvalid,
537 		.maxlen		= sizeof(int),
538 		.mode		= 0644,
539 		.proc_handler	= proc_dointvec,
540 	},
541 #endif /* CONFIG_NETLABEL */
542 	{
543 		.procname	= "tcp_available_ulp",
544 		.maxlen		= TCP_ULP_BUF_MAX,
545 		.mode		= 0444,
546 		.proc_handler   = proc_tcp_available_ulp,
547 	},
548 	{
549 		.procname	= "icmp_msgs_per_sec",
550 		.data		= &sysctl_icmp_msgs_per_sec,
551 		.maxlen		= sizeof(int),
552 		.mode		= 0644,
553 		.proc_handler	= proc_dointvec_minmax,
554 		.extra1		= SYSCTL_ZERO,
555 	},
556 	{
557 		.procname	= "icmp_msgs_burst",
558 		.data		= &sysctl_icmp_msgs_burst,
559 		.maxlen		= sizeof(int),
560 		.mode		= 0644,
561 		.proc_handler	= proc_dointvec_minmax,
562 		.extra1		= SYSCTL_ZERO,
563 	},
564 	{
565 		.procname	= "udp_mem",
566 		.data		= &sysctl_udp_mem,
567 		.maxlen		= sizeof(sysctl_udp_mem),
568 		.mode		= 0644,
569 		.proc_handler	= proc_doulongvec_minmax,
570 	},
571 	{
572 		.procname	= "fib_sync_mem",
573 		.data		= &sysctl_fib_sync_mem,
574 		.maxlen		= sizeof(sysctl_fib_sync_mem),
575 		.mode		= 0644,
576 		.proc_handler	= proc_douintvec_minmax,
577 		.extra1		= &sysctl_fib_sync_mem_min,
578 		.extra2		= &sysctl_fib_sync_mem_max,
579 	},
580 };
581 
582 static struct ctl_table ipv4_net_table[] = {
583 	{
584 		.procname	= "tcp_max_tw_buckets",
585 		.data		= &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
586 		.maxlen		= sizeof(int),
587 		.mode		= 0644,
588 		.proc_handler	= proc_dointvec
589 	},
590 	{
591 		.procname	= "icmp_echo_ignore_all",
592 		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
593 		.maxlen		= sizeof(u8),
594 		.mode		= 0644,
595 		.proc_handler	= proc_dou8vec_minmax,
596 		.extra1		= SYSCTL_ZERO,
597 		.extra2		= SYSCTL_ONE
598 	},
599 	{
600 		.procname	= "icmp_echo_enable_probe",
601 		.data		= &init_net.ipv4.sysctl_icmp_echo_enable_probe,
602 		.maxlen		= sizeof(u8),
603 		.mode		= 0644,
604 		.proc_handler	= proc_dou8vec_minmax,
605 		.extra1		= SYSCTL_ZERO,
606 		.extra2		= SYSCTL_ONE
607 	},
608 	{
609 		.procname	= "icmp_echo_ignore_broadcasts",
610 		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
611 		.maxlen		= sizeof(u8),
612 		.mode		= 0644,
613 		.proc_handler	= proc_dou8vec_minmax,
614 		.extra1		= SYSCTL_ZERO,
615 		.extra2		= SYSCTL_ONE
616 	},
617 	{
618 		.procname	= "icmp_ignore_bogus_error_responses",
619 		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
620 		.maxlen		= sizeof(u8),
621 		.mode		= 0644,
622 		.proc_handler	= proc_dou8vec_minmax,
623 		.extra1		= SYSCTL_ZERO,
624 		.extra2		= SYSCTL_ONE
625 	},
626 	{
627 		.procname	= "icmp_errors_use_inbound_ifaddr",
628 		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
629 		.maxlen		= sizeof(u8),
630 		.mode		= 0644,
631 		.proc_handler	= proc_dou8vec_minmax,
632 		.extra1		= SYSCTL_ZERO,
633 		.extra2		= SYSCTL_ONE
634 	},
635 	{
636 		.procname	= "icmp_ratelimit",
637 		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
638 		.maxlen		= sizeof(int),
639 		.mode		= 0644,
640 		.proc_handler	= proc_dointvec_ms_jiffies,
641 	},
642 	{
643 		.procname	= "icmp_ratemask",
644 		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
645 		.maxlen		= sizeof(int),
646 		.mode		= 0644,
647 		.proc_handler	= proc_dointvec
648 	},
649 	{
650 		.procname	= "ping_group_range",
651 		.data		= &init_net.ipv4.ping_group_range.range,
652 		.maxlen		= sizeof(gid_t)*2,
653 		.mode		= 0644,
654 		.proc_handler	= ipv4_ping_group_range,
655 	},
656 #ifdef CONFIG_NET_L3_MASTER_DEV
657 	{
658 		.procname	= "raw_l3mdev_accept",
659 		.data		= &init_net.ipv4.sysctl_raw_l3mdev_accept,
660 		.maxlen		= sizeof(u8),
661 		.mode		= 0644,
662 		.proc_handler	= proc_dou8vec_minmax,
663 		.extra1		= SYSCTL_ZERO,
664 		.extra2		= SYSCTL_ONE,
665 	},
666 #endif
667 	{
668 		.procname	= "tcp_ecn",
669 		.data		= &init_net.ipv4.sysctl_tcp_ecn,
670 		.maxlen		= sizeof(u8),
671 		.mode		= 0644,
672 		.proc_handler	= proc_dou8vec_minmax,
673 		.extra1		= SYSCTL_ZERO,
674 		.extra2		= SYSCTL_TWO,
675 	},
676 	{
677 		.procname	= "tcp_ecn_fallback",
678 		.data		= &init_net.ipv4.sysctl_tcp_ecn_fallback,
679 		.maxlen		= sizeof(u8),
680 		.mode		= 0644,
681 		.proc_handler	= proc_dou8vec_minmax,
682 		.extra1		= SYSCTL_ZERO,
683 		.extra2		= SYSCTL_ONE,
684 	},
685 	{
686 		.procname	= "ip_dynaddr",
687 		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
688 		.maxlen		= sizeof(u8),
689 		.mode		= 0644,
690 		.proc_handler	= proc_dou8vec_minmax,
691 	},
692 	{
693 		.procname	= "ip_early_demux",
694 		.data		= &init_net.ipv4.sysctl_ip_early_demux,
695 		.maxlen		= sizeof(u8),
696 		.mode		= 0644,
697 		.proc_handler	= proc_dou8vec_minmax,
698 	},
699 	{
700 		.procname       = "udp_early_demux",
701 		.data           = &init_net.ipv4.sysctl_udp_early_demux,
702 		.maxlen         = sizeof(u8),
703 		.mode           = 0644,
704 		.proc_handler   = proc_dou8vec_minmax,
705 	},
706 	{
707 		.procname       = "tcp_early_demux",
708 		.data           = &init_net.ipv4.sysctl_tcp_early_demux,
709 		.maxlen         = sizeof(u8),
710 		.mode           = 0644,
711 		.proc_handler   = proc_dou8vec_minmax,
712 	},
713 	{
714 		.procname       = "nexthop_compat_mode",
715 		.data           = &init_net.ipv4.sysctl_nexthop_compat_mode,
716 		.maxlen         = sizeof(u8),
717 		.mode           = 0644,
718 		.proc_handler   = proc_dou8vec_minmax,
719 		.extra1		= SYSCTL_ZERO,
720 		.extra2		= SYSCTL_ONE,
721 	},
722 	{
723 		.procname	= "ip_default_ttl",
724 		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
725 		.maxlen		= sizeof(u8),
726 		.mode		= 0644,
727 		.proc_handler	= proc_dou8vec_minmax,
728 		.extra1		= &ip_ttl_min,
729 		.extra2		= &ip_ttl_max,
730 	},
731 	{
732 		.procname	= "ip_local_port_range",
733 		.maxlen		= 0,
734 		.data		= &init_net,
735 		.mode		= 0644,
736 		.proc_handler	= ipv4_local_port_range,
737 	},
738 	{
739 		.procname	= "ip_local_reserved_ports",
740 		.data		= &init_net.ipv4.sysctl_local_reserved_ports,
741 		.maxlen		= 65536,
742 		.mode		= 0644,
743 		.proc_handler	= proc_do_large_bitmap,
744 	},
745 	{
746 		.procname	= "ip_no_pmtu_disc",
747 		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
748 		.maxlen		= sizeof(u8),
749 		.mode		= 0644,
750 		.proc_handler	= proc_dou8vec_minmax,
751 	},
752 	{
753 		.procname	= "ip_forward_use_pmtu",
754 		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
755 		.maxlen		= sizeof(u8),
756 		.mode		= 0644,
757 		.proc_handler	= proc_dou8vec_minmax,
758 	},
759 	{
760 		.procname	= "ip_forward_update_priority",
761 		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
762 		.maxlen		= sizeof(u8),
763 		.mode		= 0644,
764 		.proc_handler   = ipv4_fwd_update_priority,
765 		.extra1		= SYSCTL_ZERO,
766 		.extra2		= SYSCTL_ONE,
767 	},
768 	{
769 		.procname	= "ip_nonlocal_bind",
770 		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
771 		.maxlen		= sizeof(u8),
772 		.mode		= 0644,
773 		.proc_handler	= proc_dou8vec_minmax,
774 	},
775 	{
776 		.procname	= "ip_autobind_reuse",
777 		.data		= &init_net.ipv4.sysctl_ip_autobind_reuse,
778 		.maxlen		= sizeof(u8),
779 		.mode		= 0644,
780 		.proc_handler	= proc_dou8vec_minmax,
781 		.extra1         = SYSCTL_ZERO,
782 		.extra2         = SYSCTL_ONE,
783 	},
784 	{
785 		.procname	= "fwmark_reflect",
786 		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
787 		.maxlen		= sizeof(u8),
788 		.mode		= 0644,
789 		.proc_handler	= proc_dou8vec_minmax,
790 	},
791 	{
792 		.procname	= "tcp_fwmark_accept",
793 		.data		= &init_net.ipv4.sysctl_tcp_fwmark_accept,
794 		.maxlen		= sizeof(u8),
795 		.mode		= 0644,
796 		.proc_handler	= proc_dou8vec_minmax,
797 	},
798 #ifdef CONFIG_NET_L3_MASTER_DEV
799 	{
800 		.procname	= "tcp_l3mdev_accept",
801 		.data		= &init_net.ipv4.sysctl_tcp_l3mdev_accept,
802 		.maxlen		= sizeof(u8),
803 		.mode		= 0644,
804 		.proc_handler	= proc_dou8vec_minmax,
805 		.extra1		= SYSCTL_ZERO,
806 		.extra2		= SYSCTL_ONE,
807 	},
808 #endif
809 	{
810 		.procname	= "tcp_mtu_probing",
811 		.data		= &init_net.ipv4.sysctl_tcp_mtu_probing,
812 		.maxlen		= sizeof(u8),
813 		.mode		= 0644,
814 		.proc_handler	= proc_dou8vec_minmax,
815 	},
816 	{
817 		.procname	= "tcp_base_mss",
818 		.data		= &init_net.ipv4.sysctl_tcp_base_mss,
819 		.maxlen		= sizeof(int),
820 		.mode		= 0644,
821 		.proc_handler	= proc_dointvec,
822 	},
823 	{
824 		.procname	= "tcp_min_snd_mss",
825 		.data		= &init_net.ipv4.sysctl_tcp_min_snd_mss,
826 		.maxlen		= sizeof(int),
827 		.mode		= 0644,
828 		.proc_handler	= proc_dointvec_minmax,
829 		.extra1		= &tcp_min_snd_mss_min,
830 		.extra2		= &tcp_min_snd_mss_max,
831 	},
832 	{
833 		.procname	= "tcp_mtu_probe_floor",
834 		.data		= &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
835 		.maxlen		= sizeof(int),
836 		.mode		= 0644,
837 		.proc_handler	= proc_dointvec_minmax,
838 		.extra1		= &tcp_min_snd_mss_min,
839 		.extra2		= &tcp_min_snd_mss_max,
840 	},
841 	{
842 		.procname	= "tcp_probe_threshold",
843 		.data		= &init_net.ipv4.sysctl_tcp_probe_threshold,
844 		.maxlen		= sizeof(int),
845 		.mode		= 0644,
846 		.proc_handler	= proc_dointvec,
847 	},
848 	{
849 		.procname	= "tcp_probe_interval",
850 		.data		= &init_net.ipv4.sysctl_tcp_probe_interval,
851 		.maxlen		= sizeof(u32),
852 		.mode		= 0644,
853 		.proc_handler	= proc_douintvec_minmax,
854 		.extra2		= &u32_max_div_HZ,
855 	},
856 	{
857 		.procname	= "igmp_link_local_mcast_reports",
858 		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
859 		.maxlen		= sizeof(u8),
860 		.mode		= 0644,
861 		.proc_handler	= proc_dou8vec_minmax,
862 	},
863 	{
864 		.procname	= "igmp_max_memberships",
865 		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
866 		.maxlen		= sizeof(int),
867 		.mode		= 0644,
868 		.proc_handler	= proc_dointvec
869 	},
870 	{
871 		.procname	= "igmp_max_msf",
872 		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
873 		.maxlen		= sizeof(int),
874 		.mode		= 0644,
875 		.proc_handler	= proc_dointvec
876 	},
877 #ifdef CONFIG_IP_MULTICAST
878 	{
879 		.procname	= "igmp_qrv",
880 		.data		= &init_net.ipv4.sysctl_igmp_qrv,
881 		.maxlen		= sizeof(int),
882 		.mode		= 0644,
883 		.proc_handler	= proc_dointvec_minmax,
884 		.extra1		= SYSCTL_ONE
885 	},
886 #endif
887 	{
888 		.procname	= "tcp_congestion_control",
889 		.data		= &init_net.ipv4.tcp_congestion_control,
890 		.mode		= 0644,
891 		.maxlen		= TCP_CA_NAME_MAX,
892 		.proc_handler	= proc_tcp_congestion_control,
893 	},
894 	{
895 		.procname	= "tcp_available_congestion_control",
896 		.maxlen		= TCP_CA_BUF_MAX,
897 		.mode		= 0444,
898 		.proc_handler   = proc_tcp_available_congestion_control,
899 	},
900 	{
901 		.procname	= "tcp_allowed_congestion_control",
902 		.maxlen		= TCP_CA_BUF_MAX,
903 		.mode		= 0644,
904 		.proc_handler   = proc_allowed_congestion_control,
905 	},
906 	{
907 		.procname	= "tcp_keepalive_time",
908 		.data		= &init_net.ipv4.sysctl_tcp_keepalive_time,
909 		.maxlen		= sizeof(int),
910 		.mode		= 0644,
911 		.proc_handler	= proc_dointvec_jiffies,
912 	},
913 	{
914 		.procname	= "tcp_keepalive_probes",
915 		.data		= &init_net.ipv4.sysctl_tcp_keepalive_probes,
916 		.maxlen		= sizeof(u8),
917 		.mode		= 0644,
918 		.proc_handler	= proc_dou8vec_minmax,
919 	},
920 	{
921 		.procname	= "tcp_keepalive_intvl",
922 		.data		= &init_net.ipv4.sysctl_tcp_keepalive_intvl,
923 		.maxlen		= sizeof(int),
924 		.mode		= 0644,
925 		.proc_handler	= proc_dointvec_jiffies,
926 	},
927 	{
928 		.procname	= "tcp_syn_retries",
929 		.data		= &init_net.ipv4.sysctl_tcp_syn_retries,
930 		.maxlen		= sizeof(u8),
931 		.mode		= 0644,
932 		.proc_handler	= proc_dou8vec_minmax,
933 		.extra1		= &tcp_syn_retries_min,
934 		.extra2		= &tcp_syn_retries_max
935 	},
936 	{
937 		.procname	= "tcp_synack_retries",
938 		.data		= &init_net.ipv4.sysctl_tcp_synack_retries,
939 		.maxlen		= sizeof(u8),
940 		.mode		= 0644,
941 		.proc_handler	= proc_dou8vec_minmax,
942 	},
943 #ifdef CONFIG_SYN_COOKIES
944 	{
945 		.procname	= "tcp_syncookies",
946 		.data		= &init_net.ipv4.sysctl_tcp_syncookies,
947 		.maxlen		= sizeof(u8),
948 		.mode		= 0644,
949 		.proc_handler	= proc_dou8vec_minmax,
950 	},
951 #endif
952 	{
953 		.procname	= "tcp_migrate_req",
954 		.data		= &init_net.ipv4.sysctl_tcp_migrate_req,
955 		.maxlen		= sizeof(u8),
956 		.mode		= 0644,
957 		.proc_handler	= proc_dou8vec_minmax,
958 		.extra1		= SYSCTL_ZERO,
959 		.extra2		= SYSCTL_ONE
960 	},
961 	{
962 		.procname	= "tcp_reordering",
963 		.data		= &init_net.ipv4.sysctl_tcp_reordering,
964 		.maxlen		= sizeof(int),
965 		.mode		= 0644,
966 		.proc_handler	= proc_dointvec
967 	},
968 	{
969 		.procname	= "tcp_retries1",
970 		.data		= &init_net.ipv4.sysctl_tcp_retries1,
971 		.maxlen		= sizeof(u8),
972 		.mode		= 0644,
973 		.proc_handler	= proc_dou8vec_minmax,
974 		.extra2		= &tcp_retr1_max
975 	},
976 	{
977 		.procname	= "tcp_retries2",
978 		.data		= &init_net.ipv4.sysctl_tcp_retries2,
979 		.maxlen		= sizeof(u8),
980 		.mode		= 0644,
981 		.proc_handler	= proc_dou8vec_minmax,
982 	},
983 	{
984 		.procname	= "tcp_orphan_retries",
985 		.data		= &init_net.ipv4.sysctl_tcp_orphan_retries,
986 		.maxlen		= sizeof(u8),
987 		.mode		= 0644,
988 		.proc_handler	= proc_dou8vec_minmax,
989 	},
990 	{
991 		.procname	= "tcp_fin_timeout",
992 		.data		= &init_net.ipv4.sysctl_tcp_fin_timeout,
993 		.maxlen		= sizeof(int),
994 		.mode		= 0644,
995 		.proc_handler	= proc_dointvec_jiffies,
996 	},
997 	{
998 		.procname	= "tcp_notsent_lowat",
999 		.data		= &init_net.ipv4.sysctl_tcp_notsent_lowat,
1000 		.maxlen		= sizeof(unsigned int),
1001 		.mode		= 0644,
1002 		.proc_handler	= proc_douintvec,
1003 	},
1004 	{
1005 		.procname	= "tcp_tw_reuse",
1006 		.data		= &init_net.ipv4.sysctl_tcp_tw_reuse,
1007 		.maxlen		= sizeof(u8),
1008 		.mode		= 0644,
1009 		.proc_handler	= proc_dou8vec_minmax,
1010 		.extra1		= SYSCTL_ZERO,
1011 		.extra2		= SYSCTL_TWO,
1012 	},
1013 	{
1014 		.procname	= "tcp_max_syn_backlog",
1015 		.data		= &init_net.ipv4.sysctl_max_syn_backlog,
1016 		.maxlen		= sizeof(int),
1017 		.mode		= 0644,
1018 		.proc_handler	= proc_dointvec
1019 	},
1020 	{
1021 		.procname	= "tcp_fastopen",
1022 		.data		= &init_net.ipv4.sysctl_tcp_fastopen,
1023 		.maxlen		= sizeof(int),
1024 		.mode		= 0644,
1025 		.proc_handler	= proc_dointvec,
1026 	},
1027 	{
1028 		.procname	= "tcp_fastopen_key",
1029 		.mode		= 0600,
1030 		.data		= &init_net.ipv4.sysctl_tcp_fastopen,
1031 		/* maxlen to print the list of keys in hex (*2), with dashes
1032 		 * separating doublewords and a comma in between keys.
1033 		 */
1034 		.maxlen		= ((TCP_FASTOPEN_KEY_LENGTH *
1035 				   2 * TCP_FASTOPEN_KEY_MAX) +
1036 				   (TCP_FASTOPEN_KEY_MAX * 5)),
1037 		.proc_handler	= proc_tcp_fastopen_key,
1038 	},
1039 	{
1040 		.procname	= "tcp_fastopen_blackhole_timeout_sec",
1041 		.data		= &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1042 		.maxlen		= sizeof(int),
1043 		.mode		= 0644,
1044 		.proc_handler	= proc_tfo_blackhole_detect_timeout,
1045 		.extra1		= SYSCTL_ZERO,
1046 	},
1047 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1048 	{
1049 		.procname	= "fib_multipath_use_neigh",
1050 		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1051 		.maxlen		= sizeof(u8),
1052 		.mode		= 0644,
1053 		.proc_handler	= proc_dou8vec_minmax,
1054 		.extra1		= SYSCTL_ZERO,
1055 		.extra2		= SYSCTL_ONE,
1056 	},
1057 	{
1058 		.procname	= "fib_multipath_hash_policy",
1059 		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1060 		.maxlen		= sizeof(u8),
1061 		.mode		= 0644,
1062 		.proc_handler	= proc_fib_multipath_hash_policy,
1063 		.extra1		= SYSCTL_ZERO,
1064 		.extra2		= SYSCTL_THREE,
1065 	},
1066 	{
1067 		.procname	= "fib_multipath_hash_fields",
1068 		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1069 		.maxlen		= sizeof(u32),
1070 		.mode		= 0644,
1071 		.proc_handler	= proc_fib_multipath_hash_fields,
1072 		.extra1		= SYSCTL_ONE,
1073 		.extra2		= &fib_multipath_hash_fields_all_mask,
1074 	},
1075 #endif
1076 	{
1077 		.procname	= "ip_unprivileged_port_start",
1078 		.maxlen		= sizeof(int),
1079 		.data		= &init_net.ipv4.sysctl_ip_prot_sock,
1080 		.mode		= 0644,
1081 		.proc_handler	= ipv4_privileged_ports,
1082 	},
1083 #ifdef CONFIG_NET_L3_MASTER_DEV
1084 	{
1085 		.procname	= "udp_l3mdev_accept",
1086 		.data		= &init_net.ipv4.sysctl_udp_l3mdev_accept,
1087 		.maxlen		= sizeof(u8),
1088 		.mode		= 0644,
1089 		.proc_handler	= proc_dou8vec_minmax,
1090 		.extra1		= SYSCTL_ZERO,
1091 		.extra2		= SYSCTL_ONE,
1092 	},
1093 #endif
1094 	{
1095 		.procname	= "tcp_sack",
1096 		.data		= &init_net.ipv4.sysctl_tcp_sack,
1097 		.maxlen		= sizeof(u8),
1098 		.mode		= 0644,
1099 		.proc_handler	= proc_dou8vec_minmax,
1100 	},
1101 	{
1102 		.procname	= "tcp_window_scaling",
1103 		.data		= &init_net.ipv4.sysctl_tcp_window_scaling,
1104 		.maxlen		= sizeof(u8),
1105 		.mode		= 0644,
1106 		.proc_handler	= proc_dou8vec_minmax,
1107 	},
1108 	{
1109 		.procname	= "tcp_timestamps",
1110 		.data		= &init_net.ipv4.sysctl_tcp_timestamps,
1111 		.maxlen		= sizeof(u8),
1112 		.mode		= 0644,
1113 		.proc_handler	= proc_dou8vec_minmax,
1114 	},
1115 	{
1116 		.procname	= "tcp_early_retrans",
1117 		.data		= &init_net.ipv4.sysctl_tcp_early_retrans,
1118 		.maxlen		= sizeof(u8),
1119 		.mode		= 0644,
1120 		.proc_handler	= proc_dou8vec_minmax,
1121 		.extra1		= SYSCTL_ZERO,
1122 		.extra2		= SYSCTL_FOUR,
1123 	},
1124 	{
1125 		.procname	= "tcp_recovery",
1126 		.data		= &init_net.ipv4.sysctl_tcp_recovery,
1127 		.maxlen		= sizeof(u8),
1128 		.mode		= 0644,
1129 		.proc_handler	= proc_dou8vec_minmax,
1130 	},
1131 	{
1132 		.procname       = "tcp_thin_linear_timeouts",
1133 		.data           = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1134 		.maxlen         = sizeof(u8),
1135 		.mode           = 0644,
1136 		.proc_handler   = proc_dou8vec_minmax,
1137 	},
1138 	{
1139 		.procname	= "tcp_slow_start_after_idle",
1140 		.data		= &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1141 		.maxlen		= sizeof(u8),
1142 		.mode		= 0644,
1143 		.proc_handler	= proc_dou8vec_minmax,
1144 	},
1145 	{
1146 		.procname	= "tcp_retrans_collapse",
1147 		.data		= &init_net.ipv4.sysctl_tcp_retrans_collapse,
1148 		.maxlen		= sizeof(u8),
1149 		.mode		= 0644,
1150 		.proc_handler	= proc_dou8vec_minmax,
1151 	},
1152 	{
1153 		.procname	= "tcp_stdurg",
1154 		.data		= &init_net.ipv4.sysctl_tcp_stdurg,
1155 		.maxlen		= sizeof(u8),
1156 		.mode		= 0644,
1157 		.proc_handler	= proc_dou8vec_minmax,
1158 	},
1159 	{
1160 		.procname	= "tcp_rfc1337",
1161 		.data		= &init_net.ipv4.sysctl_tcp_rfc1337,
1162 		.maxlen		= sizeof(u8),
1163 		.mode		= 0644,
1164 		.proc_handler	= proc_dou8vec_minmax,
1165 	},
1166 	{
1167 		.procname	= "tcp_abort_on_overflow",
1168 		.data		= &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1169 		.maxlen		= sizeof(u8),
1170 		.mode		= 0644,
1171 		.proc_handler	= proc_dou8vec_minmax,
1172 	},
1173 	{
1174 		.procname	= "tcp_fack",
1175 		.data		= &init_net.ipv4.sysctl_tcp_fack,
1176 		.maxlen		= sizeof(u8),
1177 		.mode		= 0644,
1178 		.proc_handler	= proc_dou8vec_minmax,
1179 	},
1180 	{
1181 		.procname	= "tcp_max_reordering",
1182 		.data		= &init_net.ipv4.sysctl_tcp_max_reordering,
1183 		.maxlen		= sizeof(int),
1184 		.mode		= 0644,
1185 		.proc_handler	= proc_dointvec
1186 	},
1187 	{
1188 		.procname	= "tcp_dsack",
1189 		.data		= &init_net.ipv4.sysctl_tcp_dsack,
1190 		.maxlen		= sizeof(u8),
1191 		.mode		= 0644,
1192 		.proc_handler	= proc_dou8vec_minmax,
1193 	},
1194 	{
1195 		.procname	= "tcp_app_win",
1196 		.data		= &init_net.ipv4.sysctl_tcp_app_win,
1197 		.maxlen		= sizeof(u8),
1198 		.mode		= 0644,
1199 		.proc_handler	= proc_dou8vec_minmax,
1200 		.extra1		= SYSCTL_ZERO,
1201 		.extra2		= &tcp_app_win_max,
1202 	},
1203 	{
1204 		.procname	= "tcp_adv_win_scale",
1205 		.data		= &init_net.ipv4.sysctl_tcp_adv_win_scale,
1206 		.maxlen		= sizeof(int),
1207 		.mode		= 0644,
1208 		.proc_handler	= proc_dointvec_minmax,
1209 		.extra1		= &tcp_adv_win_scale_min,
1210 		.extra2		= &tcp_adv_win_scale_max,
1211 	},
1212 	{
1213 		.procname	= "tcp_frto",
1214 		.data		= &init_net.ipv4.sysctl_tcp_frto,
1215 		.maxlen		= sizeof(u8),
1216 		.mode		= 0644,
1217 		.proc_handler	= proc_dou8vec_minmax,
1218 	},
1219 	{
1220 		.procname	= "tcp_no_metrics_save",
1221 		.data		= &init_net.ipv4.sysctl_tcp_nometrics_save,
1222 		.maxlen		= sizeof(u8),
1223 		.mode		= 0644,
1224 		.proc_handler	= proc_dou8vec_minmax,
1225 	},
1226 	{
1227 		.procname	= "tcp_no_ssthresh_metrics_save",
1228 		.data		= &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1229 		.maxlen		= sizeof(u8),
1230 		.mode		= 0644,
1231 		.proc_handler	= proc_dou8vec_minmax,
1232 		.extra1		= SYSCTL_ZERO,
1233 		.extra2		= SYSCTL_ONE,
1234 	},
1235 	{
1236 		.procname	= "tcp_moderate_rcvbuf",
1237 		.data		= &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1238 		.maxlen		= sizeof(u8),
1239 		.mode		= 0644,
1240 		.proc_handler	= proc_dou8vec_minmax,
1241 	},
1242 	{
1243 		.procname	= "tcp_tso_win_divisor",
1244 		.data		= &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1245 		.maxlen		= sizeof(u8),
1246 		.mode		= 0644,
1247 		.proc_handler	= proc_dou8vec_minmax,
1248 	},
1249 	{
1250 		.procname	= "tcp_workaround_signed_windows",
1251 		.data		= &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1252 		.maxlen		= sizeof(u8),
1253 		.mode		= 0644,
1254 		.proc_handler	= proc_dou8vec_minmax,
1255 	},
1256 	{
1257 		.procname	= "tcp_limit_output_bytes",
1258 		.data		= &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1259 		.maxlen		= sizeof(int),
1260 		.mode		= 0644,
1261 		.proc_handler	= proc_dointvec
1262 	},
1263 	{
1264 		.procname	= "tcp_challenge_ack_limit",
1265 		.data		= &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1266 		.maxlen		= sizeof(int),
1267 		.mode		= 0644,
1268 		.proc_handler	= proc_dointvec
1269 	},
1270 	{
1271 		.procname	= "tcp_min_tso_segs",
1272 		.data		= &init_net.ipv4.sysctl_tcp_min_tso_segs,
1273 		.maxlen		= sizeof(u8),
1274 		.mode		= 0644,
1275 		.proc_handler	= proc_dou8vec_minmax,
1276 		.extra1		= SYSCTL_ONE,
1277 	},
1278 	{
1279 		.procname	= "tcp_tso_rtt_log",
1280 		.data		= &init_net.ipv4.sysctl_tcp_tso_rtt_log,
1281 		.maxlen		= sizeof(u8),
1282 		.mode		= 0644,
1283 		.proc_handler	= proc_dou8vec_minmax,
1284 	},
1285 	{
1286 		.procname	= "tcp_min_rtt_wlen",
1287 		.data		= &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1288 		.maxlen		= sizeof(int),
1289 		.mode		= 0644,
1290 		.proc_handler	= proc_dointvec_minmax,
1291 		.extra1		= SYSCTL_ZERO,
1292 		.extra2		= &one_day_secs
1293 	},
1294 	{
1295 		.procname	= "tcp_autocorking",
1296 		.data		= &init_net.ipv4.sysctl_tcp_autocorking,
1297 		.maxlen		= sizeof(u8),
1298 		.mode		= 0644,
1299 		.proc_handler	= proc_dou8vec_minmax,
1300 		.extra1		= SYSCTL_ZERO,
1301 		.extra2		= SYSCTL_ONE,
1302 	},
1303 	{
1304 		.procname	= "tcp_invalid_ratelimit",
1305 		.data		= &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1306 		.maxlen		= sizeof(int),
1307 		.mode		= 0644,
1308 		.proc_handler	= proc_dointvec_ms_jiffies,
1309 	},
1310 	{
1311 		.procname	= "tcp_pacing_ss_ratio",
1312 		.data		= &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1313 		.maxlen		= sizeof(int),
1314 		.mode		= 0644,
1315 		.proc_handler	= proc_dointvec_minmax,
1316 		.extra1		= SYSCTL_ZERO,
1317 		.extra2		= SYSCTL_ONE_THOUSAND,
1318 	},
1319 	{
1320 		.procname	= "tcp_pacing_ca_ratio",
1321 		.data		= &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1322 		.maxlen		= sizeof(int),
1323 		.mode		= 0644,
1324 		.proc_handler	= proc_dointvec_minmax,
1325 		.extra1		= SYSCTL_ZERO,
1326 		.extra2		= SYSCTL_ONE_THOUSAND,
1327 	},
1328 	{
1329 		.procname	= "tcp_wmem",
1330 		.data		= &init_net.ipv4.sysctl_tcp_wmem,
1331 		.maxlen		= sizeof(init_net.ipv4.sysctl_tcp_wmem),
1332 		.mode		= 0644,
1333 		.proc_handler	= proc_dointvec_minmax,
1334 		.extra1		= SYSCTL_ONE,
1335 	},
1336 	{
1337 		.procname	= "tcp_rmem",
1338 		.data		= &init_net.ipv4.sysctl_tcp_rmem,
1339 		.maxlen		= sizeof(init_net.ipv4.sysctl_tcp_rmem),
1340 		.mode		= 0644,
1341 		.proc_handler	= proc_dointvec_minmax,
1342 		.extra1		= SYSCTL_ONE,
1343 	},
1344 	{
1345 		.procname	= "tcp_comp_sack_delay_ns",
1346 		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1347 		.maxlen		= sizeof(unsigned long),
1348 		.mode		= 0644,
1349 		.proc_handler	= proc_doulongvec_minmax,
1350 	},
1351 	{
1352 		.procname	= "tcp_comp_sack_slack_ns",
1353 		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1354 		.maxlen		= sizeof(unsigned long),
1355 		.mode		= 0644,
1356 		.proc_handler	= proc_doulongvec_minmax,
1357 	},
1358 	{
1359 		.procname	= "tcp_comp_sack_nr",
1360 		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1361 		.maxlen		= sizeof(u8),
1362 		.mode		= 0644,
1363 		.proc_handler	= proc_dou8vec_minmax,
1364 		.extra1		= SYSCTL_ZERO,
1365 	},
1366 	{
1367 		.procname	= "tcp_backlog_ack_defer",
1368 		.data		= &init_net.ipv4.sysctl_tcp_backlog_ack_defer,
1369 		.maxlen		= sizeof(u8),
1370 		.mode		= 0644,
1371 		.proc_handler	= proc_dou8vec_minmax,
1372 		.extra1		= SYSCTL_ZERO,
1373 		.extra2		= SYSCTL_ONE,
1374 	},
1375 	{
1376 		.procname       = "tcp_reflect_tos",
1377 		.data           = &init_net.ipv4.sysctl_tcp_reflect_tos,
1378 		.maxlen         = sizeof(u8),
1379 		.mode           = 0644,
1380 		.proc_handler   = proc_dou8vec_minmax,
1381 		.extra1         = SYSCTL_ZERO,
1382 		.extra2         = SYSCTL_ONE,
1383 	},
1384 	{
1385 		.procname	= "tcp_ehash_entries",
1386 		.data		= &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1387 		.mode		= 0444,
1388 		.proc_handler	= proc_tcp_ehash_entries,
1389 	},
1390 	{
1391 		.procname	= "tcp_child_ehash_entries",
1392 		.data		= &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1393 		.maxlen		= sizeof(unsigned int),
1394 		.mode		= 0644,
1395 		.proc_handler	= proc_douintvec_minmax,
1396 		.extra1		= SYSCTL_ZERO,
1397 		.extra2		= &tcp_child_ehash_entries_max,
1398 	},
1399 	{
1400 		.procname	= "udp_hash_entries",
1401 		.data		= &init_net.ipv4.sysctl_udp_child_hash_entries,
1402 		.mode		= 0444,
1403 		.proc_handler	= proc_udp_hash_entries,
1404 	},
1405 	{
1406 		.procname	= "udp_child_hash_entries",
1407 		.data		= &init_net.ipv4.sysctl_udp_child_hash_entries,
1408 		.maxlen		= sizeof(unsigned int),
1409 		.mode		= 0644,
1410 		.proc_handler	= proc_douintvec_minmax,
1411 		.extra1		= SYSCTL_ZERO,
1412 		.extra2		= &udp_child_hash_entries_max,
1413 	},
1414 	{
1415 		.procname	= "udp_rmem_min",
1416 		.data		= &init_net.ipv4.sysctl_udp_rmem_min,
1417 		.maxlen		= sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1418 		.mode		= 0644,
1419 		.proc_handler	= proc_dointvec_minmax,
1420 		.extra1		= SYSCTL_ONE
1421 	},
1422 	{
1423 		.procname	= "udp_wmem_min",
1424 		.data		= &init_net.ipv4.sysctl_udp_wmem_min,
1425 		.maxlen		= sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1426 		.mode		= 0644,
1427 		.proc_handler	= proc_dointvec_minmax,
1428 		.extra1		= SYSCTL_ONE
1429 	},
1430 	{
1431 		.procname	= "fib_notify_on_flag_change",
1432 		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1433 		.maxlen		= sizeof(u8),
1434 		.mode		= 0644,
1435 		.proc_handler	= proc_dou8vec_minmax,
1436 		.extra1		= SYSCTL_ZERO,
1437 		.extra2		= SYSCTL_TWO,
1438 	},
1439 	{
1440 		.procname       = "tcp_plb_enabled",
1441 		.data           = &init_net.ipv4.sysctl_tcp_plb_enabled,
1442 		.maxlen         = sizeof(u8),
1443 		.mode           = 0644,
1444 		.proc_handler   = proc_dou8vec_minmax,
1445 		.extra1         = SYSCTL_ZERO,
1446 		.extra2         = SYSCTL_ONE,
1447 	},
1448 	{
1449 		.procname       = "tcp_plb_idle_rehash_rounds",
1450 		.data           = &init_net.ipv4.sysctl_tcp_plb_idle_rehash_rounds,
1451 		.maxlen         = sizeof(u8),
1452 		.mode           = 0644,
1453 		.proc_handler   = proc_dou8vec_minmax,
1454 		.extra2		= &tcp_plb_max_rounds,
1455 	},
1456 	{
1457 		.procname       = "tcp_plb_rehash_rounds",
1458 		.data           = &init_net.ipv4.sysctl_tcp_plb_rehash_rounds,
1459 		.maxlen         = sizeof(u8),
1460 		.mode           = 0644,
1461 		.proc_handler   = proc_dou8vec_minmax,
1462 		.extra2         = &tcp_plb_max_rounds,
1463 	},
1464 	{
1465 		.procname       = "tcp_plb_suspend_rto_sec",
1466 		.data           = &init_net.ipv4.sysctl_tcp_plb_suspend_rto_sec,
1467 		.maxlen         = sizeof(u8),
1468 		.mode           = 0644,
1469 		.proc_handler   = proc_dou8vec_minmax,
1470 	},
1471 	{
1472 		.procname       = "tcp_plb_cong_thresh",
1473 		.data           = &init_net.ipv4.sysctl_tcp_plb_cong_thresh,
1474 		.maxlen         = sizeof(int),
1475 		.mode           = 0644,
1476 		.proc_handler   = proc_dointvec_minmax,
1477 		.extra1         = SYSCTL_ZERO,
1478 		.extra2         = &tcp_plb_max_cong_thresh,
1479 	},
1480 	{
1481 		.procname	= "tcp_syn_linear_timeouts",
1482 		.data		= &init_net.ipv4.sysctl_tcp_syn_linear_timeouts,
1483 		.maxlen		= sizeof(u8),
1484 		.mode		= 0644,
1485 		.proc_handler	= proc_dou8vec_minmax,
1486 		.extra1		= SYSCTL_ZERO,
1487 		.extra2		= &tcp_syn_linear_timeouts_max,
1488 	},
1489 	{
1490 		.procname	= "tcp_shrink_window",
1491 		.data		= &init_net.ipv4.sysctl_tcp_shrink_window,
1492 		.maxlen		= sizeof(u8),
1493 		.mode		= 0644,
1494 		.proc_handler	= proc_dou8vec_minmax,
1495 		.extra1		= SYSCTL_ZERO,
1496 		.extra2		= SYSCTL_ONE,
1497 	},
1498 	{
1499 		.procname	= "tcp_pingpong_thresh",
1500 		.data		= &init_net.ipv4.sysctl_tcp_pingpong_thresh,
1501 		.maxlen		= sizeof(u8),
1502 		.mode		= 0644,
1503 		.proc_handler	= proc_dou8vec_minmax,
1504 		.extra1		= SYSCTL_ONE,
1505 	},
1506 	{
1507 		.procname	= "tcp_rto_min_us",
1508 		.data		= &init_net.ipv4.sysctl_tcp_rto_min_us,
1509 		.maxlen		= sizeof(int),
1510 		.mode		= 0644,
1511 		.proc_handler	= proc_dointvec_minmax,
1512 		.extra1		= SYSCTL_ONE,
1513 	},
1514 };
1515 
1516 static __net_init int ipv4_sysctl_init_net(struct net *net)
1517 {
1518 	size_t table_size = ARRAY_SIZE(ipv4_net_table);
1519 	struct ctl_table *table;
1520 
1521 	table = ipv4_net_table;
1522 	if (!net_eq(net, &init_net)) {
1523 		int i;
1524 
1525 		table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1526 		if (!table)
1527 			goto err_alloc;
1528 
1529 		for (i = 0; i < table_size; i++) {
1530 			if (table[i].data) {
1531 				/* Update the variables to point into
1532 				 * the current struct net
1533 				 */
1534 				table[i].data += (void *)net - (void *)&init_net;
1535 			} else {
1536 				/* Entries without data pointer are global;
1537 				 * Make them read-only in non-init_net ns
1538 				 */
1539 				table[i].mode &= ~0222;
1540 			}
1541 		}
1542 	}
1543 
1544 	net->ipv4.ipv4_hdr = register_net_sysctl_sz(net, "net/ipv4", table,
1545 						    table_size);
1546 	if (!net->ipv4.ipv4_hdr)
1547 		goto err_reg;
1548 
1549 	net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1550 	if (!net->ipv4.sysctl_local_reserved_ports)
1551 		goto err_ports;
1552 
1553 	return 0;
1554 
1555 err_ports:
1556 	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1557 err_reg:
1558 	if (!net_eq(net, &init_net))
1559 		kfree(table);
1560 err_alloc:
1561 	return -ENOMEM;
1562 }
1563 
1564 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1565 {
1566 	const struct ctl_table *table;
1567 
1568 	kfree(net->ipv4.sysctl_local_reserved_ports);
1569 	table = net->ipv4.ipv4_hdr->ctl_table_arg;
1570 	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1571 	kfree(table);
1572 }
1573 
1574 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1575 	.init = ipv4_sysctl_init_net,
1576 	.exit = ipv4_sysctl_exit_net,
1577 };
1578 
1579 static __init int sysctl_ipv4_init(void)
1580 {
1581 	struct ctl_table_header *hdr;
1582 
1583 	hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1584 	if (!hdr)
1585 		return -ENOMEM;
1586 
1587 	if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1588 		unregister_net_sysctl_table(hdr);
1589 		return -ENOMEM;
1590 	}
1591 
1592 	return 0;
1593 }
1594 
1595 __initcall(sysctl_ipv4_init);
1596