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