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(int range
[2])
48 write_seqlock(&sysctl_local_ports
.lock
);
49 sysctl_local_ports
.range
[0] = range
[0];
50 sysctl_local_ports
.range
[1] = range
[1];
51 write_sequnlock(&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
)
61 struct ctl_table tmp
= {
63 .maxlen
= sizeof(range
),
65 .extra1
= &ip_local_port_range_min
,
66 .extra2
= &ip_local_port_range_max
,
69 inet_get_local_port_range(range
, range
+ 1);
70 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
72 if (write
&& ret
== 0) {
73 if (range
[1] < range
[0])
76 set_local_port_range(range
);
83 static void inet_get_ping_group_range_table(struct ctl_table
*table
, kgid_t
*low
, kgid_t
*high
)
85 kgid_t
*data
= table
->data
;
88 seq
= read_seqbegin(&sysctl_local_ports
.lock
);
92 } while (read_seqretry(&sysctl_local_ports
.lock
, seq
));
95 /* Update system visible IP port range */
96 static void set_ping_group_range(struct ctl_table
*table
, kgid_t low
, kgid_t high
)
98 kgid_t
*data
= table
->data
;
99 write_seqlock(&sysctl_local_ports
.lock
);
102 write_sequnlock(&sysctl_local_ports
.lock
);
105 /* Validate changes from /proc interface. */
106 static int ipv4_ping_group_range(struct ctl_table
*table
, int write
,
108 size_t *lenp
, loff_t
*ppos
)
110 struct user_namespace
*user_ns
= current_user_ns();
114 struct ctl_table tmp
= {
116 .maxlen
= sizeof(urange
),
118 .extra1
= &ip_ping_group_range_min
,
119 .extra2
= &ip_ping_group_range_max
,
122 inet_get_ping_group_range_table(table
, &low
, &high
);
123 urange
[0] = from_kgid_munged(user_ns
, low
);
124 urange
[1] = from_kgid_munged(user_ns
, high
);
125 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
127 if (write
&& ret
== 0) {
128 low
= make_kgid(user_ns
, urange
[0]);
129 high
= make_kgid(user_ns
, urange
[1]);
130 if (!gid_valid(low
) || !gid_valid(high
) ||
131 (urange
[1] < urange
[0]) || gid_lt(high
, low
)) {
132 low
= make_kgid(&init_user_ns
, 1);
133 high
= make_kgid(&init_user_ns
, 0);
135 set_ping_group_range(table
, low
, high
);
141 static int proc_tcp_congestion_control(struct ctl_table
*ctl
, int write
,
142 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
144 char val
[TCP_CA_NAME_MAX
];
145 struct ctl_table tbl
= {
147 .maxlen
= TCP_CA_NAME_MAX
,
151 tcp_get_default_congestion_control(val
);
153 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
154 if (write
&& ret
== 0)
155 ret
= tcp_set_default_congestion_control(val
);
159 static int proc_tcp_available_congestion_control(struct ctl_table
*ctl
,
161 void __user
*buffer
, size_t *lenp
,
164 struct ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
, };
167 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
170 tcp_get_available_congestion_control(tbl
.data
, TCP_CA_BUF_MAX
);
171 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
176 static int proc_allowed_congestion_control(struct ctl_table
*ctl
,
178 void __user
*buffer
, size_t *lenp
,
181 struct ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
};
184 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
188 tcp_get_allowed_congestion_control(tbl
.data
, tbl
.maxlen
);
189 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
190 if (write
&& ret
== 0)
191 ret
= tcp_set_allowed_congestion_control(tbl
.data
);
196 static int ipv4_tcp_mem(struct ctl_table
*ctl
, int write
,
197 void __user
*buffer
, size_t *lenp
,
201 unsigned long vec
[3];
202 struct net
*net
= current
->nsproxy
->net_ns
;
203 #ifdef CONFIG_MEMCG_KMEM
204 struct mem_cgroup
*memcg
;
207 struct ctl_table tmp
= {
209 .maxlen
= sizeof(vec
),
214 ctl
->data
= &net
->ipv4
.sysctl_tcp_mem
;
215 return proc_doulongvec_minmax(ctl
, write
, buffer
, lenp
, ppos
);
218 ret
= proc_doulongvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
222 #ifdef CONFIG_MEMCG_KMEM
224 memcg
= mem_cgroup_from_task(current
);
226 tcp_prot_mem(memcg
, vec
[0], 0);
227 tcp_prot_mem(memcg
, vec
[1], 1);
228 tcp_prot_mem(memcg
, vec
[2], 2);
232 net
->ipv4
.sysctl_tcp_mem
[0] = vec
[0];
233 net
->ipv4
.sysctl_tcp_mem
[1] = vec
[1];
234 net
->ipv4
.sysctl_tcp_mem
[2] = vec
[2];
239 static int proc_tcp_fastopen_key(struct ctl_table
*ctl
, int write
,
240 void __user
*buffer
, size_t *lenp
,
243 struct ctl_table tbl
= { .maxlen
= (TCP_FASTOPEN_KEY_LENGTH
* 2 + 10) };
244 struct tcp_fastopen_context
*ctxt
;
246 u32 user_key
[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
248 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_KERNEL
);
253 ctxt
= rcu_dereference(tcp_fastopen_ctx
);
255 memcpy(user_key
, ctxt
->key
, TCP_FASTOPEN_KEY_LENGTH
);
257 memset(user_key
, 0, sizeof(user_key
));
260 snprintf(tbl
.data
, tbl
.maxlen
, "%08x-%08x-%08x-%08x",
261 user_key
[0], user_key
[1], user_key
[2], user_key
[3]);
262 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
264 if (write
&& ret
== 0) {
265 if (sscanf(tbl
.data
, "%x-%x-%x-%x", user_key
, user_key
+ 1,
266 user_key
+ 2, user_key
+ 3) != 4) {
270 tcp_fastopen_reset_cipher(user_key
, TCP_FASTOPEN_KEY_LENGTH
);
274 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
275 user_key
[0], user_key
[1], user_key
[2], user_key
[3],
276 (char *)tbl
.data
, ret
);
281 static struct ctl_table ipv4_table
[] = {
283 .procname
= "tcp_timestamps",
284 .data
= &sysctl_tcp_timestamps
,
285 .maxlen
= sizeof(int),
287 .proc_handler
= proc_dointvec
290 .procname
= "tcp_window_scaling",
291 .data
= &sysctl_tcp_window_scaling
,
292 .maxlen
= sizeof(int),
294 .proc_handler
= proc_dointvec
297 .procname
= "tcp_sack",
298 .data
= &sysctl_tcp_sack
,
299 .maxlen
= sizeof(int),
301 .proc_handler
= proc_dointvec
304 .procname
= "tcp_retrans_collapse",
305 .data
= &sysctl_tcp_retrans_collapse
,
306 .maxlen
= sizeof(int),
308 .proc_handler
= proc_dointvec
311 .procname
= "ip_default_ttl",
312 .data
= &sysctl_ip_default_ttl
,
313 .maxlen
= sizeof(int),
315 .proc_handler
= proc_dointvec_minmax
,
316 .extra1
= &ip_ttl_min
,
317 .extra2
= &ip_ttl_max
,
320 .procname
= "ip_no_pmtu_disc",
321 .data
= &ipv4_config
.no_pmtu_disc
,
322 .maxlen
= sizeof(int),
324 .proc_handler
= proc_dointvec
327 .procname
= "ip_nonlocal_bind",
328 .data
= &sysctl_ip_nonlocal_bind
,
329 .maxlen
= sizeof(int),
331 .proc_handler
= proc_dointvec
334 .procname
= "tcp_syn_retries",
335 .data
= &sysctl_tcp_syn_retries
,
336 .maxlen
= sizeof(int),
338 .proc_handler
= proc_dointvec_minmax
,
339 .extra1
= &tcp_syn_retries_min
,
340 .extra2
= &tcp_syn_retries_max
343 .procname
= "tcp_synack_retries",
344 .data
= &sysctl_tcp_synack_retries
,
345 .maxlen
= sizeof(int),
347 .proc_handler
= proc_dointvec
350 .procname
= "tcp_max_orphans",
351 .data
= &sysctl_tcp_max_orphans
,
352 .maxlen
= sizeof(int),
354 .proc_handler
= proc_dointvec
357 .procname
= "tcp_max_tw_buckets",
358 .data
= &tcp_death_row
.sysctl_max_tw_buckets
,
359 .maxlen
= sizeof(int),
361 .proc_handler
= proc_dointvec
364 .procname
= "ip_early_demux",
365 .data
= &sysctl_ip_early_demux
,
366 .maxlen
= sizeof(int),
368 .proc_handler
= proc_dointvec
371 .procname
= "ip_dynaddr",
372 .data
= &sysctl_ip_dynaddr
,
373 .maxlen
= sizeof(int),
375 .proc_handler
= proc_dointvec
378 .procname
= "tcp_keepalive_time",
379 .data
= &sysctl_tcp_keepalive_time
,
380 .maxlen
= sizeof(int),
382 .proc_handler
= proc_dointvec_jiffies
,
385 .procname
= "tcp_keepalive_probes",
386 .data
= &sysctl_tcp_keepalive_probes
,
387 .maxlen
= sizeof(int),
389 .proc_handler
= proc_dointvec
392 .procname
= "tcp_keepalive_intvl",
393 .data
= &sysctl_tcp_keepalive_intvl
,
394 .maxlen
= sizeof(int),
396 .proc_handler
= proc_dointvec_jiffies
,
399 .procname
= "tcp_retries1",
400 .data
= &sysctl_tcp_retries1
,
401 .maxlen
= sizeof(int),
403 .proc_handler
= proc_dointvec_minmax
,
404 .extra2
= &tcp_retr1_max
407 .procname
= "tcp_retries2",
408 .data
= &sysctl_tcp_retries2
,
409 .maxlen
= sizeof(int),
411 .proc_handler
= proc_dointvec
414 .procname
= "tcp_fin_timeout",
415 .data
= &sysctl_tcp_fin_timeout
,
416 .maxlen
= sizeof(int),
418 .proc_handler
= proc_dointvec_jiffies
,
420 #ifdef CONFIG_SYN_COOKIES
422 .procname
= "tcp_syncookies",
423 .data
= &sysctl_tcp_syncookies
,
424 .maxlen
= sizeof(int),
426 .proc_handler
= proc_dointvec
430 .procname
= "tcp_fastopen",
431 .data
= &sysctl_tcp_fastopen
,
432 .maxlen
= sizeof(int),
434 .proc_handler
= proc_dointvec
,
437 .procname
= "tcp_fastopen_key",
439 .maxlen
= ((TCP_FASTOPEN_KEY_LENGTH
* 2) + 10),
440 .proc_handler
= proc_tcp_fastopen_key
,
443 .procname
= "tcp_tw_recycle",
444 .data
= &tcp_death_row
.sysctl_tw_recycle
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= proc_dointvec
450 .procname
= "tcp_abort_on_overflow",
451 .data
= &sysctl_tcp_abort_on_overflow
,
452 .maxlen
= sizeof(int),
454 .proc_handler
= proc_dointvec
457 .procname
= "tcp_stdurg",
458 .data
= &sysctl_tcp_stdurg
,
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
464 .procname
= "tcp_rfc1337",
465 .data
= &sysctl_tcp_rfc1337
,
466 .maxlen
= sizeof(int),
468 .proc_handler
= proc_dointvec
471 .procname
= "tcp_max_syn_backlog",
472 .data
= &sysctl_max_syn_backlog
,
473 .maxlen
= sizeof(int),
475 .proc_handler
= proc_dointvec
478 .procname
= "ip_local_port_range",
479 .data
= &sysctl_local_ports
.range
,
480 .maxlen
= sizeof(sysctl_local_ports
.range
),
482 .proc_handler
= ipv4_local_port_range
,
485 .procname
= "ip_local_reserved_ports",
486 .data
= NULL
, /* initialized in sysctl_ipv4_init */
489 .proc_handler
= proc_do_large_bitmap
,
492 .procname
= "igmp_max_memberships",
493 .data
= &sysctl_igmp_max_memberships
,
494 .maxlen
= sizeof(int),
496 .proc_handler
= proc_dointvec
499 .procname
= "igmp_max_msf",
500 .data
= &sysctl_igmp_max_msf
,
501 .maxlen
= sizeof(int),
503 .proc_handler
= proc_dointvec
506 .procname
= "inet_peer_threshold",
507 .data
= &inet_peer_threshold
,
508 .maxlen
= sizeof(int),
510 .proc_handler
= proc_dointvec
513 .procname
= "inet_peer_minttl",
514 .data
= &inet_peer_minttl
,
515 .maxlen
= sizeof(int),
517 .proc_handler
= proc_dointvec_jiffies
,
520 .procname
= "inet_peer_maxttl",
521 .data
= &inet_peer_maxttl
,
522 .maxlen
= sizeof(int),
524 .proc_handler
= proc_dointvec_jiffies
,
527 .procname
= "tcp_orphan_retries",
528 .data
= &sysctl_tcp_orphan_retries
,
529 .maxlen
= sizeof(int),
531 .proc_handler
= proc_dointvec
534 .procname
= "tcp_fack",
535 .data
= &sysctl_tcp_fack
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= proc_dointvec
541 .procname
= "tcp_reordering",
542 .data
= &sysctl_tcp_reordering
,
543 .maxlen
= sizeof(int),
545 .proc_handler
= proc_dointvec
548 .procname
= "tcp_dsack",
549 .data
= &sysctl_tcp_dsack
,
550 .maxlen
= sizeof(int),
552 .proc_handler
= proc_dointvec
555 .procname
= "tcp_wmem",
556 .data
= &sysctl_tcp_wmem
,
557 .maxlen
= sizeof(sysctl_tcp_wmem
),
559 .proc_handler
= proc_dointvec_minmax
,
563 .procname
= "tcp_notsent_lowat",
564 .data
= &sysctl_tcp_notsent_lowat
,
565 .maxlen
= sizeof(sysctl_tcp_notsent_lowat
),
567 .proc_handler
= proc_dointvec
,
570 .procname
= "tcp_rmem",
571 .data
= &sysctl_tcp_rmem
,
572 .maxlen
= sizeof(sysctl_tcp_rmem
),
574 .proc_handler
= proc_dointvec_minmax
,
578 .procname
= "tcp_app_win",
579 .data
= &sysctl_tcp_app_win
,
580 .maxlen
= sizeof(int),
582 .proc_handler
= proc_dointvec
585 .procname
= "tcp_adv_win_scale",
586 .data
= &sysctl_tcp_adv_win_scale
,
587 .maxlen
= sizeof(int),
589 .proc_handler
= proc_dointvec_minmax
,
590 .extra1
= &tcp_adv_win_scale_min
,
591 .extra2
= &tcp_adv_win_scale_max
,
594 .procname
= "tcp_tw_reuse",
595 .data
= &sysctl_tcp_tw_reuse
,
596 .maxlen
= sizeof(int),
598 .proc_handler
= proc_dointvec
601 .procname
= "tcp_frto",
602 .data
= &sysctl_tcp_frto
,
603 .maxlen
= sizeof(int),
605 .proc_handler
= proc_dointvec
608 .procname
= "tcp_low_latency",
609 .data
= &sysctl_tcp_low_latency
,
610 .maxlen
= sizeof(int),
612 .proc_handler
= proc_dointvec
615 .procname
= "tcp_no_metrics_save",
616 .data
= &sysctl_tcp_nometrics_save
,
617 .maxlen
= sizeof(int),
619 .proc_handler
= proc_dointvec
,
622 .procname
= "tcp_moderate_rcvbuf",
623 .data
= &sysctl_tcp_moderate_rcvbuf
,
624 .maxlen
= sizeof(int),
626 .proc_handler
= proc_dointvec
,
629 .procname
= "tcp_tso_win_divisor",
630 .data
= &sysctl_tcp_tso_win_divisor
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= proc_dointvec
,
636 .procname
= "tcp_congestion_control",
638 .maxlen
= TCP_CA_NAME_MAX
,
639 .proc_handler
= proc_tcp_congestion_control
,
642 .procname
= "tcp_mtu_probing",
643 .data
= &sysctl_tcp_mtu_probing
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= proc_dointvec
,
649 .procname
= "tcp_base_mss",
650 .data
= &sysctl_tcp_base_mss
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= proc_dointvec
,
656 .procname
= "tcp_workaround_signed_windows",
657 .data
= &sysctl_tcp_workaround_signed_windows
,
658 .maxlen
= sizeof(int),
660 .proc_handler
= proc_dointvec
663 .procname
= "tcp_limit_output_bytes",
664 .data
= &sysctl_tcp_limit_output_bytes
,
665 .maxlen
= sizeof(int),
667 .proc_handler
= proc_dointvec
670 .procname
= "tcp_challenge_ack_limit",
671 .data
= &sysctl_tcp_challenge_ack_limit
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= proc_dointvec
676 #ifdef CONFIG_NET_DMA
678 .procname
= "tcp_dma_copybreak",
679 .data
= &sysctl_tcp_dma_copybreak
,
680 .maxlen
= sizeof(int),
682 .proc_handler
= proc_dointvec
686 .procname
= "tcp_slow_start_after_idle",
687 .data
= &sysctl_tcp_slow_start_after_idle
,
688 .maxlen
= sizeof(int),
690 .proc_handler
= proc_dointvec
692 #ifdef CONFIG_NETLABEL
694 .procname
= "cipso_cache_enable",
695 .data
= &cipso_v4_cache_enabled
,
696 .maxlen
= sizeof(int),
698 .proc_handler
= proc_dointvec
,
701 .procname
= "cipso_cache_bucket_size",
702 .data
= &cipso_v4_cache_bucketsize
,
703 .maxlen
= sizeof(int),
705 .proc_handler
= proc_dointvec
,
708 .procname
= "cipso_rbm_optfmt",
709 .data
= &cipso_v4_rbm_optfmt
,
710 .maxlen
= sizeof(int),
712 .proc_handler
= proc_dointvec
,
715 .procname
= "cipso_rbm_strictvalid",
716 .data
= &cipso_v4_rbm_strictvalid
,
717 .maxlen
= sizeof(int),
719 .proc_handler
= proc_dointvec
,
721 #endif /* CONFIG_NETLABEL */
723 .procname
= "tcp_available_congestion_control",
724 .maxlen
= TCP_CA_BUF_MAX
,
726 .proc_handler
= proc_tcp_available_congestion_control
,
729 .procname
= "tcp_allowed_congestion_control",
730 .maxlen
= TCP_CA_BUF_MAX
,
732 .proc_handler
= proc_allowed_congestion_control
,
735 .procname
= "tcp_max_ssthresh",
736 .data
= &sysctl_tcp_max_ssthresh
,
737 .maxlen
= sizeof(int),
739 .proc_handler
= proc_dointvec
,
742 .procname
= "tcp_thin_linear_timeouts",
743 .data
= &sysctl_tcp_thin_linear_timeouts
,
744 .maxlen
= sizeof(int),
746 .proc_handler
= proc_dointvec
749 .procname
= "tcp_thin_dupack",
750 .data
= &sysctl_tcp_thin_dupack
,
751 .maxlen
= sizeof(int),
753 .proc_handler
= proc_dointvec
756 .procname
= "tcp_early_retrans",
757 .data
= &sysctl_tcp_early_retrans
,
758 .maxlen
= sizeof(int),
760 .proc_handler
= proc_dointvec_minmax
,
765 .procname
= "tcp_min_tso_segs",
766 .data
= &sysctl_tcp_min_tso_segs
,
767 .maxlen
= sizeof(int),
769 .proc_handler
= proc_dointvec_minmax
,
771 .extra2
= &gso_max_segs
,
774 .procname
= "udp_mem",
775 .data
= &sysctl_udp_mem
,
776 .maxlen
= sizeof(sysctl_udp_mem
),
778 .proc_handler
= proc_doulongvec_minmax
,
781 .procname
= "udp_rmem_min",
782 .data
= &sysctl_udp_rmem_min
,
783 .maxlen
= sizeof(sysctl_udp_rmem_min
),
785 .proc_handler
= proc_dointvec_minmax
,
789 .procname
= "udp_wmem_min",
790 .data
= &sysctl_udp_wmem_min
,
791 .maxlen
= sizeof(sysctl_udp_wmem_min
),
793 .proc_handler
= proc_dointvec_minmax
,
799 static struct ctl_table ipv4_net_table
[] = {
801 .procname
= "icmp_echo_ignore_all",
802 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_all
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= proc_dointvec
808 .procname
= "icmp_echo_ignore_broadcasts",
809 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_broadcasts
,
810 .maxlen
= sizeof(int),
812 .proc_handler
= proc_dointvec
815 .procname
= "icmp_ignore_bogus_error_responses",
816 .data
= &init_net
.ipv4
.sysctl_icmp_ignore_bogus_error_responses
,
817 .maxlen
= sizeof(int),
819 .proc_handler
= proc_dointvec
822 .procname
= "icmp_errors_use_inbound_ifaddr",
823 .data
= &init_net
.ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
,
824 .maxlen
= sizeof(int),
826 .proc_handler
= proc_dointvec
829 .procname
= "icmp_ratelimit",
830 .data
= &init_net
.ipv4
.sysctl_icmp_ratelimit
,
831 .maxlen
= sizeof(int),
833 .proc_handler
= proc_dointvec_ms_jiffies
,
836 .procname
= "icmp_ratemask",
837 .data
= &init_net
.ipv4
.sysctl_icmp_ratemask
,
838 .maxlen
= sizeof(int),
840 .proc_handler
= proc_dointvec
843 .procname
= "ping_group_range",
844 .data
= &init_net
.ipv4
.sysctl_ping_group_range
,
845 .maxlen
= sizeof(gid_t
)*2,
847 .proc_handler
= ipv4_ping_group_range
,
850 .procname
= "tcp_ecn",
851 .data
= &init_net
.ipv4
.sysctl_tcp_ecn
,
852 .maxlen
= sizeof(int),
854 .proc_handler
= proc_dointvec
857 .procname
= "tcp_mem",
858 .maxlen
= sizeof(init_net
.ipv4
.sysctl_tcp_mem
),
860 .proc_handler
= ipv4_tcp_mem
,
865 static __net_init
int ipv4_sysctl_init_net(struct net
*net
)
867 struct ctl_table
*table
;
869 table
= ipv4_net_table
;
870 if (!net_eq(net
, &init_net
)) {
871 table
= kmemdup(table
, sizeof(ipv4_net_table
), GFP_KERNEL
);
876 &net
->ipv4
.sysctl_icmp_echo_ignore_all
;
878 &net
->ipv4
.sysctl_icmp_echo_ignore_broadcasts
;
880 &net
->ipv4
.sysctl_icmp_ignore_bogus_error_responses
;
882 &net
->ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
;
884 &net
->ipv4
.sysctl_icmp_ratelimit
;
886 &net
->ipv4
.sysctl_icmp_ratemask
;
888 &net
->ipv4
.sysctl_ping_group_range
;
890 &net
->ipv4
.sysctl_tcp_ecn
;
892 /* Don't export sysctls to unprivileged users */
893 if (net
->user_ns
!= &init_user_ns
)
894 table
[0].procname
= NULL
;
898 * Sane defaults - nobody may create ping sockets.
899 * Boot scripts should set this to distro-specific group.
901 net
->ipv4
.sysctl_ping_group_range
[0] = make_kgid(&init_user_ns
, 1);
902 net
->ipv4
.sysctl_ping_group_range
[1] = make_kgid(&init_user_ns
, 0);
906 net
->ipv4
.ipv4_hdr
= register_net_sysctl(net
, "net/ipv4", table
);
907 if (net
->ipv4
.ipv4_hdr
== NULL
)
913 if (!net_eq(net
, &init_net
))
919 static __net_exit
void ipv4_sysctl_exit_net(struct net
*net
)
921 struct ctl_table
*table
;
923 table
= net
->ipv4
.ipv4_hdr
->ctl_table_arg
;
924 unregister_net_sysctl_table(net
->ipv4
.ipv4_hdr
);
928 static __net_initdata
struct pernet_operations ipv4_sysctl_ops
= {
929 .init
= ipv4_sysctl_init_net
,
930 .exit
= ipv4_sysctl_exit_net
,
933 static __init
int sysctl_ipv4_init(void)
935 struct ctl_table_header
*hdr
;
938 for (i
= ipv4_table
; i
->procname
; i
++) {
939 if (strcmp(i
->procname
, "ip_local_reserved_ports") == 0) {
940 i
->data
= sysctl_local_reserved_ports
;
947 hdr
= register_net_sysctl(&init_net
, "net/ipv4", ipv4_table
);
951 if (register_pernet_subsys(&ipv4_sysctl_ops
)) {
952 unregister_net_sysctl_table(hdr
);
959 __initcall(sysctl_ipv4_init
);