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]
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>
20 #include <net/route.h>
23 #include <net/cipso_ipv4.h>
24 #include <net/inet_frag.h>
28 static int tcp_retr1_max
= 255;
29 static int ip_local_port_range_min
[] = { 1, 1 };
30 static int ip_local_port_range_max
[] = { 65535, 65535 };
31 static int tcp_adv_win_scale_min
= -31;
32 static int tcp_adv_win_scale_max
= 31;
33 static int ip_ttl_min
= 1;
34 static int ip_ttl_max
= 255;
35 static int ip_ping_group_range_min
[] = { 0, 0 };
36 static int ip_ping_group_range_max
[] = { GID_T_MAX
, GID_T_MAX
};
38 /* Update system visible IP port range */
39 static void set_local_port_range(int range
[2])
41 write_seqlock(&sysctl_local_ports
.lock
);
42 sysctl_local_ports
.range
[0] = range
[0];
43 sysctl_local_ports
.range
[1] = range
[1];
44 write_sequnlock(&sysctl_local_ports
.lock
);
47 /* Validate changes from /proc interface. */
48 static int ipv4_local_port_range(ctl_table
*table
, int write
,
50 size_t *lenp
, loff_t
*ppos
)
56 .maxlen
= sizeof(range
),
58 .extra1
= &ip_local_port_range_min
,
59 .extra2
= &ip_local_port_range_max
,
62 inet_get_local_port_range(range
, range
+ 1);
63 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
65 if (write
&& ret
== 0) {
66 if (range
[1] < range
[0])
69 set_local_port_range(range
);
76 void inet_get_ping_group_range_table(struct ctl_table
*table
, gid_t
*low
, gid_t
*high
)
78 gid_t
*data
= table
->data
;
81 seq
= read_seqbegin(&sysctl_local_ports
.lock
);
85 } while (read_seqretry(&sysctl_local_ports
.lock
, seq
));
88 /* Update system visible IP port range */
89 static void set_ping_group_range(struct ctl_table
*table
, int range
[2])
91 gid_t
*data
= table
->data
;
92 write_seqlock(&sysctl_local_ports
.lock
);
95 write_sequnlock(&sysctl_local_ports
.lock
);
98 /* Validate changes from /proc interface. */
99 static int ipv4_ping_group_range(ctl_table
*table
, int write
,
101 size_t *lenp
, loff_t
*ppos
)
107 .maxlen
= sizeof(range
),
109 .extra1
= &ip_ping_group_range_min
,
110 .extra2
= &ip_ping_group_range_max
,
113 inet_get_ping_group_range_table(table
, range
, range
+ 1);
114 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
116 if (write
&& ret
== 0)
117 set_ping_group_range(table
, range
);
122 static int proc_tcp_congestion_control(ctl_table
*ctl
, int write
,
123 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
125 char val
[TCP_CA_NAME_MAX
];
128 .maxlen
= TCP_CA_NAME_MAX
,
132 tcp_get_default_congestion_control(val
);
134 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
135 if (write
&& ret
== 0)
136 ret
= tcp_set_default_congestion_control(val
);
140 static int proc_tcp_available_congestion_control(ctl_table
*ctl
,
142 void __user
*buffer
, size_t *lenp
,
145 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
, };
148 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
151 tcp_get_available_congestion_control(tbl
.data
, TCP_CA_BUF_MAX
);
152 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
157 static int proc_allowed_congestion_control(ctl_table
*ctl
,
159 void __user
*buffer
, size_t *lenp
,
162 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
};
165 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
169 tcp_get_allowed_congestion_control(tbl
.data
, tbl
.maxlen
);
170 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
171 if (write
&& ret
== 0)
172 ret
= tcp_set_allowed_congestion_control(tbl
.data
);
177 static struct ctl_table ipv4_table
[] = {
179 .procname
= "tcp_timestamps",
180 .data
= &sysctl_tcp_timestamps
,
181 .maxlen
= sizeof(int),
183 .proc_handler
= proc_dointvec
186 .procname
= "tcp_window_scaling",
187 .data
= &sysctl_tcp_window_scaling
,
188 .maxlen
= sizeof(int),
190 .proc_handler
= proc_dointvec
193 .procname
= "tcp_sack",
194 .data
= &sysctl_tcp_sack
,
195 .maxlen
= sizeof(int),
197 .proc_handler
= proc_dointvec
200 .procname
= "tcp_retrans_collapse",
201 .data
= &sysctl_tcp_retrans_collapse
,
202 .maxlen
= sizeof(int),
204 .proc_handler
= proc_dointvec
207 .procname
= "ip_default_ttl",
208 .data
= &sysctl_ip_default_ttl
,
209 .maxlen
= sizeof(int),
211 .proc_handler
= proc_dointvec_minmax
,
212 .extra1
= &ip_ttl_min
,
213 .extra2
= &ip_ttl_max
,
216 .procname
= "ip_no_pmtu_disc",
217 .data
= &ipv4_config
.no_pmtu_disc
,
218 .maxlen
= sizeof(int),
220 .proc_handler
= proc_dointvec
223 .procname
= "ip_nonlocal_bind",
224 .data
= &sysctl_ip_nonlocal_bind
,
225 .maxlen
= sizeof(int),
227 .proc_handler
= proc_dointvec
230 .procname
= "tcp_syn_retries",
231 .data
= &sysctl_tcp_syn_retries
,
232 .maxlen
= sizeof(int),
234 .proc_handler
= proc_dointvec
237 .procname
= "tcp_synack_retries",
238 .data
= &sysctl_tcp_synack_retries
,
239 .maxlen
= sizeof(int),
241 .proc_handler
= proc_dointvec
244 .procname
= "tcp_max_orphans",
245 .data
= &sysctl_tcp_max_orphans
,
246 .maxlen
= sizeof(int),
248 .proc_handler
= proc_dointvec
251 .procname
= "tcp_max_tw_buckets",
252 .data
= &tcp_death_row
.sysctl_max_tw_buckets
,
253 .maxlen
= sizeof(int),
255 .proc_handler
= proc_dointvec
258 .procname
= "ip_dynaddr",
259 .data
= &sysctl_ip_dynaddr
,
260 .maxlen
= sizeof(int),
262 .proc_handler
= proc_dointvec
265 .procname
= "tcp_keepalive_time",
266 .data
= &sysctl_tcp_keepalive_time
,
267 .maxlen
= sizeof(int),
269 .proc_handler
= proc_dointvec_jiffies
,
272 .procname
= "tcp_keepalive_probes",
273 .data
= &sysctl_tcp_keepalive_probes
,
274 .maxlen
= sizeof(int),
276 .proc_handler
= proc_dointvec
279 .procname
= "tcp_keepalive_intvl",
280 .data
= &sysctl_tcp_keepalive_intvl
,
281 .maxlen
= sizeof(int),
283 .proc_handler
= proc_dointvec_jiffies
,
286 .procname
= "tcp_retries1",
287 .data
= &sysctl_tcp_retries1
,
288 .maxlen
= sizeof(int),
290 .proc_handler
= proc_dointvec_minmax
,
291 .extra2
= &tcp_retr1_max
294 .procname
= "tcp_retries2",
295 .data
= &sysctl_tcp_retries2
,
296 .maxlen
= sizeof(int),
298 .proc_handler
= proc_dointvec
301 .procname
= "tcp_fin_timeout",
302 .data
= &sysctl_tcp_fin_timeout
,
303 .maxlen
= sizeof(int),
305 .proc_handler
= proc_dointvec_jiffies
,
307 #ifdef CONFIG_SYN_COOKIES
309 .procname
= "tcp_syncookies",
310 .data
= &sysctl_tcp_syncookies
,
311 .maxlen
= sizeof(int),
313 .proc_handler
= proc_dointvec
317 .procname
= "tcp_tw_recycle",
318 .data
= &tcp_death_row
.sysctl_tw_recycle
,
319 .maxlen
= sizeof(int),
321 .proc_handler
= proc_dointvec
324 .procname
= "tcp_abort_on_overflow",
325 .data
= &sysctl_tcp_abort_on_overflow
,
326 .maxlen
= sizeof(int),
328 .proc_handler
= proc_dointvec
331 .procname
= "tcp_stdurg",
332 .data
= &sysctl_tcp_stdurg
,
333 .maxlen
= sizeof(int),
335 .proc_handler
= proc_dointvec
338 .procname
= "tcp_rfc1337",
339 .data
= &sysctl_tcp_rfc1337
,
340 .maxlen
= sizeof(int),
342 .proc_handler
= proc_dointvec
345 .procname
= "tcp_max_syn_backlog",
346 .data
= &sysctl_max_syn_backlog
,
347 .maxlen
= sizeof(int),
349 .proc_handler
= proc_dointvec
352 .procname
= "ip_local_port_range",
353 .data
= &sysctl_local_ports
.range
,
354 .maxlen
= sizeof(sysctl_local_ports
.range
),
356 .proc_handler
= ipv4_local_port_range
,
359 .procname
= "ip_local_reserved_ports",
360 .data
= NULL
, /* initialized in sysctl_ipv4_init */
363 .proc_handler
= proc_do_large_bitmap
,
366 .procname
= "igmp_max_memberships",
367 .data
= &sysctl_igmp_max_memberships
,
368 .maxlen
= sizeof(int),
370 .proc_handler
= proc_dointvec
373 .procname
= "igmp_max_msf",
374 .data
= &sysctl_igmp_max_msf
,
375 .maxlen
= sizeof(int),
377 .proc_handler
= proc_dointvec
380 .procname
= "inet_peer_threshold",
381 .data
= &inet_peer_threshold
,
382 .maxlen
= sizeof(int),
384 .proc_handler
= proc_dointvec
387 .procname
= "inet_peer_minttl",
388 .data
= &inet_peer_minttl
,
389 .maxlen
= sizeof(int),
391 .proc_handler
= proc_dointvec_jiffies
,
394 .procname
= "inet_peer_maxttl",
395 .data
= &inet_peer_maxttl
,
396 .maxlen
= sizeof(int),
398 .proc_handler
= proc_dointvec_jiffies
,
401 .procname
= "inet_peer_gc_mintime",
402 .data
= &inet_peer_gc_mintime
,
403 .maxlen
= sizeof(int),
405 .proc_handler
= proc_dointvec_jiffies
,
408 .procname
= "inet_peer_gc_maxtime",
409 .data
= &inet_peer_gc_maxtime
,
410 .maxlen
= sizeof(int),
412 .proc_handler
= proc_dointvec_jiffies
,
415 .procname
= "tcp_orphan_retries",
416 .data
= &sysctl_tcp_orphan_retries
,
417 .maxlen
= sizeof(int),
419 .proc_handler
= proc_dointvec
422 .procname
= "tcp_fack",
423 .data
= &sysctl_tcp_fack
,
424 .maxlen
= sizeof(int),
426 .proc_handler
= proc_dointvec
429 .procname
= "tcp_reordering",
430 .data
= &sysctl_tcp_reordering
,
431 .maxlen
= sizeof(int),
433 .proc_handler
= proc_dointvec
436 .procname
= "tcp_ecn",
437 .data
= &sysctl_tcp_ecn
,
438 .maxlen
= sizeof(int),
440 .proc_handler
= proc_dointvec
443 .procname
= "tcp_dsack",
444 .data
= &sysctl_tcp_dsack
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= proc_dointvec
450 .procname
= "tcp_mem",
451 .data
= &sysctl_tcp_mem
,
452 .maxlen
= sizeof(sysctl_tcp_mem
),
454 .proc_handler
= proc_doulongvec_minmax
457 .procname
= "tcp_wmem",
458 .data
= &sysctl_tcp_wmem
,
459 .maxlen
= sizeof(sysctl_tcp_wmem
),
461 .proc_handler
= proc_dointvec
464 .procname
= "tcp_rmem",
465 .data
= &sysctl_tcp_rmem
,
466 .maxlen
= sizeof(sysctl_tcp_rmem
),
468 .proc_handler
= proc_dointvec
471 .procname
= "tcp_app_win",
472 .data
= &sysctl_tcp_app_win
,
473 .maxlen
= sizeof(int),
475 .proc_handler
= proc_dointvec
478 .procname
= "tcp_adv_win_scale",
479 .data
= &sysctl_tcp_adv_win_scale
,
480 .maxlen
= sizeof(int),
482 .proc_handler
= proc_dointvec_minmax
,
483 .extra1
= &tcp_adv_win_scale_min
,
484 .extra2
= &tcp_adv_win_scale_max
,
487 .procname
= "tcp_tw_reuse",
488 .data
= &sysctl_tcp_tw_reuse
,
489 .maxlen
= sizeof(int),
491 .proc_handler
= proc_dointvec
494 .procname
= "tcp_frto",
495 .data
= &sysctl_tcp_frto
,
496 .maxlen
= sizeof(int),
498 .proc_handler
= proc_dointvec
501 .procname
= "tcp_frto_response",
502 .data
= &sysctl_tcp_frto_response
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= proc_dointvec
508 .procname
= "tcp_low_latency",
509 .data
= &sysctl_tcp_low_latency
,
510 .maxlen
= sizeof(int),
512 .proc_handler
= proc_dointvec
515 .procname
= "tcp_no_metrics_save",
516 .data
= &sysctl_tcp_nometrics_save
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= proc_dointvec
,
522 .procname
= "tcp_moderate_rcvbuf",
523 .data
= &sysctl_tcp_moderate_rcvbuf
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= proc_dointvec
,
529 .procname
= "tcp_tso_win_divisor",
530 .data
= &sysctl_tcp_tso_win_divisor
,
531 .maxlen
= sizeof(int),
533 .proc_handler
= proc_dointvec
,
536 .procname
= "tcp_congestion_control",
538 .maxlen
= TCP_CA_NAME_MAX
,
539 .proc_handler
= proc_tcp_congestion_control
,
542 .procname
= "tcp_abc",
543 .data
= &sysctl_tcp_abc
,
544 .maxlen
= sizeof(int),
546 .proc_handler
= proc_dointvec
,
549 .procname
= "tcp_mtu_probing",
550 .data
= &sysctl_tcp_mtu_probing
,
551 .maxlen
= sizeof(int),
553 .proc_handler
= proc_dointvec
,
556 .procname
= "tcp_base_mss",
557 .data
= &sysctl_tcp_base_mss
,
558 .maxlen
= sizeof(int),
560 .proc_handler
= proc_dointvec
,
563 .procname
= "tcp_workaround_signed_windows",
564 .data
= &sysctl_tcp_workaround_signed_windows
,
565 .maxlen
= sizeof(int),
567 .proc_handler
= proc_dointvec
569 #ifdef CONFIG_NET_DMA
571 .procname
= "tcp_dma_copybreak",
572 .data
= &sysctl_tcp_dma_copybreak
,
573 .maxlen
= sizeof(int),
575 .proc_handler
= proc_dointvec
579 .procname
= "tcp_slow_start_after_idle",
580 .data
= &sysctl_tcp_slow_start_after_idle
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= proc_dointvec
585 #ifdef CONFIG_NETLABEL
587 .procname
= "cipso_cache_enable",
588 .data
= &cipso_v4_cache_enabled
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= proc_dointvec
,
594 .procname
= "cipso_cache_bucket_size",
595 .data
= &cipso_v4_cache_bucketsize
,
596 .maxlen
= sizeof(int),
598 .proc_handler
= proc_dointvec
,
601 .procname
= "cipso_rbm_optfmt",
602 .data
= &cipso_v4_rbm_optfmt
,
603 .maxlen
= sizeof(int),
605 .proc_handler
= proc_dointvec
,
608 .procname
= "cipso_rbm_strictvalid",
609 .data
= &cipso_v4_rbm_strictvalid
,
610 .maxlen
= sizeof(int),
612 .proc_handler
= proc_dointvec
,
614 #endif /* CONFIG_NETLABEL */
616 .procname
= "tcp_available_congestion_control",
617 .maxlen
= TCP_CA_BUF_MAX
,
619 .proc_handler
= proc_tcp_available_congestion_control
,
622 .procname
= "tcp_allowed_congestion_control",
623 .maxlen
= TCP_CA_BUF_MAX
,
625 .proc_handler
= proc_allowed_congestion_control
,
628 .procname
= "tcp_max_ssthresh",
629 .data
= &sysctl_tcp_max_ssthresh
,
630 .maxlen
= sizeof(int),
632 .proc_handler
= proc_dointvec
,
635 .procname
= "tcp_cookie_size",
636 .data
= &sysctl_tcp_cookie_size
,
637 .maxlen
= sizeof(int),
639 .proc_handler
= proc_dointvec
642 .procname
= "tcp_thin_linear_timeouts",
643 .data
= &sysctl_tcp_thin_linear_timeouts
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= proc_dointvec
649 .procname
= "tcp_thin_dupack",
650 .data
= &sysctl_tcp_thin_dupack
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= proc_dointvec
656 .procname
= "udp_mem",
657 .data
= &sysctl_udp_mem
,
658 .maxlen
= sizeof(sysctl_udp_mem
),
660 .proc_handler
= proc_doulongvec_minmax
,
663 .procname
= "udp_rmem_min",
664 .data
= &sysctl_udp_rmem_min
,
665 .maxlen
= sizeof(sysctl_udp_rmem_min
),
667 .proc_handler
= proc_dointvec_minmax
,
671 .procname
= "udp_wmem_min",
672 .data
= &sysctl_udp_wmem_min
,
673 .maxlen
= sizeof(sysctl_udp_wmem_min
),
675 .proc_handler
= proc_dointvec_minmax
,
681 static struct ctl_table ipv4_net_table
[] = {
683 .procname
= "icmp_echo_ignore_all",
684 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_all
,
685 .maxlen
= sizeof(int),
687 .proc_handler
= proc_dointvec
690 .procname
= "icmp_echo_ignore_broadcasts",
691 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_broadcasts
,
692 .maxlen
= sizeof(int),
694 .proc_handler
= proc_dointvec
697 .procname
= "icmp_ignore_bogus_error_responses",
698 .data
= &init_net
.ipv4
.sysctl_icmp_ignore_bogus_error_responses
,
699 .maxlen
= sizeof(int),
701 .proc_handler
= proc_dointvec
704 .procname
= "icmp_errors_use_inbound_ifaddr",
705 .data
= &init_net
.ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
,
706 .maxlen
= sizeof(int),
708 .proc_handler
= proc_dointvec
711 .procname
= "icmp_ratelimit",
712 .data
= &init_net
.ipv4
.sysctl_icmp_ratelimit
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= proc_dointvec_ms_jiffies
,
718 .procname
= "icmp_ratemask",
719 .data
= &init_net
.ipv4
.sysctl_icmp_ratemask
,
720 .maxlen
= sizeof(int),
722 .proc_handler
= proc_dointvec
725 .procname
= "rt_cache_rebuild_count",
726 .data
= &init_net
.ipv4
.sysctl_rt_cache_rebuild_count
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= proc_dointvec
732 .procname
= "ping_group_range",
733 .data
= &init_net
.ipv4
.sysctl_ping_group_range
,
734 .maxlen
= sizeof(init_net
.ipv4
.sysctl_ping_group_range
),
736 .proc_handler
= ipv4_ping_group_range
,
741 struct ctl_path net_ipv4_ctl_path
[] = {
742 { .procname
= "net", },
743 { .procname
= "ipv4", },
746 EXPORT_SYMBOL_GPL(net_ipv4_ctl_path
);
748 static __net_init
int ipv4_sysctl_init_net(struct net
*net
)
750 struct ctl_table
*table
;
752 table
= ipv4_net_table
;
753 if (!net_eq(net
, &init_net
)) {
754 table
= kmemdup(table
, sizeof(ipv4_net_table
), GFP_KERNEL
);
759 &net
->ipv4
.sysctl_icmp_echo_ignore_all
;
761 &net
->ipv4
.sysctl_icmp_echo_ignore_broadcasts
;
763 &net
->ipv4
.sysctl_icmp_ignore_bogus_error_responses
;
765 &net
->ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
;
767 &net
->ipv4
.sysctl_icmp_ratelimit
;
769 &net
->ipv4
.sysctl_icmp_ratemask
;
771 &net
->ipv4
.sysctl_rt_cache_rebuild_count
;
773 &net
->ipv4
.sysctl_ping_group_range
;
778 * Sane defaults - nobody may create ping sockets.
779 * Boot scripts should set this to distro-specific group.
781 net
->ipv4
.sysctl_ping_group_range
[0] = 1;
782 net
->ipv4
.sysctl_ping_group_range
[1] = 0;
784 net
->ipv4
.sysctl_rt_cache_rebuild_count
= 4;
786 net
->ipv4
.ipv4_hdr
= register_net_sysctl_table(net
,
787 net_ipv4_ctl_path
, table
);
788 if (net
->ipv4
.ipv4_hdr
== NULL
)
794 if (!net_eq(net
, &init_net
))
800 static __net_exit
void ipv4_sysctl_exit_net(struct net
*net
)
802 struct ctl_table
*table
;
804 table
= net
->ipv4
.ipv4_hdr
->ctl_table_arg
;
805 unregister_net_sysctl_table(net
->ipv4
.ipv4_hdr
);
809 static __net_initdata
struct pernet_operations ipv4_sysctl_ops
= {
810 .init
= ipv4_sysctl_init_net
,
811 .exit
= ipv4_sysctl_exit_net
,
814 static __init
int sysctl_ipv4_init(void)
816 struct ctl_table_header
*hdr
;
819 for (i
= ipv4_table
; i
->procname
; i
++) {
820 if (strcmp(i
->procname
, "ip_local_reserved_ports") == 0) {
821 i
->data
= sysctl_local_reserved_ports
;
828 hdr
= register_sysctl_paths(net_ipv4_ctl_path
, ipv4_table
);
832 if (register_pernet_subsys(&ipv4_sysctl_ops
)) {
833 unregister_sysctl_table(hdr
);
840 __initcall(sysctl_ipv4_init
);