USB: usb-storage: unusual_devs update for Super TOP SATA bridge
[linux/fpc-iii.git] / net / ipv4 / sysctl_net_ipv4.c
blobbf7a604c695c42db10e412f2114b4272068f6c94
1 /*
2 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4 * Begun April 1, 1996, Mike Shaver.
5 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
6 */
8 #include <linux/mm.h>
9 #include <linux/module.h>
10 #include <linux/sysctl.h>
11 #include <linux/igmp.h>
12 #include <linux/inetdevice.h>
13 #include <linux/seqlock.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/nsproxy.h>
17 #include <linux/swap.h>
18 #include <net/snmp.h>
19 #include <net/icmp.h>
20 #include <net/ip.h>
21 #include <net/route.h>
22 #include <net/tcp.h>
23 #include <net/udp.h>
24 #include <net/cipso_ipv4.h>
25 #include <net/inet_frag.h>
26 #include <net/ping.h>
27 #include <net/tcp_memcontrol.h>
29 static int zero;
30 static int tcp_retr1_max = 255;
31 static int ip_local_port_range_min[] = { 1, 1 };
32 static int ip_local_port_range_max[] = { 65535, 65535 };
33 static int tcp_adv_win_scale_min = -31;
34 static int tcp_adv_win_scale_max = 31;
35 static int ip_ttl_min = 1;
36 static int ip_ttl_max = 255;
37 static int ip_ping_group_range_min[] = { 0, 0 };
38 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
40 /* Update system visible IP port range */
41 static void set_local_port_range(int range[2])
43 write_seqlock(&sysctl_local_ports.lock);
44 sysctl_local_ports.range[0] = range[0];
45 sysctl_local_ports.range[1] = range[1];
46 write_sequnlock(&sysctl_local_ports.lock);
49 /* Validate changes from /proc interface. */
50 static int ipv4_local_port_range(ctl_table *table, int write,
51 void __user *buffer,
52 size_t *lenp, loff_t *ppos)
54 int ret;
55 int range[2];
56 ctl_table tmp = {
57 .data = &range,
58 .maxlen = sizeof(range),
59 .mode = table->mode,
60 .extra1 = &ip_local_port_range_min,
61 .extra2 = &ip_local_port_range_max,
64 inet_get_local_port_range(range, range + 1);
65 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
67 if (write && ret == 0) {
68 if (range[1] < range[0])
69 ret = -EINVAL;
70 else
71 set_local_port_range(range);
74 return ret;
78 static void inet_get_ping_group_range_table(struct ctl_table *table, gid_t *low, gid_t *high)
80 gid_t *data = table->data;
81 unsigned seq;
82 do {
83 seq = read_seqbegin(&sysctl_local_ports.lock);
85 *low = data[0];
86 *high = data[1];
87 } while (read_seqretry(&sysctl_local_ports.lock, seq));
90 /* Update system visible IP port range */
91 static void set_ping_group_range(struct ctl_table *table, gid_t range[2])
93 gid_t *data = table->data;
94 write_seqlock(&sysctl_local_ports.lock);
95 data[0] = range[0];
96 data[1] = range[1];
97 write_sequnlock(&sysctl_local_ports.lock);
100 /* Validate changes from /proc interface. */
101 static int ipv4_ping_group_range(ctl_table *table, int write,
102 void __user *buffer,
103 size_t *lenp, loff_t *ppos)
105 int ret;
106 gid_t range[2];
107 ctl_table tmp = {
108 .data = &range,
109 .maxlen = sizeof(range),
110 .mode = table->mode,
111 .extra1 = &ip_ping_group_range_min,
112 .extra2 = &ip_ping_group_range_max,
115 inet_get_ping_group_range_table(table, range, range + 1);
116 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
118 if (write && ret == 0)
119 set_ping_group_range(table, range);
121 return ret;
124 static int proc_tcp_congestion_control(ctl_table *ctl, int write,
125 void __user *buffer, size_t *lenp, loff_t *ppos)
127 char val[TCP_CA_NAME_MAX];
128 ctl_table tbl = {
129 .data = val,
130 .maxlen = TCP_CA_NAME_MAX,
132 int ret;
134 tcp_get_default_congestion_control(val);
136 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
137 if (write && ret == 0)
138 ret = tcp_set_default_congestion_control(val);
139 return ret;
142 static int proc_tcp_available_congestion_control(ctl_table *ctl,
143 int write,
144 void __user *buffer, size_t *lenp,
145 loff_t *ppos)
147 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
148 int ret;
150 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
151 if (!tbl.data)
152 return -ENOMEM;
153 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
154 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
155 kfree(tbl.data);
156 return ret;
159 static int proc_allowed_congestion_control(ctl_table *ctl,
160 int write,
161 void __user *buffer, size_t *lenp,
162 loff_t *ppos)
164 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
165 int ret;
167 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
168 if (!tbl.data)
169 return -ENOMEM;
171 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
172 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
173 if (write && ret == 0)
174 ret = tcp_set_allowed_congestion_control(tbl.data);
175 kfree(tbl.data);
176 return ret;
179 static int ipv4_tcp_mem(ctl_table *ctl, int write,
180 void __user *buffer, size_t *lenp,
181 loff_t *ppos)
183 int ret;
184 unsigned long vec[3];
185 struct net *net = current->nsproxy->net_ns;
186 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
187 struct mem_cgroup *memcg;
188 #endif
190 ctl_table tmp = {
191 .data = &vec,
192 .maxlen = sizeof(vec),
193 .mode = ctl->mode,
196 if (!write) {
197 ctl->data = &net->ipv4.sysctl_tcp_mem;
198 return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
201 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
202 if (ret)
203 return ret;
205 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
206 rcu_read_lock();
207 memcg = mem_cgroup_from_task(current);
209 tcp_prot_mem(memcg, vec[0], 0);
210 tcp_prot_mem(memcg, vec[1], 1);
211 tcp_prot_mem(memcg, vec[2], 2);
212 rcu_read_unlock();
213 #endif
215 net->ipv4.sysctl_tcp_mem[0] = vec[0];
216 net->ipv4.sysctl_tcp_mem[1] = vec[1];
217 net->ipv4.sysctl_tcp_mem[2] = vec[2];
219 return 0;
222 static struct ctl_table ipv4_table[] = {
224 .procname = "tcp_timestamps",
225 .data = &sysctl_tcp_timestamps,
226 .maxlen = sizeof(int),
227 .mode = 0644,
228 .proc_handler = proc_dointvec
231 .procname = "tcp_window_scaling",
232 .data = &sysctl_tcp_window_scaling,
233 .maxlen = sizeof(int),
234 .mode = 0644,
235 .proc_handler = proc_dointvec
238 .procname = "tcp_sack",
239 .data = &sysctl_tcp_sack,
240 .maxlen = sizeof(int),
241 .mode = 0644,
242 .proc_handler = proc_dointvec
245 .procname = "tcp_retrans_collapse",
246 .data = &sysctl_tcp_retrans_collapse,
247 .maxlen = sizeof(int),
248 .mode = 0644,
249 .proc_handler = proc_dointvec
252 .procname = "ip_default_ttl",
253 .data = &sysctl_ip_default_ttl,
254 .maxlen = sizeof(int),
255 .mode = 0644,
256 .proc_handler = proc_dointvec_minmax,
257 .extra1 = &ip_ttl_min,
258 .extra2 = &ip_ttl_max,
261 .procname = "ip_no_pmtu_disc",
262 .data = &ipv4_config.no_pmtu_disc,
263 .maxlen = sizeof(int),
264 .mode = 0644,
265 .proc_handler = proc_dointvec
268 .procname = "ip_nonlocal_bind",
269 .data = &sysctl_ip_nonlocal_bind,
270 .maxlen = sizeof(int),
271 .mode = 0644,
272 .proc_handler = proc_dointvec
275 .procname = "tcp_syn_retries",
276 .data = &sysctl_tcp_syn_retries,
277 .maxlen = sizeof(int),
278 .mode = 0644,
279 .proc_handler = proc_dointvec
282 .procname = "tcp_synack_retries",
283 .data = &sysctl_tcp_synack_retries,
284 .maxlen = sizeof(int),
285 .mode = 0644,
286 .proc_handler = proc_dointvec
289 .procname = "tcp_max_orphans",
290 .data = &sysctl_tcp_max_orphans,
291 .maxlen = sizeof(int),
292 .mode = 0644,
293 .proc_handler = proc_dointvec
296 .procname = "tcp_max_tw_buckets",
297 .data = &tcp_death_row.sysctl_max_tw_buckets,
298 .maxlen = sizeof(int),
299 .mode = 0644,
300 .proc_handler = proc_dointvec
303 .procname = "ip_dynaddr",
304 .data = &sysctl_ip_dynaddr,
305 .maxlen = sizeof(int),
306 .mode = 0644,
307 .proc_handler = proc_dointvec
310 .procname = "tcp_keepalive_time",
311 .data = &sysctl_tcp_keepalive_time,
312 .maxlen = sizeof(int),
313 .mode = 0644,
314 .proc_handler = proc_dointvec_jiffies,
317 .procname = "tcp_keepalive_probes",
318 .data = &sysctl_tcp_keepalive_probes,
319 .maxlen = sizeof(int),
320 .mode = 0644,
321 .proc_handler = proc_dointvec
324 .procname = "tcp_keepalive_intvl",
325 .data = &sysctl_tcp_keepalive_intvl,
326 .maxlen = sizeof(int),
327 .mode = 0644,
328 .proc_handler = proc_dointvec_jiffies,
331 .procname = "tcp_retries1",
332 .data = &sysctl_tcp_retries1,
333 .maxlen = sizeof(int),
334 .mode = 0644,
335 .proc_handler = proc_dointvec_minmax,
336 .extra2 = &tcp_retr1_max
339 .procname = "tcp_retries2",
340 .data = &sysctl_tcp_retries2,
341 .maxlen = sizeof(int),
342 .mode = 0644,
343 .proc_handler = proc_dointvec
346 .procname = "tcp_fin_timeout",
347 .data = &sysctl_tcp_fin_timeout,
348 .maxlen = sizeof(int),
349 .mode = 0644,
350 .proc_handler = proc_dointvec_jiffies,
352 #ifdef CONFIG_SYN_COOKIES
354 .procname = "tcp_syncookies",
355 .data = &sysctl_tcp_syncookies,
356 .maxlen = sizeof(int),
357 .mode = 0644,
358 .proc_handler = proc_dointvec
360 #endif
362 .procname = "tcp_tw_recycle",
363 .data = &tcp_death_row.sysctl_tw_recycle,
364 .maxlen = sizeof(int),
365 .mode = 0644,
366 .proc_handler = proc_dointvec
369 .procname = "tcp_abort_on_overflow",
370 .data = &sysctl_tcp_abort_on_overflow,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = proc_dointvec
376 .procname = "tcp_stdurg",
377 .data = &sysctl_tcp_stdurg,
378 .maxlen = sizeof(int),
379 .mode = 0644,
380 .proc_handler = proc_dointvec
383 .procname = "tcp_rfc1337",
384 .data = &sysctl_tcp_rfc1337,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = proc_dointvec
390 .procname = "tcp_max_syn_backlog",
391 .data = &sysctl_max_syn_backlog,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = proc_dointvec
397 .procname = "ip_local_port_range",
398 .data = &sysctl_local_ports.range,
399 .maxlen = sizeof(sysctl_local_ports.range),
400 .mode = 0644,
401 .proc_handler = ipv4_local_port_range,
404 .procname = "ip_local_reserved_ports",
405 .data = NULL, /* initialized in sysctl_ipv4_init */
406 .maxlen = 65536,
407 .mode = 0644,
408 .proc_handler = proc_do_large_bitmap,
411 .procname = "igmp_max_memberships",
412 .data = &sysctl_igmp_max_memberships,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = proc_dointvec
418 .procname = "igmp_max_msf",
419 .data = &sysctl_igmp_max_msf,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = proc_dointvec
425 .procname = "inet_peer_threshold",
426 .data = &inet_peer_threshold,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = proc_dointvec
432 .procname = "inet_peer_minttl",
433 .data = &inet_peer_minttl,
434 .maxlen = sizeof(int),
435 .mode = 0644,
436 .proc_handler = proc_dointvec_jiffies,
439 .procname = "inet_peer_maxttl",
440 .data = &inet_peer_maxttl,
441 .maxlen = sizeof(int),
442 .mode = 0644,
443 .proc_handler = proc_dointvec_jiffies,
446 .procname = "tcp_orphan_retries",
447 .data = &sysctl_tcp_orphan_retries,
448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = proc_dointvec
453 .procname = "tcp_fack",
454 .data = &sysctl_tcp_fack,
455 .maxlen = sizeof(int),
456 .mode = 0644,
457 .proc_handler = proc_dointvec
460 .procname = "tcp_reordering",
461 .data = &sysctl_tcp_reordering,
462 .maxlen = sizeof(int),
463 .mode = 0644,
464 .proc_handler = proc_dointvec
467 .procname = "tcp_ecn",
468 .data = &sysctl_tcp_ecn,
469 .maxlen = sizeof(int),
470 .mode = 0644,
471 .proc_handler = proc_dointvec
474 .procname = "tcp_dsack",
475 .data = &sysctl_tcp_dsack,
476 .maxlen = sizeof(int),
477 .mode = 0644,
478 .proc_handler = proc_dointvec
481 .procname = "tcp_wmem",
482 .data = &sysctl_tcp_wmem,
483 .maxlen = sizeof(sysctl_tcp_wmem),
484 .mode = 0644,
485 .proc_handler = proc_dointvec
488 .procname = "tcp_rmem",
489 .data = &sysctl_tcp_rmem,
490 .maxlen = sizeof(sysctl_tcp_rmem),
491 .mode = 0644,
492 .proc_handler = proc_dointvec
495 .procname = "tcp_app_win",
496 .data = &sysctl_tcp_app_win,
497 .maxlen = sizeof(int),
498 .mode = 0644,
499 .proc_handler = proc_dointvec
502 .procname = "tcp_adv_win_scale",
503 .data = &sysctl_tcp_adv_win_scale,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &tcp_adv_win_scale_min,
508 .extra2 = &tcp_adv_win_scale_max,
511 .procname = "tcp_tw_reuse",
512 .data = &sysctl_tcp_tw_reuse,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = proc_dointvec
518 .procname = "tcp_frto",
519 .data = &sysctl_tcp_frto,
520 .maxlen = sizeof(int),
521 .mode = 0644,
522 .proc_handler = proc_dointvec
525 .procname = "tcp_frto_response",
526 .data = &sysctl_tcp_frto_response,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = proc_dointvec
532 .procname = "tcp_low_latency",
533 .data = &sysctl_tcp_low_latency,
534 .maxlen = sizeof(int),
535 .mode = 0644,
536 .proc_handler = proc_dointvec
539 .procname = "tcp_no_metrics_save",
540 .data = &sysctl_tcp_nometrics_save,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = proc_dointvec,
546 .procname = "tcp_moderate_rcvbuf",
547 .data = &sysctl_tcp_moderate_rcvbuf,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 .proc_handler = proc_dointvec,
553 .procname = "tcp_tso_win_divisor",
554 .data = &sysctl_tcp_tso_win_divisor,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 .proc_handler = proc_dointvec,
560 .procname = "tcp_congestion_control",
561 .mode = 0644,
562 .maxlen = TCP_CA_NAME_MAX,
563 .proc_handler = proc_tcp_congestion_control,
566 .procname = "tcp_abc",
567 .data = &sysctl_tcp_abc,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 .proc_handler = proc_dointvec,
573 .procname = "tcp_mtu_probing",
574 .data = &sysctl_tcp_mtu_probing,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = proc_dointvec,
580 .procname = "tcp_base_mss",
581 .data = &sysctl_tcp_base_mss,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = proc_dointvec,
587 .procname = "tcp_workaround_signed_windows",
588 .data = &sysctl_tcp_workaround_signed_windows,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec
594 .procname = "tcp_challenge_ack_limit",
595 .data = &sysctl_tcp_challenge_ack_limit,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = proc_dointvec
600 #ifdef CONFIG_NET_DMA
602 .procname = "tcp_dma_copybreak",
603 .data = &sysctl_tcp_dma_copybreak,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = proc_dointvec
608 #endif
610 .procname = "tcp_slow_start_after_idle",
611 .data = &sysctl_tcp_slow_start_after_idle,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = proc_dointvec
616 #ifdef CONFIG_NETLABEL
618 .procname = "cipso_cache_enable",
619 .data = &cipso_v4_cache_enabled,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 .proc_handler = proc_dointvec,
625 .procname = "cipso_cache_bucket_size",
626 .data = &cipso_v4_cache_bucketsize,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = proc_dointvec,
632 .procname = "cipso_rbm_optfmt",
633 .data = &cipso_v4_rbm_optfmt,
634 .maxlen = sizeof(int),
635 .mode = 0644,
636 .proc_handler = proc_dointvec,
639 .procname = "cipso_rbm_strictvalid",
640 .data = &cipso_v4_rbm_strictvalid,
641 .maxlen = sizeof(int),
642 .mode = 0644,
643 .proc_handler = proc_dointvec,
645 #endif /* CONFIG_NETLABEL */
647 .procname = "tcp_available_congestion_control",
648 .maxlen = TCP_CA_BUF_MAX,
649 .mode = 0444,
650 .proc_handler = proc_tcp_available_congestion_control,
653 .procname = "tcp_allowed_congestion_control",
654 .maxlen = TCP_CA_BUF_MAX,
655 .mode = 0644,
656 .proc_handler = proc_allowed_congestion_control,
659 .procname = "tcp_max_ssthresh",
660 .data = &sysctl_tcp_max_ssthresh,
661 .maxlen = sizeof(int),
662 .mode = 0644,
663 .proc_handler = proc_dointvec,
666 .procname = "tcp_cookie_size",
667 .data = &sysctl_tcp_cookie_size,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = proc_dointvec
673 .procname = "tcp_thin_linear_timeouts",
674 .data = &sysctl_tcp_thin_linear_timeouts,
675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = proc_dointvec
680 .procname = "tcp_thin_dupack",
681 .data = &sysctl_tcp_thin_dupack,
682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = proc_dointvec
687 .procname = "udp_mem",
688 .data = &sysctl_udp_mem,
689 .maxlen = sizeof(sysctl_udp_mem),
690 .mode = 0644,
691 .proc_handler = proc_doulongvec_minmax,
694 .procname = "udp_rmem_min",
695 .data = &sysctl_udp_rmem_min,
696 .maxlen = sizeof(sysctl_udp_rmem_min),
697 .mode = 0644,
698 .proc_handler = proc_dointvec_minmax,
699 .extra1 = &zero
702 .procname = "udp_wmem_min",
703 .data = &sysctl_udp_wmem_min,
704 .maxlen = sizeof(sysctl_udp_wmem_min),
705 .mode = 0644,
706 .proc_handler = proc_dointvec_minmax,
707 .extra1 = &zero
712 static struct ctl_table ipv4_net_table[] = {
714 .procname = "icmp_echo_ignore_all",
715 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = proc_dointvec
721 .procname = "icmp_echo_ignore_broadcasts",
722 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = proc_dointvec
728 .procname = "icmp_ignore_bogus_error_responses",
729 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
730 .maxlen = sizeof(int),
731 .mode = 0644,
732 .proc_handler = proc_dointvec
735 .procname = "icmp_errors_use_inbound_ifaddr",
736 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
737 .maxlen = sizeof(int),
738 .mode = 0644,
739 .proc_handler = proc_dointvec
742 .procname = "icmp_ratelimit",
743 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = proc_dointvec_ms_jiffies,
749 .procname = "icmp_ratemask",
750 .data = &init_net.ipv4.sysctl_icmp_ratemask,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec
756 .procname = "rt_cache_rebuild_count",
757 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
758 .maxlen = sizeof(int),
759 .mode = 0644,
760 .proc_handler = proc_dointvec
763 .procname = "ping_group_range",
764 .data = &init_net.ipv4.sysctl_ping_group_range,
765 .maxlen = sizeof(init_net.ipv4.sysctl_ping_group_range),
766 .mode = 0644,
767 .proc_handler = ipv4_ping_group_range,
770 .procname = "tcp_mem",
771 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_mem),
772 .mode = 0644,
773 .proc_handler = ipv4_tcp_mem,
778 struct ctl_path net_ipv4_ctl_path[] = {
779 { .procname = "net", },
780 { .procname = "ipv4", },
781 { },
783 EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
785 static __net_init int ipv4_sysctl_init_net(struct net *net)
787 struct ctl_table *table;
789 table = ipv4_net_table;
790 if (!net_eq(net, &init_net)) {
791 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
792 if (table == NULL)
793 goto err_alloc;
795 table[0].data =
796 &net->ipv4.sysctl_icmp_echo_ignore_all;
797 table[1].data =
798 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
799 table[2].data =
800 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
801 table[3].data =
802 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
803 table[4].data =
804 &net->ipv4.sysctl_icmp_ratelimit;
805 table[5].data =
806 &net->ipv4.sysctl_icmp_ratemask;
807 table[6].data =
808 &net->ipv4.sysctl_rt_cache_rebuild_count;
809 table[7].data =
810 &net->ipv4.sysctl_ping_group_range;
815 * Sane defaults - nobody may create ping sockets.
816 * Boot scripts should set this to distro-specific group.
818 net->ipv4.sysctl_ping_group_range[0] = 1;
819 net->ipv4.sysctl_ping_group_range[1] = 0;
821 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
823 tcp_init_mem(net);
825 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
826 net_ipv4_ctl_path, table);
827 if (net->ipv4.ipv4_hdr == NULL)
828 goto err_reg;
830 return 0;
832 err_reg:
833 if (!net_eq(net, &init_net))
834 kfree(table);
835 err_alloc:
836 return -ENOMEM;
839 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
841 struct ctl_table *table;
843 table = net->ipv4.ipv4_hdr->ctl_table_arg;
844 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
845 kfree(table);
848 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
849 .init = ipv4_sysctl_init_net,
850 .exit = ipv4_sysctl_exit_net,
853 static __init int sysctl_ipv4_init(void)
855 struct ctl_table_header *hdr;
856 struct ctl_table *i;
858 for (i = ipv4_table; i->procname; i++) {
859 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
860 i->data = sysctl_local_reserved_ports;
861 break;
864 if (!i->procname)
865 return -EINVAL;
867 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
868 if (hdr == NULL)
869 return -ENOMEM;
871 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
872 unregister_sysctl_table(hdr);
873 return -ENOMEM;
876 return 0;
879 __initcall(sysctl_ipv4_init);