1 // SPDX-License-Identifier: GPL-2.0
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
5 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
10 #include <linux/module.h>
11 #include <linux/sysctl.h>
12 #include <linux/igmp.h>
13 #include <linux/inetdevice.h>
14 #include <linux/seqlock.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/nsproxy.h>
18 #include <linux/swap.h>
22 #include <net/route.h>
25 #include <net/cipso_ipv4.h>
26 #include <net/inet_frag.h>
28 #include <net/protocol.h>
29 #include <net/netevent.h>
34 static int thousand
= 1000;
35 static int gso_max_segs
= GSO_MAX_SEGS
;
36 static int tcp_retr1_max
= 255;
37 static int ip_local_port_range_min
[] = { 1, 1 };
38 static int ip_local_port_range_max
[] = { 65535, 65535 };
39 static int tcp_adv_win_scale_min
= -31;
40 static int tcp_adv_win_scale_max
= 31;
41 static int ip_privileged_port_min
;
42 static int ip_privileged_port_max
= 65535;
43 static int ip_ttl_min
= 1;
44 static int ip_ttl_max
= 255;
45 static int tcp_syn_retries_min
= 1;
46 static int tcp_syn_retries_max
= MAX_TCP_SYNCNT
;
47 static int ip_ping_group_range_min
[] = { 0, 0 };
48 static int ip_ping_group_range_max
[] = { GID_T_MAX
, GID_T_MAX
};
51 static int sysctl_tcp_low_latency __read_mostly
;
53 /* Update system visible IP port range */
54 static void set_local_port_range(struct net
*net
, int range
[2])
56 bool same_parity
= !((range
[0] ^ range
[1]) & 1);
58 write_seqlock_bh(&net
->ipv4
.ip_local_ports
.lock
);
59 if (same_parity
&& !net
->ipv4
.ip_local_ports
.warned
) {
60 net
->ipv4
.ip_local_ports
.warned
= true;
61 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
63 net
->ipv4
.ip_local_ports
.range
[0] = range
[0];
64 net
->ipv4
.ip_local_ports
.range
[1] = range
[1];
65 write_sequnlock_bh(&net
->ipv4
.ip_local_ports
.lock
);
68 /* Validate changes from /proc interface. */
69 static int ipv4_local_port_range(struct ctl_table
*table
, int write
,
71 size_t *lenp
, loff_t
*ppos
)
74 container_of(table
->data
, struct net
, ipv4
.ip_local_ports
.range
);
77 struct ctl_table tmp
= {
79 .maxlen
= sizeof(range
),
81 .extra1
= &ip_local_port_range_min
,
82 .extra2
= &ip_local_port_range_max
,
85 inet_get_local_port_range(net
, &range
[0], &range
[1]);
87 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
89 if (write
&& ret
== 0) {
90 /* Ensure that the upper limit is not smaller than the lower,
91 * and that the lower does not encroach upon the privileged
94 if ((range
[1] < range
[0]) ||
95 (range
[0] < net
->ipv4
.sysctl_ip_prot_sock
))
98 set_local_port_range(net
, range
);
104 /* Validate changes from /proc interface. */
105 static int ipv4_privileged_ports(struct ctl_table
*table
, int write
,
106 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
108 struct net
*net
= container_of(table
->data
, struct net
,
109 ipv4
.sysctl_ip_prot_sock
);
113 struct ctl_table tmp
= {
115 .maxlen
= sizeof(pports
),
117 .extra1
= &ip_privileged_port_min
,
118 .extra2
= &ip_privileged_port_max
,
121 pports
= net
->ipv4
.sysctl_ip_prot_sock
;
123 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
125 if (write
&& ret
== 0) {
126 inet_get_local_port_range(net
, &range
[0], &range
[1]);
127 /* Ensure that the local port range doesn't overlap with the
128 * privileged port range.
130 if (range
[0] < pports
)
133 net
->ipv4
.sysctl_ip_prot_sock
= pports
;
139 static void inet_get_ping_group_range_table(struct ctl_table
*table
, kgid_t
*low
, kgid_t
*high
)
141 kgid_t
*data
= table
->data
;
143 container_of(table
->data
, struct net
, ipv4
.ping_group_range
.range
);
146 seq
= read_seqbegin(&net
->ipv4
.ping_group_range
.lock
);
150 } while (read_seqretry(&net
->ipv4
.ping_group_range
.lock
, seq
));
153 /* Update system visible IP port range */
154 static void set_ping_group_range(struct ctl_table
*table
, kgid_t low
, kgid_t high
)
156 kgid_t
*data
= table
->data
;
158 container_of(table
->data
, struct net
, ipv4
.ping_group_range
.range
);
159 write_seqlock(&net
->ipv4
.ping_group_range
.lock
);
162 write_sequnlock(&net
->ipv4
.ping_group_range
.lock
);
165 /* Validate changes from /proc interface. */
166 static int ipv4_ping_group_range(struct ctl_table
*table
, int write
,
168 size_t *lenp
, loff_t
*ppos
)
170 struct user_namespace
*user_ns
= current_user_ns();
174 struct ctl_table tmp
= {
176 .maxlen
= sizeof(urange
),
178 .extra1
= &ip_ping_group_range_min
,
179 .extra2
= &ip_ping_group_range_max
,
182 inet_get_ping_group_range_table(table
, &low
, &high
);
183 urange
[0] = from_kgid_munged(user_ns
, low
);
184 urange
[1] = from_kgid_munged(user_ns
, high
);
185 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
187 if (write
&& ret
== 0) {
188 low
= make_kgid(user_ns
, urange
[0]);
189 high
= make_kgid(user_ns
, urange
[1]);
190 if (!gid_valid(low
) || !gid_valid(high
) ||
191 (urange
[1] < urange
[0]) || gid_lt(high
, low
)) {
192 low
= make_kgid(&init_user_ns
, 1);
193 high
= make_kgid(&init_user_ns
, 0);
195 set_ping_group_range(table
, low
, high
);
201 static int proc_tcp_congestion_control(struct ctl_table
*ctl
, int write
,
202 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
204 struct net
*net
= container_of(ctl
->data
, struct net
,
205 ipv4
.tcp_congestion_control
);
206 char val
[TCP_CA_NAME_MAX
];
207 struct ctl_table tbl
= {
209 .maxlen
= TCP_CA_NAME_MAX
,
213 tcp_get_default_congestion_control(net
, val
);
215 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
216 if (write
&& ret
== 0)
217 ret
= tcp_set_default_congestion_control(net
, val
);
221 static int proc_tcp_available_congestion_control(struct ctl_table
*ctl
,
223 void __user
*buffer
, size_t *lenp
,
226 struct ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
, };
229 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
232 tcp_get_available_congestion_control(tbl
.data
, TCP_CA_BUF_MAX
);
233 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
238 static int proc_allowed_congestion_control(struct ctl_table
*ctl
,
240 void __user
*buffer
, size_t *lenp
,
243 struct ctl_table tbl
= { .maxlen
= TCP_CA_BUF_MAX
};
246 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
250 tcp_get_allowed_congestion_control(tbl
.data
, tbl
.maxlen
);
251 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
252 if (write
&& ret
== 0)
253 ret
= tcp_set_allowed_congestion_control(tbl
.data
);
258 static int proc_tcp_fastopen_key(struct ctl_table
*table
, int write
,
259 void __user
*buffer
, size_t *lenp
,
262 struct net
*net
= container_of(table
->data
, struct net
,
263 ipv4
.sysctl_tcp_fastopen
);
264 struct ctl_table tbl
= { .maxlen
= (TCP_FASTOPEN_KEY_LENGTH
* 2 + 10) };
265 struct tcp_fastopen_context
*ctxt
;
267 u32 user_key
[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
269 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_KERNEL
);
274 ctxt
= rcu_dereference(net
->ipv4
.tcp_fastopen_ctx
);
276 memcpy(user_key
, ctxt
->key
, TCP_FASTOPEN_KEY_LENGTH
);
278 memset(user_key
, 0, sizeof(user_key
));
281 snprintf(tbl
.data
, tbl
.maxlen
, "%08x-%08x-%08x-%08x",
282 user_key
[0], user_key
[1], user_key
[2], user_key
[3]);
283 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
285 if (write
&& ret
== 0) {
286 if (sscanf(tbl
.data
, "%x-%x-%x-%x", user_key
, user_key
+ 1,
287 user_key
+ 2, user_key
+ 3) != 4) {
291 tcp_fastopen_reset_cipher(net
, NULL
, user_key
,
292 TCP_FASTOPEN_KEY_LENGTH
);
296 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
297 user_key
[0], user_key
[1], user_key
[2], user_key
[3],
298 (char *)tbl
.data
, ret
);
303 static void proc_configure_early_demux(int enabled
, int protocol
)
305 struct net_protocol
*ipprot
;
306 #if IS_ENABLED(CONFIG_IPV6)
307 struct inet6_protocol
*ip6prot
;
312 ipprot
= rcu_dereference(inet_protos
[protocol
]);
314 ipprot
->early_demux
= enabled
? ipprot
->early_demux_handler
:
317 #if IS_ENABLED(CONFIG_IPV6)
318 ip6prot
= rcu_dereference(inet6_protos
[protocol
]);
320 ip6prot
->early_demux
= enabled
? ip6prot
->early_demux_handler
:
326 static int proc_tcp_early_demux(struct ctl_table
*table
, int write
,
327 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
331 ret
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
334 int enabled
= init_net
.ipv4
.sysctl_tcp_early_demux
;
336 proc_configure_early_demux(enabled
, IPPROTO_TCP
);
342 static int proc_udp_early_demux(struct ctl_table
*table
, int write
,
343 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
347 ret
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
350 int enabled
= init_net
.ipv4
.sysctl_udp_early_demux
;
352 proc_configure_early_demux(enabled
, IPPROTO_UDP
);
358 static int proc_tfo_blackhole_detect_timeout(struct ctl_table
*table
,
361 size_t *lenp
, loff_t
*ppos
)
363 struct net
*net
= container_of(table
->data
, struct net
,
364 ipv4
.sysctl_tcp_fastopen_blackhole_timeout
);
367 ret
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
368 if (write
&& ret
== 0)
369 atomic_set(&net
->ipv4
.tfo_active_disable_times
, 0);
374 static int proc_tcp_available_ulp(struct ctl_table
*ctl
,
376 void __user
*buffer
, size_t *lenp
,
379 struct ctl_table tbl
= { .maxlen
= TCP_ULP_BUF_MAX
, };
382 tbl
.data
= kmalloc(tbl
.maxlen
, GFP_USER
);
385 tcp_get_available_ulp(tbl
.data
, TCP_ULP_BUF_MAX
);
386 ret
= proc_dostring(&tbl
, write
, buffer
, lenp
, ppos
);
392 #ifdef CONFIG_IP_ROUTE_MULTIPATH
393 static int proc_fib_multipath_hash_policy(struct ctl_table
*table
, int write
,
394 void __user
*buffer
, size_t *lenp
,
397 struct net
*net
= container_of(table
->data
, struct net
,
398 ipv4
.sysctl_fib_multipath_hash_policy
);
401 ret
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
402 if (write
&& ret
== 0)
403 call_netevent_notifiers(NETEVENT_MULTIPATH_HASH_UPDATE
, net
);
409 static struct ctl_table ipv4_table
[] = {
411 .procname
= "tcp_max_orphans",
412 .data
= &sysctl_tcp_max_orphans
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= proc_dointvec
418 .procname
= "inet_peer_threshold",
419 .data
= &inet_peer_threshold
,
420 .maxlen
= sizeof(int),
422 .proc_handler
= proc_dointvec
425 .procname
= "inet_peer_minttl",
426 .data
= &inet_peer_minttl
,
427 .maxlen
= sizeof(int),
429 .proc_handler
= proc_dointvec_jiffies
,
432 .procname
= "inet_peer_maxttl",
433 .data
= &inet_peer_maxttl
,
434 .maxlen
= sizeof(int),
436 .proc_handler
= proc_dointvec_jiffies
,
439 .procname
= "tcp_mem",
440 .maxlen
= sizeof(sysctl_tcp_mem
),
441 .data
= &sysctl_tcp_mem
,
443 .proc_handler
= proc_doulongvec_minmax
,
446 .procname
= "tcp_low_latency",
447 .data
= &sysctl_tcp_low_latency
,
448 .maxlen
= sizeof(int),
450 .proc_handler
= proc_dointvec
452 #ifdef CONFIG_NETLABEL
454 .procname
= "cipso_cache_enable",
455 .data
= &cipso_v4_cache_enabled
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= proc_dointvec
,
461 .procname
= "cipso_cache_bucket_size",
462 .data
= &cipso_v4_cache_bucketsize
,
463 .maxlen
= sizeof(int),
465 .proc_handler
= proc_dointvec
,
468 .procname
= "cipso_rbm_optfmt",
469 .data
= &cipso_v4_rbm_optfmt
,
470 .maxlen
= sizeof(int),
472 .proc_handler
= proc_dointvec
,
475 .procname
= "cipso_rbm_strictvalid",
476 .data
= &cipso_v4_rbm_strictvalid
,
477 .maxlen
= sizeof(int),
479 .proc_handler
= proc_dointvec
,
481 #endif /* CONFIG_NETLABEL */
483 .procname
= "tcp_available_congestion_control",
484 .maxlen
= TCP_CA_BUF_MAX
,
486 .proc_handler
= proc_tcp_available_congestion_control
,
489 .procname
= "tcp_allowed_congestion_control",
490 .maxlen
= TCP_CA_BUF_MAX
,
492 .proc_handler
= proc_allowed_congestion_control
,
495 .procname
= "tcp_available_ulp",
496 .maxlen
= TCP_ULP_BUF_MAX
,
498 .proc_handler
= proc_tcp_available_ulp
,
501 .procname
= "icmp_msgs_per_sec",
502 .data
= &sysctl_icmp_msgs_per_sec
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= proc_dointvec_minmax
,
509 .procname
= "icmp_msgs_burst",
510 .data
= &sysctl_icmp_msgs_burst
,
511 .maxlen
= sizeof(int),
513 .proc_handler
= proc_dointvec_minmax
,
517 .procname
= "udp_mem",
518 .data
= &sysctl_udp_mem
,
519 .maxlen
= sizeof(sysctl_udp_mem
),
521 .proc_handler
= proc_doulongvec_minmax
,
524 .procname
= "udp_rmem_min",
525 .data
= &sysctl_udp_rmem_min
,
526 .maxlen
= sizeof(sysctl_udp_rmem_min
),
528 .proc_handler
= proc_dointvec_minmax
,
532 .procname
= "udp_wmem_min",
533 .data
= &sysctl_udp_wmem_min
,
534 .maxlen
= sizeof(sysctl_udp_wmem_min
),
536 .proc_handler
= proc_dointvec_minmax
,
542 static struct ctl_table ipv4_net_table
[] = {
544 .procname
= "icmp_echo_ignore_all",
545 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_all
,
546 .maxlen
= sizeof(int),
548 .proc_handler
= proc_dointvec
551 .procname
= "icmp_echo_ignore_broadcasts",
552 .data
= &init_net
.ipv4
.sysctl_icmp_echo_ignore_broadcasts
,
553 .maxlen
= sizeof(int),
555 .proc_handler
= proc_dointvec
558 .procname
= "icmp_ignore_bogus_error_responses",
559 .data
= &init_net
.ipv4
.sysctl_icmp_ignore_bogus_error_responses
,
560 .maxlen
= sizeof(int),
562 .proc_handler
= proc_dointvec
565 .procname
= "icmp_errors_use_inbound_ifaddr",
566 .data
= &init_net
.ipv4
.sysctl_icmp_errors_use_inbound_ifaddr
,
567 .maxlen
= sizeof(int),
569 .proc_handler
= proc_dointvec
572 .procname
= "icmp_ratelimit",
573 .data
= &init_net
.ipv4
.sysctl_icmp_ratelimit
,
574 .maxlen
= sizeof(int),
576 .proc_handler
= proc_dointvec_ms_jiffies
,
579 .procname
= "icmp_ratemask",
580 .data
= &init_net
.ipv4
.sysctl_icmp_ratemask
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= proc_dointvec
586 .procname
= "ping_group_range",
587 .data
= &init_net
.ipv4
.ping_group_range
.range
,
588 .maxlen
= sizeof(gid_t
)*2,
590 .proc_handler
= ipv4_ping_group_range
,
593 .procname
= "tcp_ecn",
594 .data
= &init_net
.ipv4
.sysctl_tcp_ecn
,
595 .maxlen
= sizeof(int),
597 .proc_handler
= proc_dointvec
600 .procname
= "tcp_ecn_fallback",
601 .data
= &init_net
.ipv4
.sysctl_tcp_ecn_fallback
,
602 .maxlen
= sizeof(int),
604 .proc_handler
= proc_dointvec
607 .procname
= "ip_dynaddr",
608 .data
= &init_net
.ipv4
.sysctl_ip_dynaddr
,
609 .maxlen
= sizeof(int),
611 .proc_handler
= proc_dointvec
614 .procname
= "ip_early_demux",
615 .data
= &init_net
.ipv4
.sysctl_ip_early_demux
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= proc_dointvec
621 .procname
= "udp_early_demux",
622 .data
= &init_net
.ipv4
.sysctl_udp_early_demux
,
623 .maxlen
= sizeof(int),
625 .proc_handler
= proc_udp_early_demux
628 .procname
= "tcp_early_demux",
629 .data
= &init_net
.ipv4
.sysctl_tcp_early_demux
,
630 .maxlen
= sizeof(int),
632 .proc_handler
= proc_tcp_early_demux
635 .procname
= "ip_default_ttl",
636 .data
= &init_net
.ipv4
.sysctl_ip_default_ttl
,
637 .maxlen
= sizeof(int),
639 .proc_handler
= proc_dointvec_minmax
,
640 .extra1
= &ip_ttl_min
,
641 .extra2
= &ip_ttl_max
,
644 .procname
= "ip_local_port_range",
645 .maxlen
= sizeof(init_net
.ipv4
.ip_local_ports
.range
),
646 .data
= &init_net
.ipv4
.ip_local_ports
.range
,
648 .proc_handler
= ipv4_local_port_range
,
651 .procname
= "ip_local_reserved_ports",
652 .data
= &init_net
.ipv4
.sysctl_local_reserved_ports
,
655 .proc_handler
= proc_do_large_bitmap
,
658 .procname
= "ip_no_pmtu_disc",
659 .data
= &init_net
.ipv4
.sysctl_ip_no_pmtu_disc
,
660 .maxlen
= sizeof(int),
662 .proc_handler
= proc_dointvec
665 .procname
= "ip_forward_use_pmtu",
666 .data
= &init_net
.ipv4
.sysctl_ip_fwd_use_pmtu
,
667 .maxlen
= sizeof(int),
669 .proc_handler
= proc_dointvec
,
672 .procname
= "ip_nonlocal_bind",
673 .data
= &init_net
.ipv4
.sysctl_ip_nonlocal_bind
,
674 .maxlen
= sizeof(int),
676 .proc_handler
= proc_dointvec
679 .procname
= "fwmark_reflect",
680 .data
= &init_net
.ipv4
.sysctl_fwmark_reflect
,
681 .maxlen
= sizeof(int),
683 .proc_handler
= proc_dointvec
,
686 .procname
= "tcp_fwmark_accept",
687 .data
= &init_net
.ipv4
.sysctl_tcp_fwmark_accept
,
688 .maxlen
= sizeof(int),
690 .proc_handler
= proc_dointvec
,
692 #ifdef CONFIG_NET_L3_MASTER_DEV
694 .procname
= "tcp_l3mdev_accept",
695 .data
= &init_net
.ipv4
.sysctl_tcp_l3mdev_accept
,
696 .maxlen
= sizeof(int),
698 .proc_handler
= proc_dointvec_minmax
,
704 .procname
= "tcp_mtu_probing",
705 .data
= &init_net
.ipv4
.sysctl_tcp_mtu_probing
,
706 .maxlen
= sizeof(int),
708 .proc_handler
= proc_dointvec
,
711 .procname
= "tcp_base_mss",
712 .data
= &init_net
.ipv4
.sysctl_tcp_base_mss
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= proc_dointvec
,
718 .procname
= "tcp_probe_threshold",
719 .data
= &init_net
.ipv4
.sysctl_tcp_probe_threshold
,
720 .maxlen
= sizeof(int),
722 .proc_handler
= proc_dointvec
,
725 .procname
= "tcp_probe_interval",
726 .data
= &init_net
.ipv4
.sysctl_tcp_probe_interval
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= proc_dointvec
,
732 .procname
= "igmp_link_local_mcast_reports",
733 .data
= &init_net
.ipv4
.sysctl_igmp_llm_reports
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= proc_dointvec
739 .procname
= "igmp_max_memberships",
740 .data
= &init_net
.ipv4
.sysctl_igmp_max_memberships
,
741 .maxlen
= sizeof(int),
743 .proc_handler
= proc_dointvec
746 .procname
= "igmp_max_msf",
747 .data
= &init_net
.ipv4
.sysctl_igmp_max_msf
,
748 .maxlen
= sizeof(int),
750 .proc_handler
= proc_dointvec
752 #ifdef CONFIG_IP_MULTICAST
754 .procname
= "igmp_qrv",
755 .data
= &init_net
.ipv4
.sysctl_igmp_qrv
,
756 .maxlen
= sizeof(int),
758 .proc_handler
= proc_dointvec_minmax
,
763 .procname
= "tcp_congestion_control",
764 .data
= &init_net
.ipv4
.tcp_congestion_control
,
766 .maxlen
= TCP_CA_NAME_MAX
,
767 .proc_handler
= proc_tcp_congestion_control
,
770 .procname
= "tcp_keepalive_time",
771 .data
= &init_net
.ipv4
.sysctl_tcp_keepalive_time
,
772 .maxlen
= sizeof(int),
774 .proc_handler
= proc_dointvec_jiffies
,
777 .procname
= "tcp_keepalive_probes",
778 .data
= &init_net
.ipv4
.sysctl_tcp_keepalive_probes
,
779 .maxlen
= sizeof(int),
781 .proc_handler
= proc_dointvec
784 .procname
= "tcp_keepalive_intvl",
785 .data
= &init_net
.ipv4
.sysctl_tcp_keepalive_intvl
,
786 .maxlen
= sizeof(int),
788 .proc_handler
= proc_dointvec_jiffies
,
791 .procname
= "tcp_syn_retries",
792 .data
= &init_net
.ipv4
.sysctl_tcp_syn_retries
,
793 .maxlen
= sizeof(int),
795 .proc_handler
= proc_dointvec_minmax
,
796 .extra1
= &tcp_syn_retries_min
,
797 .extra2
= &tcp_syn_retries_max
800 .procname
= "tcp_synack_retries",
801 .data
= &init_net
.ipv4
.sysctl_tcp_synack_retries
,
802 .maxlen
= sizeof(int),
804 .proc_handler
= proc_dointvec
806 #ifdef CONFIG_SYN_COOKIES
808 .procname
= "tcp_syncookies",
809 .data
= &init_net
.ipv4
.sysctl_tcp_syncookies
,
810 .maxlen
= sizeof(int),
812 .proc_handler
= proc_dointvec
816 .procname
= "tcp_reordering",
817 .data
= &init_net
.ipv4
.sysctl_tcp_reordering
,
818 .maxlen
= sizeof(int),
820 .proc_handler
= proc_dointvec
823 .procname
= "tcp_retries1",
824 .data
= &init_net
.ipv4
.sysctl_tcp_retries1
,
825 .maxlen
= sizeof(int),
827 .proc_handler
= proc_dointvec_minmax
,
828 .extra2
= &tcp_retr1_max
831 .procname
= "tcp_retries2",
832 .data
= &init_net
.ipv4
.sysctl_tcp_retries2
,
833 .maxlen
= sizeof(int),
835 .proc_handler
= proc_dointvec
838 .procname
= "tcp_orphan_retries",
839 .data
= &init_net
.ipv4
.sysctl_tcp_orphan_retries
,
840 .maxlen
= sizeof(int),
842 .proc_handler
= proc_dointvec
845 .procname
= "tcp_fin_timeout",
846 .data
= &init_net
.ipv4
.sysctl_tcp_fin_timeout
,
847 .maxlen
= sizeof(int),
849 .proc_handler
= proc_dointvec_jiffies
,
852 .procname
= "tcp_notsent_lowat",
853 .data
= &init_net
.ipv4
.sysctl_tcp_notsent_lowat
,
854 .maxlen
= sizeof(unsigned int),
856 .proc_handler
= proc_douintvec
,
859 .procname
= "tcp_tw_reuse",
860 .data
= &init_net
.ipv4
.sysctl_tcp_tw_reuse
,
861 .maxlen
= sizeof(int),
863 .proc_handler
= proc_dointvec
866 .procname
= "tcp_max_tw_buckets",
867 .data
= &init_net
.ipv4
.tcp_death_row
.sysctl_max_tw_buckets
,
868 .maxlen
= sizeof(int),
870 .proc_handler
= proc_dointvec
873 .procname
= "tcp_max_syn_backlog",
874 .data
= &init_net
.ipv4
.sysctl_max_syn_backlog
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= proc_dointvec
880 .procname
= "tcp_fastopen",
881 .data
= &init_net
.ipv4
.sysctl_tcp_fastopen
,
882 .maxlen
= sizeof(int),
884 .proc_handler
= proc_dointvec
,
887 .procname
= "tcp_fastopen_key",
889 .data
= &init_net
.ipv4
.sysctl_tcp_fastopen
,
890 .maxlen
= ((TCP_FASTOPEN_KEY_LENGTH
* 2) + 10),
891 .proc_handler
= proc_tcp_fastopen_key
,
894 .procname
= "tcp_fastopen_blackhole_timeout_sec",
895 .data
= &init_net
.ipv4
.sysctl_tcp_fastopen_blackhole_timeout
,
896 .maxlen
= sizeof(int),
898 .proc_handler
= proc_tfo_blackhole_detect_timeout
,
901 #ifdef CONFIG_IP_ROUTE_MULTIPATH
903 .procname
= "fib_multipath_use_neigh",
904 .data
= &init_net
.ipv4
.sysctl_fib_multipath_use_neigh
,
905 .maxlen
= sizeof(int),
907 .proc_handler
= proc_dointvec_minmax
,
912 .procname
= "fib_multipath_hash_policy",
913 .data
= &init_net
.ipv4
.sysctl_fib_multipath_hash_policy
,
914 .maxlen
= sizeof(int),
916 .proc_handler
= proc_fib_multipath_hash_policy
,
922 .procname
= "ip_unprivileged_port_start",
923 .maxlen
= sizeof(int),
924 .data
= &init_net
.ipv4
.sysctl_ip_prot_sock
,
926 .proc_handler
= ipv4_privileged_ports
,
928 #ifdef CONFIG_NET_L3_MASTER_DEV
930 .procname
= "udp_l3mdev_accept",
931 .data
= &init_net
.ipv4
.sysctl_udp_l3mdev_accept
,
932 .maxlen
= sizeof(int),
934 .proc_handler
= proc_dointvec_minmax
,
940 .procname
= "tcp_sack",
941 .data
= &init_net
.ipv4
.sysctl_tcp_sack
,
942 .maxlen
= sizeof(int),
944 .proc_handler
= proc_dointvec
947 .procname
= "tcp_window_scaling",
948 .data
= &init_net
.ipv4
.sysctl_tcp_window_scaling
,
949 .maxlen
= sizeof(int),
951 .proc_handler
= proc_dointvec
954 .procname
= "tcp_timestamps",
955 .data
= &init_net
.ipv4
.sysctl_tcp_timestamps
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= proc_dointvec
961 .procname
= "tcp_early_retrans",
962 .data
= &init_net
.ipv4
.sysctl_tcp_early_retrans
,
963 .maxlen
= sizeof(int),
965 .proc_handler
= proc_dointvec_minmax
,
970 .procname
= "tcp_recovery",
971 .data
= &init_net
.ipv4
.sysctl_tcp_recovery
,
972 .maxlen
= sizeof(int),
974 .proc_handler
= proc_dointvec
,
977 .procname
= "tcp_thin_linear_timeouts",
978 .data
= &init_net
.ipv4
.sysctl_tcp_thin_linear_timeouts
,
979 .maxlen
= sizeof(int),
981 .proc_handler
= proc_dointvec
984 .procname
= "tcp_slow_start_after_idle",
985 .data
= &init_net
.ipv4
.sysctl_tcp_slow_start_after_idle
,
986 .maxlen
= sizeof(int),
988 .proc_handler
= proc_dointvec
991 .procname
= "tcp_retrans_collapse",
992 .data
= &init_net
.ipv4
.sysctl_tcp_retrans_collapse
,
993 .maxlen
= sizeof(int),
995 .proc_handler
= proc_dointvec
998 .procname
= "tcp_stdurg",
999 .data
= &init_net
.ipv4
.sysctl_tcp_stdurg
,
1000 .maxlen
= sizeof(int),
1002 .proc_handler
= proc_dointvec
1005 .procname
= "tcp_rfc1337",
1006 .data
= &init_net
.ipv4
.sysctl_tcp_rfc1337
,
1007 .maxlen
= sizeof(int),
1009 .proc_handler
= proc_dointvec
1012 .procname
= "tcp_abort_on_overflow",
1013 .data
= &init_net
.ipv4
.sysctl_tcp_abort_on_overflow
,
1014 .maxlen
= sizeof(int),
1016 .proc_handler
= proc_dointvec
1019 .procname
= "tcp_fack",
1020 .data
= &init_net
.ipv4
.sysctl_tcp_fack
,
1021 .maxlen
= sizeof(int),
1023 .proc_handler
= proc_dointvec
1026 .procname
= "tcp_max_reordering",
1027 .data
= &init_net
.ipv4
.sysctl_tcp_max_reordering
,
1028 .maxlen
= sizeof(int),
1030 .proc_handler
= proc_dointvec
1033 .procname
= "tcp_dsack",
1034 .data
= &init_net
.ipv4
.sysctl_tcp_dsack
,
1035 .maxlen
= sizeof(int),
1037 .proc_handler
= proc_dointvec
1040 .procname
= "tcp_app_win",
1041 .data
= &init_net
.ipv4
.sysctl_tcp_app_win
,
1042 .maxlen
= sizeof(int),
1044 .proc_handler
= proc_dointvec
1047 .procname
= "tcp_adv_win_scale",
1048 .data
= &init_net
.ipv4
.sysctl_tcp_adv_win_scale
,
1049 .maxlen
= sizeof(int),
1051 .proc_handler
= proc_dointvec_minmax
,
1052 .extra1
= &tcp_adv_win_scale_min
,
1053 .extra2
= &tcp_adv_win_scale_max
,
1056 .procname
= "tcp_frto",
1057 .data
= &init_net
.ipv4
.sysctl_tcp_frto
,
1058 .maxlen
= sizeof(int),
1060 .proc_handler
= proc_dointvec
1063 .procname
= "tcp_no_metrics_save",
1064 .data
= &init_net
.ipv4
.sysctl_tcp_nometrics_save
,
1065 .maxlen
= sizeof(int),
1067 .proc_handler
= proc_dointvec
,
1070 .procname
= "tcp_moderate_rcvbuf",
1071 .data
= &init_net
.ipv4
.sysctl_tcp_moderate_rcvbuf
,
1072 .maxlen
= sizeof(int),
1074 .proc_handler
= proc_dointvec
,
1077 .procname
= "tcp_tso_win_divisor",
1078 .data
= &init_net
.ipv4
.sysctl_tcp_tso_win_divisor
,
1079 .maxlen
= sizeof(int),
1081 .proc_handler
= proc_dointvec
,
1084 .procname
= "tcp_workaround_signed_windows",
1085 .data
= &init_net
.ipv4
.sysctl_tcp_workaround_signed_windows
,
1086 .maxlen
= sizeof(int),
1088 .proc_handler
= proc_dointvec
1091 .procname
= "tcp_limit_output_bytes",
1092 .data
= &init_net
.ipv4
.sysctl_tcp_limit_output_bytes
,
1093 .maxlen
= sizeof(int),
1095 .proc_handler
= proc_dointvec
1098 .procname
= "tcp_challenge_ack_limit",
1099 .data
= &init_net
.ipv4
.sysctl_tcp_challenge_ack_limit
,
1100 .maxlen
= sizeof(int),
1102 .proc_handler
= proc_dointvec
1105 .procname
= "tcp_min_tso_segs",
1106 .data
= &init_net
.ipv4
.sysctl_tcp_min_tso_segs
,
1107 .maxlen
= sizeof(int),
1109 .proc_handler
= proc_dointvec_minmax
,
1111 .extra2
= &gso_max_segs
,
1114 .procname
= "tcp_min_rtt_wlen",
1115 .data
= &init_net
.ipv4
.sysctl_tcp_min_rtt_wlen
,
1116 .maxlen
= sizeof(int),
1118 .proc_handler
= proc_dointvec
1121 .procname
= "tcp_autocorking",
1122 .data
= &init_net
.ipv4
.sysctl_tcp_autocorking
,
1123 .maxlen
= sizeof(int),
1125 .proc_handler
= proc_dointvec_minmax
,
1130 .procname
= "tcp_invalid_ratelimit",
1131 .data
= &init_net
.ipv4
.sysctl_tcp_invalid_ratelimit
,
1132 .maxlen
= sizeof(int),
1134 .proc_handler
= proc_dointvec_ms_jiffies
,
1137 .procname
= "tcp_pacing_ss_ratio",
1138 .data
= &init_net
.ipv4
.sysctl_tcp_pacing_ss_ratio
,
1139 .maxlen
= sizeof(int),
1141 .proc_handler
= proc_dointvec_minmax
,
1143 .extra2
= &thousand
,
1146 .procname
= "tcp_pacing_ca_ratio",
1147 .data
= &init_net
.ipv4
.sysctl_tcp_pacing_ca_ratio
,
1148 .maxlen
= sizeof(int),
1150 .proc_handler
= proc_dointvec_minmax
,
1152 .extra2
= &thousand
,
1155 .procname
= "tcp_wmem",
1156 .data
= &init_net
.ipv4
.sysctl_tcp_wmem
,
1157 .maxlen
= sizeof(init_net
.ipv4
.sysctl_tcp_wmem
),
1159 .proc_handler
= proc_dointvec_minmax
,
1163 .procname
= "tcp_rmem",
1164 .data
= &init_net
.ipv4
.sysctl_tcp_rmem
,
1165 .maxlen
= sizeof(init_net
.ipv4
.sysctl_tcp_rmem
),
1167 .proc_handler
= proc_dointvec_minmax
,
1173 static __net_init
int ipv4_sysctl_init_net(struct net
*net
)
1175 struct ctl_table
*table
;
1177 table
= ipv4_net_table
;
1178 if (!net_eq(net
, &init_net
)) {
1181 table
= kmemdup(table
, sizeof(ipv4_net_table
), GFP_KERNEL
);
1185 /* Update the variables to point into the current struct net */
1186 for (i
= 0; i
< ARRAY_SIZE(ipv4_net_table
) - 1; i
++)
1187 table
[i
].data
+= (void *)net
- (void *)&init_net
;
1190 net
->ipv4
.ipv4_hdr
= register_net_sysctl(net
, "net/ipv4", table
);
1191 if (!net
->ipv4
.ipv4_hdr
)
1194 net
->ipv4
.sysctl_local_reserved_ports
= kzalloc(65536 / 8, GFP_KERNEL
);
1195 if (!net
->ipv4
.sysctl_local_reserved_ports
)
1201 unregister_net_sysctl_table(net
->ipv4
.ipv4_hdr
);
1203 if (!net_eq(net
, &init_net
))
1209 static __net_exit
void ipv4_sysctl_exit_net(struct net
*net
)
1211 struct ctl_table
*table
;
1213 kfree(net
->ipv4
.sysctl_local_reserved_ports
);
1214 table
= net
->ipv4
.ipv4_hdr
->ctl_table_arg
;
1215 unregister_net_sysctl_table(net
->ipv4
.ipv4_hdr
);
1219 static __net_initdata
struct pernet_operations ipv4_sysctl_ops
= {
1220 .init
= ipv4_sysctl_init_net
,
1221 .exit
= ipv4_sysctl_exit_net
,
1224 static __init
int sysctl_ipv4_init(void)
1226 struct ctl_table_header
*hdr
;
1228 hdr
= register_net_sysctl(&init_net
, "net/ipv4", ipv4_table
);
1232 if (register_pernet_subsys(&ipv4_sysctl_ops
)) {
1233 unregister_net_sysctl_table(hdr
);
1240 __initcall(sysctl_ipv4_init
);