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