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