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>
33 static int thousand = 1000;
34 static int gso_max_segs = GSO_MAX_SEGS;
35 static int tcp_retr1_max = 255;
36 static int ip_local_port_range_min[] = { 1, 1 };
37 static int ip_local_port_range_max[] = { 65535, 65535 };
38 static int tcp_adv_win_scale_min = -31;
39 static int tcp_adv_win_scale_max = 31;
40 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
41 static int tcp_min_snd_mss_max = 65535;
42 static int ip_privileged_port_min;
43 static int ip_privileged_port_max = 65535;
44 static int ip_ttl_min = 1;
45 static int ip_ttl_max = 255;
46 static int tcp_syn_retries_min = 1;
47 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
48 static int ip_ping_group_range_min[] = { 0, 0 };
49 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
50 static int comp_sack_nr_max = 255;
51 static u32 u32_max_div_HZ = UINT_MAX / HZ;
52 static int one_day_secs = 24 * 3600;
55 static int sysctl_tcp_low_latency __read_mostly;
57 /* Update system visible IP port range */
58 static void set_local_port_range(struct net *net, int range[2])
60 bool same_parity = !((range[0] ^ range[1]) & 1);
62 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
63 if (same_parity && !net->ipv4.ip_local_ports.warned) {
64 net->ipv4.ip_local_ports.warned = true;
65 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
67 net->ipv4.ip_local_ports.range[0] = range[0];
68 net->ipv4.ip_local_ports.range[1] = range[1];
69 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
72 /* Validate changes from /proc interface. */
73 static int ipv4_local_port_range(struct ctl_table *table, int write,
74 void *buffer, size_t *lenp, loff_t *ppos)
77 container_of(table->data, struct net, ipv4.ip_local_ports.range);
80 struct ctl_table tmp = {
82 .maxlen = sizeof(range),
84 .extra1 = &ip_local_port_range_min,
85 .extra2 = &ip_local_port_range_max,
88 inet_get_local_port_range(net, &range[0], &range[1]);
90 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
92 if (write && ret == 0) {
93 /* Ensure that the upper limit is not smaller than the lower,
94 * and that the lower does not encroach upon the privileged
97 if ((range[1] < range[0]) ||
98 (range[0] < net->ipv4.sysctl_ip_prot_sock))
101 set_local_port_range(net, range);
107 /* Validate changes from /proc interface. */
108 static int ipv4_privileged_ports(struct ctl_table *table, int write,
109 void *buffer, size_t *lenp, loff_t *ppos)
111 struct net *net = container_of(table->data, struct net,
112 ipv4.sysctl_ip_prot_sock);
116 struct ctl_table tmp = {
118 .maxlen = sizeof(pports),
120 .extra1 = &ip_privileged_port_min,
121 .extra2 = &ip_privileged_port_max,
124 pports = net->ipv4.sysctl_ip_prot_sock;
126 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
128 if (write && ret == 0) {
129 inet_get_local_port_range(net, &range[0], &range[1]);
130 /* Ensure that the local port range doesn't overlap with the
131 * privileged port range.
133 if (range[0] < pports)
136 net->ipv4.sysctl_ip_prot_sock = pports;
142 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
144 kgid_t *data = table->data;
146 container_of(table->data, struct net, ipv4.ping_group_range.range);
149 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
153 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
156 /* Update system visible IP port range */
157 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
159 kgid_t *data = table->data;
161 container_of(table->data, struct net, ipv4.ping_group_range.range);
162 write_seqlock(&net->ipv4.ping_group_range.lock);
165 write_sequnlock(&net->ipv4.ping_group_range.lock);
168 /* Validate changes from /proc interface. */
169 static int ipv4_ping_group_range(struct ctl_table *table, int write,
170 void *buffer, size_t *lenp, loff_t *ppos)
172 struct user_namespace *user_ns = current_user_ns();
176 struct ctl_table tmp = {
178 .maxlen = sizeof(urange),
180 .extra1 = &ip_ping_group_range_min,
181 .extra2 = &ip_ping_group_range_max,
184 inet_get_ping_group_range_table(table, &low, &high);
185 urange[0] = from_kgid_munged(user_ns, low);
186 urange[1] = from_kgid_munged(user_ns, high);
187 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
189 if (write && ret == 0) {
190 low = make_kgid(user_ns, urange[0]);
191 high = make_kgid(user_ns, urange[1]);
192 if (!gid_valid(low) || !gid_valid(high))
194 if (urange[1] < urange[0] || gid_lt(high, low)) {
195 low = make_kgid(&init_user_ns, 1);
196 high = make_kgid(&init_user_ns, 0);
198 set_ping_group_range(table, low, high);
204 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
205 void *buffer, size_t *lenp, loff_t *ppos)
210 net = container_of(table->data, struct net,
211 ipv4.sysctl_ip_fwd_update_priority);
212 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
213 if (write && ret == 0)
214 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
220 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
221 void *buffer, size_t *lenp, loff_t *ppos)
223 struct net *net = container_of(ctl->data, struct net,
224 ipv4.tcp_congestion_control);
225 char val[TCP_CA_NAME_MAX];
226 struct ctl_table tbl = {
228 .maxlen = TCP_CA_NAME_MAX,
232 tcp_get_default_congestion_control(net, val);
234 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
235 if (write && ret == 0)
236 ret = tcp_set_default_congestion_control(net, val);
240 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
241 int write, void *buffer,
242 size_t *lenp, loff_t *ppos)
244 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
247 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
250 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
251 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
256 static int proc_allowed_congestion_control(struct ctl_table *ctl,
257 int write, void *buffer,
258 size_t *lenp, loff_t *ppos)
260 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
263 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
267 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
268 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
269 if (write && ret == 0)
270 ret = tcp_set_allowed_congestion_control(tbl.data);
275 static int sscanf_key(char *buf, __le32 *key)
280 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
281 user_key + 2, user_key + 3) != 4) {
284 for (i = 0; i < ARRAY_SIZE(user_key); i++)
285 key[i] = cpu_to_le32(user_key[i]);
287 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
288 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
293 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
294 void *buffer, size_t *lenp, loff_t *ppos)
296 struct net *net = container_of(table->data, struct net,
297 ipv4.sysctl_tcp_fastopen);
298 /* maxlen to print the list of keys in hex (*2), with dashes
299 * separating doublewords and a comma in between keys.
301 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
302 2 * TCP_FASTOPEN_KEY_MAX) +
303 (TCP_FASTOPEN_KEY_MAX * 5)) };
304 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
305 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
307 int ret, i = 0, off = 0, n_keys;
309 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
313 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
315 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
319 for (i = 0; i < n_keys * 4; i++)
320 user_key[i] = le32_to_cpu(key[i]);
322 for (i = 0; i < n_keys; i++) {
323 off += snprintf(tbl.data + off, tbl.maxlen - off,
324 "%08x-%08x-%08x-%08x",
328 user_key[i * 4 + 3]);
330 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
334 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
337 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
339 if (write && ret == 0) {
340 backup_data = strchr(tbl.data, ',');
345 if (sscanf_key(tbl.data, key)) {
350 if (sscanf_key(backup_data, key + 4)) {
355 tcp_fastopen_reset_cipher(net, NULL, key,
356 backup_data ? key + 4 : NULL);
364 static void proc_configure_early_demux(int enabled, int protocol)
366 struct net_protocol *ipprot;
367 #if IS_ENABLED(CONFIG_IPV6)
368 struct inet6_protocol *ip6prot;
373 ipprot = rcu_dereference(inet_protos[protocol]);
375 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
378 #if IS_ENABLED(CONFIG_IPV6)
379 ip6prot = rcu_dereference(inet6_protos[protocol]);
381 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
387 static int proc_tcp_early_demux(struct ctl_table *table, int write,
388 void *buffer, size_t *lenp, loff_t *ppos)
392 ret = proc_dointvec(table, write, buffer, lenp, ppos);
395 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
397 proc_configure_early_demux(enabled, IPPROTO_TCP);
403 static int proc_udp_early_demux(struct ctl_table *table, int write,
404 void *buffer, size_t *lenp, loff_t *ppos)
408 ret = proc_dointvec(table, write, buffer, lenp, ppos);
411 int enabled = init_net.ipv4.sysctl_udp_early_demux;
413 proc_configure_early_demux(enabled, IPPROTO_UDP);
419 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
420 int write, void *buffer,
421 size_t *lenp, loff_t *ppos)
423 struct net *net = container_of(table->data, struct net,
424 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
427 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
428 if (write && ret == 0)
429 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
434 static int proc_tcp_available_ulp(struct ctl_table *ctl,
435 int write, void *buffer, size_t *lenp,
438 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
441 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
444 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
445 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
451 #ifdef CONFIG_IP_ROUTE_MULTIPATH
452 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
453 void *buffer, size_t *lenp,
456 struct net *net = container_of(table->data, struct net,
457 ipv4.sysctl_fib_multipath_hash_policy);
460 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
461 if (write && ret == 0)
462 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
468 static struct ctl_table ipv4_table[] = {
470 .procname = "tcp_max_orphans",
471 .data = &sysctl_tcp_max_orphans,
472 .maxlen = sizeof(int),
474 .proc_handler = proc_dointvec
477 .procname = "inet_peer_threshold",
478 .data = &inet_peer_threshold,
479 .maxlen = sizeof(int),
481 .proc_handler = proc_dointvec
484 .procname = "inet_peer_minttl",
485 .data = &inet_peer_minttl,
486 .maxlen = sizeof(int),
488 .proc_handler = proc_dointvec_jiffies,
491 .procname = "inet_peer_maxttl",
492 .data = &inet_peer_maxttl,
493 .maxlen = sizeof(int),
495 .proc_handler = proc_dointvec_jiffies,
498 .procname = "tcp_mem",
499 .maxlen = sizeof(sysctl_tcp_mem),
500 .data = &sysctl_tcp_mem,
502 .proc_handler = proc_doulongvec_minmax,
505 .procname = "tcp_low_latency",
506 .data = &sysctl_tcp_low_latency,
507 .maxlen = sizeof(int),
509 .proc_handler = proc_dointvec
511 #ifdef CONFIG_NETLABEL
513 .procname = "cipso_cache_enable",
514 .data = &cipso_v4_cache_enabled,
515 .maxlen = sizeof(int),
517 .proc_handler = proc_dointvec,
520 .procname = "cipso_cache_bucket_size",
521 .data = &cipso_v4_cache_bucketsize,
522 .maxlen = sizeof(int),
524 .proc_handler = proc_dointvec,
527 .procname = "cipso_rbm_optfmt",
528 .data = &cipso_v4_rbm_optfmt,
529 .maxlen = sizeof(int),
531 .proc_handler = proc_dointvec,
534 .procname = "cipso_rbm_strictvalid",
535 .data = &cipso_v4_rbm_strictvalid,
536 .maxlen = sizeof(int),
538 .proc_handler = proc_dointvec,
540 #endif /* CONFIG_NETLABEL */
542 .procname = "tcp_available_ulp",
543 .maxlen = TCP_ULP_BUF_MAX,
545 .proc_handler = proc_tcp_available_ulp,
548 .procname = "icmp_msgs_per_sec",
549 .data = &sysctl_icmp_msgs_per_sec,
550 .maxlen = sizeof(int),
552 .proc_handler = proc_dointvec_minmax,
553 .extra1 = SYSCTL_ZERO,
556 .procname = "icmp_msgs_burst",
557 .data = &sysctl_icmp_msgs_burst,
558 .maxlen = sizeof(int),
560 .proc_handler = proc_dointvec_minmax,
561 .extra1 = SYSCTL_ZERO,
564 .procname = "udp_mem",
565 .data = &sysctl_udp_mem,
566 .maxlen = sizeof(sysctl_udp_mem),
568 .proc_handler = proc_doulongvec_minmax,
571 .procname = "fib_sync_mem",
572 .data = &sysctl_fib_sync_mem,
573 .maxlen = sizeof(sysctl_fib_sync_mem),
575 .proc_handler = proc_douintvec_minmax,
576 .extra1 = &sysctl_fib_sync_mem_min,
577 .extra2 = &sysctl_fib_sync_mem_max,
580 .procname = "tcp_rx_skb_cache",
581 .data = &tcp_rx_skb_cache_key.key,
583 .proc_handler = proc_do_static_key,
586 .procname = "tcp_tx_skb_cache",
587 .data = &tcp_tx_skb_cache_key.key,
589 .proc_handler = proc_do_static_key,
594 static struct ctl_table ipv4_net_table[] = {
596 .procname = "icmp_echo_ignore_all",
597 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
598 .maxlen = sizeof(int),
600 .proc_handler = proc_dointvec
603 .procname = "icmp_echo_ignore_broadcasts",
604 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
605 .maxlen = sizeof(int),
607 .proc_handler = proc_dointvec
610 .procname = "icmp_ignore_bogus_error_responses",
611 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
612 .maxlen = sizeof(int),
614 .proc_handler = proc_dointvec
617 .procname = "icmp_errors_use_inbound_ifaddr",
618 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
619 .maxlen = sizeof(int),
621 .proc_handler = proc_dointvec
624 .procname = "icmp_ratelimit",
625 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
626 .maxlen = sizeof(int),
628 .proc_handler = proc_dointvec_ms_jiffies,
631 .procname = "icmp_ratemask",
632 .data = &init_net.ipv4.sysctl_icmp_ratemask,
633 .maxlen = sizeof(int),
635 .proc_handler = proc_dointvec
638 .procname = "ping_group_range",
639 .data = &init_net.ipv4.ping_group_range.range,
640 .maxlen = sizeof(gid_t)*2,
642 .proc_handler = ipv4_ping_group_range,
644 #ifdef CONFIG_NET_L3_MASTER_DEV
646 .procname = "raw_l3mdev_accept",
647 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
648 .maxlen = sizeof(int),
650 .proc_handler = proc_dointvec_minmax,
651 .extra1 = SYSCTL_ZERO,
652 .extra2 = SYSCTL_ONE,
656 .procname = "tcp_ecn",
657 .data = &init_net.ipv4.sysctl_tcp_ecn,
658 .maxlen = sizeof(int),
660 .proc_handler = proc_dointvec
663 .procname = "tcp_ecn_fallback",
664 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
665 .maxlen = sizeof(int),
667 .proc_handler = proc_dointvec
670 .procname = "ip_dynaddr",
671 .data = &init_net.ipv4.sysctl_ip_dynaddr,
672 .maxlen = sizeof(int),
674 .proc_handler = proc_dointvec
677 .procname = "ip_early_demux",
678 .data = &init_net.ipv4.sysctl_ip_early_demux,
679 .maxlen = sizeof(int),
681 .proc_handler = proc_dointvec
684 .procname = "udp_early_demux",
685 .data = &init_net.ipv4.sysctl_udp_early_demux,
686 .maxlen = sizeof(int),
688 .proc_handler = proc_udp_early_demux
691 .procname = "tcp_early_demux",
692 .data = &init_net.ipv4.sysctl_tcp_early_demux,
693 .maxlen = sizeof(int),
695 .proc_handler = proc_tcp_early_demux
698 .procname = "nexthop_compat_mode",
699 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
700 .maxlen = sizeof(int),
702 .proc_handler = proc_dointvec_minmax,
703 .extra1 = SYSCTL_ZERO,
704 .extra2 = SYSCTL_ONE,
707 .procname = "ip_default_ttl",
708 .data = &init_net.ipv4.sysctl_ip_default_ttl,
709 .maxlen = sizeof(int),
711 .proc_handler = proc_dointvec_minmax,
712 .extra1 = &ip_ttl_min,
713 .extra2 = &ip_ttl_max,
716 .procname = "ip_local_port_range",
717 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
718 .data = &init_net.ipv4.ip_local_ports.range,
720 .proc_handler = ipv4_local_port_range,
723 .procname = "ip_local_reserved_ports",
724 .data = &init_net.ipv4.sysctl_local_reserved_ports,
727 .proc_handler = proc_do_large_bitmap,
730 .procname = "ip_no_pmtu_disc",
731 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
732 .maxlen = sizeof(int),
734 .proc_handler = proc_dointvec
737 .procname = "ip_forward_use_pmtu",
738 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
739 .maxlen = sizeof(int),
741 .proc_handler = proc_dointvec,
744 .procname = "ip_forward_update_priority",
745 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
746 .maxlen = sizeof(int),
748 .proc_handler = ipv4_fwd_update_priority,
749 .extra1 = SYSCTL_ZERO,
750 .extra2 = SYSCTL_ONE,
753 .procname = "ip_nonlocal_bind",
754 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
755 .maxlen = sizeof(int),
757 .proc_handler = proc_dointvec
760 .procname = "ip_autobind_reuse",
761 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
762 .maxlen = sizeof(int),
764 .proc_handler = proc_dointvec_minmax,
765 .extra1 = SYSCTL_ZERO,
766 .extra2 = SYSCTL_ONE,
769 .procname = "fwmark_reflect",
770 .data = &init_net.ipv4.sysctl_fwmark_reflect,
771 .maxlen = sizeof(int),
773 .proc_handler = proc_dointvec,
776 .procname = "tcp_fwmark_accept",
777 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
778 .maxlen = sizeof(int),
780 .proc_handler = proc_dointvec,
782 #ifdef CONFIG_NET_L3_MASTER_DEV
784 .procname = "tcp_l3mdev_accept",
785 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
786 .maxlen = sizeof(int),
788 .proc_handler = proc_dointvec_minmax,
789 .extra1 = SYSCTL_ZERO,
790 .extra2 = SYSCTL_ONE,
794 .procname = "tcp_mtu_probing",
795 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
796 .maxlen = sizeof(int),
798 .proc_handler = proc_dointvec,
801 .procname = "tcp_base_mss",
802 .data = &init_net.ipv4.sysctl_tcp_base_mss,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec,
808 .procname = "tcp_min_snd_mss",
809 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec_minmax,
813 .extra1 = &tcp_min_snd_mss_min,
814 .extra2 = &tcp_min_snd_mss_max,
817 .procname = "tcp_mtu_probe_floor",
818 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
819 .maxlen = sizeof(int),
821 .proc_handler = proc_dointvec_minmax,
822 .extra1 = &tcp_min_snd_mss_min,
823 .extra2 = &tcp_min_snd_mss_max,
826 .procname = "tcp_probe_threshold",
827 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
828 .maxlen = sizeof(int),
830 .proc_handler = proc_dointvec,
833 .procname = "tcp_probe_interval",
834 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
835 .maxlen = sizeof(u32),
837 .proc_handler = proc_douintvec_minmax,
838 .extra2 = &u32_max_div_HZ,
841 .procname = "igmp_link_local_mcast_reports",
842 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
843 .maxlen = sizeof(int),
845 .proc_handler = proc_dointvec
848 .procname = "igmp_max_memberships",
849 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
850 .maxlen = sizeof(int),
852 .proc_handler = proc_dointvec
855 .procname = "igmp_max_msf",
856 .data = &init_net.ipv4.sysctl_igmp_max_msf,
857 .maxlen = sizeof(int),
859 .proc_handler = proc_dointvec
861 #ifdef CONFIG_IP_MULTICAST
863 .procname = "igmp_qrv",
864 .data = &init_net.ipv4.sysctl_igmp_qrv,
865 .maxlen = sizeof(int),
867 .proc_handler = proc_dointvec_minmax,
872 .procname = "tcp_congestion_control",
873 .data = &init_net.ipv4.tcp_congestion_control,
875 .maxlen = TCP_CA_NAME_MAX,
876 .proc_handler = proc_tcp_congestion_control,
879 .procname = "tcp_available_congestion_control",
880 .maxlen = TCP_CA_BUF_MAX,
882 .proc_handler = proc_tcp_available_congestion_control,
885 .procname = "tcp_allowed_congestion_control",
886 .maxlen = TCP_CA_BUF_MAX,
888 .proc_handler = proc_allowed_congestion_control,
891 .procname = "tcp_keepalive_time",
892 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
893 .maxlen = sizeof(int),
895 .proc_handler = proc_dointvec_jiffies,
898 .procname = "tcp_keepalive_probes",
899 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
900 .maxlen = sizeof(int),
902 .proc_handler = proc_dointvec
905 .procname = "tcp_keepalive_intvl",
906 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
907 .maxlen = sizeof(int),
909 .proc_handler = proc_dointvec_jiffies,
912 .procname = "tcp_syn_retries",
913 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
914 .maxlen = sizeof(int),
916 .proc_handler = proc_dointvec_minmax,
917 .extra1 = &tcp_syn_retries_min,
918 .extra2 = &tcp_syn_retries_max
921 .procname = "tcp_synack_retries",
922 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
923 .maxlen = sizeof(int),
925 .proc_handler = proc_dointvec
927 #ifdef CONFIG_SYN_COOKIES
929 .procname = "tcp_syncookies",
930 .data = &init_net.ipv4.sysctl_tcp_syncookies,
931 .maxlen = sizeof(int),
933 .proc_handler = proc_dointvec
937 .procname = "tcp_reordering",
938 .data = &init_net.ipv4.sysctl_tcp_reordering,
939 .maxlen = sizeof(int),
941 .proc_handler = proc_dointvec
944 .procname = "tcp_retries1",
945 .data = &init_net.ipv4.sysctl_tcp_retries1,
946 .maxlen = sizeof(int),
948 .proc_handler = proc_dointvec_minmax,
949 .extra2 = &tcp_retr1_max
952 .procname = "tcp_retries2",
953 .data = &init_net.ipv4.sysctl_tcp_retries2,
954 .maxlen = sizeof(int),
956 .proc_handler = proc_dointvec
959 .procname = "tcp_orphan_retries",
960 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
961 .maxlen = sizeof(int),
963 .proc_handler = proc_dointvec
966 .procname = "tcp_fin_timeout",
967 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
968 .maxlen = sizeof(int),
970 .proc_handler = proc_dointvec_jiffies,
973 .procname = "tcp_notsent_lowat",
974 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
975 .maxlen = sizeof(unsigned int),
977 .proc_handler = proc_douintvec,
980 .procname = "tcp_tw_reuse",
981 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
982 .maxlen = sizeof(int),
984 .proc_handler = proc_dointvec_minmax,
985 .extra1 = SYSCTL_ZERO,
989 .procname = "tcp_max_tw_buckets",
990 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
991 .maxlen = sizeof(int),
993 .proc_handler = proc_dointvec
996 .procname = "tcp_max_syn_backlog",
997 .data = &init_net.ipv4.sysctl_max_syn_backlog,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec
1003 .procname = "tcp_fastopen",
1004 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1005 .maxlen = sizeof(int),
1007 .proc_handler = proc_dointvec,
1010 .procname = "tcp_fastopen_key",
1012 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1013 /* maxlen to print the list of keys in hex (*2), with dashes
1014 * separating doublewords and a comma in between keys.
1016 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1017 2 * TCP_FASTOPEN_KEY_MAX) +
1018 (TCP_FASTOPEN_KEY_MAX * 5)),
1019 .proc_handler = proc_tcp_fastopen_key,
1022 .procname = "tcp_fastopen_blackhole_timeout_sec",
1023 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1024 .maxlen = sizeof(int),
1026 .proc_handler = proc_tfo_blackhole_detect_timeout,
1027 .extra1 = SYSCTL_ZERO,
1029 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1031 .procname = "fib_multipath_use_neigh",
1032 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1033 .maxlen = sizeof(int),
1035 .proc_handler = proc_dointvec_minmax,
1036 .extra1 = SYSCTL_ZERO,
1037 .extra2 = SYSCTL_ONE,
1040 .procname = "fib_multipath_hash_policy",
1041 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1042 .maxlen = sizeof(int),
1044 .proc_handler = proc_fib_multipath_hash_policy,
1045 .extra1 = SYSCTL_ZERO,
1050 .procname = "ip_unprivileged_port_start",
1051 .maxlen = sizeof(int),
1052 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1054 .proc_handler = ipv4_privileged_ports,
1056 #ifdef CONFIG_NET_L3_MASTER_DEV
1058 .procname = "udp_l3mdev_accept",
1059 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1060 .maxlen = sizeof(int),
1062 .proc_handler = proc_dointvec_minmax,
1063 .extra1 = SYSCTL_ZERO,
1064 .extra2 = SYSCTL_ONE,
1068 .procname = "tcp_sack",
1069 .data = &init_net.ipv4.sysctl_tcp_sack,
1070 .maxlen = sizeof(int),
1072 .proc_handler = proc_dointvec
1075 .procname = "tcp_window_scaling",
1076 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1077 .maxlen = sizeof(int),
1079 .proc_handler = proc_dointvec
1082 .procname = "tcp_timestamps",
1083 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1084 .maxlen = sizeof(int),
1086 .proc_handler = proc_dointvec
1089 .procname = "tcp_early_retrans",
1090 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1091 .maxlen = sizeof(int),
1093 .proc_handler = proc_dointvec_minmax,
1094 .extra1 = SYSCTL_ZERO,
1098 .procname = "tcp_recovery",
1099 .data = &init_net.ipv4.sysctl_tcp_recovery,
1100 .maxlen = sizeof(int),
1102 .proc_handler = proc_dointvec,
1105 .procname = "tcp_thin_linear_timeouts",
1106 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1107 .maxlen = sizeof(int),
1109 .proc_handler = proc_dointvec
1112 .procname = "tcp_slow_start_after_idle",
1113 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1114 .maxlen = sizeof(int),
1116 .proc_handler = proc_dointvec
1119 .procname = "tcp_retrans_collapse",
1120 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1121 .maxlen = sizeof(int),
1123 .proc_handler = proc_dointvec
1126 .procname = "tcp_stdurg",
1127 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1128 .maxlen = sizeof(int),
1130 .proc_handler = proc_dointvec
1133 .procname = "tcp_rfc1337",
1134 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1135 .maxlen = sizeof(int),
1137 .proc_handler = proc_dointvec
1140 .procname = "tcp_abort_on_overflow",
1141 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1142 .maxlen = sizeof(int),
1144 .proc_handler = proc_dointvec
1147 .procname = "tcp_fack",
1148 .data = &init_net.ipv4.sysctl_tcp_fack,
1149 .maxlen = sizeof(int),
1151 .proc_handler = proc_dointvec
1154 .procname = "tcp_max_reordering",
1155 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1156 .maxlen = sizeof(int),
1158 .proc_handler = proc_dointvec
1161 .procname = "tcp_dsack",
1162 .data = &init_net.ipv4.sysctl_tcp_dsack,
1163 .maxlen = sizeof(int),
1165 .proc_handler = proc_dointvec
1168 .procname = "tcp_app_win",
1169 .data = &init_net.ipv4.sysctl_tcp_app_win,
1170 .maxlen = sizeof(int),
1172 .proc_handler = proc_dointvec
1175 .procname = "tcp_adv_win_scale",
1176 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1177 .maxlen = sizeof(int),
1179 .proc_handler = proc_dointvec_minmax,
1180 .extra1 = &tcp_adv_win_scale_min,
1181 .extra2 = &tcp_adv_win_scale_max,
1184 .procname = "tcp_frto",
1185 .data = &init_net.ipv4.sysctl_tcp_frto,
1186 .maxlen = sizeof(int),
1188 .proc_handler = proc_dointvec
1191 .procname = "tcp_no_metrics_save",
1192 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1193 .maxlen = sizeof(int),
1195 .proc_handler = proc_dointvec,
1198 .procname = "tcp_no_ssthresh_metrics_save",
1199 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1200 .maxlen = sizeof(int),
1202 .proc_handler = proc_dointvec_minmax,
1203 .extra1 = SYSCTL_ZERO,
1204 .extra2 = SYSCTL_ONE,
1207 .procname = "tcp_moderate_rcvbuf",
1208 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1209 .maxlen = sizeof(int),
1211 .proc_handler = proc_dointvec,
1214 .procname = "tcp_tso_win_divisor",
1215 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1216 .maxlen = sizeof(int),
1218 .proc_handler = proc_dointvec,
1221 .procname = "tcp_workaround_signed_windows",
1222 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1223 .maxlen = sizeof(int),
1225 .proc_handler = proc_dointvec
1228 .procname = "tcp_limit_output_bytes",
1229 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1230 .maxlen = sizeof(int),
1232 .proc_handler = proc_dointvec
1235 .procname = "tcp_challenge_ack_limit",
1236 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1237 .maxlen = sizeof(int),
1239 .proc_handler = proc_dointvec
1242 .procname = "tcp_min_tso_segs",
1243 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1244 .maxlen = sizeof(int),
1246 .proc_handler = proc_dointvec_minmax,
1247 .extra1 = SYSCTL_ONE,
1248 .extra2 = &gso_max_segs,
1251 .procname = "tcp_min_rtt_wlen",
1252 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1253 .maxlen = sizeof(int),
1255 .proc_handler = proc_dointvec_minmax,
1256 .extra1 = SYSCTL_ZERO,
1257 .extra2 = &one_day_secs
1260 .procname = "tcp_autocorking",
1261 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1262 .maxlen = sizeof(int),
1264 .proc_handler = proc_dointvec_minmax,
1265 .extra1 = SYSCTL_ZERO,
1266 .extra2 = SYSCTL_ONE,
1269 .procname = "tcp_invalid_ratelimit",
1270 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1271 .maxlen = sizeof(int),
1273 .proc_handler = proc_dointvec_ms_jiffies,
1276 .procname = "tcp_pacing_ss_ratio",
1277 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1278 .maxlen = sizeof(int),
1280 .proc_handler = proc_dointvec_minmax,
1281 .extra1 = SYSCTL_ZERO,
1282 .extra2 = &thousand,
1285 .procname = "tcp_pacing_ca_ratio",
1286 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1287 .maxlen = sizeof(int),
1289 .proc_handler = proc_dointvec_minmax,
1290 .extra1 = SYSCTL_ZERO,
1291 .extra2 = &thousand,
1294 .procname = "tcp_wmem",
1295 .data = &init_net.ipv4.sysctl_tcp_wmem,
1296 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1298 .proc_handler = proc_dointvec_minmax,
1299 .extra1 = SYSCTL_ONE,
1302 .procname = "tcp_rmem",
1303 .data = &init_net.ipv4.sysctl_tcp_rmem,
1304 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1306 .proc_handler = proc_dointvec_minmax,
1307 .extra1 = SYSCTL_ONE,
1310 .procname = "tcp_comp_sack_delay_ns",
1311 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1312 .maxlen = sizeof(unsigned long),
1314 .proc_handler = proc_doulongvec_minmax,
1317 .procname = "tcp_comp_sack_slack_ns",
1318 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1319 .maxlen = sizeof(unsigned long),
1321 .proc_handler = proc_doulongvec_minmax,
1324 .procname = "tcp_comp_sack_nr",
1325 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1326 .maxlen = sizeof(int),
1328 .proc_handler = proc_dointvec_minmax,
1329 .extra1 = SYSCTL_ZERO,
1330 .extra2 = &comp_sack_nr_max,
1333 .procname = "tcp_reflect_tos",
1334 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1335 .maxlen = sizeof(int),
1337 .proc_handler = proc_dointvec_minmax,
1338 .extra1 = SYSCTL_ZERO,
1339 .extra2 = SYSCTL_ONE,
1342 .procname = "udp_rmem_min",
1343 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1344 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1346 .proc_handler = proc_dointvec_minmax,
1347 .extra1 = SYSCTL_ONE
1350 .procname = "udp_wmem_min",
1351 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1352 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1354 .proc_handler = proc_dointvec_minmax,
1355 .extra1 = SYSCTL_ONE
1360 static __net_init int ipv4_sysctl_init_net(struct net *net)
1362 struct ctl_table *table;
1364 table = ipv4_net_table;
1365 if (!net_eq(net, &init_net)) {
1368 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1372 /* Update the variables to point into the current struct net */
1373 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
1374 table[i].data += (void *)net - (void *)&init_net;
1377 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1378 if (!net->ipv4.ipv4_hdr)
1381 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1382 if (!net->ipv4.sysctl_local_reserved_ports)
1388 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1390 if (!net_eq(net, &init_net))
1396 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1398 struct ctl_table *table;
1400 kfree(net->ipv4.sysctl_local_reserved_ports);
1401 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1402 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1406 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1407 .init = ipv4_sysctl_init_net,
1408 .exit = ipv4_sysctl_exit_net,
1411 static __init int sysctl_ipv4_init(void)
1413 struct ctl_table_header *hdr;
1415 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1419 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1420 unregister_net_sysctl_table(hdr);
1427 __initcall(sysctl_ipv4_init);