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[] = {
592 /* tcp_max_tw_buckets must be first in this table. */
594 .procname = "tcp_max_tw_buckets",
595 /* .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets, */
596 .maxlen = sizeof(int),
598 .proc_handler = proc_dointvec
601 .procname = "icmp_echo_ignore_all",
602 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
603 .maxlen = sizeof(u8),
605 .proc_handler = proc_dou8vec_minmax,
608 .procname = "icmp_echo_enable_probe",
609 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
610 .maxlen = sizeof(u8),
612 .proc_handler = proc_dou8vec_minmax,
613 .extra1 = SYSCTL_ZERO,
617 .procname = "icmp_echo_ignore_broadcasts",
618 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
619 .maxlen = sizeof(u8),
621 .proc_handler = proc_dou8vec_minmax,
624 .procname = "icmp_ignore_bogus_error_responses",
625 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
626 .maxlen = sizeof(u8),
628 .proc_handler = proc_dou8vec_minmax,
631 .procname = "icmp_errors_use_inbound_ifaddr",
632 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
633 .maxlen = sizeof(u8),
635 .proc_handler = proc_dou8vec_minmax,
638 .procname = "icmp_ratelimit",
639 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
640 .maxlen = sizeof(int),
642 .proc_handler = proc_dointvec_ms_jiffies,
645 .procname = "icmp_ratemask",
646 .data = &init_net.ipv4.sysctl_icmp_ratemask,
647 .maxlen = sizeof(int),
649 .proc_handler = proc_dointvec
652 .procname = "ping_group_range",
653 .data = &init_net.ipv4.ping_group_range.range,
654 .maxlen = sizeof(gid_t)*2,
656 .proc_handler = ipv4_ping_group_range,
658 #ifdef CONFIG_NET_L3_MASTER_DEV
660 .procname = "raw_l3mdev_accept",
661 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
662 .maxlen = sizeof(u8),
664 .proc_handler = proc_dou8vec_minmax,
665 .extra1 = SYSCTL_ZERO,
666 .extra2 = SYSCTL_ONE,
670 .procname = "tcp_ecn",
671 .data = &init_net.ipv4.sysctl_tcp_ecn,
672 .maxlen = sizeof(u8),
674 .proc_handler = proc_dou8vec_minmax,
677 .procname = "tcp_ecn_fallback",
678 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
679 .maxlen = sizeof(u8),
681 .proc_handler = proc_dou8vec_minmax,
684 .procname = "ip_dynaddr",
685 .data = &init_net.ipv4.sysctl_ip_dynaddr,
686 .maxlen = sizeof(u8),
688 .proc_handler = proc_dou8vec_minmax,
691 .procname = "ip_early_demux",
692 .data = &init_net.ipv4.sysctl_ip_early_demux,
693 .maxlen = sizeof(u8),
695 .proc_handler = proc_dou8vec_minmax,
698 .procname = "udp_early_demux",
699 .data = &init_net.ipv4.sysctl_udp_early_demux,
700 .maxlen = sizeof(u8),
702 .proc_handler = proc_udp_early_demux
705 .procname = "tcp_early_demux",
706 .data = &init_net.ipv4.sysctl_tcp_early_demux,
707 .maxlen = sizeof(u8),
709 .proc_handler = proc_tcp_early_demux
712 .procname = "nexthop_compat_mode",
713 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
714 .maxlen = sizeof(u8),
716 .proc_handler = proc_dou8vec_minmax,
717 .extra1 = SYSCTL_ZERO,
718 .extra2 = SYSCTL_ONE,
721 .procname = "ip_default_ttl",
722 .data = &init_net.ipv4.sysctl_ip_default_ttl,
723 .maxlen = sizeof(u8),
725 .proc_handler = proc_dou8vec_minmax,
726 .extra1 = &ip_ttl_min,
727 .extra2 = &ip_ttl_max,
730 .procname = "ip_local_port_range",
731 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
732 .data = &init_net.ipv4.ip_local_ports.range,
734 .proc_handler = ipv4_local_port_range,
737 .procname = "ip_local_reserved_ports",
738 .data = &init_net.ipv4.sysctl_local_reserved_ports,
741 .proc_handler = proc_do_large_bitmap,
744 .procname = "ip_no_pmtu_disc",
745 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
746 .maxlen = sizeof(u8),
748 .proc_handler = proc_dou8vec_minmax,
751 .procname = "ip_forward_use_pmtu",
752 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
753 .maxlen = sizeof(u8),
755 .proc_handler = proc_dou8vec_minmax,
758 .procname = "ip_forward_update_priority",
759 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
760 .maxlen = sizeof(u8),
762 .proc_handler = ipv4_fwd_update_priority,
763 .extra1 = SYSCTL_ZERO,
764 .extra2 = SYSCTL_ONE,
767 .procname = "ip_nonlocal_bind",
768 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
769 .maxlen = sizeof(u8),
771 .proc_handler = proc_dou8vec_minmax,
774 .procname = "ip_autobind_reuse",
775 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
776 .maxlen = sizeof(u8),
778 .proc_handler = proc_dou8vec_minmax,
779 .extra1 = SYSCTL_ZERO,
780 .extra2 = SYSCTL_ONE,
783 .procname = "fwmark_reflect",
784 .data = &init_net.ipv4.sysctl_fwmark_reflect,
785 .maxlen = sizeof(u8),
787 .proc_handler = proc_dou8vec_minmax,
790 .procname = "tcp_fwmark_accept",
791 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
792 .maxlen = sizeof(u8),
794 .proc_handler = proc_dou8vec_minmax,
796 #ifdef CONFIG_NET_L3_MASTER_DEV
798 .procname = "tcp_l3mdev_accept",
799 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
800 .maxlen = sizeof(u8),
802 .proc_handler = proc_dou8vec_minmax,
803 .extra1 = SYSCTL_ZERO,
804 .extra2 = SYSCTL_ONE,
808 .procname = "tcp_mtu_probing",
809 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
810 .maxlen = sizeof(u8),
812 .proc_handler = proc_dou8vec_minmax,
815 .procname = "tcp_base_mss",
816 .data = &init_net.ipv4.sysctl_tcp_base_mss,
817 .maxlen = sizeof(int),
819 .proc_handler = proc_dointvec,
822 .procname = "tcp_min_snd_mss",
823 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
824 .maxlen = sizeof(int),
826 .proc_handler = proc_dointvec_minmax,
827 .extra1 = &tcp_min_snd_mss_min,
828 .extra2 = &tcp_min_snd_mss_max,
831 .procname = "tcp_mtu_probe_floor",
832 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
833 .maxlen = sizeof(int),
835 .proc_handler = proc_dointvec_minmax,
836 .extra1 = &tcp_min_snd_mss_min,
837 .extra2 = &tcp_min_snd_mss_max,
840 .procname = "tcp_probe_threshold",
841 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
842 .maxlen = sizeof(int),
844 .proc_handler = proc_dointvec,
847 .procname = "tcp_probe_interval",
848 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
849 .maxlen = sizeof(u32),
851 .proc_handler = proc_douintvec_minmax,
852 .extra2 = &u32_max_div_HZ,
855 .procname = "igmp_link_local_mcast_reports",
856 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
857 .maxlen = sizeof(u8),
859 .proc_handler = proc_dou8vec_minmax,
862 .procname = "igmp_max_memberships",
863 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
864 .maxlen = sizeof(int),
866 .proc_handler = proc_dointvec
869 .procname = "igmp_max_msf",
870 .data = &init_net.ipv4.sysctl_igmp_max_msf,
871 .maxlen = sizeof(int),
873 .proc_handler = proc_dointvec
875 #ifdef CONFIG_IP_MULTICAST
877 .procname = "igmp_qrv",
878 .data = &init_net.ipv4.sysctl_igmp_qrv,
879 .maxlen = sizeof(int),
881 .proc_handler = proc_dointvec_minmax,
886 .procname = "tcp_congestion_control",
887 .data = &init_net.ipv4.tcp_congestion_control,
889 .maxlen = TCP_CA_NAME_MAX,
890 .proc_handler = proc_tcp_congestion_control,
893 .procname = "tcp_available_congestion_control",
894 .maxlen = TCP_CA_BUF_MAX,
896 .proc_handler = proc_tcp_available_congestion_control,
899 .procname = "tcp_allowed_congestion_control",
900 .maxlen = TCP_CA_BUF_MAX,
902 .proc_handler = proc_allowed_congestion_control,
905 .procname = "tcp_keepalive_time",
906 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
907 .maxlen = sizeof(int),
909 .proc_handler = proc_dointvec_jiffies,
912 .procname = "tcp_keepalive_probes",
913 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
914 .maxlen = sizeof(u8),
916 .proc_handler = proc_dou8vec_minmax,
919 .procname = "tcp_keepalive_intvl",
920 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
921 .maxlen = sizeof(int),
923 .proc_handler = proc_dointvec_jiffies,
926 .procname = "tcp_syn_retries",
927 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
928 .maxlen = sizeof(u8),
930 .proc_handler = proc_dou8vec_minmax,
931 .extra1 = &tcp_syn_retries_min,
932 .extra2 = &tcp_syn_retries_max
935 .procname = "tcp_synack_retries",
936 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
937 .maxlen = sizeof(u8),
939 .proc_handler = proc_dou8vec_minmax,
941 #ifdef CONFIG_SYN_COOKIES
943 .procname = "tcp_syncookies",
944 .data = &init_net.ipv4.sysctl_tcp_syncookies,
945 .maxlen = sizeof(u8),
947 .proc_handler = proc_dou8vec_minmax,
951 .procname = "tcp_migrate_req",
952 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
953 .maxlen = sizeof(u8),
955 .proc_handler = proc_dou8vec_minmax,
956 .extra1 = SYSCTL_ZERO,
960 .procname = "tcp_reordering",
961 .data = &init_net.ipv4.sysctl_tcp_reordering,
962 .maxlen = sizeof(int),
964 .proc_handler = proc_dointvec
967 .procname = "tcp_retries1",
968 .data = &init_net.ipv4.sysctl_tcp_retries1,
969 .maxlen = sizeof(u8),
971 .proc_handler = proc_dou8vec_minmax,
972 .extra2 = &tcp_retr1_max
975 .procname = "tcp_retries2",
976 .data = &init_net.ipv4.sysctl_tcp_retries2,
977 .maxlen = sizeof(u8),
979 .proc_handler = proc_dou8vec_minmax,
982 .procname = "tcp_orphan_retries",
983 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
984 .maxlen = sizeof(u8),
986 .proc_handler = proc_dou8vec_minmax,
989 .procname = "tcp_fin_timeout",
990 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
991 .maxlen = sizeof(int),
993 .proc_handler = proc_dointvec_jiffies,
996 .procname = "tcp_notsent_lowat",
997 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
998 .maxlen = sizeof(unsigned int),
1000 .proc_handler = proc_douintvec,
1003 .procname = "tcp_tw_reuse",
1004 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
1005 .maxlen = sizeof(u8),
1007 .proc_handler = proc_dou8vec_minmax,
1008 .extra1 = SYSCTL_ZERO,
1012 .procname = "tcp_max_syn_backlog",
1013 .data = &init_net.ipv4.sysctl_max_syn_backlog,
1014 .maxlen = sizeof(int),
1016 .proc_handler = proc_dointvec
1019 .procname = "tcp_fastopen",
1020 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1021 .maxlen = sizeof(int),
1023 .proc_handler = proc_dointvec,
1026 .procname = "tcp_fastopen_key",
1028 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1029 /* maxlen to print the list of keys in hex (*2), with dashes
1030 * separating doublewords and a comma in between keys.
1032 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1033 2 * TCP_FASTOPEN_KEY_MAX) +
1034 (TCP_FASTOPEN_KEY_MAX * 5)),
1035 .proc_handler = proc_tcp_fastopen_key,
1038 .procname = "tcp_fastopen_blackhole_timeout_sec",
1039 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1040 .maxlen = sizeof(int),
1042 .proc_handler = proc_tfo_blackhole_detect_timeout,
1043 .extra1 = SYSCTL_ZERO,
1045 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1047 .procname = "fib_multipath_use_neigh",
1048 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1049 .maxlen = sizeof(u8),
1051 .proc_handler = proc_dou8vec_minmax,
1052 .extra1 = SYSCTL_ZERO,
1053 .extra2 = SYSCTL_ONE,
1056 .procname = "fib_multipath_hash_policy",
1057 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1058 .maxlen = sizeof(u8),
1060 .proc_handler = proc_fib_multipath_hash_policy,
1061 .extra1 = SYSCTL_ZERO,
1065 .procname = "fib_multipath_hash_fields",
1066 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1067 .maxlen = sizeof(u32),
1069 .proc_handler = proc_fib_multipath_hash_fields,
1070 .extra1 = SYSCTL_ONE,
1071 .extra2 = &fib_multipath_hash_fields_all_mask,
1075 .procname = "ip_unprivileged_port_start",
1076 .maxlen = sizeof(int),
1077 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1079 .proc_handler = ipv4_privileged_ports,
1081 #ifdef CONFIG_NET_L3_MASTER_DEV
1083 .procname = "udp_l3mdev_accept",
1084 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1085 .maxlen = sizeof(u8),
1087 .proc_handler = proc_dou8vec_minmax,
1088 .extra1 = SYSCTL_ZERO,
1089 .extra2 = SYSCTL_ONE,
1093 .procname = "tcp_sack",
1094 .data = &init_net.ipv4.sysctl_tcp_sack,
1095 .maxlen = sizeof(u8),
1097 .proc_handler = proc_dou8vec_minmax,
1100 .procname = "tcp_window_scaling",
1101 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1102 .maxlen = sizeof(u8),
1104 .proc_handler = proc_dou8vec_minmax,
1107 .procname = "tcp_timestamps",
1108 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1109 .maxlen = sizeof(u8),
1111 .proc_handler = proc_dou8vec_minmax,
1114 .procname = "tcp_early_retrans",
1115 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1116 .maxlen = sizeof(u8),
1118 .proc_handler = proc_dou8vec_minmax,
1119 .extra1 = SYSCTL_ZERO,
1123 .procname = "tcp_recovery",
1124 .data = &init_net.ipv4.sysctl_tcp_recovery,
1125 .maxlen = sizeof(u8),
1127 .proc_handler = proc_dou8vec_minmax,
1130 .procname = "tcp_thin_linear_timeouts",
1131 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1132 .maxlen = sizeof(u8),
1134 .proc_handler = proc_dou8vec_minmax,
1137 .procname = "tcp_slow_start_after_idle",
1138 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1139 .maxlen = sizeof(u8),
1141 .proc_handler = proc_dou8vec_minmax,
1144 .procname = "tcp_retrans_collapse",
1145 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1146 .maxlen = sizeof(u8),
1148 .proc_handler = proc_dou8vec_minmax,
1151 .procname = "tcp_stdurg",
1152 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1153 .maxlen = sizeof(u8),
1155 .proc_handler = proc_dou8vec_minmax,
1158 .procname = "tcp_rfc1337",
1159 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1160 .maxlen = sizeof(u8),
1162 .proc_handler = proc_dou8vec_minmax,
1165 .procname = "tcp_abort_on_overflow",
1166 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1167 .maxlen = sizeof(u8),
1169 .proc_handler = proc_dou8vec_minmax,
1172 .procname = "tcp_fack",
1173 .data = &init_net.ipv4.sysctl_tcp_fack,
1174 .maxlen = sizeof(u8),
1176 .proc_handler = proc_dou8vec_minmax,
1179 .procname = "tcp_max_reordering",
1180 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1181 .maxlen = sizeof(int),
1183 .proc_handler = proc_dointvec
1186 .procname = "tcp_dsack",
1187 .data = &init_net.ipv4.sysctl_tcp_dsack,
1188 .maxlen = sizeof(u8),
1190 .proc_handler = proc_dou8vec_minmax,
1193 .procname = "tcp_app_win",
1194 .data = &init_net.ipv4.sysctl_tcp_app_win,
1195 .maxlen = sizeof(u8),
1197 .proc_handler = proc_dou8vec_minmax,
1200 .procname = "tcp_adv_win_scale",
1201 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1202 .maxlen = sizeof(int),
1204 .proc_handler = proc_dointvec_minmax,
1205 .extra1 = &tcp_adv_win_scale_min,
1206 .extra2 = &tcp_adv_win_scale_max,
1209 .procname = "tcp_frto",
1210 .data = &init_net.ipv4.sysctl_tcp_frto,
1211 .maxlen = sizeof(u8),
1213 .proc_handler = proc_dou8vec_minmax,
1216 .procname = "tcp_no_metrics_save",
1217 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1218 .maxlen = sizeof(u8),
1220 .proc_handler = proc_dou8vec_minmax,
1223 .procname = "tcp_no_ssthresh_metrics_save",
1224 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1225 .maxlen = sizeof(u8),
1227 .proc_handler = proc_dou8vec_minmax,
1228 .extra1 = SYSCTL_ZERO,
1229 .extra2 = SYSCTL_ONE,
1232 .procname = "tcp_moderate_rcvbuf",
1233 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1234 .maxlen = sizeof(u8),
1236 .proc_handler = proc_dou8vec_minmax,
1239 .procname = "tcp_tso_win_divisor",
1240 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1241 .maxlen = sizeof(u8),
1243 .proc_handler = proc_dou8vec_minmax,
1246 .procname = "tcp_workaround_signed_windows",
1247 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1248 .maxlen = sizeof(u8),
1250 .proc_handler = proc_dou8vec_minmax,
1253 .procname = "tcp_limit_output_bytes",
1254 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1255 .maxlen = sizeof(int),
1257 .proc_handler = proc_dointvec
1260 .procname = "tcp_challenge_ack_limit",
1261 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1262 .maxlen = sizeof(int),
1264 .proc_handler = proc_dointvec
1267 .procname = "tcp_min_tso_segs",
1268 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1269 .maxlen = sizeof(u8),
1271 .proc_handler = proc_dou8vec_minmax,
1272 .extra1 = SYSCTL_ONE,
1275 .procname = "tcp_min_rtt_wlen",
1276 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1277 .maxlen = sizeof(int),
1279 .proc_handler = proc_dointvec_minmax,
1280 .extra1 = SYSCTL_ZERO,
1281 .extra2 = &one_day_secs
1284 .procname = "tcp_autocorking",
1285 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1286 .maxlen = sizeof(u8),
1288 .proc_handler = proc_dou8vec_minmax,
1289 .extra1 = SYSCTL_ZERO,
1290 .extra2 = SYSCTL_ONE,
1293 .procname = "tcp_invalid_ratelimit",
1294 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1295 .maxlen = sizeof(int),
1297 .proc_handler = proc_dointvec_ms_jiffies,
1300 .procname = "tcp_pacing_ss_ratio",
1301 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1302 .maxlen = sizeof(int),
1304 .proc_handler = proc_dointvec_minmax,
1305 .extra1 = SYSCTL_ZERO,
1306 .extra2 = &thousand,
1309 .procname = "tcp_pacing_ca_ratio",
1310 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1311 .maxlen = sizeof(int),
1313 .proc_handler = proc_dointvec_minmax,
1314 .extra1 = SYSCTL_ZERO,
1315 .extra2 = &thousand,
1318 .procname = "tcp_wmem",
1319 .data = &init_net.ipv4.sysctl_tcp_wmem,
1320 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1322 .proc_handler = proc_dointvec_minmax,
1323 .extra1 = SYSCTL_ONE,
1326 .procname = "tcp_rmem",
1327 .data = &init_net.ipv4.sysctl_tcp_rmem,
1328 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1330 .proc_handler = proc_dointvec_minmax,
1331 .extra1 = SYSCTL_ONE,
1334 .procname = "tcp_comp_sack_delay_ns",
1335 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1336 .maxlen = sizeof(unsigned long),
1338 .proc_handler = proc_doulongvec_minmax,
1341 .procname = "tcp_comp_sack_slack_ns",
1342 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1343 .maxlen = sizeof(unsigned long),
1345 .proc_handler = proc_doulongvec_minmax,
1348 .procname = "tcp_comp_sack_nr",
1349 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1350 .maxlen = sizeof(u8),
1352 .proc_handler = proc_dou8vec_minmax,
1353 .extra1 = SYSCTL_ZERO,
1356 .procname = "tcp_reflect_tos",
1357 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1358 .maxlen = sizeof(u8),
1360 .proc_handler = proc_dou8vec_minmax,
1361 .extra1 = SYSCTL_ZERO,
1362 .extra2 = SYSCTL_ONE,
1365 .procname = "udp_rmem_min",
1366 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1367 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1369 .proc_handler = proc_dointvec_minmax,
1370 .extra1 = SYSCTL_ONE
1373 .procname = "udp_wmem_min",
1374 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1375 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1377 .proc_handler = proc_dointvec_minmax,
1378 .extra1 = SYSCTL_ONE
1381 .procname = "fib_notify_on_flag_change",
1382 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1383 .maxlen = sizeof(u8),
1385 .proc_handler = proc_dou8vec_minmax,
1386 .extra1 = SYSCTL_ZERO,
1392 static __net_init int ipv4_sysctl_init_net(struct net *net)
1394 struct ctl_table *table;
1396 table = ipv4_net_table;
1397 if (!net_eq(net, &init_net)) {
1400 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1404 /* skip first entry (sysctl_max_tw_buckets) */
1405 for (i = 1; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1406 if (table[i].data) {
1407 /* Update the variables to point into
1408 * the current struct net
1410 table[i].data += (void *)net - (void *)&init_net;
1412 /* Entries without data pointer are global;
1413 * Make them read-only in non-init_net ns
1415 table[i].mode &= ~0222;
1420 table[0].data = &net->ipv4.tcp_death_row->sysctl_max_tw_buckets;
1422 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1423 if (!net->ipv4.ipv4_hdr)
1426 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1427 if (!net->ipv4.sysctl_local_reserved_ports)
1433 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1435 if (!net_eq(net, &init_net))
1441 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1443 struct ctl_table *table;
1445 kfree(net->ipv4.sysctl_local_reserved_ports);
1446 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1447 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1451 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1452 .init = ipv4_sysctl_init_net,
1453 .exit = ipv4_sysctl_exit_net,
1456 static __init int sysctl_ipv4_init(void)
1458 struct ctl_table_header *hdr;
1460 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1464 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1465 unregister_net_sysctl_table(hdr);
1472 __initcall(sysctl_ipv4_init);