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>
23 static int tcp_retr1_max = 255;
24 static int ip_local_port_range_min[] = { 1, 1 };
25 static int ip_local_port_range_max[] = { 65535, 65535 };
26 static int tcp_adv_win_scale_min = -31;
27 static int tcp_adv_win_scale_max = 31;
28 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
29 static int tcp_min_snd_mss_max = 65535;
30 static int ip_privileged_port_min;
31 static int ip_privileged_port_max = 65535;
32 static int ip_ttl_min = 1;
33 static int ip_ttl_max = 255;
34 static int tcp_syn_retries_min = 1;
35 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
36 static int ip_ping_group_range_min[] = { 0, 0 };
37 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
38 static u32 u32_max_div_HZ = UINT_MAX / HZ;
39 static int one_day_secs = 24 * 3600;
40 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
41 FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
44 static int sysctl_tcp_low_latency __read_mostly;
46 /* Update system visible IP port range */
47 static void set_local_port_range(struct net *net, int range[2])
49 bool same_parity = !((range[0] ^ range[1]) & 1);
51 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
52 if (same_parity && !net->ipv4.ip_local_ports.warned) {
53 net->ipv4.ip_local_ports.warned = true;
54 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
56 net->ipv4.ip_local_ports.range[0] = range[0];
57 net->ipv4.ip_local_ports.range[1] = range[1];
58 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
61 /* Validate changes from /proc interface. */
62 static int ipv4_local_port_range(struct ctl_table *table, int write,
63 void *buffer, size_t *lenp, loff_t *ppos)
66 container_of(table->data, struct net, ipv4.ip_local_ports.range);
69 struct ctl_table tmp = {
71 .maxlen = sizeof(range),
73 .extra1 = &ip_local_port_range_min,
74 .extra2 = &ip_local_port_range_max,
77 inet_get_local_port_range(net, &range[0], &range[1]);
79 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
81 if (write && ret == 0) {
82 /* Ensure that the upper limit is not smaller than the lower,
83 * and that the lower does not encroach upon the privileged
86 if ((range[1] < range[0]) ||
87 (range[0] < net->ipv4.sysctl_ip_prot_sock))
90 set_local_port_range(net, range);
96 /* Validate changes from /proc interface. */
97 static int ipv4_privileged_ports(struct ctl_table *table, int write,
98 void *buffer, size_t *lenp, loff_t *ppos)
100 struct net *net = container_of(table->data, struct net,
101 ipv4.sysctl_ip_prot_sock);
105 struct ctl_table tmp = {
107 .maxlen = sizeof(pports),
109 .extra1 = &ip_privileged_port_min,
110 .extra2 = &ip_privileged_port_max,
113 pports = net->ipv4.sysctl_ip_prot_sock;
115 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
117 if (write && ret == 0) {
118 inet_get_local_port_range(net, &range[0], &range[1]);
119 /* Ensure that the local port range doesn't overlap with the
120 * privileged port range.
122 if (range[0] < pports)
125 net->ipv4.sysctl_ip_prot_sock = pports;
131 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
133 kgid_t *data = table->data;
135 container_of(table->data, struct net, ipv4.ping_group_range.range);
138 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
142 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
145 /* Update system visible IP port range */
146 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
148 kgid_t *data = table->data;
150 container_of(table->data, struct net, ipv4.ping_group_range.range);
151 write_seqlock(&net->ipv4.ping_group_range.lock);
154 write_sequnlock(&net->ipv4.ping_group_range.lock);
157 /* Validate changes from /proc interface. */
158 static int ipv4_ping_group_range(struct ctl_table *table, int write,
159 void *buffer, size_t *lenp, loff_t *ppos)
161 struct user_namespace *user_ns = current_user_ns();
165 struct ctl_table tmp = {
167 .maxlen = sizeof(urange),
169 .extra1 = &ip_ping_group_range_min,
170 .extra2 = &ip_ping_group_range_max,
173 inet_get_ping_group_range_table(table, &low, &high);
174 urange[0] = from_kgid_munged(user_ns, low);
175 urange[1] = from_kgid_munged(user_ns, high);
176 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
178 if (write && ret == 0) {
179 low = make_kgid(user_ns, urange[0]);
180 high = make_kgid(user_ns, urange[1]);
181 if (!gid_valid(low) || !gid_valid(high))
183 if (urange[1] < urange[0] || gid_lt(high, low)) {
184 low = make_kgid(&init_user_ns, 1);
185 high = make_kgid(&init_user_ns, 0);
187 set_ping_group_range(table, low, high);
193 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
194 void *buffer, size_t *lenp, loff_t *ppos)
199 net = container_of(table->data, struct net,
200 ipv4.sysctl_ip_fwd_update_priority);
201 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
202 if (write && ret == 0)
203 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
209 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
210 void *buffer, size_t *lenp, loff_t *ppos)
212 struct net *net = container_of(ctl->data, struct net,
213 ipv4.tcp_congestion_control);
214 char val[TCP_CA_NAME_MAX];
215 struct ctl_table tbl = {
217 .maxlen = TCP_CA_NAME_MAX,
221 tcp_get_default_congestion_control(net, val);
223 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
224 if (write && ret == 0)
225 ret = tcp_set_default_congestion_control(net, val);
229 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
230 int write, void *buffer,
231 size_t *lenp, loff_t *ppos)
233 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
236 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
239 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
240 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
245 static int proc_allowed_congestion_control(struct ctl_table *ctl,
246 int write, void *buffer,
247 size_t *lenp, loff_t *ppos)
249 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
252 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
256 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
257 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
258 if (write && ret == 0)
259 ret = tcp_set_allowed_congestion_control(tbl.data);
264 static int sscanf_key(char *buf, __le32 *key)
269 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
270 user_key + 2, user_key + 3) != 4) {
273 for (i = 0; i < ARRAY_SIZE(user_key); i++)
274 key[i] = cpu_to_le32(user_key[i]);
276 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
277 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
282 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
283 void *buffer, size_t *lenp, loff_t *ppos)
285 struct net *net = container_of(table->data, struct net,
286 ipv4.sysctl_tcp_fastopen);
287 /* maxlen to print the list of keys in hex (*2), with dashes
288 * separating doublewords and a comma in between keys.
290 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
291 2 * TCP_FASTOPEN_KEY_MAX) +
292 (TCP_FASTOPEN_KEY_MAX * 5)) };
293 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
294 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
296 int ret, i = 0, off = 0, n_keys;
298 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
302 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
304 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
308 for (i = 0; i < n_keys * 4; i++)
309 user_key[i] = le32_to_cpu(key[i]);
311 for (i = 0; i < n_keys; i++) {
312 off += snprintf(tbl.data + off, tbl.maxlen - off,
313 "%08x-%08x-%08x-%08x",
317 user_key[i * 4 + 3]);
319 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
323 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
326 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
328 if (write && ret == 0) {
329 backup_data = strchr(tbl.data, ',');
334 if (sscanf_key(tbl.data, key)) {
339 if (sscanf_key(backup_data, key + 4)) {
344 tcp_fastopen_reset_cipher(net, NULL, key,
345 backup_data ? key + 4 : NULL);
353 static void proc_configure_early_demux(int enabled, int protocol)
355 struct net_protocol *ipprot;
356 #if IS_ENABLED(CONFIG_IPV6)
357 struct inet6_protocol *ip6prot;
362 ipprot = rcu_dereference(inet_protos[protocol]);
364 ipprot->early_demux = enabled ? ipprot->early_demux_handler :
367 #if IS_ENABLED(CONFIG_IPV6)
368 ip6prot = rcu_dereference(inet6_protos[protocol]);
370 ip6prot->early_demux = enabled ? ip6prot->early_demux_handler :
376 static int proc_tcp_early_demux(struct ctl_table *table, int write,
377 void *buffer, size_t *lenp, loff_t *ppos)
381 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
384 int enabled = init_net.ipv4.sysctl_tcp_early_demux;
386 proc_configure_early_demux(enabled, IPPROTO_TCP);
392 static int proc_udp_early_demux(struct ctl_table *table, int write,
393 void *buffer, size_t *lenp, loff_t *ppos)
397 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
400 int enabled = init_net.ipv4.sysctl_udp_early_demux;
402 proc_configure_early_demux(enabled, IPPROTO_UDP);
408 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
409 int write, void *buffer,
410 size_t *lenp, loff_t *ppos)
412 struct net *net = container_of(table->data, struct net,
413 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
416 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
417 if (write && ret == 0)
418 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
423 static int proc_tcp_available_ulp(struct ctl_table *ctl,
424 int write, void *buffer, size_t *lenp,
427 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
430 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
433 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
434 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
440 #ifdef CONFIG_IP_ROUTE_MULTIPATH
441 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
442 void *buffer, size_t *lenp,
445 struct net *net = container_of(table->data, struct net,
446 ipv4.sysctl_fib_multipath_hash_policy);
449 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
450 if (write && ret == 0)
451 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
456 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
457 void *buffer, size_t *lenp,
463 net = container_of(table->data, struct net,
464 ipv4.sysctl_fib_multipath_hash_fields);
465 ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
466 if (write && ret == 0)
467 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
473 static struct ctl_table ipv4_table[] = {
475 .procname = "tcp_max_orphans",
476 .data = &sysctl_tcp_max_orphans,
477 .maxlen = sizeof(int),
479 .proc_handler = proc_dointvec
482 .procname = "inet_peer_threshold",
483 .data = &inet_peer_threshold,
484 .maxlen = sizeof(int),
486 .proc_handler = proc_dointvec
489 .procname = "inet_peer_minttl",
490 .data = &inet_peer_minttl,
491 .maxlen = sizeof(int),
493 .proc_handler = proc_dointvec_jiffies,
496 .procname = "inet_peer_maxttl",
497 .data = &inet_peer_maxttl,
498 .maxlen = sizeof(int),
500 .proc_handler = proc_dointvec_jiffies,
503 .procname = "tcp_mem",
504 .maxlen = sizeof(sysctl_tcp_mem),
505 .data = &sysctl_tcp_mem,
507 .proc_handler = proc_doulongvec_minmax,
510 .procname = "tcp_low_latency",
511 .data = &sysctl_tcp_low_latency,
512 .maxlen = sizeof(int),
514 .proc_handler = proc_dointvec
516 #ifdef CONFIG_NETLABEL
518 .procname = "cipso_cache_enable",
519 .data = &cipso_v4_cache_enabled,
520 .maxlen = sizeof(int),
522 .proc_handler = proc_dointvec,
525 .procname = "cipso_cache_bucket_size",
526 .data = &cipso_v4_cache_bucketsize,
527 .maxlen = sizeof(int),
529 .proc_handler = proc_dointvec,
532 .procname = "cipso_rbm_optfmt",
533 .data = &cipso_v4_rbm_optfmt,
534 .maxlen = sizeof(int),
536 .proc_handler = proc_dointvec,
539 .procname = "cipso_rbm_strictvalid",
540 .data = &cipso_v4_rbm_strictvalid,
541 .maxlen = sizeof(int),
543 .proc_handler = proc_dointvec,
545 #endif /* CONFIG_NETLABEL */
547 .procname = "tcp_available_ulp",
548 .maxlen = TCP_ULP_BUF_MAX,
550 .proc_handler = proc_tcp_available_ulp,
553 .procname = "icmp_msgs_per_sec",
554 .data = &sysctl_icmp_msgs_per_sec,
555 .maxlen = sizeof(int),
557 .proc_handler = proc_dointvec_minmax,
558 .extra1 = SYSCTL_ZERO,
561 .procname = "icmp_msgs_burst",
562 .data = &sysctl_icmp_msgs_burst,
563 .maxlen = sizeof(int),
565 .proc_handler = proc_dointvec_minmax,
566 .extra1 = SYSCTL_ZERO,
569 .procname = "udp_mem",
570 .data = &sysctl_udp_mem,
571 .maxlen = sizeof(sysctl_udp_mem),
573 .proc_handler = proc_doulongvec_minmax,
576 .procname = "fib_sync_mem",
577 .data = &sysctl_fib_sync_mem,
578 .maxlen = sizeof(sysctl_fib_sync_mem),
580 .proc_handler = proc_douintvec_minmax,
581 .extra1 = &sysctl_fib_sync_mem_min,
582 .extra2 = &sysctl_fib_sync_mem_max,
587 static struct ctl_table ipv4_net_table[] = {
588 /* tcp_max_tw_buckets must be first in this table. */
590 .procname = "tcp_max_tw_buckets",
591 /* .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets, */
592 .maxlen = sizeof(int),
594 .proc_handler = proc_dointvec
597 .procname = "icmp_echo_ignore_all",
598 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
599 .maxlen = sizeof(u8),
601 .proc_handler = proc_dou8vec_minmax,
602 .extra1 = SYSCTL_ZERO,
606 .procname = "icmp_echo_enable_probe",
607 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
608 .maxlen = sizeof(u8),
610 .proc_handler = proc_dou8vec_minmax,
611 .extra1 = SYSCTL_ZERO,
615 .procname = "icmp_echo_ignore_broadcasts",
616 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
617 .maxlen = sizeof(u8),
619 .proc_handler = proc_dou8vec_minmax,
620 .extra1 = SYSCTL_ZERO,
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,
629 .extra1 = SYSCTL_ZERO,
633 .procname = "icmp_errors_use_inbound_ifaddr",
634 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
635 .maxlen = sizeof(u8),
637 .proc_handler = proc_dou8vec_minmax,
638 .extra1 = SYSCTL_ZERO,
642 .procname = "icmp_ratelimit",
643 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
644 .maxlen = sizeof(int),
646 .proc_handler = proc_dointvec_ms_jiffies,
649 .procname = "icmp_ratemask",
650 .data = &init_net.ipv4.sysctl_icmp_ratemask,
651 .maxlen = sizeof(int),
653 .proc_handler = proc_dointvec
656 .procname = "ping_group_range",
657 .data = &init_net.ipv4.ping_group_range.range,
658 .maxlen = sizeof(gid_t)*2,
660 .proc_handler = ipv4_ping_group_range,
662 #ifdef CONFIG_NET_L3_MASTER_DEV
664 .procname = "raw_l3mdev_accept",
665 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
666 .maxlen = sizeof(u8),
668 .proc_handler = proc_dou8vec_minmax,
669 .extra1 = SYSCTL_ZERO,
670 .extra2 = SYSCTL_ONE,
674 .procname = "tcp_ecn",
675 .data = &init_net.ipv4.sysctl_tcp_ecn,
676 .maxlen = sizeof(u8),
678 .proc_handler = proc_dou8vec_minmax,
679 .extra1 = SYSCTL_ZERO,
680 .extra2 = SYSCTL_TWO,
683 .procname = "tcp_ecn_fallback",
684 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
685 .maxlen = sizeof(u8),
687 .proc_handler = proc_dou8vec_minmax,
688 .extra1 = SYSCTL_ZERO,
689 .extra2 = SYSCTL_ONE,
692 .procname = "ip_dynaddr",
693 .data = &init_net.ipv4.sysctl_ip_dynaddr,
694 .maxlen = sizeof(u8),
696 .proc_handler = proc_dou8vec_minmax,
699 .procname = "ip_early_demux",
700 .data = &init_net.ipv4.sysctl_ip_early_demux,
701 .maxlen = sizeof(u8),
703 .proc_handler = proc_dou8vec_minmax,
706 .procname = "udp_early_demux",
707 .data = &init_net.ipv4.sysctl_udp_early_demux,
708 .maxlen = sizeof(u8),
710 .proc_handler = proc_udp_early_demux
713 .procname = "tcp_early_demux",
714 .data = &init_net.ipv4.sysctl_tcp_early_demux,
715 .maxlen = sizeof(u8),
717 .proc_handler = proc_tcp_early_demux
720 .procname = "nexthop_compat_mode",
721 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
722 .maxlen = sizeof(u8),
724 .proc_handler = proc_dou8vec_minmax,
725 .extra1 = SYSCTL_ZERO,
726 .extra2 = SYSCTL_ONE,
729 .procname = "ip_default_ttl",
730 .data = &init_net.ipv4.sysctl_ip_default_ttl,
731 .maxlen = sizeof(u8),
733 .proc_handler = proc_dou8vec_minmax,
734 .extra1 = &ip_ttl_min,
735 .extra2 = &ip_ttl_max,
738 .procname = "ip_local_port_range",
739 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
740 .data = &init_net.ipv4.ip_local_ports.range,
742 .proc_handler = ipv4_local_port_range,
745 .procname = "ip_local_reserved_ports",
746 .data = &init_net.ipv4.sysctl_local_reserved_ports,
749 .proc_handler = proc_do_large_bitmap,
752 .procname = "ip_no_pmtu_disc",
753 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
754 .maxlen = sizeof(u8),
756 .proc_handler = proc_dou8vec_minmax,
759 .procname = "ip_forward_use_pmtu",
760 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
761 .maxlen = sizeof(u8),
763 .proc_handler = proc_dou8vec_minmax,
766 .procname = "ip_forward_update_priority",
767 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
768 .maxlen = sizeof(u8),
770 .proc_handler = ipv4_fwd_update_priority,
771 .extra1 = SYSCTL_ZERO,
772 .extra2 = SYSCTL_ONE,
775 .procname = "ip_nonlocal_bind",
776 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
777 .maxlen = sizeof(u8),
779 .proc_handler = proc_dou8vec_minmax,
782 .procname = "ip_autobind_reuse",
783 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
784 .maxlen = sizeof(u8),
786 .proc_handler = proc_dou8vec_minmax,
787 .extra1 = SYSCTL_ZERO,
788 .extra2 = SYSCTL_ONE,
791 .procname = "fwmark_reflect",
792 .data = &init_net.ipv4.sysctl_fwmark_reflect,
793 .maxlen = sizeof(u8),
795 .proc_handler = proc_dou8vec_minmax,
798 .procname = "tcp_fwmark_accept",
799 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
800 .maxlen = sizeof(u8),
802 .proc_handler = proc_dou8vec_minmax,
804 #ifdef CONFIG_NET_L3_MASTER_DEV
806 .procname = "tcp_l3mdev_accept",
807 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
808 .maxlen = sizeof(u8),
810 .proc_handler = proc_dou8vec_minmax,
811 .extra1 = SYSCTL_ZERO,
812 .extra2 = SYSCTL_ONE,
816 .procname = "tcp_mtu_probing",
817 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
818 .maxlen = sizeof(u8),
820 .proc_handler = proc_dou8vec_minmax,
823 .procname = "tcp_base_mss",
824 .data = &init_net.ipv4.sysctl_tcp_base_mss,
825 .maxlen = sizeof(int),
827 .proc_handler = proc_dointvec,
830 .procname = "tcp_min_snd_mss",
831 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
832 .maxlen = sizeof(int),
834 .proc_handler = proc_dointvec_minmax,
835 .extra1 = &tcp_min_snd_mss_min,
836 .extra2 = &tcp_min_snd_mss_max,
839 .procname = "tcp_mtu_probe_floor",
840 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
841 .maxlen = sizeof(int),
843 .proc_handler = proc_dointvec_minmax,
844 .extra1 = &tcp_min_snd_mss_min,
845 .extra2 = &tcp_min_snd_mss_max,
848 .procname = "tcp_probe_threshold",
849 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
850 .maxlen = sizeof(int),
852 .proc_handler = proc_dointvec,
855 .procname = "tcp_probe_interval",
856 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
857 .maxlen = sizeof(u32),
859 .proc_handler = proc_douintvec_minmax,
860 .extra2 = &u32_max_div_HZ,
863 .procname = "igmp_link_local_mcast_reports",
864 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
865 .maxlen = sizeof(u8),
867 .proc_handler = proc_dou8vec_minmax,
870 .procname = "igmp_max_memberships",
871 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec
877 .procname = "igmp_max_msf",
878 .data = &init_net.ipv4.sysctl_igmp_max_msf,
879 .maxlen = sizeof(int),
881 .proc_handler = proc_dointvec
883 #ifdef CONFIG_IP_MULTICAST
885 .procname = "igmp_qrv",
886 .data = &init_net.ipv4.sysctl_igmp_qrv,
887 .maxlen = sizeof(int),
889 .proc_handler = proc_dointvec_minmax,
894 .procname = "tcp_congestion_control",
895 .data = &init_net.ipv4.tcp_congestion_control,
897 .maxlen = TCP_CA_NAME_MAX,
898 .proc_handler = proc_tcp_congestion_control,
901 .procname = "tcp_available_congestion_control",
902 .maxlen = TCP_CA_BUF_MAX,
904 .proc_handler = proc_tcp_available_congestion_control,
907 .procname = "tcp_allowed_congestion_control",
908 .maxlen = TCP_CA_BUF_MAX,
910 .proc_handler = proc_allowed_congestion_control,
913 .procname = "tcp_keepalive_time",
914 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
915 .maxlen = sizeof(int),
917 .proc_handler = proc_dointvec_jiffies,
920 .procname = "tcp_keepalive_probes",
921 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
922 .maxlen = sizeof(u8),
924 .proc_handler = proc_dou8vec_minmax,
927 .procname = "tcp_keepalive_intvl",
928 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
929 .maxlen = sizeof(int),
931 .proc_handler = proc_dointvec_jiffies,
934 .procname = "tcp_syn_retries",
935 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
936 .maxlen = sizeof(u8),
938 .proc_handler = proc_dou8vec_minmax,
939 .extra1 = &tcp_syn_retries_min,
940 .extra2 = &tcp_syn_retries_max
943 .procname = "tcp_synack_retries",
944 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
945 .maxlen = sizeof(u8),
947 .proc_handler = proc_dou8vec_minmax,
949 #ifdef CONFIG_SYN_COOKIES
951 .procname = "tcp_syncookies",
952 .data = &init_net.ipv4.sysctl_tcp_syncookies,
953 .maxlen = sizeof(u8),
955 .proc_handler = proc_dou8vec_minmax,
959 .procname = "tcp_migrate_req",
960 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
961 .maxlen = sizeof(u8),
963 .proc_handler = proc_dou8vec_minmax,
964 .extra1 = SYSCTL_ZERO,
968 .procname = "tcp_reordering",
969 .data = &init_net.ipv4.sysctl_tcp_reordering,
970 .maxlen = sizeof(int),
972 .proc_handler = proc_dointvec
975 .procname = "tcp_retries1",
976 .data = &init_net.ipv4.sysctl_tcp_retries1,
977 .maxlen = sizeof(u8),
979 .proc_handler = proc_dou8vec_minmax,
980 .extra2 = &tcp_retr1_max
983 .procname = "tcp_retries2",
984 .data = &init_net.ipv4.sysctl_tcp_retries2,
985 .maxlen = sizeof(u8),
987 .proc_handler = proc_dou8vec_minmax,
990 .procname = "tcp_orphan_retries",
991 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
992 .maxlen = sizeof(u8),
994 .proc_handler = proc_dou8vec_minmax,
997 .procname = "tcp_fin_timeout",
998 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
999 .maxlen = sizeof(int),
1001 .proc_handler = proc_dointvec_jiffies,
1004 .procname = "tcp_notsent_lowat",
1005 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
1006 .maxlen = sizeof(unsigned int),
1008 .proc_handler = proc_douintvec,
1011 .procname = "tcp_tw_reuse",
1012 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
1013 .maxlen = sizeof(u8),
1015 .proc_handler = proc_dou8vec_minmax,
1016 .extra1 = SYSCTL_ZERO,
1017 .extra2 = SYSCTL_TWO,
1020 .procname = "tcp_max_syn_backlog",
1021 .data = &init_net.ipv4.sysctl_max_syn_backlog,
1022 .maxlen = sizeof(int),
1024 .proc_handler = proc_dointvec
1027 .procname = "tcp_fastopen",
1028 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1029 .maxlen = sizeof(int),
1031 .proc_handler = proc_dointvec,
1034 .procname = "tcp_fastopen_key",
1036 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1037 /* maxlen to print the list of keys in hex (*2), with dashes
1038 * separating doublewords and a comma in between keys.
1040 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1041 2 * TCP_FASTOPEN_KEY_MAX) +
1042 (TCP_FASTOPEN_KEY_MAX * 5)),
1043 .proc_handler = proc_tcp_fastopen_key,
1046 .procname = "tcp_fastopen_blackhole_timeout_sec",
1047 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1048 .maxlen = sizeof(int),
1050 .proc_handler = proc_tfo_blackhole_detect_timeout,
1051 .extra1 = SYSCTL_ZERO,
1053 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1055 .procname = "fib_multipath_use_neigh",
1056 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1057 .maxlen = sizeof(u8),
1059 .proc_handler = proc_dou8vec_minmax,
1060 .extra1 = SYSCTL_ZERO,
1061 .extra2 = SYSCTL_ONE,
1064 .procname = "fib_multipath_hash_policy",
1065 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1066 .maxlen = sizeof(u8),
1068 .proc_handler = proc_fib_multipath_hash_policy,
1069 .extra1 = SYSCTL_ZERO,
1070 .extra2 = SYSCTL_THREE,
1073 .procname = "fib_multipath_hash_fields",
1074 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1075 .maxlen = sizeof(u32),
1077 .proc_handler = proc_fib_multipath_hash_fields,
1078 .extra1 = SYSCTL_ONE,
1079 .extra2 = &fib_multipath_hash_fields_all_mask,
1083 .procname = "ip_unprivileged_port_start",
1084 .maxlen = sizeof(int),
1085 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1087 .proc_handler = ipv4_privileged_ports,
1089 #ifdef CONFIG_NET_L3_MASTER_DEV
1091 .procname = "udp_l3mdev_accept",
1092 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1093 .maxlen = sizeof(u8),
1095 .proc_handler = proc_dou8vec_minmax,
1096 .extra1 = SYSCTL_ZERO,
1097 .extra2 = SYSCTL_ONE,
1101 .procname = "tcp_sack",
1102 .data = &init_net.ipv4.sysctl_tcp_sack,
1103 .maxlen = sizeof(u8),
1105 .proc_handler = proc_dou8vec_minmax,
1108 .procname = "tcp_window_scaling",
1109 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1110 .maxlen = sizeof(u8),
1112 .proc_handler = proc_dou8vec_minmax,
1115 .procname = "tcp_timestamps",
1116 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1117 .maxlen = sizeof(u8),
1119 .proc_handler = proc_dou8vec_minmax,
1122 .procname = "tcp_early_retrans",
1123 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1124 .maxlen = sizeof(u8),
1126 .proc_handler = proc_dou8vec_minmax,
1127 .extra1 = SYSCTL_ZERO,
1128 .extra2 = SYSCTL_FOUR,
1131 .procname = "tcp_recovery",
1132 .data = &init_net.ipv4.sysctl_tcp_recovery,
1133 .maxlen = sizeof(u8),
1135 .proc_handler = proc_dou8vec_minmax,
1138 .procname = "tcp_thin_linear_timeouts",
1139 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1140 .maxlen = sizeof(u8),
1142 .proc_handler = proc_dou8vec_minmax,
1145 .procname = "tcp_slow_start_after_idle",
1146 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1147 .maxlen = sizeof(u8),
1149 .proc_handler = proc_dou8vec_minmax,
1152 .procname = "tcp_retrans_collapse",
1153 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1154 .maxlen = sizeof(u8),
1156 .proc_handler = proc_dou8vec_minmax,
1159 .procname = "tcp_stdurg",
1160 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1161 .maxlen = sizeof(u8),
1163 .proc_handler = proc_dou8vec_minmax,
1166 .procname = "tcp_rfc1337",
1167 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1168 .maxlen = sizeof(u8),
1170 .proc_handler = proc_dou8vec_minmax,
1173 .procname = "tcp_abort_on_overflow",
1174 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1175 .maxlen = sizeof(u8),
1177 .proc_handler = proc_dou8vec_minmax,
1180 .procname = "tcp_fack",
1181 .data = &init_net.ipv4.sysctl_tcp_fack,
1182 .maxlen = sizeof(u8),
1184 .proc_handler = proc_dou8vec_minmax,
1187 .procname = "tcp_max_reordering",
1188 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1189 .maxlen = sizeof(int),
1191 .proc_handler = proc_dointvec
1194 .procname = "tcp_dsack",
1195 .data = &init_net.ipv4.sysctl_tcp_dsack,
1196 .maxlen = sizeof(u8),
1198 .proc_handler = proc_dou8vec_minmax,
1201 .procname = "tcp_app_win",
1202 .data = &init_net.ipv4.sysctl_tcp_app_win,
1203 .maxlen = sizeof(u8),
1205 .proc_handler = proc_dou8vec_minmax,
1208 .procname = "tcp_adv_win_scale",
1209 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1210 .maxlen = sizeof(int),
1212 .proc_handler = proc_dointvec_minmax,
1213 .extra1 = &tcp_adv_win_scale_min,
1214 .extra2 = &tcp_adv_win_scale_max,
1217 .procname = "tcp_frto",
1218 .data = &init_net.ipv4.sysctl_tcp_frto,
1219 .maxlen = sizeof(u8),
1221 .proc_handler = proc_dou8vec_minmax,
1224 .procname = "tcp_no_metrics_save",
1225 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1226 .maxlen = sizeof(u8),
1228 .proc_handler = proc_dou8vec_minmax,
1231 .procname = "tcp_no_ssthresh_metrics_save",
1232 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1233 .maxlen = sizeof(u8),
1235 .proc_handler = proc_dou8vec_minmax,
1236 .extra1 = SYSCTL_ZERO,
1237 .extra2 = SYSCTL_ONE,
1240 .procname = "tcp_moderate_rcvbuf",
1241 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1242 .maxlen = sizeof(u8),
1244 .proc_handler = proc_dou8vec_minmax,
1247 .procname = "tcp_tso_win_divisor",
1248 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1249 .maxlen = sizeof(u8),
1251 .proc_handler = proc_dou8vec_minmax,
1254 .procname = "tcp_workaround_signed_windows",
1255 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1256 .maxlen = sizeof(u8),
1258 .proc_handler = proc_dou8vec_minmax,
1261 .procname = "tcp_limit_output_bytes",
1262 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1263 .maxlen = sizeof(int),
1265 .proc_handler = proc_dointvec
1268 .procname = "tcp_challenge_ack_limit",
1269 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1270 .maxlen = sizeof(int),
1272 .proc_handler = proc_dointvec
1275 .procname = "tcp_min_tso_segs",
1276 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1277 .maxlen = sizeof(u8),
1279 .proc_handler = proc_dou8vec_minmax,
1280 .extra1 = SYSCTL_ONE,
1283 .procname = "tcp_tso_rtt_log",
1284 .data = &init_net.ipv4.sysctl_tcp_tso_rtt_log,
1285 .maxlen = sizeof(u8),
1287 .proc_handler = proc_dou8vec_minmax,
1290 .procname = "tcp_min_rtt_wlen",
1291 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1292 .maxlen = sizeof(int),
1294 .proc_handler = proc_dointvec_minmax,
1295 .extra1 = SYSCTL_ZERO,
1296 .extra2 = &one_day_secs
1299 .procname = "tcp_autocorking",
1300 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1301 .maxlen = sizeof(u8),
1303 .proc_handler = proc_dou8vec_minmax,
1304 .extra1 = SYSCTL_ZERO,
1305 .extra2 = SYSCTL_ONE,
1308 .procname = "tcp_invalid_ratelimit",
1309 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1310 .maxlen = sizeof(int),
1312 .proc_handler = proc_dointvec_ms_jiffies,
1315 .procname = "tcp_pacing_ss_ratio",
1316 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1317 .maxlen = sizeof(int),
1319 .proc_handler = proc_dointvec_minmax,
1320 .extra1 = SYSCTL_ZERO,
1321 .extra2 = SYSCTL_ONE_THOUSAND,
1324 .procname = "tcp_pacing_ca_ratio",
1325 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1326 .maxlen = sizeof(int),
1328 .proc_handler = proc_dointvec_minmax,
1329 .extra1 = SYSCTL_ZERO,
1330 .extra2 = SYSCTL_ONE_THOUSAND,
1333 .procname = "tcp_wmem",
1334 .data = &init_net.ipv4.sysctl_tcp_wmem,
1335 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1337 .proc_handler = proc_dointvec_minmax,
1338 .extra1 = SYSCTL_ONE,
1341 .procname = "tcp_rmem",
1342 .data = &init_net.ipv4.sysctl_tcp_rmem,
1343 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1345 .proc_handler = proc_dointvec_minmax,
1346 .extra1 = SYSCTL_ONE,
1349 .procname = "tcp_comp_sack_delay_ns",
1350 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1351 .maxlen = sizeof(unsigned long),
1353 .proc_handler = proc_doulongvec_minmax,
1356 .procname = "tcp_comp_sack_slack_ns",
1357 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1358 .maxlen = sizeof(unsigned long),
1360 .proc_handler = proc_doulongvec_minmax,
1363 .procname = "tcp_comp_sack_nr",
1364 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1365 .maxlen = sizeof(u8),
1367 .proc_handler = proc_dou8vec_minmax,
1368 .extra1 = SYSCTL_ZERO,
1371 .procname = "tcp_reflect_tos",
1372 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1373 .maxlen = sizeof(u8),
1375 .proc_handler = proc_dou8vec_minmax,
1376 .extra1 = SYSCTL_ZERO,
1377 .extra2 = SYSCTL_ONE,
1380 .procname = "udp_rmem_min",
1381 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1382 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1384 .proc_handler = proc_dointvec_minmax,
1385 .extra1 = SYSCTL_ONE
1388 .procname = "udp_wmem_min",
1389 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1390 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1392 .proc_handler = proc_dointvec_minmax,
1393 .extra1 = SYSCTL_ONE
1396 .procname = "fib_notify_on_flag_change",
1397 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1398 .maxlen = sizeof(u8),
1400 .proc_handler = proc_dou8vec_minmax,
1401 .extra1 = SYSCTL_ZERO,
1402 .extra2 = SYSCTL_TWO,
1407 static __net_init int ipv4_sysctl_init_net(struct net *net)
1409 struct ctl_table *table;
1411 table = ipv4_net_table;
1412 if (!net_eq(net, &init_net)) {
1415 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1419 /* skip first entry (sysctl_max_tw_buckets) */
1420 for (i = 1; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1421 if (table[i].data) {
1422 /* Update the variables to point into
1423 * the current struct net
1425 table[i].data += (void *)net - (void *)&init_net;
1427 /* Entries without data pointer are global;
1428 * Make them read-only in non-init_net ns
1430 table[i].mode &= ~0222;
1435 table[0].data = &net->ipv4.tcp_death_row->sysctl_max_tw_buckets;
1437 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1438 if (!net->ipv4.ipv4_hdr)
1441 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1442 if (!net->ipv4.sysctl_local_reserved_ports)
1448 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1450 if (!net_eq(net, &init_net))
1456 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1458 struct ctl_table *table;
1460 kfree(net->ipv4.sysctl_local_reserved_ports);
1461 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1462 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1466 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1467 .init = ipv4_sysctl_init_net,
1468 .exit = ipv4_sysctl_exit_net,
1471 static __init int sysctl_ipv4_init(void)
1473 struct ctl_table_header *hdr;
1475 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1479 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1480 unregister_net_sysctl_table(hdr);
1487 __initcall(sysctl_ipv4_init);