scripts/namespace.pl: improve to get more correct results
[linux-2.6.git] / net / ipv4 / sysctl_net_ipv4.c
blob7e3712ce399476be6cfdbc631654a5863fb68bc4
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 <net/snmp.h>
16 #include <net/icmp.h>
17 #include <net/ip.h>
18 #include <net/route.h>
19 #include <net/tcp.h>
20 #include <net/udp.h>
21 #include <net/cipso_ipv4.h>
22 #include <net/inet_frag.h>
24 static int zero;
25 static int tcp_retr1_max = 255;
26 static int ip_local_port_range_min[] = { 1, 1 };
27 static int ip_local_port_range_max[] = { 65535, 65535 };
29 /* Update system visible IP port range */
30 static void set_local_port_range(int range[2])
32 write_seqlock(&sysctl_local_ports.lock);
33 sysctl_local_ports.range[0] = range[0];
34 sysctl_local_ports.range[1] = range[1];
35 write_sequnlock(&sysctl_local_ports.lock);
38 /* Validate changes from /proc interface. */
39 static int ipv4_local_port_range(ctl_table *table, int write,
40 void __user *buffer,
41 size_t *lenp, loff_t *ppos)
43 int ret;
44 int range[2];
45 ctl_table tmp = {
46 .data = &range,
47 .maxlen = sizeof(range),
48 .mode = table->mode,
49 .extra1 = &ip_local_port_range_min,
50 .extra2 = &ip_local_port_range_max,
53 inet_get_local_port_range(range, range + 1);
54 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
56 if (write && ret == 0) {
57 if (range[1] < range[0])
58 ret = -EINVAL;
59 else
60 set_local_port_range(range);
63 return ret;
66 static int proc_tcp_congestion_control(ctl_table *ctl, int write,
67 void __user *buffer, size_t *lenp, loff_t *ppos)
69 char val[TCP_CA_NAME_MAX];
70 ctl_table tbl = {
71 .data = val,
72 .maxlen = TCP_CA_NAME_MAX,
74 int ret;
76 tcp_get_default_congestion_control(val);
78 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
79 if (write && ret == 0)
80 ret = tcp_set_default_congestion_control(val);
81 return ret;
84 static int proc_tcp_available_congestion_control(ctl_table *ctl,
85 int write,
86 void __user *buffer, size_t *lenp,
87 loff_t *ppos)
89 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
90 int ret;
92 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
93 if (!tbl.data)
94 return -ENOMEM;
95 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
96 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
97 kfree(tbl.data);
98 return ret;
101 static int proc_allowed_congestion_control(ctl_table *ctl,
102 int write,
103 void __user *buffer, size_t *lenp,
104 loff_t *ppos)
106 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
107 int ret;
109 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
110 if (!tbl.data)
111 return -ENOMEM;
113 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
114 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
115 if (write && ret == 0)
116 ret = tcp_set_allowed_congestion_control(tbl.data);
117 kfree(tbl.data);
118 return ret;
121 static struct ctl_table ipv4_table[] = {
123 .procname = "tcp_timestamps",
124 .data = &sysctl_tcp_timestamps,
125 .maxlen = sizeof(int),
126 .mode = 0644,
127 .proc_handler = proc_dointvec
130 .procname = "tcp_window_scaling",
131 .data = &sysctl_tcp_window_scaling,
132 .maxlen = sizeof(int),
133 .mode = 0644,
134 .proc_handler = proc_dointvec
137 .procname = "tcp_sack",
138 .data = &sysctl_tcp_sack,
139 .maxlen = sizeof(int),
140 .mode = 0644,
141 .proc_handler = proc_dointvec
144 .procname = "tcp_retrans_collapse",
145 .data = &sysctl_tcp_retrans_collapse,
146 .maxlen = sizeof(int),
147 .mode = 0644,
148 .proc_handler = proc_dointvec
151 .procname = "ip_default_ttl",
152 .data = &sysctl_ip_default_ttl,
153 .maxlen = sizeof(int),
154 .mode = 0644,
155 .proc_handler = ipv4_doint_and_flush,
156 .extra2 = &init_net,
159 .procname = "ip_no_pmtu_disc",
160 .data = &ipv4_config.no_pmtu_disc,
161 .maxlen = sizeof(int),
162 .mode = 0644,
163 .proc_handler = proc_dointvec
166 .procname = "ip_nonlocal_bind",
167 .data = &sysctl_ip_nonlocal_bind,
168 .maxlen = sizeof(int),
169 .mode = 0644,
170 .proc_handler = proc_dointvec
173 .procname = "tcp_syn_retries",
174 .data = &sysctl_tcp_syn_retries,
175 .maxlen = sizeof(int),
176 .mode = 0644,
177 .proc_handler = proc_dointvec
180 .procname = "tcp_synack_retries",
181 .data = &sysctl_tcp_synack_retries,
182 .maxlen = sizeof(int),
183 .mode = 0644,
184 .proc_handler = proc_dointvec
187 .procname = "tcp_max_orphans",
188 .data = &sysctl_tcp_max_orphans,
189 .maxlen = sizeof(int),
190 .mode = 0644,
191 .proc_handler = proc_dointvec
194 .procname = "tcp_max_tw_buckets",
195 .data = &tcp_death_row.sysctl_max_tw_buckets,
196 .maxlen = sizeof(int),
197 .mode = 0644,
198 .proc_handler = proc_dointvec
201 .procname = "ip_dynaddr",
202 .data = &sysctl_ip_dynaddr,
203 .maxlen = sizeof(int),
204 .mode = 0644,
205 .proc_handler = proc_dointvec
208 .procname = "tcp_keepalive_time",
209 .data = &sysctl_tcp_keepalive_time,
210 .maxlen = sizeof(int),
211 .mode = 0644,
212 .proc_handler = proc_dointvec_jiffies,
215 .procname = "tcp_keepalive_probes",
216 .data = &sysctl_tcp_keepalive_probes,
217 .maxlen = sizeof(int),
218 .mode = 0644,
219 .proc_handler = proc_dointvec
222 .procname = "tcp_keepalive_intvl",
223 .data = &sysctl_tcp_keepalive_intvl,
224 .maxlen = sizeof(int),
225 .mode = 0644,
226 .proc_handler = proc_dointvec_jiffies,
229 .procname = "tcp_retries1",
230 .data = &sysctl_tcp_retries1,
231 .maxlen = sizeof(int),
232 .mode = 0644,
233 .proc_handler = proc_dointvec_minmax,
234 .extra2 = &tcp_retr1_max
237 .procname = "tcp_retries2",
238 .data = &sysctl_tcp_retries2,
239 .maxlen = sizeof(int),
240 .mode = 0644,
241 .proc_handler = proc_dointvec
244 .procname = "tcp_fin_timeout",
245 .data = &sysctl_tcp_fin_timeout,
246 .maxlen = sizeof(int),
247 .mode = 0644,
248 .proc_handler = proc_dointvec_jiffies,
250 #ifdef CONFIG_SYN_COOKIES
252 .procname = "tcp_syncookies",
253 .data = &sysctl_tcp_syncookies,
254 .maxlen = sizeof(int),
255 .mode = 0644,
256 .proc_handler = proc_dointvec
258 #endif
260 .procname = "tcp_tw_recycle",
261 .data = &tcp_death_row.sysctl_tw_recycle,
262 .maxlen = sizeof(int),
263 .mode = 0644,
264 .proc_handler = proc_dointvec
267 .procname = "tcp_abort_on_overflow",
268 .data = &sysctl_tcp_abort_on_overflow,
269 .maxlen = sizeof(int),
270 .mode = 0644,
271 .proc_handler = proc_dointvec
274 .procname = "tcp_stdurg",
275 .data = &sysctl_tcp_stdurg,
276 .maxlen = sizeof(int),
277 .mode = 0644,
278 .proc_handler = proc_dointvec
281 .procname = "tcp_rfc1337",
282 .data = &sysctl_tcp_rfc1337,
283 .maxlen = sizeof(int),
284 .mode = 0644,
285 .proc_handler = proc_dointvec
288 .procname = "tcp_max_syn_backlog",
289 .data = &sysctl_max_syn_backlog,
290 .maxlen = sizeof(int),
291 .mode = 0644,
292 .proc_handler = proc_dointvec
295 .procname = "ip_local_port_range",
296 .data = &sysctl_local_ports.range,
297 .maxlen = sizeof(sysctl_local_ports.range),
298 .mode = 0644,
299 .proc_handler = ipv4_local_port_range,
301 #ifdef CONFIG_IP_MULTICAST
303 .procname = "igmp_max_memberships",
304 .data = &sysctl_igmp_max_memberships,
305 .maxlen = sizeof(int),
306 .mode = 0644,
307 .proc_handler = proc_dointvec
310 #endif
312 .procname = "igmp_max_msf",
313 .data = &sysctl_igmp_max_msf,
314 .maxlen = sizeof(int),
315 .mode = 0644,
316 .proc_handler = proc_dointvec
319 .procname = "inet_peer_threshold",
320 .data = &inet_peer_threshold,
321 .maxlen = sizeof(int),
322 .mode = 0644,
323 .proc_handler = proc_dointvec
326 .procname = "inet_peer_minttl",
327 .data = &inet_peer_minttl,
328 .maxlen = sizeof(int),
329 .mode = 0644,
330 .proc_handler = proc_dointvec_jiffies,
333 .procname = "inet_peer_maxttl",
334 .data = &inet_peer_maxttl,
335 .maxlen = sizeof(int),
336 .mode = 0644,
337 .proc_handler = proc_dointvec_jiffies,
340 .procname = "inet_peer_gc_mintime",
341 .data = &inet_peer_gc_mintime,
342 .maxlen = sizeof(int),
343 .mode = 0644,
344 .proc_handler = proc_dointvec_jiffies,
347 .procname = "inet_peer_gc_maxtime",
348 .data = &inet_peer_gc_maxtime,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = proc_dointvec_jiffies,
354 .procname = "tcp_orphan_retries",
355 .data = &sysctl_tcp_orphan_retries,
356 .maxlen = sizeof(int),
357 .mode = 0644,
358 .proc_handler = proc_dointvec
361 .procname = "tcp_fack",
362 .data = &sysctl_tcp_fack,
363 .maxlen = sizeof(int),
364 .mode = 0644,
365 .proc_handler = proc_dointvec
368 .procname = "tcp_reordering",
369 .data = &sysctl_tcp_reordering,
370 .maxlen = sizeof(int),
371 .mode = 0644,
372 .proc_handler = proc_dointvec
375 .procname = "tcp_ecn",
376 .data = &sysctl_tcp_ecn,
377 .maxlen = sizeof(int),
378 .mode = 0644,
379 .proc_handler = proc_dointvec
382 .procname = "tcp_dsack",
383 .data = &sysctl_tcp_dsack,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = proc_dointvec
389 .procname = "tcp_mem",
390 .data = &sysctl_tcp_mem,
391 .maxlen = sizeof(sysctl_tcp_mem),
392 .mode = 0644,
393 .proc_handler = proc_dointvec
396 .procname = "tcp_wmem",
397 .data = &sysctl_tcp_wmem,
398 .maxlen = sizeof(sysctl_tcp_wmem),
399 .mode = 0644,
400 .proc_handler = proc_dointvec
403 .procname = "tcp_rmem",
404 .data = &sysctl_tcp_rmem,
405 .maxlen = sizeof(sysctl_tcp_rmem),
406 .mode = 0644,
407 .proc_handler = proc_dointvec
410 .procname = "tcp_app_win",
411 .data = &sysctl_tcp_app_win,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = proc_dointvec
417 .procname = "tcp_adv_win_scale",
418 .data = &sysctl_tcp_adv_win_scale,
419 .maxlen = sizeof(int),
420 .mode = 0644,
421 .proc_handler = proc_dointvec
424 .procname = "tcp_tw_reuse",
425 .data = &sysctl_tcp_tw_reuse,
426 .maxlen = sizeof(int),
427 .mode = 0644,
428 .proc_handler = proc_dointvec
431 .procname = "tcp_frto",
432 .data = &sysctl_tcp_frto,
433 .maxlen = sizeof(int),
434 .mode = 0644,
435 .proc_handler = proc_dointvec
438 .procname = "tcp_frto_response",
439 .data = &sysctl_tcp_frto_response,
440 .maxlen = sizeof(int),
441 .mode = 0644,
442 .proc_handler = proc_dointvec
445 .procname = "tcp_low_latency",
446 .data = &sysctl_tcp_low_latency,
447 .maxlen = sizeof(int),
448 .mode = 0644,
449 .proc_handler = proc_dointvec
452 .procname = "tcp_no_metrics_save",
453 .data = &sysctl_tcp_nometrics_save,
454 .maxlen = sizeof(int),
455 .mode = 0644,
456 .proc_handler = proc_dointvec,
459 .procname = "tcp_moderate_rcvbuf",
460 .data = &sysctl_tcp_moderate_rcvbuf,
461 .maxlen = sizeof(int),
462 .mode = 0644,
463 .proc_handler = proc_dointvec,
466 .procname = "tcp_tso_win_divisor",
467 .data = &sysctl_tcp_tso_win_divisor,
468 .maxlen = sizeof(int),
469 .mode = 0644,
470 .proc_handler = proc_dointvec,
473 .procname = "tcp_congestion_control",
474 .mode = 0644,
475 .maxlen = TCP_CA_NAME_MAX,
476 .proc_handler = proc_tcp_congestion_control,
479 .procname = "tcp_abc",
480 .data = &sysctl_tcp_abc,
481 .maxlen = sizeof(int),
482 .mode = 0644,
483 .proc_handler = proc_dointvec,
486 .procname = "tcp_mtu_probing",
487 .data = &sysctl_tcp_mtu_probing,
488 .maxlen = sizeof(int),
489 .mode = 0644,
490 .proc_handler = proc_dointvec,
493 .procname = "tcp_base_mss",
494 .data = &sysctl_tcp_base_mss,
495 .maxlen = sizeof(int),
496 .mode = 0644,
497 .proc_handler = proc_dointvec,
500 .procname = "tcp_workaround_signed_windows",
501 .data = &sysctl_tcp_workaround_signed_windows,
502 .maxlen = sizeof(int),
503 .mode = 0644,
504 .proc_handler = proc_dointvec
506 #ifdef CONFIG_NET_DMA
508 .procname = "tcp_dma_copybreak",
509 .data = &sysctl_tcp_dma_copybreak,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = proc_dointvec
514 #endif
516 .procname = "tcp_slow_start_after_idle",
517 .data = &sysctl_tcp_slow_start_after_idle,
518 .maxlen = sizeof(int),
519 .mode = 0644,
520 .proc_handler = proc_dointvec
522 #ifdef CONFIG_NETLABEL
524 .procname = "cipso_cache_enable",
525 .data = &cipso_v4_cache_enabled,
526 .maxlen = sizeof(int),
527 .mode = 0644,
528 .proc_handler = proc_dointvec,
531 .procname = "cipso_cache_bucket_size",
532 .data = &cipso_v4_cache_bucketsize,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = proc_dointvec,
538 .procname = "cipso_rbm_optfmt",
539 .data = &cipso_v4_rbm_optfmt,
540 .maxlen = sizeof(int),
541 .mode = 0644,
542 .proc_handler = proc_dointvec,
545 .procname = "cipso_rbm_strictvalid",
546 .data = &cipso_v4_rbm_strictvalid,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = proc_dointvec,
551 #endif /* CONFIG_NETLABEL */
553 .procname = "tcp_available_congestion_control",
554 .maxlen = TCP_CA_BUF_MAX,
555 .mode = 0444,
556 .proc_handler = proc_tcp_available_congestion_control,
559 .procname = "tcp_allowed_congestion_control",
560 .maxlen = TCP_CA_BUF_MAX,
561 .mode = 0644,
562 .proc_handler = proc_allowed_congestion_control,
565 .procname = "tcp_max_ssthresh",
566 .data = &sysctl_tcp_max_ssthresh,
567 .maxlen = sizeof(int),
568 .mode = 0644,
569 .proc_handler = proc_dointvec,
572 .procname = "tcp_cookie_size",
573 .data = &sysctl_tcp_cookie_size,
574 .maxlen = sizeof(int),
575 .mode = 0644,
576 .proc_handler = proc_dointvec
579 .procname = "udp_mem",
580 .data = &sysctl_udp_mem,
581 .maxlen = sizeof(sysctl_udp_mem),
582 .mode = 0644,
583 .proc_handler = proc_dointvec_minmax,
584 .extra1 = &zero
587 .procname = "udp_rmem_min",
588 .data = &sysctl_udp_rmem_min,
589 .maxlen = sizeof(sysctl_udp_rmem_min),
590 .mode = 0644,
591 .proc_handler = proc_dointvec_minmax,
592 .extra1 = &zero
595 .procname = "udp_wmem_min",
596 .data = &sysctl_udp_wmem_min,
597 .maxlen = sizeof(sysctl_udp_wmem_min),
598 .mode = 0644,
599 .proc_handler = proc_dointvec_minmax,
600 .extra1 = &zero
605 static struct ctl_table ipv4_net_table[] = {
607 .procname = "icmp_echo_ignore_all",
608 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = proc_dointvec
614 .procname = "icmp_echo_ignore_broadcasts",
615 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = proc_dointvec
621 .procname = "icmp_ignore_bogus_error_responses",
622 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
623 .maxlen = sizeof(int),
624 .mode = 0644,
625 .proc_handler = proc_dointvec
628 .procname = "icmp_errors_use_inbound_ifaddr",
629 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = proc_dointvec
635 .procname = "icmp_ratelimit",
636 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
637 .maxlen = sizeof(int),
638 .mode = 0644,
639 .proc_handler = proc_dointvec_ms_jiffies,
642 .procname = "icmp_ratemask",
643 .data = &init_net.ipv4.sysctl_icmp_ratemask,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 .proc_handler = proc_dointvec
649 .procname = "rt_cache_rebuild_count",
650 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = proc_dointvec
658 struct ctl_path net_ipv4_ctl_path[] = {
659 { .procname = "net", },
660 { .procname = "ipv4", },
661 { },
663 EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
665 static __net_init int ipv4_sysctl_init_net(struct net *net)
667 struct ctl_table *table;
669 table = ipv4_net_table;
670 if (!net_eq(net, &init_net)) {
671 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
672 if (table == NULL)
673 goto err_alloc;
675 table[0].data =
676 &net->ipv4.sysctl_icmp_echo_ignore_all;
677 table[1].data =
678 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
679 table[2].data =
680 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
681 table[3].data =
682 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
683 table[4].data =
684 &net->ipv4.sysctl_icmp_ratelimit;
685 table[5].data =
686 &net->ipv4.sysctl_icmp_ratemask;
687 table[6].data =
688 &net->ipv4.sysctl_rt_cache_rebuild_count;
691 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
693 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
694 net_ipv4_ctl_path, table);
695 if (net->ipv4.ipv4_hdr == NULL)
696 goto err_reg;
698 return 0;
700 err_reg:
701 if (!net_eq(net, &init_net))
702 kfree(table);
703 err_alloc:
704 return -ENOMEM;
707 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
709 struct ctl_table *table;
711 table = net->ipv4.ipv4_hdr->ctl_table_arg;
712 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
713 kfree(table);
716 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
717 .init = ipv4_sysctl_init_net,
718 .exit = ipv4_sysctl_exit_net,
721 static __init int sysctl_ipv4_init(void)
723 struct ctl_table_header *hdr;
725 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
726 if (hdr == NULL)
727 return -ENOMEM;
729 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
730 unregister_sysctl_table(hdr);
731 return -ENOMEM;
734 return 0;
737 __initcall(sysctl_ipv4_init);