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