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>
19 #include <net/route.h>
22 #include <net/cipso_ipv4.h>
23 #include <net/inet_frag.h>
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
,
42 size_t *lenp
, loff_t
*ppos
)
48 .maxlen
= sizeof(range
),
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])
61 set_local_port_range(range
);
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
];
73 .maxlen
= TCP_CA_NAME_MAX
,
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
);
85 static int proc_tcp_available_congestion_control(ctl_table
*ctl
,
87 void __user
*buffer
, size_t *lenp
,
90 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
, };
93 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
96 tcp_get_available_congestion_control(tbl
.data
, TCP_CA_BUF_MAX
);
97 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
102 static int proc_allowed_congestion_control(ctl_table
*ctl
,
104 void __user
*buffer
, size_t *lenp
,
107 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
};
110 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
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
);
122 static struct ctl_table ipv4_table
[] = {
124 .procname
= "tcp_timestamps",
125 .data
= &sysctl_tcp_timestamps
,
126 .maxlen
= sizeof(int),
128 .proc_handler
= proc_dointvec
131 .procname
= "tcp_window_scaling",
132 .data
= &sysctl_tcp_window_scaling
,
133 .maxlen
= sizeof(int),
135 .proc_handler
= proc_dointvec
138 .procname
= "tcp_sack",
139 .data
= &sysctl_tcp_sack
,
140 .maxlen
= sizeof(int),
142 .proc_handler
= proc_dointvec
145 .procname
= "tcp_retrans_collapse",
146 .data
= &sysctl_tcp_retrans_collapse
,
147 .maxlen
= sizeof(int),
149 .proc_handler
= proc_dointvec
152 .procname
= "ip_default_ttl",
153 .data
= &sysctl_ip_default_ttl
,
154 .maxlen
= sizeof(int),
156 .proc_handler
= ipv4_doint_and_flush
,
160 .procname
= "ip_no_pmtu_disc",
161 .data
= &ipv4_config
.no_pmtu_disc
,
162 .maxlen
= sizeof(int),
164 .proc_handler
= proc_dointvec
167 .procname
= "ip_nonlocal_bind",
168 .data
= &sysctl_ip_nonlocal_bind
,
169 .maxlen
= sizeof(int),
171 .proc_handler
= proc_dointvec
174 .procname
= "tcp_syn_retries",
175 .data
= &sysctl_tcp_syn_retries
,
176 .maxlen
= sizeof(int),
178 .proc_handler
= proc_dointvec
181 .procname
= "tcp_synack_retries",
182 .data
= &sysctl_tcp_synack_retries
,
183 .maxlen
= sizeof(int),
185 .proc_handler
= proc_dointvec
188 .procname
= "tcp_max_orphans",
189 .data
= &sysctl_tcp_max_orphans
,
190 .maxlen
= sizeof(int),
192 .proc_handler
= proc_dointvec
195 .procname
= "tcp_max_tw_buckets",
196 .data
= &tcp_death_row
.sysctl_max_tw_buckets
,
197 .maxlen
= sizeof(int),
199 .proc_handler
= proc_dointvec
202 .procname
= "ip_dynaddr",
203 .data
= &sysctl_ip_dynaddr
,
204 .maxlen
= sizeof(int),
206 .proc_handler
= proc_dointvec
209 .procname
= "tcp_keepalive_time",
210 .data
= &sysctl_tcp_keepalive_time
,
211 .maxlen
= sizeof(int),
213 .proc_handler
= proc_dointvec_jiffies
,
216 .procname
= "tcp_keepalive_probes",
217 .data
= &sysctl_tcp_keepalive_probes
,
218 .maxlen
= sizeof(int),
220 .proc_handler
= proc_dointvec
223 .procname
= "tcp_keepalive_intvl",
224 .data
= &sysctl_tcp_keepalive_intvl
,
225 .maxlen
= sizeof(int),
227 .proc_handler
= proc_dointvec_jiffies
,
230 .procname
= "tcp_retries1",
231 .data
= &sysctl_tcp_retries1
,
232 .maxlen
= sizeof(int),
234 .proc_handler
= proc_dointvec_minmax
,
235 .extra2
= &tcp_retr1_max
238 .procname
= "tcp_retries2",
239 .data
= &sysctl_tcp_retries2
,
240 .maxlen
= sizeof(int),
242 .proc_handler
= proc_dointvec
245 .procname
= "tcp_fin_timeout",
246 .data
= &sysctl_tcp_fin_timeout
,
247 .maxlen
= sizeof(int),
249 .proc_handler
= proc_dointvec_jiffies
,
251 #ifdef CONFIG_SYN_COOKIES
253 .procname
= "tcp_syncookies",
254 .data
= &sysctl_tcp_syncookies
,
255 .maxlen
= sizeof(int),
257 .proc_handler
= proc_dointvec
261 .procname
= "tcp_tw_recycle",
262 .data
= &tcp_death_row
.sysctl_tw_recycle
,
263 .maxlen
= sizeof(int),
265 .proc_handler
= proc_dointvec
268 .procname
= "tcp_abort_on_overflow",
269 .data
= &sysctl_tcp_abort_on_overflow
,
270 .maxlen
= sizeof(int),
272 .proc_handler
= proc_dointvec
275 .procname
= "tcp_stdurg",
276 .data
= &sysctl_tcp_stdurg
,
277 .maxlen
= sizeof(int),
279 .proc_handler
= proc_dointvec
282 .procname
= "tcp_rfc1337",
283 .data
= &sysctl_tcp_rfc1337
,
284 .maxlen
= sizeof(int),
286 .proc_handler
= proc_dointvec
289 .procname
= "tcp_max_syn_backlog",
290 .data
= &sysctl_max_syn_backlog
,
291 .maxlen
= sizeof(int),
293 .proc_handler
= proc_dointvec
296 .procname
= "ip_local_port_range",
297 .data
= &sysctl_local_ports
.range
,
298 .maxlen
= sizeof(sysctl_local_ports
.range
),
300 .proc_handler
= ipv4_local_port_range
,
303 .procname
= "ip_local_reserved_ports",
304 .data
= NULL
, /* initialized in sysctl_ipv4_init */
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),
315 .proc_handler
= proc_dointvec
320 .procname
= "igmp_max_msf",
321 .data
= &sysctl_igmp_max_msf
,
322 .maxlen
= sizeof(int),
324 .proc_handler
= proc_dointvec
327 .procname
= "inet_peer_threshold",
328 .data
= &inet_peer_threshold
,
329 .maxlen
= sizeof(int),
331 .proc_handler
= proc_dointvec
334 .procname
= "inet_peer_minttl",
335 .data
= &inet_peer_minttl
,
336 .maxlen
= sizeof(int),
338 .proc_handler
= proc_dointvec_jiffies
,
341 .procname
= "inet_peer_maxttl",
342 .data
= &inet_peer_maxttl
,
343 .maxlen
= sizeof(int),
345 .proc_handler
= proc_dointvec_jiffies
,
348 .procname
= "inet_peer_gc_mintime",
349 .data
= &inet_peer_gc_mintime
,
350 .maxlen
= sizeof(int),
352 .proc_handler
= proc_dointvec_jiffies
,
355 .procname
= "inet_peer_gc_maxtime",
356 .data
= &inet_peer_gc_maxtime
,
357 .maxlen
= sizeof(int),
359 .proc_handler
= proc_dointvec_jiffies
,
362 .procname
= "tcp_orphan_retries",
363 .data
= &sysctl_tcp_orphan_retries
,
364 .maxlen
= sizeof(int),
366 .proc_handler
= proc_dointvec
369 .procname
= "tcp_fack",
370 .data
= &sysctl_tcp_fack
,
371 .maxlen
= sizeof(int),
373 .proc_handler
= proc_dointvec
376 .procname
= "tcp_reordering",
377 .data
= &sysctl_tcp_reordering
,
378 .maxlen
= sizeof(int),
380 .proc_handler
= proc_dointvec
383 .procname
= "tcp_ecn",
384 .data
= &sysctl_tcp_ecn
,
385 .maxlen
= sizeof(int),
387 .proc_handler
= proc_dointvec
390 .procname
= "tcp_dsack",
391 .data
= &sysctl_tcp_dsack
,
392 .maxlen
= sizeof(int),
394 .proc_handler
= proc_dointvec
397 .procname
= "tcp_mem",
398 .data
= &sysctl_tcp_mem
,
399 .maxlen
= sizeof(sysctl_tcp_mem
),
401 .proc_handler
= proc_dointvec
404 .procname
= "tcp_wmem",
405 .data
= &sysctl_tcp_wmem
,
406 .maxlen
= sizeof(sysctl_tcp_wmem
),
408 .proc_handler
= proc_dointvec
411 .procname
= "tcp_rmem",
412 .data
= &sysctl_tcp_rmem
,
413 .maxlen
= sizeof(sysctl_tcp_rmem
),
415 .proc_handler
= proc_dointvec
418 .procname
= "tcp_app_win",
419 .data
= &sysctl_tcp_app_win
,
420 .maxlen
= sizeof(int),
422 .proc_handler
= proc_dointvec
425 .procname
= "tcp_adv_win_scale",
426 .data
= &sysctl_tcp_adv_win_scale
,
427 .maxlen
= sizeof(int),
429 .proc_handler
= proc_dointvec
432 .procname
= "tcp_tw_reuse",
433 .data
= &sysctl_tcp_tw_reuse
,
434 .maxlen
= sizeof(int),
436 .proc_handler
= proc_dointvec
439 .procname
= "tcp_frto",
440 .data
= &sysctl_tcp_frto
,
441 .maxlen
= sizeof(int),
443 .proc_handler
= proc_dointvec
446 .procname
= "tcp_frto_response",
447 .data
= &sysctl_tcp_frto_response
,
448 .maxlen
= sizeof(int),
450 .proc_handler
= proc_dointvec
453 .procname
= "tcp_low_latency",
454 .data
= &sysctl_tcp_low_latency
,
455 .maxlen
= sizeof(int),
457 .proc_handler
= proc_dointvec
460 .procname
= "tcp_no_metrics_save",
461 .data
= &sysctl_tcp_nometrics_save
,
462 .maxlen
= sizeof(int),
464 .proc_handler
= proc_dointvec
,
467 .procname
= "tcp_moderate_rcvbuf",
468 .data
= &sysctl_tcp_moderate_rcvbuf
,
469 .maxlen
= sizeof(int),
471 .proc_handler
= proc_dointvec
,
474 .procname
= "tcp_tso_win_divisor",
475 .data
= &sysctl_tcp_tso_win_divisor
,
476 .maxlen
= sizeof(int),
478 .proc_handler
= proc_dointvec
,
481 .procname
= "tcp_congestion_control",
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),
491 .proc_handler
= proc_dointvec
,
494 .procname
= "tcp_mtu_probing",
495 .data
= &sysctl_tcp_mtu_probing
,
496 .maxlen
= sizeof(int),
498 .proc_handler
= proc_dointvec
,
501 .procname
= "tcp_base_mss",
502 .data
= &sysctl_tcp_base_mss
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= proc_dointvec
,
508 .procname
= "tcp_workaround_signed_windows",
509 .data
= &sysctl_tcp_workaround_signed_windows
,
510 .maxlen
= sizeof(int),
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),
520 .proc_handler
= proc_dointvec
524 .procname
= "tcp_slow_start_after_idle",
525 .data
= &sysctl_tcp_slow_start_after_idle
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= proc_dointvec
530 #ifdef CONFIG_NETLABEL
532 .procname
= "cipso_cache_enable",
533 .data
= &cipso_v4_cache_enabled
,
534 .maxlen
= sizeof(int),
536 .proc_handler
= proc_dointvec
,
539 .procname
= "cipso_cache_bucket_size",
540 .data
= &cipso_v4_cache_bucketsize
,
541 .maxlen
= sizeof(int),
543 .proc_handler
= proc_dointvec
,
546 .procname
= "cipso_rbm_optfmt",
547 .data
= &cipso_v4_rbm_optfmt
,
548 .maxlen
= sizeof(int),
550 .proc_handler
= proc_dointvec
,
553 .procname
= "cipso_rbm_strictvalid",
554 .data
= &cipso_v4_rbm_strictvalid
,
555 .maxlen
= sizeof(int),
557 .proc_handler
= proc_dointvec
,
559 #endif /* CONFIG_NETLABEL */
561 .procname
= "tcp_available_congestion_control",
562 .maxlen
= TCP_CA_BUF_MAX
,
564 .proc_handler
= proc_tcp_available_congestion_control
,
567 .procname
= "tcp_allowed_congestion_control",
568 .maxlen
= TCP_CA_BUF_MAX
,
570 .proc_handler
= proc_allowed_congestion_control
,
573 .procname
= "tcp_max_ssthresh",
574 .data
= &sysctl_tcp_max_ssthresh
,
575 .maxlen
= sizeof(int),
577 .proc_handler
= proc_dointvec
,
580 .procname
= "tcp_cookie_size",
581 .data
= &sysctl_tcp_cookie_size
,
582 .maxlen
= sizeof(int),
584 .proc_handler
= proc_dointvec
587 .procname
= "tcp_thin_linear_timeouts",
588 .data
= &sysctl_tcp_thin_linear_timeouts
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= proc_dointvec
594 .procname
= "tcp_thin_dupack",
595 .data
= &sysctl_tcp_thin_dupack
,
596 .maxlen
= sizeof(int),
598 .proc_handler
= proc_dointvec
601 .procname
= "udp_mem",
602 .data
= &sysctl_udp_mem
,
603 .maxlen
= sizeof(sysctl_udp_mem
),
605 .proc_handler
= proc_dointvec_minmax
,
609 .procname
= "udp_rmem_min",
610 .data
= &sysctl_udp_rmem_min
,
611 .maxlen
= sizeof(sysctl_udp_rmem_min
),
613 .proc_handler
= proc_dointvec_minmax
,
617 .procname
= "udp_wmem_min",
618 .data
= &sysctl_udp_wmem_min
,
619 .maxlen
= sizeof(sysctl_udp_wmem_min
),
621 .proc_handler
= proc_dointvec_minmax
,
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),
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),
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),
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),
654 .proc_handler
= proc_dointvec
657 .procname
= "icmp_ratelimit",
658 .data
= &init_net
.ipv4
.sysctl_icmp_ratelimit
,
659 .maxlen
= sizeof(int),
661 .proc_handler
= proc_dointvec_ms_jiffies
,
664 .procname
= "icmp_ratemask",
665 .data
= &init_net
.ipv4
.sysctl_icmp_ratemask
,
666 .maxlen
= sizeof(int),
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),
675 .proc_handler
= proc_dointvec
680 struct ctl_path net_ipv4_ctl_path
[] = {
681 { .procname
= "net", },
682 { .procname
= "ipv4", },
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
);
698 &net
->ipv4
.sysctl_icmp_echo_ignore_all
;
700 &net
->ipv4
.sysctl_icmp_echo_ignore_broadcasts
;
702 &net
->ipv4
.sysctl_icmp_ignore_bogus_error_responses
;
704 &net
->ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
;
706 &net
->ipv4
.sysctl_icmp_ratelimit
;
708 &net
->ipv4
.sysctl_icmp_ratemask
;
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
)
723 if (!net_eq(net
, &init_net
))
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
);
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
;
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
;
757 hdr
= register_sysctl_paths(net_ipv4_ctl_path
, ipv4_table
);
761 if (register_pernet_subsys(&ipv4_sysctl_ops
)) {
762 unregister_sysctl_table(hdr
);
769 __initcall(sysctl_ipv4_init
);