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