xref: /linux/net/ipv4/sysctl_net_ipv4.c (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
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 two = 2;
24 static int three __maybe_unused = 3;
25 static int four = 4;
26 static int thousand = 1000;
27 static int tcp_retr1_max = 255;
28 static int ip_local_port_range_min[] = { 1, 1 };
29 static int ip_local_port_range_max[] = { 65535, 65535 };
30 static int tcp_adv_win_scale_min = -31;
31 static int tcp_adv_win_scale_max = 31;
32 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
33 static int tcp_min_snd_mss_max = 65535;
34 static int ip_privileged_port_min;
35 static int ip_privileged_port_max = 65535;
36 static int ip_ttl_min = 1;
37 static int ip_ttl_max = 255;
38 static int tcp_syn_retries_min = 1;
39 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
40 static int ip_ping_group_range_min[] = { 0, 0 };
41 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
42 static u32 u32_max_div_HZ = UINT_MAX / HZ;
43 static int one_day_secs = 24 * 3600;
44 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
45 	FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
46 
47 /* obsolete */
48 static int sysctl_tcp_low_latency __read_mostly;
49 
50 /* Update system visible IP port range */
51 static void set_local_port_range(struct net *net, int range[2])
52 {
53 	bool same_parity = !((range[0] ^ range[1]) & 1);
54 
55 	write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
56 	if (same_parity && !net->ipv4.ip_local_ports.warned) {
57 		net->ipv4.ip_local_ports.warned = true;
58 		pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
59 	}
60 	net->ipv4.ip_local_ports.range[0] = range[0];
61 	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 		.data = &range,
75 		.maxlen = sizeof(range),
76 		.mode = table->mode,
77 		.extra1 = &ip_local_port_range_min,
78 		.extra2 = &ip_local_port_range_max,
79 	};
80 
81 	inet_get_local_port_range(net, &range[0], &range[1]);
82 
83 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
84 
85 	if (write && ret == 0) {
86 		/* Ensure that the upper limit is not smaller than the lower,
87 		 * and that the lower does not encroach upon the privileged
88 		 * port limit.
89 		 */
90 		if ((range[1] < range[0]) ||
91 		    (range[0] < net->ipv4.sysctl_ip_prot_sock))
92 			ret = -EINVAL;
93 		else
94 			set_local_port_range(net, range);
95 	}
96 
97 	return ret;
98 }
99 
100 /* Validate changes from /proc interface. */
101 static int ipv4_privileged_ports(struct ctl_table *table, int write,
102 				void *buffer, size_t *lenp, loff_t *ppos)
103 {
104 	struct net *net = container_of(table->data, struct net,
105 	    ipv4.sysctl_ip_prot_sock);
106 	int ret;
107 	int pports;
108 	int range[2];
109 	struct ctl_table tmp = {
110 		.data = &pports,
111 		.maxlen = sizeof(pports),
112 		.mode = table->mode,
113 		.extra1 = &ip_privileged_port_min,
114 		.extra2 = &ip_privileged_port_max,
115 	};
116 
117 	pports = net->ipv4.sysctl_ip_prot_sock;
118 
119 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
120 
121 	if (write && ret == 0) {
122 		inet_get_local_port_range(net, &range[0], &range[1]);
123 		/* Ensure that the local port range doesn't overlap with the
124 		 * privileged port range.
125 		 */
126 		if (range[0] < pports)
127 			ret = -EINVAL;
128 		else
129 			net->ipv4.sysctl_ip_prot_sock = pports;
130 	}
131 
132 	return ret;
133 }
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 		*low = data[0];
145 		*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 	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 	gid_t 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_dointvec_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 void proc_configure_early_demux(int enabled, int protocol)
358 {
359 	struct net_protocol *ipprot;
360 #if IS_ENABLED(CONFIG_IPV6)
361 	struct inet6_protocol *ip6prot;
362 #endif
363 
364 	rcu_read_lock();
365 
366 	ipprot = rcu_dereference(inet_protos[protocol]);
367 	if (ipprot)
368 		ipprot->early_demux = enabled ? ipprot->early_demux_handler :
369 						NULL;
370 
371 #if IS_ENABLED(CONFIG_IPV6)
372 	ip6prot = rcu_dereference(inet6_protos[protocol]);
373 	if (ip6prot)
374 		ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
375 						 NULL;
376 #endif
377 	rcu_read_unlock();
378 }
379 
380 static int proc_tcp_early_demux(struct ctl_table *table, int write,
381 				void *buffer, size_t *lenp, loff_t *ppos)
382 {
383 	int ret = 0;
384 
385 	ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
386 
387 	if (write && !ret) {
388 		int enabled = init_net.ipv4.sysctl_tcp_early_demux;
389 
390 		proc_configure_early_demux(enabled, IPPROTO_TCP);
391 	}
392 
393 	return ret;
394 }
395 
396 static int proc_udp_early_demux(struct ctl_table *table, int write,
397 				void *buffer, size_t *lenp, loff_t *ppos)
398 {
399 	int ret = 0;
400 
401 	ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
402 
403 	if (write && !ret) {
404 		int enabled = init_net.ipv4.sysctl_udp_early_demux;
405 
406 		proc_configure_early_demux(enabled, IPPROTO_UDP);
407 	}
408 
409 	return ret;
410 }
411 
412 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
413 					     int write, void *buffer,
414 					     size_t *lenp, loff_t *ppos)
415 {
416 	struct net *net = container_of(table->data, struct net,
417 	    ipv4.sysctl_tcp_fastopen_blackhole_timeout);
418 	int ret;
419 
420 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
421 	if (write && ret == 0)
422 		atomic_set(&net->ipv4.tfo_active_disable_times, 0);
423 
424 	return ret;
425 }
426 
427 static int proc_tcp_available_ulp(struct ctl_table *ctl,
428 				  int write, void *buffer, size_t *lenp,
429 				  loff_t *ppos)
430 {
431 	struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
432 	int ret;
433 
434 	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
435 	if (!tbl.data)
436 		return -ENOMEM;
437 	tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
438 	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
439 	kfree(tbl.data);
440 
441 	return ret;
442 }
443 
444 #ifdef CONFIG_IP_ROUTE_MULTIPATH
445 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
446 					  void *buffer, size_t *lenp,
447 					  loff_t *ppos)
448 {
449 	struct net *net = container_of(table->data, struct net,
450 	    ipv4.sysctl_fib_multipath_hash_policy);
451 	int ret;
452 
453 	ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
454 	if (write && ret == 0)
455 		call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
456 
457 	return ret;
458 }
459 
460 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
461 					  void *buffer, size_t *lenp,
462 					  loff_t *ppos)
463 {
464 	struct net *net;
465 	int ret;
466 
467 	net = container_of(table->data, struct net,
468 			   ipv4.sysctl_fib_multipath_hash_fields);
469 	ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
470 	if (write && ret == 0)
471 		call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
472 
473 	return ret;
474 }
475 #endif
476 
477 static struct ctl_table ipv4_table[] = {
478 	{
479 		.procname	= "tcp_max_orphans",
480 		.data		= &sysctl_tcp_max_orphans,
481 		.maxlen		= sizeof(int),
482 		.mode		= 0644,
483 		.proc_handler	= proc_dointvec
484 	},
485 	{
486 		.procname	= "inet_peer_threshold",
487 		.data		= &inet_peer_threshold,
488 		.maxlen		= sizeof(int),
489 		.mode		= 0644,
490 		.proc_handler	= proc_dointvec
491 	},
492 	{
493 		.procname	= "inet_peer_minttl",
494 		.data		= &inet_peer_minttl,
495 		.maxlen		= sizeof(int),
496 		.mode		= 0644,
497 		.proc_handler	= proc_dointvec_jiffies,
498 	},
499 	{
500 		.procname	= "inet_peer_maxttl",
501 		.data		= &inet_peer_maxttl,
502 		.maxlen		= sizeof(int),
503 		.mode		= 0644,
504 		.proc_handler	= proc_dointvec_jiffies,
505 	},
506 	{
507 		.procname	= "tcp_mem",
508 		.maxlen		= sizeof(sysctl_tcp_mem),
509 		.data		= &sysctl_tcp_mem,
510 		.mode		= 0644,
511 		.proc_handler	= proc_doulongvec_minmax,
512 	},
513 	{
514 		.procname	= "tcp_low_latency",
515 		.data		= &sysctl_tcp_low_latency,
516 		.maxlen		= sizeof(int),
517 		.mode		= 0644,
518 		.proc_handler	= proc_dointvec
519 	},
520 #ifdef CONFIG_NETLABEL
521 	{
522 		.procname	= "cipso_cache_enable",
523 		.data		= &cipso_v4_cache_enabled,
524 		.maxlen		= sizeof(int),
525 		.mode		= 0644,
526 		.proc_handler	= proc_dointvec,
527 	},
528 	{
529 		.procname	= "cipso_cache_bucket_size",
530 		.data		= &cipso_v4_cache_bucketsize,
531 		.maxlen		= sizeof(int),
532 		.mode		= 0644,
533 		.proc_handler	= proc_dointvec,
534 	},
535 	{
536 		.procname	= "cipso_rbm_optfmt",
537 		.data		= &cipso_v4_rbm_optfmt,
538 		.maxlen		= sizeof(int),
539 		.mode		= 0644,
540 		.proc_handler	= proc_dointvec,
541 	},
542 	{
543 		.procname	= "cipso_rbm_strictvalid",
544 		.data		= &cipso_v4_rbm_strictvalid,
545 		.maxlen		= sizeof(int),
546 		.mode		= 0644,
547 		.proc_handler	= proc_dointvec,
548 	},
549 #endif /* CONFIG_NETLABEL */
550 	{
551 		.procname	= "tcp_available_ulp",
552 		.maxlen		= TCP_ULP_BUF_MAX,
553 		.mode		= 0444,
554 		.proc_handler   = proc_tcp_available_ulp,
555 	},
556 	{
557 		.procname	= "icmp_msgs_per_sec",
558 		.data		= &sysctl_icmp_msgs_per_sec,
559 		.maxlen		= sizeof(int),
560 		.mode		= 0644,
561 		.proc_handler	= proc_dointvec_minmax,
562 		.extra1		= SYSCTL_ZERO,
563 	},
564 	{
565 		.procname	= "icmp_msgs_burst",
566 		.data		= &sysctl_icmp_msgs_burst,
567 		.maxlen		= sizeof(int),
568 		.mode		= 0644,
569 		.proc_handler	= proc_dointvec_minmax,
570 		.extra1		= SYSCTL_ZERO,
571 	},
572 	{
573 		.procname	= "udp_mem",
574 		.data		= &sysctl_udp_mem,
575 		.maxlen		= sizeof(sysctl_udp_mem),
576 		.mode		= 0644,
577 		.proc_handler	= proc_doulongvec_minmax,
578 	},
579 	{
580 		.procname	= "fib_sync_mem",
581 		.data		= &sysctl_fib_sync_mem,
582 		.maxlen		= sizeof(sysctl_fib_sync_mem),
583 		.mode		= 0644,
584 		.proc_handler	= proc_douintvec_minmax,
585 		.extra1		= &sysctl_fib_sync_mem_min,
586 		.extra2		= &sysctl_fib_sync_mem_max,
587 	},
588 	{ }
589 };
590 
591 static struct ctl_table ipv4_net_table[] = {
592 	{
593 		.procname	= "icmp_echo_ignore_all",
594 		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
595 		.maxlen		= sizeof(u8),
596 		.mode		= 0644,
597 		.proc_handler	= proc_dou8vec_minmax,
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 	},
615 	{
616 		.procname	= "icmp_ignore_bogus_error_responses",
617 		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
618 		.maxlen		= sizeof(u8),
619 		.mode		= 0644,
620 		.proc_handler	= proc_dou8vec_minmax,
621 	},
622 	{
623 		.procname	= "icmp_errors_use_inbound_ifaddr",
624 		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
625 		.maxlen		= sizeof(u8),
626 		.mode		= 0644,
627 		.proc_handler	= proc_dou8vec_minmax,
628 	},
629 	{
630 		.procname	= "icmp_ratelimit",
631 		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
632 		.maxlen		= sizeof(int),
633 		.mode		= 0644,
634 		.proc_handler	= proc_dointvec_ms_jiffies,
635 	},
636 	{
637 		.procname	= "icmp_ratemask",
638 		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
639 		.maxlen		= sizeof(int),
640 		.mode		= 0644,
641 		.proc_handler	= proc_dointvec
642 	},
643 	{
644 		.procname	= "ping_group_range",
645 		.data		= &init_net.ipv4.ping_group_range.range,
646 		.maxlen		= sizeof(gid_t)*2,
647 		.mode		= 0644,
648 		.proc_handler	= ipv4_ping_group_range,
649 	},
650 #ifdef CONFIG_NET_L3_MASTER_DEV
651 	{
652 		.procname	= "raw_l3mdev_accept",
653 		.data		= &init_net.ipv4.sysctl_raw_l3mdev_accept,
654 		.maxlen		= sizeof(u8),
655 		.mode		= 0644,
656 		.proc_handler	= proc_dou8vec_minmax,
657 		.extra1		= SYSCTL_ZERO,
658 		.extra2		= SYSCTL_ONE,
659 	},
660 #endif
661 	{
662 		.procname	= "tcp_ecn",
663 		.data		= &init_net.ipv4.sysctl_tcp_ecn,
664 		.maxlen		= sizeof(u8),
665 		.mode		= 0644,
666 		.proc_handler	= proc_dou8vec_minmax,
667 	},
668 	{
669 		.procname	= "tcp_ecn_fallback",
670 		.data		= &init_net.ipv4.sysctl_tcp_ecn_fallback,
671 		.maxlen		= sizeof(u8),
672 		.mode		= 0644,
673 		.proc_handler	= proc_dou8vec_minmax,
674 	},
675 	{
676 		.procname	= "ip_dynaddr",
677 		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
678 		.maxlen		= sizeof(u8),
679 		.mode		= 0644,
680 		.proc_handler	= proc_dou8vec_minmax,
681 	},
682 	{
683 		.procname	= "ip_early_demux",
684 		.data		= &init_net.ipv4.sysctl_ip_early_demux,
685 		.maxlen		= sizeof(u8),
686 		.mode		= 0644,
687 		.proc_handler	= proc_dou8vec_minmax,
688 	},
689 	{
690 		.procname       = "udp_early_demux",
691 		.data           = &init_net.ipv4.sysctl_udp_early_demux,
692 		.maxlen         = sizeof(u8),
693 		.mode           = 0644,
694 		.proc_handler   = proc_udp_early_demux
695 	},
696 	{
697 		.procname       = "tcp_early_demux",
698 		.data           = &init_net.ipv4.sysctl_tcp_early_demux,
699 		.maxlen         = sizeof(u8),
700 		.mode           = 0644,
701 		.proc_handler   = proc_tcp_early_demux
702 	},
703 	{
704 		.procname       = "nexthop_compat_mode",
705 		.data           = &init_net.ipv4.sysctl_nexthop_compat_mode,
706 		.maxlen         = sizeof(u8),
707 		.mode           = 0644,
708 		.proc_handler   = proc_dou8vec_minmax,
709 		.extra1		= SYSCTL_ZERO,
710 		.extra2		= SYSCTL_ONE,
711 	},
712 	{
713 		.procname	= "ip_default_ttl",
714 		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
715 		.maxlen		= sizeof(u8),
716 		.mode		= 0644,
717 		.proc_handler	= proc_dou8vec_minmax,
718 		.extra1		= &ip_ttl_min,
719 		.extra2		= &ip_ttl_max,
720 	},
721 	{
722 		.procname	= "ip_local_port_range",
723 		.maxlen		= sizeof(init_net.ipv4.ip_local_ports.range),
724 		.data		= &init_net.ipv4.ip_local_ports.range,
725 		.mode		= 0644,
726 		.proc_handler	= ipv4_local_port_range,
727 	},
728 	{
729 		.procname	= "ip_local_reserved_ports",
730 		.data		= &init_net.ipv4.sysctl_local_reserved_ports,
731 		.maxlen		= 65536,
732 		.mode		= 0644,
733 		.proc_handler	= proc_do_large_bitmap,
734 	},
735 	{
736 		.procname	= "ip_no_pmtu_disc",
737 		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
738 		.maxlen		= sizeof(u8),
739 		.mode		= 0644,
740 		.proc_handler	= proc_dou8vec_minmax,
741 	},
742 	{
743 		.procname	= "ip_forward_use_pmtu",
744 		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
745 		.maxlen		= sizeof(u8),
746 		.mode		= 0644,
747 		.proc_handler	= proc_dou8vec_minmax,
748 	},
749 	{
750 		.procname	= "ip_forward_update_priority",
751 		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
752 		.maxlen		= sizeof(u8),
753 		.mode		= 0644,
754 		.proc_handler   = ipv4_fwd_update_priority,
755 		.extra1		= SYSCTL_ZERO,
756 		.extra2		= SYSCTL_ONE,
757 	},
758 	{
759 		.procname	= "ip_nonlocal_bind",
760 		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
761 		.maxlen		= sizeof(u8),
762 		.mode		= 0644,
763 		.proc_handler	= proc_dou8vec_minmax,
764 	},
765 	{
766 		.procname	= "ip_autobind_reuse",
767 		.data		= &init_net.ipv4.sysctl_ip_autobind_reuse,
768 		.maxlen		= sizeof(u8),
769 		.mode		= 0644,
770 		.proc_handler	= proc_dou8vec_minmax,
771 		.extra1         = SYSCTL_ZERO,
772 		.extra2         = SYSCTL_ONE,
773 	},
774 	{
775 		.procname	= "fwmark_reflect",
776 		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
777 		.maxlen		= sizeof(u8),
778 		.mode		= 0644,
779 		.proc_handler	= proc_dou8vec_minmax,
780 	},
781 	{
782 		.procname	= "tcp_fwmark_accept",
783 		.data		= &init_net.ipv4.sysctl_tcp_fwmark_accept,
784 		.maxlen		= sizeof(u8),
785 		.mode		= 0644,
786 		.proc_handler	= proc_dou8vec_minmax,
787 	},
788 #ifdef CONFIG_NET_L3_MASTER_DEV
789 	{
790 		.procname	= "tcp_l3mdev_accept",
791 		.data		= &init_net.ipv4.sysctl_tcp_l3mdev_accept,
792 		.maxlen		= sizeof(u8),
793 		.mode		= 0644,
794 		.proc_handler	= proc_dou8vec_minmax,
795 		.extra1		= SYSCTL_ZERO,
796 		.extra2		= SYSCTL_ONE,
797 	},
798 #endif
799 	{
800 		.procname	= "tcp_mtu_probing",
801 		.data		= &init_net.ipv4.sysctl_tcp_mtu_probing,
802 		.maxlen		= sizeof(u8),
803 		.mode		= 0644,
804 		.proc_handler	= proc_dou8vec_minmax,
805 	},
806 	{
807 		.procname	= "tcp_base_mss",
808 		.data		= &init_net.ipv4.sysctl_tcp_base_mss,
809 		.maxlen		= sizeof(int),
810 		.mode		= 0644,
811 		.proc_handler	= proc_dointvec,
812 	},
813 	{
814 		.procname	= "tcp_min_snd_mss",
815 		.data		= &init_net.ipv4.sysctl_tcp_min_snd_mss,
816 		.maxlen		= sizeof(int),
817 		.mode		= 0644,
818 		.proc_handler	= proc_dointvec_minmax,
819 		.extra1		= &tcp_min_snd_mss_min,
820 		.extra2		= &tcp_min_snd_mss_max,
821 	},
822 	{
823 		.procname	= "tcp_mtu_probe_floor",
824 		.data		= &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
825 		.maxlen		= sizeof(int),
826 		.mode		= 0644,
827 		.proc_handler	= proc_dointvec_minmax,
828 		.extra1		= &tcp_min_snd_mss_min,
829 		.extra2		= &tcp_min_snd_mss_max,
830 	},
831 	{
832 		.procname	= "tcp_probe_threshold",
833 		.data		= &init_net.ipv4.sysctl_tcp_probe_threshold,
834 		.maxlen		= sizeof(int),
835 		.mode		= 0644,
836 		.proc_handler	= proc_dointvec,
837 	},
838 	{
839 		.procname	= "tcp_probe_interval",
840 		.data		= &init_net.ipv4.sysctl_tcp_probe_interval,
841 		.maxlen		= sizeof(u32),
842 		.mode		= 0644,
843 		.proc_handler	= proc_douintvec_minmax,
844 		.extra2		= &u32_max_div_HZ,
845 	},
846 	{
847 		.procname	= "igmp_link_local_mcast_reports",
848 		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
849 		.maxlen		= sizeof(u8),
850 		.mode		= 0644,
851 		.proc_handler	= proc_dou8vec_minmax,
852 	},
853 	{
854 		.procname	= "igmp_max_memberships",
855 		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
856 		.maxlen		= sizeof(int),
857 		.mode		= 0644,
858 		.proc_handler	= proc_dointvec
859 	},
860 	{
861 		.procname	= "igmp_max_msf",
862 		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
863 		.maxlen		= sizeof(int),
864 		.mode		= 0644,
865 		.proc_handler	= proc_dointvec
866 	},
867 #ifdef CONFIG_IP_MULTICAST
868 	{
869 		.procname	= "igmp_qrv",
870 		.data		= &init_net.ipv4.sysctl_igmp_qrv,
871 		.maxlen		= sizeof(int),
872 		.mode		= 0644,
873 		.proc_handler	= proc_dointvec_minmax,
874 		.extra1		= SYSCTL_ONE
875 	},
876 #endif
877 	{
878 		.procname	= "tcp_congestion_control",
879 		.data		= &init_net.ipv4.tcp_congestion_control,
880 		.mode		= 0644,
881 		.maxlen		= TCP_CA_NAME_MAX,
882 		.proc_handler	= proc_tcp_congestion_control,
883 	},
884 	{
885 		.procname	= "tcp_available_congestion_control",
886 		.maxlen		= TCP_CA_BUF_MAX,
887 		.mode		= 0444,
888 		.proc_handler   = proc_tcp_available_congestion_control,
889 	},
890 	{
891 		.procname	= "tcp_allowed_congestion_control",
892 		.maxlen		= TCP_CA_BUF_MAX,
893 		.mode		= 0644,
894 		.proc_handler   = proc_allowed_congestion_control,
895 	},
896 	{
897 		.procname	= "tcp_keepalive_time",
898 		.data		= &init_net.ipv4.sysctl_tcp_keepalive_time,
899 		.maxlen		= sizeof(int),
900 		.mode		= 0644,
901 		.proc_handler	= proc_dointvec_jiffies,
902 	},
903 	{
904 		.procname	= "tcp_keepalive_probes",
905 		.data		= &init_net.ipv4.sysctl_tcp_keepalive_probes,
906 		.maxlen		= sizeof(u8),
907 		.mode		= 0644,
908 		.proc_handler	= proc_dou8vec_minmax,
909 	},
910 	{
911 		.procname	= "tcp_keepalive_intvl",
912 		.data		= &init_net.ipv4.sysctl_tcp_keepalive_intvl,
913 		.maxlen		= sizeof(int),
914 		.mode		= 0644,
915 		.proc_handler	= proc_dointvec_jiffies,
916 	},
917 	{
918 		.procname	= "tcp_syn_retries",
919 		.data		= &init_net.ipv4.sysctl_tcp_syn_retries,
920 		.maxlen		= sizeof(u8),
921 		.mode		= 0644,
922 		.proc_handler	= proc_dou8vec_minmax,
923 		.extra1		= &tcp_syn_retries_min,
924 		.extra2		= &tcp_syn_retries_max
925 	},
926 	{
927 		.procname	= "tcp_synack_retries",
928 		.data		= &init_net.ipv4.sysctl_tcp_synack_retries,
929 		.maxlen		= sizeof(u8),
930 		.mode		= 0644,
931 		.proc_handler	= proc_dou8vec_minmax,
932 	},
933 #ifdef CONFIG_SYN_COOKIES
934 	{
935 		.procname	= "tcp_syncookies",
936 		.data		= &init_net.ipv4.sysctl_tcp_syncookies,
937 		.maxlen		= sizeof(u8),
938 		.mode		= 0644,
939 		.proc_handler	= proc_dou8vec_minmax,
940 	},
941 #endif
942 	{
943 		.procname	= "tcp_migrate_req",
944 		.data		= &init_net.ipv4.sysctl_tcp_migrate_req,
945 		.maxlen		= sizeof(u8),
946 		.mode		= 0644,
947 		.proc_handler	= proc_dou8vec_minmax,
948 		.extra1		= SYSCTL_ZERO,
949 		.extra2		= SYSCTL_ONE
950 	},
951 	{
952 		.procname	= "tcp_reordering",
953 		.data		= &init_net.ipv4.sysctl_tcp_reordering,
954 		.maxlen		= sizeof(int),
955 		.mode		= 0644,
956 		.proc_handler	= proc_dointvec
957 	},
958 	{
959 		.procname	= "tcp_retries1",
960 		.data		= &init_net.ipv4.sysctl_tcp_retries1,
961 		.maxlen		= sizeof(u8),
962 		.mode		= 0644,
963 		.proc_handler	= proc_dou8vec_minmax,
964 		.extra2		= &tcp_retr1_max
965 	},
966 	{
967 		.procname	= "tcp_retries2",
968 		.data		= &init_net.ipv4.sysctl_tcp_retries2,
969 		.maxlen		= sizeof(u8),
970 		.mode		= 0644,
971 		.proc_handler	= proc_dou8vec_minmax,
972 	},
973 	{
974 		.procname	= "tcp_orphan_retries",
975 		.data		= &init_net.ipv4.sysctl_tcp_orphan_retries,
976 		.maxlen		= sizeof(u8),
977 		.mode		= 0644,
978 		.proc_handler	= proc_dou8vec_minmax,
979 	},
980 	{
981 		.procname	= "tcp_fin_timeout",
982 		.data		= &init_net.ipv4.sysctl_tcp_fin_timeout,
983 		.maxlen		= sizeof(int),
984 		.mode		= 0644,
985 		.proc_handler	= proc_dointvec_jiffies,
986 	},
987 	{
988 		.procname	= "tcp_notsent_lowat",
989 		.data		= &init_net.ipv4.sysctl_tcp_notsent_lowat,
990 		.maxlen		= sizeof(unsigned int),
991 		.mode		= 0644,
992 		.proc_handler	= proc_douintvec,
993 	},
994 	{
995 		.procname	= "tcp_tw_reuse",
996 		.data		= &init_net.ipv4.sysctl_tcp_tw_reuse,
997 		.maxlen		= sizeof(u8),
998 		.mode		= 0644,
999 		.proc_handler	= proc_dou8vec_minmax,
1000 		.extra1		= SYSCTL_ZERO,
1001 		.extra2		= &two,
1002 	},
1003 	{
1004 		.procname	= "tcp_max_tw_buckets",
1005 		.data		= &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
1006 		.maxlen		= sizeof(int),
1007 		.mode		= 0644,
1008 		.proc_handler	= proc_dointvec
1009 	},
1010 	{
1011 		.procname	= "tcp_max_syn_backlog",
1012 		.data		= &init_net.ipv4.sysctl_max_syn_backlog,
1013 		.maxlen		= sizeof(int),
1014 		.mode		= 0644,
1015 		.proc_handler	= proc_dointvec
1016 	},
1017 	{
1018 		.procname	= "tcp_fastopen",
1019 		.data		= &init_net.ipv4.sysctl_tcp_fastopen,
1020 		.maxlen		= sizeof(int),
1021 		.mode		= 0644,
1022 		.proc_handler	= proc_dointvec,
1023 	},
1024 	{
1025 		.procname	= "tcp_fastopen_key",
1026 		.mode		= 0600,
1027 		.data		= &init_net.ipv4.sysctl_tcp_fastopen,
1028 		/* maxlen to print the list of keys in hex (*2), with dashes
1029 		 * separating doublewords and a comma in between keys.
1030 		 */
1031 		.maxlen		= ((TCP_FASTOPEN_KEY_LENGTH *
1032 				   2 * TCP_FASTOPEN_KEY_MAX) +
1033 				   (TCP_FASTOPEN_KEY_MAX * 5)),
1034 		.proc_handler	= proc_tcp_fastopen_key,
1035 	},
1036 	{
1037 		.procname	= "tcp_fastopen_blackhole_timeout_sec",
1038 		.data		= &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1039 		.maxlen		= sizeof(int),
1040 		.mode		= 0644,
1041 		.proc_handler	= proc_tfo_blackhole_detect_timeout,
1042 		.extra1		= SYSCTL_ZERO,
1043 	},
1044 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1045 	{
1046 		.procname	= "fib_multipath_use_neigh",
1047 		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1048 		.maxlen		= sizeof(u8),
1049 		.mode		= 0644,
1050 		.proc_handler	= proc_dou8vec_minmax,
1051 		.extra1		= SYSCTL_ZERO,
1052 		.extra2		= SYSCTL_ONE,
1053 	},
1054 	{
1055 		.procname	= "fib_multipath_hash_policy",
1056 		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1057 		.maxlen		= sizeof(u8),
1058 		.mode		= 0644,
1059 		.proc_handler	= proc_fib_multipath_hash_policy,
1060 		.extra1		= SYSCTL_ZERO,
1061 		.extra2		= &three,
1062 	},
1063 	{
1064 		.procname	= "fib_multipath_hash_fields",
1065 		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1066 		.maxlen		= sizeof(u32),
1067 		.mode		= 0644,
1068 		.proc_handler	= proc_fib_multipath_hash_fields,
1069 		.extra1		= SYSCTL_ONE,
1070 		.extra2		= &fib_multipath_hash_fields_all_mask,
1071 	},
1072 #endif
1073 	{
1074 		.procname	= "ip_unprivileged_port_start",
1075 		.maxlen		= sizeof(int),
1076 		.data		= &init_net.ipv4.sysctl_ip_prot_sock,
1077 		.mode		= 0644,
1078 		.proc_handler	= ipv4_privileged_ports,
1079 	},
1080 #ifdef CONFIG_NET_L3_MASTER_DEV
1081 	{
1082 		.procname	= "udp_l3mdev_accept",
1083 		.data		= &init_net.ipv4.sysctl_udp_l3mdev_accept,
1084 		.maxlen		= sizeof(u8),
1085 		.mode		= 0644,
1086 		.proc_handler	= proc_dou8vec_minmax,
1087 		.extra1		= SYSCTL_ZERO,
1088 		.extra2		= SYSCTL_ONE,
1089 	},
1090 #endif
1091 	{
1092 		.procname	= "tcp_sack",
1093 		.data		= &init_net.ipv4.sysctl_tcp_sack,
1094 		.maxlen		= sizeof(u8),
1095 		.mode		= 0644,
1096 		.proc_handler	= proc_dou8vec_minmax,
1097 	},
1098 	{
1099 		.procname	= "tcp_window_scaling",
1100 		.data		= &init_net.ipv4.sysctl_tcp_window_scaling,
1101 		.maxlen		= sizeof(u8),
1102 		.mode		= 0644,
1103 		.proc_handler	= proc_dou8vec_minmax,
1104 	},
1105 	{
1106 		.procname	= "tcp_timestamps",
1107 		.data		= &init_net.ipv4.sysctl_tcp_timestamps,
1108 		.maxlen		= sizeof(u8),
1109 		.mode		= 0644,
1110 		.proc_handler	= proc_dou8vec_minmax,
1111 	},
1112 	{
1113 		.procname	= "tcp_early_retrans",
1114 		.data		= &init_net.ipv4.sysctl_tcp_early_retrans,
1115 		.maxlen		= sizeof(u8),
1116 		.mode		= 0644,
1117 		.proc_handler	= proc_dou8vec_minmax,
1118 		.extra1		= SYSCTL_ZERO,
1119 		.extra2		= &four,
1120 	},
1121 	{
1122 		.procname	= "tcp_recovery",
1123 		.data		= &init_net.ipv4.sysctl_tcp_recovery,
1124 		.maxlen		= sizeof(u8),
1125 		.mode		= 0644,
1126 		.proc_handler	= proc_dou8vec_minmax,
1127 	},
1128 	{
1129 		.procname       = "tcp_thin_linear_timeouts",
1130 		.data           = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1131 		.maxlen         = sizeof(u8),
1132 		.mode           = 0644,
1133 		.proc_handler   = proc_dou8vec_minmax,
1134 	},
1135 	{
1136 		.procname	= "tcp_slow_start_after_idle",
1137 		.data		= &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1138 		.maxlen		= sizeof(u8),
1139 		.mode		= 0644,
1140 		.proc_handler	= proc_dou8vec_minmax,
1141 	},
1142 	{
1143 		.procname	= "tcp_retrans_collapse",
1144 		.data		= &init_net.ipv4.sysctl_tcp_retrans_collapse,
1145 		.maxlen		= sizeof(u8),
1146 		.mode		= 0644,
1147 		.proc_handler	= proc_dou8vec_minmax,
1148 	},
1149 	{
1150 		.procname	= "tcp_stdurg",
1151 		.data		= &init_net.ipv4.sysctl_tcp_stdurg,
1152 		.maxlen		= sizeof(u8),
1153 		.mode		= 0644,
1154 		.proc_handler	= proc_dou8vec_minmax,
1155 	},
1156 	{
1157 		.procname	= "tcp_rfc1337",
1158 		.data		= &init_net.ipv4.sysctl_tcp_rfc1337,
1159 		.maxlen		= sizeof(u8),
1160 		.mode		= 0644,
1161 		.proc_handler	= proc_dou8vec_minmax,
1162 	},
1163 	{
1164 		.procname	= "tcp_abort_on_overflow",
1165 		.data		= &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1166 		.maxlen		= sizeof(u8),
1167 		.mode		= 0644,
1168 		.proc_handler	= proc_dou8vec_minmax,
1169 	},
1170 	{
1171 		.procname	= "tcp_fack",
1172 		.data		= &init_net.ipv4.sysctl_tcp_fack,
1173 		.maxlen		= sizeof(u8),
1174 		.mode		= 0644,
1175 		.proc_handler	= proc_dou8vec_minmax,
1176 	},
1177 	{
1178 		.procname	= "tcp_max_reordering",
1179 		.data		= &init_net.ipv4.sysctl_tcp_max_reordering,
1180 		.maxlen		= sizeof(int),
1181 		.mode		= 0644,
1182 		.proc_handler	= proc_dointvec
1183 	},
1184 	{
1185 		.procname	= "tcp_dsack",
1186 		.data		= &init_net.ipv4.sysctl_tcp_dsack,
1187 		.maxlen		= sizeof(u8),
1188 		.mode		= 0644,
1189 		.proc_handler	= proc_dou8vec_minmax,
1190 	},
1191 	{
1192 		.procname	= "tcp_app_win",
1193 		.data		= &init_net.ipv4.sysctl_tcp_app_win,
1194 		.maxlen		= sizeof(u8),
1195 		.mode		= 0644,
1196 		.proc_handler	= proc_dou8vec_minmax,
1197 	},
1198 	{
1199 		.procname	= "tcp_adv_win_scale",
1200 		.data		= &init_net.ipv4.sysctl_tcp_adv_win_scale,
1201 		.maxlen		= sizeof(int),
1202 		.mode		= 0644,
1203 		.proc_handler	= proc_dointvec_minmax,
1204 		.extra1		= &tcp_adv_win_scale_min,
1205 		.extra2		= &tcp_adv_win_scale_max,
1206 	},
1207 	{
1208 		.procname	= "tcp_frto",
1209 		.data		= &init_net.ipv4.sysctl_tcp_frto,
1210 		.maxlen		= sizeof(u8),
1211 		.mode		= 0644,
1212 		.proc_handler	= proc_dou8vec_minmax,
1213 	},
1214 	{
1215 		.procname	= "tcp_no_metrics_save",
1216 		.data		= &init_net.ipv4.sysctl_tcp_nometrics_save,
1217 		.maxlen		= sizeof(u8),
1218 		.mode		= 0644,
1219 		.proc_handler	= proc_dou8vec_minmax,
1220 	},
1221 	{
1222 		.procname	= "tcp_no_ssthresh_metrics_save",
1223 		.data		= &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1224 		.maxlen		= sizeof(u8),
1225 		.mode		= 0644,
1226 		.proc_handler	= proc_dou8vec_minmax,
1227 		.extra1		= SYSCTL_ZERO,
1228 		.extra2		= SYSCTL_ONE,
1229 	},
1230 	{
1231 		.procname	= "tcp_moderate_rcvbuf",
1232 		.data		= &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1233 		.maxlen		= sizeof(u8),
1234 		.mode		= 0644,
1235 		.proc_handler	= proc_dou8vec_minmax,
1236 	},
1237 	{
1238 		.procname	= "tcp_tso_win_divisor",
1239 		.data		= &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1240 		.maxlen		= sizeof(u8),
1241 		.mode		= 0644,
1242 		.proc_handler	= proc_dou8vec_minmax,
1243 	},
1244 	{
1245 		.procname	= "tcp_workaround_signed_windows",
1246 		.data		= &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1247 		.maxlen		= sizeof(u8),
1248 		.mode		= 0644,
1249 		.proc_handler	= proc_dou8vec_minmax,
1250 	},
1251 	{
1252 		.procname	= "tcp_limit_output_bytes",
1253 		.data		= &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1254 		.maxlen		= sizeof(int),
1255 		.mode		= 0644,
1256 		.proc_handler	= proc_dointvec
1257 	},
1258 	{
1259 		.procname	= "tcp_challenge_ack_limit",
1260 		.data		= &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1261 		.maxlen		= sizeof(int),
1262 		.mode		= 0644,
1263 		.proc_handler	= proc_dointvec
1264 	},
1265 	{
1266 		.procname	= "tcp_min_tso_segs",
1267 		.data		= &init_net.ipv4.sysctl_tcp_min_tso_segs,
1268 		.maxlen		= sizeof(u8),
1269 		.mode		= 0644,
1270 		.proc_handler	= proc_dou8vec_minmax,
1271 		.extra1		= SYSCTL_ONE,
1272 	},
1273 	{
1274 		.procname	= "tcp_min_rtt_wlen",
1275 		.data		= &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1276 		.maxlen		= sizeof(int),
1277 		.mode		= 0644,
1278 		.proc_handler	= proc_dointvec_minmax,
1279 		.extra1		= SYSCTL_ZERO,
1280 		.extra2		= &one_day_secs
1281 	},
1282 	{
1283 		.procname	= "tcp_autocorking",
1284 		.data		= &init_net.ipv4.sysctl_tcp_autocorking,
1285 		.maxlen		= sizeof(u8),
1286 		.mode		= 0644,
1287 		.proc_handler	= proc_dou8vec_minmax,
1288 		.extra1		= SYSCTL_ZERO,
1289 		.extra2		= SYSCTL_ONE,
1290 	},
1291 	{
1292 		.procname	= "tcp_invalid_ratelimit",
1293 		.data		= &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1294 		.maxlen		= sizeof(int),
1295 		.mode		= 0644,
1296 		.proc_handler	= proc_dointvec_ms_jiffies,
1297 	},
1298 	{
1299 		.procname	= "tcp_pacing_ss_ratio",
1300 		.data		= &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1301 		.maxlen		= sizeof(int),
1302 		.mode		= 0644,
1303 		.proc_handler	= proc_dointvec_minmax,
1304 		.extra1		= SYSCTL_ZERO,
1305 		.extra2		= &thousand,
1306 	},
1307 	{
1308 		.procname	= "tcp_pacing_ca_ratio",
1309 		.data		= &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1310 		.maxlen		= sizeof(int),
1311 		.mode		= 0644,
1312 		.proc_handler	= proc_dointvec_minmax,
1313 		.extra1		= SYSCTL_ZERO,
1314 		.extra2		= &thousand,
1315 	},
1316 	{
1317 		.procname	= "tcp_wmem",
1318 		.data		= &init_net.ipv4.sysctl_tcp_wmem,
1319 		.maxlen		= sizeof(init_net.ipv4.sysctl_tcp_wmem),
1320 		.mode		= 0644,
1321 		.proc_handler	= proc_dointvec_minmax,
1322 		.extra1		= SYSCTL_ONE,
1323 	},
1324 	{
1325 		.procname	= "tcp_rmem",
1326 		.data		= &init_net.ipv4.sysctl_tcp_rmem,
1327 		.maxlen		= sizeof(init_net.ipv4.sysctl_tcp_rmem),
1328 		.mode		= 0644,
1329 		.proc_handler	= proc_dointvec_minmax,
1330 		.extra1		= SYSCTL_ONE,
1331 	},
1332 	{
1333 		.procname	= "tcp_comp_sack_delay_ns",
1334 		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1335 		.maxlen		= sizeof(unsigned long),
1336 		.mode		= 0644,
1337 		.proc_handler	= proc_doulongvec_minmax,
1338 	},
1339 	{
1340 		.procname	= "tcp_comp_sack_slack_ns",
1341 		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1342 		.maxlen		= sizeof(unsigned long),
1343 		.mode		= 0644,
1344 		.proc_handler	= proc_doulongvec_minmax,
1345 	},
1346 	{
1347 		.procname	= "tcp_comp_sack_nr",
1348 		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1349 		.maxlen		= sizeof(u8),
1350 		.mode		= 0644,
1351 		.proc_handler	= proc_dou8vec_minmax,
1352 		.extra1		= SYSCTL_ZERO,
1353 	},
1354 	{
1355 		.procname       = "tcp_reflect_tos",
1356 		.data           = &init_net.ipv4.sysctl_tcp_reflect_tos,
1357 		.maxlen         = sizeof(u8),
1358 		.mode           = 0644,
1359 		.proc_handler   = proc_dou8vec_minmax,
1360 		.extra1         = SYSCTL_ZERO,
1361 		.extra2         = SYSCTL_ONE,
1362 	},
1363 	{
1364 		.procname	= "udp_rmem_min",
1365 		.data		= &init_net.ipv4.sysctl_udp_rmem_min,
1366 		.maxlen		= sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1367 		.mode		= 0644,
1368 		.proc_handler	= proc_dointvec_minmax,
1369 		.extra1		= SYSCTL_ONE
1370 	},
1371 	{
1372 		.procname	= "udp_wmem_min",
1373 		.data		= &init_net.ipv4.sysctl_udp_wmem_min,
1374 		.maxlen		= sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1375 		.mode		= 0644,
1376 		.proc_handler	= proc_dointvec_minmax,
1377 		.extra1		= SYSCTL_ONE
1378 	},
1379 	{
1380 		.procname	= "fib_notify_on_flag_change",
1381 		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1382 		.maxlen		= sizeof(u8),
1383 		.mode		= 0644,
1384 		.proc_handler	= proc_dou8vec_minmax,
1385 		.extra1		= SYSCTL_ZERO,
1386 		.extra2		= &two,
1387 	},
1388 	{ }
1389 };
1390 
1391 static __net_init int ipv4_sysctl_init_net(struct net *net)
1392 {
1393 	struct ctl_table *table;
1394 
1395 	table = ipv4_net_table;
1396 	if (!net_eq(net, &init_net)) {
1397 		int i;
1398 
1399 		table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1400 		if (!table)
1401 			goto err_alloc;
1402 
1403 		for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1404 			if (table[i].data) {
1405 				/* Update the variables to point into
1406 				 * the current struct net
1407 				 */
1408 				table[i].data += (void *)net - (void *)&init_net;
1409 			} else {
1410 				/* Entries without data pointer are global;
1411 				 * Make them read-only in non-init_net ns
1412 				 */
1413 				table[i].mode &= ~0222;
1414 			}
1415 		}
1416 	}
1417 
1418 	net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1419 	if (!net->ipv4.ipv4_hdr)
1420 		goto err_reg;
1421 
1422 	net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1423 	if (!net->ipv4.sysctl_local_reserved_ports)
1424 		goto err_ports;
1425 
1426 	return 0;
1427 
1428 err_ports:
1429 	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1430 err_reg:
1431 	if (!net_eq(net, &init_net))
1432 		kfree(table);
1433 err_alloc:
1434 	return -ENOMEM;
1435 }
1436 
1437 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1438 {
1439 	struct ctl_table *table;
1440 
1441 	kfree(net->ipv4.sysctl_local_reserved_ports);
1442 	table = net->ipv4.ipv4_hdr->ctl_table_arg;
1443 	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1444 	kfree(table);
1445 }
1446 
1447 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1448 	.init = ipv4_sysctl_init_net,
1449 	.exit = ipv4_sysctl_exit_net,
1450 };
1451 
1452 static __init int sysctl_ipv4_init(void)
1453 {
1454 	struct ctl_table_header *hdr;
1455 
1456 	hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1457 	if (!hdr)
1458 		return -ENOMEM;
1459 
1460 	if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1461 		unregister_net_sysctl_table(hdr);
1462 		return -ENOMEM;
1463 	}
1464 
1465 	return 0;
1466 }
1467 
1468 __initcall(sysctl_ipv4_init);
1469