arch/sh/mm: Eliminate a double lock
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / ipv4 / sysctl_net_ipv4.c
blobd96c1da4b17cf97790bb2a426abbe5eb4582356d
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 <net/snmp.h>
17 #include <net/icmp.h>
18 #include <net/ip.h>
19 #include <net/route.h>
20 #include <net/tcp.h>
21 #include <net/udp.h>
22 #include <net/cipso_ipv4.h>
23 #include <net/inet_frag.h>
25 static int zero;
26 static int tcp_retr1_max = 255;
27 static int ip_local_port_range_min[] = { 1, 1 };
28 static int ip_local_port_range_max[] = { 65535, 65535 };
30 /* Update system visible IP port range */
31 static void set_local_port_range(int range[2])
33 write_seqlock(&sysctl_local_ports.lock);
34 sysctl_local_ports.range[0] = range[0];
35 sysctl_local_ports.range[1] = range[1];
36 write_sequnlock(&sysctl_local_ports.lock);
39 /* Validate changes from /proc interface. */
40 static int ipv4_local_port_range(ctl_table *table, int write,
41 void __user *buffer,
42 size_t *lenp, loff_t *ppos)
44 int ret;
45 int range[2];
46 ctl_table tmp = {
47 .data = &range,
48 .maxlen = sizeof(range),
49 .mode = table->mode,
50 .extra1 = &ip_local_port_range_min,
51 .extra2 = &ip_local_port_range_max,
54 inet_get_local_port_range(range, range + 1);
55 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
57 if (write && ret == 0) {
58 if (range[1] < range[0])
59 ret = -EINVAL;
60 else
61 set_local_port_range(range);
64 return ret;
67 static int proc_tcp_congestion_control(ctl_table *ctl, int write,
68 void __user *buffer, size_t *lenp, loff_t *ppos)
70 char val[TCP_CA_NAME_MAX];
71 ctl_table tbl = {
72 .data = val,
73 .maxlen = TCP_CA_NAME_MAX,
75 int ret;
77 tcp_get_default_congestion_control(val);
79 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
80 if (write && ret == 0)
81 ret = tcp_set_default_congestion_control(val);
82 return ret;
85 static int proc_tcp_available_congestion_control(ctl_table *ctl,
86 int write,
87 void __user *buffer, size_t *lenp,
88 loff_t *ppos)
90 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
91 int ret;
93 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94 if (!tbl.data)
95 return -ENOMEM;
96 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
97 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
98 kfree(tbl.data);
99 return ret;
102 static int proc_allowed_congestion_control(ctl_table *ctl,
103 int write,
104 void __user *buffer, size_t *lenp,
105 loff_t *ppos)
107 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
108 int ret;
110 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
111 if (!tbl.data)
112 return -ENOMEM;
114 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
115 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
116 if (write && ret == 0)
117 ret = tcp_set_allowed_congestion_control(tbl.data);
118 kfree(tbl.data);
119 return ret;
122 static struct ctl_table ipv4_table[] = {
124 .procname = "tcp_timestamps",
125 .data = &sysctl_tcp_timestamps,
126 .maxlen = sizeof(int),
127 .mode = 0644,
128 .proc_handler = proc_dointvec
131 .procname = "tcp_window_scaling",
132 .data = &sysctl_tcp_window_scaling,
133 .maxlen = sizeof(int),
134 .mode = 0644,
135 .proc_handler = proc_dointvec
138 .procname = "tcp_sack",
139 .data = &sysctl_tcp_sack,
140 .maxlen = sizeof(int),
141 .mode = 0644,
142 .proc_handler = proc_dointvec
145 .procname = "tcp_retrans_collapse",
146 .data = &sysctl_tcp_retrans_collapse,
147 .maxlen = sizeof(int),
148 .mode = 0644,
149 .proc_handler = proc_dointvec
152 .procname = "ip_default_ttl",
153 .data = &sysctl_ip_default_ttl,
154 .maxlen = sizeof(int),
155 .mode = 0644,
156 .proc_handler = ipv4_doint_and_flush,
157 .extra2 = &init_net,
160 .procname = "ip_no_pmtu_disc",
161 .data = &ipv4_config.no_pmtu_disc,
162 .maxlen = sizeof(int),
163 .mode = 0644,
164 .proc_handler = proc_dointvec
167 .procname = "ip_nonlocal_bind",
168 .data = &sysctl_ip_nonlocal_bind,
169 .maxlen = sizeof(int),
170 .mode = 0644,
171 .proc_handler = proc_dointvec
174 .procname = "tcp_syn_retries",
175 .data = &sysctl_tcp_syn_retries,
176 .maxlen = sizeof(int),
177 .mode = 0644,
178 .proc_handler = proc_dointvec
181 .procname = "tcp_synack_retries",
182 .data = &sysctl_tcp_synack_retries,
183 .maxlen = sizeof(int),
184 .mode = 0644,
185 .proc_handler = proc_dointvec
188 .procname = "tcp_max_orphans",
189 .data = &sysctl_tcp_max_orphans,
190 .maxlen = sizeof(int),
191 .mode = 0644,
192 .proc_handler = proc_dointvec
195 .procname = "tcp_max_tw_buckets",
196 .data = &tcp_death_row.sysctl_max_tw_buckets,
197 .maxlen = sizeof(int),
198 .mode = 0644,
199 .proc_handler = proc_dointvec
202 .procname = "ip_dynaddr",
203 .data = &sysctl_ip_dynaddr,
204 .maxlen = sizeof(int),
205 .mode = 0644,
206 .proc_handler = proc_dointvec
209 .procname = "tcp_keepalive_time",
210 .data = &sysctl_tcp_keepalive_time,
211 .maxlen = sizeof(int),
212 .mode = 0644,
213 .proc_handler = proc_dointvec_jiffies,
216 .procname = "tcp_keepalive_probes",
217 .data = &sysctl_tcp_keepalive_probes,
218 .maxlen = sizeof(int),
219 .mode = 0644,
220 .proc_handler = proc_dointvec
223 .procname = "tcp_keepalive_intvl",
224 .data = &sysctl_tcp_keepalive_intvl,
225 .maxlen = sizeof(int),
226 .mode = 0644,
227 .proc_handler = proc_dointvec_jiffies,
230 .procname = "tcp_retries1",
231 .data = &sysctl_tcp_retries1,
232 .maxlen = sizeof(int),
233 .mode = 0644,
234 .proc_handler = proc_dointvec_minmax,
235 .extra2 = &tcp_retr1_max
238 .procname = "tcp_retries2",
239 .data = &sysctl_tcp_retries2,
240 .maxlen = sizeof(int),
241 .mode = 0644,
242 .proc_handler = proc_dointvec
245 .procname = "tcp_fin_timeout",
246 .data = &sysctl_tcp_fin_timeout,
247 .maxlen = sizeof(int),
248 .mode = 0644,
249 .proc_handler = proc_dointvec_jiffies,
251 #ifdef CONFIG_SYN_COOKIES
253 .procname = "tcp_syncookies",
254 .data = &sysctl_tcp_syncookies,
255 .maxlen = sizeof(int),
256 .mode = 0644,
257 .proc_handler = proc_dointvec
259 #endif
261 .procname = "tcp_tw_recycle",
262 .data = &tcp_death_row.sysctl_tw_recycle,
263 .maxlen = sizeof(int),
264 .mode = 0644,
265 .proc_handler = proc_dointvec
268 .procname = "tcp_abort_on_overflow",
269 .data = &sysctl_tcp_abort_on_overflow,
270 .maxlen = sizeof(int),
271 .mode = 0644,
272 .proc_handler = proc_dointvec
275 .procname = "tcp_stdurg",
276 .data = &sysctl_tcp_stdurg,
277 .maxlen = sizeof(int),
278 .mode = 0644,
279 .proc_handler = proc_dointvec
282 .procname = "tcp_rfc1337",
283 .data = &sysctl_tcp_rfc1337,
284 .maxlen = sizeof(int),
285 .mode = 0644,
286 .proc_handler = proc_dointvec
289 .procname = "tcp_max_syn_backlog",
290 .data = &sysctl_max_syn_backlog,
291 .maxlen = sizeof(int),
292 .mode = 0644,
293 .proc_handler = proc_dointvec
296 .procname = "ip_local_port_range",
297 .data = &sysctl_local_ports.range,
298 .maxlen = sizeof(sysctl_local_ports.range),
299 .mode = 0644,
300 .proc_handler = ipv4_local_port_range,
303 .procname = "ip_local_reserved_ports",
304 .data = NULL, /* initialized in sysctl_ipv4_init */
305 .maxlen = 65536,
306 .mode = 0644,
307 .proc_handler = proc_do_large_bitmap,
309 #ifdef CONFIG_IP_MULTICAST
311 .procname = "igmp_max_memberships",
312 .data = &sysctl_igmp_max_memberships,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = proc_dointvec
318 #endif
320 .procname = "igmp_max_msf",
321 .data = &sysctl_igmp_max_msf,
322 .maxlen = sizeof(int),
323 .mode = 0644,
324 .proc_handler = proc_dointvec
327 .procname = "inet_peer_threshold",
328 .data = &inet_peer_threshold,
329 .maxlen = sizeof(int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec
334 .procname = "inet_peer_minttl",
335 .data = &inet_peer_minttl,
336 .maxlen = sizeof(int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec_jiffies,
341 .procname = "inet_peer_maxttl",
342 .data = &inet_peer_maxttl,
343 .maxlen = sizeof(int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec_jiffies,
348 .procname = "inet_peer_gc_mintime",
349 .data = &inet_peer_gc_mintime,
350 .maxlen = sizeof(int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec_jiffies,
355 .procname = "inet_peer_gc_maxtime",
356 .data = &inet_peer_gc_maxtime,
357 .maxlen = sizeof(int),
358 .mode = 0644,
359 .proc_handler = proc_dointvec_jiffies,
362 .procname = "tcp_orphan_retries",
363 .data = &sysctl_tcp_orphan_retries,
364 .maxlen = sizeof(int),
365 .mode = 0644,
366 .proc_handler = proc_dointvec
369 .procname = "tcp_fack",
370 .data = &sysctl_tcp_fack,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = proc_dointvec
376 .procname = "tcp_reordering",
377 .data = &sysctl_tcp_reordering,
378 .maxlen = sizeof(int),
379 .mode = 0644,
380 .proc_handler = proc_dointvec
383 .procname = "tcp_ecn",
384 .data = &sysctl_tcp_ecn,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = proc_dointvec
390 .procname = "tcp_dsack",
391 .data = &sysctl_tcp_dsack,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = proc_dointvec
397 .procname = "tcp_mem",
398 .data = &sysctl_tcp_mem,
399 .maxlen = sizeof(sysctl_tcp_mem),
400 .mode = 0644,
401 .proc_handler = proc_dointvec
404 .procname = "tcp_wmem",
405 .data = &sysctl_tcp_wmem,
406 .maxlen = sizeof(sysctl_tcp_wmem),
407 .mode = 0644,
408 .proc_handler = proc_dointvec
411 .procname = "tcp_rmem",
412 .data = &sysctl_tcp_rmem,
413 .maxlen = sizeof(sysctl_tcp_rmem),
414 .mode = 0644,
415 .proc_handler = proc_dointvec
418 .procname = "tcp_app_win",
419 .data = &sysctl_tcp_app_win,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = proc_dointvec
425 .procname = "tcp_adv_win_scale",
426 .data = &sysctl_tcp_adv_win_scale,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = proc_dointvec
432 .procname = "tcp_tw_reuse",
433 .data = &sysctl_tcp_tw_reuse,
434 .maxlen = sizeof(int),
435 .mode = 0644,
436 .proc_handler = proc_dointvec
439 .procname = "tcp_frto",
440 .data = &sysctl_tcp_frto,
441 .maxlen = sizeof(int),
442 .mode = 0644,
443 .proc_handler = proc_dointvec
446 .procname = "tcp_frto_response",
447 .data = &sysctl_tcp_frto_response,
448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = proc_dointvec
453 .procname = "tcp_low_latency",
454 .data = &sysctl_tcp_low_latency,
455 .maxlen = sizeof(int),
456 .mode = 0644,
457 .proc_handler = proc_dointvec
460 .procname = "tcp_no_metrics_save",
461 .data = &sysctl_tcp_nometrics_save,
462 .maxlen = sizeof(int),
463 .mode = 0644,
464 .proc_handler = proc_dointvec,
467 .procname = "tcp_moderate_rcvbuf",
468 .data = &sysctl_tcp_moderate_rcvbuf,
469 .maxlen = sizeof(int),
470 .mode = 0644,
471 .proc_handler = proc_dointvec,
474 .procname = "tcp_tso_win_divisor",
475 .data = &sysctl_tcp_tso_win_divisor,
476 .maxlen = sizeof(int),
477 .mode = 0644,
478 .proc_handler = proc_dointvec,
481 .procname = "tcp_congestion_control",
482 .mode = 0644,
483 .maxlen = TCP_CA_NAME_MAX,
484 .proc_handler = proc_tcp_congestion_control,
487 .procname = "tcp_abc",
488 .data = &sysctl_tcp_abc,
489 .maxlen = sizeof(int),
490 .mode = 0644,
491 .proc_handler = proc_dointvec,
494 .procname = "tcp_mtu_probing",
495 .data = &sysctl_tcp_mtu_probing,
496 .maxlen = sizeof(int),
497 .mode = 0644,
498 .proc_handler = proc_dointvec,
501 .procname = "tcp_base_mss",
502 .data = &sysctl_tcp_base_mss,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = proc_dointvec,
508 .procname = "tcp_workaround_signed_windows",
509 .data = &sysctl_tcp_workaround_signed_windows,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = proc_dointvec
514 #ifdef CONFIG_NET_DMA
516 .procname = "tcp_dma_copybreak",
517 .data = &sysctl_tcp_dma_copybreak,
518 .maxlen = sizeof(int),
519 .mode = 0644,
520 .proc_handler = proc_dointvec
522 #endif
524 .procname = "tcp_slow_start_after_idle",
525 .data = &sysctl_tcp_slow_start_after_idle,
526 .maxlen = sizeof(int),
527 .mode = 0644,
528 .proc_handler = proc_dointvec
530 #ifdef CONFIG_NETLABEL
532 .procname = "cipso_cache_enable",
533 .data = &cipso_v4_cache_enabled,
534 .maxlen = sizeof(int),
535 .mode = 0644,
536 .proc_handler = proc_dointvec,
539 .procname = "cipso_cache_bucket_size",
540 .data = &cipso_v4_cache_bucketsize,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = proc_dointvec,
546 .procname = "cipso_rbm_optfmt",
547 .data = &cipso_v4_rbm_optfmt,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 .proc_handler = proc_dointvec,
553 .procname = "cipso_rbm_strictvalid",
554 .data = &cipso_v4_rbm_strictvalid,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 .proc_handler = proc_dointvec,
559 #endif /* CONFIG_NETLABEL */
561 .procname = "tcp_available_congestion_control",
562 .maxlen = TCP_CA_BUF_MAX,
563 .mode = 0444,
564 .proc_handler = proc_tcp_available_congestion_control,
567 .procname = "tcp_allowed_congestion_control",
568 .maxlen = TCP_CA_BUF_MAX,
569 .mode = 0644,
570 .proc_handler = proc_allowed_congestion_control,
573 .procname = "tcp_max_ssthresh",
574 .data = &sysctl_tcp_max_ssthresh,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = proc_dointvec,
580 .procname = "tcp_cookie_size",
581 .data = &sysctl_tcp_cookie_size,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = proc_dointvec
587 .procname = "tcp_thin_linear_timeouts",
588 .data = &sysctl_tcp_thin_linear_timeouts,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec
594 .procname = "tcp_thin_dupack",
595 .data = &sysctl_tcp_thin_dupack,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = proc_dointvec
601 .procname = "udp_mem",
602 .data = &sysctl_udp_mem,
603 .maxlen = sizeof(sysctl_udp_mem),
604 .mode = 0644,
605 .proc_handler = proc_dointvec_minmax,
606 .extra1 = &zero
609 .procname = "udp_rmem_min",
610 .data = &sysctl_udp_rmem_min,
611 .maxlen = sizeof(sysctl_udp_rmem_min),
612 .mode = 0644,
613 .proc_handler = proc_dointvec_minmax,
614 .extra1 = &zero
617 .procname = "udp_wmem_min",
618 .data = &sysctl_udp_wmem_min,
619 .maxlen = sizeof(sysctl_udp_wmem_min),
620 .mode = 0644,
621 .proc_handler = proc_dointvec_minmax,
622 .extra1 = &zero
627 static struct ctl_table ipv4_net_table[] = {
629 .procname = "icmp_echo_ignore_all",
630 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = proc_dointvec
636 .procname = "icmp_echo_ignore_broadcasts",
637 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 .proc_handler = proc_dointvec
643 .procname = "icmp_ignore_bogus_error_responses",
644 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = proc_dointvec
650 .procname = "icmp_errors_use_inbound_ifaddr",
651 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = proc_dointvec
657 .procname = "icmp_ratelimit",
658 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = proc_dointvec_ms_jiffies,
664 .procname = "icmp_ratemask",
665 .data = &init_net.ipv4.sysctl_icmp_ratemask,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = proc_dointvec
671 .procname = "rt_cache_rebuild_count",
672 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = proc_dointvec
680 struct ctl_path net_ipv4_ctl_path[] = {
681 { .procname = "net", },
682 { .procname = "ipv4", },
683 { },
685 EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
687 static __net_init int ipv4_sysctl_init_net(struct net *net)
689 struct ctl_table *table;
691 table = ipv4_net_table;
692 if (!net_eq(net, &init_net)) {
693 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
694 if (table == NULL)
695 goto err_alloc;
697 table[0].data =
698 &net->ipv4.sysctl_icmp_echo_ignore_all;
699 table[1].data =
700 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
701 table[2].data =
702 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
703 table[3].data =
704 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
705 table[4].data =
706 &net->ipv4.sysctl_icmp_ratelimit;
707 table[5].data =
708 &net->ipv4.sysctl_icmp_ratemask;
709 table[6].data =
710 &net->ipv4.sysctl_rt_cache_rebuild_count;
713 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
715 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
716 net_ipv4_ctl_path, table);
717 if (net->ipv4.ipv4_hdr == NULL)
718 goto err_reg;
720 return 0;
722 err_reg:
723 if (!net_eq(net, &init_net))
724 kfree(table);
725 err_alloc:
726 return -ENOMEM;
729 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
731 struct ctl_table *table;
733 table = net->ipv4.ipv4_hdr->ctl_table_arg;
734 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
735 kfree(table);
738 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
739 .init = ipv4_sysctl_init_net,
740 .exit = ipv4_sysctl_exit_net,
743 static __init int sysctl_ipv4_init(void)
745 struct ctl_table_header *hdr;
746 struct ctl_table *i;
748 for (i = ipv4_table; i->procname; i++) {
749 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
750 i->data = sysctl_local_reserved_ports;
751 break;
754 if (!i->procname)
755 return -EINVAL;
757 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
758 if (hdr == NULL)
759 return -ENOMEM;
761 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
762 unregister_sysctl_table(hdr);
763 return -ENOMEM;
766 return 0;
769 __initcall(sysctl_ipv4_init);