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]
9 #include <linux/sysctl.h>
10 #include <linux/seqlock.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
15 #include <net/ip_fib.h>
18 #include <net/cipso_ipv4.h>
20 #include <net/protocol.h>
21 #include <net/netevent.h>
24 static int three __maybe_unused = 3;
26 static int thousand = 1000;
27 static int tcp_retr1_max = 255;
28 static int ip_local_port_range_min[] = { 1, 1 };
29 static int ip_local_port_range_max[] = { 65535, 65535 };
30 static int tcp_adv_win_scale_min = -31;
31 static int tcp_adv_win_scale_max = 31;
32 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
33 static int tcp_min_snd_mss_max = 65535;
34 static int ip_privileged_port_min;
35 static int ip_privileged_port_max = 65535;
36 static int ip_ttl_min = 1;
37 static int ip_ttl_max = 255;
38 static int tcp_syn_retries_min = 1;
39 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
40 static int ip_ping_group_range_min[] = { 0, 0 };
41 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
42 static u32 u32_max_div_HZ = UINT_MAX / HZ;
43 static int one_day_secs = 24 * 3600;
44 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
45 FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
48 static int sysctl_tcp_low_latency __read_mostly;
50 /* Update system visible IP port range */
51 static void set_local_port_range(struct net *net, int range[2])
53 bool same_parity = !((range[0] ^ range[1]) & 1);
55 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
56 if (same_parity && !net->ipv4.ip_local_ports.warned) {
57 net->ipv4.ip_local_ports.warned = true;
58 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
60 net->ipv4.ip_local_ports.range[0] = range[0];
61 net->ipv4.ip_local_ports.range[1] = range[1];
62 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
65 /* Validate changes from /proc interface. */
66 static int ipv4_local_port_range(struct ctl_table *table, int write,
67 void *buffer, size_t *lenp, loff_t *ppos)
70 container_of(table->data, struct net, ipv4.ip_local_ports.range);
73 struct ctl_table tmp = {
75 .maxlen = sizeof(range),
77 .extra1 = &ip_local_port_range_min,
78 .extra2 = &ip_local_port_range_max,
81 inet_get_local_port_range(net, &range[0], &range[1]);
83 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
85 if (write && ret == 0) {
86 /* Ensure that the upper limit is not smaller than the lower,
87 * and that the lower does not encroach upon the privileged
90 if ((range[1] < range[0]) ||
91 (range[0] < net->ipv4.sysctl_ip_prot_sock))
94 set_local_port_range(net, range);
100 /* Validate changes from /proc interface. */
101 static int ipv4_privileged_ports(struct ctl_table *table, int write,
102 void *buffer, size_t *lenp, loff_t *ppos)
104 struct net *net = container_of(table->data, struct net,
105 ipv4.sysctl_ip_prot_sock);
109 struct ctl_table tmp = {
111 .maxlen = sizeof(pports),
113 .extra1 = &ip_privileged_port_min,
114 .extra2 = &ip_privileged_port_max,
117 pports = net->ipv4.sysctl_ip_prot_sock;
119 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
121 if (write && ret == 0) {
122 inet_get_local_port_range(net, &range[0], &range[1]);
123 /* Ensure that the local port range doesn't overlap with the
124 * privileged port range.
126 if (range[0] < pports)
129 net->ipv4.sysctl_ip_prot_sock = pports;
135 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
137 kgid_t *data = table->data;
139 container_of(table->data, struct net, ipv4.ping_group_range.range);
142 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
146 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
149 /* Update system visible IP port range */
150 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
152 kgid_t *data = table->data;
154 container_of(table->data, struct net, ipv4.ping_group_range.range);
155 write_seqlock(&net->ipv4.ping_group_range.lock);
158 write_sequnlock(&net->ipv4.ping_group_range.lock);
161 /* Validate changes from /proc interface. */
162 static int ipv4_ping_group_range(struct ctl_table *table, int write,
163 void *buffer, size_t *lenp, loff_t *ppos)
165 struct user_namespace *user_ns = current_user_ns();
169 struct ctl_table tmp = {
171 .maxlen = sizeof(urange),
173 .extra1 = &ip_ping_group_range_min,
174 .extra2 = &ip_ping_group_range_max,
177 inet_get_ping_group_range_table(table, &low, &high);
178 urange[0] = from_kgid_munged(user_ns, low);
179 urange[1] = from_kgid_munged(user_ns, high);
180 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
182 if (write && ret == 0) {
183 low = make_kgid(user_ns, urange[0]);
184 high = make_kgid(user_ns, urange[1]);
185 if (!gid_valid(low) || !gid_valid(high))
187 if (urange[1] < urange[0] || gid_lt(high, low)) {
188 low = make_kgid(&init_user_ns, 1);
189 high = make_kgid(&init_user_ns, 0);
191 set_ping_group_range(table, low, high);
197 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
198 void *buffer, size_t *lenp, loff_t *ppos)
203 net = container_of(table->data, struct net,
204 ipv4.sysctl_ip_fwd_update_priority);
205 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
206 if (write && ret == 0)
207 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
213 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
214 void *buffer, size_t *lenp, loff_t *ppos)
216 struct net *net = container_of(ctl->data, struct net,
217 ipv4.tcp_congestion_control);
218 char val[TCP_CA_NAME_MAX];
219 struct ctl_table tbl = {
221 .maxlen = TCP_CA_NAME_MAX,
225 tcp_get_default_congestion_control(net, val);
227 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
228 if (write && ret == 0)
229 ret = tcp_set_default_congestion_control(net, val);
233 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
234 int write, void *buffer,
235 size_t *lenp, loff_t *ppos)
237 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
240 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
243 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
244 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
249 static int proc_allowed_congestion_control(struct ctl_table *ctl,
250 int write, void *buffer,
251 size_t *lenp, loff_t *ppos)
253 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
256 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
260 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
261 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
262 if (write && ret == 0)
263 ret = tcp_set_allowed_congestion_control(tbl.data);
268 static int sscanf_key(char *buf, __le32 *key)
273 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
274 user_key + 2, user_key + 3) != 4) {
277 for (i = 0; i < ARRAY_SIZE(user_key); i++)
278 key[i] = cpu_to_le32(user_key[i]);
280 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
281 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
286 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
287 void *buffer, size_t *lenp, loff_t *ppos)
289 struct net *net = container_of(table->data, struct net,
290 ipv4.sysctl_tcp_fastopen);
291 /* maxlen to print the list of keys in hex (*2), with dashes
292 * separating doublewords and a comma in between keys.
294 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
295 2 * TCP_FASTOPEN_KEY_MAX) +
296 (TCP_FASTOPEN_KEY_MAX * 5)) };
297 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
298 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
300 int ret, i = 0, off = 0, n_keys;
302 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
306 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
308 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
312 for (i = 0; i < n_keys * 4; i++)
313 user_key[i] = le32_to_cpu(key[i]);
315 for (i = 0; i < n_keys; i++) {
316 off += snprintf(tbl.data + off, tbl.maxlen - off,
317 "%08x-%08x-%08x-%08x",
321 user_key[i * 4 + 3]);
323 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
327 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
330 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
332 if (write && ret == 0) {
333 backup_data = strchr(tbl.data, ',');
338 if (sscanf_key(tbl.data, key)) {
343 if (sscanf_key(backup_data, key + 4)) {
348 tcp_fastopen_reset_cipher(net, NULL, key,
349 backup_data ? key + 4 : NULL);
357 static void proc_configure_early_demux(int enabled, int protocol)
359 struct net_protocol *ipprot;
360 #if IS_ENABLED(CONFIG_IPV6)
361 struct inet6_protocol *ip6prot;
366 ipprot = rcu_dereference(inet_protos[protocol]);
368 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
371 #if IS_ENABLED(CONFIG_IPV6)
372 ip6prot = rcu_dereference(inet6_protos[protocol]);
374 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
380 static int proc_tcp_early_demux(struct ctl_table *table, int write,
381 void *buffer, size_t *lenp, loff_t *ppos)
385 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
388 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
390 proc_configure_early_demux(enabled, IPPROTO_TCP);
396 static int proc_udp_early_demux(struct ctl_table *table, int write,
397 void *buffer, size_t *lenp, loff_t *ppos)
401 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
404 int enabled = init_net.ipv4.sysctl_udp_early_demux;
406 proc_configure_early_demux(enabled, IPPROTO_UDP);
412 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
413 int write, void *buffer,
414 size_t *lenp, loff_t *ppos)
416 struct net *net = container_of(table->data, struct net,
417 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
420 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
421 if (write && ret == 0)
422 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
427 static int proc_tcp_available_ulp(struct ctl_table *ctl,
428 int write, void *buffer, size_t *lenp,
431 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
434 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
437 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
438 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
444 #ifdef CONFIG_IP_ROUTE_MULTIPATH
445 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
446 void *buffer, size_t *lenp,
449 struct net *net = container_of(table->data, struct net,
450 ipv4.sysctl_fib_multipath_hash_policy);
453 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
454 if (write && ret == 0)
455 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
460 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
461 void *buffer, size_t *lenp,
467 net = container_of(table->data, struct net,
468 ipv4.sysctl_fib_multipath_hash_fields);
469 ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
470 if (write && ret == 0)
471 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
477 static struct ctl_table ipv4_table[] = {
479 .procname = "tcp_max_orphans",
480 .data = &sysctl_tcp_max_orphans,
481 .maxlen = sizeof(int),
483 .proc_handler = proc_dointvec
486 .procname = "inet_peer_threshold",
487 .data = &inet_peer_threshold,
488 .maxlen = sizeof(int),
490 .proc_handler = proc_dointvec
493 .procname = "inet_peer_minttl",
494 .data = &inet_peer_minttl,
495 .maxlen = sizeof(int),
497 .proc_handler = proc_dointvec_jiffies,
500 .procname = "inet_peer_maxttl",
501 .data = &inet_peer_maxttl,
502 .maxlen = sizeof(int),
504 .proc_handler = proc_dointvec_jiffies,
507 .procname = "tcp_mem",
508 .maxlen = sizeof(sysctl_tcp_mem),
509 .data = &sysctl_tcp_mem,
511 .proc_handler = proc_doulongvec_minmax,
514 .procname = "tcp_low_latency",
515 .data = &sysctl_tcp_low_latency,
516 .maxlen = sizeof(int),
518 .proc_handler = proc_dointvec
520 #ifdef CONFIG_NETLABEL
522 .procname = "cipso_cache_enable",
523 .data = &cipso_v4_cache_enabled,
524 .maxlen = sizeof(int),
526 .proc_handler = proc_dointvec,
529 .procname = "cipso_cache_bucket_size",
530 .data = &cipso_v4_cache_bucketsize,
531 .maxlen = sizeof(int),
533 .proc_handler = proc_dointvec,
536 .procname = "cipso_rbm_optfmt",
537 .data = &cipso_v4_rbm_optfmt,
538 .maxlen = sizeof(int),
540 .proc_handler = proc_dointvec,
543 .procname = "cipso_rbm_strictvalid",
544 .data = &cipso_v4_rbm_strictvalid,
545 .maxlen = sizeof(int),
547 .proc_handler = proc_dointvec,
549 #endif /* CONFIG_NETLABEL */
551 .procname = "tcp_available_ulp",
552 .maxlen = TCP_ULP_BUF_MAX,
554 .proc_handler = proc_tcp_available_ulp,
557 .procname = "icmp_msgs_per_sec",
558 .data = &sysctl_icmp_msgs_per_sec,
559 .maxlen = sizeof(int),
561 .proc_handler = proc_dointvec_minmax,
562 .extra1 = SYSCTL_ZERO,
565 .procname = "icmp_msgs_burst",
566 .data = &sysctl_icmp_msgs_burst,
567 .maxlen = sizeof(int),
569 .proc_handler = proc_dointvec_minmax,
570 .extra1 = SYSCTL_ZERO,
573 .procname = "udp_mem",
574 .data = &sysctl_udp_mem,
575 .maxlen = sizeof(sysctl_udp_mem),
577 .proc_handler = proc_doulongvec_minmax,
580 .procname = "fib_sync_mem",
581 .data = &sysctl_fib_sync_mem,
582 .maxlen = sizeof(sysctl_fib_sync_mem),
584 .proc_handler = proc_douintvec_minmax,
585 .extra1 = &sysctl_fib_sync_mem_min,
586 .extra2 = &sysctl_fib_sync_mem_max,
591 static struct ctl_table ipv4_net_table[] = {
593 .procname = "icmp_echo_ignore_all",
594 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
595 .maxlen = sizeof(u8),
597 .proc_handler = proc_dou8vec_minmax,
600 .procname = "icmp_echo_enable_probe",
601 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
602 .maxlen = sizeof(u8),
604 .proc_handler = proc_dou8vec_minmax,
605 .extra1 = SYSCTL_ZERO,
609 .procname = "icmp_echo_ignore_broadcasts",
610 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
611 .maxlen = sizeof(u8),
613 .proc_handler = proc_dou8vec_minmax,
616 .procname = "icmp_ignore_bogus_error_responses",
617 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
618 .maxlen = sizeof(u8),
620 .proc_handler = proc_dou8vec_minmax,
623 .procname = "icmp_errors_use_inbound_ifaddr",
624 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
625 .maxlen = sizeof(u8),
627 .proc_handler = proc_dou8vec_minmax,
630 .procname = "icmp_ratelimit",
631 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
632 .maxlen = sizeof(int),
634 .proc_handler = proc_dointvec_ms_jiffies,
637 .procname = "icmp_ratemask",
638 .data = &init_net.ipv4.sysctl_icmp_ratemask,
639 .maxlen = sizeof(int),
641 .proc_handler = proc_dointvec
644 .procname = "ping_group_range",
645 .data = &init_net.ipv4.ping_group_range.range,
646 .maxlen = sizeof(gid_t)*2,
648 .proc_handler = ipv4_ping_group_range,
650 #ifdef CONFIG_NET_L3_MASTER_DEV
652 .procname = "raw_l3mdev_accept",
653 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
654 .maxlen = sizeof(u8),
656 .proc_handler = proc_dou8vec_minmax,
657 .extra1 = SYSCTL_ZERO,
658 .extra2 = SYSCTL_ONE,
662 .procname = "tcp_ecn",
663 .data = &init_net.ipv4.sysctl_tcp_ecn,
664 .maxlen = sizeof(u8),
666 .proc_handler = proc_dou8vec_minmax,
669 .procname = "tcp_ecn_fallback",
670 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
671 .maxlen = sizeof(u8),
673 .proc_handler = proc_dou8vec_minmax,
676 .procname = "ip_dynaddr",
677 .data = &init_net.ipv4.sysctl_ip_dynaddr,
678 .maxlen = sizeof(u8),
680 .proc_handler = proc_dou8vec_minmax,
683 .procname = "ip_early_demux",
684 .data = &init_net.ipv4.sysctl_ip_early_demux,
685 .maxlen = sizeof(u8),
687 .proc_handler = proc_dou8vec_minmax,
690 .procname = "udp_early_demux",
691 .data = &init_net.ipv4.sysctl_udp_early_demux,
692 .maxlen = sizeof(u8),
694 .proc_handler = proc_udp_early_demux
697 .procname = "tcp_early_demux",
698 .data = &init_net.ipv4.sysctl_tcp_early_demux,
699 .maxlen = sizeof(u8),
701 .proc_handler = proc_tcp_early_demux
704 .procname = "nexthop_compat_mode",
705 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
706 .maxlen = sizeof(u8),
708 .proc_handler = proc_dou8vec_minmax,
709 .extra1 = SYSCTL_ZERO,
710 .extra2 = SYSCTL_ONE,
713 .procname = "ip_default_ttl",
714 .data = &init_net.ipv4.sysctl_ip_default_ttl,
715 .maxlen = sizeof(u8),
717 .proc_handler = proc_dou8vec_minmax,
718 .extra1 = &ip_ttl_min,
719 .extra2 = &ip_ttl_max,
722 .procname = "ip_local_port_range",
723 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
724 .data = &init_net.ipv4.ip_local_ports.range,
726 .proc_handler = ipv4_local_port_range,
729 .procname = "ip_local_reserved_ports",
730 .data = &init_net.ipv4.sysctl_local_reserved_ports,
733 .proc_handler = proc_do_large_bitmap,
736 .procname = "ip_no_pmtu_disc",
737 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
738 .maxlen = sizeof(u8),
740 .proc_handler = proc_dou8vec_minmax,
743 .procname = "ip_forward_use_pmtu",
744 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
745 .maxlen = sizeof(u8),
747 .proc_handler = proc_dou8vec_minmax,
750 .procname = "ip_forward_update_priority",
751 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
752 .maxlen = sizeof(u8),
754 .proc_handler = ipv4_fwd_update_priority,
755 .extra1 = SYSCTL_ZERO,
756 .extra2 = SYSCTL_ONE,
759 .procname = "ip_nonlocal_bind",
760 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
761 .maxlen = sizeof(u8),
763 .proc_handler = proc_dou8vec_minmax,
766 .procname = "ip_autobind_reuse",
767 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
768 .maxlen = sizeof(u8),
770 .proc_handler = proc_dou8vec_minmax,
771 .extra1 = SYSCTL_ZERO,
772 .extra2 = SYSCTL_ONE,
775 .procname = "fwmark_reflect",
776 .data = &init_net.ipv4.sysctl_fwmark_reflect,
777 .maxlen = sizeof(u8),
779 .proc_handler = proc_dou8vec_minmax,
782 .procname = "tcp_fwmark_accept",
783 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
784 .maxlen = sizeof(u8),
786 .proc_handler = proc_dou8vec_minmax,
788 #ifdef CONFIG_NET_L3_MASTER_DEV
790 .procname = "tcp_l3mdev_accept",
791 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
792 .maxlen = sizeof(u8),
794 .proc_handler = proc_dou8vec_minmax,
795 .extra1 = SYSCTL_ZERO,
796 .extra2 = SYSCTL_ONE,
800 .procname = "tcp_mtu_probing",
801 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
802 .maxlen = sizeof(u8),
804 .proc_handler = proc_dou8vec_minmax,
807 .procname = "tcp_base_mss",
808 .data = &init_net.ipv4.sysctl_tcp_base_mss,
809 .maxlen = sizeof(int),
811 .proc_handler = proc_dointvec,
814 .procname = "tcp_min_snd_mss",
815 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
816 .maxlen = sizeof(int),
818 .proc_handler = proc_dointvec_minmax,
819 .extra1 = &tcp_min_snd_mss_min,
820 .extra2 = &tcp_min_snd_mss_max,
823 .procname = "tcp_mtu_probe_floor",
824 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
825 .maxlen = sizeof(int),
827 .proc_handler = proc_dointvec_minmax,
828 .extra1 = &tcp_min_snd_mss_min,
829 .extra2 = &tcp_min_snd_mss_max,
832 .procname = "tcp_probe_threshold",
833 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
834 .maxlen = sizeof(int),
836 .proc_handler = proc_dointvec,
839 .procname = "tcp_probe_interval",
840 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
841 .maxlen = sizeof(u32),
843 .proc_handler = proc_douintvec_minmax,
844 .extra2 = &u32_max_div_HZ,
847 .procname = "igmp_link_local_mcast_reports",
848 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
849 .maxlen = sizeof(u8),
851 .proc_handler = proc_dou8vec_minmax,
854 .procname = "igmp_max_memberships",
855 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
856 .maxlen = sizeof(int),
858 .proc_handler = proc_dointvec
861 .procname = "igmp_max_msf",
862 .data = &init_net.ipv4.sysctl_igmp_max_msf,
863 .maxlen = sizeof(int),
865 .proc_handler = proc_dointvec
867 #ifdef CONFIG_IP_MULTICAST
869 .procname = "igmp_qrv",
870 .data = &init_net.ipv4.sysctl_igmp_qrv,
871 .maxlen = sizeof(int),
873 .proc_handler = proc_dointvec_minmax,
878 .procname = "tcp_congestion_control",
879 .data = &init_net.ipv4.tcp_congestion_control,
881 .maxlen = TCP_CA_NAME_MAX,
882 .proc_handler = proc_tcp_congestion_control,
885 .procname = "tcp_available_congestion_control",
886 .maxlen = TCP_CA_BUF_MAX,
888 .proc_handler = proc_tcp_available_congestion_control,
891 .procname = "tcp_allowed_congestion_control",
892 .maxlen = TCP_CA_BUF_MAX,
894 .proc_handler = proc_allowed_congestion_control,
897 .procname = "tcp_keepalive_time",
898 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
899 .maxlen = sizeof(int),
901 .proc_handler = proc_dointvec_jiffies,
904 .procname = "tcp_keepalive_probes",
905 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
906 .maxlen = sizeof(u8),
908 .proc_handler = proc_dou8vec_minmax,
911 .procname = "tcp_keepalive_intvl",
912 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
913 .maxlen = sizeof(int),
915 .proc_handler = proc_dointvec_jiffies,
918 .procname = "tcp_syn_retries",
919 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
920 .maxlen = sizeof(u8),
922 .proc_handler = proc_dou8vec_minmax,
923 .extra1 = &tcp_syn_retries_min,
924 .extra2 = &tcp_syn_retries_max
927 .procname = "tcp_synack_retries",
928 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
929 .maxlen = sizeof(u8),
931 .proc_handler = proc_dou8vec_minmax,
933 #ifdef CONFIG_SYN_COOKIES
935 .procname = "tcp_syncookies",
936 .data = &init_net.ipv4.sysctl_tcp_syncookies,
937 .maxlen = sizeof(u8),
939 .proc_handler = proc_dou8vec_minmax,
943 .procname = "tcp_migrate_req",
944 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
945 .maxlen = sizeof(u8),
947 .proc_handler = proc_dou8vec_minmax,
948 .extra1 = SYSCTL_ZERO,
952 .procname = "tcp_reordering",
953 .data = &init_net.ipv4.sysctl_tcp_reordering,
954 .maxlen = sizeof(int),
956 .proc_handler = proc_dointvec
959 .procname = "tcp_retries1",
960 .data = &init_net.ipv4.sysctl_tcp_retries1,
961 .maxlen = sizeof(u8),
963 .proc_handler = proc_dou8vec_minmax,
964 .extra2 = &tcp_retr1_max
967 .procname = "tcp_retries2",
968 .data = &init_net.ipv4.sysctl_tcp_retries2,
969 .maxlen = sizeof(u8),
971 .proc_handler = proc_dou8vec_minmax,
974 .procname = "tcp_orphan_retries",
975 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
976 .maxlen = sizeof(u8),
978 .proc_handler = proc_dou8vec_minmax,
981 .procname = "tcp_fin_timeout",
982 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
983 .maxlen = sizeof(int),
985 .proc_handler = proc_dointvec_jiffies,
988 .procname = "tcp_notsent_lowat",
989 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
990 .maxlen = sizeof(unsigned int),
992 .proc_handler = proc_douintvec,
995 .procname = "tcp_tw_reuse",
996 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
997 .maxlen = sizeof(u8),
999 .proc_handler = proc_dou8vec_minmax,
1000 .extra1 = SYSCTL_ZERO,
1004 .procname = "tcp_max_tw_buckets",
1005 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
1006 .maxlen = sizeof(int),
1008 .proc_handler = proc_dointvec
1011 .procname = "tcp_max_syn_backlog",
1012 .data = &init_net.ipv4.sysctl_max_syn_backlog,
1013 .maxlen = sizeof(int),
1015 .proc_handler = proc_dointvec
1018 .procname = "tcp_fastopen",
1019 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1020 .maxlen = sizeof(int),
1022 .proc_handler = proc_dointvec,
1025 .procname = "tcp_fastopen_key",
1027 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1028 /* maxlen to print the list of keys in hex (*2), with dashes
1029 * separating doublewords and a comma in between keys.
1031 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1032 2 * TCP_FASTOPEN_KEY_MAX) +
1033 (TCP_FASTOPEN_KEY_MAX * 5)),
1034 .proc_handler = proc_tcp_fastopen_key,
1037 .procname = "tcp_fastopen_blackhole_timeout_sec",
1038 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1039 .maxlen = sizeof(int),
1041 .proc_handler = proc_tfo_blackhole_detect_timeout,
1042 .extra1 = SYSCTL_ZERO,
1044 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1046 .procname = "fib_multipath_use_neigh",
1047 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1048 .maxlen = sizeof(u8),
1050 .proc_handler = proc_dou8vec_minmax,
1051 .extra1 = SYSCTL_ZERO,
1052 .extra2 = SYSCTL_ONE,
1055 .procname = "fib_multipath_hash_policy",
1056 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1057 .maxlen = sizeof(u8),
1059 .proc_handler = proc_fib_multipath_hash_policy,
1060 .extra1 = SYSCTL_ZERO,
1064 .procname = "fib_multipath_hash_fields",
1065 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1066 .maxlen = sizeof(u32),
1068 .proc_handler = proc_fib_multipath_hash_fields,
1069 .extra1 = SYSCTL_ONE,
1070 .extra2 = &fib_multipath_hash_fields_all_mask,
1074 .procname = "ip_unprivileged_port_start",
1075 .maxlen = sizeof(int),
1076 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1078 .proc_handler = ipv4_privileged_ports,
1080 #ifdef CONFIG_NET_L3_MASTER_DEV
1082 .procname = "udp_l3mdev_accept",
1083 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1084 .maxlen = sizeof(u8),
1086 .proc_handler = proc_dou8vec_minmax,
1087 .extra1 = SYSCTL_ZERO,
1088 .extra2 = SYSCTL_ONE,
1092 .procname = "tcp_sack",
1093 .data = &init_net.ipv4.sysctl_tcp_sack,
1094 .maxlen = sizeof(u8),
1096 .proc_handler = proc_dou8vec_minmax,
1099 .procname = "tcp_window_scaling",
1100 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1101 .maxlen = sizeof(u8),
1103 .proc_handler = proc_dou8vec_minmax,
1106 .procname = "tcp_timestamps",
1107 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1108 .maxlen = sizeof(u8),
1110 .proc_handler = proc_dou8vec_minmax,
1113 .procname = "tcp_early_retrans",
1114 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1115 .maxlen = sizeof(u8),
1117 .proc_handler = proc_dou8vec_minmax,
1118 .extra1 = SYSCTL_ZERO,
1122 .procname = "tcp_recovery",
1123 .data = &init_net.ipv4.sysctl_tcp_recovery,
1124 .maxlen = sizeof(u8),
1126 .proc_handler = proc_dou8vec_minmax,
1129 .procname = "tcp_thin_linear_timeouts",
1130 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1131 .maxlen = sizeof(u8),
1133 .proc_handler = proc_dou8vec_minmax,
1136 .procname = "tcp_slow_start_after_idle",
1137 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1138 .maxlen = sizeof(u8),
1140 .proc_handler = proc_dou8vec_minmax,
1143 .procname = "tcp_retrans_collapse",
1144 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1145 .maxlen = sizeof(u8),
1147 .proc_handler = proc_dou8vec_minmax,
1150 .procname = "tcp_stdurg",
1151 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1152 .maxlen = sizeof(u8),
1154 .proc_handler = proc_dou8vec_minmax,
1157 .procname = "tcp_rfc1337",
1158 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1159 .maxlen = sizeof(u8),
1161 .proc_handler = proc_dou8vec_minmax,
1164 .procname = "tcp_abort_on_overflow",
1165 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1166 .maxlen = sizeof(u8),
1168 .proc_handler = proc_dou8vec_minmax,
1171 .procname = "tcp_fack",
1172 .data = &init_net.ipv4.sysctl_tcp_fack,
1173 .maxlen = sizeof(u8),
1175 .proc_handler = proc_dou8vec_minmax,
1178 .procname = "tcp_max_reordering",
1179 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1180 .maxlen = sizeof(int),
1182 .proc_handler = proc_dointvec
1185 .procname = "tcp_dsack",
1186 .data = &init_net.ipv4.sysctl_tcp_dsack,
1187 .maxlen = sizeof(u8),
1189 .proc_handler = proc_dou8vec_minmax,
1192 .procname = "tcp_app_win",
1193 .data = &init_net.ipv4.sysctl_tcp_app_win,
1194 .maxlen = sizeof(u8),
1196 .proc_handler = proc_dou8vec_minmax,
1199 .procname = "tcp_adv_win_scale",
1200 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1201 .maxlen = sizeof(int),
1203 .proc_handler = proc_dointvec_minmax,
1204 .extra1 = &tcp_adv_win_scale_min,
1205 .extra2 = &tcp_adv_win_scale_max,
1208 .procname = "tcp_frto",
1209 .data = &init_net.ipv4.sysctl_tcp_frto,
1210 .maxlen = sizeof(u8),
1212 .proc_handler = proc_dou8vec_minmax,
1215 .procname = "tcp_no_metrics_save",
1216 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1217 .maxlen = sizeof(u8),
1219 .proc_handler = proc_dou8vec_minmax,
1222 .procname = "tcp_no_ssthresh_metrics_save",
1223 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1224 .maxlen = sizeof(u8),
1226 .proc_handler = proc_dou8vec_minmax,
1227 .extra1 = SYSCTL_ZERO,
1228 .extra2 = SYSCTL_ONE,
1231 .procname = "tcp_moderate_rcvbuf",
1232 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1233 .maxlen = sizeof(u8),
1235 .proc_handler = proc_dou8vec_minmax,
1238 .procname = "tcp_tso_win_divisor",
1239 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1240 .maxlen = sizeof(u8),
1242 .proc_handler = proc_dou8vec_minmax,
1245 .procname = "tcp_workaround_signed_windows",
1246 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1247 .maxlen = sizeof(u8),
1249 .proc_handler = proc_dou8vec_minmax,
1252 .procname = "tcp_limit_output_bytes",
1253 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1254 .maxlen = sizeof(int),
1256 .proc_handler = proc_dointvec
1259 .procname = "tcp_challenge_ack_limit",
1260 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1261 .maxlen = sizeof(int),
1263 .proc_handler = proc_dointvec
1266 .procname = "tcp_min_tso_segs",
1267 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1268 .maxlen = sizeof(u8),
1270 .proc_handler = proc_dou8vec_minmax,
1271 .extra1 = SYSCTL_ONE,
1274 .procname = "tcp_min_rtt_wlen",
1275 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1276 .maxlen = sizeof(int),
1278 .proc_handler = proc_dointvec_minmax,
1279 .extra1 = SYSCTL_ZERO,
1280 .extra2 = &one_day_secs
1283 .procname = "tcp_autocorking",
1284 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1285 .maxlen = sizeof(u8),
1287 .proc_handler = proc_dou8vec_minmax,
1288 .extra1 = SYSCTL_ZERO,
1289 .extra2 = SYSCTL_ONE,
1292 .procname = "tcp_invalid_ratelimit",
1293 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1294 .maxlen = sizeof(int),
1296 .proc_handler = proc_dointvec_ms_jiffies,
1299 .procname = "tcp_pacing_ss_ratio",
1300 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1301 .maxlen = sizeof(int),
1303 .proc_handler = proc_dointvec_minmax,
1304 .extra1 = SYSCTL_ZERO,
1305 .extra2 = &thousand,
1308 .procname = "tcp_pacing_ca_ratio",
1309 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1310 .maxlen = sizeof(int),
1312 .proc_handler = proc_dointvec_minmax,
1313 .extra1 = SYSCTL_ZERO,
1314 .extra2 = &thousand,
1317 .procname = "tcp_wmem",
1318 .data = &init_net.ipv4.sysctl_tcp_wmem,
1319 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1321 .proc_handler = proc_dointvec_minmax,
1322 .extra1 = SYSCTL_ONE,
1325 .procname = "tcp_rmem",
1326 .data = &init_net.ipv4.sysctl_tcp_rmem,
1327 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1329 .proc_handler = proc_dointvec_minmax,
1330 .extra1 = SYSCTL_ONE,
1333 .procname = "tcp_comp_sack_delay_ns",
1334 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1335 .maxlen = sizeof(unsigned long),
1337 .proc_handler = proc_doulongvec_minmax,
1340 .procname = "tcp_comp_sack_slack_ns",
1341 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1342 .maxlen = sizeof(unsigned long),
1344 .proc_handler = proc_doulongvec_minmax,
1347 .procname = "tcp_comp_sack_nr",
1348 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1349 .maxlen = sizeof(u8),
1351 .proc_handler = proc_dou8vec_minmax,
1352 .extra1 = SYSCTL_ZERO,
1355 .procname = "tcp_reflect_tos",
1356 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1357 .maxlen = sizeof(u8),
1359 .proc_handler = proc_dou8vec_minmax,
1360 .extra1 = SYSCTL_ZERO,
1361 .extra2 = SYSCTL_ONE,
1364 .procname = "udp_rmem_min",
1365 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1366 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1368 .proc_handler = proc_dointvec_minmax,
1369 .extra1 = SYSCTL_ONE
1372 .procname = "udp_wmem_min",
1373 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1374 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1376 .proc_handler = proc_dointvec_minmax,
1377 .extra1 = SYSCTL_ONE
1380 .procname = "fib_notify_on_flag_change",
1381 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1382 .maxlen = sizeof(u8),
1384 .proc_handler = proc_dou8vec_minmax,
1385 .extra1 = SYSCTL_ZERO,
1391 static __net_init int ipv4_sysctl_init_net(struct net *net)
1393 struct ctl_table *table;
1395 table = ipv4_net_table;
1396 if (!net_eq(net, &init_net)) {
1399 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1403 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1404 if (table[i].data) {
1405 /* Update the variables to point into
1406 * the current struct net
1408 table[i].data += (void *)net - (void *)&init_net;
1410 /* Entries without data pointer are global;
1411 * Make them read-only in non-init_net ns
1413 table[i].mode &= ~0222;
1418 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1419 if (!net->ipv4.ipv4_hdr)
1422 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1423 if (!net->ipv4.sysctl_local_reserved_ports)
1429 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1431 if (!net_eq(net, &init_net))
1437 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1439 struct ctl_table *table;
1441 kfree(net->ipv4.sysctl_local_reserved_ports);
1442 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1443 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1447 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1448 .init = ipv4_sysctl_init_net,
1449 .exit = ipv4_sysctl_exit_net,
1452 static __init int sysctl_ipv4_init(void)
1454 struct ctl_table_header *hdr;
1456 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1460 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1461 unregister_net_sysctl_table(hdr);
1468 __initcall(sysctl_ipv4_init);