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>
17 #include <linux/swap.h>
21 #include <net/route.h>
24 #include <net/cipso_ipv4.h>
25 #include <net/inet_frag.h>
27 #include <net/tcp_memcontrol.h>
32 static int gso_max_segs
= GSO_MAX_SEGS
;
33 static int tcp_retr1_max
= 255;
34 static int ip_local_port_range_min
[] = { 1, 1 };
35 static int ip_local_port_range_max
[] = { 65535, 65535 };
36 static int tcp_adv_win_scale_min
= -31;
37 static int tcp_adv_win_scale_max
= 31;
38 static int ip_ttl_min
= 1;
39 static int ip_ttl_max
= 255;
40 static int tcp_syn_retries_min
= 1;
41 static int tcp_syn_retries_max
= MAX_TCP_SYNCNT
;
42 static int ip_ping_group_range_min
[] = { 0, 0 };
43 static int ip_ping_group_range_max
[] = { GID_T_MAX
, GID_T_MAX
};
45 /* Update system visible IP port range */
46 static void set_local_port_range(struct net
*net
, int range
[2])
48 write_seqlock(&net
->ipv4
.sysctl_local_ports
.lock
);
49 net
->ipv4
.sysctl_local_ports
.range
[0] = range
[0];
50 net
->ipv4
.sysctl_local_ports
.range
[1] = range
[1];
51 write_sequnlock(&net
->ipv4
.sysctl_local_ports
.lock
);
54 /* Validate changes from /proc interface. */
55 static int ipv4_local_port_range(struct ctl_table
*table
, int write
,
57 size_t *lenp
, loff_t
*ppos
)
60 container_of(table
->data
, struct net
, ipv4
.sysctl_local_ports
.range
);
63 struct ctl_table tmp
= {
65 .maxlen
= sizeof(range
),
67 .extra1
= &ip_local_port_range_min
,
68 .extra2
= &ip_local_port_range_max
,
71 inet_get_local_port_range(net
, &range
[0], &range
[1]);
73 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
75 if (write
&& ret
== 0) {
76 if (range
[1] < range
[0])
79 set_local_port_range(net
, range
);
86 static void inet_get_ping_group_range_table(struct ctl_table
*table
, kgid_t
*low
, kgid_t
*high
)
88 kgid_t
*data
= table
->data
;
90 container_of(table
->data
, struct net
, ipv4
.sysctl_ping_group_range
);
93 seq
= read_seqbegin(&net
->ipv4
.sysctl_local_ports
.lock
);
97 } while (read_seqretry(&net
->ipv4
.sysctl_local_ports
.lock
, seq
));
100 /* Update system visible IP port range */
101 static void set_ping_group_range(struct ctl_table
*table
, kgid_t low
, kgid_t high
)
103 kgid_t
*data
= table
->data
;
105 container_of(table
->data
, struct net
, ipv4
.sysctl_ping_group_range
);
106 write_seqlock(&net
->ipv4
.sysctl_local_ports
.lock
);
109 write_sequnlock(&net
->ipv4
.sysctl_local_ports
.lock
);
112 /* Validate changes from /proc interface. */
113 static int ipv4_ping_group_range(struct ctl_table
*table
, int write
,
115 size_t *lenp
, loff_t
*ppos
)
117 struct user_namespace
*user_ns
= current_user_ns();
121 struct ctl_table tmp
= {
123 .maxlen
= sizeof(urange
),
125 .extra1
= &ip_ping_group_range_min
,
126 .extra2
= &ip_ping_group_range_max
,
129 inet_get_ping_group_range_table(table
, &low
, &high
);
130 urange
[0] = from_kgid_munged(user_ns
, low
);
131 urange
[1] = from_kgid_munged(user_ns
, high
);
132 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
134 if (write
&& ret
== 0) {
135 low
= make_kgid(user_ns
, urange
[0]);
136 high
= make_kgid(user_ns
, urange
[1]);
137 if (!gid_valid(low
) || !gid_valid(high
) ||
138 (urange
[1] < urange
[0]) || gid_lt(high
, low
)) {
139 low
= make_kgid(&init_user_ns
, 1);
140 high
= make_kgid(&init_user_ns
, 0);
142 set_ping_group_range(table
, low
, high
);
148 static int proc_tcp_congestion_control(struct ctl_table
*ctl
, int write
,
149 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
151 char val
[TCP_CA_NAME_MAX
];
152 struct ctl_table tbl
= {
154 .maxlen
= TCP_CA_NAME_MAX
,
158 tcp_get_default_congestion_control(val
);
160 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
161 if (write
&& ret
== 0)
162 ret
= tcp_set_default_congestion_control(val
);
166 static int proc_tcp_available_congestion_control(struct ctl_table
*ctl
,
168 void __user
*buffer
, size_t *lenp
,
171 struct ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
, };
174 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
177 tcp_get_available_congestion_control(tbl
.data
, TCP_CA_BUF_MAX
);
178 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
183 static int proc_allowed_congestion_control(struct ctl_table
*ctl
,
185 void __user
*buffer
, size_t *lenp
,
188 struct ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
};
191 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
195 tcp_get_allowed_congestion_control(tbl
.data
, tbl
.maxlen
);
196 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
197 if (write
&& ret
== 0)
198 ret
= tcp_set_allowed_congestion_control(tbl
.data
);
203 static int ipv4_tcp_mem(struct ctl_table
*ctl
, int write
,
204 void __user
*buffer
, size_t *lenp
,
207 ctl
->data
= ¤t
->nsproxy
->net_ns
->ipv4
.sysctl_tcp_mem
;
208 return proc_doulongvec_minmax(ctl
, write
, buffer
, lenp
, ppos
);
211 static int proc_tcp_fastopen_key(struct ctl_table
*ctl
, int write
,
212 void __user
*buffer
, size_t *lenp
,
215 struct ctl_table tbl
= { .maxlen
= (TCP_FASTOPEN_KEY_LENGTH
* 2 + 10) };
216 struct tcp_fastopen_context
*ctxt
;
218 u32 user_key
[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
220 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_KERNEL
);
225 ctxt
= rcu_dereference(tcp_fastopen_ctx
);
227 memcpy(user_key
, ctxt
->key
, TCP_FASTOPEN_KEY_LENGTH
);
229 memset(user_key
, 0, sizeof(user_key
));
232 snprintf(tbl
.data
, tbl
.maxlen
, "%08x-%08x-%08x-%08x",
233 user_key
[0], user_key
[1], user_key
[2], user_key
[3]);
234 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
236 if (write
&& ret
== 0) {
237 if (sscanf(tbl
.data
, "%x-%x-%x-%x", user_key
, user_key
+ 1,
238 user_key
+ 2, user_key
+ 3) != 4) {
242 /* Generate a dummy secret but don't publish it. This
243 * is needed so we don't regenerate a new key on the
244 * first invocation of tcp_fastopen_cookie_gen
246 tcp_fastopen_init_key_once(false);
247 tcp_fastopen_reset_cipher(user_key
, TCP_FASTOPEN_KEY_LENGTH
);
251 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
252 user_key
[0], user_key
[1], user_key
[2], user_key
[3],
253 (char *)tbl
.data
, ret
);
258 static struct ctl_table ipv4_table
[] = {
260 .procname
= "tcp_timestamps",
261 .data
= &sysctl_tcp_timestamps
,
262 .maxlen
= sizeof(int),
264 .proc_handler
= proc_dointvec
267 .procname
= "tcp_window_scaling",
268 .data
= &sysctl_tcp_window_scaling
,
269 .maxlen
= sizeof(int),
271 .proc_handler
= proc_dointvec
274 .procname
= "tcp_sack",
275 .data
= &sysctl_tcp_sack
,
276 .maxlen
= sizeof(int),
278 .proc_handler
= proc_dointvec
281 .procname
= "tcp_retrans_collapse",
282 .data
= &sysctl_tcp_retrans_collapse
,
283 .maxlen
= sizeof(int),
285 .proc_handler
= proc_dointvec
288 .procname
= "ip_default_ttl",
289 .data
= &sysctl_ip_default_ttl
,
290 .maxlen
= sizeof(int),
292 .proc_handler
= proc_dointvec_minmax
,
293 .extra1
= &ip_ttl_min
,
294 .extra2
= &ip_ttl_max
,
297 .procname
= "ip_no_pmtu_disc",
298 .data
= &ipv4_config
.no_pmtu_disc
,
299 .maxlen
= sizeof(int),
301 .proc_handler
= proc_dointvec
304 .procname
= "ip_nonlocal_bind",
305 .data
= &sysctl_ip_nonlocal_bind
,
306 .maxlen
= sizeof(int),
308 .proc_handler
= proc_dointvec
311 .procname
= "tcp_syn_retries",
312 .data
= &sysctl_tcp_syn_retries
,
313 .maxlen
= sizeof(int),
315 .proc_handler
= proc_dointvec_minmax
,
316 .extra1
= &tcp_syn_retries_min
,
317 .extra2
= &tcp_syn_retries_max
320 .procname
= "tcp_synack_retries",
321 .data
= &sysctl_tcp_synack_retries
,
322 .maxlen
= sizeof(int),
324 .proc_handler
= proc_dointvec
327 .procname
= "tcp_max_orphans",
328 .data
= &sysctl_tcp_max_orphans
,
329 .maxlen
= sizeof(int),
331 .proc_handler
= proc_dointvec
334 .procname
= "tcp_max_tw_buckets",
335 .data
= &tcp_death_row
.sysctl_max_tw_buckets
,
336 .maxlen
= sizeof(int),
338 .proc_handler
= proc_dointvec
341 .procname
= "ip_early_demux",
342 .data
= &sysctl_ip_early_demux
,
343 .maxlen
= sizeof(int),
345 .proc_handler
= proc_dointvec
348 .procname
= "ip_dynaddr",
349 .data
= &sysctl_ip_dynaddr
,
350 .maxlen
= sizeof(int),
352 .proc_handler
= proc_dointvec
355 .procname
= "tcp_keepalive_time",
356 .data
= &sysctl_tcp_keepalive_time
,
357 .maxlen
= sizeof(int),
359 .proc_handler
= proc_dointvec_jiffies
,
362 .procname
= "tcp_keepalive_probes",
363 .data
= &sysctl_tcp_keepalive_probes
,
364 .maxlen
= sizeof(int),
366 .proc_handler
= proc_dointvec
369 .procname
= "tcp_keepalive_intvl",
370 .data
= &sysctl_tcp_keepalive_intvl
,
371 .maxlen
= sizeof(int),
373 .proc_handler
= proc_dointvec_jiffies
,
376 .procname
= "tcp_retries1",
377 .data
= &sysctl_tcp_retries1
,
378 .maxlen
= sizeof(int),
380 .proc_handler
= proc_dointvec_minmax
,
381 .extra2
= &tcp_retr1_max
384 .procname
= "tcp_retries2",
385 .data
= &sysctl_tcp_retries2
,
386 .maxlen
= sizeof(int),
388 .proc_handler
= proc_dointvec
391 .procname
= "tcp_fin_timeout",
392 .data
= &sysctl_tcp_fin_timeout
,
393 .maxlen
= sizeof(int),
395 .proc_handler
= proc_dointvec_jiffies
,
397 #ifdef CONFIG_SYN_COOKIES
399 .procname
= "tcp_syncookies",
400 .data
= &sysctl_tcp_syncookies
,
401 .maxlen
= sizeof(int),
403 .proc_handler
= proc_dointvec
407 .procname
= "tcp_fastopen",
408 .data
= &sysctl_tcp_fastopen
,
409 .maxlen
= sizeof(int),
411 .proc_handler
= proc_dointvec
,
414 .procname
= "tcp_fastopen_key",
416 .maxlen
= ((TCP_FASTOPEN_KEY_LENGTH
* 2) + 10),
417 .proc_handler
= proc_tcp_fastopen_key
,
420 .procname
= "tcp_tw_recycle",
421 .data
= &tcp_death_row
.sysctl_tw_recycle
,
422 .maxlen
= sizeof(int),
424 .proc_handler
= proc_dointvec
427 .procname
= "tcp_abort_on_overflow",
428 .data
= &sysctl_tcp_abort_on_overflow
,
429 .maxlen
= sizeof(int),
431 .proc_handler
= proc_dointvec
434 .procname
= "tcp_stdurg",
435 .data
= &sysctl_tcp_stdurg
,
436 .maxlen
= sizeof(int),
438 .proc_handler
= proc_dointvec
441 .procname
= "tcp_rfc1337",
442 .data
= &sysctl_tcp_rfc1337
,
443 .maxlen
= sizeof(int),
445 .proc_handler
= proc_dointvec
448 .procname
= "tcp_max_syn_backlog",
449 .data
= &sysctl_max_syn_backlog
,
450 .maxlen
= sizeof(int),
452 .proc_handler
= proc_dointvec
455 .procname
= "ip_local_reserved_ports",
456 .data
= NULL
, /* initialized in sysctl_ipv4_init */
459 .proc_handler
= proc_do_large_bitmap
,
462 .procname
= "igmp_max_memberships",
463 .data
= &sysctl_igmp_max_memberships
,
464 .maxlen
= sizeof(int),
466 .proc_handler
= proc_dointvec
469 .procname
= "igmp_max_msf",
470 .data
= &sysctl_igmp_max_msf
,
471 .maxlen
= sizeof(int),
473 .proc_handler
= proc_dointvec
476 .procname
= "inet_peer_threshold",
477 .data
= &inet_peer_threshold
,
478 .maxlen
= sizeof(int),
480 .proc_handler
= proc_dointvec
483 .procname
= "inet_peer_minttl",
484 .data
= &inet_peer_minttl
,
485 .maxlen
= sizeof(int),
487 .proc_handler
= proc_dointvec_jiffies
,
490 .procname
= "inet_peer_maxttl",
491 .data
= &inet_peer_maxttl
,
492 .maxlen
= sizeof(int),
494 .proc_handler
= proc_dointvec_jiffies
,
497 .procname
= "tcp_orphan_retries",
498 .data
= &sysctl_tcp_orphan_retries
,
499 .maxlen
= sizeof(int),
501 .proc_handler
= proc_dointvec
504 .procname
= "tcp_fack",
505 .data
= &sysctl_tcp_fack
,
506 .maxlen
= sizeof(int),
508 .proc_handler
= proc_dointvec
511 .procname
= "tcp_reordering",
512 .data
= &sysctl_tcp_reordering
,
513 .maxlen
= sizeof(int),
515 .proc_handler
= proc_dointvec
518 .procname
= "tcp_dsack",
519 .data
= &sysctl_tcp_dsack
,
520 .maxlen
= sizeof(int),
522 .proc_handler
= proc_dointvec
525 .procname
= "tcp_wmem",
526 .data
= &sysctl_tcp_wmem
,
527 .maxlen
= sizeof(sysctl_tcp_wmem
),
529 .proc_handler
= proc_dointvec_minmax
,
533 .procname
= "tcp_notsent_lowat",
534 .data
= &sysctl_tcp_notsent_lowat
,
535 .maxlen
= sizeof(sysctl_tcp_notsent_lowat
),
537 .proc_handler
= proc_dointvec
,
540 .procname
= "tcp_rmem",
541 .data
= &sysctl_tcp_rmem
,
542 .maxlen
= sizeof(sysctl_tcp_rmem
),
544 .proc_handler
= proc_dointvec_minmax
,
548 .procname
= "tcp_app_win",
549 .data
= &sysctl_tcp_app_win
,
550 .maxlen
= sizeof(int),
552 .proc_handler
= proc_dointvec
555 .procname
= "tcp_adv_win_scale",
556 .data
= &sysctl_tcp_adv_win_scale
,
557 .maxlen
= sizeof(int),
559 .proc_handler
= proc_dointvec_minmax
,
560 .extra1
= &tcp_adv_win_scale_min
,
561 .extra2
= &tcp_adv_win_scale_max
,
564 .procname
= "tcp_tw_reuse",
565 .data
= &sysctl_tcp_tw_reuse
,
566 .maxlen
= sizeof(int),
568 .proc_handler
= proc_dointvec
571 .procname
= "tcp_frto",
572 .data
= &sysctl_tcp_frto
,
573 .maxlen
= sizeof(int),
575 .proc_handler
= proc_dointvec
578 .procname
= "tcp_low_latency",
579 .data
= &sysctl_tcp_low_latency
,
580 .maxlen
= sizeof(int),
582 .proc_handler
= proc_dointvec
585 .procname
= "tcp_no_metrics_save",
586 .data
= &sysctl_tcp_nometrics_save
,
587 .maxlen
= sizeof(int),
589 .proc_handler
= proc_dointvec
,
592 .procname
= "tcp_moderate_rcvbuf",
593 .data
= &sysctl_tcp_moderate_rcvbuf
,
594 .maxlen
= sizeof(int),
596 .proc_handler
= proc_dointvec
,
599 .procname
= "tcp_tso_win_divisor",
600 .data
= &sysctl_tcp_tso_win_divisor
,
601 .maxlen
= sizeof(int),
603 .proc_handler
= proc_dointvec
,
606 .procname
= "tcp_congestion_control",
608 .maxlen
= TCP_CA_NAME_MAX
,
609 .proc_handler
= proc_tcp_congestion_control
,
612 .procname
= "tcp_mtu_probing",
613 .data
= &sysctl_tcp_mtu_probing
,
614 .maxlen
= sizeof(int),
616 .proc_handler
= proc_dointvec
,
619 .procname
= "tcp_base_mss",
620 .data
= &sysctl_tcp_base_mss
,
621 .maxlen
= sizeof(int),
623 .proc_handler
= proc_dointvec
,
626 .procname
= "tcp_workaround_signed_windows",
627 .data
= &sysctl_tcp_workaround_signed_windows
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= proc_dointvec
633 .procname
= "tcp_limit_output_bytes",
634 .data
= &sysctl_tcp_limit_output_bytes
,
635 .maxlen
= sizeof(int),
637 .proc_handler
= proc_dointvec
640 .procname
= "tcp_challenge_ack_limit",
641 .data
= &sysctl_tcp_challenge_ack_limit
,
642 .maxlen
= sizeof(int),
644 .proc_handler
= proc_dointvec
646 #ifdef CONFIG_NET_DMA
648 .procname
= "tcp_dma_copybreak",
649 .data
= &sysctl_tcp_dma_copybreak
,
650 .maxlen
= sizeof(int),
652 .proc_handler
= proc_dointvec
656 .procname
= "tcp_slow_start_after_idle",
657 .data
= &sysctl_tcp_slow_start_after_idle
,
658 .maxlen
= sizeof(int),
660 .proc_handler
= proc_dointvec
662 #ifdef CONFIG_NETLABEL
664 .procname
= "cipso_cache_enable",
665 .data
= &cipso_v4_cache_enabled
,
666 .maxlen
= sizeof(int),
668 .proc_handler
= proc_dointvec
,
671 .procname
= "cipso_cache_bucket_size",
672 .data
= &cipso_v4_cache_bucketsize
,
673 .maxlen
= sizeof(int),
675 .proc_handler
= proc_dointvec
,
678 .procname
= "cipso_rbm_optfmt",
679 .data
= &cipso_v4_rbm_optfmt
,
680 .maxlen
= sizeof(int),
682 .proc_handler
= proc_dointvec
,
685 .procname
= "cipso_rbm_strictvalid",
686 .data
= &cipso_v4_rbm_strictvalid
,
687 .maxlen
= sizeof(int),
689 .proc_handler
= proc_dointvec
,
691 #endif /* CONFIG_NETLABEL */
693 .procname
= "tcp_available_congestion_control",
694 .maxlen
= TCP_CA_BUF_MAX
,
696 .proc_handler
= proc_tcp_available_congestion_control
,
699 .procname
= "tcp_allowed_congestion_control",
700 .maxlen
= TCP_CA_BUF_MAX
,
702 .proc_handler
= proc_allowed_congestion_control
,
705 .procname
= "tcp_max_ssthresh",
706 .data
= &sysctl_tcp_max_ssthresh
,
707 .maxlen
= sizeof(int),
709 .proc_handler
= proc_dointvec
,
712 .procname
= "tcp_thin_linear_timeouts",
713 .data
= &sysctl_tcp_thin_linear_timeouts
,
714 .maxlen
= sizeof(int),
716 .proc_handler
= proc_dointvec
719 .procname
= "tcp_thin_dupack",
720 .data
= &sysctl_tcp_thin_dupack
,
721 .maxlen
= sizeof(int),
723 .proc_handler
= proc_dointvec
726 .procname
= "tcp_early_retrans",
727 .data
= &sysctl_tcp_early_retrans
,
728 .maxlen
= sizeof(int),
730 .proc_handler
= proc_dointvec_minmax
,
735 .procname
= "tcp_min_tso_segs",
736 .data
= &sysctl_tcp_min_tso_segs
,
737 .maxlen
= sizeof(int),
739 .proc_handler
= proc_dointvec_minmax
,
741 .extra2
= &gso_max_segs
,
744 .procname
= "udp_mem",
745 .data
= &sysctl_udp_mem
,
746 .maxlen
= sizeof(sysctl_udp_mem
),
748 .proc_handler
= proc_doulongvec_minmax
,
751 .procname
= "udp_rmem_min",
752 .data
= &sysctl_udp_rmem_min
,
753 .maxlen
= sizeof(sysctl_udp_rmem_min
),
755 .proc_handler
= proc_dointvec_minmax
,
759 .procname
= "udp_wmem_min",
760 .data
= &sysctl_udp_wmem_min
,
761 .maxlen
= sizeof(sysctl_udp_wmem_min
),
763 .proc_handler
= proc_dointvec_minmax
,
769 static struct ctl_table ipv4_net_table
[] = {
771 .procname
= "icmp_echo_ignore_all",
772 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_all
,
773 .maxlen
= sizeof(int),
775 .proc_handler
= proc_dointvec
778 .procname
= "icmp_echo_ignore_broadcasts",
779 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_broadcasts
,
780 .maxlen
= sizeof(int),
782 .proc_handler
= proc_dointvec
785 .procname
= "icmp_ignore_bogus_error_responses",
786 .data
= &init_net
.ipv4
.sysctl_icmp_ignore_bogus_error_responses
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= proc_dointvec
792 .procname
= "icmp_errors_use_inbound_ifaddr",
793 .data
= &init_net
.ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
,
794 .maxlen
= sizeof(int),
796 .proc_handler
= proc_dointvec
799 .procname
= "icmp_ratelimit",
800 .data
= &init_net
.ipv4
.sysctl_icmp_ratelimit
,
801 .maxlen
= sizeof(int),
803 .proc_handler
= proc_dointvec_ms_jiffies
,
806 .procname
= "icmp_ratemask",
807 .data
= &init_net
.ipv4
.sysctl_icmp_ratemask
,
808 .maxlen
= sizeof(int),
810 .proc_handler
= proc_dointvec
813 .procname
= "ping_group_range",
814 .data
= &init_net
.ipv4
.sysctl_ping_group_range
,
815 .maxlen
= sizeof(gid_t
)*2,
817 .proc_handler
= ipv4_ping_group_range
,
820 .procname
= "tcp_ecn",
821 .data
= &init_net
.ipv4
.sysctl_tcp_ecn
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= proc_dointvec
827 .procname
= "ip_local_port_range",
828 .maxlen
= sizeof(init_net
.ipv4
.sysctl_local_ports
.range
),
829 .data
= &init_net
.ipv4
.sysctl_local_ports
.range
,
831 .proc_handler
= ipv4_local_port_range
,
834 .procname
= "tcp_mem",
835 .maxlen
= sizeof(init_net
.ipv4
.sysctl_tcp_mem
),
837 .proc_handler
= ipv4_tcp_mem
,
842 static __net_init
int ipv4_sysctl_init_net(struct net
*net
)
844 struct ctl_table
*table
;
846 table
= ipv4_net_table
;
847 if (!net_eq(net
, &init_net
)) {
848 table
= kmemdup(table
, sizeof(ipv4_net_table
), GFP_KERNEL
);
853 &net
->ipv4
.sysctl_icmp_echo_ignore_all
;
855 &net
->ipv4
.sysctl_icmp_echo_ignore_broadcasts
;
857 &net
->ipv4
.sysctl_icmp_ignore_bogus_error_responses
;
859 &net
->ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
;
861 &net
->ipv4
.sysctl_icmp_ratelimit
;
863 &net
->ipv4
.sysctl_icmp_ratemask
;
865 &net
->ipv4
.sysctl_ping_group_range
;
867 &net
->ipv4
.sysctl_tcp_ecn
;
869 &net
->ipv4
.sysctl_local_ports
.range
;
871 /* Don't export sysctls to unprivileged users */
872 if (net
->user_ns
!= &init_user_ns
)
873 table
[0].procname
= NULL
;
877 * Sane defaults - nobody may create ping sockets.
878 * Boot scripts should set this to distro-specific group.
880 net
->ipv4
.sysctl_ping_group_range
[0] = make_kgid(&init_user_ns
, 1);
881 net
->ipv4
.sysctl_ping_group_range
[1] = make_kgid(&init_user_ns
, 0);
884 * Set defaults for local port range
886 seqlock_init(&net
->ipv4
.sysctl_local_ports
.lock
);
887 net
->ipv4
.sysctl_local_ports
.range
[0] = 32768;
888 net
->ipv4
.sysctl_local_ports
.range
[1] = 61000;
892 net
->ipv4
.ipv4_hdr
= register_net_sysctl(net
, "net/ipv4", table
);
893 if (net
->ipv4
.ipv4_hdr
== NULL
)
899 if (!net_eq(net
, &init_net
))
905 static __net_exit
void ipv4_sysctl_exit_net(struct net
*net
)
907 struct ctl_table
*table
;
909 table
= net
->ipv4
.ipv4_hdr
->ctl_table_arg
;
910 unregister_net_sysctl_table(net
->ipv4
.ipv4_hdr
);
914 static __net_initdata
struct pernet_operations ipv4_sysctl_ops
= {
915 .init
= ipv4_sysctl_init_net
,
916 .exit
= ipv4_sysctl_exit_net
,
919 static __init
int sysctl_ipv4_init(void)
921 struct ctl_table_header
*hdr
;
924 for (i
= ipv4_table
; i
->procname
; i
++) {
925 if (strcmp(i
->procname
, "ip_local_reserved_ports") == 0) {
926 i
->data
= sysctl_local_reserved_ports
;
933 hdr
= register_net_sysctl(&init_net
, "net/ipv4", ipv4_table
);
937 if (register_pernet_subsys(&ipv4_sysctl_ops
)) {
938 unregister_net_sysctl_table(hdr
);
945 __initcall(sysctl_ipv4_init
);