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 tcp_retr1_max = 255;
35 static int ip_local_port_range_min[] = { 1, 1 };
36 static int ip_local_port_range_max[] = { 65535, 65535 };
37 static int tcp_adv_win_scale_min = -31;
38 static int tcp_adv_win_scale_max = 31;
39 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
40 static int tcp_min_snd_mss_max = 65535;
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 };
49 static u32 u32_max_div_HZ = UINT_MAX / HZ;
50 static int one_day_secs = 24 * 3600;
53 static int sysctl_tcp_low_latency __read_mostly;
55 /* Update system visible IP port range */
56 static void set_local_port_range(struct net *net, int range[2])
58 bool same_parity = !((range[0] ^ range[1]) & 1);
60 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
61 if (same_parity && !net->ipv4.ip_local_ports.warned) {
62 net->ipv4.ip_local_ports.warned = true;
63 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
65 net->ipv4.ip_local_ports.range[0] = range[0];
66 net->ipv4.ip_local_ports.range[1] = range[1];
67 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
70 /* Validate changes from /proc interface. */
71 static int ipv4_local_port_range(struct ctl_table *table, int write,
72 void *buffer, size_t *lenp, loff_t *ppos)
75 container_of(table->data, struct net, ipv4.ip_local_ports.range);
78 struct ctl_table tmp = {
80 .maxlen = sizeof(range),
82 .extra1 = &ip_local_port_range_min,
83 .extra2 = &ip_local_port_range_max,
86 inet_get_local_port_range(net, &range[0], &range[1]);
88 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
90 if (write && ret == 0) {
91 /* Ensure that the upper limit is not smaller than the lower,
92 * and that the lower does not encroach upon the privileged
95 if ((range[1] < range[0]) ||
96 (range[0] < net->ipv4.sysctl_ip_prot_sock))
99 set_local_port_range(net, range);
105 /* Validate changes from /proc interface. */
106 static int ipv4_privileged_ports(struct ctl_table *table, int write,
107 void *buffer, size_t *lenp, loff_t *ppos)
109 struct net *net = container_of(table->data, struct net,
110 ipv4.sysctl_ip_prot_sock);
114 struct ctl_table tmp = {
116 .maxlen = sizeof(pports),
118 .extra1 = &ip_privileged_port_min,
119 .extra2 = &ip_privileged_port_max,
122 pports = net->ipv4.sysctl_ip_prot_sock;
124 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
126 if (write && ret == 0) {
127 inet_get_local_port_range(net, &range[0], &range[1]);
128 /* Ensure that the local port range doesn't overlap with the
129 * privileged port range.
131 if (range[0] < pports)
134 net->ipv4.sysctl_ip_prot_sock = pports;
140 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
142 kgid_t *data = table->data;
144 container_of(table->data, struct net, ipv4.ping_group_range.range);
147 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
151 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
154 /* Update system visible IP port range */
155 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
157 kgid_t *data = table->data;
159 container_of(table->data, struct net, ipv4.ping_group_range.range);
160 write_seqlock(&net->ipv4.ping_group_range.lock);
163 write_sequnlock(&net->ipv4.ping_group_range.lock);
166 /* Validate changes from /proc interface. */
167 static int ipv4_ping_group_range(struct ctl_table *table, int write,
168 void *buffer, 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))
192 if (urange[1] < urange[0] || gid_lt(high, low)) {
193 low = make_kgid(&init_user_ns, 1);
194 high = make_kgid(&init_user_ns, 0);
196 set_ping_group_range(table, low, high);
202 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
203 void *buffer, size_t *lenp, loff_t *ppos)
208 net = container_of(table->data, struct net,
209 ipv4.sysctl_ip_fwd_update_priority);
210 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
211 if (write && ret == 0)
212 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
218 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
219 void *buffer, size_t *lenp, loff_t *ppos)
221 struct net *net = container_of(ctl->data, struct net,
222 ipv4.tcp_congestion_control);
223 char val[TCP_CA_NAME_MAX];
224 struct ctl_table tbl = {
226 .maxlen = TCP_CA_NAME_MAX,
230 tcp_get_default_congestion_control(net, val);
232 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
233 if (write && ret == 0)
234 ret = tcp_set_default_congestion_control(net, val);
238 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
239 int write, void *buffer,
240 size_t *lenp, loff_t *ppos)
242 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
245 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
248 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
249 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
254 static int proc_allowed_congestion_control(struct ctl_table *ctl,
255 int write, void *buffer,
256 size_t *lenp, loff_t *ppos)
258 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
261 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
265 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
266 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
267 if (write && ret == 0)
268 ret = tcp_set_allowed_congestion_control(tbl.data);
273 static int sscanf_key(char *buf, __le32 *key)
278 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
279 user_key + 2, user_key + 3) != 4) {
282 for (i = 0; i < ARRAY_SIZE(user_key); i++)
283 key[i] = cpu_to_le32(user_key[i]);
285 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
286 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
291 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
292 void *buffer, size_t *lenp, loff_t *ppos)
294 struct net *net = container_of(table->data, struct net,
295 ipv4.sysctl_tcp_fastopen);
296 /* maxlen to print the list of keys in hex (*2), with dashes
297 * separating doublewords and a comma in between keys.
299 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
300 2 * TCP_FASTOPEN_KEY_MAX) +
301 (TCP_FASTOPEN_KEY_MAX * 5)) };
302 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
303 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
305 int ret, i = 0, off = 0, n_keys;
307 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
311 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
313 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
317 for (i = 0; i < n_keys * 4; i++)
318 user_key[i] = le32_to_cpu(key[i]);
320 for (i = 0; i < n_keys; i++) {
321 off += snprintf(tbl.data + off, tbl.maxlen - off,
322 "%08x-%08x-%08x-%08x",
326 user_key[i * 4 + 3]);
328 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
332 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
335 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
337 if (write && ret == 0) {
338 backup_data = strchr(tbl.data, ',');
343 if (sscanf_key(tbl.data, key)) {
348 if (sscanf_key(backup_data, key + 4)) {
353 tcp_fastopen_reset_cipher(net, NULL, key,
354 backup_data ? key + 4 : NULL);
362 static void proc_configure_early_demux(int enabled, int protocol)
364 struct net_protocol *ipprot;
365 #if IS_ENABLED(CONFIG_IPV6)
366 struct inet6_protocol *ip6prot;
371 ipprot = rcu_dereference(inet_protos[protocol]);
373 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
376 #if IS_ENABLED(CONFIG_IPV6)
377 ip6prot = rcu_dereference(inet6_protos[protocol]);
379 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
385 static int proc_tcp_early_demux(struct ctl_table *table, int write,
386 void *buffer, size_t *lenp, loff_t *ppos)
390 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
393 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
395 proc_configure_early_demux(enabled, IPPROTO_TCP);
401 static int proc_udp_early_demux(struct ctl_table *table, int write,
402 void *buffer, size_t *lenp, loff_t *ppos)
406 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
409 int enabled = init_net.ipv4.sysctl_udp_early_demux;
411 proc_configure_early_demux(enabled, IPPROTO_UDP);
417 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
418 int write, void *buffer,
419 size_t *lenp, loff_t *ppos)
421 struct net *net = container_of(table->data, struct net,
422 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
425 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
426 if (write && ret == 0)
427 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
432 static int proc_tcp_available_ulp(struct ctl_table *ctl,
433 int write, void *buffer, size_t *lenp,
436 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
439 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
442 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
443 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
449 #ifdef CONFIG_IP_ROUTE_MULTIPATH
450 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
451 void *buffer, size_t *lenp,
454 struct net *net = container_of(table->data, struct net,
455 ipv4.sysctl_fib_multipath_hash_policy);
458 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
459 if (write && ret == 0)
460 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
466 static struct ctl_table ipv4_table[] = {
468 .procname = "tcp_max_orphans",
469 .data = &sysctl_tcp_max_orphans,
470 .maxlen = sizeof(int),
472 .proc_handler = proc_dointvec
475 .procname = "inet_peer_threshold",
476 .data = &inet_peer_threshold,
477 .maxlen = sizeof(int),
479 .proc_handler = proc_dointvec
482 .procname = "inet_peer_minttl",
483 .data = &inet_peer_minttl,
484 .maxlen = sizeof(int),
486 .proc_handler = proc_dointvec_jiffies,
489 .procname = "inet_peer_maxttl",
490 .data = &inet_peer_maxttl,
491 .maxlen = sizeof(int),
493 .proc_handler = proc_dointvec_jiffies,
496 .procname = "tcp_mem",
497 .maxlen = sizeof(sysctl_tcp_mem),
498 .data = &sysctl_tcp_mem,
500 .proc_handler = proc_doulongvec_minmax,
503 .procname = "tcp_low_latency",
504 .data = &sysctl_tcp_low_latency,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec
509 #ifdef CONFIG_NETLABEL
511 .procname = "cipso_cache_enable",
512 .data = &cipso_v4_cache_enabled,
513 .maxlen = sizeof(int),
515 .proc_handler = proc_dointvec,
518 .procname = "cipso_cache_bucket_size",
519 .data = &cipso_v4_cache_bucketsize,
520 .maxlen = sizeof(int),
522 .proc_handler = proc_dointvec,
525 .procname = "cipso_rbm_optfmt",
526 .data = &cipso_v4_rbm_optfmt,
527 .maxlen = sizeof(int),
529 .proc_handler = proc_dointvec,
532 .procname = "cipso_rbm_strictvalid",
533 .data = &cipso_v4_rbm_strictvalid,
534 .maxlen = sizeof(int),
536 .proc_handler = proc_dointvec,
538 #endif /* CONFIG_NETLABEL */
540 .procname = "tcp_available_ulp",
541 .maxlen = TCP_ULP_BUF_MAX,
543 .proc_handler = proc_tcp_available_ulp,
546 .procname = "icmp_msgs_per_sec",
547 .data = &sysctl_icmp_msgs_per_sec,
548 .maxlen = sizeof(int),
550 .proc_handler = proc_dointvec_minmax,
551 .extra1 = SYSCTL_ZERO,
554 .procname = "icmp_msgs_burst",
555 .data = &sysctl_icmp_msgs_burst,
556 .maxlen = sizeof(int),
558 .proc_handler = proc_dointvec_minmax,
559 .extra1 = SYSCTL_ZERO,
562 .procname = "udp_mem",
563 .data = &sysctl_udp_mem,
564 .maxlen = sizeof(sysctl_udp_mem),
566 .proc_handler = proc_doulongvec_minmax,
569 .procname = "fib_sync_mem",
570 .data = &sysctl_fib_sync_mem,
571 .maxlen = sizeof(sysctl_fib_sync_mem),
573 .proc_handler = proc_douintvec_minmax,
574 .extra1 = &sysctl_fib_sync_mem_min,
575 .extra2 = &sysctl_fib_sync_mem_max,
578 .procname = "tcp_rx_skb_cache",
579 .data = &tcp_rx_skb_cache_key.key,
581 .proc_handler = proc_do_static_key,
584 .procname = "tcp_tx_skb_cache",
585 .data = &tcp_tx_skb_cache_key.key,
587 .proc_handler = proc_do_static_key,
592 static struct ctl_table ipv4_net_table[] = {
594 .procname = "icmp_echo_ignore_all",
595 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
596 .maxlen = sizeof(u8),
598 .proc_handler = proc_dou8vec_minmax,
601 .procname = "icmp_echo_enable_probe",
602 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
603 .maxlen = sizeof(u8),
605 .proc_handler = proc_dou8vec_minmax,
606 .extra1 = SYSCTL_ZERO,
610 .procname = "icmp_echo_ignore_broadcasts",
611 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
612 .maxlen = sizeof(u8),
614 .proc_handler = proc_dou8vec_minmax,
617 .procname = "icmp_ignore_bogus_error_responses",
618 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
619 .maxlen = sizeof(u8),
621 .proc_handler = proc_dou8vec_minmax,
624 .procname = "icmp_errors_use_inbound_ifaddr",
625 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
626 .maxlen = sizeof(u8),
628 .proc_handler = proc_dou8vec_minmax,
631 .procname = "icmp_ratelimit",
632 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
633 .maxlen = sizeof(int),
635 .proc_handler = proc_dointvec_ms_jiffies,
638 .procname = "icmp_ratemask",
639 .data = &init_net.ipv4.sysctl_icmp_ratemask,
640 .maxlen = sizeof(int),
642 .proc_handler = proc_dointvec
645 .procname = "ping_group_range",
646 .data = &init_net.ipv4.ping_group_range.range,
647 .maxlen = sizeof(gid_t)*2,
649 .proc_handler = ipv4_ping_group_range,
651 #ifdef CONFIG_NET_L3_MASTER_DEV
653 .procname = "raw_l3mdev_accept",
654 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
655 .maxlen = sizeof(u8),
657 .proc_handler = proc_dou8vec_minmax,
658 .extra1 = SYSCTL_ZERO,
659 .extra2 = SYSCTL_ONE,
663 .procname = "tcp_ecn",
664 .data = &init_net.ipv4.sysctl_tcp_ecn,
665 .maxlen = sizeof(u8),
667 .proc_handler = proc_dou8vec_minmax,
670 .procname = "tcp_ecn_fallback",
671 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
672 .maxlen = sizeof(u8),
674 .proc_handler = proc_dou8vec_minmax,
677 .procname = "ip_dynaddr",
678 .data = &init_net.ipv4.sysctl_ip_dynaddr,
679 .maxlen = sizeof(u8),
681 .proc_handler = proc_dou8vec_minmax,
684 .procname = "ip_early_demux",
685 .data = &init_net.ipv4.sysctl_ip_early_demux,
686 .maxlen = sizeof(u8),
688 .proc_handler = proc_dou8vec_minmax,
691 .procname = "udp_early_demux",
692 .data = &init_net.ipv4.sysctl_udp_early_demux,
693 .maxlen = sizeof(u8),
695 .proc_handler = proc_udp_early_demux
698 .procname = "tcp_early_demux",
699 .data = &init_net.ipv4.sysctl_tcp_early_demux,
700 .maxlen = sizeof(u8),
702 .proc_handler = proc_tcp_early_demux
705 .procname = "nexthop_compat_mode",
706 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
707 .maxlen = sizeof(u8),
709 .proc_handler = proc_dou8vec_minmax,
710 .extra1 = SYSCTL_ZERO,
711 .extra2 = SYSCTL_ONE,
714 .procname = "ip_default_ttl",
715 .data = &init_net.ipv4.sysctl_ip_default_ttl,
716 .maxlen = sizeof(u8),
718 .proc_handler = proc_dou8vec_minmax,
719 .extra1 = &ip_ttl_min,
720 .extra2 = &ip_ttl_max,
723 .procname = "ip_local_port_range",
724 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
725 .data = &init_net.ipv4.ip_local_ports.range,
727 .proc_handler = ipv4_local_port_range,
730 .procname = "ip_local_reserved_ports",
731 .data = &init_net.ipv4.sysctl_local_reserved_ports,
734 .proc_handler = proc_do_large_bitmap,
737 .procname = "ip_no_pmtu_disc",
738 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
739 .maxlen = sizeof(u8),
741 .proc_handler = proc_dou8vec_minmax,
744 .procname = "ip_forward_use_pmtu",
745 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
746 .maxlen = sizeof(u8),
748 .proc_handler = proc_dou8vec_minmax,
751 .procname = "ip_forward_update_priority",
752 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
753 .maxlen = sizeof(u8),
755 .proc_handler = ipv4_fwd_update_priority,
756 .extra1 = SYSCTL_ZERO,
757 .extra2 = SYSCTL_ONE,
760 .procname = "ip_nonlocal_bind",
761 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
762 .maxlen = sizeof(u8),
764 .proc_handler = proc_dou8vec_minmax,
767 .procname = "ip_autobind_reuse",
768 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
769 .maxlen = sizeof(u8),
771 .proc_handler = proc_dou8vec_minmax,
772 .extra1 = SYSCTL_ZERO,
773 .extra2 = SYSCTL_ONE,
776 .procname = "fwmark_reflect",
777 .data = &init_net.ipv4.sysctl_fwmark_reflect,
778 .maxlen = sizeof(u8),
780 .proc_handler = proc_dou8vec_minmax,
783 .procname = "tcp_fwmark_accept",
784 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
785 .maxlen = sizeof(u8),
787 .proc_handler = proc_dou8vec_minmax,
789 #ifdef CONFIG_NET_L3_MASTER_DEV
791 .procname = "tcp_l3mdev_accept",
792 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
793 .maxlen = sizeof(u8),
795 .proc_handler = proc_dou8vec_minmax,
796 .extra1 = SYSCTL_ZERO,
797 .extra2 = SYSCTL_ONE,
801 .procname = "tcp_mtu_probing",
802 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
803 .maxlen = sizeof(u8),
805 .proc_handler = proc_dou8vec_minmax,
808 .procname = "tcp_base_mss",
809 .data = &init_net.ipv4.sysctl_tcp_base_mss,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec,
815 .procname = "tcp_min_snd_mss",
816 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
817 .maxlen = sizeof(int),
819 .proc_handler = proc_dointvec_minmax,
820 .extra1 = &tcp_min_snd_mss_min,
821 .extra2 = &tcp_min_snd_mss_max,
824 .procname = "tcp_mtu_probe_floor",
825 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
826 .maxlen = sizeof(int),
828 .proc_handler = proc_dointvec_minmax,
829 .extra1 = &tcp_min_snd_mss_min,
830 .extra2 = &tcp_min_snd_mss_max,
833 .procname = "tcp_probe_threshold",
834 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
835 .maxlen = sizeof(int),
837 .proc_handler = proc_dointvec,
840 .procname = "tcp_probe_interval",
841 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
842 .maxlen = sizeof(u32),
844 .proc_handler = proc_douintvec_minmax,
845 .extra2 = &u32_max_div_HZ,
848 .procname = "igmp_link_local_mcast_reports",
849 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
850 .maxlen = sizeof(u8),
852 .proc_handler = proc_dou8vec_minmax,
855 .procname = "igmp_max_memberships",
856 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
857 .maxlen = sizeof(int),
859 .proc_handler = proc_dointvec
862 .procname = "igmp_max_msf",
863 .data = &init_net.ipv4.sysctl_igmp_max_msf,
864 .maxlen = sizeof(int),
866 .proc_handler = proc_dointvec
868 #ifdef CONFIG_IP_MULTICAST
870 .procname = "igmp_qrv",
871 .data = &init_net.ipv4.sysctl_igmp_qrv,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec_minmax,
879 .procname = "tcp_congestion_control",
880 .data = &init_net.ipv4.tcp_congestion_control,
882 .maxlen = TCP_CA_NAME_MAX,
883 .proc_handler = proc_tcp_congestion_control,
886 .procname = "tcp_available_congestion_control",
887 .maxlen = TCP_CA_BUF_MAX,
889 .proc_handler = proc_tcp_available_congestion_control,
892 .procname = "tcp_allowed_congestion_control",
893 .maxlen = TCP_CA_BUF_MAX,
895 .proc_handler = proc_allowed_congestion_control,
898 .procname = "tcp_keepalive_time",
899 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
900 .maxlen = sizeof(int),
902 .proc_handler = proc_dointvec_jiffies,
905 .procname = "tcp_keepalive_probes",
906 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
907 .maxlen = sizeof(u8),
909 .proc_handler = proc_dou8vec_minmax,
912 .procname = "tcp_keepalive_intvl",
913 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
914 .maxlen = sizeof(int),
916 .proc_handler = proc_dointvec_jiffies,
919 .procname = "tcp_syn_retries",
920 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
921 .maxlen = sizeof(u8),
923 .proc_handler = proc_dou8vec_minmax,
924 .extra1 = &tcp_syn_retries_min,
925 .extra2 = &tcp_syn_retries_max
928 .procname = "tcp_synack_retries",
929 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
930 .maxlen = sizeof(u8),
932 .proc_handler = proc_dou8vec_minmax,
934 #ifdef CONFIG_SYN_COOKIES
936 .procname = "tcp_syncookies",
937 .data = &init_net.ipv4.sysctl_tcp_syncookies,
938 .maxlen = sizeof(u8),
940 .proc_handler = proc_dou8vec_minmax,
944 .procname = "tcp_reordering",
945 .data = &init_net.ipv4.sysctl_tcp_reordering,
946 .maxlen = sizeof(int),
948 .proc_handler = proc_dointvec
951 .procname = "tcp_retries1",
952 .data = &init_net.ipv4.sysctl_tcp_retries1,
953 .maxlen = sizeof(u8),
955 .proc_handler = proc_dou8vec_minmax,
956 .extra2 = &tcp_retr1_max
959 .procname = "tcp_retries2",
960 .data = &init_net.ipv4.sysctl_tcp_retries2,
961 .maxlen = sizeof(u8),
963 .proc_handler = proc_dou8vec_minmax,
966 .procname = "tcp_orphan_retries",
967 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
968 .maxlen = sizeof(u8),
970 .proc_handler = proc_dou8vec_minmax,
973 .procname = "tcp_fin_timeout",
974 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
975 .maxlen = sizeof(int),
977 .proc_handler = proc_dointvec_jiffies,
980 .procname = "tcp_notsent_lowat",
981 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
982 .maxlen = sizeof(unsigned int),
984 .proc_handler = proc_douintvec,
987 .procname = "tcp_tw_reuse",
988 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
989 .maxlen = sizeof(u8),
991 .proc_handler = proc_dou8vec_minmax,
992 .extra1 = SYSCTL_ZERO,
996 .procname = "tcp_max_tw_buckets",
997 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec
1003 .procname = "tcp_max_syn_backlog",
1004 .data = &init_net.ipv4.sysctl_max_syn_backlog,
1005 .maxlen = sizeof(int),
1007 .proc_handler = proc_dointvec
1010 .procname = "tcp_fastopen",
1011 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1012 .maxlen = sizeof(int),
1014 .proc_handler = proc_dointvec,
1017 .procname = "tcp_fastopen_key",
1019 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1020 /* maxlen to print the list of keys in hex (*2), with dashes
1021 * separating doublewords and a comma in between keys.
1023 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1024 2 * TCP_FASTOPEN_KEY_MAX) +
1025 (TCP_FASTOPEN_KEY_MAX * 5)),
1026 .proc_handler = proc_tcp_fastopen_key,
1029 .procname = "tcp_fastopen_blackhole_timeout_sec",
1030 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1031 .maxlen = sizeof(int),
1033 .proc_handler = proc_tfo_blackhole_detect_timeout,
1034 .extra1 = SYSCTL_ZERO,
1036 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1038 .procname = "fib_multipath_use_neigh",
1039 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1040 .maxlen = sizeof(u8),
1042 .proc_handler = proc_dou8vec_minmax,
1043 .extra1 = SYSCTL_ZERO,
1044 .extra2 = SYSCTL_ONE,
1047 .procname = "fib_multipath_hash_policy",
1048 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1049 .maxlen = sizeof(u8),
1051 .proc_handler = proc_fib_multipath_hash_policy,
1052 .extra1 = SYSCTL_ZERO,
1057 .procname = "ip_unprivileged_port_start",
1058 .maxlen = sizeof(int),
1059 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1061 .proc_handler = ipv4_privileged_ports,
1063 #ifdef CONFIG_NET_L3_MASTER_DEV
1065 .procname = "udp_l3mdev_accept",
1066 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1067 .maxlen = sizeof(u8),
1069 .proc_handler = proc_dou8vec_minmax,
1070 .extra1 = SYSCTL_ZERO,
1071 .extra2 = SYSCTL_ONE,
1075 .procname = "tcp_sack",
1076 .data = &init_net.ipv4.sysctl_tcp_sack,
1077 .maxlen = sizeof(u8),
1079 .proc_handler = proc_dou8vec_minmax,
1082 .procname = "tcp_window_scaling",
1083 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1084 .maxlen = sizeof(u8),
1086 .proc_handler = proc_dou8vec_minmax,
1089 .procname = "tcp_timestamps",
1090 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1091 .maxlen = sizeof(u8),
1093 .proc_handler = proc_dou8vec_minmax,
1096 .procname = "tcp_early_retrans",
1097 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1098 .maxlen = sizeof(u8),
1100 .proc_handler = proc_dou8vec_minmax,
1101 .extra1 = SYSCTL_ZERO,
1105 .procname = "tcp_recovery",
1106 .data = &init_net.ipv4.sysctl_tcp_recovery,
1107 .maxlen = sizeof(u8),
1109 .proc_handler = proc_dou8vec_minmax,
1112 .procname = "tcp_thin_linear_timeouts",
1113 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1114 .maxlen = sizeof(u8),
1116 .proc_handler = proc_dou8vec_minmax,
1119 .procname = "tcp_slow_start_after_idle",
1120 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1121 .maxlen = sizeof(u8),
1123 .proc_handler = proc_dou8vec_minmax,
1126 .procname = "tcp_retrans_collapse",
1127 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1128 .maxlen = sizeof(u8),
1130 .proc_handler = proc_dou8vec_minmax,
1133 .procname = "tcp_stdurg",
1134 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1135 .maxlen = sizeof(u8),
1137 .proc_handler = proc_dou8vec_minmax,
1140 .procname = "tcp_rfc1337",
1141 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1142 .maxlen = sizeof(u8),
1144 .proc_handler = proc_dou8vec_minmax,
1147 .procname = "tcp_abort_on_overflow",
1148 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1149 .maxlen = sizeof(u8),
1151 .proc_handler = proc_dou8vec_minmax,
1154 .procname = "tcp_fack",
1155 .data = &init_net.ipv4.sysctl_tcp_fack,
1156 .maxlen = sizeof(u8),
1158 .proc_handler = proc_dou8vec_minmax,
1161 .procname = "tcp_max_reordering",
1162 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1163 .maxlen = sizeof(int),
1165 .proc_handler = proc_dointvec
1168 .procname = "tcp_dsack",
1169 .data = &init_net.ipv4.sysctl_tcp_dsack,
1170 .maxlen = sizeof(u8),
1172 .proc_handler = proc_dou8vec_minmax,
1175 .procname = "tcp_app_win",
1176 .data = &init_net.ipv4.sysctl_tcp_app_win,
1177 .maxlen = sizeof(u8),
1179 .proc_handler = proc_dou8vec_minmax,
1182 .procname = "tcp_adv_win_scale",
1183 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1184 .maxlen = sizeof(int),
1186 .proc_handler = proc_dointvec_minmax,
1187 .extra1 = &tcp_adv_win_scale_min,
1188 .extra2 = &tcp_adv_win_scale_max,
1191 .procname = "tcp_frto",
1192 .data = &init_net.ipv4.sysctl_tcp_frto,
1193 .maxlen = sizeof(u8),
1195 .proc_handler = proc_dou8vec_minmax,
1198 .procname = "tcp_no_metrics_save",
1199 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1200 .maxlen = sizeof(u8),
1202 .proc_handler = proc_dou8vec_minmax,
1205 .procname = "tcp_no_ssthresh_metrics_save",
1206 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1207 .maxlen = sizeof(u8),
1209 .proc_handler = proc_dou8vec_minmax,
1210 .extra1 = SYSCTL_ZERO,
1211 .extra2 = SYSCTL_ONE,
1214 .procname = "tcp_moderate_rcvbuf",
1215 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1216 .maxlen = sizeof(u8),
1218 .proc_handler = proc_dou8vec_minmax,
1221 .procname = "tcp_tso_win_divisor",
1222 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1223 .maxlen = sizeof(u8),
1225 .proc_handler = proc_dou8vec_minmax,
1228 .procname = "tcp_workaround_signed_windows",
1229 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1230 .maxlen = sizeof(u8),
1232 .proc_handler = proc_dou8vec_minmax,
1235 .procname = "tcp_limit_output_bytes",
1236 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1237 .maxlen = sizeof(int),
1239 .proc_handler = proc_dointvec
1242 .procname = "tcp_challenge_ack_limit",
1243 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1244 .maxlen = sizeof(int),
1246 .proc_handler = proc_dointvec
1249 .procname = "tcp_min_tso_segs",
1250 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1251 .maxlen = sizeof(u8),
1253 .proc_handler = proc_dou8vec_minmax,
1254 .extra1 = SYSCTL_ONE,
1257 .procname = "tcp_min_rtt_wlen",
1258 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1259 .maxlen = sizeof(int),
1261 .proc_handler = proc_dointvec_minmax,
1262 .extra1 = SYSCTL_ZERO,
1263 .extra2 = &one_day_secs
1266 .procname = "tcp_autocorking",
1267 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1268 .maxlen = sizeof(u8),
1270 .proc_handler = proc_dou8vec_minmax,
1271 .extra1 = SYSCTL_ZERO,
1272 .extra2 = SYSCTL_ONE,
1275 .procname = "tcp_invalid_ratelimit",
1276 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1277 .maxlen = sizeof(int),
1279 .proc_handler = proc_dointvec_ms_jiffies,
1282 .procname = "tcp_pacing_ss_ratio",
1283 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1284 .maxlen = sizeof(int),
1286 .proc_handler = proc_dointvec_minmax,
1287 .extra1 = SYSCTL_ZERO,
1288 .extra2 = &thousand,
1291 .procname = "tcp_pacing_ca_ratio",
1292 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1293 .maxlen = sizeof(int),
1295 .proc_handler = proc_dointvec_minmax,
1296 .extra1 = SYSCTL_ZERO,
1297 .extra2 = &thousand,
1300 .procname = "tcp_wmem",
1301 .data = &init_net.ipv4.sysctl_tcp_wmem,
1302 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1304 .proc_handler = proc_dointvec_minmax,
1305 .extra1 = SYSCTL_ONE,
1308 .procname = "tcp_rmem",
1309 .data = &init_net.ipv4.sysctl_tcp_rmem,
1310 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1312 .proc_handler = proc_dointvec_minmax,
1313 .extra1 = SYSCTL_ONE,
1316 .procname = "tcp_comp_sack_delay_ns",
1317 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1318 .maxlen = sizeof(unsigned long),
1320 .proc_handler = proc_doulongvec_minmax,
1323 .procname = "tcp_comp_sack_slack_ns",
1324 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1325 .maxlen = sizeof(unsigned long),
1327 .proc_handler = proc_doulongvec_minmax,
1330 .procname = "tcp_comp_sack_nr",
1331 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1332 .maxlen = sizeof(u8),
1334 .proc_handler = proc_dou8vec_minmax,
1335 .extra1 = SYSCTL_ZERO,
1338 .procname = "tcp_reflect_tos",
1339 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1340 .maxlen = sizeof(u8),
1342 .proc_handler = proc_dou8vec_minmax,
1343 .extra1 = SYSCTL_ZERO,
1344 .extra2 = SYSCTL_ONE,
1347 .procname = "udp_rmem_min",
1348 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1349 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1351 .proc_handler = proc_dointvec_minmax,
1352 .extra1 = SYSCTL_ONE
1355 .procname = "udp_wmem_min",
1356 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1357 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1359 .proc_handler = proc_dointvec_minmax,
1360 .extra1 = SYSCTL_ONE
1363 .procname = "fib_notify_on_flag_change",
1364 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1365 .maxlen = sizeof(u8),
1367 .proc_handler = proc_dou8vec_minmax,
1368 .extra1 = SYSCTL_ZERO,
1374 static __net_init int ipv4_sysctl_init_net(struct net *net)
1376 struct ctl_table *table;
1378 table = ipv4_net_table;
1379 if (!net_eq(net, &init_net)) {
1382 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1386 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1387 if (table[i].data) {
1388 /* Update the variables to point into
1389 * the current struct net
1391 table[i].data += (void *)net - (void *)&init_net;
1393 /* Entries without data pointer are global;
1394 * Make them read-only in non-init_net ns
1396 table[i].mode &= ~0222;
1401 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1402 if (!net->ipv4.ipv4_hdr)
1405 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1406 if (!net->ipv4.sysctl_local_reserved_ports)
1412 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1414 if (!net_eq(net, &init_net))
1420 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1422 struct ctl_table *table;
1424 kfree(net->ipv4.sysctl_local_reserved_ports);
1425 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1426 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1430 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1431 .init = ipv4_sysctl_init_net,
1432 .exit = ipv4_sysctl_exit_net,
1435 static __init int sysctl_ipv4_init(void)
1437 struct ctl_table_header *hdr;
1439 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1443 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1444 unregister_net_sysctl_table(hdr);
1451 __initcall(sysctl_ipv4_init);