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>
18 #include <net/route.h>
21 #include <net/cipso_ipv4.h>
22 #include <net/inet_frag.h>
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
,
41 size_t *lenp
, loff_t
*ppos
)
47 .maxlen
= sizeof(range
),
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])
60 set_local_port_range(range
);
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
];
72 .maxlen
= TCP_CA_NAME_MAX
,
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
);
84 static int proc_tcp_available_congestion_control(ctl_table
*ctl
,
86 void __user
*buffer
, size_t *lenp
,
89 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
, };
92 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
95 tcp_get_available_congestion_control(tbl
.data
, TCP_CA_BUF_MAX
);
96 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
101 static int proc_allowed_congestion_control(ctl_table
*ctl
,
103 void __user
*buffer
, size_t *lenp
,
106 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
};
109 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
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
);
121 static struct ctl_table ipv4_table
[] = {
123 .procname
= "tcp_timestamps",
124 .data
= &sysctl_tcp_timestamps
,
125 .maxlen
= sizeof(int),
127 .proc_handler
= proc_dointvec
130 .procname
= "tcp_window_scaling",
131 .data
= &sysctl_tcp_window_scaling
,
132 .maxlen
= sizeof(int),
134 .proc_handler
= proc_dointvec
137 .procname
= "tcp_sack",
138 .data
= &sysctl_tcp_sack
,
139 .maxlen
= sizeof(int),
141 .proc_handler
= proc_dointvec
144 .procname
= "tcp_retrans_collapse",
145 .data
= &sysctl_tcp_retrans_collapse
,
146 .maxlen
= sizeof(int),
148 .proc_handler
= proc_dointvec
151 .procname
= "ip_default_ttl",
152 .data
= &sysctl_ip_default_ttl
,
153 .maxlen
= sizeof(int),
155 .proc_handler
= ipv4_doint_and_flush
,
159 .procname
= "ip_no_pmtu_disc",
160 .data
= &ipv4_config
.no_pmtu_disc
,
161 .maxlen
= sizeof(int),
163 .proc_handler
= proc_dointvec
166 .procname
= "ip_nonlocal_bind",
167 .data
= &sysctl_ip_nonlocal_bind
,
168 .maxlen
= sizeof(int),
170 .proc_handler
= proc_dointvec
173 .procname
= "tcp_syn_retries",
174 .data
= &sysctl_tcp_syn_retries
,
175 .maxlen
= sizeof(int),
177 .proc_handler
= proc_dointvec
180 .procname
= "tcp_synack_retries",
181 .data
= &sysctl_tcp_synack_retries
,
182 .maxlen
= sizeof(int),
184 .proc_handler
= proc_dointvec
187 .procname
= "tcp_max_orphans",
188 .data
= &sysctl_tcp_max_orphans
,
189 .maxlen
= sizeof(int),
191 .proc_handler
= proc_dointvec
194 .procname
= "tcp_max_tw_buckets",
195 .data
= &tcp_death_row
.sysctl_max_tw_buckets
,
196 .maxlen
= sizeof(int),
198 .proc_handler
= proc_dointvec
201 .procname
= "ip_dynaddr",
202 .data
= &sysctl_ip_dynaddr
,
203 .maxlen
= sizeof(int),
205 .proc_handler
= proc_dointvec
208 .procname
= "tcp_keepalive_time",
209 .data
= &sysctl_tcp_keepalive_time
,
210 .maxlen
= sizeof(int),
212 .proc_handler
= proc_dointvec_jiffies
,
215 .procname
= "tcp_keepalive_probes",
216 .data
= &sysctl_tcp_keepalive_probes
,
217 .maxlen
= sizeof(int),
219 .proc_handler
= proc_dointvec
222 .procname
= "tcp_keepalive_intvl",
223 .data
= &sysctl_tcp_keepalive_intvl
,
224 .maxlen
= sizeof(int),
226 .proc_handler
= proc_dointvec_jiffies
,
229 .procname
= "tcp_retries1",
230 .data
= &sysctl_tcp_retries1
,
231 .maxlen
= sizeof(int),
233 .proc_handler
= proc_dointvec_minmax
,
234 .extra2
= &tcp_retr1_max
237 .procname
= "tcp_retries2",
238 .data
= &sysctl_tcp_retries2
,
239 .maxlen
= sizeof(int),
241 .proc_handler
= proc_dointvec
244 .procname
= "tcp_fin_timeout",
245 .data
= &sysctl_tcp_fin_timeout
,
246 .maxlen
= sizeof(int),
248 .proc_handler
= proc_dointvec_jiffies
,
250 #ifdef CONFIG_SYN_COOKIES
252 .procname
= "tcp_syncookies",
253 .data
= &sysctl_tcp_syncookies
,
254 .maxlen
= sizeof(int),
256 .proc_handler
= proc_dointvec
260 .procname
= "tcp_tw_recycle",
261 .data
= &tcp_death_row
.sysctl_tw_recycle
,
262 .maxlen
= sizeof(int),
264 .proc_handler
= proc_dointvec
267 .procname
= "tcp_abort_on_overflow",
268 .data
= &sysctl_tcp_abort_on_overflow
,
269 .maxlen
= sizeof(int),
271 .proc_handler
= proc_dointvec
274 .procname
= "tcp_stdurg",
275 .data
= &sysctl_tcp_stdurg
,
276 .maxlen
= sizeof(int),
278 .proc_handler
= proc_dointvec
281 .procname
= "tcp_rfc1337",
282 .data
= &sysctl_tcp_rfc1337
,
283 .maxlen
= sizeof(int),
285 .proc_handler
= proc_dointvec
288 .procname
= "tcp_max_syn_backlog",
289 .data
= &sysctl_max_syn_backlog
,
290 .maxlen
= sizeof(int),
292 .proc_handler
= proc_dointvec
295 .procname
= "ip_local_port_range",
296 .data
= &sysctl_local_ports
.range
,
297 .maxlen
= sizeof(sysctl_local_ports
.range
),
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),
307 .proc_handler
= proc_dointvec
312 .procname
= "igmp_max_msf",
313 .data
= &sysctl_igmp_max_msf
,
314 .maxlen
= sizeof(int),
316 .proc_handler
= proc_dointvec
319 .procname
= "inet_peer_threshold",
320 .data
= &inet_peer_threshold
,
321 .maxlen
= sizeof(int),
323 .proc_handler
= proc_dointvec
326 .procname
= "inet_peer_minttl",
327 .data
= &inet_peer_minttl
,
328 .maxlen
= sizeof(int),
330 .proc_handler
= proc_dointvec_jiffies
,
333 .procname
= "inet_peer_maxttl",
334 .data
= &inet_peer_maxttl
,
335 .maxlen
= sizeof(int),
337 .proc_handler
= proc_dointvec_jiffies
,
340 .procname
= "inet_peer_gc_mintime",
341 .data
= &inet_peer_gc_mintime
,
342 .maxlen
= sizeof(int),
344 .proc_handler
= proc_dointvec_jiffies
,
347 .procname
= "inet_peer_gc_maxtime",
348 .data
= &inet_peer_gc_maxtime
,
349 .maxlen
= sizeof(int),
351 .proc_handler
= proc_dointvec_jiffies
,
354 .procname
= "tcp_orphan_retries",
355 .data
= &sysctl_tcp_orphan_retries
,
356 .maxlen
= sizeof(int),
358 .proc_handler
= proc_dointvec
361 .procname
= "tcp_fack",
362 .data
= &sysctl_tcp_fack
,
363 .maxlen
= sizeof(int),
365 .proc_handler
= proc_dointvec
368 .procname
= "tcp_reordering",
369 .data
= &sysctl_tcp_reordering
,
370 .maxlen
= sizeof(int),
372 .proc_handler
= proc_dointvec
375 .procname
= "tcp_ecn",
376 .data
= &sysctl_tcp_ecn
,
377 .maxlen
= sizeof(int),
379 .proc_handler
= proc_dointvec
382 .procname
= "tcp_dsack",
383 .data
= &sysctl_tcp_dsack
,
384 .maxlen
= sizeof(int),
386 .proc_handler
= proc_dointvec
389 .procname
= "tcp_mem",
390 .data
= &sysctl_tcp_mem
,
391 .maxlen
= sizeof(sysctl_tcp_mem
),
393 .proc_handler
= proc_dointvec
396 .procname
= "tcp_wmem",
397 .data
= &sysctl_tcp_wmem
,
398 .maxlen
= sizeof(sysctl_tcp_wmem
),
400 .proc_handler
= proc_dointvec
403 .procname
= "tcp_rmem",
404 .data
= &sysctl_tcp_rmem
,
405 .maxlen
= sizeof(sysctl_tcp_rmem
),
407 .proc_handler
= proc_dointvec
410 .procname
= "tcp_app_win",
411 .data
= &sysctl_tcp_app_win
,
412 .maxlen
= sizeof(int),
414 .proc_handler
= proc_dointvec
417 .procname
= "tcp_adv_win_scale",
418 .data
= &sysctl_tcp_adv_win_scale
,
419 .maxlen
= sizeof(int),
421 .proc_handler
= proc_dointvec
424 .procname
= "tcp_tw_reuse",
425 .data
= &sysctl_tcp_tw_reuse
,
426 .maxlen
= sizeof(int),
428 .proc_handler
= proc_dointvec
431 .procname
= "tcp_frto",
432 .data
= &sysctl_tcp_frto
,
433 .maxlen
= sizeof(int),
435 .proc_handler
= proc_dointvec
438 .procname
= "tcp_frto_response",
439 .data
= &sysctl_tcp_frto_response
,
440 .maxlen
= sizeof(int),
442 .proc_handler
= proc_dointvec
445 .procname
= "tcp_low_latency",
446 .data
= &sysctl_tcp_low_latency
,
447 .maxlen
= sizeof(int),
449 .proc_handler
= proc_dointvec
452 .procname
= "tcp_no_metrics_save",
453 .data
= &sysctl_tcp_nometrics_save
,
454 .maxlen
= sizeof(int),
456 .proc_handler
= proc_dointvec
,
459 .procname
= "tcp_moderate_rcvbuf",
460 .data
= &sysctl_tcp_moderate_rcvbuf
,
461 .maxlen
= sizeof(int),
463 .proc_handler
= proc_dointvec
,
466 .procname
= "tcp_tso_win_divisor",
467 .data
= &sysctl_tcp_tso_win_divisor
,
468 .maxlen
= sizeof(int),
470 .proc_handler
= proc_dointvec
,
473 .procname
= "tcp_congestion_control",
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),
483 .proc_handler
= proc_dointvec
,
486 .procname
= "tcp_mtu_probing",
487 .data
= &sysctl_tcp_mtu_probing
,
488 .maxlen
= sizeof(int),
490 .proc_handler
= proc_dointvec
,
493 .procname
= "tcp_base_mss",
494 .data
= &sysctl_tcp_base_mss
,
495 .maxlen
= sizeof(int),
497 .proc_handler
= proc_dointvec
,
500 .procname
= "tcp_workaround_signed_windows",
501 .data
= &sysctl_tcp_workaround_signed_windows
,
502 .maxlen
= sizeof(int),
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),
512 .proc_handler
= proc_dointvec
516 .procname
= "tcp_slow_start_after_idle",
517 .data
= &sysctl_tcp_slow_start_after_idle
,
518 .maxlen
= sizeof(int),
520 .proc_handler
= proc_dointvec
522 #ifdef CONFIG_NETLABEL
524 .procname
= "cipso_cache_enable",
525 .data
= &cipso_v4_cache_enabled
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= proc_dointvec
,
531 .procname
= "cipso_cache_bucket_size",
532 .data
= &cipso_v4_cache_bucketsize
,
533 .maxlen
= sizeof(int),
535 .proc_handler
= proc_dointvec
,
538 .procname
= "cipso_rbm_optfmt",
539 .data
= &cipso_v4_rbm_optfmt
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= proc_dointvec
,
545 .procname
= "cipso_rbm_strictvalid",
546 .data
= &cipso_v4_rbm_strictvalid
,
547 .maxlen
= sizeof(int),
549 .proc_handler
= proc_dointvec
,
551 #endif /* CONFIG_NETLABEL */
553 .procname
= "tcp_available_congestion_control",
554 .maxlen
= TCP_CA_BUF_MAX
,
556 .proc_handler
= proc_tcp_available_congestion_control
,
559 .procname
= "tcp_allowed_congestion_control",
560 .maxlen
= TCP_CA_BUF_MAX
,
562 .proc_handler
= proc_allowed_congestion_control
,
565 .procname
= "tcp_max_ssthresh",
566 .data
= &sysctl_tcp_max_ssthresh
,
567 .maxlen
= sizeof(int),
569 .proc_handler
= proc_dointvec
,
572 .procname
= "tcp_cookie_size",
573 .data
= &sysctl_tcp_cookie_size
,
574 .maxlen
= sizeof(int),
576 .proc_handler
= proc_dointvec
579 .procname
= "udp_mem",
580 .data
= &sysctl_udp_mem
,
581 .maxlen
= sizeof(sysctl_udp_mem
),
583 .proc_handler
= proc_dointvec_minmax
,
587 .procname
= "udp_rmem_min",
588 .data
= &sysctl_udp_rmem_min
,
589 .maxlen
= sizeof(sysctl_udp_rmem_min
),
591 .proc_handler
= proc_dointvec_minmax
,
595 .procname
= "udp_wmem_min",
596 .data
= &sysctl_udp_wmem_min
,
597 .maxlen
= sizeof(sysctl_udp_wmem_min
),
599 .proc_handler
= proc_dointvec_minmax
,
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),
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),
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),
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),
632 .proc_handler
= proc_dointvec
635 .procname
= "icmp_ratelimit",
636 .data
= &init_net
.ipv4
.sysctl_icmp_ratelimit
,
637 .maxlen
= sizeof(int),
639 .proc_handler
= proc_dointvec_ms_jiffies
,
642 .procname
= "icmp_ratemask",
643 .data
= &init_net
.ipv4
.sysctl_icmp_ratemask
,
644 .maxlen
= sizeof(int),
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),
653 .proc_handler
= proc_dointvec
658 struct ctl_path net_ipv4_ctl_path
[] = {
659 { .procname
= "net", },
660 { .procname
= "ipv4", },
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
);
676 &net
->ipv4
.sysctl_icmp_echo_ignore_all
;
678 &net
->ipv4
.sysctl_icmp_echo_ignore_broadcasts
;
680 &net
->ipv4
.sysctl_icmp_ignore_bogus_error_responses
;
682 &net
->ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
;
684 &net
->ipv4
.sysctl_icmp_ratelimit
;
686 &net
->ipv4
.sysctl_icmp_ratemask
;
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
)
701 if (!net_eq(net
, &init_net
))
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
);
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
);
729 if (register_pernet_subsys(&ipv4_sysctl_ops
)) {
730 unregister_sysctl_table(hdr
);
737 __initcall(sysctl_ipv4_init
);