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 };
29 static int tcp_adv_win_scale_min
= -31;
30 static int tcp_adv_win_scale_max
= 31;
31 static int ip_ttl_min
= 1;
32 static int ip_ttl_max
= 255;
34 /* Update system visible IP port range */
35 static void set_local_port_range(int range
[2])
37 write_seqlock(&sysctl_local_ports
.lock
);
38 sysctl_local_ports
.range
[0] = range
[0];
39 sysctl_local_ports
.range
[1] = range
[1];
40 write_sequnlock(&sysctl_local_ports
.lock
);
43 /* Validate changes from /proc interface. */
44 static int ipv4_local_port_range(ctl_table
*table
, int write
,
46 size_t *lenp
, loff_t
*ppos
)
52 .maxlen
= sizeof(range
),
54 .extra1
= &ip_local_port_range_min
,
55 .extra2
= &ip_local_port_range_max
,
58 inet_get_local_port_range(range
, range
+ 1);
59 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
61 if (write
&& ret
== 0) {
62 if (range
[1] < range
[0])
65 set_local_port_range(range
);
71 static int proc_tcp_congestion_control(ctl_table
*ctl
, int write
,
72 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
74 char val
[TCP_CA_NAME_MAX
];
77 .maxlen
= TCP_CA_NAME_MAX
,
81 tcp_get_default_congestion_control(val
);
83 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
84 if (write
&& ret
== 0)
85 ret
= tcp_set_default_congestion_control(val
);
89 static int proc_tcp_available_congestion_control(ctl_table
*ctl
,
91 void __user
*buffer
, size_t *lenp
,
94 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
, };
97 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
100 tcp_get_available_congestion_control(tbl
.data
, TCP_CA_BUF_MAX
);
101 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
106 static int proc_allowed_congestion_control(ctl_table
*ctl
,
108 void __user
*buffer
, size_t *lenp
,
111 ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
};
114 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
118 tcp_get_allowed_congestion_control(tbl
.data
, tbl
.maxlen
);
119 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
120 if (write
&& ret
== 0)
121 ret
= tcp_set_allowed_congestion_control(tbl
.data
);
126 static struct ctl_table ipv4_table
[] = {
128 .procname
= "tcp_timestamps",
129 .data
= &sysctl_tcp_timestamps
,
130 .maxlen
= sizeof(int),
132 .proc_handler
= proc_dointvec
135 .procname
= "tcp_window_scaling",
136 .data
= &sysctl_tcp_window_scaling
,
137 .maxlen
= sizeof(int),
139 .proc_handler
= proc_dointvec
142 .procname
= "tcp_sack",
143 .data
= &sysctl_tcp_sack
,
144 .maxlen
= sizeof(int),
146 .proc_handler
= proc_dointvec
149 .procname
= "tcp_retrans_collapse",
150 .data
= &sysctl_tcp_retrans_collapse
,
151 .maxlen
= sizeof(int),
153 .proc_handler
= proc_dointvec
156 .procname
= "ip_default_ttl",
157 .data
= &sysctl_ip_default_ttl
,
158 .maxlen
= sizeof(int),
160 .proc_handler
= proc_dointvec_minmax
,
161 .extra1
= &ip_ttl_min
,
162 .extra2
= &ip_ttl_max
,
165 .procname
= "ip_no_pmtu_disc",
166 .data
= &ipv4_config
.no_pmtu_disc
,
167 .maxlen
= sizeof(int),
169 .proc_handler
= proc_dointvec
172 .procname
= "ip_nonlocal_bind",
173 .data
= &sysctl_ip_nonlocal_bind
,
174 .maxlen
= sizeof(int),
176 .proc_handler
= proc_dointvec
179 .procname
= "tcp_syn_retries",
180 .data
= &sysctl_tcp_syn_retries
,
181 .maxlen
= sizeof(int),
183 .proc_handler
= proc_dointvec
186 .procname
= "tcp_synack_retries",
187 .data
= &sysctl_tcp_synack_retries
,
188 .maxlen
= sizeof(int),
190 .proc_handler
= proc_dointvec
193 .procname
= "tcp_max_orphans",
194 .data
= &sysctl_tcp_max_orphans
,
195 .maxlen
= sizeof(int),
197 .proc_handler
= proc_dointvec
200 .procname
= "tcp_max_tw_buckets",
201 .data
= &tcp_death_row
.sysctl_max_tw_buckets
,
202 .maxlen
= sizeof(int),
204 .proc_handler
= proc_dointvec
207 .procname
= "ip_dynaddr",
208 .data
= &sysctl_ip_dynaddr
,
209 .maxlen
= sizeof(int),
211 .proc_handler
= proc_dointvec
214 .procname
= "tcp_keepalive_time",
215 .data
= &sysctl_tcp_keepalive_time
,
216 .maxlen
= sizeof(int),
218 .proc_handler
= proc_dointvec_jiffies
,
221 .procname
= "tcp_keepalive_probes",
222 .data
= &sysctl_tcp_keepalive_probes
,
223 .maxlen
= sizeof(int),
225 .proc_handler
= proc_dointvec
228 .procname
= "tcp_keepalive_intvl",
229 .data
= &sysctl_tcp_keepalive_intvl
,
230 .maxlen
= sizeof(int),
232 .proc_handler
= proc_dointvec_jiffies
,
235 .procname
= "tcp_retries1",
236 .data
= &sysctl_tcp_retries1
,
237 .maxlen
= sizeof(int),
239 .proc_handler
= proc_dointvec_minmax
,
240 .extra2
= &tcp_retr1_max
243 .procname
= "tcp_retries2",
244 .data
= &sysctl_tcp_retries2
,
245 .maxlen
= sizeof(int),
247 .proc_handler
= proc_dointvec
250 .procname
= "tcp_fin_timeout",
251 .data
= &sysctl_tcp_fin_timeout
,
252 .maxlen
= sizeof(int),
254 .proc_handler
= proc_dointvec_jiffies
,
256 #ifdef CONFIG_SYN_COOKIES
258 .procname
= "tcp_syncookies",
259 .data
= &sysctl_tcp_syncookies
,
260 .maxlen
= sizeof(int),
262 .proc_handler
= proc_dointvec
266 .procname
= "tcp_tw_recycle",
267 .data
= &tcp_death_row
.sysctl_tw_recycle
,
268 .maxlen
= sizeof(int),
270 .proc_handler
= proc_dointvec
273 .procname
= "tcp_abort_on_overflow",
274 .data
= &sysctl_tcp_abort_on_overflow
,
275 .maxlen
= sizeof(int),
277 .proc_handler
= proc_dointvec
280 .procname
= "tcp_stdurg",
281 .data
= &sysctl_tcp_stdurg
,
282 .maxlen
= sizeof(int),
284 .proc_handler
= proc_dointvec
287 .procname
= "tcp_rfc1337",
288 .data
= &sysctl_tcp_rfc1337
,
289 .maxlen
= sizeof(int),
291 .proc_handler
= proc_dointvec
294 .procname
= "tcp_max_syn_backlog",
295 .data
= &sysctl_max_syn_backlog
,
296 .maxlen
= sizeof(int),
298 .proc_handler
= proc_dointvec
301 .procname
= "ip_local_port_range",
302 .data
= &sysctl_local_ports
.range
,
303 .maxlen
= sizeof(sysctl_local_ports
.range
),
305 .proc_handler
= ipv4_local_port_range
,
308 .procname
= "ip_local_reserved_ports",
309 .data
= NULL
, /* initialized in sysctl_ipv4_init */
312 .proc_handler
= proc_do_large_bitmap
,
315 .procname
= "igmp_max_memberships",
316 .data
= &sysctl_igmp_max_memberships
,
317 .maxlen
= sizeof(int),
319 .proc_handler
= proc_dointvec
322 .procname
= "igmp_max_msf",
323 .data
= &sysctl_igmp_max_msf
,
324 .maxlen
= sizeof(int),
326 .proc_handler
= proc_dointvec
329 .procname
= "inet_peer_threshold",
330 .data
= &inet_peer_threshold
,
331 .maxlen
= sizeof(int),
333 .proc_handler
= proc_dointvec
336 .procname
= "inet_peer_minttl",
337 .data
= &inet_peer_minttl
,
338 .maxlen
= sizeof(int),
340 .proc_handler
= proc_dointvec_jiffies
,
343 .procname
= "inet_peer_maxttl",
344 .data
= &inet_peer_maxttl
,
345 .maxlen
= sizeof(int),
347 .proc_handler
= proc_dointvec_jiffies
,
350 .procname
= "inet_peer_gc_mintime",
351 .data
= &inet_peer_gc_mintime
,
352 .maxlen
= sizeof(int),
354 .proc_handler
= proc_dointvec_jiffies
,
357 .procname
= "inet_peer_gc_maxtime",
358 .data
= &inet_peer_gc_maxtime
,
359 .maxlen
= sizeof(int),
361 .proc_handler
= proc_dointvec_jiffies
,
364 .procname
= "tcp_orphan_retries",
365 .data
= &sysctl_tcp_orphan_retries
,
366 .maxlen
= sizeof(int),
368 .proc_handler
= proc_dointvec
371 .procname
= "tcp_fack",
372 .data
= &sysctl_tcp_fack
,
373 .maxlen
= sizeof(int),
375 .proc_handler
= proc_dointvec
378 .procname
= "tcp_reordering",
379 .data
= &sysctl_tcp_reordering
,
380 .maxlen
= sizeof(int),
382 .proc_handler
= proc_dointvec
385 .procname
= "tcp_ecn",
386 .data
= &sysctl_tcp_ecn
,
387 .maxlen
= sizeof(int),
389 .proc_handler
= proc_dointvec
392 .procname
= "tcp_dsack",
393 .data
= &sysctl_tcp_dsack
,
394 .maxlen
= sizeof(int),
396 .proc_handler
= proc_dointvec
399 .procname
= "tcp_mem",
400 .data
= &sysctl_tcp_mem
,
401 .maxlen
= sizeof(sysctl_tcp_mem
),
403 .proc_handler
= proc_doulongvec_minmax
406 .procname
= "tcp_wmem",
407 .data
= &sysctl_tcp_wmem
,
408 .maxlen
= sizeof(sysctl_tcp_wmem
),
410 .proc_handler
= proc_dointvec
413 .procname
= "tcp_rmem",
414 .data
= &sysctl_tcp_rmem
,
415 .maxlen
= sizeof(sysctl_tcp_rmem
),
417 .proc_handler
= proc_dointvec
420 .procname
= "tcp_app_win",
421 .data
= &sysctl_tcp_app_win
,
422 .maxlen
= sizeof(int),
424 .proc_handler
= proc_dointvec
427 .procname
= "tcp_adv_win_scale",
428 .data
= &sysctl_tcp_adv_win_scale
,
429 .maxlen
= sizeof(int),
431 .proc_handler
= proc_dointvec_minmax
,
432 .extra1
= &tcp_adv_win_scale_min
,
433 .extra2
= &tcp_adv_win_scale_max
,
436 .procname
= "tcp_tw_reuse",
437 .data
= &sysctl_tcp_tw_reuse
,
438 .maxlen
= sizeof(int),
440 .proc_handler
= proc_dointvec
443 .procname
= "tcp_frto",
444 .data
= &sysctl_tcp_frto
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= proc_dointvec
450 .procname
= "tcp_frto_response",
451 .data
= &sysctl_tcp_frto_response
,
452 .maxlen
= sizeof(int),
454 .proc_handler
= proc_dointvec
457 .procname
= "tcp_low_latency",
458 .data
= &sysctl_tcp_low_latency
,
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
464 .procname
= "tcp_no_metrics_save",
465 .data
= &sysctl_tcp_nometrics_save
,
466 .maxlen
= sizeof(int),
468 .proc_handler
= proc_dointvec
,
471 .procname
= "tcp_moderate_rcvbuf",
472 .data
= &sysctl_tcp_moderate_rcvbuf
,
473 .maxlen
= sizeof(int),
475 .proc_handler
= proc_dointvec
,
478 .procname
= "tcp_tso_win_divisor",
479 .data
= &sysctl_tcp_tso_win_divisor
,
480 .maxlen
= sizeof(int),
482 .proc_handler
= proc_dointvec
,
485 .procname
= "tcp_congestion_control",
487 .maxlen
= TCP_CA_NAME_MAX
,
488 .proc_handler
= proc_tcp_congestion_control
,
491 .procname
= "tcp_abc",
492 .data
= &sysctl_tcp_abc
,
493 .maxlen
= sizeof(int),
495 .proc_handler
= proc_dointvec
,
498 .procname
= "tcp_mtu_probing",
499 .data
= &sysctl_tcp_mtu_probing
,
500 .maxlen
= sizeof(int),
502 .proc_handler
= proc_dointvec
,
505 .procname
= "tcp_base_mss",
506 .data
= &sysctl_tcp_base_mss
,
507 .maxlen
= sizeof(int),
509 .proc_handler
= proc_dointvec
,
512 .procname
= "tcp_workaround_signed_windows",
513 .data
= &sysctl_tcp_workaround_signed_windows
,
514 .maxlen
= sizeof(int),
516 .proc_handler
= proc_dointvec
518 #ifdef CONFIG_NET_DMA
520 .procname
= "tcp_dma_copybreak",
521 .data
= &sysctl_tcp_dma_copybreak
,
522 .maxlen
= sizeof(int),
524 .proc_handler
= proc_dointvec
528 .procname
= "tcp_slow_start_after_idle",
529 .data
= &sysctl_tcp_slow_start_after_idle
,
530 .maxlen
= sizeof(int),
532 .proc_handler
= proc_dointvec
534 #ifdef CONFIG_NETLABEL
536 .procname
= "cipso_cache_enable",
537 .data
= &cipso_v4_cache_enabled
,
538 .maxlen
= sizeof(int),
540 .proc_handler
= proc_dointvec
,
543 .procname
= "cipso_cache_bucket_size",
544 .data
= &cipso_v4_cache_bucketsize
,
545 .maxlen
= sizeof(int),
547 .proc_handler
= proc_dointvec
,
550 .procname
= "cipso_rbm_optfmt",
551 .data
= &cipso_v4_rbm_optfmt
,
552 .maxlen
= sizeof(int),
554 .proc_handler
= proc_dointvec
,
557 .procname
= "cipso_rbm_strictvalid",
558 .data
= &cipso_v4_rbm_strictvalid
,
559 .maxlen
= sizeof(int),
561 .proc_handler
= proc_dointvec
,
563 #endif /* CONFIG_NETLABEL */
565 .procname
= "tcp_available_congestion_control",
566 .maxlen
= TCP_CA_BUF_MAX
,
568 .proc_handler
= proc_tcp_available_congestion_control
,
571 .procname
= "tcp_allowed_congestion_control",
572 .maxlen
= TCP_CA_BUF_MAX
,
574 .proc_handler
= proc_allowed_congestion_control
,
577 .procname
= "tcp_max_ssthresh",
578 .data
= &sysctl_tcp_max_ssthresh
,
579 .maxlen
= sizeof(int),
581 .proc_handler
= proc_dointvec
,
584 .procname
= "tcp_cookie_size",
585 .data
= &sysctl_tcp_cookie_size
,
586 .maxlen
= sizeof(int),
588 .proc_handler
= proc_dointvec
591 .procname
= "tcp_thin_linear_timeouts",
592 .data
= &sysctl_tcp_thin_linear_timeouts
,
593 .maxlen
= sizeof(int),
595 .proc_handler
= proc_dointvec
598 .procname
= "tcp_thin_dupack",
599 .data
= &sysctl_tcp_thin_dupack
,
600 .maxlen
= sizeof(int),
602 .proc_handler
= proc_dointvec
605 .procname
= "udp_mem",
606 .data
= &sysctl_udp_mem
,
607 .maxlen
= sizeof(sysctl_udp_mem
),
609 .proc_handler
= proc_doulongvec_minmax
,
612 .procname
= "udp_rmem_min",
613 .data
= &sysctl_udp_rmem_min
,
614 .maxlen
= sizeof(sysctl_udp_rmem_min
),
616 .proc_handler
= proc_dointvec_minmax
,
620 .procname
= "udp_wmem_min",
621 .data
= &sysctl_udp_wmem_min
,
622 .maxlen
= sizeof(sysctl_udp_wmem_min
),
624 .proc_handler
= proc_dointvec_minmax
,
630 static struct ctl_table ipv4_net_table
[] = {
632 .procname
= "icmp_echo_ignore_all",
633 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_all
,
634 .maxlen
= sizeof(int),
636 .proc_handler
= proc_dointvec
639 .procname
= "icmp_echo_ignore_broadcasts",
640 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_broadcasts
,
641 .maxlen
= sizeof(int),
643 .proc_handler
= proc_dointvec
646 .procname
= "icmp_ignore_bogus_error_responses",
647 .data
= &init_net
.ipv4
.sysctl_icmp_ignore_bogus_error_responses
,
648 .maxlen
= sizeof(int),
650 .proc_handler
= proc_dointvec
653 .procname
= "icmp_errors_use_inbound_ifaddr",
654 .data
= &init_net
.ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
,
655 .maxlen
= sizeof(int),
657 .proc_handler
= proc_dointvec
660 .procname
= "icmp_ratelimit",
661 .data
= &init_net
.ipv4
.sysctl_icmp_ratelimit
,
662 .maxlen
= sizeof(int),
664 .proc_handler
= proc_dointvec_ms_jiffies
,
667 .procname
= "icmp_ratemask",
668 .data
= &init_net
.ipv4
.sysctl_icmp_ratemask
,
669 .maxlen
= sizeof(int),
671 .proc_handler
= proc_dointvec
674 .procname
= "rt_cache_rebuild_count",
675 .data
= &init_net
.ipv4
.sysctl_rt_cache_rebuild_count
,
676 .maxlen
= sizeof(int),
678 .proc_handler
= proc_dointvec
683 struct ctl_path net_ipv4_ctl_path
[] = {
684 { .procname
= "net", },
685 { .procname
= "ipv4", },
688 EXPORT_SYMBOL_GPL(net_ipv4_ctl_path
);
690 static __net_init
int ipv4_sysctl_init_net(struct net
*net
)
692 struct ctl_table
*table
;
694 table
= ipv4_net_table
;
695 if (!net_eq(net
, &init_net
)) {
696 table
= kmemdup(table
, sizeof(ipv4_net_table
), GFP_KERNEL
);
701 &net
->ipv4
.sysctl_icmp_echo_ignore_all
;
703 &net
->ipv4
.sysctl_icmp_echo_ignore_broadcasts
;
705 &net
->ipv4
.sysctl_icmp_ignore_bogus_error_responses
;
707 &net
->ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
;
709 &net
->ipv4
.sysctl_icmp_ratelimit
;
711 &net
->ipv4
.sysctl_icmp_ratemask
;
713 &net
->ipv4
.sysctl_rt_cache_rebuild_count
;
716 net
->ipv4
.sysctl_rt_cache_rebuild_count
= 4;
718 net
->ipv4
.ipv4_hdr
= register_net_sysctl_table(net
,
719 net_ipv4_ctl_path
, table
);
720 if (net
->ipv4
.ipv4_hdr
== NULL
)
726 if (!net_eq(net
, &init_net
))
732 static __net_exit
void ipv4_sysctl_exit_net(struct net
*net
)
734 struct ctl_table
*table
;
736 table
= net
->ipv4
.ipv4_hdr
->ctl_table_arg
;
737 unregister_net_sysctl_table(net
->ipv4
.ipv4_hdr
);
741 static __net_initdata
struct pernet_operations ipv4_sysctl_ops
= {
742 .init
= ipv4_sysctl_init_net
,
743 .exit
= ipv4_sysctl_exit_net
,
746 static __init
int sysctl_ipv4_init(void)
748 struct ctl_table_header
*hdr
;
751 for (i
= ipv4_table
; i
->procname
; i
++) {
752 if (strcmp(i
->procname
, "ip_local_reserved_ports") == 0) {
753 i
->data
= sysctl_local_reserved_ports
;
760 hdr
= register_sysctl_paths(net_ipv4_ctl_path
, ipv4_table
);
764 if (register_pernet_subsys(&ipv4_sysctl_ops
)) {
765 unregister_sysctl_table(hdr
);
772 __initcall(sysctl_ipv4_init
);