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>
35 static int thousand = 1000;
36 static int gso_max_segs = GSO_MAX_SEGS;
37 static int tcp_retr1_max = 255;
38 static int ip_local_port_range_min[] = { 1, 1 };
39 static int ip_local_port_range_max[] = { 65535, 65535 };
40 static int tcp_adv_win_scale_min = -31;
41 static int tcp_adv_win_scale_max = 31;
42 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
43 static int tcp_min_snd_mss_max = 65535;
44 static int ip_privileged_port_min;
45 static int ip_privileged_port_max = 65535;
46 static int ip_ttl_min = 1;
47 static int ip_ttl_max = 255;
48 static int tcp_syn_retries_min = 1;
49 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
50 static int ip_ping_group_range_min[] = { 0, 0 };
51 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
52 static int comp_sack_nr_max = 255;
53 static u32 u32_max_div_HZ = UINT_MAX / HZ;
54 static int one_day_secs = 24 * 3600;
57 static int sysctl_tcp_low_latency __read_mostly;
59 /* Update system visible IP port range */
60 static void set_local_port_range(struct net *net, int range[2])
62 bool same_parity = !((range[0] ^ range[1]) & 1);
64 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
65 if (same_parity && !net->ipv4.ip_local_ports.warned) {
66 net->ipv4.ip_local_ports.warned = true;
67 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
69 net->ipv4.ip_local_ports.range[0] = range[0];
70 net->ipv4.ip_local_ports.range[1] = range[1];
71 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
74 /* Validate changes from /proc interface. */
75 static int ipv4_local_port_range(struct ctl_table *table, int write,
77 size_t *lenp, loff_t *ppos)
80 container_of(table->data, struct net, ipv4.ip_local_ports.range);
83 struct ctl_table tmp = {
85 .maxlen = sizeof(range),
87 .extra1 = &ip_local_port_range_min,
88 .extra2 = &ip_local_port_range_max,
91 inet_get_local_port_range(net, &range[0], &range[1]);
93 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
95 if (write && ret == 0) {
96 /* Ensure that the upper limit is not smaller than the lower,
97 * and that the lower does not encroach upon the privileged
100 if ((range[1] < range[0]) ||
101 (range[0] < net->ipv4.sysctl_ip_prot_sock))
104 set_local_port_range(net, range);
110 /* Validate changes from /proc interface. */
111 static int ipv4_privileged_ports(struct ctl_table *table, int write,
112 void __user *buffer, size_t *lenp, loff_t *ppos)
114 struct net *net = container_of(table->data, struct net,
115 ipv4.sysctl_ip_prot_sock);
119 struct ctl_table tmp = {
121 .maxlen = sizeof(pports),
123 .extra1 = &ip_privileged_port_min,
124 .extra2 = &ip_privileged_port_max,
127 pports = net->ipv4.sysctl_ip_prot_sock;
129 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
131 if (write && ret == 0) {
132 inet_get_local_port_range(net, &range[0], &range[1]);
133 /* Ensure that the local port range doesn't overlap with the
134 * privileged port range.
136 if (range[0] < pports)
139 net->ipv4.sysctl_ip_prot_sock = pports;
145 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
147 kgid_t *data = table->data;
149 container_of(table->data, struct net, ipv4.ping_group_range.range);
152 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
156 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
159 /* Update system visible IP port range */
160 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
162 kgid_t *data = table->data;
164 container_of(table->data, struct net, ipv4.ping_group_range.range);
165 write_seqlock(&net->ipv4.ping_group_range.lock);
168 write_sequnlock(&net->ipv4.ping_group_range.lock);
171 /* Validate changes from /proc interface. */
172 static int ipv4_ping_group_range(struct ctl_table *table, int write,
174 size_t *lenp, loff_t *ppos)
176 struct user_namespace *user_ns = current_user_ns();
180 struct ctl_table tmp = {
182 .maxlen = sizeof(urange),
184 .extra1 = &ip_ping_group_range_min,
185 .extra2 = &ip_ping_group_range_max,
188 inet_get_ping_group_range_table(table, &low, &high);
189 urange[0] = from_kgid_munged(user_ns, low);
190 urange[1] = from_kgid_munged(user_ns, high);
191 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
193 if (write && ret == 0) {
194 low = make_kgid(user_ns, urange[0]);
195 high = make_kgid(user_ns, urange[1]);
196 if (!gid_valid(low) || !gid_valid(high))
198 if (urange[1] < urange[0] || gid_lt(high, low)) {
199 low = make_kgid(&init_user_ns, 1);
200 high = make_kgid(&init_user_ns, 0);
202 set_ping_group_range(table, low, high);
208 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
210 size_t *lenp, loff_t *ppos)
215 net = container_of(table->data, struct net,
216 ipv4.sysctl_ip_fwd_update_priority);
217 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
218 if (write && ret == 0)
219 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
225 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos)
228 struct net *net = container_of(ctl->data, struct net,
229 ipv4.tcp_congestion_control);
230 char val[TCP_CA_NAME_MAX];
231 struct ctl_table tbl = {
233 .maxlen = TCP_CA_NAME_MAX,
237 tcp_get_default_congestion_control(net, val);
239 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
240 if (write && ret == 0)
241 ret = tcp_set_default_congestion_control(net, val);
245 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
247 void __user *buffer, size_t *lenp,
250 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
253 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
256 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
257 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
262 static int proc_allowed_congestion_control(struct ctl_table *ctl,
264 void __user *buffer, size_t *lenp,
267 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
270 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
274 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
275 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
276 if (write && ret == 0)
277 ret = tcp_set_allowed_congestion_control(tbl.data);
282 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
283 void __user *buffer, size_t *lenp,
286 struct net *net = container_of(table->data, struct net,
287 ipv4.sysctl_tcp_fastopen);
288 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
289 struct tcp_fastopen_context *ctxt;
290 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
294 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
299 ctxt = rcu_dereference(net->ipv4.tcp_fastopen_ctx);
301 memcpy(key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
303 memset(key, 0, sizeof(key));
306 for (i = 0; i < ARRAY_SIZE(key); i++)
307 user_key[i] = le32_to_cpu(key[i]);
309 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
310 user_key[0], user_key[1], user_key[2], user_key[3]);
311 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
313 if (write && ret == 0) {
314 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
315 user_key + 2, user_key + 3) != 4) {
320 for (i = 0; i < ARRAY_SIZE(user_key); i++)
321 key[i] = cpu_to_le32(user_key[i]);
323 tcp_fastopen_reset_cipher(net, NULL, key,
324 TCP_FASTOPEN_KEY_LENGTH);
328 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
329 user_key[0], user_key[1], user_key[2], user_key[3],
330 (char *)tbl.data, ret);
335 static void proc_configure_early_demux(int enabled, int protocol)
337 struct net_protocol *ipprot;
338 #if IS_ENABLED(CONFIG_IPV6)
339 struct inet6_protocol *ip6prot;
344 ipprot = rcu_dereference(inet_protos[protocol]);
346 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
349 #if IS_ENABLED(CONFIG_IPV6)
350 ip6prot = rcu_dereference(inet6_protos[protocol]);
352 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
358 static int proc_tcp_early_demux(struct ctl_table *table, int write,
359 void __user *buffer, size_t *lenp, loff_t *ppos)
363 ret = proc_dointvec(table, write, buffer, lenp, ppos);
366 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
368 proc_configure_early_demux(enabled, IPPROTO_TCP);
374 static int proc_udp_early_demux(struct ctl_table *table, int write,
375 void __user *buffer, size_t *lenp, loff_t *ppos)
379 ret = proc_dointvec(table, write, buffer, lenp, ppos);
382 int enabled = init_net.ipv4.sysctl_udp_early_demux;
384 proc_configure_early_demux(enabled, IPPROTO_UDP);
390 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
393 size_t *lenp, loff_t *ppos)
395 struct net *net = container_of(table->data, struct net,
396 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
399 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
400 if (write && ret == 0)
401 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
406 static int proc_tcp_available_ulp(struct ctl_table *ctl,
408 void __user *buffer, size_t *lenp,
411 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
414 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
417 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
418 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
424 #ifdef CONFIG_IP_ROUTE_MULTIPATH
425 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
426 void __user *buffer, size_t *lenp,
429 struct net *net = container_of(table->data, struct net,
430 ipv4.sysctl_fib_multipath_hash_policy);
433 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
434 if (write && ret == 0)
435 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
441 static struct ctl_table ipv4_table[] = {
443 .procname = "tcp_max_orphans",
444 .data = &sysctl_tcp_max_orphans,
445 .maxlen = sizeof(int),
447 .proc_handler = proc_dointvec
450 .procname = "inet_peer_threshold",
451 .data = &inet_peer_threshold,
452 .maxlen = sizeof(int),
454 .proc_handler = proc_dointvec
457 .procname = "inet_peer_minttl",
458 .data = &inet_peer_minttl,
459 .maxlen = sizeof(int),
461 .proc_handler = proc_dointvec_jiffies,
464 .procname = "inet_peer_maxttl",
465 .data = &inet_peer_maxttl,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec_jiffies,
471 .procname = "tcp_mem",
472 .maxlen = sizeof(sysctl_tcp_mem),
473 .data = &sysctl_tcp_mem,
475 .proc_handler = proc_doulongvec_minmax,
478 .procname = "tcp_low_latency",
479 .data = &sysctl_tcp_low_latency,
480 .maxlen = sizeof(int),
482 .proc_handler = proc_dointvec
484 #ifdef CONFIG_NETLABEL
486 .procname = "cipso_cache_enable",
487 .data = &cipso_v4_cache_enabled,
488 .maxlen = sizeof(int),
490 .proc_handler = proc_dointvec,
493 .procname = "cipso_cache_bucket_size",
494 .data = &cipso_v4_cache_bucketsize,
495 .maxlen = sizeof(int),
497 .proc_handler = proc_dointvec,
500 .procname = "cipso_rbm_optfmt",
501 .data = &cipso_v4_rbm_optfmt,
502 .maxlen = sizeof(int),
504 .proc_handler = proc_dointvec,
507 .procname = "cipso_rbm_strictvalid",
508 .data = &cipso_v4_rbm_strictvalid,
509 .maxlen = sizeof(int),
511 .proc_handler = proc_dointvec,
513 #endif /* CONFIG_NETLABEL */
515 .procname = "tcp_available_congestion_control",
516 .maxlen = TCP_CA_BUF_MAX,
518 .proc_handler = proc_tcp_available_congestion_control,
521 .procname = "tcp_allowed_congestion_control",
522 .maxlen = TCP_CA_BUF_MAX,
524 .proc_handler = proc_allowed_congestion_control,
527 .procname = "tcp_available_ulp",
528 .maxlen = TCP_ULP_BUF_MAX,
530 .proc_handler = proc_tcp_available_ulp,
533 .procname = "icmp_msgs_per_sec",
534 .data = &sysctl_icmp_msgs_per_sec,
535 .maxlen = sizeof(int),
537 .proc_handler = proc_dointvec_minmax,
541 .procname = "icmp_msgs_burst",
542 .data = &sysctl_icmp_msgs_burst,
543 .maxlen = sizeof(int),
545 .proc_handler = proc_dointvec_minmax,
549 .procname = "udp_mem",
550 .data = &sysctl_udp_mem,
551 .maxlen = sizeof(sysctl_udp_mem),
553 .proc_handler = proc_doulongvec_minmax,
558 static struct ctl_table ipv4_net_table[] = {
560 .procname = "icmp_echo_ignore_all",
561 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
562 .maxlen = sizeof(int),
564 .proc_handler = proc_dointvec
567 .procname = "icmp_echo_ignore_broadcasts",
568 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
569 .maxlen = sizeof(int),
571 .proc_handler = proc_dointvec
574 .procname = "icmp_ignore_bogus_error_responses",
575 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
576 .maxlen = sizeof(int),
578 .proc_handler = proc_dointvec
581 .procname = "icmp_errors_use_inbound_ifaddr",
582 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
583 .maxlen = sizeof(int),
585 .proc_handler = proc_dointvec
588 .procname = "icmp_ratelimit",
589 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
590 .maxlen = sizeof(int),
592 .proc_handler = proc_dointvec_ms_jiffies,
595 .procname = "icmp_ratemask",
596 .data = &init_net.ipv4.sysctl_icmp_ratemask,
597 .maxlen = sizeof(int),
599 .proc_handler = proc_dointvec
602 .procname = "ping_group_range",
603 .data = &init_net.ipv4.ping_group_range.range,
604 .maxlen = sizeof(gid_t)*2,
606 .proc_handler = ipv4_ping_group_range,
609 .procname = "tcp_ecn",
610 .data = &init_net.ipv4.sysctl_tcp_ecn,
611 .maxlen = sizeof(int),
613 .proc_handler = proc_dointvec
616 .procname = "tcp_ecn_fallback",
617 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
618 .maxlen = sizeof(int),
620 .proc_handler = proc_dointvec
623 .procname = "ip_dynaddr",
624 .data = &init_net.ipv4.sysctl_ip_dynaddr,
625 .maxlen = sizeof(int),
627 .proc_handler = proc_dointvec
630 .procname = "ip_early_demux",
631 .data = &init_net.ipv4.sysctl_ip_early_demux,
632 .maxlen = sizeof(int),
634 .proc_handler = proc_dointvec
637 .procname = "udp_early_demux",
638 .data = &init_net.ipv4.sysctl_udp_early_demux,
639 .maxlen = sizeof(int),
641 .proc_handler = proc_udp_early_demux
644 .procname = "tcp_early_demux",
645 .data = &init_net.ipv4.sysctl_tcp_early_demux,
646 .maxlen = sizeof(int),
648 .proc_handler = proc_tcp_early_demux
651 .procname = "ip_default_ttl",
652 .data = &init_net.ipv4.sysctl_ip_default_ttl,
653 .maxlen = sizeof(int),
655 .proc_handler = proc_dointvec_minmax,
656 .extra1 = &ip_ttl_min,
657 .extra2 = &ip_ttl_max,
660 .procname = "ip_local_port_range",
661 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
662 .data = &init_net.ipv4.ip_local_ports.range,
664 .proc_handler = ipv4_local_port_range,
667 .procname = "ip_local_reserved_ports",
668 .data = &init_net.ipv4.sysctl_local_reserved_ports,
671 .proc_handler = proc_do_large_bitmap,
674 .procname = "ip_no_pmtu_disc",
675 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
676 .maxlen = sizeof(int),
678 .proc_handler = proc_dointvec
681 .procname = "ip_forward_use_pmtu",
682 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
683 .maxlen = sizeof(int),
685 .proc_handler = proc_dointvec,
688 .procname = "ip_forward_update_priority",
689 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
690 .maxlen = sizeof(int),
692 .proc_handler = ipv4_fwd_update_priority,
697 .procname = "ip_nonlocal_bind",
698 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
699 .maxlen = sizeof(int),
701 .proc_handler = proc_dointvec
704 .procname = "fwmark_reflect",
705 .data = &init_net.ipv4.sysctl_fwmark_reflect,
706 .maxlen = sizeof(int),
708 .proc_handler = proc_dointvec,
711 .procname = "tcp_fwmark_accept",
712 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
713 .maxlen = sizeof(int),
715 .proc_handler = proc_dointvec,
717 #ifdef CONFIG_NET_L3_MASTER_DEV
719 .procname = "tcp_l3mdev_accept",
720 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
721 .maxlen = sizeof(int),
723 .proc_handler = proc_dointvec_minmax,
729 .procname = "tcp_mtu_probing",
730 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
731 .maxlen = sizeof(int),
733 .proc_handler = proc_dointvec,
736 .procname = "tcp_base_mss",
737 .data = &init_net.ipv4.sysctl_tcp_base_mss,
738 .maxlen = sizeof(int),
740 .proc_handler = proc_dointvec,
743 .procname = "tcp_min_snd_mss",
744 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
745 .maxlen = sizeof(int),
747 .proc_handler = proc_dointvec_minmax,
748 .extra1 = &tcp_min_snd_mss_min,
749 .extra2 = &tcp_min_snd_mss_max,
752 .procname = "tcp_probe_threshold",
753 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
754 .maxlen = sizeof(int),
756 .proc_handler = proc_dointvec,
759 .procname = "tcp_probe_interval",
760 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
761 .maxlen = sizeof(u32),
763 .proc_handler = proc_douintvec_minmax,
764 .extra2 = &u32_max_div_HZ,
767 .procname = "igmp_link_local_mcast_reports",
768 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
769 .maxlen = sizeof(int),
771 .proc_handler = proc_dointvec
774 .procname = "igmp_max_memberships",
775 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
776 .maxlen = sizeof(int),
778 .proc_handler = proc_dointvec
781 .procname = "igmp_max_msf",
782 .data = &init_net.ipv4.sysctl_igmp_max_msf,
783 .maxlen = sizeof(int),
785 .proc_handler = proc_dointvec
787 #ifdef CONFIG_IP_MULTICAST
789 .procname = "igmp_qrv",
790 .data = &init_net.ipv4.sysctl_igmp_qrv,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec_minmax,
798 .procname = "tcp_congestion_control",
799 .data = &init_net.ipv4.tcp_congestion_control,
801 .maxlen = TCP_CA_NAME_MAX,
802 .proc_handler = proc_tcp_congestion_control,
805 .procname = "tcp_keepalive_time",
806 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
807 .maxlen = sizeof(int),
809 .proc_handler = proc_dointvec_jiffies,
812 .procname = "tcp_keepalive_probes",
813 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
814 .maxlen = sizeof(int),
816 .proc_handler = proc_dointvec
819 .procname = "tcp_keepalive_intvl",
820 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
821 .maxlen = sizeof(int),
823 .proc_handler = proc_dointvec_jiffies,
826 .procname = "tcp_syn_retries",
827 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
828 .maxlen = sizeof(int),
830 .proc_handler = proc_dointvec_minmax,
831 .extra1 = &tcp_syn_retries_min,
832 .extra2 = &tcp_syn_retries_max
835 .procname = "tcp_synack_retries",
836 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
837 .maxlen = sizeof(int),
839 .proc_handler = proc_dointvec
841 #ifdef CONFIG_SYN_COOKIES
843 .procname = "tcp_syncookies",
844 .data = &init_net.ipv4.sysctl_tcp_syncookies,
845 .maxlen = sizeof(int),
847 .proc_handler = proc_dointvec
851 .procname = "tcp_reordering",
852 .data = &init_net.ipv4.sysctl_tcp_reordering,
853 .maxlen = sizeof(int),
855 .proc_handler = proc_dointvec
858 .procname = "tcp_retries1",
859 .data = &init_net.ipv4.sysctl_tcp_retries1,
860 .maxlen = sizeof(int),
862 .proc_handler = proc_dointvec_minmax,
863 .extra2 = &tcp_retr1_max
866 .procname = "tcp_retries2",
867 .data = &init_net.ipv4.sysctl_tcp_retries2,
868 .maxlen = sizeof(int),
870 .proc_handler = proc_dointvec
873 .procname = "tcp_orphan_retries",
874 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
875 .maxlen = sizeof(int),
877 .proc_handler = proc_dointvec
880 .procname = "tcp_fin_timeout",
881 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
882 .maxlen = sizeof(int),
884 .proc_handler = proc_dointvec_jiffies,
887 .procname = "tcp_notsent_lowat",
888 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
889 .maxlen = sizeof(unsigned int),
891 .proc_handler = proc_douintvec,
894 .procname = "tcp_tw_reuse",
895 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
896 .maxlen = sizeof(int),
898 .proc_handler = proc_dointvec_minmax,
903 .procname = "tcp_max_tw_buckets",
904 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
905 .maxlen = sizeof(int),
907 .proc_handler = proc_dointvec
910 .procname = "tcp_max_syn_backlog",
911 .data = &init_net.ipv4.sysctl_max_syn_backlog,
912 .maxlen = sizeof(int),
914 .proc_handler = proc_dointvec
917 .procname = "tcp_fastopen",
918 .data = &init_net.ipv4.sysctl_tcp_fastopen,
919 .maxlen = sizeof(int),
921 .proc_handler = proc_dointvec,
924 .procname = "tcp_fastopen_key",
926 .data = &init_net.ipv4.sysctl_tcp_fastopen,
927 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
928 .proc_handler = proc_tcp_fastopen_key,
931 .procname = "tcp_fastopen_blackhole_timeout_sec",
932 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
933 .maxlen = sizeof(int),
935 .proc_handler = proc_tfo_blackhole_detect_timeout,
938 #ifdef CONFIG_IP_ROUTE_MULTIPATH
940 .procname = "fib_multipath_use_neigh",
941 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
942 .maxlen = sizeof(int),
944 .proc_handler = proc_dointvec_minmax,
949 .procname = "fib_multipath_hash_policy",
950 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
951 .maxlen = sizeof(int),
953 .proc_handler = proc_fib_multipath_hash_policy,
959 .procname = "ip_unprivileged_port_start",
960 .maxlen = sizeof(int),
961 .data = &init_net.ipv4.sysctl_ip_prot_sock,
963 .proc_handler = ipv4_privileged_ports,
965 #ifdef CONFIG_NET_L3_MASTER_DEV
967 .procname = "udp_l3mdev_accept",
968 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
969 .maxlen = sizeof(int),
971 .proc_handler = proc_dointvec_minmax,
977 .procname = "tcp_sack",
978 .data = &init_net.ipv4.sysctl_tcp_sack,
979 .maxlen = sizeof(int),
981 .proc_handler = proc_dointvec
984 .procname = "tcp_window_scaling",
985 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
986 .maxlen = sizeof(int),
988 .proc_handler = proc_dointvec
991 .procname = "tcp_timestamps",
992 .data = &init_net.ipv4.sysctl_tcp_timestamps,
993 .maxlen = sizeof(int),
995 .proc_handler = proc_dointvec
998 .procname = "tcp_early_retrans",
999 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1000 .maxlen = sizeof(int),
1002 .proc_handler = proc_dointvec_minmax,
1007 .procname = "tcp_recovery",
1008 .data = &init_net.ipv4.sysctl_tcp_recovery,
1009 .maxlen = sizeof(int),
1011 .proc_handler = proc_dointvec,
1014 .procname = "tcp_thin_linear_timeouts",
1015 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1016 .maxlen = sizeof(int),
1018 .proc_handler = proc_dointvec
1021 .procname = "tcp_slow_start_after_idle",
1022 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1023 .maxlen = sizeof(int),
1025 .proc_handler = proc_dointvec
1028 .procname = "tcp_retrans_collapse",
1029 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1030 .maxlen = sizeof(int),
1032 .proc_handler = proc_dointvec
1035 .procname = "tcp_stdurg",
1036 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1037 .maxlen = sizeof(int),
1039 .proc_handler = proc_dointvec
1042 .procname = "tcp_rfc1337",
1043 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1044 .maxlen = sizeof(int),
1046 .proc_handler = proc_dointvec
1049 .procname = "tcp_abort_on_overflow",
1050 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1051 .maxlen = sizeof(int),
1053 .proc_handler = proc_dointvec
1056 .procname = "tcp_fack",
1057 .data = &init_net.ipv4.sysctl_tcp_fack,
1058 .maxlen = sizeof(int),
1060 .proc_handler = proc_dointvec
1063 .procname = "tcp_max_reordering",
1064 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1065 .maxlen = sizeof(int),
1067 .proc_handler = proc_dointvec
1070 .procname = "tcp_dsack",
1071 .data = &init_net.ipv4.sysctl_tcp_dsack,
1072 .maxlen = sizeof(int),
1074 .proc_handler = proc_dointvec
1077 .procname = "tcp_app_win",
1078 .data = &init_net.ipv4.sysctl_tcp_app_win,
1079 .maxlen = sizeof(int),
1081 .proc_handler = proc_dointvec
1084 .procname = "tcp_adv_win_scale",
1085 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1086 .maxlen = sizeof(int),
1088 .proc_handler = proc_dointvec_minmax,
1089 .extra1 = &tcp_adv_win_scale_min,
1090 .extra2 = &tcp_adv_win_scale_max,
1093 .procname = "tcp_frto",
1094 .data = &init_net.ipv4.sysctl_tcp_frto,
1095 .maxlen = sizeof(int),
1097 .proc_handler = proc_dointvec
1100 .procname = "tcp_no_metrics_save",
1101 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1102 .maxlen = sizeof(int),
1104 .proc_handler = proc_dointvec,
1107 .procname = "tcp_moderate_rcvbuf",
1108 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1109 .maxlen = sizeof(int),
1111 .proc_handler = proc_dointvec,
1114 .procname = "tcp_tso_win_divisor",
1115 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1116 .maxlen = sizeof(int),
1118 .proc_handler = proc_dointvec,
1121 .procname = "tcp_workaround_signed_windows",
1122 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1123 .maxlen = sizeof(int),
1125 .proc_handler = proc_dointvec
1128 .procname = "tcp_limit_output_bytes",
1129 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1130 .maxlen = sizeof(int),
1132 .proc_handler = proc_dointvec
1135 .procname = "tcp_challenge_ack_limit",
1136 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1137 .maxlen = sizeof(int),
1139 .proc_handler = proc_dointvec
1142 .procname = "tcp_min_tso_segs",
1143 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1144 .maxlen = sizeof(int),
1146 .proc_handler = proc_dointvec_minmax,
1148 .extra2 = &gso_max_segs,
1151 .procname = "tcp_min_rtt_wlen",
1152 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1153 .maxlen = sizeof(int),
1155 .proc_handler = proc_dointvec_minmax,
1157 .extra2 = &one_day_secs
1160 .procname = "tcp_autocorking",
1161 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1162 .maxlen = sizeof(int),
1164 .proc_handler = proc_dointvec_minmax,
1169 .procname = "tcp_invalid_ratelimit",
1170 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1171 .maxlen = sizeof(int),
1173 .proc_handler = proc_dointvec_ms_jiffies,
1176 .procname = "tcp_pacing_ss_ratio",
1177 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1178 .maxlen = sizeof(int),
1180 .proc_handler = proc_dointvec_minmax,
1182 .extra2 = &thousand,
1185 .procname = "tcp_pacing_ca_ratio",
1186 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1187 .maxlen = sizeof(int),
1189 .proc_handler = proc_dointvec_minmax,
1191 .extra2 = &thousand,
1194 .procname = "tcp_wmem",
1195 .data = &init_net.ipv4.sysctl_tcp_wmem,
1196 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1198 .proc_handler = proc_dointvec_minmax,
1202 .procname = "tcp_rmem",
1203 .data = &init_net.ipv4.sysctl_tcp_rmem,
1204 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1206 .proc_handler = proc_dointvec_minmax,
1210 .procname = "tcp_comp_sack_delay_ns",
1211 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1212 .maxlen = sizeof(unsigned long),
1214 .proc_handler = proc_doulongvec_minmax,
1217 .procname = "tcp_comp_sack_nr",
1218 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1219 .maxlen = sizeof(int),
1221 .proc_handler = proc_dointvec_minmax,
1223 .extra2 = &comp_sack_nr_max,
1226 .procname = "udp_rmem_min",
1227 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1228 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1230 .proc_handler = proc_dointvec_minmax,
1234 .procname = "udp_wmem_min",
1235 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1236 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1238 .proc_handler = proc_dointvec_minmax,
1244 static __net_init int ipv4_sysctl_init_net(struct net *net)
1246 struct ctl_table *table;
1248 table = ipv4_net_table;
1249 if (!net_eq(net, &init_net)) {
1252 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1256 /* Update the variables to point into the current struct net */
1257 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1258 table[i].data += (void *)net - (void *)&init_net;
1261 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1262 if (!net->ipv4.ipv4_hdr)
1265 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1266 if (!net->ipv4.sysctl_local_reserved_ports)
1272 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1274 if (!net_eq(net, &init_net))
1280 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1282 struct ctl_table *table;
1284 kfree(net->ipv4.sysctl_local_reserved_ports);
1285 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1286 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1290 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1291 .init = ipv4_sysctl_init_net,
1292 .exit = ipv4_sysctl_exit_net,
1295 static __init int sysctl_ipv4_init(void)
1297 struct ctl_table_header *hdr;
1299 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1303 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1304 unregister_net_sysctl_table(hdr);
1311 __initcall(sysctl_ipv4_init);